0

This is my first question, so please let me know if I am doing something wrong. I tried to build a simple facebook messenger bot using the 'messenger-ruby' gem (https://github.com/netguru/messenger-ruby). I installed the gem successfully, but I think I don't really get how to send / receive messages.

In detail, I followed all the steps in the readme:

  1. get page access token
  2. create messenger.rb as outlined in the readme
  3. added the routes exactly as in the readme
  4. created the messenger_controller.rb as in the readme
  5. set up webhooks successfully as in the readme
  6. visited /messenger/subscribe to subscribe

This all worked so far, at https://developers.facebook.com/apps/.../messenger I see a green check under Webooks and see my page under Subscribed pages.

I did not do the "App Review for Messenger".

Now the problem: I tried to send a standard reply to every incoming message. I put the code from the readme under #components into messenger_controller.rb:

# YOUR_APP/app/controllers/messenger_controller.rb
class MessengerController < Messenger::MessengerController
  def webhook
  #logic here
    if fb_params.first_entry.callback.message?
      Messenger::Client.send(
        Messenger::Request.new(
          Messenger::Elements::Text.new(text: 'some text'),
          fb_params.first_entry.sender_id
        )
      )
    end
    render nothing: true, status: 200
  end
end

But when one of the page admins sends a message to the page, nothing happens. I looked in the logs, but don't see the POST request I'd expect.

When use my browser to visit https:/.../messenger/webhook, I see "Invalid verify token", and in the logs it shows the following:

Started GET "/messenger/webhook" for xxx.xxx.xxx.xxx at 2016-07-22 14:39:52 +0000
Cannot render console from xxx.xxx.xxx.xxx! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by Messenger::MessengerController#validate as HTML
Completed 200 OK in 10ms (Views: 0.3ms | ActiveRecord: 0.0ms)

I guess that's ok, but I am not sure.

I'm sure I probably made a simple mistake, but I was reading the docs all day and couldn't find a solution. I'm not even sure what the problem is, as I'd expect to find the POST request in the logs...

Any help would really be appreciated. And please let me know how I could improve my question.

Daniel Wu
  • 101
  • 4

1 Answers1

2

After writing my question, I was fiddling around with https://developers.facebook.com/apps/. I realized:

  1. that the user who was sending the message was only a page admin, but not an app administrator.
  2. my app was not public and my page was not published.

I added the user as app administrator, and it worked. The code above and the gem installation is ok.

As this cost me almost a full day, I hope this answer helps others as well. Sorry if I answer my own question.

Daniel Wu
  • 101
  • 4