0

I'm building a chatbot with wit.ai and python and integrating it with Facebook Messenger. I have set up webhooks as well as send function and fb_message function exactly like in this tutorial: https://github.com/wit-ai/pywit/blob/master/examples/messenger.py

My bot works fine when I test it in wit.ai or in console, but when I test it in actual Facebook Messenger, it gives each reply twice. It doesn't matter which function inside the bot gets called, I always get two replies.

My most simple action is this:

def defaultAnswer(request):
    context = request['context']
    return context

(This returns always the same string, which is defined in wit.ai engine.)

Demeter
  • 106
  • 1
  • 8
  • do you check if the message from facebook api is empty? $input['entry'][0]['messaging'][0]['message'] -> check if this one is empty or not... if empty then don't process the request. – ssakash Nov 29 '16 at 17:44

3 Answers3

3

If your bot is subscribed to events other than pages_messaging, like messaging_deliveries, make sure you're handling this event as well.

What's happening is your that bot is receiving the message request, then receiving another one by another event, and your code is handling them both as messages.

I think this is the problem, and if it's not, give us more details about it.

Dani Sh90
  • 176
  • 1
  • 9
1

Someone might have a case like mine.

My case:

I mistakenly subscribe my two different bots to one facebook page on the developer.facebook.com.

Due to the this mistake, when i write a specific command(e.g. restart) to my facebook page, bot replies exactly same two messages(e.g. "Bot Restarted", "Bot Restarted") to me.

It made me a crazy to find out the problem.

You should subscribe one bot to your facebook page at most.

Fatih Turgut
  • 319
  • 3
  • 9
0

I had this issue before and it turns out, the message_echoes was enabled. What happens essentially if this is enabled is that the Bot will try to echo whatever you text you entered.

My logic ended up catching the echo and then responded with the same response. I do have a handler to catch similar responses so I was able to avoid the infinite loop.

Alvin Reyes
  • 710
  • 1
  • 8
  • 24