feat: Add support for Whatsapp template messages in the UI (#4711)

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
Fayaz Ahmed
2022-06-07 17:33:33 +05:30
committed by GitHub
parent 56f668db6b
commit bad24f97ab
22 changed files with 733 additions and 54 deletions

View File

@@ -1,6 +1,13 @@
require 'rails_helper'
describe Whatsapp::SendOnWhatsappService do
template_params = {
name: 'sample_shipping_confirmation',
namespace: '23423423_2342423_324234234_2343224',
language: 'en_US',
processed_params: { '1' => '3' }
}
describe '#perform' do
before do
stub_request(:post, 'https://waba.360dialog.io/v1/configs/webhook')
@@ -54,6 +61,30 @@ describe Whatsapp::SendOnWhatsappService do
expect(message.reload.source_id).to eq('123456789')
end
it 'calls channel.send_template if template_params are present' do
message = create(:message, additional_attributes: { template_params: template_params },
content: 'Your package will be delivered in 3 business days.', conversation: conversation, message_type: :outgoing)
allow(HTTParty).to receive(:post).and_return(whatsapp_request)
allow(whatsapp_request).to receive(:success?).and_return(true)
allow(whatsapp_request).to receive(:[]).with('messages').and_return([{ 'id' => '123456789' }])
expect(HTTParty).to receive(:post).with(
'https://waba.360dialog.io/v1/messages',
headers: { 'D360-API-KEY' => 'test_key', 'Content-Type' => 'application/json' },
body: {
to: '123456789',
template: {
name: 'sample_shipping_confirmation',
namespace: '23423423_2342423_324234234_2343224',
language: { 'policy': 'deterministic', 'code': 'en_US' },
components: [{ 'type': 'body', 'parameters': [{ 'type': 'text', 'text': '3' }] }]
},
type: 'template'
}.to_json
)
described_class.new(message: message).perform
expect(message.reload.source_id).to eq('123456789')
end
it 'calls channel.send_template when template has regexp characters' do
message = create(
:message,