chore: Generate webhook-verify-token automatically (#5593)

- Autogenerate webhook verification token in the WhatsAppCloud channel.

Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
Pranav Raj S
2022-10-12 11:32:31 +11:00
committed by GitHub
parent 5f4b6f2ce4
commit 38776906ab
8 changed files with 58 additions and 36 deletions

View File

@@ -25,11 +25,12 @@ class Channel::Whatsapp < ApplicationRecord
# default at the moment is 360dialog lets change later.
PROVIDERS = %w[default whatsapp_cloud].freeze
before_validation :ensure_webhook_verify_token
validates :provider, inclusion: { in: PROVIDERS }
validates :phone_number, presence: true, uniqueness: true
validate :validate_provider_config
after_create :sync_templates
def name
@@ -56,6 +57,10 @@ class Channel::Whatsapp < ApplicationRecord
private
def ensure_webhook_verify_token
provider_config['webhook_verify_token'] ||= SecureRandom.hex(16) if provider == 'whatsapp_cloud'
end
def validate_provider_config
errors.add(:provider_config, 'Invalid Credentials') unless provider_service.validate_provider_config?
end