Twilio Conversations enables back-and-forth messaging across various communication channels. This means multiple users from different supported messaging platforms are able to seamlessly communicate with one another. Use Studio to handle interactions or logic for incoming Conversation messages and leverage the powerful capabilities of Conversations' cross-channel and multi-user support.
Conversations provides the ability to add or remove Participants that are interacting with a Flow's Execution, creating the opportunity to add support agents at any point to assist users with your Studio application. Additionally, the Conversations integration enables collaborative capabilities within your application as multiple Participants can provide input and move the same Flow Execution forward.
To connect a Twilio Conversation to your Studio Flow, check out the following tutorials:
A Studio Flow's Execution will start when a message is created in the Conversation that is connected to the Flow. Use the Incoming Conversation
transition within the Trigger (Start) Widget. Once a message is sent in a Conversation, the Widget connected to the Incoming Conversation transition will be run.
If you are using Flex Conversations, remember to handle certain terminal TaskRouter events according to you application's needs, as conversations may stay orphaned with an open
state.
See Conversations Best Practices for details.
You can modify Conversations Participants using the Run Function Widget along with a Twilio Function. A Twilio Function will run code that makes a request to the Conversations API to add or remove Participants.
In this example, customers will send the keyword "support" as a Conversation message. The Studio Flow will detect that the keyword was sent and add a Participant to the Conversation. The Participant will be the support agent in this case.
The Incoming Conversation transition from the Trigger (Start) Widget is used to detect and start the Studio Flow when a new message is sent in the Conversation the Studio Flow is connected to. All messages sent within the Studio Flow will be delivered to all Participants in the Conversation.
Add a Split Based On… Widget to the Canvas to check if the keyword "support" is sent within the Conversation. Rename the Widget to check-support
. Liquid variables are values stored within a Studio Flow that can be used by your Widgets. When checking for the "support" keyword, the Split Based On… Widget evaluates the {{trigger.conversation.Body}}
variable. This variable holds the message that was sent in the Conversation. In the Variable to Test field, enter {{trigger.conversation.Body}}
.
_25exports.handler = function(context, event, callback) {_25_25 // get the Twilio client_25 const client = context.getTwilioClient();_25_25 // store the Conversation ID passed in from the Studio Flow_25 const conversationsSid = event.conversationID;_25_25 // add a participant to the Conversation_25 client.conversations_25 .conversations(conversationsSid)_25 .participants_25 .create({_25 'messagingBinding.address': 'enter-support-agent-phone-number',_25 'messagingBinding.proxyAddress': 'enter-twilio-phone-number'_25 })_25 .then(participant => {_25 console.log(participant.sid);_25 return callback(null, "Success");_25 })_25 .catch(err => {_25 console.log(err);_25 callback(err)_25 })_25};
Add a Run Function Widget, which runs code you write in a Twilio Function, to the Canvas. Rename the Run Function Widget to add-support-agent
. Connect the Support
transition you created in the check-support
Widget to this Widget by clicking the dangling dot under the Support
transition and dragging it to the Run Function Widget before letting go.