Class: Bobot::WebhookController
- Inherits:
-
ApplicationController
- Object
- ActionController::API
- ApplicationController
- Bobot::WebhookController
- Defined in:
- app/controllers/bobot/webhook_controller.rb
Defined Under Namespace
Classes: BadRequestError
Constant Summary collapse
- X_HUB_SIGNATURE_MISSING_WARNING =
<<-HEREDOC.freeze The X-Hub-Signature header is not present in the request. This is expected for the first webhook requests. If it continues after some time, check your app's secret token. HEREDOC
- OPEN_SSL_AUTHENTICATION_CODE =
OpenSSL::Digest.new('sha1'.freeze)
Instance Method Summary collapse
Instance Method Details
#receive ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/bobot/webhook_controller.rb', line 32 def receive @body = nil @parsed_body = nil check_integrity unless skip_check_integrity? trigger(parsed_body) head :ok rescue => e render plain: e., status: :ok end |
#verify ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'app/controllers/bobot/webhook_controller.rb', line 23 def verify if params['hub.mode'.freeze] == 'subscribe' && params['hub.verify_token'.freeze] == Bobot.config.verify_token render plain: params['hub.challenge'.freeze], status: :ok else render plain: "Error wrong verify token".freeze, status: :forbidden end end |
#webhook ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'app/controllers/bobot/webhook_controller.rb', line 13 def webhook if request.get? verify elsif request.post? receive else head :method_not_allowed end end |