mirror of
https://github.com/lingble/chatwoot.git
synced 2025-10-30 02:32:29 +00:00
fix: Ensure message is always present in conversation_created webhook for WhatsApp attachment messages (#12507)
Fixes https://github.com/chatwoot/chatwoot/issues/11753 and https://github.com/chatwoot/chatwoot/issues/12442 **Problem** When a WhatsApp conversation started with a media message, the conversation created webhook would sometimes fire before the message and its relationships were fully committed to the database. This resulted in the message being missing from the webhook payload, breaking external automations that rely on this field. **Solution** Added `ActiveRecord::Base.transaction` wrapper around the core message processing operations in `Whatsapp::IncomingMessageBaseService` to ensure atomic execution: - `set_conversation` (creates conversation) - `create_messages` (creates message with account_id) - `clear_message_source_id_from_redis` (cleanup) Now the webhook only triggers after all related data is fully persisted, guaranteeing message availability.
This commit is contained in:
@@ -32,9 +32,11 @@ class Whatsapp::IncomingMessageBaseService
|
||||
set_contact
|
||||
return unless @contact
|
||||
|
||||
set_conversation
|
||||
create_messages
|
||||
clear_message_source_id_from_redis
|
||||
ActiveRecord::Base.transaction do
|
||||
set_conversation
|
||||
create_messages
|
||||
clear_message_source_id_from_redis
|
||||
end
|
||||
end
|
||||
|
||||
def process_statuses
|
||||
|
||||
Reference in New Issue
Block a user