lib/whatsapp_sdk/api/medias.rb in whatsapp_sdk-0.11.0 vs lib/whatsapp_sdk/api/medias.rb in whatsapp_sdk-0.12.0

- old
+ new

@@ -62,16 +62,19 @@ # Download Media by URL. # # @param url URL. # @param file_path [String] The file_path to download the media e.g. "tmp/downloaded_image.png". - # @param media_type [String] The media type e.g. "audio/mp4". See the supported types in the official - # documentation https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media#supported-media-types. + # @param media_type [String] The media type e.g. "audio/mp4". See possible types in the official + # documentation https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media#supported-media-types, + # but note that the API may allow more depending on the client. # @return [Api::Response] Response object. sig { params(url: String, file_path: String, media_type: String).returns(Api::Response) } def download(url:, file_path:, media_type:) - raise InvalidMediaTypeError.new(media_type: media_type) unless valid_media_type?(media_type) + # Allow download of unsupported media types, since Cloud API may decide to let it through. + # https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/discussions/127 + # raise InvalidMediaTypeError.new(media_type: media_type) unless valid_media_type?(media_type) content_type_header = map_media_type_to_content_type_header(media_type) response = download_file(url: url, file_path: file_path, content_type_header: content_type_header) response = if response.code.to_i == 200 @@ -102,10 +105,10 @@ messaging_product: "whatsapp", file: Faraday::FilePart.new(file_path, type), type: type } - response = send_request(http_method: "post", endpoint: "#{sender_id}/media", params: params) + response = send_request(http_method: "post", endpoint: "#{sender_id}/media", params: params, multipart: true) Api::Response.new( response: response, data_class_type: Api::Responses::MediaDataResponse )