https://flex-api.twilio.com/v1
The Flex API uses the same HTTP Basic Authentication as other Twilio APIs. Use your Twilio account SID as your username and your Auth Token as your password.
The following is an example of an agent-initiated interaction.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createInteraction() {11const interaction = await client.flexApi.v1.interaction.create({12channel: {13type: "sms",14initiated_by: "agent",15participants: [16{17address: "+13115552368",18proxy_address: "+192555512345",19},20],21},22routing: {23properties: {24workspace_sid: "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",25workflow_sid: "WWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",26queue_sid: "WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",27worker_sid: "WKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",28task_channel_unique_name: "sms",29attributes: {30customerName: "silly name",31customerAddress: "+13115552368",32},33},34},35});3637console.log(interaction.sid);38}3940createInteraction();
1{2"sid": "KDaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"channel": {4"type": "sms",5"sid": "UOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"6},7"routing": {8"reservation": null,9"properties": {10"date_updated": 1634845217,11"task_queue_entered_date": 1634845217,12"workflow_name": "Default Fifo Workflow",13"age_in_queue": 0,14"task_channel_unique_name": "default",15"assignment_status": "pending",16"queue_name": "Sample Queue",17"assignmentCounter": 0,18"priority": 0,19"sid": "WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",20"workflow_sid": "WWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",21"routing_target": "WKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",22"reason": "",23"attributes": "{\"customerAddress\":\"customer phone address\",\"flexChannelInviteSid\":\"KGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"conversationSid\":\"CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"channelType\":\"sms\",\"customers\":{\"phone\":\"customer phone address\",\"name\":\"customer name\"},\"conversations\":{\"initiated_by\":\"customer\",\"conversation_id\":\"KDaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"media\":[{\"type\":\"ChatTranscript\",\"sid\":\"CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}]},\"customerName\":\"customer name\",\"flexInteractionChannelSid\":\"UOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"initiatedBy\":\"customer\",\"flexInteractionSid\":\"KDaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"direction\":\"inbound\"}",24"task_channel_sid": "TCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",25"age": 0,26"workspace_sid": "WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",27"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",28"timeout": 86400,29"date_created": 1634845217,30"addons": "{}",31"queue_sid": "WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"32}33},34"interaction_context_sid": null,35"url": "https://flex-api.twilio.com/v1/Interactions/KDaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",36"links": {37"channels": "https://flex-api.twilio.com/v1/Interactions/KDaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels"38}39}
1{2"url": "https://https://flex-api.twilio.com//v1/Interactions/KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",3"routing": {4"reservation": null,5"properties": {6"date_updated": 1637013849,7"task_queue_entered_date": 1637013849,8"workflow_name": "Assign to Anyone",9"age_in_queue": 0,10"task_channel_unique_name": "sms",11"assignment_status": "pending",12"queue_name": "Everyone",13"assignmentCounter": 0,14"priority": 0,15"sid": "WTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",16"workflow_sid": "WWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",17"routing_target": "WKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",18"reason": null,19"attributes": "{\"customerAddress\":\"+1311-555-2368\",\"flexChannelInviteSid\":\"KGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\"conversationSid\":\"CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\"channelType\":\"sms\",\"conversations\":{\"initiated_by\":\"Agent\",\"communication_channel\":\"Sms\",\"media\":[{\"conversation_sid\":\"CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\"}],\"direction\":\"Outbound\"},\"customerName\":\"silly name\",\"flexInteractionChannelSid\":\"UOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\"initiatedBy\":\"agent\",\"direction\":\"outbound\"}",20"task_channel_sid": "TCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",21"age": 0,22"workspace_sid": "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",23"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",24"timeout": 86400,25"date_created": 1637013849,26"addons": "{}",27"queue_sid": "WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"28}29},30"channel": {31"type": "sms",32"sid": "UOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"33},34"sid": "KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",35"links": {36"channels": "https://https://flex-api.twilio.com/v1/Interactions/KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Channels"37}38}
The following table lists a set of "well known" attributes that are consumed by the Flex UI and/or Flex Insights.
Attribute | Description | Example |
---|---|---|
customerName | For Insights, it is used to populate conversations.customers.name. In the Flex UI, it is rendered as the main customer's name for an email task. | Al Fresco |
customerAddress | For Insights, it is used to populate conversations.customers.email or conversations.customers.phone. In the Flex UI, it is rendered as the main customer's email address for an email task. | +192522212345 or alfresco@aol.com |
from | This is the Flex UI's preferred attribute for identifying the customer on non-email tasks. For email tasks, it uses customerName. | Al Fresco, +19251235555 |
subject | In the Flex UI, it is rendered as the initial subject of an email thread task. | Issue with shoes |
flexInteractionChannelSid | Used in the Flex UI to identify whether a task is interaction-based or not and therefore whether there is a need for Flex UI orchestration or not. | UOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
flexInteractionSid | The interaction SID | KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
flexChannelInviteSid | The invite SID | KGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
followed_by | Used for external warm transfers | |
outcome | Used for external warm transfers | |
customers | This object is automatically added if customerAddress and customerName are provided. This object contains the name, phone, and email of a single customer. name [required]: The display name of the customer. If name is not available, it must be set to null phone [required]: The phone number or WhatsApp number of the customer. If number is not available, it should be set to null email [required]: The email address of the customer. If no email address is available, it should be set to null | "customers": { "name": "Al Fresco", "Phone": "+19252148887", "email": null } |
The following attributes are added when the channel is created (asynchronously):
Attribute | Description | Example |
---|---|---|
conversations.external_contact (This is the Conversation projected address) | For Insights, this is the contact address the customer used to reach you or the contact address from which you have reached them. This may be an inbound support phone number, your support email, or a phone number that appears on the customer's phone when you call them. The contact information (email, phone) that the customer uses or sees when communicating with the contact center can be used for traffic segmentation. | help@example.com |
Some interaction request channel attributes are also used to create other task attributes. The following table lists those task attributes that are created from the given channel attributes:
Interaction Channel Attribute | Task Attribute(s) | Values |
---|---|---|
type | conversations.media.type (Insights) For all conversation media types | ChatTranscript |
conversations.communication_channel (Insights) | Email, SMS, Whatsapp, Web, Chat | |
channelType (FlexUI) The Flex UI uses this to identify tasks that have the same "uniqueTaskChannelName" as chat, but have to be treated differently, e.g. whatsapp, sms. | email, sms, whatsapp, web, chat, messenger, gbm | |
initiated_by | direction (Flex UI) When initiated_by is set to "agent", this value is outbound, otherwise it's inbound. | customer | api | agent |
properties.media_channel_sid | conversations.conversation_id (Insights) | KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
conversations.media.sid (Insights) | ||
conversationSid (Flex UI) |
The following table captures the reason for requiring these attributes:
Flex Insights attributes | How/why is it used |
---|---|
conversations.media.type | Example of the entire media object with attached chat transcript |
conversations.initiated_by | Flex Insights: Used to identify how the conversation was initiated. This helps to identify funnels leading towards a conversation. |
conversations.external_contact | Flex Insights: The contact address the customer used to reach you or the contact address from which you have reached them. This may be an inbound support phone number, your support email, or a phone number that appears on the customer's phone when you call them. Useful for segmenting traffic by contact information (email, phone) |
conversations.conversation_id conversations.media.sid | The ID of the conversation used for Historical insights. The Media SID is used to get access to the transcripts. |
Some common errors you may encounter include Error 20003 and Error 11200. See the Twilio Error and Warning Dictionary for a list of potential errors.