Created
April 11, 2018 07:51
-
-
Save marcorei/1d2779d666075c1481f8d55f1eccd866 to your computer and use it in GitHub Desktop.
idea for states with default intent handlers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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