Flex Conversations requires Flex UI 2.0.x. If you are on Flex UI 1.x.x, refer to the Messaging in Flex pages.
Unlike voice channels, digital channels like SMS and chat are asynchronous and last indefinitely, with no clear event indicating the end of a conversation.
Due to this open-ended nature of digital channels, a customer contact or inquiry could stall, and an agent may need to wait for the customer or a back-office personnel to reply in order to continue the conversation. This scenario could persist over several days, or even weeks.
The Interactions API allows you to remove the agent from the channel while leaving the customer in the interaction. In order to follow along, please review the Interactions Resource and the Interaction Channel Participants page for detailed examples.
An interaction channel (UOXXXXXX) is deleted after 180 days of inactivity, regardless of its state. Retrieving the channel after 180 days from deletion returns a 404 Not Found
. Note that the initial TTL (Time to Live) period resets every time there is an update to the interaction channel, such as if an agent accepts the new task through Flex UI. Changes to the Conversations channel, such as updating conversation status or adding or removing a participant, do not reset the interaction channel's inactivity period.
Make sure to include the original task attributes in your subsequent POST
/Invites requests since these attributes are not carried over to the new Task created as a result of sending the Invite.
To remove an agent, send a POST
(update) request to the Participants endpoint.
1curl -X POST https://flex-api.twilio.com/v1/Interactions/KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Channels/UOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Participants/UTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \2--data-urlencode "Status=closed" \3-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN4
When a "closed" status is passed, the associated task is completed but the channel, Conversation in this case, remains active.
To re-add an agent, or "unpark/pick up" the interaction, you can use the Invites endpoint to reroute the new task to a specific agent or to specify a workflow for evaluating a suitable queue or agent.
To create a new task for workflow evaluation, send a POST
(create) request to the Invites endpoint.
1ROUTING=$(cat << EOF2{3"properties": {4"attributes": {5"from": "+13115552368"6},7"workflow_sid": "WWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",8"workspace_sid": "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"9}10}11EOF12)1314curl -X POST https://flex-api.twilio.com/v1/Interactions/KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Channels/UOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Invites \15--data-urlencode "Routing=$ROUTING" \16-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN1718
1{2"url": "https://flex-api.twilio.com/v1/Interactions/KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Channels/UOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Invites/KGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",3"interaction_sid": "KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",4"channel_sid": "UOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",5"routing": {6"reservation": null,7"properties": {8"date_updated": 1636401979,9"age_in_queue": 0,10"task_channel_unique_name": "default",11"assignment_status": "pending",12"queue_name": "Sample Queue",13"assignmentCounter": 0,14"priority": 0,15"sid": "WTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",16"task_queue_entered_date": 1636401979,17"workflow_name": "Default Fifo Workflow",18"workflow_sid": "WWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",19"routing_target": "WKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",20"reason": null,21"attributes": "{\"flexChannelInviteSid\":\"KGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\"conversationSid\":\"UOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\"channelType\":\"email\",\"conversations\":{\"communication_channel\":\"Email\",\"conversation_id\":\"KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\"media\":[{\"conversation_sid\":\"UOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\"media\":[{\"type\":\"ChatTranscript\",\"sid\":\"CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\"}],\"customers\":{\"phone\":\"+13115552368\",\"name\":null,\"email\":null}},\"flexInteractionChannelSid\":\"UOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\"flexInteractionSid\":\"KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\"}",22"task_channel_sid": "TCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",23"age": 0,24"workspace_sid": "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",25"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",26"timeout": 86400,27"date_created": 1636401979,28"addons": "{}",29"queue_sid": "WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"30}31},32"sid": "KGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"33}
Alternatively, you can include a queue SID and a Worker SID in your POST
Invites request to add a specific agent back to the Interaction:
1ROUTING=$(cat << EOF2{3"properties": {4"attributes": {5"from": "+13115552368"6},7"workflow_sid": "WWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",8"workspace_sid": "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",9"queue_sid": "WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",10"worker_sid": "WKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"11}12}13EOF14)1516curl -X POST https://flex-api.twilio.com/v1/Interactions/KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Channels/UOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Invites \17--data-urlencode "Routing=$ROUTING" \18-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
Once the customer issue has been solved, you can set the status of the interaction channel to closed
by sending a POST
(update) Interaction Channel request like so:
1curl -X POST https://flex-api.twilio.com/v1/Interactions/KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Channels/UOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \2--data-urlencode "Status=closed" \3-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
This will set any reservations to the "wrapping" status.
To try out a working implementation of an interaction park feature, check out the source code in this sample plugin repository.