-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.esnext.js
38 lines (33 loc) · 1.29 KB
/
bot.esnext.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
38
"use strict";
const builder = require("claudia-bot-builder");
const { DynamoDB } = require('aws-sdk');
const { Dialogue } = require('dialogue-builder');
const onboarding = require('./onboarding');
module.exports = builder((message, apiRequest) => {
try {
const dynamo = new DynamoDB.DocumentClient();
const storage = {
async retrieve() {
const user = await dynamo.get({
TableName: 'pointless-bot-users',
Key: { fbid: message.sender },
ConsistentRead: true
}).promise();
return user.Item && user.Item['state'];
},
async store(state) {
await dynamo.put({
TableName: 'pointless-bot-users',
Item: { fbid: message.sender, state: state }
}).promise();
}
};
const dialogue = new Dialogue(onboarding, storage, message.sender);
dialogue.setKeywordHandler(['back', 'undo'], 'undo');
dialogue.setKeywordHandler('reset', 'restart');
return dialogue.consume(message, apiRequest).catch(() => ['I have said all I have to say']);
}
catch (error) {
return `${error} at ${error.stack}`;
}
}, { platforms: ["facebook"] });