inline_query/
inline_query.rs

1use std::env;
2use bot_framework::{BotWrapper, BotHandler};
3use telegram_bot::prelude::*;
4use telegram_bot::types::*;
5use telegram_bot::Api;
6
7struct MyBot;
8
9impl BotHandler for MyBot {
10    fn inline_query(&self, api: &Api, query: InlineQuery) {
11        let input_text_message_content = InputTextMessageContent {
12            message_text: query.query.clone(),
13            parse_mode: Some(telegram_bot::ParseMode::Markdown),
14            disable_web_page_preview: true,
15        };
16
17        let mut article = InlineQueryResultArticle::new(
18            format!("{}", query.from.id),
19            format!("Hello, User!"),
20            input_text_message_content,
21        );
22        article.description(format!("This is an inline query result article"));
23
24        let mut ans = query.answer(vec![]);
25        ans.add_inline_result(article);
26        api.spawn(ans);
27    }
28}
29
30fn main() {
31    let token = env::var("TELEGRAM_BOT_KEY").expect("TELEGRAM_BOT_KEY not found in env");
32    let bot = BotWrapper::new_with_handler(token, MyBot);
33    bot.run();
34}