0

i am trying to call one http post api when user gives some raw input using actions sdk, but i get error "action isn’t responding right now. Try again soon" , my code is as follows

if (assistant.getRawInput() == 'test') { 
      request({
        url: url,
        json: true
      }, function (error, response, body) {
          if (error) {          
            assistant.tell('There is some error!');
          }
          else {         
             assistant.tell('we got the response!');
          }
        }
      )

there is no issue with the code as it works perfectly fine seperately using node command , i am new to google actions , please assist

Ether
  • 125
  • 1
  • 9

2 Answers2

0

How long is it taking to do the request? Actions need to complete within about 5 seconds, and if the URL you're calling takes a significant chunk of this time, the Action may time out.

Prisoner
  • 49,922
  • 7
  • 53
  • 105
  • the url responds within 1 second – Ether Feb 24 '17 at 05:34
  • And it is definitely invoking the request logic (and raw input is exactly 'test')? Could it be that there is no match on the raw input and some other part of your logic is not doing an assistant.ask or tell? – Leon Nicholls Feb 24 '17 at 16:43
0

I'm pretty sure its how you reference the assistant variable inside the callback handler for the request. Try to console log the assistant variable when the callback gets executed (you can see console logs in the google cloud logs for the function) you should see that its not defined. Try using the ES6 fat arrow syntax to have access to the assistant variable e.g.

if (assistant.getRawInput() == 'test') { 
      request({
        url: url,
        json: true
      }, (error, response, body) => {
          if (error) {          
            assistant.tell('There is some error!');
          }
          else {         
             assistant.tell('we got the response!');
          }
        }
      )
Ewert
  • 301
  • 3
  • 9