Skip to content

Instantly share code, notes, and snippets.

@marcorei
Created April 11, 2018 07:51
Show Gist options
  • Save marcorei/1d2779d666075c1481f8d55f1eccd866 to your computer and use it in GitHub Desktop.
Save marcorei/1d2779d666075c1481f8d55f1eccd866 to your computer and use it in GitHub Desktop.
idea for states with default intent handlers
const defaultIntents = [
{
intentName: 'AMAZON.HelpIntent',
handler: yourFunctionPointer
},
// ... more Intents that are the same for each state.
]
const firstStateIntents = [
{
intentName: 'MySpecialIntentForThisState',
handler: yourFunctionPointer
},
// ... more Intents specific to this state.
]
const secondStateIntents = [
{
intentName: 'MySpecialIntentForThisOtherState',
handler: yourFunctionPointer
},
// ... more Intents specific to this state.
]
const states = [
{
stateName: 'constants.states.PLAY_MODE',
intents: firstStateIntents
},
{
stateName: 'someOtherState',
intents: secondStateIntents
}
]
alexa.registerHandlers.apply(alexa, states.map(
state =>
alexa.CreateStateHandler(state.stateName, state.intents
.concat(defaultIntents)
.reduce(
(map, intent) => {
map[intent.intentName] = intent.handler
return map
},
{}))
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment