Compare commits

..

4 commits

Author SHA1 Message Date
Tejaswini Chile
10f72cdf31
Merge branch 'develop' into fix/6120-whatsapp-multiple-images 2022-12-23 10:07:39 +05:30
Tejaswini Chile
bce8695d0e codeclimate fix 2022-12-22 23:40:13 +05:30
Tejaswini Chile
4988d9e99f fix: whatsapp cloud to consider multiple attachments 2022-12-22 23:37:48 +05:30
Tejaswini Chile
a356c824d0 fix: whatsapp cloud to consider multiple attachments 2022-12-22 18:43:49 +05:30
3 changed files with 20 additions and 11 deletions

View file

@ -174,7 +174,7 @@ export default {
feedback_message: this.feedbackMessage,
};
} catch (error) {
const errorMessage = error?.response?.data?.error;
const errorMessage = error?.response?.data?.message;
this.errorMessage = errorMessage || this.$t('SURVEY.API.ERROR_MESSAGE');
} finally {
this.isUpdating = false;

View file

@ -1,7 +1,10 @@
class Whatsapp::Providers::WhatsappCloudService < Whatsapp::Providers::BaseService
ATTACHMENT_TYPES = %w[image audio video].freeze
MESSAGE_CONTENT = %w[audio sticker].freeze
def send_message(phone_number, message)
if message.attachments.present?
send_attachment_message(phone_number, message)
process_attachments(phone_number, message)
else
send_text_message(phone_number, message)
end
@ -66,14 +69,20 @@ class Whatsapp::Providers::WhatsappCloudService < Whatsapp::Providers::BaseServi
process_response(response)
end
def send_attachment_message(phone_number, message)
attachment = message.attachments.first
type = %w[image audio video].include?(attachment.file_type) ? attachment.file_type : 'document'
type_content = {
'link': attachment.download_url
}
type_content['caption'] = message.content unless %w[audio sticker].include?(type)
def process_attachments(phone_number, message)
responses = []
message.attachments.each do |attachment|
responses << send_attachment_message(phone_number, message, attachment)
end
responses
end
def send_attachment_message(phone_number, message, attachment)
type = self.class::ATTACHMENT_TYPES.include?(attachment.file_type) ? attachment.file_type : 'document'
type_content = { 'link': attachment.download_url }
type_content['caption'] = message.content unless self.class::MESSAGE_CONTENT.include?(type)
type_content['filename'] = attachment.file.filename if type == 'document'
response = HTTParty.post(
"#{phone_id_path}/messages",
headers: api_headers,

View file

@ -42,7 +42,7 @@ describe Whatsapp::Providers::WhatsappCloudService do
})
)
.to_return(status: 200, body: whatsapp_response.to_json, headers: response_headers)
expect(service.send_message('+123456789', message)).to eq 'message_id'
expect(service.send_message('+123456789', message)).to eq ['message_id']
end
it 'calls message endpoints for document attachment message messages' do
@ -61,7 +61,7 @@ describe Whatsapp::Providers::WhatsappCloudService do
})
)
.to_return(status: 200, body: whatsapp_response.to_json, headers: response_headers)
expect(service.send_message('+123456789', message)).to eq 'message_id'
expect(service.send_message('+123456789', message)).to eq ['message_id']
end
end
end