0

I´m playing with the Alexa API. I want to have Alexa respond with content received from a service.

not sure where to add the promise. I tried with this but Alexa is saying "There was a problem with the requested skill's response"

const HelloWorldIntentHandler = {
    canHandle(handlerInput) {
        return handlerInput.requestEnvelope.request.type === 'IntentRequest'
            && handlerInput.requestEnvelope.request.intent.name === 'HelloWorldIntent';
    },
    handle(handlerInput) {

        MyService.facts().then(function(data) {

            const speechText = 'No facts';

            if (data) {
                speechText = 'random facts: '
                data.forEach(function (fact) {
                    speechText += fact;
                })
            }

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

        }, function(err) {
            console.log(err);
        });

    }
};
handsome
  • 2,335
  • 7
  • 45
  • 73

1 Answers1

1

Promise's response is not used. How about this example:

async handle(handlerInput) {
    return await MyService.facts().then(function(data) {
        // other stuff
    });
}
Kristianmitk
  • 4,528
  • 5
  • 26
  • 46