-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse.js
49 lines (39 loc) · 1.49 KB
/
parse.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
39
40
41
42
43
44
45
46
47
48
49
'use strict';
const
sha1 = require('sha1'),
mongoose = require('mongoose');
function getSlotValues(slots) {
if (!slots) return '';
return Object.keys(slots).map(key => slots[key].value || '').join(' ');
}
module.exports = function alexaParse(messageObject) {
if (messageObject && messageObject.session && messageObject.session.user && messageObject.session.application &&
messageObject.session.user.userId && messageObject.request.type) {
var textMsg = '';
var requestTypeModification = null;
if (messageObject.request.intent && messageObject.request.intent.name) {
if (messageObject.request.intent.name == 'AMAZON.StopIntent')
requestTypeModification = 'StopRequest';
if (messageObject.request.intent.slots)
textMsg = getSlotValues(messageObject.request.intent.slots) || '';
}
return {
sender: sha1(messageObject.session.user.userId),
applicationId: messageObject.session.application.applicationId,
requestType: requestTypeModification ? requestTypeModification : messageObject.request.type, // LaunchRequest,IntentRequest,StopRequest;
msg: textMsg,
sessionId: messageObject.session.sessionId,
originalRequest: messageObject,
type: 'alexa-skill'
};
} else {
// Defective or faulty packer received
return {
sender: messageObject.session.user.userId || '',
requestType: "DEFECTIVEOBJECT",
text: '',
originalRequest: messageObject,
type: 'alexa-skill'
};
}
};