Interactions Resource
Flex Conversations requires Flex UI 2.0. If you are on Flex UI 1.x, please refer to Messaging in Flex pages.
Interactions Resource
The Interactions resource lets you create inbound and outbound interactions for different channel types. To create an interaction, you must supply Channel and Routing attributes. The Channel attributes are used to either create or to bind to an underlying media channel such as a conversation. The Routing attributes are used to create a task which is then routed according to your specified workspace and workflow. A successful interaction results in a task reservation being offered to an agent which references the associated media channel.
Creating an interaction is an asynchronous request for which a 200
response only indicates that the server has accepted the request. You need to use the getter methods to check if the interaction channel was set up successfully. Additionally, the example JSON responses on this page are not representative of the actual API response. See example response on the API overview page.
In this release, an interaction supports a single channel. Refer to the Invites subresource to see how you can create multiple tasks for the same interaction channel to include multiple agents.
POST /Interactions
Remember to handle certain terminal TaskRouter events according to your application's needs, as conversations may stay orphaned with an open
state.
See Conversations Best Practices for details.
Interaction properties
Resource Properties in REST API format | |
---|---|
sid
|
The unique string created by Twilio to identify an Interaction resource, prefixed with KD. |
channel
|
A JSON object that defines the Interaction’s communication channel and includes details about the channel. See the Outbound SMS and inbound (API-initiated) Channel object examples. |
routing
|
A JSON Object representing the routing rules for the Interaction Channel. See Outbound SMS Example for an example Routing object. The Interactions resource uses TaskRouter for all routing functionality. All attributes in the Routing object on your Interaction request body are added “as is” to the task. For a list of known attributes consumed by the Flex UI and/or Flex Insights, see Known Task Attributes. |
url
|
|
links
|
|
interaction_context_sid
|
|
Request Parameters
Parameter | Sub-fields | Description | |
Channel [required] | A JSON object that defines the interaction’s communication channel and includes details about the channel. See the Outbound Email, Outbound SMS, and inbound (API-initiated) Channel object examples. | ||
type [required] |
The media channel type. Allowed values: Note: These can be different from the task channel type specified in the Routing attributes. Task channel type corresponds to channel capacity while this channel type is the actual media type. |
||
initiated_by [required] |
The actor that created this Interaction. Allowed values: customer: Indicates that this interaction was initiated by a customer and will always trigger an inbound task. The agent: initiated by an agent’s click. Will always trigger an outbound Task for the same agent. This will also create a new Conversation and add the agent to that Conversation. api: Triggered or initiated by a secondary type of interaction e.g. webform, automation, etc. This will create an inbound Task. If a |
||
properties [optional] |
The media channel properties. In this release only Twilio Conversations is supported as a media channel. Depending on the value used in media_channel_sid is required for all channels, when For email channel with from: email address of contact center team (e.g. support@yourcompany.com). This is set as the from_name: name of contact center team (e.g. Twilio Support) |
||
participants [ ] [optional] |
An array of participants. Required for outbound interactions where initiated_by is set to agent. Otherwise, it’s optional. The specified participants will be added to the media channel and to the interaction channel. The attributes required to specify the participant address depends on the type of address, as follows: SMS & Whatsapp: proxy_address: This is the business number which must be a Twilio-verified number e.g +192555512345, whatsapp:+19251235555 address: Actual phone number of the customer Chat & Web: identity: The chat identity of the user in Twilio conversations. We recommend following the standard URI specification and avoid the following reserved characters ! * ' ( ) ; : @ & = + $ , / ? % # [ ] for values such as identity and friendly name. Email: level: the recipient field. Could be to, cc, or bcc name: customer display name in your Flex application address: customer email address For more information, refer to the Twilio Conversations Participant resource. |
||
Routing [required] | A JSON Object representing the routing rules for the Interaction Channel. See Outbound SMS Example for an example Routing object. The Interactions resource uses TaskRouter for all routing functionality. | ||
properties [required] |
Fields needed to create a task: workspace_sid [required] The TaskRouter Workspace SID which starts with WS. workflow_sid [optional] The Workflow SID prefixed by WW. Optional if there’s only one workflow defined otherwise it’s mandatory queue_sid [required for agent-initiated], the Task router Queue SID prefixed by WQ. worker_sid [required for agent-initiated] task_channel_sid [optional] task_channel_unique_name [optional] attributes [optional] : The task attributes. priority [optional]: The priority of the task in the queue. timeout [optional]: The task/reservation timeout interval in seconds.
|
Create an Interaction resource
https://flex-api.twilio.com/v1/Interactions
Parameters
Parameters in REST API format | |
---|---|
channel
Required
|
The Interaction's channel. |
routing
Required
|
The Interaction's routing logic. |
interaction_context_sid
Optional
|
The Interaction context sid is used for adding a context lookup sid |
Customer-initiated SMS Contact
For customer-initiated contacts, you must have an existing Conversation SID for the required media_channel_sid
.
In this example, we have configured the SMS address in the Console with a webhook
integration. As a result, our endpoint will be called when a new conversation is created and a new message (SMS) is added. At this time, we would create the Interaction and the Channel and have it routed to an agent. The diagram illustrates the flow.
Example 1
Agent-initiated Outbound Interactions
This example shows how to create an outbound Flex interaction from your backend application. Use the /Interactions endpoint to implement additional opportunities for agents to send an outbound SMS, WhatsApp, Chat, or Email*.
*Please note that Email in Flex is currently in private beta stage.
Some practical examples include a “click-to-sms” or “click-to-email” functionality in your CRM integration.
The API response will contain a newly created task SID, which you can use to update the task attributes, retrieve the conversation SID, or do some additional programming as needed. The agent initiating the interaction must be available in the Flex application to start the conversation in the Flex UI.
Example 2
API-initiated Contact
You can use the API to prompt an agent through a workflow to message your customer.
These tasks can be prompted by a customer requesting assistance (for example, an “ask for help” form) or through automation (for example, analysis of reviews). Accordingly, you must indicate that the interaction was initiated by the API. An example flow can go like this:
- Your customer fills out a web form on your site or application.
- Your application logic creates an interaction. The content from the form is used to populate the task attributes, and the Interactions resource creates an inbound task.
- The Interactions endpoint will take care of creating the conversation and adding the participant
- An agent is assigned the task, accepts the reservation, and writes to the customer to solve their issue.
In the diagram above, step 2 might look something like this:
Example 3
Need some help?
We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.