IntentHandlers
Hidetaka Okamoto edited this page Jun 10, 2018
·
1 revision
Check is display interface supports.
Ref: https://developer.amazon.com/ja/blogs/alexa/post/6839eb1c-f718-41cd-ad0c-6ba59c5360f5/alexa-skill-recipe-making-the-most-of-devices-that-support-display
const { supportsDisplay } = handlerInput
/* NewsIntent handler without display */
const NewsNoDisplayIntentHandler = {
canHandle (handlerInput) {
if (!intentHandlers.canHandle(handlerInput, 'IntentRequest', 'NewsIntent')) return false
if (supportsDisplay(handlerInput)) return false
return true
},
handle (handlerInput) {
const speechText = 'This is example skill'
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.withSimpleCard(SKILL_NAME, speechText)
.getResponse()
}
}
/* NewsIntent handler with display */
const NewsWithDisplayIntentHandler = {
canHandle (handlerInput) {
if (!intentHandlers.canHandle(handlerInput, 'IntentRequest', 'NewsIntent')) return false
if (!supportsDisplay(handlerInput)) return false
return true
},
handle (handlerInput) {
const myImage = new Alexa.ImageHelper()
.withDescription('FooDescription')
.addImageInstance('http://BarImageSource')
.getImage()
const myTextContent = new Alexa.PlainTextContentHelper()
.withPrimaryText('Foo')
.withSecondaryText('Bar')
.withTertiaryText('Baz')
.getTextContent()
const myTextContent = new Alexa.RichTextContentHelper()
.withPrimaryText('Foo')
.withSecondaryText('Bar')
.withTertiaryText('Baz')
.getTextContent()
return handlerInput.responseBuilder
.speak('hello')
.addRenderTemplateDirective({
type: 'BodyTemplate1',
backButton: 'VISIBLE',
backgroundImage: backgroundImage,
title: title,
textContent: textContent,
token : "token",
})
.getResponse()
}
}