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
// 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(¶ms)
.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(¶ms)
.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(¶ms)
.keyed()
.no_content();
self.http.request(parts)
}
}