-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
36 lines (30 loc) · 983 Bytes
/
bot.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
'use strict';
var Dialog = require('dialog-api');
var sample = require('lodash.sample');
var botBuilder = require('claudia-bot-builder');
var dialog = new Dialog(process.env.DIALOG_API_TOKEN, process.env.DIALOG_BOT_ID);
var getIntentName = function(alexaPayload) {
return alexaPayload &&
alexaPayload.request &&
alexaPayload.request.type === 'IntentRequest' &&
alexaPayload.request.intent &&
alexaPayload.request.intent.name;
};
var api = botBuilder(function(message, originalRequest) {
if (message.text) {
return 'I think ' + message.text + ' is a ' + sample(['good old ', 'one hell of a ']) + sample(['pal', 'friend', 'bro']);
} else if (getIntentName(originalRequest.body) === 'ExitApp') {
return {
response: {
outputSpeech: {
type: 'PlainText',
text: 'Bye from Dialog Example!'
},
shouldEndSession: true
}
};
} else {
return {};
}
}, { platforms: ['alexa'] });
module.exports = api;