Search code examples
pythonchatbotwit.aifacebook-chatbotfacebook-messenger-bot

Facebook messenger chatbot gives duplicate replies


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.)


Solution

  • 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.