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

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

Output

_35
{
_35
"sid": "KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_35
"channel": {
_35
"type": "sms",
_35
"initiated_by": "agent",
_35
"properties": {
_35
"type": "sms"
_35
},
_35
"participants": [
_35
{
_35
"address": "+13115552368",
_35
"proxy_address": "+192555512345",
_35
"type": "sms"
_35
}
_35
]
_35
},
_35
"routing": {
_35
"properties": {
_35
"workspace_sid": "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_35
"workflow_sid": "WWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_35
"queue_sid": "WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_35
"worker_sid": "WKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_35
"task_channel_unique_name": "sms",
_35
"attributes": {
_35
"customerName": "silly name",
_35
"customerAddress": "+1311-555-2368"
_35
}
_35
}
_35
},
_35
"interaction_context_sid": null,
_35
"url": "https://flex-api.twilio.com/v1/Interactions/KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_35
"links": {
_35
"channels": "https://flex-api.twilio.com/v1/Interactions/KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Channels"
_35
}
_35
}


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

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

Output

_34
{
_34
"sid": "KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_34
"channel": {
_34
"type": "whatsapp",
_34
"initiated_by": "agent",
_34
"properties": {
_34
"type": "whatsapp"
_34
},
_34
"participants": [
_34
{
_34
"address": "whatsapp:+1311-555-2368",
_34
"proxy_address": "whatsapp:+19251235555",
_34
"type": "whatsapp"
_34
}
_34
]
_34
},
_34
"routing": {
_34
"properties": {
_34
"workspace_sid": "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_34
"workflow_sid": "WWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_34
"queue_sid": "WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_34
"worker_sid": "WKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_34
"attributes": {
_34
"customerName": "Test Customer",
_34
"customerAddress": "whatsapp:+1311-555-2368"
_34
}
_34
}
_34
},
_34
"interaction_context_sid": null,
_34
"url": "https://flex-api.twilio.com/v1/Interactions/KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_34
"links": {
_34
"channels": "https://flex-api.twilio.com/v1/Interactions/KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Channels"
_34
}
_34
}

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: