canHandle(handlerInput) { // launch requests as well as any new session, as games are not saved in progress, which makes // no one shots a reasonable idea except for help, and the welcome message provides some help. return Alexa.isNewSession(handlerInput.requestEnvelope) || Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest'; }
function imageMaker(pDesc, pSource) { const myImage = new Alexa.ImageHelper() .withDescription(pDesc) .addImageInstance(pSource) .getImage(); return myImage; }
function plainTextMaker(pPrimaryText, pSecondaryText, pTertiaryText) { const myTextContent = new Alexa.PlainTextContentHelper() .withPrimaryText(pPrimaryText) .withSecondaryText(pSecondaryText) .withTertiaryText(pTertiaryText) .getTextContent(); return myTextContent; }
canHandle(handlerInput) { // only treat no as an exit when outside a game let isCurrentlyPlaying = false; const { attributesManager } = handlerInput; const sessionAttributes = attributesManager.getSessionAttributes(); if (sessionAttributes.gameState && sessionAttributes.gameState === 'STARTED') { isCurrentlyPlaying = true; } return !isCurrentlyPlaying && Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' && Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.NoIntent'; }
function richTextMaker(pPrimaryText, pSecondaryText, pTertiaryText) { const myTextContent = new Alexa.RichTextContentHelper(); if (pPrimaryText) myTextContent.withPrimaryText(pPrimaryText); if (pSecondaryText) myTextContent.withSecondaryText(pSecondaryText); if (pTertiaryText) myTextContent.withTertiaryText(pTertiaryText); return myTextContent.getTextContent(); }
canHandle(handlerInput) { // handle fallback intent, yes and no when playing a game // for yes and no, will only get here if and not caught by the normal intent handler return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' && (Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.FallbackIntent' || Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.YesIntent' || Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.NoIntent'); }
const sessionAttributes = attributesManager.getSessionAttributes(); const guessNum = parseInt(Alexa.getSlotValue(handlerInput.requestEnvelope, 'number'), 10); const targetNum = sessionAttributes.guessNumber;
process(handlerInput) { const localizationClient = i18n.use(sprintf).init({ lng: Alexa.getLocale(handlerInput.requestEnvelope), resources: languageStrings, }); localizationClient.localize = function localize() { const args = arguments; const values = []; for (let i = 1; i < args.length; i += 1) { values.push(args[i]); } const value = i18n.t(args[0], { returnObjects: true, postProcess: 'sprintf', sprintf: values, }); if (Array.isArray(value)) { return value[Math.floor(Math.random() * value.length)]; } return value; }; const attributes = handlerInput.attributesManager.getRequestAttributes(); attributes.t = function translate(...args) { return localizationClient.localize(...args); }; }
itemList.push({ "token": pArray[i].token, "textContent": new Alexa.PlainTextContentHelper().withPrimaryText(capitalizeFirstLetter(listItemNames[i])).getTextContent(), "image": imageMaker("", pArray[i].imageURL) });
canHandle(handlerInput) { return Alexa.getRequestType(handlerInput.requestEnvelope) === 'SessionEndedRequest'; }
canHandle(handlerInput) { return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' && Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.HelpIntent'; }
canHandle(handlerInput) { return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' && (Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.CancelIntent' || Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.StopIntent'); }
canHandle(handlerInput) { // only start a new game if yes is said when not playing a game. let isCurrentlyPlaying = false; const { attributesManager } = handlerInput; const sessionAttributes = attributesManager.getSessionAttributes(); if (sessionAttributes.gameState && sessionAttributes.gameState === 'STARTED') { isCurrentlyPlaying = true; } return !isCurrentlyPlaying && Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' && Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.YesIntent'; }
canHandle(handlerInput) { // handle numbers only during a game let isCurrentlyPlaying = false; const { attributesManager } = handlerInput; const sessionAttributes = attributesManager.getSessionAttributes(); if (sessionAttributes.gameState && sessionAttributes.gameState === 'STARTED') { isCurrentlyPlaying = true; } return isCurrentlyPlaying && Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' && Alexa.getIntentName(handlerInput.requestEnvelope) === 'NumberGuessIntent'; }