fix: whatsapp cloud to consider multiple attachments
This commit is contained in:
parent
34f7405689
commit
a356c824d0
1 changed files with 22 additions and 18 deletions
|
@ -1,4 +1,7 @@
|
||||||
class Whatsapp::Providers::WhatsappCloudService < Whatsapp::Providers::BaseService
|
class Whatsapp::Providers::WhatsappCloudService < Whatsapp::Providers::BaseService
|
||||||
|
ATTACHMENT_TYPE = [image, audio, video].freeze
|
||||||
|
MESSAGE_CONTENT = [audio, sticker].freeze
|
||||||
|
|
||||||
def send_message(phone_number, message)
|
def send_message(phone_number, message)
|
||||||
if message.attachments.present?
|
if message.attachments.present?
|
||||||
send_attachment_message(phone_number, message)
|
send_attachment_message(phone_number, message)
|
||||||
|
@ -67,12 +70,12 @@ class Whatsapp::Providers::WhatsappCloudService < Whatsapp::Providers::BaseServi
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_attachment_message(phone_number, message)
|
def send_attachment_message(phone_number, message)
|
||||||
attachment = message.attachments.first
|
message.attachments.each do |attachment|
|
||||||
type = %w[image audio video].include?(attachment.file_type) ? attachment.file_type : 'document'
|
type = ATTACHMENT_TYPE.include?(attachment.file_type) ? attachment.file_type : 'document'
|
||||||
type_content = {
|
type_content = {
|
||||||
'link': attachment.download_url
|
'link': attachment.download_url
|
||||||
}
|
}
|
||||||
type_content['caption'] = message.content unless %w[audio sticker].include?(type)
|
type_content['caption'] = message.content unless MESSAGE_CONTENT.include?(type)
|
||||||
type_content['filename'] = attachment.file.filename if type == 'document'
|
type_content['filename'] = attachment.file.filename if type == 'document'
|
||||||
response = HTTParty.post(
|
response = HTTParty.post(
|
||||||
"#{phone_id_path}/messages",
|
"#{phone_id_path}/messages",
|
||||||
|
@ -87,6 +90,7 @@ class Whatsapp::Providers::WhatsappCloudService < Whatsapp::Providers::BaseServi
|
||||||
|
|
||||||
process_response(response)
|
process_response(response)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def process_response(response)
|
def process_response(response)
|
||||||
if response.success?
|
if response.success?
|
||||||
|
|
Loading…
Reference in a new issue