Updated: 02/06/2018 - v.0.4
"Create chatbot using Node.js, which allows a user to conduct all his reminders - create/delete and reminders alert with an ability to confirm/snooze the reminder.
Bot should use LUIS or Dialogflow API for NLU, and bot application must be the only one on a Facebook Page. You should use LUIS/Dialogflow as an API only (use for defining intents and save context).
Bot should have “Getting started" feature and use a persistent menu for a basic operation like - create a reminder, show all reminders for today etc.
Bot should use structured messages to interact with a user, for example, reminders alert message should be a ""Generic template"" with accept/snooze buttons.
You should use ESlint(Airbnb code style config), npm scripts, database (PostgreSQL or MongoDB), environment variables (Dotenv)."
Not strict but desired in 1 week. If by Thu., 05/24/2018: ~40 hours (5h/d * 5 weekdays + ~7h/d * 2 days off) because of current job and family ;)
Set up a general plan of work and preliminary dialog flow for the bot
Installed node.js, express (+ request, apiai), WebStorm
Got "Hello world" on JS ;)
Created a FB page and app, got FB credentials
Created Dialogflow's agent
Following manual - https://medium.com/crowdbotics/how-to-create-your-very-own-facebook-messenger-bot-with-dialogflow-and-node-js-in-just-one-day-f5f2f5792be5
Uploaded code to github - https://github.com/IuriiD/remindmebot.git
At the moment messages don't come from FB Messenger to local webhook
9:12
Planning..
1) "Hello world" on JS (Node.js)
2) Write functions:
a. create_reminder(),
b. delete_reminder(N),
c. clear_all_reminders(),
d. show_all_reminders() # for today
e. confirm_reminder(),
f. snooze_reminder() # change time +X min (for eg., 15min)
g. alert_reminder()
3) Create a bot on Dialogflow (DF), get credentials
4) Communication with DF via API, triggering functions
9:30
5) Contexts and dialog flow:
a. INPUT_CONTEXT = []
Greeting (Getting started" feature?): Good day [morning/day/evening],
Buttons:
Display my reminders for today
Add a reminder
Let's talk/Tell me a joke ;) (SmallTalk/etc, optionally)
OUTPUT_CONTEXT = []
b. INPUT_CONTEXT = []
User clicked "Display my reminders for today" - trigger show_all_reminders()
Buttons:
Add a reminder
Delete reminder
Clear all reminders
OUTPUT_CONTEXT = [reminders_shown]
c. INPUT_CONTEXT = [reminders_shown]
User clicked "Delete reminder" – ask user to enter a reminder number (integer value will be expected from DF)
Buttons:
Cancel
Main menu (Display…/Add a reminder/…)
OUTPUT_CONTEXT = [which_reminder_to_delete]
d. INPUT_CONTEXT = [which_reminder_to_delete]
User entered something
Integer number is expected – if not, tell user that's not a number and to ask to repeat + "Cancel" button
In range of reminders quantity – if not, tell user that value entered is incorrect and ask to repeat + "Cancel" button
If Ok – trigger delete_reminder(N), trigger show_all_reminders() (for today)
Buttons:
Add a reminder
Delete reminder
Clear all reminders
OUTPUT_CONTEXT = []
e. INPUT_CONTEXT = []
User clicked "Add a reminder" – ask user smth like "What to remind you about?" sys.any input is expected
Buttons:
Main menu (Display…/Add a reminder/…)
OUTPUT_CONTEXT = [reminder_content_input]
f. INPUT_CONTEXT = [reminder_content_input]
User entered something (anything) – tell smth like "Got it!"
Hold reminder content
On which date/time should I set this reminder? – date + time input is expected from DF
Buttons:
Cancel (go to main menu)
OUTPUT_CONTEXT = [reminder_time_input]
g. INPUT_CONTEXT = [reminder_time_input]
If not correct – "Sorry but that date/time seems to be incorrect. Could you please enter a valid value? Thanks ;)"
Buttons:
Cancel (go to main menu)
OUTPUT_CONTEXT = [reminder_time_input]
h. INPUT_CONTEXT = [reminder_time_input]
If date/time Ok - trigger create_reminder(), save data to DB
Inform user "A new reminder 'XXXX' for
Buttons:
Display my reminders for today
Add a reminder
Let's talk/Tell me a joke ;) (SmallTalk/etc, optionally)
OUTPUT_CONTEXT = []
10:00
Draw a paper scheme of actions
10:30
6) Create a FB page and app, get credentials
Backend – FB Messenger interaction
Reading
How To Create Your Very Own Facebook Messenger Bot with Dialogflow and Node.js In Just One Day
Building a Facebook Messenger Bot Using Node.js, Heroku & API.AI
11:00
Created a FB Page: https://www.facebook.com/Remindmebot-191533734823967
Created a FB Messenger bot – Remindmebot
Generated FB page access token: ####
FB App – Callback ULR - https://709fd61d.ngrok.io
Verify Token – remindmebot
Messages, postbacks
11:30
Trying to install express.js on Ubunty in Vagrant or on Windows
npm install express --save
Getting CERT_UNTRUSTED error on Ubuntu
https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-16-04
https://expressjs.com/en/starter/installing.html
github - https://github.com/IuriiD/remindmebot.git
Bypassing https helped (https://stackoverflow.com/questions/21855035/ssl-error-cert-untrusted-while-using-npm-command?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa)
npm config set strict-ssl false
npm install express --save
Reading “Hello World!” app with Node.js and Express
12:00
Failing to get 'Hello world' work
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
Didn't work in Ubuntu (in Vagrant on Windows) but works from Windows
Getting Cannot GET / error on localhost:3000
Installing WebStorm (worked in PyCharm ;)
12:30
So:
Hello world from manual (https://medium.com/@adnanrahic/hello-world-app-with-node-js-and-express-c1eb7cfa8a30 ) works, including via ngrok (https://709fd61d.ngrok.io/)
Code from manual (https://medium.com/crowdbotics/how-to-create-your-very-own-facebook-messenger-bot-with-dialogflow-and-node-js-in-just-one-day-f5f2f5792be5 ) gives Cannot GET / error (localhost:3000, https://709fd61d.ngrok.io/) >> failing to finish NewPageSubscription on FB
13:00
Article (https://medium.com/crowdbotics/how-to-create-your-very-own-facebook-messenger-bot-with-dialogflow-and-node-js-in-just-one-day-f5f2f5792be5) seems to be a bit incorrect(?)
Following comments, changed
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.listen(3000, () => console.log('Webhook server is listening, port 3000'));
to
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const verificationController = require('./controllers/verification');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/', verificationController);
app.listen(3000, () => console.log('Webhook server is listening, port 3000'));
and NewPageSubscription on FB seems to have succeeded
Creating a bot on Dialogflow…
Remindmebot
Client access token: ###
13:43
npm install apiai —- save
npm install request —- save
Stop for today - back to main job