WhatsappElixir.Upload (whatsapp_elixir v0.1.9)
View SourceHandles CRUD operations for media using the WhatsApp Cloud API.
This module provides functionalities for uploading, querying, deleting, and downloading media files associated with your WhatsApp Business account.
### Endpoints The following endpoints are used for media management:
- POST /PHONE_NUMBER_ID/media: Upload media.
- GET /MEDIA_ID: Retrieve the URL for a specific media.
- DELETE /MEDIA_ID: Delete a specific media.
- GET /MEDIA_URL: Download media from a media URL.
### Supported Media Types Refer to the official documentation for details on supported media types, size limits, and other constraints: WhatsApp Cloud API - Media Reference
Summary
Functions
Downloads media from a given media_url and saves it to the specified file path.
Queries the URL of a media item using its media ID.
Uploads media to the WhatsApp Cloud API.
Functions
Downloads media from a given media_url and saves it to the specified file path.
Arguments
media_url(string): The URL of the media to be downloaded.mime_type(string): The MIME type of the media (e.g.,"image/png","video/mp4").file_path(string, optional): The file path to save the media. Do not include the file extension. Defaults to"temp".
Returns
{:ok, file_path}on successful download.{:error, reason}if the download fails.
Notes
The media_url expires after 5 minutes. To download the file after the URL has expired, you will need to request a new URL.
Queries the URL of a media item using its media ID.
Parameters:
media_id(string): ID of the media to query.custom_config(optional list): Custom configuration for the HTTP request.
Returns:
{:ok, url}on success.{:error, reason}on failure.
Example:
Upload.query_media_url("575674161631216")
Uploads media to the WhatsApp Cloud API.
Parameters:
media_path(string): Path to the media file to upload.mime_type(string): MIME type of the media (e.g., "image/png").custom_config(optional list): Custom configuration for the HTTP request.
Returns:
{:ok, response}on success.{:error, response}on failure.
Example:
Upload.upload_media("new.png", "image/png")