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
//! The example demonstrates the basic usage of the framework.
//!
//! The following steps are required to run a simple bot:
//!
//! 1. Declare an [`Update`] handler.
//! 2. Obtain a Bot API token.
//! 3. Create an API [`Client`] instance to interact with the Telegram Bot API.
//! 4. Create a [`Context`] instance to share objects with the handler.
//! 5. Create an [`App`] instance which serves as the main entry point for the bot.
//! 6. Start the bot using the [`LongPoll`] for development environment
//! or the [`WebhookServer`] for production environment.
//!
//! The [`App`] creates a [`HandlerInput`] containing the [`Context`] instance
//! and an [`Update`] received from the Telegram Bot API,
//! then converts it into an input for the handler using [`TryFromInput`] trait.
//!
//! The handler must implement the [`Handler`] trait.
//! Since this trait is implemented for [`Fn`] (with up to 10 arguments),
//! you can use regular functions as handlers.
//!
//! It's recommended to use a function when you need a simple handler.
//! Implement the [`Handler`] trait for your own type only in complex cases,
//! e.g. you need to write your own decorator or a predicate.
//!
//! The handler is executed only when the [`TryFromInput`] returns `Some(T)`.
//! When your handler is a regular function, [`TryFromInput`] must return `Some(T)`
//! for all arguments of the function. Otherwise the handler will not be executed.
//!
//! The handler must return a future with a [`HandlerResult`] output.
//! You can use any type that converts into it
//! ([`IntoHandlerResult`] is implemented for the type):
//!
//! | From | To |
//! |------------------|---------------------|
//! | `()` | `Ok(())` |
//! | `Ok(())` | `Ok(())` |
//! | `Err(YourError)` | `Err(HandlerError)` |
//!
//! See the `app` example for advanced usage information.
//!
//! [`IntoHandlerResult`]: carapax::IntoHandlerResult
//! [`Handler`]: carapax::Handler
//! [`HandlerInput`]: carapax::HandlerInput
//! [`HandlerResult`]: carapax::HandlerResult
//! [`TryFromInput`]: carapax::TryFromInput
//! [`Update`]: carapax::types::Update
use env;
use dotenv;
use ;
const DEBUG: bool = true;
/// The update handler
///
/// It will be executed only when the [`carapax::types::Update`] contains
/// a [`ChatPeerId`] and a [`Text`] (message text, media captions).
///
/// Use [`Ref`] as the argument type when you need to retrieve an object from the context.
/// If the object is not found, [`carapax::TryFromInput`] returns an error and
/// the handler will not be executed.
async
async