feat: add external_created_at to message creation and update specs for provider callback

This commit is contained in:
gabrieljablonski 2026-02-17 23:32:27 -03:00
parent 9a4c5058f3
commit 248d6c23b3
2 changed files with 7 additions and 2 deletions

View File

@ -194,6 +194,7 @@ class Whatsapp::IncomingMessageBaseService # rubocop:disable Metrics/ClassLength
def create_message(message, source_id: nil)
content_attrs = outgoing_echo ? { external_echo: true } : {}
content_attrs[:in_reply_to_external_id] = @in_reply_to_external_id if @in_reply_to_external_id.present?
content_attrs[:external_created_at] = message[:timestamp].to_i
@message = @conversation.messages.build(
content: message_content(message),
@ -204,8 +205,7 @@ class Whatsapp::IncomingMessageBaseService # rubocop:disable Metrics/ClassLength
status: outgoing_echo ? :delivered : :sent,
sender: outgoing_echo ? nil : @contact,
source_id: (source_id || message[:id]).to_s,
content_attributes: content_attrs,
external_created_at: message[:timestamp].to_i
content_attributes: content_attrs
)
end

View File

@ -489,6 +489,11 @@ RSpec.describe Channel::Whatsapp do
context 'when provider does not implement the method' do
let(:channel) { create(:channel_whatsapp, provider: 'whatsapp_cloud', validate_provider_config: false, sync_templates: false) }
before do
stub_request(:delete, "https://graph.facebook.com/v22.0/#{channel.provider_config['business_account_id']}/subscribed_apps")
.to_return(status: 200, body: '', headers: {})
end
it 'does not invoke callback' do
expect(channel).not_to receive(:disconnect_channel_provider)