feat: Read/Delivery status for Whatsapp Cloud API (#5157)
Process field statuses received in webhook WhatsApp cloud API ref: #1021 Co-authored-by: Sojan <sojan@pepalo.com> Co-authored-by: Nithin David <1277421+nithindavid@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
a397f01692
commit
edcbd53425
@@ -70,6 +70,46 @@ describe Whatsapp::IncomingMessageService do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when valid status params' do
|
||||
let(:from) { '2423423243' }
|
||||
let(:contact_inbox) { create(:contact_inbox, inbox: whatsapp_channel.inbox, source_id: from) }
|
||||
let(:params) do
|
||||
{
|
||||
'contacts' => [{ 'profile' => { 'name' => 'Sojan Jose' }, 'wa_id' => from }],
|
||||
'messages' => [{ 'from' => from, 'id' => from, 'text' => { 'body' => 'Test' },
|
||||
'timestamp' => '1633034394', 'type' => 'text' }]
|
||||
}.with_indifferent_access
|
||||
end
|
||||
|
||||
before do
|
||||
create(:conversation, inbox: whatsapp_channel.inbox, contact_inbox: contact_inbox)
|
||||
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
||||
end
|
||||
|
||||
it 'update status message to read' do
|
||||
status_params = {
|
||||
'statuses' => [{ 'recipient_id' => from, 'id' => from, 'status' => 'read' }]
|
||||
}.with_indifferent_access
|
||||
message = Message.find_by!(source_id: from)
|
||||
expect(message.status).to eq('sent')
|
||||
described_class.new(inbox: whatsapp_channel.inbox, params: status_params).perform
|
||||
expect(message.reload.status).to eq('read')
|
||||
end
|
||||
|
||||
it 'update status message to failed' do
|
||||
status_params = {
|
||||
'statuses' => [{ 'recipient_id' => from, 'id' => from, 'status' => 'failed',
|
||||
'errors' => [{ 'code': 123, 'title': 'abc' }] }]
|
||||
}.with_indifferent_access
|
||||
|
||||
message = Message.find_by!(source_id: from)
|
||||
expect(message.status).to eq('sent')
|
||||
described_class.new(inbox: whatsapp_channel.inbox, params: status_params).perform
|
||||
expect(message.reload.status).to eq('failed')
|
||||
expect(message.external_error).to eq('123: abc')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when valid interactive message params' do
|
||||
it 'creates appropriate conversations, message and contacts' do
|
||||
params = {
|
||||
|
||||
Reference in New Issue
Block a user