lib/messenger/bot/transmitter.rb in messenger-bot-0.1.6 vs lib/messenger/bot/transmitter.rb in messenger-bot-0.1.7

- old
+ new

@@ -1,34 +1,23 @@ module Messenger module Bot class Transmitter def initialize(sender) - @data = { - recipient: { id: sender } - } + @sender_id = sender end def reply(data) - @data[:message] = data - send_message(@data) + data = { + recipient: { + id: @sender_id + }, + message: data + } + Messenger::Bot::Request.post("https://graph.facebook.com/v2.6/me/messages?access_token=#{Messenger::Bot::Config.access_token}", data) end - private - - def send_message(data) - url = URI.parse("https://graph.facebook.com/v2.6/me/messages?access_token=#{Messenger::Bot::Config.access_token}") - http = Net::HTTP.new(url.host, 443) - http.use_ssl = true - begin - request = Net::HTTP::Post.new(url.request_uri) - request["Content-Type"] = "application/json" - request.body = data.to_json - response = http.request(request) - body = JSON(response.body) - return { ret: body["error"].nil?, body: body } - rescue => e - raise e - end + def get_profile + Messenger::Bot::Request.get("https://graph.facebook.com/v2.6/#{@sender_id}?fields=first_name,last_name,profile_pic&access_token=#{Messenger::Bot::Config.access_token}") end end end end