Integrate a Custom Chat Client with Flex
This guide is for Flex UI 1.x and channels that use Programmable Chat and Proxy. If you are using Flex UI 2.x or you are starting out, we recommend that you build with Flex Conversations.
You may have already built a custom chat experience with Programmable Chat or from scratch. You can integrate these chat experiences with Flex and hand off incoming Chat messages to your agents.
Custom chat integrations require a Flex Flow
How to Integrate Your Chat Application with Flex
First, initialize the Twilio Chat SDK using an access token that links a user with a unique identity - for example:
abc123. The Chat SDK is going to help you pass messages back and forth with Flex.
Make sure this identity uniquely identifies your end user and avoid using personally identifiable information like names.
Now you need to:
- Ensure you have a relevant Message Handler. You can add Studio to the communication flow, immediately create a task, or do something else entirely depending on how you've configured your Flex Flow.
- Create a Flex Chat Channel (or reuse one if this is a return customer and you're using Long Lived channels)
- Creating a Channel will also automatically create a Chat User and place it in the Channel.
This configuration could require a minimum of four API requests, but with Flex you can do everything with a single request to Flex Chat Channels API.
Bringing it all together
Now you can use the Twilio Chat SDK to manage communications on the Chat Channel you created with Flex:
- When a message comes in, you'll receive a
messageAddedevent and can render it in your custom UI.
- When you need to send a message, the SDK includes a
sendMessage()method that you can use to publish media over the Twilio Chat Channel.
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.