-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.ts
41 lines (35 loc) · 1.42 KB
/
bot.ts
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
39
40
41
import { DynamoDB } from 'aws-sdk'
import { Request } from 'claudia-api-builder'
import { Dialogue } from 'dialogue-builder'
import onboarding from './onboarding'
import builder = require('claudia-bot-builder')
import Message = builder.Message
export = builder(async (message: Message, apiRequest: Request) => {
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: Object) {
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) {
console.log(error);
console.log(error.stack);
return `${error} at ${error.stack}`;
}
}, { platforms: ["facebook"] })