wuapi 0.13.1

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;

/// A hosted page you send to someone else, your customer, a store manager or a sales rep, so they link their own WhatsApp into one of your projects without an account, a dashboard or an API key. The page is public at `https://wuapi.dev/invite/{token}`, `noindex`, and shows nothing about your other projects, accounts or invitations.
#[derive(Clone, Debug)]
pub struct InvitationsResource {
    http: HttpClient,
}

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

    /// Create an invitation
    ///
    /// A hosted page (`url`) where someone else links their own WhatsApp into your project: they pick where the number's proxy exits (unless you set `proxyLocation`), then scan a QR code or type a pairing code. The account is created in the project when they start, and `invitation.status_changed` fires at each step. With `inviteeEmail`, the invitation is emailed when email is enabled (`emailSentAt`).
    ///
    /// `POST /v1/invitations`
    ///
    /// 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, params: types::InvitationsCreateParams) -> Request<types::Invitation> {
        let parts = RequestParts::new(Method::Post, "/v1/invitations").body(&params).keyed();
        self.http.request(parts)
    }

    /// List invitations
    ///
    /// Invitations in scope, newest first. `url` is always `null` here.
    ///
    /// `GET /v1/invitations`
    ///
    /// Safe to repeat: retried on timeouts, network errors, `429` and `5xx`.
    pub fn list(&self, params: types::InvitationsListParams) -> Paginator<types::InvitationList> {
        let parts = RequestParts::new(Method::Get, "/v1/invitations")
            .query_opt("status", params.status.as_ref())
            .query_opt("limit", params.limit.as_ref())
            .query_opt("projectId", params.project_id.as_ref())
            .retryable();
        Paginator::new(self.http.clone(), parts, "cursor", params.cursor)
    }

    /// Get an invitation
    ///
    /// `url` is always `null` here.
    ///
    /// `GET /v1/invitations/{invitationId}`
    ///
    /// Safe to repeat: retried on timeouts, network errors, `429` and `5xx`.
    pub fn get(&self, invitation_id: &str) -> Request<types::Invitation> {
        let parts = RequestParts::new(Method::Get, format!("/v1/invitations/{}", encode_path(invitation_id)))
            .retryable();
        self.http.request(parts)
    }

    /// Cancel an invitation
    ///
    /// The link stops working. Cancelling a cancelled invitation changes nothing. An account the invitee already started stays in the project, unlinked.
    ///
    /// `POST /v1/invitations/{invitationId}/cancel`
    ///
    /// 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 cancel(&self, invitation_id: &str) -> Request<types::Invitation> {
        let parts = RequestParts::new(Method::Post, format!("/v1/invitations/{}/cancel", encode_path(invitation_id)))
            .keyed();
        self.http.request(parts)
    }

    /// Resend an invitation
    ///
    /// Rotates the token (the old `url` stops working), moves the invitation back to `pending` with a new expiry of the same length, and emails it again when it has an `inviteeEmail`. An account the invitee started is kept, so they resume where they left off.
    ///
    /// `POST /v1/invitations/{invitationId}/resend`
    ///
    /// 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 resend(&self, invitation_id: &str) -> Request<types::Invitation> {
        let parts = RequestParts::new(Method::Post, format!("/v1/invitations/{}/resend", encode_path(invitation_id)))
            .keyed();
        self.http.request(parts)
    }
}