Menu

Expand
Rate this page:

Interactions Resource

This Twilio product is currently available as a Beta release. Some features are not yet implemented and others may be changed before the product is declared as Generally Available. Use of this Beta release is subject to the relevant terms of the applicable license agreement. Beta products are not covered by a Twilio SLA. Learn more about beta product support.

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.

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

Interaction properties

Resource Properties in REST API format
sid
sid<KD> Not PII

The unique string created by Twilio to identify an Interaction resource, prefixed with KD.

channel
object Not PII

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
object Not PII

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
url Not PII

links
uri_map Not PII

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: sms, whatsapp, web, chat, or email

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, agent, or api


customer: Indicates that this interaction was initiated by a customer and will always trigger an inbound task. The media_channel_sid, defined in the properties object, is required and the customer participant must already be in that given media_channel_sid.


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 media_channel_sid is not given, a new one will be created and the given participants in the participants object will be added.

properties [optional]

The media channel properties. In this release only Twilio Conversations is supported as a media channel.

Depending on the value used in initiated_by and Channel type, there are required values in some cases as follows:

media_channel_sid is required for all channels, when initiated_by is set to the value customer. Note, this must be set to a Twilio Conversation SID which is prefixed by CH. See the sid property on the Conversation Resource.

For email channel with initiated_by set to agent or api, the following are required:

from: email address of contact center team (e.g. support@twilio.com). This is set as the projected_address parameter on the Conversation Participant resource.

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.


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.



Create an Interaction resource

post
https://flex-api.twilio.com/v1/Interactions
Parameters
Parameters in REST API format
channel
Required
post object Not PII

The Interaction's channel.

routing
Required
post object Not PII

The Interaction's routing logic.

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.

customer-initiated sms contact diagram

Example 1
        
        
        
        This requires a preexisting Conversation SID.

        Customer-initiated SMS Contact

        This requires a preexisting Conversation SID.

        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.

        outbound agent-initiated interaction diagram

        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.

        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:

              api-initiated contact diagram

              1. Your customer fills out a web form on your site or application.
              2. 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.
              3. The Interactions endpoint will take care of creating the conversation and adding the participant
              4. 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
                    
                    
                    
                    Rate this page:

                    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.

                          
                          
                          

                          Thank you for your feedback!

                          Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

                          Sending your feedback...
                          🎉 Thank you for your feedback!
                          Something went wrong. Please try again.

                          Thanks for your feedback!

                          Refer us and get $10 in 3 simple steps!

                          Step 1

                          Get link

                          Get a free personal referral link here

                          Step 2

                          Give $10

                          Your user signs up and upgrade using link

                          Step 3

                          Get $10

                          1,250 free SMSes
                          OR 1,000 free voice mins
                          OR 12,000 chats
                          OR more