Skip to content

Instantly share code, notes, and snippets.

@bbezerra82
Forked from germanviscuso/index.js
Last active February 13, 2020 09:08
Show Gist options
  • Save bbezerra82/d7b0e83d0dc8d6206e028b0818aa1438 to your computer and use it in GitHub Desktop.
Save bbezerra82/d7b0e83d0dc8d6206e028b0818aa1438 to your computer and use it in GitHub Desktop.
Quick code to support an intent that plays long form audio in an Alexa skill
var stream = {
"token": "my_token", // no auth token, you decide what this is
"url": 'https://my_song.mp3',
"metadata" : {
"title": "My Song Title",
"subtitle": "My Song Subtitle",
"art": {
"sources": [
{
"contentDescription": "image",
"url": "https://my_song_image.png",
"widthPixels": 512,
"heightPixels": 512
}
]
},
"backgroundImage": {
"sources": [
{
"contentDescription": "example image",
"url": "https://my_song_background_image.gif",
"widthPixels": 1200,
"heightPixels": 800
}
]
}
}
};
const SongHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return (request.type === 'IntentRequest'
&& request.intent.name === 'SongIntent') ||
(request.type === 'IntentRequest'
&& request.intent.name === 'AMAZON.ResumeIntent');
},
handle(handlerInput) {
handlerInput.responseBuilder
//.speak(`starting ${stream.metadata.title}`)
.addAudioPlayerPlayDirective('REPLACE_ALL', stream.url, stream.token, 0, null, stream.metadata);
return handlerInput.responseBuilder.getResponse();
}
};
const AMAZON_StopPauseCancelIntent_Handler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && (
request.intent.name === 'AMAZON.PauseIntent' ||
request.intent.name === 'AMAZON.CancelIntent' ||
request.intent.name === 'AMAZON.StopIntent');
},
handle(handlerInput) {
return handlerInput.responseBuilder
.addAudioPlayerStopDirective()
.getResponse();
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment