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;

/// WhatsApp channels: follow, read, react. Post with `POST /v1/messages` and `to` set to the channel id.
#[derive(Clone, Debug)]
pub struct ChannelsResource {
    http: HttpClient,
}

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

    /// List followed channels
    ///
    /// Channels the account follows, read live from WhatsApp.
    ///
    /// `GET /v1/accounts/{accountId}/channels`
    ///
    /// Safe to repeat: retried on timeouts, network errors, `429` and `5xx`.
    pub fn list(
        &self,
        account_id: &str,
        params: types::ChannelsListParams,
    ) -> Paginator<types::ChannelList> {
        let parts = RequestParts::new(Method::Get, format!("/v1/accounts/{}/channels", encode_path(account_id)))
            .query_opt("limit", params.limit.as_ref())
            .retryable();
        Paginator::new(self.http.clone(), parts, "cursor", params.cursor)
    }

    /// Create a channel
    ///
    /// The account becomes its owner. Post to it with `POST /v1/messages` and `to` set to its id.
    ///
    /// `POST /v1/accounts/{accountId}/channels`
    ///
    /// 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 create(
        &self,
        account_id: &str,
        params: types::ChannelsCreateParams,
    ) -> Request<types::Channel> {
        let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/channels", encode_path(account_id)))
            .body(&params)
            .keyed();
        self.http.request(parts)
    }

    /// Preview a channel invite
    ///
    /// The channel behind an invite code.
    ///
    /// `GET /v1/accounts/{accountId}/channels/invites/{code}`
    ///
    /// Safe to repeat: retried on timeouts, network errors, `429` and `5xx`.
    pub fn get_invite(&self, account_id: &str, code: &str) -> Request<types::Channel> {
        let parts = RequestParts::new(Method::Get, format!("/v1/accounts/{}/channels/invites/{}", encode_path(account_id), encode_path(code)))
            .retryable();
        self.http.request(parts)
    }

    /// Get a channel
    ///
    /// A channel, read live from WhatsApp.
    ///
    /// `GET /v1/accounts/{accountId}/channels/{channelId}`
    ///
    /// Safe to repeat: retried on timeouts, network errors, `429` and `5xx`.
    pub fn get(&self, account_id: &str, channel_id: &str) -> Request<types::Channel> {
        let parts = RequestParts::new(Method::Get, format!("/v1/accounts/{}/channels/{}", encode_path(account_id), encode_path(channel_id)))
            .retryable();
        self.http.request(parts)
    }

    /// Follow a channel
    ///
    /// Start receiving the channel's messages.
    ///
    /// `POST /v1/accounts/{accountId}/channels/{channelId}/follow`
    ///
    /// 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 follow(&self, account_id: &str, channel_id: &str) -> Request<()> {
        let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/channels/{}/follow", encode_path(account_id), encode_path(channel_id)))
            .keyed()
            .no_content();
        self.http.request(parts)
    }

    /// Unfollow a channel
    ///
    /// Stop following the channel.
    ///
    /// `POST /v1/accounts/{accountId}/channels/{channelId}/unfollow`
    ///
    /// 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 unfollow(&self, account_id: &str, channel_id: &str) -> Request<()> {
        let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/channels/{}/unfollow", encode_path(account_id), encode_path(channel_id)))
            .keyed()
            .no_content();
        self.http.request(parts)
    }

    /// Mute a channel
    ///
    /// Mute the channel's notifications.
    ///
    /// `POST /v1/accounts/{accountId}/channels/{channelId}/mute`
    ///
    /// 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 mute(&self, account_id: &str, channel_id: &str) -> Request<()> {
        let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/channels/{}/mute", encode_path(account_id), encode_path(channel_id)))
            .keyed()
            .no_content();
        self.http.request(parts)
    }

    /// Unmute a channel
    ///
    /// Turn the channel's notifications back on.
    ///
    /// `POST /v1/accounts/{accountId}/channels/{channelId}/unmute`
    ///
    /// 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 unmute(&self, account_id: &str, channel_id: &str) -> Request<()> {
        let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/channels/{}/unmute", encode_path(account_id), encode_path(channel_id)))
            .keyed()
            .no_content();
        self.http.request(parts)
    }

    /// List a channel's messages
    ///
    /// Messages in the channel, newest first, read live from WhatsApp.
    ///
    /// `GET /v1/accounts/{accountId}/channels/{channelId}/messages`
    ///
    /// Safe to repeat: retried on timeouts, network errors, `429` and `5xx`.
    pub fn list_messages(
        &self,
        account_id: &str,
        channel_id: &str,
        params: types::ChannelsListMessagesParams,
    ) -> Paginator<types::ChannelMessageList> {
        let parts = RequestParts::new(Method::Get, format!("/v1/accounts/{}/channels/{}/messages", encode_path(account_id), encode_path(channel_id)))
            .query_opt("limit", params.limit.as_ref())
            .retryable();
        Paginator::new(self.http.clone(), parts, "cursor", params.cursor)
    }

    /// React to a channel message
    ///
    /// An empty `emoji` removes the reaction.
    ///
    /// `POST /v1/accounts/{accountId}/channels/{channelId}/messages/{channelMessageId}/react`
    ///
    /// 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 react(
        &self,
        account_id: &str,
        channel_id: &str,
        channel_message_id: &str,
        params: types::ChannelsReactParams,
    ) -> Request<()> {
        let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/channels/{}/messages/{}/react", encode_path(account_id), encode_path(channel_id), encode_path(channel_message_id)))
            .body(&params)
            .keyed()
            .no_content();
        self.http.request(parts)
    }

    /// Mark channel messages viewed
    ///
    /// Count the account as a viewer of these messages.
    ///
    /// `POST /v1/accounts/{accountId}/channels/{channelId}/mark-viewed`
    ///
    /// 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 mark_viewed(
        &self,
        account_id: &str,
        channel_id: &str,
        params: types::ChannelsMarkViewedParams,
    ) -> Request<()> {
        let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/channels/{}/mark-viewed", encode_path(account_id), encode_path(channel_id)))
            .body(&params)
            .keyed()
            .no_content();
        self.http.request(parts)
    }
}