Skip to content

Instantly share code, notes, and snippets.

@arunjeetsingh
Last active September 2, 2020 02:47
Show Gist options
  • Save arunjeetsingh/70e001c8b27946f76c6412bc3c2c89c0 to your computer and use it in GitHub Desktop.
Save arunjeetsingh/70e001c8b27946f76c6412bc3c2c89c0 to your computer and use it in GitHub Desktop.
This gist consists of 3 skill responses that together show how to use the new APL back stack extension with a voice command. Page1.json shows a response that renders the first page of the interaction. Note that we load the back extension and set a backstackId on Page1 so it is added to the back stack. When a customer speaks an utterance (say "go…
//When a customer says "go back" or something similar next a skill
//can respond with GoBack.json to navigate back on the back stack.
//Note that the "token" value for the GoBack response's ExecuteCommands
//directive and the token value for the APL document currently
//rendered (Page2.json) must be the same. This is how Alexa knows where
//to direct the commands.
{
"outputSpeech": {
"type": "SSML",
"ssml": "<speak>Going back!</speak>"
},
"directives": [{
"type": "Alexa.Presentation.APL.ExecuteCommands",
"token": "MySkill",
"commands": [{
"type": "Back:GoBack"
}]
}]
}
//Page1.json shows a response that renders the first page of the interaction.
//Note that we load the back extension and set a backstackId on Page1 so it
//is added to the back stack.
{
"outputSpeech": {
"type": "SSML",
"ssml": "<speak>Page 1</speak>"
},
"directives": [
{
"type": "Alexa.Presentation.APL.RenderDocument",
"token": "MySkill",
"document": {
"type": "APL",
"version": "1.4",
"extensions": [
{
"name": "Back",
"uri": "aplext:backstack:10"
}
],
"settings": {
"Back": {
"backstackId": "Page1"
}
},
"mainTemplate": {
"items": [
{
"type": "Container",
"height": "100%",
"width": "100%",
"items": [
{
"type": "Text",
"text": "Page 1"
},
{
"type": "AlexaButton",
"buttonText": "Go Back",
"id": "containedButtonId",
"paddingLeft": "@spacingLarge",
"paddingRight": "@spacingLarge",
"paddingBottom": "@spacingLarge",
"paddingTop": "@spacingLarge",
"primaryAction": {
"type": "Back:GoBack"
}
},
{
"type": "Container",
"bind": {
"name": "Responsible",
"value": "${environment.extension.Back.responsibleForBackButton}"
},
"firstItem": {
"type": "Text",
"text": "There are ${environment.extension.Back.backstack.length} items on the back stack"
},
"data": "${environment.extension.Back.backstack}",
"items": {
"type": "Text",
"text": "Backstack ${index}: '${data}'"
},
"lastItem": {
"type": "Text",
"text": "The back button ${Responsible ? 'should' : 'should not'} to be drawn"
}
}
]
}
]
}
},
"datasources": {}
}
]
}
//When a customer speaks an utterance (say "go to page 2") a skill would
//respond with Page2.json. This document again loads the back stack extension
//and adds itself to the back stack. Now we have 2 APL documents in the back stack.
{
"outputSpeech": {
"type": "SSML",
"ssml": "<speak>Page 2</speak>"
},
"directives": [
{
"type": "Alexa.Presentation.APL.RenderDocument",
"token": "MySkill",
"document": {
"type": "APL",
"version": "1.4",
"extensions": [
{
"name": "Back",
"uri": "aplext:backstack:10"
}
],
"settings": {
"Back": {
"backstackId": "Page2"
}
},
"mainTemplate": {
"items": [
{
"type": "Container",
"height": "100%",
"width": "100%",
"items": [
{
"type": "Text",
"text": "Page 2"
},
{
"type": "AlexaButton",
"buttonText": "Go Back",
"id": "containedButtonId",
"paddingLeft": "@spacingLarge",
"paddingRight": "@spacingLarge",
"paddingBottom": "@spacingLarge",
"paddingTop": "@spacingLarge",
"primaryAction": {
"type": "Back:GoBack"
}
},
{
"type": "Container",
"bind": {
"name": "Responsible",
"value": "${environment.extension.Back.responsibleForBackButton}"
},
"firstItem": {
"type": "Text",
"text": "There are ${environment.extension.Back.backstack.length} items on the back stack"
},
"data": "${environment.extension.Back.backstack}",
"items": {
"type": "Text",
"text": "Backstack ${index}: '${data}'"
},
"lastItem": {
"type": "Text",
"text": "The back button ${Responsible ? 'should' : 'should not'} to be drawn"
}
}
]
}
]
}
},
"datasources": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment