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 |
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.
- 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
andchai
- Automated CI testing using GitHub Actions
- Linting and formatting using ESLint and Prettier
- Interactive configuration of environment variables upon running
npm run setup
usingconfigure-env
- Project specific environment variables using
.env
files anddotenv-safe
by comparing.env.example
and.env
. - One click deploy buttons for Heroku and Glitch
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 |
After the above requirements have been met:
- Clone this repository and
cd
into it
git clone [email protected]:twilio-labs/sample-autopilot-support-bot.git
cd sample-autopilot-support-bot
- Install dependencies
npm install
npm install -g ngrok
- Set your environment variables
npm run setup
See Twilio Account Settings to locate the necessary environment variables.
- 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
- 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 usingngrok
:
ngrok http 3000
This will generate a url similar to: https://cd2ef758.ngrok.io
-
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. -
(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.
-
Send a text message to the phone number provisioned on Twilio to start the conversation!
That's it!
You can run the tests locally by typing:
npm test
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 | |
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.
-
This project was generated using this sample NodeJS template
-
GitHub's repository template functionality
This template is open source and welcomes contributions. All contributions are subject to our Code of Conduct.
No warranty expressed or implied. Software is as is.