parent
e997aaceb7
commit
693f2531ab
2 changed files with 20 additions and 1 deletions
|
@ -29,6 +29,7 @@ class Whatsapp::IncomingMessageService
|
|||
def message_content(message)
|
||||
# TODO: map interactive messages back to button messages in chatwoot
|
||||
message.dig(:text, :body) ||
|
||||
message.dig(:button, :text) ||
|
||||
message.dig(:interactive, :button_reply, :title) ||
|
||||
message.dig(:interactive, :list_reply, :title)
|
||||
end
|
||||
|
@ -77,7 +78,7 @@ class Whatsapp::IncomingMessageService
|
|||
|
||||
def attach_files
|
||||
message_type = params[:messages].first[:type]
|
||||
return if %w[text interactive].include?(message_type)
|
||||
return if %w[text button interactive].include?(message_type)
|
||||
|
||||
attachment_payload = params[:messages].first[message_type.to_sym]
|
||||
attachment_file = Down.download(inbox.channel.media_url(attachment_payload[:id]), headers: inbox.channel.api_headers)
|
||||
|
|
|
@ -43,6 +43,24 @@ describe Whatsapp::IncomingMessageService do
|
|||
end
|
||||
end
|
||||
|
||||
# ref: https://github.com/chatwoot/chatwoot/issues/3795#issuecomment-1018057318
|
||||
context 'when valid template button message params' do
|
||||
it 'creates appropriate conversations, message and contacts' do
|
||||
params = {
|
||||
'contacts' => [{ 'profile' => { 'name' => 'Sojan Jose' }, 'wa_id' => '2423423243' }],
|
||||
'messages' => [{ 'from' => '2423423243', 'id' => 'SDFADSf23sfasdafasdfa',
|
||||
'button' => {
|
||||
'text' => 'Yes this is a button'
|
||||
},
|
||||
'timestamp' => '1633034394', 'type' => 'button' }]
|
||||
}.with_indifferent_access
|
||||
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
||||
expect(whatsapp_channel.inbox.conversations.count).not_to eq(0)
|
||||
expect(Contact.all.first.name).to eq('Sojan Jose')
|
||||
expect(whatsapp_channel.inbox.messages.first.content).to eq('Yes this is a button')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when valid attachment message params' do
|
||||
it 'creates appropriate conversations, message and contacts' do
|
||||
stub_request(:get, whatsapp_channel.media_url('b1c68f38-8734-4ad3-b4a1-ef0c10d683')).to_return(
|
||||
|
|
Loading…
Reference in a new issue