On 6/6/2020, we made a bot that tells you what programming language you are. This README has instructions on getting started with your bot and where to put the JSON and JS code in this repo, as well as some Resources at the bottom.
You'll need
- a Twilio account--sign up for a free one here and receive an extra $10 if you upgrade through this link
- A Twilio phone number with SMS capabilities - configure one here
Go to your Autopilot console and under Create a Bot
select Start from Scratch
.
Give your bot a title like what-programming-language-are-you and click Create bot
.
Select Channels
from the left-hand menu and then click Programmable Messaging
.
Copy that Messaging URL and in a new tab configure your Twilio number in your phone number console.
You can also do the same for programmable voice so your bot is a phone call bot.
If you don't have a Twilio number yet, go to the Phone Numbers section of your Twilio Console and search for a phone number in your country and region, making sure the SMS checkbox is ticked.
In the Messaging
section of your purchased number, in the A Message Comes In
section, set the Webhook to be your Messaging URL and hit Save.
Make a task called main_questions
. Add the code from bot.json
into it. It asks a series of questions in a Collect
Action and takes in those questions. Each question has a name and a Validate
instruction to limit what the user can answer with. We use the Validate attribute allowed_values to provide an array of possible answers. If this was a quiz where there is only one right answer, it might only have one allowed value.
After the last question, the bot redirects (with a Redirect
Action) to a Twilio Function (a serverless environment for Node.js apps) to tally up all the answers and calculate the all-important answer to "What Twilio Product are you?"
Make a new Function by clicking the red plus button in your Functions Console. Select a Blank
template and click Create
.
Append /superpos
to the path of your Function, then copy the path and paste it in your Autopilot bot JSON bin's on_complete: redirect: uri. Then add the JavaScript code in bot.js
to get the memory of each of the fifteen answered questions and create an empty response object that will soon be filled.
You can add more questions, more answer choices, more emojis, or a more complex system of tallying up the answers. With people sheltering at home, now is a great time to create entertaining quizzes for personal or professional use. Twilio Autopilot makes it easy for you to get creative with chatbots and quizzes to engage with customers, fans, friends, and family, or just have fun. Let me know online or in the comments what you're building.