Rate this page:

Integrate a Custom Chat Client with Flex

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.


        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.


              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 Community Forums or browsing the Twilio tag on Stack Overflow.


                    Thank you for your feedback!

                    We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

                    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