Flex uses Twilio Studio to implement pre-agent workflows. Refer to the Core Concepts: Studio chapter for a general introduction.
The Studio Flow is executed when one of the Trigger events happens. For Flex, the most relevant triggers are Incoming Message, Incoming Call and Incoming Conversation.
To configure a Phone Number to trigger your desired Studio Flow, head to Phone Numbers > Manage > Active numbers, choose the respective number, and set the Voice or Messaging trigger to call the respective Studio Flow.
The Send to Flex widget will create a TaskRouter Task for the incoming communication, and execute a TaskRouter Workflow to route it to an agent.
For the Incoming Call trigger, Send to Flex will enqueue the Voice and the caller will hear hold music while waiting for an agent to respond.
In Flex Conversations (which requires Flex UI 2.0), a new Trigger Incoming Conversation has been added. In this case, Send to Flex will create a new Interaction using the /Interactions endpoint, which then creates a new Task for assignment to a Worker.
Optionally, you can declare Task attributes, priority, timeout, and a hold music TwiML URL. To learn more, see Send to Flex.
Use Studio Flows to build out any logic that needs to execute before a Task is created and routed to an agent. Typical use cases include IVR, chat bots, and call deflection. Some useful resources include:
The Studio REST API v2 allows you to programmatically create, publish, and manage your Studio Flows without having to log in to the Twilio Console. Studio Flows are defined using a JSON schema to configure the widgets and the functionality. The REST API also provides methods to trigger an outbound call or message, as well as for reporting on Executions that have completed.