chore: Add reauthorization prompt for Whatsapp Channel (#5929)

- Add reauthorization prompt for Whatsapp Channel

fixes: #5782
This commit is contained in:
Sojan Jose
2022-11-24 11:50:32 +00:00
committed by GitHub
parent 606fc9046a
commit 8ea0660862
11 changed files with 148 additions and 7 deletions

View File

@@ -96,9 +96,11 @@ class Whatsapp::IncomingMessageBaseService
return if %w[text button interactive location].include?(message_type)
attachment_payload = @processed_params[:messages].first[message_type.to_sym]
attachment_file = download_attachment_file(attachment_payload)
@message.content ||= attachment_payload[:caption]
attachment_file = download_attachment_file(attachment_payload)
return if attachment_file.blank?
@message.attachments.new(
account_id: @message.account_id,
file_type: file_content_type(message_type),

View File

@@ -10,6 +10,8 @@ class Whatsapp::IncomingMessageWhatsappCloudService < Whatsapp::IncomingMessageB
def download_attachment_file(attachment_payload)
url_response = HTTParty.get(inbox.channel.media_url(attachment_payload[:id]), headers: inbox.channel.api_headers)
Down.download(url_response.parsed_response['url'], headers: inbox.channel.api_headers)
# 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?
end
end