Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

A2P 10DLC - Event Streams Setup


Customers who are registering Brands, Campaigns and 10DLC Phone Numbers for A2P Messaging can now set up subscriptions to events which will notify them when a Brand, Campaign or Phone Number's status has changed. This setup and subscription is handled through Twilio's Event Streams product, which allows users to define a sink (in this case a webhook) to which an event notification will be sent for any events to which the user has subscribed - in this case, when a Brand or Campaign has been either successfully submitted or not, and whether successfully-submitted Brands and Campaigns are ultimately approved or rejected, or what a phone number's status is in it's A2P registration or deregistration process. With these event notifications now 'pushed' to customers via the Event Streams framework, it will no longer be necessary to repeatedly query the Brand and Campaign creation APIs, be in limbo about the number's registration status, or continually visit the A2P Console pages, in order to be kept up to date on registration status.

This document will cover the following topics:

  • How to set up event sinks and subscriptions via the Event Streams APIs, which will be the most likely path for Independent Software Vendors (SVs) managing the registration of large numbers of secondary brands, either Sole Proprietor or Standard/Low-Volume Standard.
  • How to set up event sinks and subscriptions via the Event Streams Console, which will be the likely path for Direct customers who make use of the Event Streams service.
  • How to read the json payloads sent in messages for various events, with example payloads for each event.

Set up Event Streams via the Event Streams API

set-up-event-streams-via-the-event-streams-api page anchor

Setting up webhook sinks and event subscriptions via the Event Streams API entails the following steps:

  1. Creating a sink resource
  2. Note the possible event types you're interested in
  3. Creating a subscription to specific events, for a specified sink

NOTE: If you are an ISV using separate subaccounts for each of your secondary clients, the Event Stream setup (both Sink and Subscription) will need to be done for each subaccount.

1 Create a new sink resource

1-create-a-new-sink-resource page anchor

A new sink is created via a POST/create call to the sinksendpoint of the Events API.

Sinks are the destinations to which events selected in a subscription will be delivered. Each sink has a sink_type property. At this time, the Sink resource supports three types: AWS Kinesis indicated by the value kinesis, Webhooks (which you will be using) indicated by the value webhook, and Segment indicated by the value segment . Each Sink has a sink_configuration property which expresses its set up. Finally, each sink resource has a friendly-name description parameter.

Again, if you are configuring a secondary customer whose Profile/Brand/Campaign resides in a subaccount, the account_sid and auth_token parameters used in this call (as well as the Subscription creation call in Step 1.3 below) must be those of the subaccount.

Sink_configuration is an object parameter whose elements are different for each sink_type. For the Webhook type, sink_configuration is formatted as follows:


_10
"sink_configuration": {
_10
_10
"destination": "http://example.org/webhook",
_10
_10
"method": "<POST|GET>",
_10
_10
"batch_events": <true|false>
_10
_10
}

ParameterDescription
destinationThe customers' url endpoint i.e http://example.org/webhook(link takes you to an external page)
methodThe HTTP method for updating the data on the webhook. The currently available options are GET and POST.
batch_eventsfalse if you want to receive single events and true if you want events sent in batches. Batched events currently have a 64kB data limit.

Note finally that the sid return parameter from this call will become the sink_sid parameter used in Step 1.3 below.

Create Sink

create-sink page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_14
// Download the helper library from https://www.twilio.com/docs/node/install
_14
// Find your Account SID and Auth Token at twilio.com/console
_14
// and set the environment variables. See http://twil.io/secure
_14
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_14
const authToken = process.env.TWILIO_AUTH_TOKEN;
_14
const client = require('twilio')(accountSid, authToken);
_14
_14
client.events.v1.sinks
_14
.create({description: 'My A2P Sink', sinkConfiguration: {
_14
destination: 'http://example.org/webhook',
_14
method: '<POST|GET>',
_14
batch_events: '<true|false>'
_14
}, sinkType: 'webhook'})
_14
.then(sink => console.log(sink.sid));

Output

_18
{
_18
"status": "initialized",
_18
"sink_configuration": {
_18
"destination": "http://example.org/webhook",
_18
"method": "<POST|GET>",
_18
"batch_events": "<true|false>"
_18
},
_18
"description": "My A2P Sink",
_18
"sid": "DGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_18
"date_created": "2015-07-30T20:00:00Z",
_18
"sink_type": "webhook",
_18
"date_updated": "2015-07-30T20:00:00Z",
_18
"url": "https://events.twilio.com/v1/Sinks/DGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_18
"links": {
_18
"sink_test": "https://events.twilio.com/v1/Sinks/DGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Test",
_18
"sink_validate": "https://events.twilio.com/v1/Sinks/DGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Validate"
_18
}
_18
}

2 Event types and type IDs

2-event-types-and-type-ids page anchor

You can fetch a list of all subscribable event types from the event_type endpoint of the Events API. You must pass all of these inside the types parameter object when you create your subscription in the next step.

Brand and Campaign Registration Events

brand-and-campaign-registration-events page anchor

The following is a list of all six event types associated with A2P Brand and Campaign registration, and the corresponding Event Type ID string.

Event TypeEvent type ID
Brand Registration Failurecom.twilio.messaging.compliance.brand-registration.brand-failure
Brand Registered Unverifiedcom.twilio.messaging.compliance.brand-registration.brand-unverified
Brand Registeredcom.twilio.messaging.compliance.brand-registration.brand-registered
Campaign Registration Submittedcom.twilio.messaging.compliance.campaign-registration.campaign-submitted
Campaign Registration Failed or Rejectedcom.twilio.messaging.compliance.campaign-registration.campaign-failure
Campaign Registration Approvedcom.twilio.messaging.compliance.campaign-registration.campaign-approved

Phone Number Registration Events

phone-number-registration-events page anchor

The following is a list of all six event types associated with A2P Number Registration, and the corresponding Event Type ID string.

Event TypeEvent type ID
Number Deregistration Failedcom.twilio.messaging.compliance.number-deregistration.failed
Number Deregistration Pendingcom.twilio.messaging.compliance.number-deregistration.pending
Number Deregistration Successfulcom.twilio.messaging.compliance.number-deregistration.successful
Number Registration Failedcom.twilio.messaging.compliance.number-registration.failed
Number Registration Pendingcom.twilio.messaging.compliance.number-registration.pending
Number Registration Successfulcom.twilio.messaging.compliance.number-registration.successful

3 Create a subscription to specific events, for a specific sink

3-create-a-subscription-to-specific-events-for-a-specific-sink page anchor

To create a new subscription, use a POST/create call to the subscriptions endpoint of the Events API. This call must associate a specific array of event types with a specific sink to which these event messages will be sent when they are raised.

The subscription create call has the following parameters:

description - a brief human-readable description of the subscription, which should be clearly associated with the sink you're specifying here

sink_sid - the SID of the new sink you created in Step 1.1 above

types - an object containing a delimited list of all the event type IDs for the events you wish to subscribe to, in this case all of the IDs enumerated in 1.2 above. The exact syntax of the types object will vary depending the library you are using; please refer to the code snippet below. In python, for example, the syntax would be:


_10
types=[
_10
{'type': 'com.twilio.messaging.message.delivered'},
_10
{'type': 'com.twilio.messaging.message.sent', 'schema_version': 2}
_10
],

In the above example we are subscribing to only two events: messaging.message.delivered and messaging.message.sent, but in your create call you will include all 6 events enumerated in Step 1.2 above. Note that in this example, the second event also specifies a schema_version of 2; if this is not specified, the default schema used will be 1 (currently only schema 1 is available for A2P events, so schema_version need not be specified).

Create a new Subscription

create-a-new-subscription page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_14
// Download the helper library from https://www.twilio.com/docs/node/install
_14
// Find your Account SID and Auth Token at twilio.com/console
_14
// and set the environment variables. See http://twil.io/secure
_14
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_14
const authToken = process.env.TWILIO_AUTH_TOKEN;
_14
const client = require('twilio')(accountSid, authToken);
_14
_14
client.events.v1.subscriptions
_14
.create({
_14
description: `"My A2P Subscription"`,
_14
sinkSid: `"DGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"`,
_14
types: [{'type': 'com.twilio.messaging.message.delivered'}, {'type': 'com.twilio.messaging.message.sent', 'schema_version': 2}]
_14
})
_14
.then(subscription => console.log(subscription.sid));

Output

_12
{
_12
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_12
"date_created": "2015-07-30T20:00:00Z",
_12
"date_updated": "2015-07-30T20:01:33Z",
_12
"sid": "DFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_12
"sink_sid": "DGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_12
"description": "\"My A2P Subscription\"",
_12
"url": "https://events.twilio.com/v1/Subscriptions/DFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_12
"links": {
_12
"subscribed_events": "https://events.twilio.com/v1/Subscriptions/DFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SubscribedEvents"
_12
}
_12
}


Set up Webhooks and subscribe to A2P Registration Events via the Event Streams Console

set-up-webhooks-and-subscribe-to-a2p-registration-events-via-the-event-streams-console page anchor
  1. From your Twilio Console home, search for Event Streams > Manage in the search bar:
Console_home_search_for_Event_Streams.Rate this page:

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.