Menu

Rate this page:

Thanks for rating this page!

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

Programmable Chat

Learn how to build web and mobile chat bots with Autopilot and Programmable Chat. First, you need setup Programmable Chat, then you can connect to Autopilot. We'll walk you through both steps.

Setting up Programmable Chat

To get started with Programmable Chat check out the Quickstarts for Javascript, iOS and Android:

After the quickstart,you should have a working Chat Service Instance.

Connecting Chat to Autopilot

To use Autopilot with Programmable Chat follow the steps below:

  1. Initialize Chat
  2. Create a Channel and join it
  3. Add Autopilot URL to Channel Webhook
    1. Programmable Chat Standalone
    2. Programmable Chat through Studio
  4. Handle Autopilot messages in your Chat UI
  5. Test it!
  6. When finished, remove the Bot from the channel

1. Initialize Chat Client

For every end user session you need to initialize a chat client with an identity following the instructions below:

2. Create a channel and join channel

Once you have the chat client initiated, you need to create a new channel. You should create a channel for every interaction with the bot so that the user starts with an empty chat. Once you create the channel you need to join it.

Create a channel

Join Channel

3. Add Autpilot URL to Channel

You can use Autopilot with Programmable Chat directly or through Studio. Below are the instrucctions to configure Programmable Chat both ways. You should configure one or the other, but not both.

3.1. Programmable Chat

For every Programmable Chat Channel, you need to add a webhook that points to Autopilot so that Autopilot get's the end-user's message and knows where to respond.

POST /Services/ISXXX/Channels/CHXXX/Webhooks/

request parameters

Attribute

Value

Type

webhook

Configuration.Url

{Your Autopilot Programmable Chat URL}

Configuration.Method

POST

Configuration.Filters

onMessageSent

        
        
        
        

        Make sure to replace:

        ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - with the Chat Service Instance Sid you are using

        CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - with the Channel you created for the user

        ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - with the Account Sid

        {ProgrammableChatURL} - with your Assistant's Programmable Chat URL (Channels -> Programmable Chat in Console)

        3.2 Programmable Chat through Studio

        For every Programmable Chat Channel, you need to add a webhook that points to Studio so that the Autopilot widget in Studio get's the end-user's message and knows where to respond. To enable incoming Chat messages, add the Studio Flow's webhook URL as a Chat Channel webhook.

        POST /Services/ISXXX/Channels/CHXXX/Webhooks/
        

        request parameters

        Attribute

        Value

        Type

        studio

        Configuration.FlowSid

        FWxxxxxxxxx

              
              
              
              

              Make sure to replace:

              ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - with the Chat Service Instance Sid you are using

              CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - with the Channel you created for the user

              ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - with the Account Sid

              {Flow Sid} - with the Studio Flow Sid

              New messages posted in the Chat Channel will create a new Studio Execution, enabling the Studio Flow to interact with the Chat user.

              Autopilot URL Parameters

              Parameter Description
              TargetTask

              A string representing the unique name of the destination Task. If no TargetTask is provided, the destination task is determined by the natural language understanding.


              TargetTask is useful when you want to control what task a user is routed to. You may want users that write in from different web pages to land in different tasks

              For Example: Note the TargetTask parameter at the end of the URL

              https://channels.autopilot.twilio.com/v1/AC005c432c1f038a6fcf60e7708db371f4/UAbe96379c4e0ff73bd6b1d5e345de172e/twilio-chat?TargetTask=life_insurance_home
              

              Any message sent to a bot with this URL will land in the life_insurance_home task.

              4. Handle Autopilot messages in your Chat UI

              Behind the scenes, Autopilot uses the Programmable Chat REST API to publish messages from your Assistant to the Chat Channel using the default value of system as the from parameter on the message. To change this, replace this value with the name of your Assistant or any other value you want when implementing the SDK on the front end. Learn more about Android, Javascript and iOS SDKs here.

              5. Test it!

              You are all set. Send a message to the channel, this will go to Autopilot and Autopilot will respond. You can check the Autopilot Logs -> Queries to make sure the message is getting to Autopilot. You should see which task it is hitting. Then you can program each Tasks with the the desired conversational experience.

              6. When finished, remove the Bot from the Channel

              When the interaction s complete or you want a human to take over you just need to remove the webhook from the Channel.

                    
                    
                    
                    
                    Remove webhook from Channel

                    Remove webhook from Channel

                    Remove webhook from 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 browsing the Twilio tag on Stack Overflow.