fix: Setup webhooks for manual WhatsApp Cloud channel creation (#13278)

Fixes https://github.com/chatwoot/chatwoot/issues/13097

### Problem
The PR #12176 removed the `before_save :setup_webhooks` callback to fix
a race condition where Meta's webhook verification request arrived
before the channel was saved to the database. This change broke manual
WhatsApp Cloud channel setup. While embedded signup explicitly calls
`channel.setup_webhooks` in `EmbeddedSignupService`, manual setup had no
equivalent call - meaning the `subscribed_apps` endpoint was never
invoked and Meta never sent webhook events to Chatwoot.


### Solution
Added an `after_commit` callback that triggers webhook setup for manual
WhatsApp Cloud channels
This commit is contained in:
Muhsin Keloth
2026-01-19 14:12:36 +04:00
committed by GitHub
parent b2ffad1998
commit 7e4d93f649
5 changed files with 65 additions and 13 deletions

View File

@@ -96,8 +96,16 @@ FactoryBot.define do
channel_whatsapp.define_singleton_method(:sync_templates) { nil } unless options.sync_templates
channel_whatsapp.define_singleton_method(:validate_provider_config) { nil } unless options.validate_provider_config
if channel_whatsapp.provider == 'whatsapp_cloud'
channel_whatsapp.provider_config = channel_whatsapp.provider_config.merge({ 'api_key' => 'test_key', 'phone_number_id' => '123456789',
'business_account_id' => '123456789' })
# Add 'source' => 'embedded_signup' to skip after_commit :setup_webhooks callback in tests
# The callback is for manual setup flow; embedded signup handles webhook setup explicitly
# Only set source if not already provided (allows tests to override)
default_config = {
'api_key' => 'test_key',
'phone_number_id' => '123456789',
'business_account_id' => '123456789'
}
default_config['source'] = 'embedded_signup' unless channel_whatsapp.provider_config.key?('source')
channel_whatsapp.provider_config = channel_whatsapp.provider_config.merge(default_config)
end
end