Limited Availability
In order to move into production using the Twilio API for WhatsApp, you need a WhatsApp Business Profile. Please read our documentation on Connecting your Twilio Number with your WhatsApp Business Profile. That being said, you can start building your bot with the WhatsApp Sandbox and move it over to a WhatsApp Business Profile when you receive access.
Whatsapp location pinning is not supported by Autopilot
With Twilio Autopilot, you can build Whatsapp bots. On this page, we'll walk you through how to connect your Whatsapp Sandbox to Autopilot so you can get started building your bot.
- Connect a Whatsapp number- of you have an approved Whatsapp number
- Set up the sandbox - if you are exploring Whatsapp but don't yet have a number approved
Connect a Whatsapp Number
Once you have an approved Whatsapp sender, you can enter the Autopilot Whatsapp URL in the Webhook URL for incoming messages. That way incoming messages will be handled by Autopilot.
Set up the Sandbox
- Sign up for a Twilio account here if you don't already have one.
- Follow these step-by-step instructions for setting up your Sandbox in the Learn page of the WhatsApp console menu.
- Once configured, you can see all the configuration details in the Sandbox page of the WhatsApp menu. You'll need these for the next set of steps.
Connect Autopilot to the Sandbox
Once you have successfully configured your Sandbox, you'll need to connect it to your Autopilot Assistant.
- Go to the Autopilot menu in the console and click into the Assistant you want to connect to WhatsApp.
- Go to the Channels tab in the Assistant Menu and select WhatsApp.
- Copy the URL displayed in the Configuration tab. This is the callback URL used to send incoming messages to your Assistant.
- Go back to the Sandbox page in the WhatsApp console menu. Paste the callback URL where it says 'When a message comes in'.
- Click Save and you're all set!
Test
Now that you have WhatsApp configured it's time to test!
- Open the WhatsApp app
- Tap into the chat window with your WhatsApp bot
- Send your first message, you should get a response from Autopilot
- Check the Autopilot Query logs
Setting up Whatsapp with Flex and Autopilot
First, you need make sure that your Whatsapp Sandbox is setup correctly and that Flex us receiving the messages. You can follow the instructions below:
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. |
Memory |
Lets you send Inbound Context to Autopilot. Should be a JSON string containing key-value pairs to insert into the Autopilot memory before starting a dialogue with the bot. Useful for passing data stored in third party systems like a CRM into Autopilot to deliver a more contextual experience.
|
Example 1: Using TargetTask parameter at the end of the URL
https://channels.autopilot.twilio.com/v1/<ACCOUNT_SID>/<ASSISTANT_SID>/twilio-messaging/whatsapp?TargetTask=handle_appointment_confirmation
Any message sent to number or messaging service configured with this URL will land in the handle_appointment_confirmation task.
Example 2: Passing Inbound Context with Memory
https://channels.autopilot.twilio.com/v1/<ACCOUNT_SID>/<ASSISTANT_SID>/twilio-messaging/whatsapp?Memory={"CarModel":"Diablo","CarMake":"Lamborghini","CarYear":"2019"}
Any message sent to a bot with this URL will insert CarModel, CarMake and CarYear into the Autopilot Memory.
When sending messages using multiple Say
's, Twilio cannot guarantee the ordering with Whatsapp and the user might receive them in a different order.
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.