@@ -17,10 +17,10 @@ var app = new alexa.app('connect');
17
17
app . express ( { expressApp : express_app } ) ;
18
18
19
19
const successSound = "<audio src='soundbank://soundlibrary/ui/gameshow/amzn_ui_sfx_gameshow_neutral_response_02'/>" ;
20
- const connectDeviceCard = ( res ) => ( {
20
+ const connectDeviceCard = ( context ) => ( {
21
21
type : "Simple" ,
22
- title : res . __ ( "Connecting to a device using Spotify Connect" ) ,
23
- content : res . __ ( "To add a device to Spotify Connect,"
22
+ title : context . __ ( "Connecting to a device using Spotify Connect" ) ,
23
+ content : context . __ ( "To add a device to Spotify Connect,"
24
24
+ " log in to your Spotify account on a supported device"
25
25
+ " such as an Echo, phone, or computer"
26
26
+ "\nhttps://support.spotify.com/uk/article/spotify-connect/" )
@@ -32,11 +32,11 @@ app.pre = function (req, res, _type) {
32
32
i18n . configure ( {
33
33
directory : __dirname + '/locales' ,
34
34
defaultLocale : 'en-GB' ,
35
- register : res ,
35
+ register : req . context ,
36
36
} ) ;
37
37
38
38
if ( req . data . request . locale ) {
39
- res . setLocale ( req . data . request . locale ) ;
39
+ req . context . setLocale ( req . data . request . locale ) ;
40
40
}
41
41
// Error if the application ID of the request is not for this skill
42
42
if ( req . applicationId != applicationId &&
@@ -45,22 +45,22 @@ app.pre = function (req, res, _type) {
45
45
}
46
46
// Check that the user has an access token, if they have linked their account
47
47
if ( ! ( req . context . System . user . accessToken || req . getSession ( ) . details . user . accessToken ) ) {
48
- res . say ( res . __ ( "You have not linked your Spotify account, check your Alexa app to link the account" ) ) ;
48
+ res . say ( req . context . __ ( "You have not linked your Spotify account, check your Alexa app to link the account" ) ) ;
49
49
res . linkAccount ( ) ;
50
50
}
51
51
} ;
52
52
53
53
// Run after every request
54
54
app . post = function ( req , res , _type , exception ) {
55
55
if ( exception ) {
56
- return res . clear ( ) . say ( res . __ ( "An error occured: " ) + exception ) . send ( ) ;
56
+ return res . clear ( ) . say ( req . context . __ ( "An error occured: " ) + exception ) . send ( ) ;
57
57
}
58
58
} ;
59
59
60
60
// Function for when skill is invoked without intent
61
61
app . launch ( function ( req , res ) {
62
- res . say ( res . __ ( "I can control your Spotify Connect devices, to start, ask me to list your devices" ) )
63
- . reprompt ( res . __ ( "To start, ask me to list your devices" ) ) ;
62
+ res . say ( req . context . __ ( "I can control your Spotify Connect devices, to start, ask me to list your devices" ) )
63
+ . reprompt ( req . context . __ ( "To start, ask me to list your devices" ) ) ;
64
64
// Keep session open
65
65
res . shouldEndSession ( false ) ;
66
66
} ) ;
@@ -71,9 +71,9 @@ app.intent("AMAZON.HelpIntent", {
71
71
"slots" : { } ,
72
72
"utterances" : [ ]
73
73
} , function ( req , res ) {
74
- res . say ( res . __ ( "You can ask me to list your connect devices and then control them. " ) )
75
- . say ( res . __ ( "For example, tell me to play on a device after listing devices" ) )
76
- . reprompt ( res . __ ( "What would you like to do?" ) ) ;
74
+ res . say ( req . context . __ ( "You can ask me to list your connect devices and then control them. " ) )
75
+ . say ( req . context . __ ( "For example, tell me to play on a device after listing devices" ) )
76
+ . reprompt ( req . context . __ ( "What would you like to do?" ) ) ;
77
77
// Keep session open
78
78
res . shouldEndSession ( false ) ;
79
79
} ) ;
@@ -112,10 +112,10 @@ app.intent('PlayIntent', {
112
112
req . getSession ( ) . set ( "statusCode" , r . statusCode ) ;
113
113
res . say ( successSound ) ;
114
114
} ) . catch ( ( err ) => {
115
- if ( err . statusCode === 403 ) res . say ( res . __ ( "Make sure your Spotify account is premium" ) ) ;
115
+ if ( err . statusCode === 403 ) res . say ( req . context . __ ( "Make sure your Spotify account is premium" ) ) ;
116
116
if ( err . statusCode === 404 ) {
117
- res . say ( res . __ ( "I couldn't find any connect devices, check your Alexa app for information on connecting a device" ) ) ;
118
- res . card ( connectDeviceCard ( res ) ) ;
117
+ res . say ( req . context . __ ( "I couldn't find any connect devices, check your Alexa app for information on connecting a device" ) ) ;
118
+ res . card ( connectDeviceCard ( req . context ) ) ;
119
119
}
120
120
} ) ;
121
121
}
@@ -135,10 +135,10 @@ app.intent('PauseIntent', {
135
135
req . getSession ( ) . set ( "statusCode" , r . statusCode ) ;
136
136
res . say ( successSound ) ;
137
137
} ) . catch ( ( err ) => {
138
- if ( err . statusCode === 403 ) res . say ( res . __ ( "Make sure your Spotify account is premium" ) ) ;
138
+ if ( err . statusCode === 403 ) res . say ( req . context . __ ( "Make sure your Spotify account is premium" ) ) ;
139
139
if ( err . statusCode === 404 ) {
140
- res . say ( res . __ ( "I couldn't find any connect devices, check your Alexa app for information on connecting a device" ) ) ;
141
- res . card ( connectDeviceCard ( res ) ) ;
140
+ res . say ( req . context . __ ( "I couldn't find any connect devices, check your Alexa app for information on connecting a device" ) ) ;
141
+ res . card ( connectDeviceCard ( req ) ) ;
142
142
}
143
143
} ) ;
144
144
}
@@ -160,9 +160,9 @@ app.intent('SkipNextIntent', {
160
160
req . getSession ( ) . set ( "statusCode" , r . statusCode ) ;
161
161
res . say ( successSound ) ;
162
162
} ) . catch ( ( err ) => {
163
- if ( err . statusCode === 403 ) res . say ( res . __ ( "Make sure your Spotify account is premium" ) ) ;
163
+ if ( err . statusCode === 403 ) res . say ( req . context . __ ( "Make sure your Spotify account is premium" ) ) ;
164
164
if ( err . statusCode === 404 ) {
165
- res . say ( res . __ ( "I couldn't find any connect devices, check your Alexa app for information on connecting a device" ) ) ;
165
+ res . say ( req . context . __ ( "I couldn't find any connect devices, check your Alexa app for information on connecting a device" ) ) ;
166
166
res . card ( connectDeviceCard ( res ) ) ;
167
167
}
168
168
} ) ;
@@ -186,9 +186,9 @@ app.intent('SkipPreviousIntent', {
186
186
req . getSession ( ) . set ( "statusCode" , r . statusCode ) ;
187
187
res . say ( successSound ) ;
188
188
} ) . catch ( ( err ) => {
189
- if ( err . statusCode === 403 ) res . say ( res . __ ( "Make sure your Spotify account is premium" ) ) ;
189
+ if ( err . statusCode === 403 ) res . say ( req . context . __ ( "Make sure your Spotify account is premium" ) ) ;
190
190
if ( err . statusCode === 404 ) {
191
- res . say ( res . __ ( "I couldn't find any connect devices, check your Alexa app for information on connecting a device" ) ) ;
191
+ res . say ( req . context . __ ( "I couldn't find any connect devices, check your Alexa app for information on connecting a device" ) ) ;
192
192
res . card ( connectDeviceCard ( res ) ) ;
193
193
}
194
194
} ) ;
@@ -207,9 +207,9 @@ const setVolume = (volumePercent, req, res) => {
207
207
// Handle sending as JSON
208
208
json : true
209
209
} ) . catch ( ( err ) => {
210
- if ( err . statusCode === 403 ) res . say ( res . __ ( "Make sure your Spotify account is premium" ) ) ;
210
+ if ( err . statusCode === 403 ) res . say ( req . context . __ ( "Make sure your Spotify account is premium" ) ) ;
211
211
if ( err . statusCode === 404 ) {
212
- res . say ( res . __ ( "I couldn't find any connect devices, check your Alexa app for information on connecting a device" ) ) ;
212
+ res . say ( req . context . __ ( "I couldn't find any connect devices, check your Alexa app for information on connecting a device" ) ) ;
213
213
res . card ( connectDeviceCard ( res ) ) ;
214
214
}
215
215
} ) ;
@@ -228,7 +228,7 @@ const getAndValidateVolumePercentFromSlot = (req, res, isPercentIntent) => {
228
228
}
229
229
else {
230
230
// If not valid volume
231
- res . say ( res . __ ( isPercentIntent
231
+ res . say ( req . context . __ ( isPercentIntent
232
232
? "You can only set the volume percent between 0 and 100"
233
233
: "You can only set the volume between 0 and 10" ) ) ;
234
234
// Keep session open
@@ -238,22 +238,22 @@ const getAndValidateVolumePercentFromSlot = (req, res, isPercentIntent) => {
238
238
}
239
239
else {
240
240
// Not a number
241
- res . say ( res . __ ( isPercentIntent
241
+ res . say ( req . context . __ ( isPercentIntent
242
242
? "Try setting a volume percent between 0 and 100"
243
243
: "Try setting a volume between 0 and 10" ) )
244
- . reprompt ( res . __ ( "What would you like to do?" ) ) ;
244
+ . reprompt ( req . context . __ ( "What would you like to do?" ) ) ;
245
245
// Keep session open
246
246
res . shouldEndSession ( false ) ;
247
247
return null ;
248
248
}
249
249
}
250
250
else {
251
251
// No slot value
252
- res . say ( res . __ ( "I couldn't work out the volume to use." ) )
253
- . say ( res . __ ( isPercentIntent
252
+ res . say ( req . context . __ ( "I couldn't work out the volume to use." ) )
253
+ . say ( req . context . __ ( isPercentIntent
254
254
? "Try setting a volume percent between 0 and 100"
255
255
: "Try setting a volume between 0 and 10" ) )
256
- . reprompt ( res . __ ( "What would you like to do?" ) ) ;
256
+ . reprompt ( req . context . __ ( "What would you like to do?" ) ) ;
257
257
// Keep session open
258
258
res . shouldEndSession ( false ) ;
259
259
return null ;
@@ -320,15 +320,15 @@ app.intent('GetDevicesIntent', {
320
320
// Check if user has devices
321
321
if ( devices . length > 0 ) {
322
322
// Comma separated list of device names
323
- res . say ( res . __ ( "I found these connect devices: " ) )
324
- . say ( [ deviceNames . slice ( 0 , - 1 ) . join ( ', ' ) , deviceNames . slice ( - 1 ) [ 0 ] ] . join ( deviceNames . length < 2 ? '' : ',' + res . __ ( ' and ' ) ) + ". " )
325
- . say ( res . __ ( "What would you like to do with these devices?" ) ) . reprompt ( res . __ ( "What would you like to do?" ) ) ;
323
+ res . say ( req . context . __ ( "I found these connect devices: " ) )
324
+ . say ( [ deviceNames . slice ( 0 , - 1 ) . join ( ', ' ) , deviceNames . slice ( - 1 ) [ 0 ] ] . join ( deviceNames . length < 2 ? '' : ',' + req . context . __ ( ' and ' ) ) + ". " )
325
+ . say ( req . context . __ ( "What would you like to do with these devices?" ) ) . reprompt ( req . context . __ ( "What would you like to do?" ) ) ;
326
326
// Keep session open
327
327
res . shouldEndSession ( false ) ;
328
328
}
329
329
else {
330
330
// No devices found
331
- res . say ( res . __ ( "I couldn't find any connect devices, check your Alexa app for information on connecting a device" ) ) ;
331
+ res . say ( req . context . __ ( "I couldn't find any connect devices, check your Alexa app for information on connecting a device" ) ) ;
332
332
res . card ( connectDeviceCard ( res ) ) ;
333
333
}
334
334
} )
@@ -376,29 +376,29 @@ app.intent('DevicePlayIntent', {
376
376
// Handle sending as JSON
377
377
json : true
378
378
} ) . then ( ( _r ) => {
379
- res . say ( res . __ ( "Playing on device {{deviceName}}" , { deviceName : device . name } ) ) ;
379
+ res . say ( req . context . __ ( "Playing on device {{deviceName}}" , { deviceName : device . name } ) ) ;
380
380
} ) . catch ( ( err ) => {
381
- if ( err . statusCode === 403 ) res . say ( res . __ ( "Make sure your Spotify account is premium" ) ) ;
381
+ if ( err . statusCode === 403 ) res . say ( req . context . __ ( "Make sure your Spotify account is premium" ) ) ;
382
382
if ( err . statusCode === 404 ) {
383
- res . say ( res . __ ( "I couldn't find any connect devices, check your Alexa app for information on connecting a device" ) ) ;
383
+ res . say ( req . context . __ ( "I couldn't find any connect devices, check your Alexa app for information on connecting a device" ) ) ;
384
384
res . card ( connectDeviceCard ( res ) ) ;
385
385
}
386
386
} ) ;
387
387
}
388
388
else {
389
389
// If device not found
390
- res . say ( res . __ ( "I couldn't find a device named {{DEVICE}}." , { DEVICE } ) )
391
- . say ( res . __ ( "Try asking me to list devices first" ) ) ;
390
+ res . say ( req . context . __ ( "I couldn't find a device named {{DEVICE}}." , { DEVICE } ) )
391
+ . say ( req . context . __ ( "Try asking me to list devices first" ) ) ;
392
392
// Keep session open
393
393
res . shouldEndSession ( false ) ;
394
394
}
395
395
} ) ;
396
396
}
397
397
else {
398
398
// No slot value
399
- res . say ( res . __ ( "I couldn't work out which device to play on." ) )
400
- . say ( res . __ ( "Try asking me to list devices first" ) )
401
- . reprompt ( res . __ ( "What would you like to do?" ) ) ;
399
+ res . say ( req . context . __ ( "I couldn't work out which device to play on." ) )
400
+ . say ( req . context . __ ( "Try asking me to list devices first" ) )
401
+ . reprompt ( req . context . __ ( "What would you like to do?" ) ) ;
402
402
// Keep session open
403
403
res . shouldEndSession ( false ) ;
404
404
}
@@ -429,8 +429,8 @@ app.intent(
429
429
if ( ! req . slot ( "TRACKNAME" ) ) {
430
430
// No slot value
431
431
res
432
- . say ( res . __ ( "I couldn't work out which song you want to queue." ) )
433
- . reprompt ( res . __ ( "What would you like to do?" ) ) ;
432
+ . say ( req . context . __ ( "I couldn't work out which song you want to queue." ) )
433
+ . reprompt ( req . context . __ ( "What would you like to do?" ) ) ;
434
434
// Keep session open
435
435
res . shouldEndSession ( false ) ;
436
436
}
@@ -473,21 +473,21 @@ app.intent(
473
473
} )
474
474
. then ( ( response ) => {
475
475
res . say (
476
- res . __ ( "Queued track {{trackName}}" , {
476
+ req . context . __ ( "Queued track {{trackName}}" , {
477
477
trackName,
478
478
} )
479
479
) ;
480
480
} )
481
481
. catch ( ( err ) => {
482
482
res
483
- . say ( res . __ ( "Sorry, I couldn't queue that song." ) )
484
- . reprompt ( res . __ ( "What would you like to do?" ) ) ;
483
+ . say ( req . context . __ ( "Sorry, I couldn't queue that song." ) )
484
+ . reprompt ( req . context . __ ( "What would you like to do?" ) ) ;
485
485
} ) ;
486
486
} )
487
487
. catch ( ( err ) => {
488
488
res
489
- . say ( res . __ ( "Sorry, I couldn't queue that song." ) )
490
- . reprompt ( res . __ ( "What would you like to do?" ) ) ;
489
+ . say ( req . context . __ ( "Sorry, I couldn't queue that song." ) )
490
+ . reprompt ( req . context . __ ( "What would you like to do?" ) ) ;
491
491
} ) ;
492
492
}
493
493
) ;
@@ -527,29 +527,29 @@ app.intent('DeviceTransferIntent', {
527
527
// Handle sending as JSON
528
528
json : true
529
529
} ) . then ( ( _r ) => {
530
- res . say ( res . __ ( "Transferring to {{deviceName}}" , { deviceName : device . name } ) ) ;
530
+ res . say ( req . context . __ ( "Transferring to {{deviceName}}" , { deviceName : device . name } ) ) ;
531
531
} ) . catch ( ( err ) => {
532
- if ( err . statusCode === 403 ) res . say ( res . __ ( "Make sure your Spotify account is premium" ) ) ;
532
+ if ( err . statusCode === 403 ) res . say ( req . context . __ ( "Make sure your Spotify account is premium" ) ) ;
533
533
if ( err . statusCode === 404 ) {
534
- res . say ( res . __ ( "I couldn't find any connect devices, check your Alexa app for information on connecting a device" ) ) ;
534
+ res . say ( req . context . __ ( "I couldn't find any connect devices, check your Alexa app for information on connecting a device" ) ) ;
535
535
res . card ( connectDeviceCard ( res ) ) ;
536
536
}
537
537
} ) ;
538
538
}
539
539
else {
540
540
// If device not found
541
- res . say ( res . __ ( "I couldn't find a device named {{DEVICE}}." , { DEVICE } ) )
542
- . say ( res . __ ( "Try asking me to list devices first" ) ) ;
541
+ res . say ( req . context . __ ( "I couldn't find a device named {{DEVICE}}." , { DEVICE } ) )
542
+ . say ( req . context . __ ( "Try asking me to list devices first" ) ) ;
543
543
// Keep session open
544
544
res . shouldEndSession ( false ) ;
545
545
}
546
546
} ) ;
547
547
}
548
548
else {
549
549
// No slot value
550
- res . say ( res . __ ( "I couldn't work out which device to transfer to." ) )
551
- . say ( res . __ ( "Try asking me to list devices first" ) )
552
- . reprompt ( res . __ ( "What would you like to do?" ) ) ;
550
+ res . say ( req . context . __ ( "I couldn't work out which device to transfer to." ) )
551
+ . say ( req . context . __ ( "Try asking me to list devices first" ) )
552
+ . reprompt ( req . context . __ ( "What would you like to do?" ) ) ;
553
553
// Keep session open
554
554
res . shouldEndSession ( false ) ;
555
555
}
@@ -578,16 +578,16 @@ app.intent('GetTrackIntent', {
578
578
} )
579
579
. then ( function ( body ) {
580
580
if ( body . is_playing ) {
581
- res . say ( res . __ ( "This is {{name}} by {{artist}}" , { name : body . item . name , artist : body . item . artists [ 0 ] . name } ) ) ;
581
+ res . say ( req . context . __ ( "This is {{name}} by {{artist}}" , { name : body . item . name , artist : body . item . artists [ 0 ] . name } ) ) ;
582
582
}
583
583
else {
584
584
if ( body . item . name ) {
585
585
// If not playing but last track known
586
- res . say ( res . __ ( "That was {{name}} by {{artist}}" , { name : body . item . name , artist : body . item . artists [ 0 ] . name } ) ) ;
586
+ res . say ( req . context . __ ( "That was {{name}} by {{artist}}" , { name : body . item . name , artist : body . item . artists [ 0 ] . name } ) ) ;
587
587
}
588
588
else {
589
589
// If unknown
590
- res . say ( res . __ ( "Nothing is playing" ) ) ;
590
+ res . say ( req . context . __ ( "Nothing is playing" ) ) ;
591
591
}
592
592
}
593
593
} )
0 commit comments