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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
// @generated by xtask/generate_services.py — do not edit by hand.
//! `chat-widget` — typed methods for all 8 API v3 operations
//! in this module.
//!
//! Access via [`Ghl::v3`](crate::Ghl::v3)`().chat_widget()`. These endpoints send `Version: v3`.
//!
//! Request and response types come from [`ghl_models::v3::chat_widget`](https://docs.rs/ghl-models/latest/ghl_models/v3/chat_widget/); every endpoint is also documented in the
//! [`chat-widget` API reference](https://github.com/Shahroz/ghl-rs/blob/main/docs/api/chat-widget.md).
//!
//! Enable with `features = ["chat-widget"]`.
#![allow(clippy::too_many_arguments)]
use crate::client::Ghl;
use crate::error::Result;
use ghl_models::v3::chat_widget as models;
/// Typed access to the `chat-widget` API v3 surface (8 operations). Obtained via
/// [`Ghl::v3`](crate::Ghl::v3)`().chat_widget()`.
#[derive(Debug, Clone)]
pub struct ChatWidgetService {
pub(crate) client: Ghl,
}
impl ChatWidgetService {
pub(crate) fn new(client: Ghl) -> Self {
Self { client }
}
}
/// Query parameters for [`ChatWidgetService::list_chat_widgets`].
#[derive(Debug, Clone, Default)]
pub struct ListChatWidgetsParams {
/// The location ID
/// Required by the API.
pub location_id: String,
/// Offset
/// Required by the API.
pub offset: String,
/// Limit
/// Required by the API.
pub limit: String,
/// The type of chat widget. Supports normal ChatType values, plus the virtual umbrella
/// "webChat" (maps to facebookChat/emailChat/instagramChat/waChat).
/// Allowed values: `liveChat`, `waChat`, `emailChat`, `allInOneChat`, `voiceAiChat`,
/// `facebookChat`, `instagramChat`, `webChat`.
pub chat_type: Option<String>,
/// The type of chat widget
/// Allowed values: `liveChat`, `waChat`, `emailChat`, `allInOneChat`, `voiceAiChat`,
/// `facebookChat`, `instagramChat`.
pub exclude_chat_type: Option<String>,
/// The voice AI agent ID
pub voice_ai_agent_id: Option<String>,
/// All-in-one chat type to filter by. Only applies when chatType is "allInOneChat".
/// Supports normal ChatType values plus the virtual umbrella "webChat" (maps to
/// facebookChat/emailChat/instagramChat/waChat).
/// Allowed values: `liveChat`, `waChat`, `emailChat`, `allInOneChat`, `voiceAiChat`,
/// `facebookChat`, `instagramChat`, `webChat`.
pub all_in_one_chat_types: Option<String>,
}
impl ListChatWidgetsParams {
/// Start from the parameters the API requires.
pub fn new(
location_id: impl Into<String>,
offset: impl Into<String>,
limit: impl Into<String>,
) -> Self {
Self {
location_id: location_id.into(),
offset: offset.into(),
limit: limit.into(),
..Default::default()
}
}
/// The type of chat widget. Supports normal ChatType values, plus the virtual umbrella
/// "webChat" (maps to facebookChat/emailChat/instagramChat/waChat).
pub fn chat_type(mut self, v: impl Into<String>) -> Self {
self.chat_type = Some(v.into());
self
}
/// The type of chat widget
pub fn exclude_chat_type(mut self, v: impl Into<String>) -> Self {
self.exclude_chat_type = Some(v.into());
self
}
/// The voice AI agent ID
pub fn voice_ai_agent_id(mut self, v: impl Into<String>) -> Self {
self.voice_ai_agent_id = Some(v.into());
self
}
/// All-in-one chat type to filter by. Only applies when chatType is "allInOneChat".
/// Supports normal ChatType values plus the virtual umbrella "webChat" (maps to
/// facebookChat/emailChat/instagramChat/waChat).
pub fn all_in_one_chat_types(mut self, v: impl Into<String>) -> Self {
self.all_in_one_chat_types = Some(v.into());
self
}
fn to_query(&self) -> Vec<(String, String)> {
let mut q: Vec<(String, String)> = vec![
("locationId".into(), self.location_id.clone()),
("offset".into(), self.offset.clone()),
("limit".into(), self.limit.clone()),
];
if let Some(v) = &self.chat_type {
q.push(("chatType".into(), v.to_string()));
}
if let Some(v) = &self.exclude_chat_type {
q.push(("excludeChatType".into(), v.to_string()));
}
if let Some(v) = &self.voice_ai_agent_id {
q.push(("voiceAiAgentId".into(), v.to_string()));
}
if let Some(v) = &self.all_in_one_chat_types {
q.push(("allInOneChatTypes".into(), v.to_string()));
}
q
}
}
/// Query parameters for [`ChatWidgetService::get_widget_config`].
#[derive(Debug, Clone, Default)]
pub struct GetWidgetConfigParams {
/// `version` query parameter.
pub version: Option<String>,
}
impl GetWidgetConfigParams {
/// Start from the parameters the API requires.
pub fn new() -> Self {
Self {
..Default::default()
}
}
/// Set the `version` query parameter.
pub fn version(mut self, v: impl Into<String>) -> Self {
self.version = Some(v.into());
self
}
fn to_query(&self) -> Vec<(String, String)> {
let mut q: Vec<(String, String)> = Vec::new();
if let Some(v) = &self.version {
q.push(("version".into(), v.to_string()));
}
q
}
}
impl ChatWidgetService {
/// Create Chat Widget
///
/// Creates a new chat widget for the given sub-account.
///
/// `POST /chat-widget/`
///
/// Requires scope: `chat-widget.write`.
pub async fn create_chat_widget(
&self,
body: &models::CreateWidgetDTO,
) -> Result<serde_json::Value> {
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::POST,
"/chat-widget/",
&query,
Some(body),
Some("v3"),
)
.await
}
/// Clone Chat Widget
///
/// Creates a copy of an existing chat widget in the same sub-account.
///
/// `POST /chat-widget/clone`
///
/// Requires scope: `chat-widget.write`.
pub async fn clone_chat_widget(
&self,
body: &models::CloneChatWidgetDTO,
) -> Result<serde_json::Value> {
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::POST,
"/chat-widget/clone",
&query,
Some(body),
Some("v3"),
)
.await
}
/// Get Chat Widget
///
/// Returns a single chat widget by ID.
///
/// `GET /chat-widget/data/{locationId}/{id}`
///
/// Requires scope: `chat-widget.readonly`.
pub async fn get_chat_widget(&self, location_id: &str, id: &str) -> Result<serde_json::Value> {
let path = format!(
"/chat-widget/data/{}/{}",
crate::services::encode(location_id),
crate::services::encode(id)
);
let query = Vec::new();
self.client
.send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, Some("v3"))
.await
}
/// Patch Chat Widget
///
/// Partial update of a chat widget resource.
///
/// `PATCH /chat-widget/data/{locationId}/{id}`
///
/// Requires scope: `chat-widget.write`.
pub async fn patch_chat_widget(
&self,
location_id: &str,
id: &str,
body: &models::UpdateWidgetDTO,
) -> Result<serde_json::Value> {
let path = format!(
"/chat-widget/data/{}/{}",
crate::services::encode(location_id),
crate::services::encode(id)
);
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::PATCH,
&path,
&query,
Some(body),
Some("v3"),
)
.await
}
/// Update Chat Widget
///
/// Full update of a chat widget resource.
///
/// `PUT /chat-widget/data/{locationId}/{id}`
///
/// Requires scope: `chat-widget.write`.
pub async fn update_chat_widget(
&self,
location_id: &str,
id: &str,
body: &models::UpdateWidgetDTO,
) -> Result<serde_json::Value> {
let path = format!(
"/chat-widget/data/{}/{}",
crate::services::encode(location_id),
crate::services::encode(id)
);
let query = Vec::new();
self.client
.send_versioned(reqwest::Method::PUT, &path, &query, Some(body), Some("v3"))
.await
}
/// List Chat Widgets
///
/// Returns chat widgets for the sub-account with pagination and optional filters.
///
/// `GET /chat-widget/list`
///
/// Requires scope: `chat-widget.readonly`.
pub async fn list_chat_widgets(
&self,
params: &ListChatWidgetsParams,
) -> Result<serde_json::Value> {
let query = params.to_query();
self.client
.send_versioned(
reqwest::Method::GET,
"/chat-widget/list",
&query,
None::<&()>,
Some("v3"),
)
.await
}
/// Get Widget Config
///
/// Returns widget configuration by ID.
///
/// `GET /chat-widget/public/config/{id}`
pub async fn get_widget_config(
&self,
id: &str,
params: &GetWidgetConfigParams,
) -> Result<serde_json::Value> {
let path = format!("/chat-widget/public/config/{}", crate::services::encode(id));
let query = params.to_query();
self.client
.send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, Some("v3"))
.await
}
/// Delete Chat Widget
///
/// Soft-deletes a chat widget. If it was the default, another widget may be promoted.
///
/// `DELETE /chat-widget/{locationId}/{id}`
///
/// Requires scope: `chat-widget.write`.
pub async fn delete_chat_widget(
&self,
location_id: &str,
id: &str,
) -> Result<serde_json::Value> {
let path = format!(
"/chat-widget/{}/{}",
crate::services::encode(location_id),
crate::services::encode(id)
);
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::DELETE,
&path,
&query,
None::<&()>,
Some("v3"),
)
.await
}
}