wuapi 0.5.0

Rust SDK for wuapi, a WhatsApp API for developers. Link numbers by QR or pairing code, send and receive messages, manage chats, contacts, groups and channels, split them into projects and verify webhooks.
Documentation
// Generated by wuapi-codegen from the OpenAPI spec. Do not edit: run `bun run codegen`.

use crate::http::{HttpClient, Method, Request, RequestParts, encode_path};
use crate::pagination::Paginator;
use crate::types;

/// The `contacts` methods.
#[derive(Clone, Debug)]
pub struct ContactsResource {
    http: HttpClient,
}

impl ContactsResource {
    pub(crate) fn new(http: HttpClient) -> Self {
        Self { http }
    }

    /// Check numbers on WhatsApp
    ///
    /// Which numbers have WhatsApp. Read-only: works for a suspended project.
    ///
    /// `POST /v1/accounts/{accountId}/contacts/check`
    ///
    /// Sends `Idempotency-Key` (a random key, or your own with `.idempotency_key(..)`), so it is retried on timeouts, network errors, `429` and `5xx` without repeating its effect.
    pub fn check(
        &self,
        account_id: &str,
        params: types::ContactsCheckParams,
    ) -> Request<types::ContactCheckList> {
        let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/contacts/check", encode_path(account_id)))
            .body(&params)
            .keyed();
        self.http.request(parts)
    }

    /// Look up contacts
    ///
    /// About text, picture id, verified business name and device count. Read-only.
    ///
    /// `POST /v1/accounts/{accountId}/contacts/lookup`
    ///
    /// Sends `Idempotency-Key` (a random key, or your own with `.idempotency_key(..)`), so it is retried on timeouts, network errors, `429` and `5xx` without repeating its effect.
    pub fn lookup(
        &self,
        account_id: &str,
        params: types::ContactsLookupParams,
    ) -> Request<types::ContactList> {
        let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/contacts/lookup", encode_path(account_id)))
            .body(&params)
            .keyed();
        self.http.request(parts)
    }

    /// Get a profile picture
    ///
    /// The contact's profile picture, if this account can see it.
    ///
    /// `GET /v1/accounts/{accountId}/contacts/{contactId}/picture`
    ///
    /// Safe to repeat: retried on timeouts, network errors, `429` and `5xx`.
    pub fn get_picture(
        &self,
        account_id: &str,
        contact_id: &str,
        params: types::ContactsGetPictureParams,
    ) -> Request<types::Picture> {
        let parts = RequestParts::new(Method::Get, format!("/v1/accounts/{}/contacts/{}/picture", encode_path(account_id), encode_path(contact_id)))
            .query_opt("preview", params.preview.as_ref())
            .retryable();
        self.http.request(parts)
    }

    /// Get a business profile
    ///
    /// The WhatsApp Business profile of a contact.
    ///
    /// `GET /v1/accounts/{accountId}/contacts/{contactId}/business-profile`
    ///
    /// Safe to repeat: retried on timeouts, network errors, `429` and `5xx`.
    pub fn get_business_profile(
        &self,
        account_id: &str,
        contact_id: &str,
    ) -> Request<types::BusinessProfile> {
        let parts = RequestParts::new(Method::Get, format!("/v1/accounts/{}/contacts/{}/business-profile", encode_path(account_id), encode_path(contact_id)))
            .retryable();
        self.http.request(parts)
    }

    /// Subscribe to a contact's presence
    ///
    /// Receive `contact.presence_updated` events for the contact. Needs the engine's extended events; otherwise `400 not_supported`.
    ///
    /// `POST /v1/accounts/{accountId}/contacts/{contactId}/subscribe-presence`
    ///
    /// Sends `Idempotency-Key` (a random key, or your own with `.idempotency_key(..)`), so it is retried on timeouts, network errors, `429` and `5xx` without repeating its effect.
    pub fn subscribe_presence(&self, account_id: &str, contact_id: &str) -> Request<()> {
        let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/contacts/{}/subscribe-presence", encode_path(account_id), encode_path(contact_id)))
            .keyed()
            .no_content();
        self.http.request(parts)
    }

    /// Block a contact
    ///
    /// The contact can no longer message or call the account.
    ///
    /// `POST /v1/accounts/{accountId}/contacts/{contactId}/block`
    ///
    /// Sends `Idempotency-Key` (a random key, or your own with `.idempotency_key(..)`), so it is retried on timeouts, network errors, `429` and `5xx` without repeating its effect.
    pub fn block(&self, account_id: &str, contact_id: &str) -> Request<()> {
        let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/contacts/{}/block", encode_path(account_id), encode_path(contact_id)))
            .keyed()
            .no_content();
        self.http.request(parts)
    }

    /// Unblock a contact
    ///
    /// Remove the contact from the blocklist.
    ///
    /// `POST /v1/accounts/{accountId}/contacts/{contactId}/unblock`
    ///
    /// Sends `Idempotency-Key` (a random key, or your own with `.idempotency_key(..)`), so it is retried on timeouts, network errors, `429` and `5xx` without repeating its effect.
    pub fn unblock(&self, account_id: &str, contact_id: &str) -> Request<()> {
        let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/contacts/{}/unblock", encode_path(account_id), encode_path(contact_id)))
            .keyed()
            .no_content();
        self.http.request(parts)
    }

    /// List blocked contacts
    ///
    /// The account's blocklist, read live from WhatsApp. `contactId` is the contact as WhatsApp lists it (often a LID); `phone` and `lid` add the number and the LID when the account knows them.
    ///
    /// `GET /v1/accounts/{accountId}/blocklist`
    ///
    /// Safe to repeat: retried on timeouts, network errors, `429` and `5xx`.
    pub fn list_blocked(
        &self,
        account_id: &str,
        params: types::ContactsListBlockedParams,
    ) -> Paginator<types::BlockedContactList> {
        let parts = RequestParts::new(Method::Get, format!("/v1/accounts/{}/blocklist", encode_path(account_id)))
            .query_opt("limit", params.limit.as_ref())
            .retryable();
        Paginator::new(self.http.clone(), parts, "cursor", params.cursor)
    }

    /// Get the account's contact link
    ///
    /// The account's own contact QR link.
    ///
    /// `GET /v1/accounts/{accountId}/contact-link`
    ///
    /// Safe to repeat: retried on timeouts, network errors, `429` and `5xx`.
    pub fn get_link(&self, account_id: &str) -> Request<types::ContactLink> {
        let parts = RequestParts::new(Method::Get, format!("/v1/accounts/{}/contact-link", encode_path(account_id)))
            .retryable();
        self.http.request(parts)
    }

    /// Reset the account's contact link
    ///
    /// Revoke the current contact link and return a new one.
    ///
    /// `POST /v1/accounts/{accountId}/contact-link/reset`
    ///
    /// Sends `Idempotency-Key` (a random key, or your own with `.idempotency_key(..)`), so it is retried on timeouts, network errors, `429` and `5xx` without repeating its effect.
    pub fn reset_link(&self, account_id: &str) -> Request<types::ContactLink> {
        let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/contact-link/reset", encode_path(account_id)))
            .keyed();
        self.http.request(parts)
    }

    /// Resolve a contact or business link
    ///
    /// Who a contact QR link or a business message link points to. Read-only. `400 not_supported` when WhatsApp does not offer link resolution to this account.
    ///
    /// `POST /v1/accounts/{accountId}/links/resolve`
    ///
    /// Sends `Idempotency-Key` (a random key, or your own with `.idempotency_key(..)`), so it is retried on timeouts, network errors, `429` and `5xx` without repeating its effect.
    pub fn resolve_link(
        &self,
        account_id: &str,
        params: types::ContactsResolveLinkParams,
    ) -> Request<types::ResolvedLink> {
        let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/links/resolve", encode_path(account_id)))
            .body(&params)
            .keyed();
        self.http.request(parts)
    }
}