Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"dependencies": {
"bcrypt": "^1.0.3",
"browserify": "^14.5.0",
"cleverbot.io": "^1.0.4",
"csv-stringify": "2.0.0",
"envify": "^4.1.0",
"express": "4.16.2",
Expand All @@ -37,10 +38,10 @@
"grunt-contrib-sass": "1.0.0",
"grunt-contrib-uglify-es": "git://github.com/gruntjs/grunt-contrib-uglify.git#harmony",
"grunt-env": "^0.4.4",
"librelay": "3.4.0",
"jquery": "3.2.1",
"jsonwebtoken": "^8.1.0",
"jwt-decode": "^2.2.0",
"librelay": "3.4.2",
"lodash": "^4.17.4",
"morgan": "1.9.0",
"semantic-ui": "2.2.13",
Expand Down
38 changes: 27 additions & 11 deletions server/forsta_bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
const BotAtlasClient = require('./atlas_client');
const cache = require('./cache');
const relay = require('librelay');

const cleverbot = require("cleverbot.io");
const bot = new cleverbot(process.env.CBOT_API_USER,process.env.CBOT_API_KEY);

class ForstaBot {

Expand All @@ -26,9 +27,18 @@ class ForstaBot {

this.msgSender = await relay.MessageSender.factory();

this.bot = await bot.create(function (err, session){
err ? console.log("cleverbot error:", err) : console.info("bot session:", session);
return bot;
});

await this.msgReceiver.connect();

}




stop() {
if (this.msgReceiver) {
console.warn("Stopping message receiver");
Expand Down Expand Up @@ -65,19 +75,25 @@ class ForstaBot {
console.error("Received unsupported message:", msgEnvelope);
return;
}

const dist = await this.resolveTags(msg.distribution.expression);
const senderUser = (await this.getUsers([msg.sender.userId]))[0];

const reply = `Hello, ${senderUser.first_name}!`;

this.msgSender.send({
distribution: dist,
threadId: msg.threadId,
html: `${ reply }`,
text: reply
const query = msg.data.body[0].value;
bot.ask(query, (err, response) => {
if (!err) {
;
console.info("you:", query);
console.info("cleverbot:", response);
this.msgSender.send({
distribution: dist,
threadId: msg.threadId,
html: `${ response }`,
text: response
});
} else {
console.info("error:", err);
}
});

}
}

module.exports = ForstaBot;