facebookarchive / DEPRECATED-node-wit

Node wrapper for Wit.ai
Other
122 stars 26 forks source link

Array passed to context.state throws 400, claiming object. #7

Closed irfaan closed 9 years ago

irfaan commented 9 years ago

Wit.js passes:

{ 
    q: 'test',
    verbose: false,
    context: { state: [ 'some_state' ] }
}

Returns:

Response from Wit for text input: 
Error:  Invalid response received from server: 400
"State supplied is not in a correct format, format accepted are string or array, was given :{\"0\":\"some_state\"}"
l5t commented 9 years ago

I checked quickly and it appears to come from the require lib. For some reason, it transforms the json array into a json object... I check our API with a curl, and it works with an array. curl \ -H 'Authorization: Bearer YOUR_TOKEN' \ 'https://api.wit.ai/message?v=20150421&q=what%27s%20the%20weather%20in%20Berkeley&context=%7B%22state%22%3A%5B%22yes_or_no%22%2C%22cancel%22%5D%7D'

irfaan commented 9 years ago

I've been looking around for a solution, but with no luck. To clarify, you're suggesting that it is the node 'request' library that is transforming the json array into a json object?

Any idea how we might handle this?

irfaan commented 9 years ago

@l5t Any chance you can shed some light on this? https://github.com/request/request/issues/1550#issuecomment-95721689

What format is the array being expected in?

oliviervaussy commented 9 years ago

Hi @irfaan,

You need to stringify your context before sending it to Wit.ai. I've added some test to give you some example which works: https://github.com/wit-ai/node-wit/commit/fc5a6ea4ff4e4e6c015eee8b1edbe10ef1715f85

Let me know if you have any questions

irfaan commented 9 years ago

Thank you, @oliviervaussy!