watson-developer-cloud / botkit-middleware

A middleware to connect Watson Conversation Service to different chat channels using Botkit
https://www.npmjs.com/package/botkit-middleware-watson
Apache License 2.0
206 stars 254 forks source link

Facebook bot does not reply back #99

Closed jerinsj closed 7 years ago

jerinsj commented 7 years ago

screenshot 1 issue

Can anyone tell me what the fatal type error means and how i can get the facebook bot to reply back. I used localtunnel just to try out the facebook bot, here's how that looks in the visual code terminal.... localtunnel

newbies13 commented 7 years ago

I am getting the same error, it looks like they've had this problem before, there is a reference to a #28 which was fixed but seems to have popped up again.

Naktibalda commented 7 years ago

Are you checking message.watsonError before using message.watsonData in your code?

jerinsj commented 7 years ago

where can i check message.watsonError and message.watsonData and how do you know if that could be a problem?

Naktibalda commented 7 years ago

Replace bot.reply line with

 if (message.watsonError.) {
    console.log(message.watsonError);
    bot.reply(message, "I'm sorry, but for technical reasons I can't respond to your message");
  } else {
    bot.reply(message, message.watsonData.output.text.join('\n'));
  }
jerinsj commented 7 years ago

I am going to try that and let you know, although i don't think that will get the bot to have a conversation.

Naktibalda commented 7 years ago

No, but it will help to understand why your bot isn't working.

jerinsj commented 7 years ago

Yes my friend I tried that and this is the message that I see... issue2

leading upto this... I used local tunnel set it to listen on port 5000, received URL for webhook, went on facebook and added the webhook, everything went well but that's the error message I get on the terminal...

jerinsj commented 7 years ago

oh wow! the bot responded " I'm sorry but for technical reasons cant respond to your message. msg

Naktibalda commented 7 years ago

It looks like you get Forbidden response from Watson. Check if you are setting correct username, password and workspace_id.

kkarlallan commented 7 years ago

Good Day Guys,

I've had the same initial issue with @jerinsj. And the error logs say "ERCD-NOCONFIG" image

you can print this by following below: image

Further research suggests that this points to having incorrect username, password, or workspace_id like what @Naktibalda said. BUT, here's the issue with the Botkit I've found:

I've tried adding in the credentials manually and they don't work. as seen here: image

I also noticed that in the Application details in Bluemix, the conversation service was binded and a different set of credentials were given, I tried them also and to no success. I've read from a different post that this might be due to the version_date sending the wrong POST request format like "https://gateway.watsonplatform.net/conversation/api/v1/workspaces/{workspace_id}/message?version=`ConversationV1.VERSION_DATE_2017_05_26`".

May I request help? or can someone teach me how to see the POST requests my botkit is sending to the Watson API endpoint?

reference: Experience And this thread - https://github.com/watson-developer-cloud/botkit-middleware/issues/46 (Can anyone teach me how the guy in this thread was able to generate the POST request logs of his botkit? Thanks)

Naktibalda commented 7 years ago

@kkarlallan I see 2 unrelated pieces of code. The first screenshot is a complete code of a very minimal bot which does nothing.

Second screenshot creates middleware object. Is there a third file which plugs the first two together?

URL in the error log looks completely wrong too.

My advice is not to use Watson middleware example code as a starting point for your bot. Use botkit starter kit instead and plug Watson middleware to it.

kkarlallan commented 7 years ago

Hey @Naktibalda . I fixed my problem and I'm guessing this will fix @jerinsj 's problem too. Thanks for putting a bit of time into this. This was quite embarrassing.

Here's the absurd solution: In the .env file. Delete the commented "#US-South" on line 2. Voila! image

This took me 3 days to find out. What a life. *sigh

But seriously though, I used this as my botkit starter and just updated the Watson Credentials: https://github.com/watson-developer-cloud/botkit-middleware/tree/master/examples/multi-bot

I suggest there be a comment inside the env file there that states "delete this later on -> #US-South" or something like that since it creates a fuss.

Thanks for hearing me out. Hope this helps other newbies like me.

To recreate the error by the way is:

  1. download botkit-middleware/ as zip and unzip to chosen directory
  2. navigate to directory/examples/multi-bot/
  3. update .env file to use your Watson and FB Messenger credentials
  4. deploy app
  5. set up messenger
  6. chat anything

Debug:

  1. use --debug in the command
  2. view the request sent to Watson request curl will show the endpoint as: "https://gateway.watsonplatform.net/conversation/api%20%20US-South/workspace/{workspace_id}/message?version_date=2017-05-26"

Everything's now working fine. Crying in bliss

jerinsj commented 7 years ago

Awesome! that was exactly the problem. Thanks. I am so excited to be talking with my bot for the very first time.

Naktibalda commented 7 years ago

@kkarlallan sorry for that, I assumed that # comments work like in programming languages and didn't test them.