Twilio Event Streams integration with Segment, Segment Sink enables you to send Twilio Events to Segment so that:
To get started,
You'll need Segment Account.
Provide your Segment source's writeKey to when configuring Segment Sink.
Subscribe to the Segment available events
In the Segment app, from your workspace's /sources
page, click Add source
.
Choose Twilio Event Streams.
Give the source a nickname. The nickname is a label used in the Segment interface. It can be whatever you like, but we recommend sticking to something that reflects the source itself, like Twilio Events
for nickname and twilio_events
for the schema name.
Note : You can add multiple instances if you have multiple Twilio accounts. That's why we allow you to customize the source's nickname!
When you click Connect , you'll be prompted for your Twilio WriteKey. Follow the steps below to setup the Segment Sink in the Twilio Console and get a write key.
You'll be re-directed to Twilio's app and you'll need to authorize Segment to read from your account data. To authorize, click in the "Allow" button. Once approved, you'll be redirected back to the set up page in the Segment app.
Click on the "Finish" button and you'll be good to go! We'll begin syncing your Twilio data into Segment momentarily, and it will be written to your warehouse at your next Warehouse run.
Via the Console
Events Streams
from the left-hand menu, then click Manage
.Create
a new Sink.Write Key
box in the Twilio Console. Complete the setup in the Segment App.You will need to install and set up the Twilio CLI for your account to use the following command.
To create a new Segment Sink, run this command:
1twilio api:events:v1:sinks:create --description <add sink description here> \2--sink-configuration '{"write_key":"${your segment write key}"}' \3--sink-type segment
If we are unable to deliver events to your Sink due to a problem with the Sink, we send errors through Twilio Debugger. After the first error about Sink failure, we will continue to notify you every 20 minutes. The notification will include the Sink ID and error details.
Now that you have a created Segment Sink, you can subscribe to one or more events. The following are the events that are available for subscription to Segment Sink. In order to prevent profile duplication within Segment, we have limited the availability of the events to the following events.
Event Type | Schema Version |
---|---|
com.twilio.messaging.message.queued | 4 |
com.twilio.messaging.message.sent | 4 |
com.twilio.messaging.message.delivered | 4 |
com.twilio.messaging.message.failed | 4 |
com.twilio.messaging.message.undelivered | 4 |
com.twilio.messaging.message.read | 4 |
com.twilio.messaging.inbound-message.received. | 4 |
Create
a new Subscription. A subscription is comprised of a set of pairs of Event Types and Schema versions.Create Subscription
.You can subscribe to any of these events by making an API call. This is done with the following command. The new subscription is configured to read the event-types from the --types
argument — you'll need the event type and schema version from the table above. The event-types you specify in the--types
argument will be sent to the Sink specified by the --sink-sid
argument. Use the Sink SID of the Sink you created above.
1twilio api:events:v1:subscriptions:create --description <description> \2--sink-sid <sink id DGxxx> \3--types '{"type": "<event_type>","schema_version": <version>}'
For instance, to subscribe to all call summary events, you would run:
1twilio api:events:v1:subscriptions:create \2--description "Subscription on 3 call_summary events" \3--sink-sid <sink id DGxxx> \4--types '{"type":"com.twilio.voice.insights.call-summary.partial","schema_version":1}' \5--types '{"type":"com.twilio.voice.insights.call-summary.predicted-complete","schema_version":1}' \6--types '{"type":"com.twilio.voice.insights.call-summary.complete","schema_version":1}'
Data is sent to Segment as a JSON with the Segment Analytics format. Here's a Message Delivered event, for example:
1{2"anonymousId": "13460360364754414896",3"context": {4"externalIds": [5{6"collection": "users",7"encoding": "none",8"id": "+34606234664",9"type": "phone"10}11],12"library": {13"name": "unknown",14"version": "unknown"15}16},17"event": "com.twilio.messaging.message.delivered",18"integrations": {},19"messageId": "EZ159d95769704d0837c04fde4fd2d32e4",20"originalTimestamp": "2021-11-17T05:11:29.346644414-08:00",21"properties": {22"accountSid": "AC824d654a84f279949ca008d28875f833",23"apiVersion": "2010-04-01",24"eventName": "com.twilio.messaging.message.delivered",25"from": "+18126097345",26"messageSid": "SMbfcfc5f402de469aa18941e3e11c59ae",27"messageStatus": "DELIVERED",28"messagingServiceSid": "MGcf4248034753df3eac81423fd08fa0cd",29"timestamp": "2021-11-17T13:11:28.963Z",30"to": "+ 18126097345"31},32"receivedAt": "2021-11-17T13:11:29.378Z",33"timestamp": "2021-11-17T13:11:29.346Z",34"type": "track"35}
The properties
field should meet its schema, which is the Messaging.MessageStatus schema in this case.
Optional: For Personas + Twilio Messaging customers only