alexa-samples / skill-sample-nodejs-fact

Build An Alexa Fact Skill
Apache License 2.0
1.15k stars 1.19k forks source link

AMAZON.RepeatIntent #139

Closed glaze17 closed 1 year ago

glaze17 commented 4 years ago

I've been looking for two days and I am not able to find ANYTHING that outlines how to code the AMAZON.RepeatIntent in the fact skill :/ I know you have to add a session attribute, but I'm not sure where to that. I'm assuming somewhere in the GetNewFactHandler?

Is there anything else that needs to be done besides updating these two handlers? Anything with keeping the session open?

Thanks so much.

const GetNewFactHandler = { canHandle(handlerInput) { const request = handlerInput.requestEnvelope.request; return request.type === 'LaunchRequest' || (request.type === 'IntentRequest' && request.intent.name === 'GetNewFactIntent'); }, handle(handlerInput) { const requestAttributes = handlerInput.attributesManager.getRequestAttributes(); const randomFact = requestAttributes.t('FACTS'); const speakOutput = requestAttributes.t('GET_FACT_MESSAGE') + randomFact;

return handlerInput.responseBuilder
  .speak(speakOutput)
  // Uncomment the next line if you want to keep the session open so you can
  // ask for another fact without first re-opening the skill
  // .reprompt(requestAttributes.t('HELP_REPROMPT'))
  .withSimpleCard(requestAttributes.t('SKILL_NAME'), randomFact)
  .getResponse();

}, };

const RepeatIntentHandler = { canHandle(handlerInput) { return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' && Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.RepeatIntent'; }, handle(handlerInput) { const sessionAttributes = handlerInput.attributesManager.getSessionAttributes(); const { lastResponse } = sessionAttributes; const speakOutput = lastResponse;

return handlerInput.responseBuilder .speak(speakOutput) .reprompt(speakOutput) .getResponse(); } };

kweekhant commented 3 years ago

I've been looking for two days and I am not able to find ANYTHING that outlines how to code the AMAZON.RepeatIntent in the fact skill :/ I know you have to add a session attribute, but I'm not sure where to that. I'm assuming somewhere in the GetNewFactHandler?

Is there anything else that needs to be done besides updating these two handlers? Anything with keeping the session open?

Thanks so much.

const GetNewFactHandler = { canHandle(handlerInput) { const request = handlerInput.requestEnvelope.request; return request.type === 'LaunchRequest' || (request.type === 'IntentRequest' && request.intent.name === 'GetNewFactIntent'); }, handle(handlerInput) { const requestAttributes = handlerInput.attributesManager.getRequestAttributes(); const randomFact = requestAttributes.t('FACTS'); const speakOutput = requestAttributes.t('GET_FACT_MESSAGE') + randomFact;

return handlerInput.responseBuilder
  .speak(speakOutput)
  // Uncomment the next line if you want to keep the session open so you can
  // ask for another fact without first re-opening the skill
  // .reprompt(requestAttributes.t('HELP_REPROMPT'))
  .withSimpleCard(requestAttributes.t('SKILL_NAME'), randomFact)
  .getResponse();

}, };

const RepeatIntentHandler = { canHandle(handlerInput) { return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' && Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.RepeatIntent'; }, handle(handlerInput) { const sessionAttributes = handlerInput.attributesManager.getSessionAttributes(); const { lastResponse } = sessionAttributes; const speakOutput = lastResponse;

return handlerInput.responseBuilder .speak(speakOutput) .reprompt(speakOutput) .getResponse(); } };

kweekhant4545@gmail.com

aszk commented 1 year ago

Sorry for the late reply. Please refer documents below to see how to save sessionAttributes. There are some sample codes.