Yoctol / bottender

⚡️ A framework for building conversational user interfaces.
https://bottender.js.org
MIT License
4.22k stars 335 forks source link

Postback not triggering from Messenger #152

Closed JordanVScher closed 6 years ago

JordanVScher commented 6 years ago

I connected my nodejs chatbot to messenger using ngrok and it works fine except for the postback_messages. Nothing happens when I press the 'start' button or the return to beginning button. What I have to do is click on the button and then send a text message. Everything works just fine after that. I believe that the postback message is not triggening the "onEvent" function, that's why I need the text message. Yes, I have the messaging_postbacks event selected on my facebook app. Does anyone have any ideas? Is there something I have to do with ngrok to make the postback reach the bot?

pavei commented 6 years ago

i'm getting the same issue..

chentsulin commented 6 years ago

I can't reproduce this issue using hello world example.

Could you run your bot with DEBUG=bottender/bot/Bot env variable and provide some details request body to us? And maybe part of code will be helpful too.

pavei commented 6 years ago

@chentsulin i dont receive any data.. but i got that the "start" and "menu" actions was created by another APP ID and Page TOKEN. So i made a new request to put the "start" button and it works nice. it was a misconfiguration. Thanks for your help :)

JordanVScher commented 6 years ago

Could you run your bot with DEBUG=bottender/bot/Bot env variable and provide some details request body to us? And maybe part of code will be helpful too.

I did that. Nothing comes up when I click any of the buttons(as expected). When I send a message this comes up:

{
  "object": "page",
  "entry": [
    {
      "id": "1220627118067968",
      "time": 1516020353792,
      "messaging": [
        {
          "sender": {
            "id": "1591680880914002"
          },
          "recipient": {
            "id": "1220627118067968"
          },
          "timestamp": 1516020353371,
          "message": {
            "mid": "mid.$cAAQM00kS3hNnKyARW1g-drI_bBi3",
            "seq": 306825,
            "text": "blabla"
           }
         }
      ]
   }

The IDs in entry and recipient are the same as my facebook page. The ID in sender doesn't match any of the ids I have. Maybe it's from another app I had previously attached to my page? EDIT: No, it's not.

chentsulin commented 6 years ago

@JordanVScher You can open http://127.0.0.1:4040/ to check requests in web interface when using ngrok.

image Ngrok Docs

If you receive messages events correctly, but only miss messaging_postbacks events, it most likely there are some problems in your webhook subscription. I would unsubscribe it and subscribe again and make sure messaging_postbacks is selected.

JordanVScher commented 6 years ago

@chentsulin Hello, thanks for answering.

If you receive messages events correctly, but only miss messaging_postbacks events, it most likely there are some problems in your webhook subscription.

That's exactly what's happening but I have tried unsubscribing and subscribing the page multiple times with no luck. I have only the messages, messaging_postbacks and messaging_optins events enabled. Here's the code I'm using: https://github.com/AppCivico/MandatoAberto-chatbot/blob/develop/app/index.js I didn't write it, but I have see it working just fine in another page, postbacks included.

tw0517tw commented 6 years ago

Hi @JordanVScher ,

The sender id in that request is called page-scoped ID which is unique over pages, so it will be different from the real Facebook user id or app id.

If you still can't receive postback events from Messenger Platform, you can consider reporting a bug at Facebook Developer's Site.

JordanVScher commented 6 years ago

Yeah, so I was being stupid. The buttons I was seeing were created by a different app with a different webhook. After sending a few post requests with curl I managed to make everything work as @amite said. Sadly, the documentation provided by facebook didn't help me at all but I found lots of useful information here, in case anyone else needs it: http://thedebuggers.com/persistent-menu-get-started-buttons-bot/

Thanks for all your help. :)

tw0517tw commented 6 years ago

Seems this has been resolved, closing. :)