TwilioHackathon - Manage homeworks in WhatsApp chat easily
Tags: twiliohackathon, typescript, node
Published: 2020-04-22 07:52:46

[Comment]: # (All of this is placeholder text. Use this format or any other format of your choosing to best describe your project.)

[Reminder]: # (Make sure you've submitted the Twilio CodeExchange agreement: https://ahoy.twilio.com/code-exchange-community)

[Important]: # (By making a submission, you agree to the competition's terms: https://www.twilio.com/legal/twilio-dev-hackathon-terms)

Hello, Everyone.

As in many other countries, in Russia due to the quarantine schools are closed as well. So, teachers and students (mainly teachers) have to start using WhatsApp for organizing chats for sending, scheduling, and receiving homeworks. That is the pretty common situation for the primary school when a single teacher is responsible for all subjects to have a WhatsApp chat with pupils and their parents.
The similar situation could be applied for the middle school - when several teachers taught different subject. It is just the exacerbated situation either with the single chat or with multiple chats :)
When you have 20 pupils and 20+ parents in a chat pretty often you cannot easily find necessary information quickly. For example: what is my homework for art on Thursday?

So, in order to make the life of teachers, parents and pupils a bit easier, I decided to build a chat bot or virtual assistant that will keep this information and answer to everyone who needs it.

The use-case:
- A Teacher decides to announce the homework for math on next Tuesday. So, he or she can do it by typing in a chat:

**@hw math Tuesday Do calculus!**
- A pupil (or a parent) would like to know what is the homework for a specific subject. So they can do it by typing in chat:

**@bot What is my homework? or What should I do?** 
- Bot will ask you to clarify the request:

*Could you specify the subject your are interested in?*
**@bot math**

*Please remind me on what day you would like to get the homework?*
**@bot Tuesday**

- And finally, a pupil or a parent gets the answer:  
**Do calculus!**

### Format of commands

* The initial question is possible in several forms:
![Possible initial question forms](https://github.com/sergeyfsv/twilio-hackathon/raw/master/docs/HW%20Bot%20-%20Homework%20Intents.png)

* A teacher could specify the hometask in the following form:
**@hw**[space][subject][space][date]
So far, several subjects are supported with the their synonyms.
![Supported Subjects](https://github.com/sergeyfsv/twilio-hackathon/raw/master/docs/HW%20Bot%20-%20Subjects.png)
Date could be specified in different formats: 
  * Today, Tomorrow, Yesterday, Last Friday, etc
  * 17 August 2013 - 19 August 2013
  * This Friday from 13:00 - 16.00
  * 5 days ago
  * 2 weeks from now
  * Sat Aug 17 2013 18:40:39 GMT+0900 (JST)
  * 2014-11-30T08:15:30-05:30

* **@bot**[space][any text that will be sent to the assistant as your answer]
* Resetting the dialog
In case of getting to the dead-end (probably your questions will be to difficult for the assistant), it is possible to reset the dialog with the following commands:
![Start Over the conversation](https://github.com/sergeyfsv/twilio-hackathon/raw/master/docs/HW%20Bot%20-%20Start%20Over%20Intents.png)
or just type "Reset" if you do not want to be so polite, as suggested in the examples 😊

### Demo Video
If you would like to test it or the jury would like to verify the functionality,
*send a WhatsApp message to+ 1 415 523 8886 with code join owner-chair*.

{% youtube npIJiUH5xTE %} 

### Link to Code
{% github sergeyfsv/twilio-hackathon no-readme %}

### How I built it (what's the stack? did I run into issues or discover something new along the way?)

**Technological Stack**
* Node.JS
* TypeScript
* IBM Cloud Services (IBM Watson, IBM Cloud Foundry and so on)

### Architecture (extremely high-level)

![Homework Bot Architecture Diagram](https://github.com/sergeyfsv/twilio-hackathon/raw/master/docs/HW%20Bot%20-%20Diagram.png)

One of the most difficult part in integrating with Twilio was understanding what should I put in into the field that is labeled as:
*WHEN A MESSAGE COMES IN* 😊
Twilio guys, that is not 100% obvious that here should be link to the webhook.

To be serious, IBM Watson bot development and deployment to IBM Cloud took significant amount of time, especially if you are doing it the first time. I hope that the code that have been shared will allow you start creating application without bothering how to combine libraries for node.js, typescript, twilio or even using IBM Watson.

### Additional Resources/Info

* Nice Visio Stencils if you decide to draw something cloud related [Stencils](https://github.com/ibm-cloud-architecture/ibm-cloud-stencils)