2022-07-06 19:45:03 +00:00
|
|
|
# https://docs.360dialog.com/whatsapp-api/whatsapp-api/media
|
|
|
|
# https://developers.facebook.com/docs/whatsapp/api/media/
|
|
|
|
|
|
|
|
class Whatsapp::IncomingMessageWhatsappCloudService < Whatsapp::IncomingMessageBaseService
|
|
|
|
private
|
|
|
|
|
|
|
|
def processed_params
|
|
|
|
@processed_params ||= params[:entry].first['changes'].first['value']
|
|
|
|
end
|
|
|
|
|
|
|
|
def download_attachment_file(attachment_payload)
|
|
|
|
url_response = HTTParty.get(inbox.channel.media_url(attachment_payload[:id]), headers: inbox.channel.api_headers)
|
2022-11-24 11:50:32 +00:00
|
|
|
# This url response will be failure if the access token has expired.
|
|
|
|
inbox.channel.authorization_error! if url_response.unauthorized?
|
|
|
|
Down.download(url_response.parsed_response['url'], headers: inbox.channel.api_headers) if url_response.success?
|
2022-07-06 19:45:03 +00:00
|
|
|
end
|
|
|
|
end
|