-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
37 lines (29 loc) · 931 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
const express = require('express'),
Intelligo = require('intelligo');
const app = express();
const bot = new Intelligo({
PAGE_ACCESS_TOKEN: 'PAGE_ACCESS_TOKEN',
VALIDATION_TOKEN: 'VALIDATION_TOKEN',
APP_SECRET: 'APP_SECRET',
app: app
});
bot.initWebhook();
//Train the neural network with an array of training data.
bot.learn([
{ input: 'I feel great about the world!', output: 'happy' },
{ input: 'The world is a terrible place!', output: 'sad' },
]);
//Subscribe to messages sent by the user with the bot.on() method.
bot.on('message', (event) => {
const senderID = event.sender.id,
message = event.message;
if (message.text) {
const result = bot.answer(message.text);
bot.sendTextMessage(senderID, result);
}
});
app.set('port', process.env.PORT || 5000);
app.listen(app.get('port'), function() {
console.log('Server is running on port', app.get('port'));
});