📱WhatsApp / SMS (Twilio)

Deploy your chatbot using WhatsApp and/or SMS with Twilio

We provide a webhook to receive and send messages with Twilio to serve your chatbot over WhatsApp and/or SMS.

We are planning to add more functionality and are looking for feature requests. If you'd like to have a feature which we don't support yet, or want to provide some feedback, feel free to reach out to us directly to founders@stack-ai.com

WhatsApp with Twilio

Using Twilio to set up a WhatsApp number involves a few steps. Here's a general outline to get started:

  1. Sign Up for Twilio and Enable WhatsApp Sandbox:

    • Sign up for a Twilio account if you haven't already.

    • Navigate to the WhatsApp section in the Twilio Console.

    • Here you'll find the WhatsApp Sandbox.

    • While you're testing, you can use the sandbox environment provided by Twilio to send and receive messages without connecting to an official business profile. We'll show later how to connect to an official business profile.

  2. Test with Twilio Sandbox:

    • You'll see a sandbox number and a code.

    • To activate your personal number for testing, send the given code to the sandbox number from your personal WhatsApp.

    • Once activated, any messages sent to the sandbox number will be relayed to your Twilio account.

  3. Set Up Webhook to connect Twilio with Stack AI:

    • To make your number interactive (i.e., send and receive messages), let's set up a webhook that will connect Twilio to Stack AI.

      1. Once you have built your Stack AI flow, click on 'Publish' at the top-right of the flow builder (next to the 'Run' button). Make sure the button turns green.

      2. Once published, click on 'Export' at the top-right of the flow builder.

      3. You will be prompted with the Export wizard.

        1. Click on 'WhatsApp/SMS' tab.

          1. Step 1: General tab

            1. Give your interface a name by filling the Interface Name

          2. Step 2: Inputs/Outputs tab

            1. Make sure you select at least one input and one output. These will be used to receive (input) and send (output) messages to WhatsApp.

          3. Step 3: Export. Here you will find a webhook URL that you need to copy/paste into Twilio's Sandbox Settings.

            1. If the webhook URL (starting with https://www.stack-inference.com ) contains a placeholder <YOUR_API_KEY>, you need to click on 'Show Token' to display your API key.

            2. Copy the webhook URL displayed. Make sure your API key is filled in.

        2. Go back to Twilio's "Sandbox settings" tab, and find the Sandbox Configuration section.

        3. Paste the webhook URL in the When a message comes in field, inside the Sandbox Configuration section.

        4. Make sure the Method is set to POST

        5. The Status callback URL can be left blank.

Develop and Test your Application

  • Whenever a user sends a message to your Twilio WhatsApp number, Twilio will make a request to your webhook URL. Your Stack AI flow can then decide how to respond, using Twilio to send a reply back to the user.

  • Send a message to WhatsApp and confirm that you are receiving an answer from Stack AI.

  • If this doesn't work, repeat the previous steps or contact us at support@stack-ai.com

Move to Production

  • Once you're done with sandbox testing, you can apply to have your business profile approved by WhatsApp.

  • Navigate to Twilio’s WhatsApp Request Form and fill it out.

  • After you get approval, you'll connect your business profile with Twilio, and you can start sending messages to all users without them having to join the sandbox.

Always follow WhatsApp's policies and guidelines when sending and receiving messages. Avoid spammy behaviors as WhatsApp is strict, and misuse can lead to the banning of your business profile.

Always refer to the official Twilio and WhatsApp documentation for the most accurate and up-to-date information.


My StackAI WhatsApp bot stopped working after 24h.

  • If you are using Twilio's Sandbox, you will need to send a message, something along the lines of join solid-watersend to activate for 24 more hours. Make sure you redo the Sandbox initialization that you can find on Twilio's website. Once your prototype is working, and you want to move it to production, check out the Move to Production guide above.

Last updated