-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
188 lines (167 loc) · 5.68 KB
/
index.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
const Alexa = require('ask-sdk-core');
const STREAMS = [
{
token: '1',
url: 'https://dance-with-panda.de/stream/stream.pls',
metadata: {
title: 'Radio',
subtitle: 'Dance-With-Panda Stream',
art: {
sources: [
{
contentDescription: 'example image',
url: 'https://s3.amazonaws.com/cdn.dabblelab.com/img/audiostream-starter-512x512.png',
widthPixels: 512,
heightPixels: 512,
},
],
},
backgroundImage: {
sources: [
{
contentDescription: 'example image',
url: 'https://s3.amazonaws.com/cdn.dabblelab.com/img/wayfarer-on-beach-1200x800.png',
widthPixels: 1200,
heightPixels: 800,
},
],
},
},
},
];
const PlayStreamIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'LaunchRequest'
|| handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& (
handlerInput.requestEnvelope.request.intent.name === 'PlayStreamIntent'
|| handlerInput.requestEnvelope.request.intent.name === 'AMAZON.ResumeIntent'
|| handlerInput.requestEnvelope.request.intent.name === 'AMAZON.LoopOnIntent'
|| handlerInput.requestEnvelope.request.intent.name === 'AMAZON.NextIntent'
|| handlerInput.requestEnvelope.request.intent.name === 'AMAZON.PreviousIntent'
|| handlerInput.requestEnvelope.request.intent.name === 'AMAZON.RepeatIntent'
|| handlerInput.requestEnvelope.request.intent.name === 'AMAZON.ShuffleOnIntent'
|| handlerInput.requestEnvelope.request.intent.name === 'AMAZON.StartOverIntent'
);
},
handle(handlerInput) {
const stream = STREAMS[0];
handlerInput.responseBuilder
.speak(`Starte ${stream.metadata.title}`)
.addAudioPlayerPlayDirective('REPLACE_ALL', stream.url, stream.token, 0, null, stream.metadata);
return handlerInput.responseBuilder
.getResponse();
},
};
const HelpIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent';
},
handle(handlerInput) {
const speechText = '';
return handlerInput.responseBuilder
.speak(speechText)
.getResponse();
},
};
const AboutIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'AboutIntent';
},
handle(handlerInput) {
const speechText = '';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
},
};
const CancelAndStopIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& (
handlerInput.requestEnvelope.request.intent.name === 'AMAZON.StopIntent'
|| handlerInput.requestEnvelope.request.intent.name === 'AMAZON.PauseIntent'
|| handlerInput.requestEnvelope.request.intent.name === 'AMAZON.CancelIntent'
|| handlerInput.requestEnvelope.request.intent.name === 'AMAZON.LoopOffIntent'
|| handlerInput.requestEnvelope.request.intent.name === 'AMAZON.ShuffleOffIntent'
);
},
handle(handlerInput) {
handlerInput.responseBuilder
.addAudioPlayerClearQueueDirective('CLEAR_ALL')
.addAudioPlayerStopDirective();
return handlerInput.responseBuilder
.getResponse();
},
};
const PlaybackStoppedIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'PlaybackController.PauseCommandIssued'
|| handlerInput.requestEnvelope.request.type === 'AudioPlayer.PlaybackStopped';
},
handle(handlerInput) {
handlerInput.responseBuilder
.addAudioPlayerClearQueueDirective('CLEAR_ALL')
.addAudioPlayerStopDirective();
return handlerInput.responseBuilder
.getResponse();
},
};
const PlaybackStartedIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'AudioPlayer.PlaybackStarted';
},
handle(handlerInput) {
handlerInput.responseBuilder
.addAudioPlayerClearQueueDirective('CLEAR_ENQUEUED');
return handlerInput.responseBuilder
.getResponse();
},
};
const SessionEndedRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
},
handle(handlerInput) {
console.log(`Session ended with reason: ${handlerInput.requestEnvelope.request.reason}`);
return handlerInput.responseBuilder
.getResponse();
},
};
const ExceptionEncounteredRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'System.ExceptionEncountered';
},
handle(handlerInput) {
console.log(`Session ended with reason: ${handlerInput.requestEnvelope.request.reason}`);
return true;
},
};
const ErrorHandler = {
canHandle() {
return true;
},
handle(handlerInput, error) {
console.log(`Error handled: ${error.message}`);
console.log(handlerInput.requestEnvelope.request.type);
return handlerInput.responseBuilder
.getResponse();
},
};
const skillBuilder = Alexa.SkillBuilders.custom();
exports.handler = skillBuilder
.addRequestHandlers(
PlayStreamIntentHandler,
PlaybackStartedIntentHandler,
CancelAndStopIntentHandler,
PlaybackStoppedIntentHandler,
AboutIntentHandler,
HelpIntentHandler,
ExceptionEncounteredRequestHandler,
SessionEndedRequestHandler,
)
.addErrorHandlers(ErrorHandler)
.lambda();