Sha256: 44362fdd4268045ff4b2fbd33e9d23fe9111baac2c753c316afbc64706e21ff7

Contents?: true

Size: 865 Bytes

Versions: 3

Compression:

Stored size: 865 Bytes

Contents

module Facebook
  module Bot
    class Transmitter
      def initialize(sender)
        @data = {
          recipient: { id: sender }
        }
      end

      def reply(data)
        @data[:message] = data
        send_message(@data)
      end

      private

      def send_message(data)
        url = URI.parse("https://graph.facebook.com/v2.6/me/messages?access_token=#{Facebook::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
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
facebook-bot-0.1.3 lib/facebook/bot/transmitter.rb
facebook-bot-0.1.2 lib/facebook/bot/transmitter.rb
facebook-bot-0.1.1 lib/facebook/bot/transmitter.rb