0
const LaunchRequestHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
  },
  handle(handlerInput) {
      function getNameAndWelcome(callback) {
        request(amznProfileURL,function (error, response, body) {
          if (response.statusCode == 200) {
            var profile = JSON.parse(body);
            let name = profile.name.split(" ")[0];
            const speechText = `Welcome to the real estate skill ${name}, you can enquire about properties in various cities like Austin.`;
            Response = handlerInput.responseBuilder
            .speak(speechText)
            .reprompt(speechText)
            .withSimpleCard('Real Estate', speechText)
            .getResponse();
          }else{
            const speechText = `Welcome to the real estate skill, you can enquire about properties in various cities like Austin.`;
            Response = handlerInput.responseBuilder
            .speak(speechText)
            .reprompt(speechText)
            .withSimpleCard('Real Estate', speechText)
            .getResponse();
          }
          callback(Response);
        })
      }
      return getNameAndWelcome(function(res){
        return res;
      });
    }else{
      const speechText = 'Hi there! This skill requires account linking. Please follow the steps sent on the alexa application in your mobile.';

      return handlerInput.responseBuilder
      .speak(speechText)
      .reprompt(speechText)
      .withLinkAccountCard()
      .getResponse();
    } 
  }
};

This is a code snippet on which I have been banging my head all day long.I am trying to return the object in the variable "Response" to the "handle" function.I hope it is clear from the code what I have tried. Basically I am sending a callback which I hope will return the "Response" object to the function "getNameAndWelcome" and then I can return that again to the outer scope but as you can guess it does not work. Where am I making a mistake?Thanks.

This is the part where I register my handlers.

    exports.handler = async function (event, context) {
  if (!skill) {
    skill = Alexa.SkillBuilders.custom()
    .addRequestHandlers(
      LaunchRequestHandler,
      LocationIntentHandler,
      StatusIntentHandler,
      GeneralIntentHandler,
      QAIntentHandler,
      LowestPriceIntentHandler,
      HighestPriceIntentHandler,
      HelpIntentHandler,
      CancelAndStopIntentHandler,
      SessionEndedRequestHandler,
      )
    .addRequestInterceptors(AccessTokenInterceptor)
    .addErrorHandlers(ErrorHandler)
    .withSkillId(skillId)
    .create();
  }

  return skill.invoke(event,context);
}
RagingBull
  • 241
  • 1
  • 2
  • 10

0 Answers0