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

Send Outbound Messages with Flex Conversations Channels


(information)

Info

Flex Conversations requires Flex UI 2.0.x. If you are on Flex UI 1.x.x, refer to the Messaging in Flex pages.

(information)

Info

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.

Request body parameters

request-body-parameters page anchor
Property nameTypeRequiredPIIDescription
Channelobjectrequired
Not PII

The Interaction's channel.


RoutingobjectOptional

The Interaction's routing logic.


InteractionContextSidSID<HQ>Optional

The Interaction context sid is used for adding a context lookup sid

Pattern: ^HQ[0-9a-fA-F]{32}$Min length: 34Max 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.

Outbound SMS

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

_44
// Download the helper library from https://www.twilio.com/docs/node/install
_44
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_44
_44
// Find your Account SID and Auth Token at twilio.com/console
_44
// and set the environment variables. See http://twil.io/secure
_44
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_44
const authToken = process.env.TWILIO_AUTH_TOKEN;
_44
const client = twilio(accountSid, authToken);
_44
_44
async function createInteraction() {
_44
const interaction = await client.flexApi.v1.interaction.create({
_44
channel: {
_44
type: "sms",
_44
initiated_by: "agent",
_44
properties: {
_44
type: "sms",
_44
},
_44
participants: [
_44
{
_44
address: "+13115552368",
_44
proxy_address: "+192555512345",
_44
type: "sms",
_44
},
_44
],
_44
},
_44
routing: {
_44
properties: {
_44
workspace_sid: "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_44
workflow_sid: "WWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_44
queue_sid: "WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_44
worker_sid: "WKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_44
task_channel_unique_name: "sms",
_44
attributes: {
_44
customerName: "silly name",
_44
customerAddress: "+1311-555-2368",
_44
},
_44
},
_44
},
_44
});
_44
_44
console.log(interaction.sid);
_44
}
_44
_44
createInteraction();

Output

_39
{
_39
"sid": "KDaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39
"channel": {
_39
"type": "sms",
_39
"sid": "UOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_39
},
_39
"routing": {
_39
"reservation": null,
_39
"properties": {
_39
"date_updated": 1634845217,
_39
"task_queue_entered_date": 1634845217,
_39
"workflow_name": "Default Fifo Workflow",
_39
"age_in_queue": 0,
_39
"task_channel_unique_name": "default",
_39
"assignment_status": "pending",
_39
"queue_name": "Sample Queue",
_39
"assignmentCounter": 0,
_39
"priority": 0,
_39
"sid": "WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39
"workflow_sid": "WWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39
"routing_target": "WKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39
"reason": "",
_39
"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\"}",
_39
"task_channel_sid": "TCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39
"age": 0,
_39
"workspace_sid": "WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39
"timeout": 86400,
_39
"date_created": 1634845217,
_39
"addons": "{}",
_39
"queue_sid": "WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_39
}
_39
},
_39
"interaction_context_sid": null,
_39
"url": "https://flex-api.twilio.com/v1/Interactions/KDaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39
"links": {
_39
"channels": "https://flex-api.twilio.com/v1/Interactions/KDaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels"
_39
}
_39
}


Outbound WhatsApp

outbound-whatsapp page anchor

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.

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_43
// Download the helper library from https://www.twilio.com/docs/node/install
_43
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_43
_43
// Find your Account SID and Auth Token at twilio.com/console
_43
// and set the environment variables. See http://twil.io/secure
_43
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_43
const authToken = process.env.TWILIO_AUTH_TOKEN;
_43
const client = twilio(accountSid, authToken);
_43
_43
async function createInteraction() {
_43
const interaction = await client.flexApi.v1.interaction.create({
_43
channel: {
_43
type: "whatsapp",
_43
initiated_by: "agent",
_43
properties: {
_43
type: "whatsapp",
_43
},
_43
participants: [
_43
{
_43
address: "whatsapp:+1311-555-2368",
_43
proxy_address: "whatsapp:+19251235555",
_43
type: "whatsapp",
_43
},
_43
],
_43
},
_43
routing: {
_43
properties: {
_43
workspace_sid: "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_43
workflow_sid: "WWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_43
queue_sid: "WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_43
worker_sid: "WKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_43
attributes: {
_43
customerName: "Test Customer",
_43
customerAddress: "whatsapp:+1311-555-2368",
_43
},
_43
},
_43
},
_43
});
_43
_43
console.log(interaction.sid);
_43
}
_43
_43
createInteraction();

Output

_39
{
_39
"sid": "KDaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39
"channel": {
_39
"type": "sms",
_39
"sid": "UOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_39
},
_39
"routing": {
_39
"reservation": null,
_39
"properties": {
_39
"date_updated": 1634845217,
_39
"task_queue_entered_date": 1634845217,
_39
"workflow_name": "Default Fifo Workflow",
_39
"age_in_queue": 0,
_39
"task_channel_unique_name": "default",
_39
"assignment_status": "pending",
_39
"queue_name": "Sample Queue",
_39
"assignmentCounter": 0,
_39
"priority": 0,
_39
"sid": "WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39
"workflow_sid": "WWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39
"routing_target": "WKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39
"reason": "",
_39
"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\"}",
_39
"task_channel_sid": "TCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39
"age": 0,
_39
"workspace_sid": "WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39
"timeout": 86400,
_39
"date_created": 1634845217,
_39
"addons": "{}",
_39
"queue_sid": "WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_39
}
_39
},
_39
"interaction_context_sid": null,
_39
"url": "https://flex-api.twilio.com/v1/Interactions/KDaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39
"links": {
_39
"channels": "https://flex-api.twilio.com/v1/Interactions/KDaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels"
_39
}
_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.


_10
curl -X POST https://conversations.twilio.com/v1/Conversations/CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages \
_10
--data-urlencode "Author=agentname" \
_10
--data-urlencode "Body=Hello world" \
_10
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN


Rate this page: