From 6d053e58168722b8001af212222c8f0c3a90f6fe Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Thu, 3 Oct 2024 22:13:41 -0700 Subject: [PATCH] chore: Move line attachment creation to a single db commit (#10194) Similar to the work we did with the legacy code of other channels like Twilio, we need to move the message creation and attachment creation to be under a single db commit for the line channel. Otherwise, the emitted webhook events for message creation will miss the attachment payload. Ref: https://github.com/orgs/chatwoot/discussions/7546#discussioncomment-10814495 Ref: https://github.com/chatwoot/chatwoot/pull/10167 --- app/services/line/incoming_message_service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/line/incoming_message_service.rb b/app/services/line/incoming_message_service.rb index 2d6988476..f36bce0f0 100644 --- a/app/services/line/incoming_message_service.rb +++ b/app/services/line/incoming_message_service.rb @@ -25,13 +25,14 @@ class Line::IncomingMessageService next unless message_created? event attach_files event['message'] + @message.save! end end def message_created?(event) return unless event_type_message?(event) - @message = @conversation.messages.create!( + @message = @conversation.messages.build( content: message_content(event), account_id: @inbox.account_id, content_type: message_content_type(event), @@ -90,7 +91,6 @@ class Line::IncomingMessageService content_type: response.content_type } ) - @message.save! end def event_type_message?(event)