Ruby on Rails Gem for the Facebook Messenger Bot Platform
Ruby on Rails client!! for Facebook Messenger Platform
Requires Rails >= 4
Bundler in your Gemfile.
gem 'messenger-bot'
Now sign in into the Facebook developer and create an application
messenger-bot-rails
to your Gemfilegem 'messenger-bot'
config/initializers/messenger_bot.rb
Messenger::Bot.config do |config|
config.access_token = <PAGE_ACCESS_TOKEN>
config.validation_token = <VERIFY_TOKEN>
config.secret_token = <FB_APP_SECRET_TOKEN>
end
config/routes.rb
mount Messenger::Bot::Space => "/webhook"
app/controllers/messenger_bot_controller.rb
class MessengerBotController < ActionController::Base
def message(event, sender)
# profile = sender.get_profile(field) # default field [:locale, :timezone, :gender, :first_name, :last_name, :profile_pic]
sender.reply({ text: "Reply: #{event['message']['text']}" })
end
def delivery(event, sender)
end
def postback(event, sender)
payload = event["postback"]["payload"]
case payload
when :something
#ex) process sender.reply({text: "button click event!"})
end
end
end
event
- Hash containing the message event from Facebook format
sender
- Class to call the 'reply, get_profile' method.event
- Hash containing the delivery event from Facebook format
sender
- Class to call the 'reply, get_profile' method.event
- Hash containing the postback event from Facebook format
sender
- Class to call the 'reply, get_profile' method.event
- Hash containing the optin event from Facebook format
sender
- Class to call the 'reply, get_profile' method.MIT, see LICENSE.txt