Skip to contentSkip to navigationSkip to topbar
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
Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
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 SMSLink to code sample: Outbound SMS
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createInteraction() {
11
const interaction = await client.flexApi.v1.interaction.create({
12
channel: {
13
type: "sms",
14
initiated_by: "agent",
15
properties: {
16
type: "sms",
17
},
18
participants: [
19
{
20
address: "+13115552368",
21
proxy_address: "+192555512345",
22
type: "sms",
23
},
24
],
25
},
26
routing: {
27
properties: {
28
workspace_sid: "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
29
workflow_sid: "WWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
30
queue_sid: "WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
31
worker_sid: "WKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
32
task_channel_unique_name: "sms",
33
attributes: {
34
customerName: "silly name",
35
customerAddress: "+1311-555-2368",
36
},
37
},
38
},
39
});
40
41
console.log(interaction.sid);
42
}
43
44
createInteraction();

Output

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
}

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.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createInteraction() {
11
const interaction = await client.flexApi.v1.interaction.create({
12
channel: {
13
type: "whatsapp",
14
initiated_by: "agent",
15
properties: {
16
type: "whatsapp",
17
},
18
participants: [
19
{
20
address: "whatsapp:+1311-555-2368",
21
proxy_address: "whatsapp:+19251235555",
22
type: "whatsapp",
23
},
24
],
25
},
26
routing: {
27
properties: {
28
workspace_sid: "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
29
workflow_sid: "WWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
30
queue_sid: "WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
31
worker_sid: "WKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
32
attributes: {
33
customerName: "Test Customer",
34
customerAddress: "whatsapp:+1311-555-2368",
35
},
36
},
37
},
38
});
39
40
console.log(interaction.sid);
41
}
42
43
createInteraction();

Output

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.

1
curl -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

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.