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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// 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::types;
/// The `chats` methods.
#[derive(Clone, Debug)]
pub struct ChatsResource {
http: HttpClient,
}
impl ChatsResource {
pub(crate) fn new(http: HttpClient) -> Self {
Self { http }
}
/// Show typing or recording
///
/// Show (`typing`, `recording`) or clear (`paused`) the indicator in a chat.
///
/// `POST /v1/accounts/{accountId}/chats/{chatId}/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 send_presence(
&self,
account_id: &str,
chat_id: &str,
params: types::ChatsSendPresenceParams,
) -> Request<()> {
let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/chats/{}/presence", encode_path(account_id), encode_path(chat_id)))
.body(¶ms)
.keyed()
.no_content();
self.http.request(parts)
}
/// Send read receipts
///
/// Send read receipts (blue ticks) for messages in a chat. Without `messageIds`, every unread inbound message wuapi stores for the chat. In a group WhatsApp takes one receipt per author, so this makes one change per author.
///
/// `POST /v1/accounts/{accountId}/chats/{chatId}/read`
///
/// 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 send_read_receipts(
&self,
account_id: &str,
chat_id: &str,
params: types::ChatsSendReadReceiptsParams,
) -> Request<types::ChatRead> {
let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/chats/{}/read", encode_path(account_id), encode_path(chat_id)))
.body(¶ms)
.keyed();
self.http.request(parts)
}
/// Mark a chat read
///
/// Clear the chat's unread badge on the phone and other devices. Sends no read receipts; use `POST .../read` for those.
///
/// `POST /v1/accounts/{accountId}/chats/{chatId}/mark-read`
///
/// 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_read(&self, account_id: &str, chat_id: &str) -> Request<()> {
let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/chats/{}/mark-read", encode_path(account_id), encode_path(chat_id)))
.keyed()
.no_content();
self.http.request(parts)
}
/// Mark a chat unread
///
/// Put the unread badge back on the chat.
///
/// `POST /v1/accounts/{accountId}/chats/{chatId}/mark-unread`
///
/// 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_unread(&self, account_id: &str, chat_id: &str) -> Request<()> {
let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/chats/{}/mark-unread", encode_path(account_id), encode_path(chat_id)))
.keyed()
.no_content();
self.http.request(parts)
}
/// Archive a chat
///
/// Archive the chat on the phone and other devices.
///
/// `POST /v1/accounts/{accountId}/chats/{chatId}/archive`
///
/// 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 archive(&self, account_id: &str, chat_id: &str) -> Request<()> {
let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/chats/{}/archive", encode_path(account_id), encode_path(chat_id)))
.keyed()
.no_content();
self.http.request(parts)
}
/// Unarchive a chat
///
/// Move the chat out of the archive.
///
/// `POST /v1/accounts/{accountId}/chats/{chatId}/unarchive`
///
/// 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 unarchive(&self, account_id: &str, chat_id: &str) -> Request<()> {
let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/chats/{}/unarchive", encode_path(account_id), encode_path(chat_id)))
.keyed()
.no_content();
self.http.request(parts)
}
/// Pin a chat
///
/// Pin the chat to the top.
///
/// `POST /v1/accounts/{accountId}/chats/{chatId}/pin`
///
/// 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 pin(&self, account_id: &str, chat_id: &str) -> Request<()> {
let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/chats/{}/pin", encode_path(account_id), encode_path(chat_id)))
.keyed()
.no_content();
self.http.request(parts)
}
/// Unpin a chat
///
/// Unpin the chat.
///
/// `POST /v1/accounts/{accountId}/chats/{chatId}/unpin`
///
/// 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 unpin(&self, account_id: &str, chat_id: &str) -> Request<()> {
let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/chats/{}/unpin", encode_path(account_id), encode_path(chat_id)))
.keyed()
.no_content();
self.http.request(parts)
}
/// Mute a chat
///
/// Mute notifications for the chat, for `durationSeconds` or until unmuted.
///
/// `POST /v1/accounts/{accountId}/chats/{chatId}/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,
chat_id: &str,
params: types::ChatsMuteParams,
) -> Request<()> {
let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/chats/{}/mute", encode_path(account_id), encode_path(chat_id)))
.body(¶ms)
.keyed()
.no_content();
self.http.request(parts)
}
/// Unmute a chat
///
/// Turn the chat's notifications back on.
///
/// `POST /v1/accounts/{accountId}/chats/{chatId}/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, chat_id: &str) -> Request<()> {
let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/chats/{}/unmute", encode_path(account_id), encode_path(chat_id)))
.keyed()
.no_content();
self.http.request(parts)
}
/// Delete a chat
///
/// Delete the chat on the linked devices. Messages stored in wuapi are kept.
///
/// `DELETE /v1/accounts/{accountId}/chats/{chatId}`
///
/// Safe to repeat: retried on timeouts, network errors, `429` and `5xx`.
pub fn delete(
&self,
account_id: &str,
chat_id: &str,
params: types::ChatsDeleteParams,
) -> Request<()> {
let parts = RequestParts::new(Method::Delete, format!("/v1/accounts/{}/chats/{}", encode_path(account_id), encode_path(chat_id)))
.query_opt("deleteMedia", params.delete_media.as_ref())
.retryable()
.no_content();
self.http.request(parts)
}
/// Set a chat's disappearing timer
///
/// Messages in the chat disappear after `durationSeconds`; 0 turns it off.
///
/// `PUT /v1/accounts/{accountId}/chats/{chatId}/disappearing-timer`
///
/// Safe to repeat: retried on timeouts, network errors, `429` and `5xx`.
pub fn set_disappearing_timer(
&self,
account_id: &str,
chat_id: &str,
params: types::ChatsSetDisappearingTimerParams,
) -> Request<()> {
let parts = RequestParts::new(Method::Put, format!("/v1/accounts/{}/chats/{}/disappearing-timer", encode_path(account_id), encode_path(chat_id)))
.body(¶ms)
.retryable()
.no_content();
self.http.request(parts)
}
/// Label a chat
///
/// WhatsApp Business accounts only; others answer `400 not_supported`.
///
/// `POST /v1/accounts/{accountId}/chats/{chatId}/labels`
///
/// 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 add_label(
&self,
account_id: &str,
chat_id: &str,
params: types::ChatsAddLabelParams,
) -> Request<()> {
let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/chats/{}/labels", encode_path(account_id), encode_path(chat_id)))
.body(¶ms)
.keyed()
.no_content();
self.http.request(parts)
}
/// Remove a label from a chat
///
/// WhatsApp Business accounts only.
///
/// `DELETE /v1/accounts/{accountId}/chats/{chatId}/labels/{labelId}`
///
/// Safe to repeat: retried on timeouts, network errors, `429` and `5xx`.
pub fn remove_label(&self, account_id: &str, chat_id: &str, label_id: &str) -> Request<()> {
let parts = RequestParts::new(Method::Delete, format!("/v1/accounts/{}/chats/{}/labels/{}", encode_path(account_id), encode_path(chat_id), encode_path(label_id)))
.retryable()
.no_content();
self.http.request(parts)
}
}