1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// 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(¶ms).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(¶ms);
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)
}
}