alexa-js / alexa-app

A framework for Alexa (Amazon Echo) apps using Node.js
https://www.youtube.com/watch?v=pzM4jv7k7Rg
MIT License
1.03k stars 212 forks source link

res.say doesn't work for intentRequest #283

Open relentless-coder opened 7 years ago

relentless-coder commented 7 years ago
app.intent('tfc', {
  'slots': {
    'phonenumber': 'AMAZON.NUMBER'
  },
  'utterances': ['{|my} {|contact number} {|phone number} {|number} {|is} {-|phonenumber}']
}, (req, res)=>{
  let number - req.slot('phonenumber');
  let login = new TfcLogin();
  login.sendOtp(number).then((data)=>{
    res.say('Enter the otp received on your phone').shouldEndSession(false);
  }).catch((error)=>{
    res.say(`${error.message}`).prompt('What is your registered contact number').shouldEndSession(false);
  })
})

This is a simple intent request, but it isn't working the way it should. TfcLogin is a class, and whole code is working fine, if there is an error it falls in the catch block, but res.say isn't working as expected. Here's the response that I received

{
  "version": "1.0",
  "response": {
    "directives": [],
    "shouldEndSession": true
  },
  "sessionAttributes": {},
  "dummy": "text"
}

What could be the reason for this?

dblock commented 7 years ago

You need to return a promise from this function, doesn't look like you're?

relentless-coder commented 7 years ago

Are you talking about the login.sendOtp(number) function call? If so, it is working fine, I am receiving response from the server.

dblock commented 7 years ago

No, you must return a Promise from the function. Try return login.sendOtp(number).... to begin with?

artifactdev commented 6 years ago

I have the same problem maybe:

https://github.com/artifactdev/alexa-fahrplan-dresden/blob/api-workaround/index.js#L92

if (resultObject !== undefined) { console.log(resultObject); response.say(resultObject[0]).send(); cardArray.push(JSON.stringify(resultObject[1])); return false; }

The resultObject[0] is a String and console.log() gives me the String but the response is always empty.

joshianuj commented 6 years ago

send in promise like this return(Promise.then((res)=> response.say(res.data.name).send())