/*
* 1MSG WhatsApp Business API (Public)
*
* Public client API for sending messages, managing groups, flows, and templates. This is the API exposed to end customers via platform.1msg.io **Authentication:** All requests require `token` query parameter with JWT or API key. **Documentation:** https://help.1msg.io/platform-1msg/getting-start/quick-start **API Docs:** https://docs.1msg.io/
*
* The version of the OpenAPI document: 1.0.0
* Contact: support@1msg.io
* Generated by: https://openapi-generator.tech
*/
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
/// struct for typed errors of method [`create_read_message`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateReadMessageError {
Status401(models::CreateReadMessage401Response),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`create_upload_media`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateUploadMediaError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_media`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteMediaError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_media_legacy`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteMediaLegacyError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_mm_lite_status`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetMmLiteStatusError {
Status401(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_messages`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListMessagesError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`retrieve_media`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RetrieveMediaError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`send_address_message`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SendAddressMessageError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status429(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`send_button`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SendButtonError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status429(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`send_carousel`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SendCarouselError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status429(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`send_contact`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SendContactError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status429(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`send_cta_url`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SendCtaUrlError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status429(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`send_file`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SendFileError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status429(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`send_flow`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SendFlowError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status429(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`send_list`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SendListError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status429(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`send_location`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SendLocationError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status429(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`send_location_request`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SendLocationRequestError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status429(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`send_message`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SendMessageError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status429(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`send_order_details`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SendOrderDetailsError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`send_payment_request`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SendPaymentRequestError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`send_product`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SendProductError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status429(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`send_reaction`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SendReactionError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status429(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`send_sticker`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SendStickerError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status429(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
pub async fn create_read_message(configuration: &configuration::Configuration, token: &str, message_id: Option<&str>, msg_id: Option<&str>, typing_indicator: Option<bool>) -> Result<models::CreateReadMessage200Response, Error<CreateReadMessageError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let p_form_message_id = message_id;
let p_form_msg_id = msg_id;
let p_form_typing_indicator = typing_indicator;
let uri_str = format!("{}/readMessage", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let mut multipart_form_params = std::collections::HashMap::new();
if let Some(param_value) = p_form_message_id {
multipart_form_params.insert("messageId", param_value.to_string());
}
if let Some(param_value) = p_form_msg_id {
multipart_form_params.insert("msgId", param_value.to_string());
}
if let Some(param_value) = p_form_typing_indicator {
multipart_form_params.insert("typingIndicator", param_value.to_string());
}
req_builder = req_builder.form(&multipart_form_params);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateReadMessage200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::CreateReadMessage200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CreateReadMessageError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn create_upload_media(configuration: &configuration::Configuration, token: &str, request_body: Option<std::collections::HashMap<String, serde_json::Value>>) -> Result<(), Error<CreateUploadMediaError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let p_body_request_body = request_body;
let uri_str = format!("{}/uploadMedia", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_body_request_body);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<CreateUploadMediaError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Delete previously uploaded media by numeric `mediaId` (from `/uploadMedia`). This is the canonical deletion endpoint and uses the REST `DELETE` verb on the media resource path. The older `POST /deleteMedia` is a deprecated alias.
pub async fn delete_media(configuration: &configuration::Configuration, token: &str, media_id: &str) -> Result<models::SuccessResponse, Error<DeleteMediaError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let p_path_media_id = media_id;
let uri_str = format!("{}/media/{mediaId}", configuration.base_path, mediaId=crate::apis::urlencode(p_path_media_id));
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SuccessResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SuccessResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<DeleteMediaError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// **Deprecated.** Use `DELETE /media/{mediaId}` instead. This POST alias is kept for backward compatibility with earlier integrations. New integrations should call `DELETE /media/{mediaId}`: 1msg follows REST conventions for resource deletion going forward (delete a resource with the `DELETE` verb on its resource path).
#[deprecated]
pub async fn delete_media_legacy(configuration: &configuration::Configuration, token: &str, delete_media_legacy_request: models::DeleteMediaLegacyRequest) -> Result<models::SuccessResponse, Error<DeleteMediaLegacyError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let p_body_delete_media_legacy_request = delete_media_legacy_request;
let uri_str = format!("{}/deleteMedia", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_body_delete_media_legacy_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SuccessResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SuccessResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<DeleteMediaLegacyError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_mm_lite_status(configuration: &configuration::Configuration, token: &str) -> Result<models::GetMmLiteStatus200Response, Error<GetMmLiteStatusError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let uri_str = format!("{}/mmLiteStatus", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetMmLiteStatus200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetMmLiteStatus200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetMmLiteStatusError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn list_messages(configuration: &configuration::Configuration, token: &str) -> Result<models::ListMessages200Response, Error<ListMessagesError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let uri_str = format!("{}/messages", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListMessages200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListMessages200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListMessagesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Get WABA media URL and metadata by mediaId (from uploadMedia). The returned `url` is temporary and typically expires within ~5 minutes.
pub async fn retrieve_media(configuration: &configuration::Configuration, token: &str, media_id: &str) -> Result<models::RetrieveMedia200Response, Error<RetrieveMediaError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let p_query_media_id = media_id;
let uri_str = format!("{}/retrieveMedia", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
req_builder = req_builder.query(&[("mediaId", &p_query_media_id.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RetrieveMedia200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RetrieveMedia200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<RetrieveMediaError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Request shipping address from the user (WhatsApp interactive `address_message`). **India and Singapore only.** Requires: - Business WhatsApp number registered in that country - Recipient phone matching the country (`+91` ↔ `IN`, `+65` ↔ `SG`) Pass `country: \"IN\"` or `country: \"SG\"`. Eligibility is validated upstream; mismatches (e.g. Singapore phone with `country: \"IN\"`) return errors such as `Unsupported Interactive Message type` (HTTP 200 with `sent: false`). Optional action parameters: `values`, `saved_addresses`, `validation_errors`.
pub async fn send_address_message(configuration: &configuration::Configuration, token: &str, send_address_message_request: models::SendAddressMessageRequest) -> Result<models::MessageSentResponse, Error<SendAddressMessageError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let p_body_send_address_message_request = send_address_message_request;
let uri_str = format!("{}/sendAddressMessage", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_body_send_address_message_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MessageSentResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MessageSentResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SendAddressMessageError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn send_button(configuration: &configuration::Configuration, token: &str, send_button_request: Option<models::SendButtonRequest>) -> Result<models::MessageSentResponse, Error<SendButtonError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let p_body_send_button_request = send_button_request;
let uri_str = format!("{}/sendButton", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_body_send_button_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MessageSentResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MessageSentResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SendButtonError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// You can send product cards via Carousel in two ways: Template messages: do not require a 24-hour customer service window between you and the recipient. Use sendTemplate. Free-form messages: can be sent only when a customer service window is open between you and the recipient. Use sendCarousel. The message structure in /sendCarousel is largely similar to sending a template. However, in this case you must explicitly specify all elements that are created in advance when working with templates. This is because the message is sent without using a template. In /sendCarousel, for sending a Catalog Carousel there can be either 1 URL button or one or more quick reply buttons.
pub async fn send_carousel(configuration: &configuration::Configuration, token: &str, params: Vec<serde_json::Value>, body: Option<&str>, quoted_msg_id: Option<&str>, chat_id: Option<&str>, phone: Option<i32>) -> Result<models::MessageSentResponse, Error<SendCarouselError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let p_form_params = params;
let p_form_body = body;
let p_form_quoted_msg_id = quoted_msg_id;
let p_form_chat_id = chat_id;
let p_form_phone = phone;
let uri_str = format!("{}/sendCarousel", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let mut multipart_form_params = std::collections::HashMap::new();
if let Some(param_value) = p_form_body {
multipart_form_params.insert("body", param_value.to_string());
}
multipart_form_params.insert("params", p_form_params.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string());
if let Some(param_value) = p_form_quoted_msg_id {
multipart_form_params.insert("quotedMsgId", param_value.to_string());
}
if let Some(param_value) = p_form_chat_id {
multipart_form_params.insert("chatId", param_value.to_string());
}
if let Some(param_value) = p_form_phone {
multipart_form_params.insert("phone", param_value.to_string());
}
req_builder = req_builder.form(&multipart_form_params);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MessageSentResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MessageSentResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SendCarouselError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn send_contact(configuration: &configuration::Configuration, token: &str, send_contact_request: Option<models::SendContactRequest>) -> Result<models::MessageSentResponse, Error<SendContactError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let p_body_send_contact_request = send_contact_request;
let uri_str = format!("{}/sendContact", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_body_send_contact_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MessageSentResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MessageSentResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SendContactError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Send an interactive message with a single call-to-action URL button.
pub async fn send_cta_url(configuration: &configuration::Configuration, token: &str, send_cta_url_request: models::SendCtaUrlRequest) -> Result<models::MessageSentResponse, Error<SendCtaUrlError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let p_body_send_cta_url_request = send_cta_url_request;
let uri_str = format!("{}/sendCtaUrl", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_body_send_cta_url_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MessageSentResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MessageSentResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SendCtaUrlError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Send a file to an existing chat. (Only if the dialogue has an Open Session). Only one of two parameters is needed to determine the destination - chatId or phone.
pub async fn send_file(configuration: &configuration::Configuration, token: &str, body: Option<&str>, filename: Option<&str>, media_id: Option<&str>, media_type: Option<&str>, voice: Option<bool>, caption: Option<&str>, quoted_msg_id: Option<&str>, chat_id: Option<&str>, phone: Option<i32>) -> Result<models::MessageSentResponse, Error<SendFileError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let p_form_body = body;
let p_form_filename = filename;
let p_form_media_id = media_id;
let p_form_media_type = media_type;
let p_form_voice = voice;
let p_form_caption = caption;
let p_form_quoted_msg_id = quoted_msg_id;
let p_form_chat_id = chat_id;
let p_form_phone = phone;
let uri_str = format!("{}/sendFile", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let mut multipart_form_params = std::collections::HashMap::new();
if let Some(param_value) = p_form_body {
multipart_form_params.insert("body", param_value.to_string());
}
if let Some(param_value) = p_form_filename {
multipart_form_params.insert("filename", param_value.to_string());
}
if let Some(param_value) = p_form_media_id {
multipart_form_params.insert("mediaId", param_value.to_string());
}
if let Some(param_value) = p_form_media_type {
multipart_form_params.insert("mediaType", param_value.to_string());
}
if let Some(param_value) = p_form_voice {
multipart_form_params.insert("voice", param_value.to_string());
}
if let Some(param_value) = p_form_caption {
multipart_form_params.insert("caption", param_value.to_string());
}
if let Some(param_value) = p_form_quoted_msg_id {
multipart_form_params.insert("quotedMsgId", param_value.to_string());
}
if let Some(param_value) = p_form_chat_id {
multipart_form_params.insert("chatId", param_value.to_string());
}
if let Some(param_value) = p_form_phone {
multipart_form_params.insert("phone", param_value.to_string());
}
req_builder = req_builder.form(&multipart_form_params);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MessageSentResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MessageSentResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SendFileError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Send Interactive WhatsApp Flow message to an existing chat. (Only if the dialogue has an Open Session). Only one of two parameters is needed to determine the destination - chatId or phone. Use this method to send a published WhatsApp Flow as a service (interactive) message. If the 24-hour window is closed, send a template with a FLOW button via /sendTemplate.
pub async fn send_flow(configuration: &configuration::Configuration, token: &str, body: &str, flow_id: &str, flow_token: &str, flow_cta: &str, header: Option<models::models::SendFlowRequestHeader>, footer: Option<&str>, flow_action: Option<&str>, flow_action_payload: Option<models::serde_json::Value>, flow_message_version: Option<&str>, mode: Option<&str>, flow_action_data: Option<models::serde_json::Value>, flow_action_screen: Option<&str>, quoted_msg_id: Option<&str>, chat_id: Option<&str>, phone: Option<i32>) -> Result<models::MessageSentResponse, Error<SendFlowError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let p_form_body = body;
let p_form_flow_id = flow_id;
let p_form_flow_token = flow_token;
let p_form_flow_cta = flow_cta;
let p_form_header = header;
let p_form_footer = footer;
let p_form_flow_action = flow_action;
let p_form_flow_action_payload = flow_action_payload;
let p_form_flow_message_version = flow_message_version;
let p_form_mode = mode;
let p_form_flow_action_data = flow_action_data;
let p_form_flow_action_screen = flow_action_screen;
let p_form_quoted_msg_id = quoted_msg_id;
let p_form_chat_id = chat_id;
let p_form_phone = phone;
let uri_str = format!("{}/sendFlow", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let mut multipart_form_params = std::collections::HashMap::new();
multipart_form_params.insert("body", p_form_body.to_string());
if let Some(param_value) = p_form_header {
multipart_form_params.insert("header", param_value.to_string());
}
if let Some(param_value) = p_form_footer {
multipart_form_params.insert("footer", param_value.to_string());
}
multipart_form_params.insert("flowId", p_form_flow_id.to_string());
multipart_form_params.insert("flowToken", p_form_flow_token.to_string());
multipart_form_params.insert("flowCta", p_form_flow_cta.to_string());
if let Some(param_value) = p_form_flow_action {
multipart_form_params.insert("flowAction", param_value.to_string());
}
if let Some(param_value) = p_form_flow_action_payload {
multipart_form_params.insert("flowActionPayload", param_value.to_string());
}
if let Some(param_value) = p_form_flow_message_version {
multipart_form_params.insert("flowMessageVersion", param_value.to_string());
}
if let Some(param_value) = p_form_mode {
multipart_form_params.insert("mode", param_value.to_string());
}
if let Some(param_value) = p_form_flow_action_data {
multipart_form_params.insert("flowActionData", param_value.to_string());
}
if let Some(param_value) = p_form_flow_action_screen {
multipart_form_params.insert("flowActionScreen", param_value.to_string());
}
if let Some(param_value) = p_form_quoted_msg_id {
multipart_form_params.insert("quotedMsgId", param_value.to_string());
}
if let Some(param_value) = p_form_chat_id {
multipart_form_params.insert("chatId", param_value.to_string());
}
if let Some(param_value) = p_form_phone {
multipart_form_params.insert("phone", param_value.to_string());
}
req_builder = req_builder.form(&multipart_form_params);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MessageSentResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MessageSentResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SendFlowError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn send_list(configuration: &configuration::Configuration, token: &str, send_list_request: Option<models::SendListRequest>) -> Result<models::MessageSentResponse, Error<SendListError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let p_body_send_list_request = send_list_request;
let uri_str = format!("{}/sendList", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_body_send_list_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MessageSentResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MessageSentResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SendListError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Send a location to an existing chat. (Only if the dialogue has an Open Session). Only one of two parameters is needed to determine the destination - chatId or phone.
pub async fn send_location(configuration: &configuration::Configuration, token: &str, lat: &str, lng: &str, address: Option<&str>, name: Option<&str>, quoted_msg_id: Option<&str>, chat_id: Option<&str>, phone: Option<i32>) -> Result<models::MessageSentResponse, Error<SendLocationError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let p_form_lat = lat;
let p_form_lng = lng;
let p_form_address = address;
let p_form_name = name;
let p_form_quoted_msg_id = quoted_msg_id;
let p_form_chat_id = chat_id;
let p_form_phone = phone;
let uri_str = format!("{}/sendLocation", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let mut multipart_form_params = std::collections::HashMap::new();
multipart_form_params.insert("lat", p_form_lat.to_string());
multipart_form_params.insert("lng", p_form_lng.to_string());
if let Some(param_value) = p_form_address {
multipart_form_params.insert("address", param_value.to_string());
}
if let Some(param_value) = p_form_name {
multipart_form_params.insert("name", param_value.to_string());
}
if let Some(param_value) = p_form_quoted_msg_id {
multipart_form_params.insert("quotedMsgId", param_value.to_string());
}
if let Some(param_value) = p_form_chat_id {
multipart_form_params.insert("chatId", param_value.to_string());
}
if let Some(param_value) = p_form_phone {
multipart_form_params.insert("phone", param_value.to_string());
}
req_builder = req_builder.form(&multipart_form_params);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MessageSentResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MessageSentResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SendLocationError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn send_location_request(configuration: &configuration::Configuration, token: &str, send_location_request_request: Option<models::SendLocationRequestRequest>) -> Result<models::MessageSentResponse, Error<SendLocationRequestError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let p_body_send_location_request_request = send_location_request_request;
let uri_str = format!("{}/sendLocationRequest", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_body_send_location_request_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MessageSentResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MessageSentResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SendLocationRequestError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Send a message to an existing chat. (Only if the dialogue has an Open Session). The message will be added to the queue for sending and delivered even if the phone is disconnected from the Internet or authorization is not passed. Only one of two parameters is needed to determine the destination - chatId or phone.
pub async fn send_message(configuration: &configuration::Configuration, token: &str, body: &str, quoted_msg_id: Option<&str>, chat_id: Option<&str>, phone: Option<i32>) -> Result<models::MessageSentResponse, Error<SendMessageError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let p_form_body = body;
let p_form_quoted_msg_id = quoted_msg_id;
let p_form_chat_id = chat_id;
let p_form_phone = phone;
let uri_str = format!("{}/sendMessage", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let mut multipart_form_params = std::collections::HashMap::new();
multipart_form_params.insert("body", p_form_body.to_string());
if let Some(param_value) = p_form_quoted_msg_id {
multipart_form_params.insert("quotedMsgId", param_value.to_string());
}
if let Some(param_value) = p_form_chat_id {
multipart_form_params.insert("chatId", param_value.to_string());
}
if let Some(param_value) = p_form_phone {
multipart_form_params.insert("phone", param_value.to_string());
}
req_builder = req_builder.form(&multipart_form_params);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MessageSentResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MessageSentResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SendMessageError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Send a WhatsApp **order details** payment / invoice message using a pre-approved **Utility** template that has an `ORDER_DETAILS` button. **India only** (WhatsApp Payments India). Requires: - India WhatsApp Business number - Commerce enabled on the channel (`GET`/`POST /commerce`) - Approved template with an `ORDER_DETAILS` button Use this method when you need structured fields (`order`, `referenceId`, `currency`, `paymentSettings`). The API appends a template button `sub_type: order_details` and sends via the same path as `POST /sendTemplate`. Works **outside the 24-hour session window** (template message). You can also send the same payload yourself with `POST /sendTemplate` by including a button component in `params`: ```json { \"type\": \"button\", \"sub_type\": \"order_details\", \"index\": 0, \"parameters\": [{ \"type\": \"action\", \"action\": { \"order_details\": { \"reference_id\": \"order-123\", \"currency\": \"INR\", \"order\": { \"status\": \"pending\", \"items\": [], \"subtotal\": { \"offset\": 100, \"value\": 50000 } } } } }] } ```
pub async fn send_order_details(configuration: &configuration::Configuration, token: &str, send_order_details_request: models::SendOrderDetailsRequest) -> Result<models::MessageSentResponse, Error<SendOrderDetailsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let p_body_send_order_details_request = send_order_details_request;
let uri_str = format!("{}/sendOrderDetails", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_body_send_order_details_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MessageSentResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MessageSentResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SendOrderDetailsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Send a regional payment request interactive message (beta scaffold). `region` must be IN, SG, or BR. Payload shape follows Meta regional payments docs; verify on stage before production use. Full regional builders are not implemented yet.
pub async fn send_payment_request(configuration: &configuration::Configuration, token: &str, send_payment_request_request: models::SendPaymentRequestRequest) -> Result<models::MessageSentResponse, Error<SendPaymentRequestError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let p_body_send_payment_request_request = send_payment_request_request;
let uri_str = format!("{}/sendPaymentRequest", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_body_send_payment_request_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MessageSentResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MessageSentResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SendPaymentRequestError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn send_product(configuration: &configuration::Configuration, token: &str, request_body: Option<std::collections::HashMap<String, serde_json::Value>>) -> Result<models::MessageSentResponse, Error<SendProductError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let p_body_request_body = request_body;
let uri_str = format!("{}/sendProduct", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_body_request_body);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MessageSentResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MessageSentResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SendProductError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn send_reaction(configuration: &configuration::Configuration, token: &str, send_reaction_request: Option<models::SendReactionRequest>) -> Result<models::MessageSentResponse, Error<SendReactionError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let p_body_send_reaction_request = send_reaction_request;
let uri_str = format!("{}/sendReaction", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_body_send_reaction_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MessageSentResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MessageSentResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SendReactionError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Send a WhatsApp sticker by mediaId or link URL.
pub async fn send_sticker(configuration: &configuration::Configuration, token: &str, send_sticker_request: models::SendStickerRequest) -> Result<models::MessageSentResponse, Error<SendStickerError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_token = token;
let p_body_send_sticker_request = send_sticker_request;
let uri_str = format!("{}/sendSticker", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("token", &p_query_token.to_string())]);
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.query(&[("token", value)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_body_send_sticker_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MessageSentResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MessageSentResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SendStickerError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}