This sample bot is designed to make a student's life seamless on matters academics and resources. It uses Twilio as the messaging client, Google's Dialog flow for intent filtering, and runs on a Node.js server.
- Ngrok account
- Dialogflow account
- Twilio account
- GCP service account
git clone https://github.com/Dev-Elie/Student_assistant_bot.git
cd Student_assistant_bot
npm install
-
Go to the Dialogflow website (https://dialogflow.cloud.google.com/) and sign up for an account.
-
On the Dialogflow console, click the Create Agent button in the top left corner.
- Enter a name for your agent and select the default language and time zone. Then click on the Create button.
- In the left sidebar of the Dialogflow console, click on the Intents option.
- Click on the Create Intent button.
- Add some training phrases that represent the user's input. These phrases should represent the type of input the intent is designed to handle.
As you will see in the later steps, a user can respond to the bot using phrases above or others that match the intent and get the desired response.
- Under the Action and parameters section, define an action. We describe an action
studentassistant.MENU
that triggers the show welcome menu logic in your service.
When a user says something similar to a training phrase, Dialogflow matches it to the intent, which is responsible for showing the welcome menu message.
This action-based response logic \controllers\response\controller.js
file.
-
Click on the Save button to save your changes.
-
Repeat the same process for portals and events. The training phrases are everyday words or stuff we say. For example, for the Portal intent, we can have training phrases like “portal,” “my portal,” “students portal,” and a number depending on how the options appear in the response. Say, we have the responses in this order:
- Portals
- Events
We can therefore have 1
and 2
as training phrases.
You are free to add as many intents as you desire while adding more logic to handle the same.
That’s it; Dialogflow is ready to match user responses to the right actions.
Here’s a video tutorial to help you set up.
Once you have downloaded the client.json
file, proceed to \config\config.js
and fill it in with your keys from the downloaded file. Remember, these are sensitive credentials, and the news is there’s no unique way I have handled them in this project. You might want to store them as environment variables
.
Good job, just one more set up to go, buddy 🙂
-
Log in to your Twilio console (https://console.twilio.com/)
-
On the top right, click on the Account menu.
- On the drop-down, select API Keys & tokens. Once created, add the Live credentials;
TWILIO_ACCOUNT_SID
and TWILIO_AUTH_TOKEN
to your .env
file.
- Start Ngrok as follows.
ngrok http 3000
For more info on setting up Ngrok, see the Getting started steps.
-
On the Twilio console, on the left sidebar, go to
Messaging > Settings > WhatsApp sandbox settings
. -
On the Ngrok terminal, copy the forwarding URL and paste it in the space “WHEN A MESSAGE COMES IN” in the following format.
https://f749-197-156-137-143.eu.ngrok.io/webhook
Make sure to append /webhook
at the end of the URL.
-
Save the changes.
-
Finally, on your WhatsApp, send a message to the WhatsApp number in the WhatsApp sandbox participants section with the issued code.
If you get the error
RestException [Error]: Twilio could not find a Channel with the specified From address
; double-check that you are using the Live credentials and not the Test credentials.
Viva! That’s all to it. Go ahead and test the bot.
Happy hacking, let’s connect on Twitter @dev_elie