tele 0.1.23

Ergonomic Telegram Bot API SDK for Rust, built on reqx
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
527
528
529
530
531
532
533
534
535
536
537
use super::*;
use crate::types::{ChatAction, InputMediaGroupItem, InputPollOption, MessageId};

/// Request-scoped runtime facade for handler code.
///
/// This is the preferred entry point inside handlers. It mirrors the stable runtime surface of
/// [`crate::client::AppApi`], but keeps the call path centered on `context.app()` so handler code
/// reads naturally and stays on the business/runtime plane.
#[derive(Clone)]
pub struct ContextAppApi {
    client: Client,
}

impl ContextAppApi {
    pub(crate) fn new(client: Client) -> Self {
        Self { client }
    }

    /// Returns the governance-oriented moderation facade for handler-side actions.
    pub fn moderation(&self) -> crate::client::ModerationApi {
        self.client.app().moderation()
    }

    /// Returns the membership/capability facade used by install and bind pre-check flows.
    pub fn membership(&self) -> crate::client::MembershipApi {
        self.client.app().membership()
    }

    /// Returns the dedicated Web App facade for runtime query handling.
    pub fn web_app(&self) -> crate::client::WebAppApi {
        self.client.app().web_app()
    }

    /// Starts a callback-answer builder.
    ///
    /// Prefer this when callback replies need options such as `show_alert`, `url`, or
    /// `cache_time`.
    pub fn callback_answer(
        &self,
        callback_query_id: impl Into<String>,
    ) -> crate::client::CallbackAnswerBuilder {
        self.client.app().callback_answer(callback_query_id)
    }

    /// Starts a callback-answer builder using the callback id extracted from an update.
    pub fn callback_answer_from_update(
        &self,
        update: &Update,
    ) -> Result<crate::client::CallbackAnswerBuilder> {
        self.client.app().callback_answer_from_update(update)
    }

    /// Starts a text-send builder for a target chat.
    pub fn text(
        &self,
        chat_id: impl Into<ChatId>,
        text: impl Into<String>,
    ) -> Result<crate::client::TextSendBuilder> {
        self.client.app().text(chat_id, text)
    }

    /// Starts a text-send builder using the update reply target and quoting its source message when present.
    pub fn reply(
        &self,
        update: &Update,
        text: impl Into<String>,
    ) -> Result<crate::client::TextSendBuilder> {
        self.client.app().reply(update, text)
    }

    /// Starts a location-send builder for a target chat.
    pub fn location(
        &self,
        chat_id: impl Into<ChatId>,
        latitude: f64,
        longitude: f64,
    ) -> crate::client::LocationSendBuilder {
        self.client.app().location(chat_id, latitude, longitude)
    }

    /// Starts a location-send builder using the update reply target and quoting its source message when present.
    pub fn reply_location(
        &self,
        update: &Update,
        latitude: f64,
        longitude: f64,
    ) -> Result<crate::client::LocationSendBuilder> {
        self.client
            .app()
            .reply_location(update, latitude, longitude)
    }

    /// Starts a venue-send builder for a target chat.
    pub fn venue(
        &self,
        chat_id: impl Into<ChatId>,
        latitude: f64,
        longitude: f64,
        title: impl Into<String>,
        address: impl Into<String>,
    ) -> crate::client::VenueSendBuilder {
        self.client
            .app()
            .venue(chat_id, latitude, longitude, title, address)
    }

    /// Starts a venue-send builder using the update reply target and quoting its source message when present.
    pub fn reply_venue(
        &self,
        update: &Update,
        latitude: f64,
        longitude: f64,
        title: impl Into<String>,
        address: impl Into<String>,
    ) -> Result<crate::client::VenueSendBuilder> {
        self.client
            .app()
            .reply_venue(update, latitude, longitude, title, address)
    }

    /// Starts a contact-send builder for a target chat.
    pub fn contact(
        &self,
        chat_id: impl Into<ChatId>,
        phone_number: impl Into<String>,
        first_name: impl Into<String>,
    ) -> crate::client::ContactSendBuilder {
        self.client.app().contact(chat_id, phone_number, first_name)
    }

    /// Starts a contact-send builder using the update reply target and quoting its source message when present.
    pub fn reply_contact(
        &self,
        update: &Update,
        phone_number: impl Into<String>,
        first_name: impl Into<String>,
    ) -> Result<crate::client::ContactSendBuilder> {
        self.client
            .app()
            .reply_contact(update, phone_number, first_name)
    }

    /// Starts a poll-send builder for a target chat.
    pub fn poll(
        &self,
        chat_id: impl Into<ChatId>,
        question: impl Into<String>,
        options: impl IntoIterator<Item = impl Into<InputPollOption>>,
    ) -> Result<crate::client::PollSendBuilder> {
        self.client.app().poll(chat_id, question, options)
    }

    /// Starts a poll-send builder using the update reply target and quoting its source message when present.
    pub fn reply_poll(
        &self,
        update: &Update,
        question: impl Into<String>,
        options: impl IntoIterator<Item = impl Into<InputPollOption>>,
    ) -> Result<crate::client::PollSendBuilder> {
        self.client.app().reply_poll(update, question, options)
    }

    /// Starts a stop-poll builder for a target chat and message.
    pub fn stop_poll(
        &self,
        chat_id: impl Into<ChatId>,
        message_id: MessageId,
    ) -> crate::client::StopPollBuilder {
        self.client.app().stop_poll(chat_id, message_id)
    }

    /// Starts a dice-send builder for a target chat.
    pub fn dice(&self, chat_id: impl Into<ChatId>) -> crate::client::DiceSendBuilder {
        self.client.app().dice(chat_id)
    }

    /// Starts a dice-send builder using the update reply target and quoting its source message when present.
    pub fn reply_dice(&self, update: &Update) -> Result<crate::client::DiceSendBuilder> {
        self.client.app().reply_dice(update)
    }

    /// Starts a chat-action builder for a target chat.
    pub fn chat_action(
        &self,
        chat_id: impl Into<ChatId>,
        action: ChatAction,
    ) -> crate::client::ChatActionBuilder {
        self.client.app().chat_action(chat_id, action)
    }

    /// Starts a chat-action builder using the update reply target.
    pub fn chat_action_for_update(
        &self,
        update: &Update,
        action: ChatAction,
    ) -> Result<crate::client::ChatActionBuilder> {
        self.client.app().chat_action_for_update(update, action)
    }

    /// Starts a photo-send builder for a target chat.
    pub fn photo(
        &self,
        chat_id: impl Into<ChatId>,
        photo: impl Into<String>,
    ) -> crate::client::PhotoSendBuilder {
        self.client.app().photo(chat_id, photo)
    }

    /// Starts a photo-upload builder for a target chat.
    pub fn photo_upload(&self, chat_id: impl Into<ChatId>) -> crate::client::PhotoUploadBuilder {
        self.client.app().photo_upload(chat_id)
    }

    /// Starts a photo-send builder using the update reply target and quoting its source message when present.
    pub fn reply_photo(
        &self,
        update: &Update,
        photo: impl Into<String>,
    ) -> Result<crate::client::PhotoSendBuilder> {
        self.client.app().reply_photo(update, photo)
    }

    /// Starts a photo-upload builder using the update reply target and quoting its source message when present.
    pub fn reply_photo_upload(&self, update: &Update) -> Result<crate::client::PhotoUploadBuilder> {
        self.client.app().reply_photo_upload(update)
    }

    /// Starts a document-send builder for a target chat.
    pub fn document(
        &self,
        chat_id: impl Into<ChatId>,
        document: impl Into<String>,
    ) -> crate::client::DocumentSendBuilder {
        self.client.app().document(chat_id, document)
    }

    /// Starts a document-upload builder for a target chat.
    pub fn document_upload(
        &self,
        chat_id: impl Into<ChatId>,
    ) -> crate::client::DocumentUploadBuilder {
        self.client.app().document_upload(chat_id)
    }

    /// Starts a document-send builder using the update reply target and quoting its source message when present.
    pub fn reply_document(
        &self,
        update: &Update,
        document: impl Into<String>,
    ) -> Result<crate::client::DocumentSendBuilder> {
        self.client.app().reply_document(update, document)
    }

    /// Starts a document-upload builder using the update reply target and quoting its source message when present.
    pub fn reply_document_upload(
        &self,
        update: &Update,
    ) -> Result<crate::client::DocumentUploadBuilder> {
        self.client.app().reply_document_upload(update)
    }

    /// Starts a video-send builder for a target chat.
    pub fn video(
        &self,
        chat_id: impl Into<ChatId>,
        video: impl Into<String>,
    ) -> crate::client::VideoSendBuilder {
        self.client.app().video(chat_id, video)
    }

    /// Starts a video-upload builder for a target chat.
    pub fn video_upload(&self, chat_id: impl Into<ChatId>) -> crate::client::VideoUploadBuilder {
        self.client.app().video_upload(chat_id)
    }

    /// Starts a video-send builder using the update reply target and quoting its source message when present.
    pub fn reply_video(
        &self,
        update: &Update,
        video: impl Into<String>,
    ) -> Result<crate::client::VideoSendBuilder> {
        self.client.app().reply_video(update, video)
    }

    /// Starts a video-upload builder using the update reply target and quoting its source message when present.
    pub fn reply_video_upload(&self, update: &Update) -> Result<crate::client::VideoUploadBuilder> {
        self.client.app().reply_video_upload(update)
    }

    /// Starts an audio-send builder for a target chat.
    pub fn audio(
        &self,
        chat_id: impl Into<ChatId>,
        audio: impl Into<String>,
    ) -> crate::client::AudioSendBuilder {
        self.client.app().audio(chat_id, audio)
    }

    /// Starts an audio-upload builder for a target chat.
    pub fn audio_upload(&self, chat_id: impl Into<ChatId>) -> crate::client::AudioUploadBuilder {
        self.client.app().audio_upload(chat_id)
    }

    /// Starts an audio-send builder using the update reply target and quoting its source message when present.
    pub fn reply_audio(
        &self,
        update: &Update,
        audio: impl Into<String>,
    ) -> Result<crate::client::AudioSendBuilder> {
        self.client.app().reply_audio(update, audio)
    }

    /// Starts an audio-upload builder using the update reply target and quoting its source message when present.
    pub fn reply_audio_upload(&self, update: &Update) -> Result<crate::client::AudioUploadBuilder> {
        self.client.app().reply_audio_upload(update)
    }

    /// Starts an animation-send builder for a target chat.
    pub fn animation(
        &self,
        chat_id: impl Into<ChatId>,
        animation: impl Into<String>,
    ) -> crate::client::AnimationSendBuilder {
        self.client.app().animation(chat_id, animation)
    }

    /// Starts an animation-upload builder for a target chat.
    pub fn animation_upload(
        &self,
        chat_id: impl Into<ChatId>,
    ) -> crate::client::AnimationUploadBuilder {
        self.client.app().animation_upload(chat_id)
    }

    /// Starts an animation-send builder using the update reply target and quoting its source message when present.
    pub fn reply_animation(
        &self,
        update: &Update,
        animation: impl Into<String>,
    ) -> Result<crate::client::AnimationSendBuilder> {
        self.client.app().reply_animation(update, animation)
    }

    /// Starts an animation-upload builder using the update reply target and quoting its source message when present.
    pub fn reply_animation_upload(
        &self,
        update: &Update,
    ) -> Result<crate::client::AnimationUploadBuilder> {
        self.client.app().reply_animation_upload(update)
    }

    /// Starts a voice-send builder for a target chat.
    pub fn voice(
        &self,
        chat_id: impl Into<ChatId>,
        voice: impl Into<String>,
    ) -> crate::client::VoiceSendBuilder {
        self.client.app().voice(chat_id, voice)
    }

    /// Starts a voice-upload builder for a target chat.
    pub fn voice_upload(&self, chat_id: impl Into<ChatId>) -> crate::client::VoiceUploadBuilder {
        self.client.app().voice_upload(chat_id)
    }

    /// Starts a voice-send builder using the update reply target and quoting its source message when present.
    pub fn reply_voice(
        &self,
        update: &Update,
        voice: impl Into<String>,
    ) -> Result<crate::client::VoiceSendBuilder> {
        self.client.app().reply_voice(update, voice)
    }

    /// Starts a voice-upload builder using the update reply target and quoting its source message when present.
    pub fn reply_voice_upload(&self, update: &Update) -> Result<crate::client::VoiceUploadBuilder> {
        self.client.app().reply_voice_upload(update)
    }

    /// Starts a video-note-send builder for a target chat.
    pub fn video_note(
        &self,
        chat_id: impl Into<ChatId>,
        video_note: impl Into<String>,
    ) -> crate::client::VideoNoteSendBuilder {
        self.client.app().video_note(chat_id, video_note)
    }

    /// Starts a video-note-upload builder for a target chat.
    pub fn video_note_upload(
        &self,
        chat_id: impl Into<ChatId>,
    ) -> crate::client::VideoNoteUploadBuilder {
        self.client.app().video_note_upload(chat_id)
    }

    /// Starts a video-note-send builder using the update reply target and quoting its source message when present.
    pub fn reply_video_note(
        &self,
        update: &Update,
        video_note: impl Into<String>,
    ) -> Result<crate::client::VideoNoteSendBuilder> {
        self.client.app().reply_video_note(update, video_note)
    }

    /// Starts a video-note-upload builder using the update reply target and quoting its source message when present.
    pub fn reply_video_note_upload(
        &self,
        update: &Update,
    ) -> Result<crate::client::VideoNoteUploadBuilder> {
        self.client.app().reply_video_note_upload(update)
    }

    /// Starts a sticker-send builder for a target chat.
    pub fn sticker(
        &self,
        chat_id: impl Into<ChatId>,
        sticker: impl Into<String>,
    ) -> crate::client::StickerSendBuilder {
        self.client.app().sticker(chat_id, sticker)
    }

    /// Starts a sticker-upload builder for a target chat.
    pub fn sticker_upload(
        &self,
        chat_id: impl Into<ChatId>,
    ) -> crate::client::StickerUploadBuilder {
        self.client.app().sticker_upload(chat_id)
    }

    /// Starts a sticker-send builder using the update reply target and quoting its source message when present.
    pub fn reply_sticker(
        &self,
        update: &Update,
        sticker: impl Into<String>,
    ) -> Result<crate::client::StickerSendBuilder> {
        self.client.app().reply_sticker(update, sticker)
    }

    /// Starts a sticker-upload builder using the update reply target and quoting its source message when present.
    pub fn reply_sticker_upload(
        &self,
        update: &Update,
    ) -> Result<crate::client::StickerUploadBuilder> {
        self.client.app().reply_sticker_upload(update)
    }

    /// Starts a media-group builder for a target chat.
    pub fn media_group<I, M>(
        &self,
        chat_id: impl Into<ChatId>,
        media: I,
    ) -> Result<crate::client::MediaGroupSendBuilder>
    where
        I: IntoIterator<Item = M>,
        M: Into<InputMediaGroupItem>,
    {
        self.client.app().media_group(chat_id, media)
    }

    /// Starts a media-group upload builder for a target chat.
    pub fn media_group_upload<I, M>(
        &self,
        chat_id: impl Into<ChatId>,
        media: I,
    ) -> Result<crate::client::MediaGroupUploadBuilder>
    where
        I: IntoIterator<Item = M>,
        M: Into<InputMediaGroupItem>,
    {
        self.client.app().media_group_upload(chat_id, media)
    }

    /// Starts a media-group builder using the update reply target and quoting its source message when present.
    pub fn reply_media_group<I, M>(
        &self,
        update: &Update,
        media: I,
    ) -> Result<crate::client::MediaGroupSendBuilder>
    where
        I: IntoIterator<Item = M>,
        M: Into<InputMediaGroupItem>,
    {
        self.client.app().reply_media_group(update, media)
    }

    /// Starts a media-group upload builder using the update reply target and quoting its source message when present.
    pub fn reply_media_group_upload<I, M>(
        &self,
        update: &Update,
        media: I,
    ) -> Result<crate::client::MediaGroupUploadBuilder>
    where
        I: IntoIterator<Item = M>,
        M: Into<InputMediaGroupItem>,
    {
        self.client.app().reply_media_group_upload(update, media)
    }

    /// Shortcut for `text(...).send().await`.
    pub async fn send_text(
        &self,
        chat_id: impl Into<ChatId>,
        text: impl Into<String>,
    ) -> Result<Message> {
        self.client.app().send_text(chat_id, text).await
    }

    /// Shortcut for `reply(...).send().await`.
    pub async fn reply_text(&self, update: &Update, text: impl Into<String>) -> Result<Message> {
        self.client.app().reply_text(update, text).await
    }

    /// Shortcut for `callback_answer(...).text_optional(...).send().await`.
    pub async fn answer_callback(
        &self,
        callback_query_id: impl Into<String>,
        text: Option<String>,
    ) -> Result<bool> {
        self.client
            .app()
            .answer_callback(callback_query_id, text)
            .await
    }

    /// Shortcut for `callback_answer_from_update(...).text_optional(...).send().await`.
    pub async fn answer_callback_from_update(
        &self,
        update: &Update,
        text: Option<String>,
    ) -> Result<bool> {
        self.client
            .app()
            .answer_callback_from_update(update, text)
            .await
    }
}