telexide 0.1.17

An async Rust library for the telegram bot API.
Documentation
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
use super::InputFile;
use crate::model::{
    utils::{unix_date_formatting, IntegerOrString},
    Chat,
    ChatPermissions,
};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use telexide_proc_macros::build_struct;

/// struct for holding data needed to call
/// [`ban_chat_member`]
///
/// [`ban_chat_member`]:
/// ../../api/trait.API.html#method.ban_chat_member
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct BanChatMember {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
    /// Unique identifier of the target user
    pub user_id: i64,
    /// Date when the user will be unbanned, unix time.
    /// If user is banned for more than 366 days or less than 30 seconds from
    /// the current time they are considered to be banned forever
    #[serde(skip_serializing_if = "Option::is_none")]
    pub until_date: Option<i64>,
    /// Pass True to delete all messages from the chat for the user that is
    /// being removed. If False, the user will be able to see messages in
    /// the group that were sent before the user was removed. Always True
    /// for supergroups and channels.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub revoke_messages: Option<bool>,
}

/// struct for holding data needed to call
/// [`unban_chat_member`]
///
/// [`unban_chat_member`]:
/// ../../api/trait.API.html#method.unban_chat_member
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct UnbanChatMember {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
    /// Unique identifier of the target user
    pub user_id: i64,
    /// Do nothing if the user is not banned
    #[serde(skip_serializing_if = "Option::is_none")]
    pub only_if_banned: Option<bool>,
}

/// struct for holding data needed to call
/// [`restrict_chat_member`]
///
/// [`restrict_chat_member`]:
/// ../../api/trait.API.html#method.restrict_chat_member
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct RestrictChatMember {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
    /// Unique identifier of the target user
    pub user_id: i64,
    /// New user permissions
    pub permissions: ChatPermissions,
    /// Pass True if chat permissions are set independently. Otherwise, the
    /// can_send_other_messages and can_add_web_page_previews permissions will
    /// imply the can_send_messages, can_send_audios, can_send_documents,
    /// can_send_photos, can_send_videos, can_send_video_notes, and
    /// can_send_voice_notes permissions; the can_send_polls permission will
    /// imply the can_send_messages permission.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub use_independent_chat_permissions: Option<bool>,
    /// Date when the user will be unbanned, unix time.
    /// If user is banned for more than 366 days or less than 30 seconds from
    /// the current time they are considered to be banned forever
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(with = "unix_date_formatting::optional")]
    pub until_date: Option<DateTime<Utc>>,
}

/// struct for holding data needed to call
/// [`promote_chat_member`]
///
/// [`promote_chat_member`]:
/// ../../api/trait.API.html#method.promote_chat_member
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct PromoteChatMember {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
    /// Unique identifier of the target user
    pub user_id: i64,
    /// If the administrator's presence in the chat is hidden
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_anonymous: Option<bool>,
    /// If the administrator can create channel posts, channels only
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_post_messages: Option<bool>,
    /// If the administrator can edit messages of other users and can pin
    /// messages, channels only
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_edit_messages: Option<bool>,
    /// If the administrator can delete messages of other users
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_delete_messages: Option<bool>,
    /// If the administrator can restrict, ban or unban chat members
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_restrict_members: Option<bool>,
    /// If the administrator can add new administrators with a subset of his own
    /// privileges or demote administrators that he has promoted, directly
    /// or indirectly (promoted by administrators that were appointed by
    /// him)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_promote_members: Option<bool>,
    /// If the administrator can change chat title, photo and other settings
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_change_info: Option<bool>,
    /// If the administrator can invite new users to the chat
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_invite_users: Option<bool>,
    /// If the administrator can pin messages, supergroups only
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_pin_messages: Option<bool>,
    /// If the administrator can manage video chats, supergroups only
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_manage_video_chats: Option<bool>,
    /// If the administrator can access the chat event log, chat statistics,
    /// message statistics in channels, see channel members, see anonymous
    /// administrators in supergroups and ignore slow mode. Implied by any
    /// other administrator privilege.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_manage_chat: Option<bool>,
    /// If the administrator can post stories in the channel; channels only
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_post_stories: Option<bool>,
    /// If the administrator can edit stories posted by other users; channels
    /// only
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_edit_stories: Option<bool>,
    /// If the administrator can delete stories posted by other users; channels
    /// only
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_delete_stories: Option<bool>,
    /// If the user is allowed to create, rename, close, and reopen forum
    /// topics, supergroups only
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_manage_topics: Option<bool>,
}

/// struct for holding data needed to call
/// [`set_chat_administrator_custom_title`]
///
/// [`set_chat_administrator_custom_title`]:
/// ../../api/trait.API.html#method.set_chat_administrator_custom_title
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetChatAdministratorCustomTitle {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
    /// Unique identifier of the target user
    pub user_id: i64,
    /// New custom title for the administrator; 0-16 characters, emoji are not
    /// allowed
    pub custom_title: String,
}

/// struct for holding data needed to call [`ban_chat_sender_chat`]
///
/// [`ban_chat_sender_chat`]:
/// ../../api/trait.API.html#method.ban_chat_sender_chat
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct BanChatSenderChat {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
    /// Unique identifier of the target sender chat
    pub sender_chat_id: i64,
}

/// struct for holding data needed to call [`unban_chat_sender_chat`]
///
/// [`unban_chat_sender_chat`]:
/// ../../api/trait.API.html#method.unban_chat_sender_chat
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct UnbanChatSenderChat {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
    /// Unique identifier of the target sender chat
    pub sender_chat_id: i64,
}

/// struct for holding data needed to call [`set_chat_permissions`]
///
/// [`set_chat_permissions`]:
/// ../../api/trait.API.html#method.set_chat_permissions
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetChatPermissions {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
    /// New default chat permissions
    pub permissions: ChatPermissions,
    /// Pass True if chat permissions are set independently. Otherwise, the
    /// can_send_other_messages and can_add_web_page_previews permissions will
    /// imply the can_send_messages, can_send_audios, can_send_documents,
    /// can_send_photos, can_send_videos, can_send_video_notes, and
    /// can_send_voice_notes permissions; the can_send_polls permission will
    /// imply the can_send_messages permission.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub use_independent_chat_permissions: Option<bool>,
}

/// struct for holding data needed to call [`export_chat_invite_link`]
///
/// [`export_chat_invite_link`]:
/// ../../api/trait.API.html#method.export_chat_invite_link
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct ExportChatInviteLink {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
}

/// struct for holding data needed to call
/// [`set_chat_photo`]
///
/// [`set_chat_photo`]:
/// ../../api/trait.API.html#method.set_chat_photo
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetChatPhoto {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
    /// New chat photo
    pub photo: InputFile,
}

/// struct for holding data needed to call
/// [`delete_chat_photo`]
///
/// [`delete_chat_photo`]:
/// ../../api/trait.API.html#method.delete_chat_photo
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct DeleteChatPhoto {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
}

/// struct for holding data needed to call
/// [`set_chat_title`]
///
/// [`set_chat_title`]:
/// ../../api/trait.API.html#method.set_chat_title
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetChatTitle {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
    /// New chat title, 1-255 characters
    pub title: String,
}

/// struct for holding data needed to call
/// [`set_chat_description`]
///
/// [`set_chat_description`]:
/// ../../api/trait.API.html#method.set_chat_description
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetChatDescription {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
    /// New chat description, 0-255 characters
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
}

/// struct for holding data needed to call
/// [`pin_chat_message`]
///
/// [`pin_chat_message`]:
/// ../../api/trait.API.html#method.pin_chat_message
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct PinChatMessage {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
    /// Identifier of a message to pin
    pub message_id: i64,
    /// Sends the message silently. Users will receive a notification with no
    /// sound.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub disable_notification: Option<bool>,
}

/// struct for holding data needed to call
/// [`unpin_chat_message`]
///
/// [`unpin_chat_message`]:
/// ../../api/trait.API.html#method.unpin_chat_message
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct UnpinChatMessage {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
    /// Identifier of a message to unpin. If not specified, the most recent
    /// pinned message (by sending date) will be unpinned.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message_id: Option<i64>,
}

/// struct for holding data needed to call
/// [`unpin_all_chat_messages`]
///
/// [`unpin_all_chat_messages`]:
/// ../../api/trait.API.html#method.unpin_all_chat_message
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct UnpinAllChatMessages {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
}

/// struct for holding data needed to call
/// [`leave_chat`]
///
/// [`leave_chat`]:
/// ../../api/trait.API.html#method.leave_chat
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct LeaveChat {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
}

/// struct for holding data needed to call
/// [`get_chat`]
///
/// [`get_chat`]:
/// ../../api/trait.API.html#method.get_chat
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetChat {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
}

/// struct for holding data needed to call
/// [`get_chat_administrator`]
///
/// [`get_chat_administrator`]:
/// ../../api/trait.API.html#method.get_chat_administrator
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetChatAdministrators {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
}

/// struct for holding data needed to call
/// [`get_chat_member_count`]
///
/// [`get_chat_member_count`]:
/// ../../api/trait.API.html#method.get_chat_member_count
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetChatMemberCount {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
}

/// struct for holding data needed to call
/// [`get_chat_member`]
///
/// [`get_chat_member`]:
/// ../../api/trait.API.html#method.get_chat_member
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetChatMember {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
    /// Unique identifier of the target user
    pub user_id: i64,
}

/// struct for holding data needed to call
/// [`set_chat_sticker_set`]
///
/// [`set_chat_sticker_set`]:
/// ../../api/trait.API.html#method.get_chat_sticker_set
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetChatStickerSet {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
    /// Name of the sticker set to be set as the group sticker set
    pub sticker_set_name: String,
}

/// struct for holding data needed to call
/// [`delete_chat_sticker_set`]
///
/// [`delete_chat_sticker_set`]:
/// ../../api/trait.API.html#method.delete_chat_sticker_set
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct DeleteChatStickerSet {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
}

/// struct for holding data needed to call [`create_chat_invite_link`]
///
/// [`create_chat_invite_link`]:
/// ../../api/trait.API.html#method.create_chat_invite_link
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct CreateChatInviteLink {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
    /// Invite link name; 0-32 characters.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Point in time (Unix timestamp) when the link will expire
    #[serde(skip_serializing_if = "Option::is_none")]
    pub expire_date: Option<i64>,
    /// Maximum number of users that can be members of the chat simultaneously
    /// after joining the chat via this invite link; 1-99999
    #[serde(skip_serializing_if = "Option::is_none")]
    pub member_limit: Option<i32>,
    /// True, if users joining the chat via the link need to be approved by chat
    /// administrators. If True, member_limit can't be specified.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub creates_join_request: Option<bool>,
}

/// struct for holding data needed to call [`edit_chat_invite_link`]
///
/// [`edit_chat_invite_link`]:
/// ../../api/trait.API.html#method.edit_chat_invite_link
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct EditChatInviteLink {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
    /// The invite link to edit
    pub invite_link: String,
    /// Invite link name; 0-32 characters.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Point in time (Unix timestamp) when the link will expire
    #[serde(skip_serializing_if = "Option::is_none")]
    pub expire_date: Option<i64>,
    /// Maximum number of users that can be members of the chat simultaneously
    /// after joining the chat via this invite link; 1-99999
    #[serde(skip_serializing_if = "Option::is_none")]
    pub member_limit: Option<i32>,
    /// True, if users joining the chat via the link need to be approved by chat
    /// administrators. If True, member_limit can't be specified.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub creates_join_request: Option<bool>,
}

/// struct for holding data needed to call [`revoke_chat_invite_link`]
///
/// [`revoke_chat_invite_link`]:
/// ../../api/trait.API.html#method.revoke_chat_invite_link
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct RevokeChatInviteLink {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
    /// The invite link to revoke
    pub invite_link: String,
}

/// struct for holding data needed to call [`approve_chat_join_request`]
///
/// [`approve_chat_join_request`]:
/// ../../api/trait.API.html#method.approve_chat_join_request
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct ApproveChatJoinRequest {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
    /// Unique identifier of the target user
    pub user_id: i64,
}

/// struct for holding data needed to call [`decline_chat_join_request`]
///
/// [`decline_chat_join_request`]:
/// ../../api/trait.API.html#method.decline_chat_join_request
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct DeclineChatJoinRequest {
    /// Unique identifier for the target chat
    pub chat_id: IntegerOrString,
    /// Unique identifier of the target user
    pub user_id: i64,
}

macro_rules! impl_from_chat {
    ($name:ident) => {
        impl From<Chat> for $name {
            fn from(chat: Chat) -> Self {
                Self {
                    chat_id: chat.get_id().into(),
                }
            }
        }
    };
}

impl_from_chat!(ExportChatInviteLink);
impl_from_chat!(DeleteChatPhoto);
impl_from_chat!(UnpinAllChatMessages);
impl_from_chat!(LeaveChat);
impl_from_chat!(GetChat);
impl_from_chat!(GetChatAdministrators);
impl_from_chat!(GetChatMemberCount);
impl_from_chat!(DeleteChatStickerSet);