-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdispatcher.js
109 lines (83 loc) · 3.55 KB
/
dispatcher.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Configuration
const SqueezeServer = require("squeezenode-lordpengwin");
const config = require("./config");
const Utils = require("./utils");
const IntentMap = require("./intents/intent-map");
class Dispatcher {
/**
* Called when the session starts.
*/
static onSessionStarted(sessionStartedRequest, session) {
"use strict";
console.log("Dispatcher.onSessionStarted requestId=" + sessionStartedRequest.requestId + ", sessionId=" + session.sessionId);
}
/**
* Called when the user launches the skill without specifying what they want. When this happens we go into a mode where
* they can issue multiple requests
*
* @param launchRequest The request
* @param session The current session
* @param callback A callback used to return the result
*/
static onLaunch(launchRequest, session, callback) {
"use strict";
console.log("Dispatcher.onLaunch requestId=" + launchRequest.requestId + ", sessionId=" + session.sessionId);
// Connect to the squeeze server and wait for it to finish its registration. We do this to make sure that it is online.
var squeezeserver = new SqueezeServer(config.squeezeserverURL, config.squeezeserverPort, config.squeezeServerUsername, config.squeezeServerPassword);
squeezeserver.on('register', function() {
console.log("SqueezeServer registered");
Dispatcher.startInteractiveSession(callback);
});
}
/**
* Called when the user specifies an intent for this skill.
*
* @param intentRequest The full request
* @param session The current session
* @param callback A callback used to return results
*/
static onIntent(intentRequest, session, callback) {
"use strict";
console.log("Dispatcher.onIntent requestId=" + intentRequest.requestId + ", sessionId=" + session.sessionId);
IntentMap.onIntent(intentRequest, session, callback);
}
/**
* Called when the user ends the session.
* Is not called when the skill returns shouldEndSession=true.
*/
static onSessionEnded(sessionEndedRequest, session) {
"use strict";
console.log("Dispatcher.onSessionEnded requestId=" + sessionEndedRequest.requestId + ", sessionId=" + session.sessionId);
}
/**
* This is called when the user activates the service without arguments
*
* @param callback A callback to execute to return the response
*/
static startInteractiveSession(callback) {
// If we wanted to initialize the session to have some attributes we could add those here.
"use strict";
console.log("in startInteractiveSession");
var sessionAttributes = {};
var cardTitle = "Control Started";
var speechOutput = "Squeezebox control started";
var shouldEndSession = false;
// Format the default response
callback(sessionAttributes, Utils.buildSpeechResponse(cardTitle, speechOutput, null, shouldEndSession));
}
/**
* Called to close an interactive session
*
* @param callback A callback to execute to return the response
*/
static closeInteractiveSession(callback) {
"use strict";
var sessionAttributes = {};
var cardTitle = "Control Ended";
var speechOutput = "Squeezebox control ended";
var shouldEndSession = true;
// Format the default response
callback(sessionAttributes, Utils.buildSpeechResponse(cardTitle, speechOutput, null, shouldEndSession));
}
}
module.exports = Dispatcher;