wuapi 0.17.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;

/// A secret URL that sends a WhatsApp message from one of your accounts to one fixed contact or group: `POST` a body to it, no API key. Manage them here; the URL in each object is the credential.
#[derive(Clone, Debug)]
pub struct IncomingWebhooksResource {
    http: HttpClient,
}

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

    /// List incoming webhooks
    ///
    /// The incoming webhooks in scope, with their URLs. Filter with `projectId`.
    ///
    /// `GET /v1/incoming-webhooks`
    ///
    /// Safe to repeat: retried on timeouts, network errors, `429` and `5xx`.
    pub fn list(
        &self,
        params: types::IncomingWebhooksListParams,
    ) -> Paginator<types::IncomingWebhookList> {
        let parts = RequestParts::new(Method::Get, "/v1/incoming-webhooks")
            .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)
    }

    /// Create an incoming webhook
    ///
    /// Ties a new secret URL to one of your accounts and one fixed destination. At most 50 per organization; one more answers `400 limit_reached`. Anything that can reach the URL can send to `to`, and only to it.
    ///
    /// The URL takes `POST` with a JSON body (`{"text": "..."}`, or `content` as Discord does, with an optional https `imageUrl`) or a plain text body, no API key. It answers `202` once the message is queued and `200` with `Idempotent-Replayed: true` when the `Idempotency-Key` header repeats. 60 messages per minute per hook; over it, `429`.
    ///
    /// `POST /v1/incoming-webhooks`
    ///
    /// 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::IncomingWebhooksCreateParams,
    ) -> Request<types::IncomingWebhook> {
        let parts = RequestParts::new(Method::Post, "/v1/incoming-webhooks").body(&params).keyed();
        self.http.request(parts)
    }

    /// Get an incoming webhook
    ///
    /// The hook with its current URL.
    ///
    /// `GET /v1/incoming-webhooks/{incomingWebhookId}`
    ///
    /// Safe to repeat: retried on timeouts, network errors, `429` and `5xx`.
    pub fn get(&self, incoming_webhook_id: &str) -> Request<types::IncomingWebhook> {
        let parts = RequestParts::new(Method::Get, format!("/v1/incoming-webhooks/{}", encode_path(incoming_webhook_id)))
            .retryable();
        self.http.request(parts)
    }

    /// Update an incoming webhook
    ///
    /// Rename it, pause it with `enabled: false`, or issue a new URL with `rotateUrl: true` when the old one leaked. The destination cannot change: create another hook for that.
    ///
    /// `PATCH /v1/incoming-webhooks/{incomingWebhookId}`
    ///
    /// Not idempotent: retried only when the request never reached the API or was refused with `429`.
    pub fn update(
        &self,
        incoming_webhook_id: &str,
        params: types::IncomingWebhooksUpdateParams,
    ) -> Request<types::IncomingWebhook> {
        let parts = RequestParts::new(Method::Patch, format!("/v1/incoming-webhooks/{}", encode_path(incoming_webhook_id)))
            .body(&params);
        self.http.request(parts)
    }

    /// Delete an incoming webhook
    ///
    /// Its URL stops working at once.
    ///
    /// `DELETE /v1/incoming-webhooks/{incomingWebhookId}`
    ///
    /// Safe to repeat: retried on timeouts, network errors, `429` and `5xx`.
    pub fn delete(&self, incoming_webhook_id: &str) -> Request<()> {
        let parts = RequestParts::new(Method::Delete, format!("/v1/incoming-webhooks/{}", encode_path(incoming_webhook_id)))
            .retryable()
            .no_content();
        self.http.request(parts)
    }
}