Closed angelacode closed 6 years ago
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Ruby |
/usr/local/rvm/gems/ruby-2.2.1/gems/facebook-messenger-1.0.0/lib/facebook/messenger/bot/error_parser.rb : in raise_errors_from , line 53
|
---|---|
Web | POST dev.hellokaya.com/webhook |
/usr/local/rvm/gems/ruby-2.2.1/gems/facebook-messenger-1.0.0/lib/facebook/messenger/bot/error_parser.rb
: in raise_errors_from
/usr/local/rvm/gems/ruby-2.2.1/gems/facebook-messenger-1.0.0/lib/facebook/messenger/bot.rb
: in deliver
/usr/local/rvm/gems/ruby-2.2.1/gems/facebook-messenger-1.0.0/lib/facebook/messenger/incoming/common.rb
: in reply
/root/kaya-nitrous/bot.rb
: in block in <top (required)>
/usr/local/rvm/gems/ruby-2.2.1/gems/facebook-messenger-1.0.0/lib/facebook/messenger/bot.rb
: in call
/usr/local/rvm/gems/ruby-2.2.1/gems/facebook-messenger-1.0.0/lib/facebook/messenger/bot.rb
: in trigger
/usr/local/rvm/gems/ruby-2.2.1/gems/facebook-messenger-1.0.0/lib/facebook/messenger/bot.rb
: in receive
/usr/local/rvm/gems/ruby-2.2.1/gems/facebook-messenger-1.0.0/lib/facebook/messenger/server.rb
: in block (2 levels) in trigger
/usr/local/rvm/gems/ruby-2.2.1/gems/facebook-messenger-1.0.0/lib/facebook/messenger/server.rb
: in each
/usr/local/rvm/gems/ruby-2.2.1/gems/facebook-messenger-1.0.0/lib/facebook/messenger/server.rb
: in block in trigger
/usr/local/rvm/gems/ruby-2.2.1/gems/facebook-messenger-1.0.0/lib/facebook/messenger/server.rb
: in each
/usr/local/rvm/gems/ruby-2.2.1/gems/facebook-messenger-1.0.0/lib/facebook/messenger/server.rb
: in trigger
/usr/local/rvm/gems/ruby-2.2.1/gems/facebook-messenger-1.0.0/lib/facebook/messenger/server.rb
: in receive
/usr/local/rvm/gems/ruby-2.2.1/gems/facebook-messenger-1.0.0/lib/facebook/messenger/server.rb
: in call
/usr/local/rvm/gems/ruby-2.2.1/gems/facebook-messenger-1.0.0/lib/facebook/messenger/server.rb
: in call
/usr/local/rvm/gems/ruby-2.2.1/gems/rack-1.6.8/lib/rack/urlmap.rb
: in block in call
/usr/local/rvm/gems/ruby-2.2.1/gems/rack-1.6.8/lib/rack/urlmap.rb
: in each
/usr/local/rvm/gems/ruby-2.2.1/gems/rack-1.6.8/lib/rack/urlmap.rb
: in call
/usr/local/rvm/gems/ruby-2.2.1/gems/rack-1.6.8/lib/rack/tempfile_reaper.rb
: in call
/usr/local/rvm/gems/ruby-2.2.1/gems/rack-1.6.8/lib/rack/lint.rb
: in _call
/usr/local/rvm/gems/ruby-2.2.1/gems/rack-1.6.8/lib/rack/lint.rb
: in call
/usr/local/rvm/gems/ruby-2.2.1/gems/rack-1.6.8/lib/rack/showexceptions.rb
: in call
/usr/local/rvm/gems/ruby-2.2.1/gems/rack-1.6.8/lib/rack/commonlogger.rb
: in call
/usr/local/rvm/gems/ruby-2.2.1/gems/sinatra-1.4.8/lib/sinatra/base.rb
: in call
/usr/local/rvm/gems/ruby-2.2.1/gems/rack-1.6.8/lib/rack/chunked.rb
: in call
/usr/local/rvm/gems/ruby-2.2.1/gems/rack-1.6.8/lib/rack/content_length.rb
: in call
/usr/local/rvm/gems/ruby-2.2.1/gems/rack-1.6.8/lib/rack/handler/webrick.rb
: in service
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb
: in service
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb
: in run
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb
: in block in start_thread
No GET data.
No POST data.
No cookie data.
Variable | Value |
---|---|
CONTENT_LENGTH | 348 |
CONTENT_TYPE | application/json |
GATEWAY_INTERFACE | CGI/1.1 |
HTTP_ACCEPT | */* |
HTTP_ACCEPT_ENCODING | gzip |
HTTP_CF_CONNECTING_IP | 54.226.227.229 |
HTTP_CF_IPCOUNTRY | US |
HTTP_CF_RAY | 38d9b44f8f082456-IAD |
HTTP_CF_VISITOR | {"scheme":"https"} |
HTTP_CONNECTION | Keep-Alive |
HTTP_HOST | dev.hellokaya.com |
HTTP_VERSION | HTTP/1.1 |
HTTP_X_FORWARDED_FOR | 54.226.227.229 |
HTTP_X_FORWARDED_PROTO | https |
HTTP_X_HUB_SIGNATURE | sha1=9950b65cbac721687c836b0bd3e14e2384096075 |
PATH_INFO | /webhook |
QUERY_STRING | |
REMOTE_ADDR | 162.158.78.252 |
REMOTE_HOST | 162.158.78.252 |
REQUEST_METHOD | POST |
REQUEST_PATH | /webhook |
REQUEST_URI | https://dev.hellokaya.com/webhook |
SCRIPT_NAME | |
SERVER_NAME | dev.hellokaya.com |
SERVER_PORT | 443 |
SERVER_PROTOCOL | HTTP/1.1 |
SERVER_SOFTWARE | WEBrick/1.3.1 (Ruby/2.2.1/2015-02-26) |
rack.errors | #<Rack::Lint::ErrorWrapper:0x000000022ba960 @error=#<IO:<STDERR>>> |
rack.hijack | #<Proc:0x000000022bb400@/usr/local/rvm/gems/ruby-2.2.1/gems/rack-1.6.8/lib/rack/lint.rb:525> |
rack.hijack? | true |
rack.hijack_io | nil |
rack.input | #<Rack::Lint::InputWrapper:0x000000022ba988 @input=#<StringIO:0x000000022e4558>> |
rack.multiprocess | false |
rack.multithread | true |
rack.request.cookie_hash | {} |
rack.request.query_hash | {} |
rack.request.query_string | |
rack.run_once | false |
rack.tempfiles | [] |
rack.url_scheme | http |
rack.version | [1, 3] |
sinatra.commonlogger | true |
You're seeing this error because you use Rack::ShowExceptions
.
I have discovered the problem. The code implies that by subscribing and providing the access token, that all methods would work when requiring it.
It turns out the ENV['ACCESS_TOKEN']
is hard coded elsewhere....I subscribed with the following:
subscribe = Facebook::Messenger::Subscriptions.subscribe(access_token: ENV["MESSENGER_ACCESS_TOKEN"])
I have tons of other access tokens in my app so each one needs to be identified.
The error is fixed when I explicitly do the following:
ENV['ACCESS_TOKEN'] = ENV['MESSENGER_ACCESS_TOKEN']
This is confusing: the code implies that the application understand the access token identified when subscribing. But it looks like a hard-coded value for it is used elsewhere.
Is there a way to make token assignments more explicit and consistent?
You can make a configuration provider https://github.com/jgorset/facebook-messenger#make-a-configuration-provider
I ended up with something like this
class FacebookVerificationProvider < Facebook::Messenger::Configuration::Providers::Base
def valid_verify_token?(token)
ENV['FACEBOOK_VERIFICATION_TOKEN'] == token
end
def app_secret_for(page_id)
ENV['FACEBOOK_APP_SECRET']
end
def access_token_for(page_id)
ENV['FACEBOOK_ACCESS_TOKEN']
end
end
and on my bot
require 'facebook/messenger'
require_relative './verification_provider'
include Facebook::Messenger
Facebook::Messenger.configure do |config|
config.provider = FacebookVerificationProvider.new
end
...
You could potentially include some sort of validation that the page_id you get is the one you want your bot to reply from but not even sure if necessary.
However, I agree with @angelacode, the name for the environment variable should not be hardcoded in the gem and rather get that from a configuration users can set on an initializer or similar, especially the name of such variable being 'ACCESS_TOKEN'
I agree, @oscarsiniscalchi -- it's hard to change it now without breaking compatibility, though, and considering that it is possible to change by writing your own configuration provider I guess that'll have to do.
I have a valid access token.
I have an output 'true' when I subscribe in my app.
However, I still get this error:
Facebook::Messenger::FacebookError: An active access token must be used to query information about the current user.
I successfully exit at
binding.pry
but get the error when Imessage.reply
.When I output the
ENV
variable for message_access_token, it matches what is in the Facebook app under developer.facebook.com.So this is confusing why message fails.
How can I better debug this?