wit icon indicating copy to clipboard operation
wit copied to clipboard

Nodes sdk for wit ai messenger js file invalid json response

Open hoerlanton opened this issue 9 years ago • 13 comments

I wanted to get started with the Node.js SDK for Wit.ai. I followed the steps according to the comments in the messenger.js file:

// 1. npm install body-parser express request

// 2. Download and install ngrok from https://ngrok.com/download

// 3. ./ngrok http 8445

// 4. WIT_TOKEN=your_access_token FB_APP_SECRET=your_app_secret FB_PAGE_TOKEN=your_page_token node examples/messenger.js

// 5. Subscribe your page to the Webhooks using verify_token and https://<your_ngrok_io>/webhook as callback URL.

// 6. Talk to your bot on Messenger!

When I send a message to the server via Facebook messenger I receive the following error:

invalid json response body at https://f91805fe.ngrok.io/converse?session_id=2017-08-06T15%3A37%3A04.862Z&q=ldldl reason: Unexpected token T in JSON at position 0 invalid-son Oops! Got an error from Wit: Error at /Users/antonhorl/Documents/projekte-lokal/HotelMessenger/bots/node-wit-bot/node_modules/node-fetch/lib/body.js:49:31 at at process._tickCallback (internal/process/next_tick.js:188:7)

Has somebody any idea why? Thanks a lot for the effort.

hoerlanton avatar Aug 06 '17 16:08 hoerlanton

Node.js SDK ticket: https://github.com/wit-ai/node-wit/issues/153

patapizza avatar Aug 07 '17 22:08 patapizza

got the same problem.

iamkenken avatar Aug 10 '17 09:08 iamkenken

Not sure this is specific to Node.js SDK. @iamkenken @hoerlanton can you provide your app ids and steps to reproduce the issue?

blandinw avatar Aug 14 '17 23:08 blandinw

@blandinw The response from wit is working right now but there are times that the response is not working and it happens everyday. I'm just not sure what time. Is it because that I'm using the stories? Here is the sample response when it's not working.

Error: FetchError: invalid json response body at https://api.wit.ai/converse?session_id=8cae3fc1517e2f1ba275de42&q=Tondo reason: Unexpected token S in JSON at position 0

iamkenken avatar Aug 15 '17 06:08 iamkenken

Thanks @iamkenken, this helps, I'll investigate internally. Precise timestamps would help if you can provide them.

To your question, it is due to the fact that you're using Stories. It should still work so we'll try to fix that, but we highly recommend you move over to using Understanding + GET /message API (more context @ https://wit.ai/blog/2017/07/27/sunsetting-stories)

blandinw avatar Aug 15 '17 18:08 blandinw

@blandinw Hi, we are also using stories and we were told that support for them will be mantained until the end of the year. Nevertheless, we are having the same issue mentioned above:

SyntaxError: Unexpected token S in JSON at position 0
     at Object.parse (native)
     at /var/lib/strong-pm/svc/1/work/c5de636719749fc481da6db4c69c2aba1b90f46d.1490025319357/node_modules/node-wit/node_modules/isomorphic-fetch/node_modules/node-fetch/lib/body.js:49:15
     at process._tickCallback (internal/process/next_tick.js:103:7)

We debug the response on that line and found that wit.ai is responding this:

Something went wrong. We've been notified.

We need to know if this issue is going to be solved and when, since our production app is not working and is affecting lots of our users (+5000).

Regards, Federico Martinez

fmartinez-oneloop avatar Aug 22 '17 13:08 fmartinez-oneloop

Hey @fmartinez-oneloop -- we will most definitely continue to support.

Would you mind sending me an example request, with the app-id of your service?

stopachka avatar Aug 22 '17 16:08 stopachka

the invalid-json here is a red-herring -- will fix that as well, but the actual issue is that the backend seems to be returning a 500

stopachka avatar Aug 22 '17 16:08 stopachka

Hi @stopachka. Here is the request URL we are sending to the wit.ai api that we got by configuring the client with a logger in DEBUG mode:

POST https://api.wit.ai/converse?session_id=f0535c27-2c94-47de-93a7-460f2d29f847&q=hola

And our app-id is:

58418b49-ad02-45ae-a899-e966ff918854

Thanks!

fmartinez-oneloop avatar Aug 22 '17 17:08 fmartinez-oneloop

Hi @fmartinez-oneloop,

I've just tried with that session and it seems like it works:

$ curl -XPOST 'https://api.wit.ai/converse?session_id=f0535c27-2c94-47de-93a7-460f2d29f847&q=hola'
{
  "confidence" : 1,
  "type" : "msg",
  "msg" : "Hola, como puedo ayudarte?",
  "entities" : {
    "saludo" : [ {
      "confidence" : 0.99388070251418,
      "value" : "hola",
      "type" : "value"
    } ]
  }

Are you experiencing the issue consistently on your end?

patapizza avatar Aug 23 '17 17:08 patapizza

Hi,

I am facing the same issue as well.

https://api.wit.ai/converse?session_id=2017-08-24T02:47:01.912Z&q=24

App Id: 58e1c245-4e57-4a25-a87f-19b75c288742

Please get wit.ai up and running like how it used to be untill the timeline mentioned.

mani541 avatar Aug 24 '17 07:08 mani541

@patapizza @stopachka Apparently it is working fine today. We checked our application logs and found that yesterday at around 4:15pm (PDT) the issue stopped and wit.ai endpoint started to respond correctly.

Have the wit.ai team made any fix on their backend to address the issue? A confirmation on this would be helpful since we want to be sure this issue won't happen again in the days to come.

fmartinez-oneloop avatar Aug 24 '17 15:08 fmartinez-oneloop

I can confirm we did fix something on our backend yesterday around that time. Closing. Feel free to reopen

l5t avatar Aug 24 '17 17:08 l5t