How to implement Twilio Flex on Android?

Greetings

I want to implement Twilio Flex on Android. I don't want to implement the contact center part. I want to implement the bubble that opens a chat for the consumer.

From what I can see, the documentation is for Web https://www.twilio.com/docs/flex, so I'm wondering how this has to be handled on Android?

Answers

  • Hi Cutiko,

    If you are not looking to implement a Flex contact center (which includes features like agent routing), then you may be better served by the Conversations API. The docs offer an Android quickstart which you may find useful:

    If you are looking to implement agent routing, then Flex will be the way to go.

    Like you noticed, Flex webchat is a React app, and if you're looking to implement a chat feature you would be better served by creating a chat app using the relevant SDK to create the interface, and then connecting those messages to Flex via Programmable Chat.

    At a high level, the flow will look something like the following:

    To imitate the behavior outlined above, use the Flex WebChannel endpoint.

    The most convenient way to handle the username and channel creation is through the token generator. When generating the token for Programmable Chat SDK, you can also generate the name of the user and the channel name by making a request to Flex Channel Orchestration.

    The endpoint you want to call is:

    https://flex-api.twilio.com/v1/Channels

    A sample Curl request would look like this:

    curl -X POST \
    https://flex-api.twilio.com/v1/Channels \
    --data-urlencode "FlexFlowSid=FOxxxxx" \
    --data-urlencode "Identity=abc123" \
    --data-urlencode "ChatUserFriendlyName=John" \
    --data-urlencode "ChatFriendlyName=Inbound chat with abc123" \
    -u ACxxxx:your_auth_token
    

    Note: the attributes listed above are all required to connect to Flex.

    Once you successfully create the channel, you will receive a response with a Channel SID. Your user will be joined to the channel and you can consume the Channel object by calling the method getSubscribedChannels() when initializing the user with the token.

    Twilio.Chat.Client.create(data.token).then(client => {
     chatClient = client;
     chatClient.getSubscribedChannels().then( channels => {
     
     });
    });
    

    Once you have the Channel object, you call the updateAttributes() method from the Programmable Chat SDK. This updates the channel attributes with any pre-engagement form that you would like to pass.

    If you are using a Studio flow to connect to the Flex interface, the Channel Attributes will arrive to Studio in the trigger.message.ChannelAttributes parameter when the user sends the first message. You can then pass these attributes to the Flex interface using the SendToFlex widget.

  • Thanks.

    I think the answer puts me in the right direction. I did get confused by something.

    You mention Programmable Chat and Conversations. However, the documentation indicates Programmable Chat API will be sunset in July. The correct SDK to use would be Conversation, then? Or Flex, as you suggest, can't be accessed by conversation?

If this is an emergency, please contact Twilio Support. This is not an official Support channel. https://support.twilio.com/
Have an urgent question?
Please contact Twilio Support. This is not an official Support channel.
Contact Support