Rate this page:

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 ChannelType of custom.

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.

Loading Code Sample...

        Creating an Access Token (Chat)

        Now you need to:

        1. 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.
        2. Create a Flex Chat Channel (or reuse one if this is a return customer and you're using Long Lived channels)
          1. 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.

        Loading Code Sample...

              Create a Flex Chat Channel

              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 messageAdded event 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.
              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.

              Loading Code Sample...

                    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!