Sha256: 48e72d5281ca21eba6ba99830ac3119bc0bdc87e17eb6c864da75720bcee1c66
Contents?: true
Size: 1.39 KB
Versions: 2
Compression:
Stored size: 1.39 KB
Contents
module Messenger module Bot class Space::StationController < ::MessengerBotController before_action :authenticate, only: [:receive] def validation if params["hub.verify_token"] === Messenger::Bot::Config.validation_token return render json: params["hub.challenge"] end render body: "Error, wrong validation token" end def receive Messenger::Bot::Receiver.share(params) messaging_events = params["entry"].first["messaging"] messaging_events.each_with_index do |event, key| sender = Messenger::Bot::Transmitter.new(event["sender"]["id"]) if event["message"] && !defined?(message).nil? send(:message, event, sender) elsif event["postback"] && !defined?(postback).nil? send(:postback, event, sender) elsif event["delivery"] && !defined?(delivery).nil? send(:delivery, event, sender) end end render body: "ok" end def authenticate return true if Messenger::Bot::Config.secret_token.nil? signature = "sha1=" + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), Messenger::Bot::Config.secret_token, request.body.read) return render(body: "Error, Signatures didn't match", status: 500) unless Rack::Utils.secure_compare(signature, request.env['HTTP_X_HUB_SIGNATURE']) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
messenger-bot-0.1.9 | lib/messenger/bot/station.rb |
messenger-bot-0.1.8 | lib/messenger/bot/station.rb |