Flex Conversations requires Flex UI 2.0.x. If you are on Flex UI 1.x.x, refer to the Messaging in Flex pages.
Flex Conversations currently does not support displaying the customer's WhatsApp Profile Name.
You can use the /Interactions
endpoint to implement additional opportunities for agents to send an outbound SMS, WhatsApp, Chat, Email, Facebook message (Public Beta), and Google Business message (Public Beta).
Some practical examples include a "click-to-sms" or "click-to-email" functionality in your CRM integration.
application/x-www-form-urlencoded
The Interaction context sid is used for adding a context lookup sid
^HQ[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
On your outbound request, you must set the initiated_by
property to "agent". Also, there are specific field requirements depending on your channel type. See Interactions resource request parameters for the different properties you can set.
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",15properties: {16type: "sms",17},18participants: [19{20address: "+13115552368",21proxy_address: "+192555512345",22type: "sms",23},24],25},26routing: {27properties: {28workspace_sid: "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",29workflow_sid: "WWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",30queue_sid: "WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",31worker_sid: "WKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",32task_channel_unique_name: "sms",33attributes: {34customerName: "silly name",35customerAddress: "+1311-555-2368",36},37},38},39});4041console.log(interaction.sid);42}4344createInteraction();
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}
Please note, creating outbound WhatsApp interactions is very similar to outbound SMS. However, you will need to create outbound templates in order for an agent to initiate contact.
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: "whatsapp",14initiated_by: "agent",15properties: {16type: "whatsapp",17},18participants: [19{20address: "whatsapp:+1311-555-2368",21proxy_address: "whatsapp:+19251235555",22type: "whatsapp",23},24],25},26routing: {27properties: {28workspace_sid: "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",29workflow_sid: "WWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",30queue_sid: "WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",31worker_sid: "WKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",32attributes: {33customerName: "Test Customer",34customerAddress: "whatsapp:+1311-555-2368",35},36},37},38});3940console.log(interaction.sid);41}4243createInteraction();
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}
Once your interaction is created, grab the conversation SID (prefixed by CH) and pass it as a parameter when you create a conversation message.
1curl -X POST https://conversations.twilio.com/v1/Conversations/CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages \2--data-urlencode "Author=agentname" \3--data-urlencode "Body=Hello world" \4-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN