alexa-app icon indicating copy to clipboard operation
alexa-app copied to clipboard

res.say doesn't work for intentRequest

Open relentless-coder opened this issue 8 years ago • 5 comments

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?

relentless-coder avatar Sep 13 '17 11:09 relentless-coder

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

dblock avatar Sep 13 '17 16:09 dblock

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

relentless-coder avatar Sep 13 '17 16:09 relentless-coder

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

dblock avatar Sep 13 '17 17:09 dblock

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.

artifactdev avatar Sep 26 '17 22:09 artifactdev

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

joshianuj avatar Dec 06 '17 12:12 joshianuj