-
Notifications
You must be signed in to change notification settings - Fork 0
/
intentFunction.js
70 lines (54 loc) · 2.23 KB
/
intentFunction.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const Alexa = require('ask-sdk-core');
const helperMethod = require('../helpers/helper.js');
const { displayList } = require('../models/displayList.js');
const { repromptList } = require('../models/repromptList.js');
function canDoAPLFunction(handlerInput, intentName){
const intentData = helperMethod.search(intentName, displayList);
var responseBuilder = handlerInput.responseBuilder;
if(Alexa.getSupportedInterfaces(handlerInput.requestEnvelope)['Alexa.Presentation.APL'])
{
var responseBuilder = APLFunction(intentData, responseBuilder, intentName)
}
else
{
var responseBuilder = standardCardFunction(intentData, responseBuilder)
}
return handlerInput.responseBuilder;
};
function APLFunction(intentData, responseBuilder,intentName){
if(intentName != 'LAUNCH' && intentName != 'HELP')
{
APLDataSettings(intentData)
}
responseBuilder.addDirective({
type: 'Alexa.Presentation.APL.RenderDocument',
document: intentData.document,
datasources: intentData.datasources
});
return responseBuilder
};
function APLDataSettings(intentData){
intentData.datasources.detailImageRightData.image.sources[0].url = `${intentData.URL}`;
intentData.datasources.detailImageRightData.textContent.locationText.text = `${intentData.description}`;
intentData.datasources.detailImageRightData.textContent.primaryText.text = `${intentData.title}`;
};
function standardCardFunction(intentData, responseBuilder){
return responseBuilder
.withStandardCard(
`${intentData.title}`,
`${intentData.description}`,
`${intentData.URL}`,
`${intentData.URL}`)
.getResponse();
};
function speakOutputFunction(intentName){
const intentData = helperMethod.search(intentName, displayList);
var speakOutput = intentData.speakOutput
return speakOutput;
};
function repromptFunction(){
const repromptExist = repromptList[Math.floor(Math.random() * repromptList.length)];
const repromptText = repromptExist.description;
return repromptText;
};
module.exports = { canDoAPLFunction, APLFunction, standardCardFunction, speakOutputFunction, repromptFunction};