class Fb::Messenger::Client

fb rest client

Public Class Methods

send(payload) click to toggle source
# File lib/fb/messenger/client.rb, line 8
def send(payload)
  RestClient.post("#{BASE_URL}/me/messages?access_token=#{Fb::Messenger.config.access_token}",
                  payload.to_json, content_type: :json, accept: :json)
end
send_message_template(recipient, template) click to toggle source
# File lib/fb/messenger/client.rb, line 20
def send_message_template(recipient, template)
  payload = {
    recipient: {
      id: recipient
    },
    message: template
  }
  send(payload)
end
send_message_text(recipient, text) click to toggle source
# File lib/fb/messenger/client.rb, line 30
def send_message_text(recipient, text)
  payload = {
    recipient: {
      id: recipient
    },
    message: {
      text: text
    }
  }
  send(payload)
end
user_info(user_id) click to toggle source
# File lib/fb/messenger/client.rb, line 13
def user_info(user_id)
  r = RestClient.get("#{BASE_URL}/#{user_id}",
                     params: { access_token: Fb::Messenger.config.access_token },
                     accept: :json)
  JSON.parse(r)
end