3
votes

I'm trying to build a messenger bot using the facebook messenger gem provided by Hypersolo: https://github.com/hyperoslo/facebook-messenger

I always get the following error: Facebook::Messenger::Bot::RecipientNotFound (Unsupported post request. Object with ID 'me' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api)

I assumed the error was due to an invalid or inactive access_token, however I requested a new one over and over again and the error remains. I checked my page subscriptions which seem to be fine as well as disabling message_echoes in webhooks.

The code I'm using is simple:

require 'facebook/messenger'
include Facebook::Messenger

Facebook::Messenger::Subscriptions.subscribe(access_token: ENV["ACCESS_TOKEN"])

Bot.on :message do |message|
  message.reply(text: 'Hello, human!')
end

Additionally; leaving out the reply and inspecting the message variable gives me a valid message object.

#<Facebook::Messenger::Incoming::Message:0x007fdd2d4a40e0 @messaging={"sender"=>{"id"=>"1349987331712XXX"}, "recipient"=>{"id"=>"1683630555268XXX"}, "timestamp"=>1484149162343, "message"=>{"mid"=>"mid.1484149162343:d5a47f1649", "seq"=>121620, "text"=>"Why wont this work?"}}>
1
did you check facebook app permissions?Jonny Vu

1 Answers

1
votes

I never have used hyperoslo framework like you but I found something that could explain your question.

Your message value:

#<Facebook::Messenger::Incoming::Message:0x007fdd2d4a40e0 @messaging={"sender"=>{"id"=>"1349987331712XXX"}, "recipient"=>{"id"=>"1683630555268XXX"}, "timestamp"=>1484149162343, "message"=>{"mid"=>"mid.1484149162343:d5a47f1649", "seq"=>121620, "text"=>"Why wont this work?"}}>

That mean, to get sender id, the code should be @message['sender']['id'] But I found on hyperoslo source (https://github.com/hyperoslo/facebook-messenger/blob/master/lib/facebook/messenger/incoming/common.rb), it seem inconsistent:

    def sender
      @messaging['sender']
    end

    def recipient
      @messaging['recipient']
    end

    def reply(message)
      payload = {
        recipient: sender,
        message: message
      }

      Facebook::Messenger::Bot.deliver(payload, access_token: access_token)
    end

I think, it should be @messaging['sender']['id'] rather than @messaging['sender'].

Anyway, take a look at this issue: https://github.com/hyperoslo/facebook-messenger/issues/96.