Upload, inspect, delete and download WhatsApp media.
Size limits set by Meta: images (jpeg, png) 5 MB; video (mp4, 3gp) and audio (aac, mp3, ogg, opus) 16 MB; documents 100 MB; stickers (webp) 100 KB static or 500 KB animated.
To upload media from a public URL instead of bytes, use
KapsoEx.Platform.Media.upload/4.
Summary
Functions
Deletes an uploaded media file.
Downloads the bytes of a media file.
Gets media metadata, including a url and a short-lived download_url
(valid for about 5 minutes).
Uploads content (a binary) and returns its media ID.
Uploads the file at path. Options: :filename (defaults to the file's
basename) and :content_type.
Types
@type result() :: {:ok, map()} | {:error, KapsoEx.Error.t()}
Functions
@spec delete(KapsoEx.Client.t(), String.t(), String.t()) :: result()
Deletes an uploaded media file.
@spec download(KapsoEx.Client.t(), String.t(), String.t()) :: {:ok, binary()} | {:error, KapsoEx.Error.t()}
Downloads the bytes of a media file.
Fetches the metadata with get/3 and then the signed download_url, so
the media must be known to Kapso (inbound media, or outbound media shortly
after it was sent).
{:ok, bytes} = Media.download(client, media_id, phone_number_id)
@spec get(KapsoEx.Client.t(), String.t(), String.t()) :: result()
Gets media metadata, including a url and a short-lived download_url
(valid for about 5 minutes).
@spec upload(KapsoEx.Client.t(), String.t(), iodata(), keyword()) :: result()
Uploads content (a binary) and returns its media ID.
Options
:filename- required, for example"photo.jpg".:content_type- MIME type; inferred from:filenamewhen omitted.
Examples
{:ok, %{"id" => media_id}} =
Media.upload(client, phone_number_id, File.read!("photo.jpg"), filename: "photo.jpg")
Messages.send_image(client, phone_number_id, "56961567267", media_id, caption: "Hi")
@spec upload_file(KapsoEx.Client.t(), String.t(), Path.t(), keyword()) :: result()
Uploads the file at path. Options: :filename (defaults to the file's
basename) and :content_type.