Ajit kohir
Ajit kohir

Reputation: 481

Alexa Skill response is showing nothing when doing in setTimeout

Stuck from day. Problem is like this.

var alexa = require('alexa-app');

// Define an alexa-app
var myapp = new alexa.app('myapp');

myapp.intent('WelcomeIntent', function(request,response) {
    console.log(request);
    response.say("This  is not working.<break time='2s'/>")
    setTimeout(function(){
            response.say("This  is inside timeout.")
    },1000);
});

On the Speech Simulator Amazon Alexa the output look like this.

{
  "version": "1.0",
  "response": {
    "outputSpeech": {
      "type": "SSML",
      "ssml": "<speak>This is not working.<break time='2s'/></speak>"
    },
    "shouldEndSession": false
  },
  "sessionAttributes": {}
}

Please help me out. Problem is the response inside the asynchronous function like Promise or setTimeout or fetch or google map API I am not getting the proper response.

Upvotes: 0

Views: 451

Answers (1)

Ajit kohir
Ajit kohir

Reputation: 481

So finally I figure out the solution.

To handle async callback in the alexa-app framework there are two way.

Using version below 4.0.0

var alexa = require('alexa-app');

// Define an alexa-app
var myapp = new alexa.app('myapp');

myapp.intent('WelcomeIntent', function(request,response) {
    console.log(request);
    makePromiseBasedCallback(request,response);
    return false;
});
makePromiseBasedCallback.then(function(data){
    response.say(data.cardContent);
    response.send();
});

Using version 4.0.0

follow the github link

Upvotes: 1

Related Questions