configuration.rb 828 B

1234567891011121314151617181920212223242526272829
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Whatsapp::Webhook
  3. class Configuration
  4. include Whatsapp::Webhook::Concerns::HasChannel
  5. def initialize(options:)
  6. @options = options
  7. end
  8. def verify!
  9. raise VerificationError if @options.blank?
  10. raise VerificationError if @options[:'hub.mode'] != 'subscribe'
  11. raise VerificationError if @options[:'hub.challenge'].to_i.zero?
  12. channel = find_channel!(@options[:callback_url_uuid])
  13. raise VerificationError if channel.options[:verify_token] != @options[:'hub.verify_token']
  14. @options[:'hub.challenge']
  15. end
  16. class VerificationError < StandardError
  17. def initialize
  18. super(__('The WhatsApp channel webhook configuration could not be verified.'))
  19. end
  20. end
  21. end
  22. end