diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..4cca6d1 --- /dev/null +++ b/src/main.rs | |||
@@ -0,0 +1,23 @@ | |||
1 | extern crate telegram_bot; | ||
2 | |||
3 | use telegram_bot::{Api, ListeningMethod, ListeningAction, MessageType, Update}; | ||
4 | |||
5 | fn main() { | ||
6 | let api = Api::from_env("TELEGRAM_BOT_TOKEN").unwrap(); | ||
7 | |||
8 | println!("api started: {:?}", api.get_me()); | ||
9 | |||
10 | let mut listener = api.listener(ListeningMethod::LongPoll(None)); | ||
11 | let res = listener.listen(|u| { | ||
12 | if let Some(m) = u.message { | ||
13 | let name = m.from.first_name; | ||
14 | |||
15 | println!("got message from {}", name); | ||
16 | }; | ||
17 | Ok(ListeningAction::Continue) | ||
18 | }); | ||
19 | |||
20 | if let Err(e) = res { | ||
21 | panic!(e); | ||
22 | } | ||
23 | } | ||