0.04
No commit activity in last 3 years
No release in over 3 years
Ruby on Rails Gem for the Facebook Messenger Platform
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.11
~> 10.0
~> 3.0
 Project Readme

messenger-bot

Build Status Gem Version

Ruby on Rails client!! for Facebook Messenger Platform

Requires Rails >= 4

Installation

Bundler in your Gemfile.

gem 'messenger-bot'

Getting Started

Before You Begin

Now sign in into the Facebook developer and create an application

  1. Add messenger-bot-rails to your Gemfile
gem 'messenger-bot'
  1. Set config in 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

Subscribe the App to the Page

  1. Add the following to your config/routes.rb
mount Messenger::Bot::Space => "/webhook"
  1. create a controller in 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

wiki

Usage

message(event, sender)

  • event - Hash containing the message event from Facebook format
  • sender - Class to call the 'reply, get_profile' method.

delivery(event, sender)

  • event - Hash containing the delivery event from Facebook format
  • sender - Class to call the 'reply, get_profile' method.

postback(event, sender)

  • event - Hash containing the postback event from Facebook format
  • sender - Class to call the 'reply, get_profile' method.

optin(event, sender)

  • event - Hash containing the optin event from Facebook format
  • sender - Class to call the 'reply, get_profile' method.

license

MIT, see LICENSE.txt