Connect a bot to Twilio (SMS)

APPLIES TO: SDK v4

You can configure your bot to communicate with people using the Twilio (SMS) cloud communication platform. This article describes how to configure a bot to communicate using Twilio by creating a TwiML application and connecting the bot in the Azure portal.

Prerequisites

  • An Azure account. If you don't already have one, create a free account before you begin.
  • An existing bot published to Azure.

Create a TwiML application

  1. If you don't have a Twilio account, create a new account. If you already have a Twilio account, continue to the next step.
  2. Follow the instructions to create a TwiML application.
    • Enter a Friendly Name for your TwiML app.

    • Under Voice Configuration, leave the Request URL empty

    • Under Messaging Configuration, set the Request URL:

      • For a global bot, enter https://sms.botframework.com/api/sms.
      • For a regional bot, enter following url according to the selected region:
      Region Request URL
      Europe https://europe.sms.botframework.com/api/sms
      India https://india.sms.botframework.com/api/sms

Select or add a phone number

Follow the instructions to add a verified caller via the Console. You can skip this if you already have a verified caller ID.

After you finish, you'll see your verified number in Verified Caller IDs.

Specify TwiML app to use for voice and messaging

After adding a verified caller ID, configure your number's setting to use the TwiML app you created.

  1. Select Active numbers under Phone Numbers > Manage. Select the number and go to Configure.
  2. Under both Voice & Fax and Messaging, set Configure With to *TwiML App. Then set TwiML APP to the TwiML app you created earlier. After you finish, select Save.
  3. Select Active Numbers again. You'll see the Active Configuration of both Voice and Messaging are set to your TwiML App.

Gather credentials from Twilio

  1. Go back to the Twilio Console homepage

  2. Under Account Info, you'll see your Account SID and Auth Token on the project dashboard, shown below. Copy and save these values for later steps.

    Gather app credentials from Twilio Console

Enter Twilio credentials in the Azure portal

Now that you have the necessary values from Twilio, connect your bot to Twilio in the Azure portal.

  1. In a separate window or tab, go to the Azure portal.

  2. Select the bot that you want to connect to Twilio.

  3. Under Settings, select Channels, then select the Twilio (SMS) icon from the list of Available Channels.

  4. Enter the Phone Number, Account Sid, and Auth Token you saved earlier. After you finish, select Apply.

    Enter Twilio credentials in Azure

Your bot's now successfully configured to communicate with Twilio users.

Test your bot in Twilio

To test whether your bot is connected to Twilio correctly, send an SMS message to your Twilio number. When your bot receives the message, it sends a message back to you, echoing the text from your message.

Additional information

To learn more about developing for Twilio, see the Twilio SMS documentation.

Connect a bot to Twilio using the Twilio adapter

In addition to using the available Azure AI Bot Service channel to connect your bot with Twilio, the Bot Builder Community repos define a custom channel adapter for Twilio.