8000 feat: add flag to edited messages and content history tracking by CayoPOliveira · Pull Request #35 · fazer-ai/chatwoot · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add flag to edited messages and content history tracking #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 6, 2025
5 changes: 4 additions & 1 deletion app/models/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,12 @@ class Message < ApplicationRecord
# [:external_created_at] : Can specify if the message was created at a different timestamp externally
# [:external_error : Can specify if the message creation failed due to an error at external API
# [:is_reaction] : Used to denote if the message is a reaction and differentiate it from a simple reply message
# [:is_edited, :previous_content] : Used to indicated edited message and previous content (before edit)

store :content_attributes, accessors: [:submitted_email, :items, :submitted_values, :email, :in_reply_to, :deleted,
:external_created_at, :story_sender, :story_id, :external_error,
:translations, :in_reply_to_external_id, :is_unsupported, :is_reaction], coder: JSON
:translations, :in_reply_to_external_id, :is_unsupported,
:is_reaction, :is_edited, :previous_content], coder: JSON

store :external_source_ids, accessors: [:slack], coder: JSON, prefix: :external_source_id

Expand Down
16 changes: 8 additions & 8 deletions app/services/whatsapp/incoming_message_baileys_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def handle_update
raise MessageNotFoundError unless find_message_by_source_id(message_id)

update_status if @raw_message.dig(:update, :status).present?
update_message_content if @raw_message.dig(:update, :message).present?
handle_edited_content if @raw_message.dig(:update, :message).present?
end

def update_status
Expand Down Expand Up @@ -318,15 +318,15 @@ def status_transition_allowed?(new_status)
true
end

def update_message_content
message = @raw_message.dig(:update, :message, :editedMessage, :message)
if message.blank?
Rails.logger.warn 'No valid message content found in the update event'
def handle_edited_content
@raw_message = @raw_message.dig(:update, :message, :editedMessage)
content = message_content

unless content
Rails.logger.warn 'No valid message content found in the edit event'
return
end

content = message[:conversation] || message.dig(:extendedTextMessage, :text)

@message.update!(content: content) if content.present?
@message.update!(content: content, is_edited: true, previous_content: @message.content)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,10 @@

described_class.new(inbox: inbox, params: params).perform

original_content = message.content
expect(message.reload.content).to eq('New message content')
expect(message.is_edited).to be(true)
expect(message.previous_content).to eq(original_content)
end
end

Expand Down
0