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
//! Contexts for update handlers.
//!
//! A context is a struct that is passed to update handlers, contains data about
//! the update, and provides methods that infer certain data from the update.
//! For example:
//!
//! ```no_run
//! use tbot::prelude::*;
//!
//! let mut bot = tbot::bot!("BOT_TOKEN").event_loop();
//!
//! bot.text(|context| {
//! let reversed: String = context.text.value.chars().rev().collect();
//! let reply = context
//! .send_message_in_reply(&reversed)
//! .into_future()
//! .map_err(|err| {
//! dbg!(err);
//! });
//!
//! tbot::spawn(reply);
//! });
//! ```
//!
//! Here, we set a [`text`][text-handler] handler for our bot. Whenever we get
//! a text message, the handler is called with a reference to
//! a [`Text`][text-context] context that contains data about the incoming data,
//! e.g. the text of the message. Then we call the [`send_message_in_reply`]
//! method on the context, which does what the name says: sends a message
//! in the same chat in reply to the incoming message, inferring your bot's
//! token and IDs of the chat and the message.
//!
//! All contexts have one common field named `bot`. Through this field, you can
//! call any API method you can call using a [`Bot`]:
//!
//! ```no_run
//! # use tbot::prelude::*;
//! # let mut bot = tbot::Bot::new(tbot::Token::new(String::new()))
//! # .event_loop();
//! use tbot::types::chat;
//! const ADMIN_CHAT: chat::Id = chat::Id(0);
//!
//! bot.text(|context| {
//! let notification = context
//! .bot
//! .send_message(ADMIN_CHAT, "New message!")
//! .into_future()
//! .map_err(|err| {
//! dbg!(err);
//! });
//!
//! tbot::spawn(notification);
//! });
//! ```
//!
//! Most contexts implement certain traits, such as [`ChatMethods`]
//! or [`Pinnable`]. These traits share common methods between contexts,
//! e.g. [`send_message_in_reply`] you have seen above.
//!
//! [text-handler]: ../struct.Bot.html#method.text
//! [text-context]: ./struct.Text.html
//! [`send_message_in_reply`]: ./traits/trait.ChatMethods.html#method.send_message_in_reply
//! [`Bot`]: ../struct.Bot.html
//! [`ChatMethods`]: ./traits/trait.ChatMethods.html
//! [`Pinnable`]: ./traits/trait.Pinnable.html
pub use ;