feat: support reply to for outgoing message in WhatsApp (#8107)
- This PR enables replies to WhatsApp.
This commit is contained in:
@@ -3,8 +3,18 @@ require 'rails_helper'
|
||||
describe Whatsapp::Providers::WhatsappCloudService do
|
||||
subject(:service) { described_class.new(whatsapp_channel: whatsapp_channel) }
|
||||
|
||||
let(:conversation) { create(:conversation, inbox: whatsapp_channel.inbox) }
|
||||
let(:whatsapp_channel) { create(:channel_whatsapp, provider: 'whatsapp_cloud', validate_provider_config: false, sync_templates: false) }
|
||||
let(:message) { create(:message, message_type: :outgoing, content: 'test', inbox: whatsapp_channel.inbox) }
|
||||
|
||||
let(:message) do
|
||||
create(:message, conversation: conversation, message_type: :outgoing, content: 'test', inbox: whatsapp_channel.inbox, source_id: 'external_id')
|
||||
end
|
||||
|
||||
let(:message_with_reply) do
|
||||
create(:message, conversation: conversation, message_type: :outgoing, content: 'reply', inbox: whatsapp_channel.inbox,
|
||||
content_attributes: { in_reply_to: message.id })
|
||||
end
|
||||
|
||||
let(:response_headers) { { 'Content-Type' => 'application/json' } }
|
||||
let(:whatsapp_response) { { messages: [{ id: 'message_id' }] } }
|
||||
|
||||
@@ -19,6 +29,7 @@ describe Whatsapp::Providers::WhatsappCloudService do
|
||||
.with(
|
||||
body: {
|
||||
messaging_product: 'whatsapp',
|
||||
context: nil,
|
||||
to: '+123456789',
|
||||
text: { body: message.content },
|
||||
type: 'text'
|
||||
@@ -28,6 +39,23 @@ describe Whatsapp::Providers::WhatsappCloudService do
|
||||
expect(service.send_message('+123456789', message)).to eq 'message_id'
|
||||
end
|
||||
|
||||
it 'calls message endpoints for a reply to messages' do
|
||||
stub_request(:post, 'https://graph.facebook.com/v13.0/123456789/messages')
|
||||
.with(
|
||||
body: {
|
||||
messaging_product: 'whatsapp',
|
||||
context: {
|
||||
message_id: message.source_id
|
||||
},
|
||||
to: '+123456789',
|
||||
text: { body: message_with_reply.content },
|
||||
type: 'text'
|
||||
}.to_json
|
||||
)
|
||||
.to_return(status: 200, body: whatsapp_response.to_json, headers: response_headers)
|
||||
expect(service.send_message('+123456789', message_with_reply)).to eq 'message_id'
|
||||
end
|
||||
|
||||
it 'calls message endpoints for image attachment message messages' do
|
||||
attachment = message.attachments.new(account_id: message.account_id, file_type: :image)
|
||||
attachment.file.attach(io: Rails.root.join('spec/assets/avatar.png').open, filename: 'avatar.png', content_type: 'image/png')
|
||||
|
||||
Reference in New Issue
Block a user