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
use teloxide::{
prelude::*,
types::{
InlineQueryResult, InlineQueryResultArticle, InputMessageContent, InputMessageContentText,
},
Bot,
};
#[tokio::main]
async fn main() {
pretty_env_logger::init();
log::info!("Starting inline bot...");
let bot = Bot::from_env();
let handler = Update::filter_inline_query().branch(dptree::endpoint(
|bot: Bot, q: InlineQuery| async move {
let google_search = InlineQueryResultArticle::new(
"01".to_string(),
"Google Search",
InputMessageContent::Text(InputMessageContentText::new(format!(
"https://www.google.com/search?q={}",
q.query,
))),
);
let ddg_search = InlineQueryResultArticle::new(
"02".to_string(),
"DuckDuckGo Search".to_string(),
InputMessageContent::Text(InputMessageContentText::new(format!(
"https://duckduckgo.com/?q={}",
q.query
))),
)
.description("DuckDuckGo Search")
.thumb_url("https://duckduckgo.com/assets/logo_header.v108.png".parse().unwrap())
.url("https://duckduckgo.com/about".parse().unwrap()); let results = vec![
InlineQueryResult::Article(google_search),
InlineQueryResult::Article(ddg_search),
];
let response = bot.answer_inline_query(&q.id, results).send().await;
if let Err(err) = response {
log::error!("Error in handler: {:?}", err);
}
respond(())
},
));
Dispatcher::builder(bot, handler).enable_ctrlc_handler().build().dispatch().await;
}