Skip to content

This sample application shows how to build an automated SMS chatbot using Twilio's autopilot

License

Notifications You must be signed in to change notification settings

twilio-labs/sample-autopilot-support-bot

Repository files navigation

Twilio

Twilio SMS Support Chatbot

Actions Status

About

This sample application shows how to build an automated SMS chatbot using Twilio's autopilot

Implementations in other languages:

.NET Java Python PHP Ruby
TBD TBD TBD TBD TBD

How it works

After the user sets and submits the configuration parameters on the /config page, the sample will automatically create an Autopilot assistant with predefined Tasks and actions using Twilio's REST API. Then, the user can send a text message to the configure phone number to start the conversation. The bot will ask the user for specific input to provide a proper response.

Features

  • Node.js web server using Express.js
  • Basic web user interface using Pug for templating and Bootstrap for UI
  • User interface to configure some SMS parameters.
  • Sms parameters can be stored in a JSON database using lowdb.
  • Unit tests using mocha and chai
  • Automated CI testing using GitHub Actions
  • Linting and formatting using ESLint and Prettier
  • Interactive configuration of environment variables upon running npm run setup using configure-env
  • Project specific environment variables using .env files and dotenv-safe by comparing .env.example and .env.
  • One click deploy buttons for Heroku and Glitch

Set up

Requirements

Twilio Account Settings

This application should give you a ready-made starting point for writing your own SMS chatbot application. Before we begin, we need to collect all the config values we need to run the application:

Config Value Description
Account Sid Your primary Twilio account identifier - find this in the Console.
Auth Token Used to authenticate - just like the above, you'll find this here.
Phone number A Twilio phone number in E.164 format - you can get one here

Local development

After the above requirements have been met:

  1. Clone this repository and cd into it
git clone [email protected]:twilio-labs/sample-autopilot-support-bot.git
cd sample-autopilot-support-bot
  1. Install dependencies
npm install
npm install -g ngrok
  1. Set your environment variables
npm run setup

See Twilio Account Settings to locate the necessary environment variables.

  1. Run the application
npm start

Alternatively, you can use this command to start the server in development mode. It will reload whenever you change any files.

npm run dev
  1. Once you have your server running, you need to expose your localhost to a public domain so the Twilio aurtopilot can reach the expected endpoint. This is easy using ngrok:
ngrok http 3000

This will generate a url similar to: https://cd2ef758.ngrok.io

  1. Navigate to /config preceding with the ngrok url you got earlier to set the SMS params and create the autopilot assistant. NOTE: Always submit the configuration using the ngrok url, never with localhost. Otherwise the autopilot assistant won't be able to establish a call with the operator, if you choose that option.

  2. (Optional) After submitting the configuration you can go to your Twilio's Console and take a look at at the created autopilot for more details.

  3. Send a text message to the phone number provisioned on Twilio to start the conversation!

That's it!

Tests

You can run the tests locally by typing:

npm test

Cloud deployment

Additionally to trying out this application locally, you can deploy it to a variety of host services. Here is a small selection of them.

Please be aware that some of these might charge you for the usage or might make the source code for this application visible to the public. When in doubt research the respective hosting service first.

Don't forget to set the environmental variables on each hosting service!

Service
Heroku Deploy
Glitch Remix on Glitch

Here are some notes about the services:

  • Heroku: Very straightforward, just create an account and after clicking the deploy button you need to follow the instructions and that's it.
  • Glitch: It requirers an additional step. Once you click on the deploy button, you need to manually create the file .env and set the variables. You can duplicate the .env.example file and edit it accordingly.

Resources

Contributing

This template is open source and welcomes contributions. All contributions are subject to our Code of Conduct.

Visit the project on GitHub

License

MIT

Disclaimer

No warranty expressed or implied. Software is as is.

About

This sample application shows how to build an automated SMS chatbot using Twilio's autopilot

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •