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
This commit is contained in:
@@ -25,13 +25,14 @@ class Line::IncomingMessageService
|
|||||||
next unless message_created? event
|
next unless message_created? event
|
||||||
|
|
||||||
attach_files event['message']
|
attach_files event['message']
|
||||||
|
@message.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def message_created?(event)
|
def message_created?(event)
|
||||||
return unless event_type_message?(event)
|
return unless event_type_message?(event)
|
||||||
|
|
||||||
@message = @conversation.messages.create!(
|
@message = @conversation.messages.build(
|
||||||
content: message_content(event),
|
content: message_content(event),
|
||||||
account_id: @inbox.account_id,
|
account_id: @inbox.account_id,
|
||||||
content_type: message_content_type(event),
|
content_type: message_content_type(event),
|
||||||
@@ -90,7 +91,6 @@ class Line::IncomingMessageService
|
|||||||
content_type: response.content_type
|
content_type: response.content_type
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@message.save!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def event_type_message?(event)
|
def event_type_message?(event)
|
||||||
|
|||||||
Reference in New Issue
Block a user