frankenstein 0.50.1

Telegram bot API client for Rust
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
//! API Objects related to [Rich Messages](https://core.telegram.org/bots/api#rich-messages).

use serde::{Deserialize, Serialize};

use crate::macros::{apistruct, apply};
use crate::types::{Animation, Audio, Location, PhotoSize, User, Video, Voice};

#[apply(apistruct!)]
pub struct RichMessage {
    pub blocks: Vec<RichBlock>,
    pub is_rtl: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct InputRichMessage {
    pub html: Option<String>,
    pub markdown: Option<String>,
    pub is_rtl: Option<bool>,
    pub skip_entity_detection: Option<bool>,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub enum RichText {
    Text(String),
    List(Vec<Self>),
    Object(RichTextObject),
}

impl From<String> for RichText {
    fn from(value: String) -> Self {
        Self::Text(value)
    }
}

impl From<&str> for RichText {
    fn from(value: &str) -> Self {
        Self::Text(value.to_owned())
    }
}

impl From<Vec<Self>> for RichText {
    fn from(value: Vec<Self>) -> Self {
        Self::List(value)
    }
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum RichTextObject {
    Bold(RichTextBold),
    Italic(RichTextItalic),
    Underline(RichTextUnderline),
    Strikethrough(RichTextStrikethrough),
    Spoiler(RichTextSpoiler),
    DateTime(RichTextDateTime),
    TextMention(RichTextTextMention),
    Subscript(RichTextSubscript),
    Superscript(RichTextSuperscript),
    Marked(RichTextMarked),
    Code(RichTextCode),
    CustomEmoji(RichTextCustomEmoji),
    MathematicalExpression(RichTextMathematicalExpression),
    Url(RichTextUrl),
    EmailAddress(RichTextEmailAddress),
    PhoneNumber(RichTextPhoneNumber),
    BankCardNumber(RichTextBankCardNumber),
    Mention(RichTextMention),
    Hashtag(RichTextHashtag),
    Cashtag(RichTextCashtag),
    BotCommand(RichTextBotCommand),
    Anchor(RichTextAnchor),
    AnchorLink(RichTextAnchorLink),
    Reference(RichTextReference),
    ReferenceLink(RichTextReferenceLink),
}

macro_rules! rich_text_from {
    ($type:ident, $variant:ident) => {
        impl From<$type> for RichText {
            fn from(value: $type) -> Self {
                Self::Object(RichTextObject::$variant(value))
            }
        }
    };
}

rich_text_from!(RichTextBold, Bold);
rich_text_from!(RichTextItalic, Italic);
rich_text_from!(RichTextUnderline, Underline);
rich_text_from!(RichTextStrikethrough, Strikethrough);
rich_text_from!(RichTextSpoiler, Spoiler);
rich_text_from!(RichTextDateTime, DateTime);
rich_text_from!(RichTextTextMention, TextMention);
rich_text_from!(RichTextSubscript, Subscript);
rich_text_from!(RichTextSuperscript, Superscript);
rich_text_from!(RichTextMarked, Marked);
rich_text_from!(RichTextCode, Code);
rich_text_from!(RichTextCustomEmoji, CustomEmoji);
rich_text_from!(RichTextMathematicalExpression, MathematicalExpression);
rich_text_from!(RichTextUrl, Url);
rich_text_from!(RichTextEmailAddress, EmailAddress);
rich_text_from!(RichTextPhoneNumber, PhoneNumber);
rich_text_from!(RichTextBankCardNumber, BankCardNumber);
rich_text_from!(RichTextMention, Mention);
rich_text_from!(RichTextHashtag, Hashtag);
rich_text_from!(RichTextCashtag, Cashtag);
rich_text_from!(RichTextBotCommand, BotCommand);
rich_text_from!(RichTextAnchor, Anchor);
rich_text_from!(RichTextAnchorLink, AnchorLink);
rich_text_from!(RichTextReference, Reference);
rich_text_from!(RichTextReferenceLink, ReferenceLink);

macro_rules! rich_text_format_struct {
    ($type:ident) => {
        #[apply(apistruct!)]
        pub struct $type {
            pub text: Box<RichText>,
        }
    };
}

rich_text_format_struct!(RichTextBold);
rich_text_format_struct!(RichTextItalic);
rich_text_format_struct!(RichTextUnderline);
rich_text_format_struct!(RichTextStrikethrough);
rich_text_format_struct!(RichTextSpoiler);
rich_text_format_struct!(RichTextSubscript);
rich_text_format_struct!(RichTextSuperscript);
rich_text_format_struct!(RichTextMarked);
rich_text_format_struct!(RichTextCode);

#[apply(apistruct!)]
pub struct RichTextDateTime {
    pub text: Box<RichText>,
    pub unix_time: u64,
    pub date_time_format: String,
}

#[apply(apistruct!)]
pub struct RichTextTextMention {
    pub text: Box<RichText>,
    pub user: User,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct RichTextCustomEmoji {
    pub custom_emoji_id: String,
    pub alternative_text: String,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct RichTextMathematicalExpression {
    pub expression: String,
}

#[apply(apistruct!)]
pub struct RichTextUrl {
    pub text: Box<RichText>,
    pub url: String,
}

#[apply(apistruct!)]
pub struct RichTextEmailAddress {
    pub text: Box<RichText>,
    pub email_address: String,
}

#[apply(apistruct!)]
pub struct RichTextPhoneNumber {
    pub text: Box<RichText>,
    pub phone_number: String,
}

#[apply(apistruct!)]
pub struct RichTextBankCardNumber {
    pub text: Box<RichText>,
    pub bank_card_number: String,
}

#[apply(apistruct!)]
pub struct RichTextMention {
    pub text: Box<RichText>,
    pub username: String,
}

#[apply(apistruct!)]
pub struct RichTextHashtag {
    pub text: Box<RichText>,
    pub hashtag: String,
}

#[apply(apistruct!)]
pub struct RichTextCashtag {
    pub text: Box<RichText>,
    pub cashtag: String,
}

#[apply(apistruct!)]
pub struct RichTextBotCommand {
    pub text: Box<RichText>,
    pub bot_command: String,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct RichTextAnchor {
    pub name: String,
}

#[apply(apistruct!)]
pub struct RichTextAnchorLink {
    pub text: Box<RichText>,
    pub anchor_name: String,
}

#[apply(apistruct!)]
pub struct RichTextReference {
    pub text: Box<RichText>,
    pub name: String,
}

#[apply(apistruct!)]
pub struct RichTextReferenceLink {
    pub text: Box<RichText>,
    pub reference_name: String,
}

#[apply(apistruct!)]
pub struct RichBlockCaption {
    pub text: RichText,
    pub credit: Option<RichText>,
}

#[apply(apistruct!)]
pub struct RichBlockTableCell {
    pub text: Option<RichText>,
    pub is_header: Option<bool>,
    pub colspan: Option<u32>,
    pub rowspan: Option<u32>,
    pub align: String,
    pub valign: String,
}

#[apply(apistruct!)]
pub struct RichBlockListItem {
    pub label: String,
    pub blocks: Vec<RichBlock>,
    pub has_checkbox: Option<bool>,
    pub is_checked: Option<bool>,
    pub value: Option<i32>,
    #[serde(rename = "type")]
    pub type_field: Option<String>,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum RichBlock {
    Paragraph(RichBlockParagraph),
    Heading(RichBlockSectionHeading),
    Pre(RichBlockPreformatted),
    Footer(RichBlockFooter),
    Divider(RichBlockDivider),
    MathematicalExpression(RichBlockMathematicalExpression),
    Anchor(RichBlockAnchor),
    List(RichBlockList),
    Blockquote(RichBlockBlockQuotation),
    Pullquote(RichBlockPullQuotation),
    Collage(RichBlockCollage),
    Slideshow(RichBlockSlideshow),
    Table(RichBlockTable),
    Details(RichBlockDetails),
    Map(RichBlockMap),
    Animation(RichBlockAnimation),
    Audio(RichBlockAudio),
    Photo(RichBlockPhoto),
    Video(RichBlockVideo),
    VoiceNote(RichBlockVoiceNote),
    Thinking(RichBlockThinking),
}

#[apply(apistruct!)]
pub struct RichBlockParagraph {
    pub text: RichText,
}

#[apply(apistruct!)]
pub struct RichBlockSectionHeading {
    pub text: RichText,
    pub size: u8,
}

#[apply(apistruct!)]
pub struct RichBlockPreformatted {
    pub text: RichText,
    pub language: Option<String>,
}

#[apply(apistruct!)]
pub struct RichBlockFooter {
    pub text: RichText,
}

#[apply(apistruct!)]
#[derive(Copy, Eq)]
pub struct RichBlockDivider {}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct RichBlockMathematicalExpression {
    pub expression: String,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct RichBlockAnchor {
    pub name: String,
}

#[apply(apistruct!)]
pub struct RichBlockList {
    pub items: Vec<RichBlockListItem>,
}

#[apply(apistruct!)]
pub struct RichBlockBlockQuotation {
    pub blocks: Vec<RichBlock>,
    pub credit: Option<RichText>,
}

#[apply(apistruct!)]
pub struct RichBlockPullQuotation {
    pub text: RichText,
    pub credit: Option<RichText>,
}

#[apply(apistruct!)]
pub struct RichBlockCollage {
    pub blocks: Vec<RichBlock>,
    pub caption: Option<RichBlockCaption>,
}

#[apply(apistruct!)]
pub struct RichBlockSlideshow {
    pub blocks: Vec<RichBlock>,
    pub caption: Option<RichBlockCaption>,
}

#[apply(apistruct!)]
pub struct RichBlockTable {
    pub cells: Vec<Vec<RichBlockTableCell>>,
    pub is_bordered: Option<bool>,
    pub is_striped: Option<bool>,
    pub caption: Option<RichText>,
}

#[apply(apistruct!)]
pub struct RichBlockDetails {
    pub summary: RichText,
    pub blocks: Vec<RichBlock>,
    pub is_open: Option<bool>,
}

#[apply(apistruct!)]
pub struct RichBlockMap {
    pub location: Location,
    pub zoom: u8,
    pub width: u32,
    pub height: u32,
    pub caption: Option<RichBlockCaption>,
}

#[apply(apistruct!)]
pub struct RichBlockAnimation {
    pub animation: Animation,
    pub has_spoiler: Option<bool>,
    pub caption: Option<RichBlockCaption>,
}

#[apply(apistruct!)]
pub struct RichBlockAudio {
    pub audio: Audio,
    pub caption: Option<RichBlockCaption>,
}

#[apply(apistruct!)]
pub struct RichBlockPhoto {
    pub photo: Vec<PhotoSize>,
    pub has_spoiler: Option<bool>,
    pub caption: Option<RichBlockCaption>,
}

#[apply(apistruct!)]
pub struct RichBlockVideo {
    pub video: Video,
    pub has_spoiler: Option<bool>,
    pub caption: Option<RichBlockCaption>,
}

#[apply(apistruct!)]
pub struct RichBlockVoiceNote {
    pub voice_note: Voice,
    pub caption: Option<RichBlockCaption>,
}

#[apply(apistruct!)]
pub struct RichBlockThinking {
    pub text: RichText,
}