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).
  2. Once published, click on ‘Export’ at the top-right of the flow builder.
  3. You will be prompted with the Export wizard.

In the Export tab, follow these steps:

  1. On the top-left dropdown, select ‘WhatsApp/SMS’.

    1.1. Select Input and Output node Make sure you select at least one input and one output. These will be used to receive (input) and send (output) messages to WhatsApp.

    1.2 Account SID. You can find your Account SID in Twilio’s console. Please, select the LIVE credentials rather than the test ones.

    1.3 Auth Token. You can find your Auth Token in Twilio’s console. Please, select the LIVE credentials rather than the test ones.

    1.2. Webhook URL. Finally, copy/paste Stack AI’s webhook URL into Twilio’s Sandbox Settings. If the webhook URL (starting with ) contains a placeholder <YOUR_API_KEY>, you need to click on ‘Show Token’ to display your API key. - Copy the webhook URL displayed. Make sure your API key is filled in.

    1. Go back to Twilio’s “Sandbox settings” tab, and find the Sandbox Configuration section.
    2. Paste the webhook URL in the When a message comes in field, inside the Sandbox Configuration section.
    3. Make sure the Method is set to POST
    4. 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.

FAQ

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-water send 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