2021-08-19 19:56:39 +02:00
|
|
|
use teloxide::{
|
|
|
|
prelude::*,
|
|
|
|
types::{
|
|
|
|
InlineQueryResult, InlineQueryResultArticle, InputMessageContent, InputMessageContentText,
|
|
|
|
},
|
|
|
|
Bot,
|
|
|
|
};
|
2021-08-19 06:54:32 +02:00
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
2022-01-06 12:30:27 +01:00
|
|
|
teloxide::enable_logging!();
|
|
|
|
log::info!("Starting inline_bot...");
|
|
|
|
|
2021-08-19 19:56:39 +02:00
|
|
|
let bot = Bot::from_env().auto_send();
|
2022-01-06 12:30:27 +01:00
|
|
|
|
2021-08-19 19:56:39 +02:00
|
|
|
Dispatcher::new(bot)
|
2022-01-06 12:30:27 +01:00
|
|
|
.inline_queries_handler(|b| {
|
|
|
|
b.branch(dptree::endpoint(|query: InlineQuery, bot: AutoSend<Bot>| async move {
|
2021-08-19 19:56:39 +02:00
|
|
|
// First, create your actual response
|
|
|
|
let google_search = InlineQueryResultArticle::new(
|
2021-12-26 15:55:24 +01:00
|
|
|
// Each item needs a unique ID, as well as the response container for the
|
|
|
|
// items. These can be whatever, as long as they don't
|
|
|
|
// conflict.
|
2021-08-19 19:56:39 +02:00
|
|
|
"01".to_string(),
|
|
|
|
// What the user will actually see
|
|
|
|
"Google Search",
|
2021-08-19 20:00:58 +02:00
|
|
|
// What message will be sent when clicked/tapped
|
2021-08-19 19:56:39 +02:00
|
|
|
InputMessageContent::Text(InputMessageContentText::new(format!(
|
|
|
|
"https://www.google.com/search?q={}",
|
2022-01-06 12:30:27 +01:00
|
|
|
query.query,
|
2021-08-19 19:56:39 +02:00
|
|
|
))),
|
|
|
|
);
|
2021-12-26 15:55:24 +01:00
|
|
|
// While constructing them from the struct itself is possible, it is preferred
|
|
|
|
// to use the builder pattern if you wish to add more
|
|
|
|
// information to your result. Please refer to the documentation
|
2022-01-06 13:25:01 +01:00
|
|
|
// for more detailed information about each field. https://docs.rs/teloxide/latest/teloxide/types/struct.InlineQueryResultArticle.html
|
2021-08-19 20:23:57 +02:00
|
|
|
let ddg_search = InlineQueryResultArticle::new(
|
|
|
|
"02".to_string(),
|
|
|
|
"DuckDuckGo Search".to_string(),
|
|
|
|
InputMessageContent::Text(InputMessageContentText::new(format!(
|
|
|
|
"https://duckduckgo.com/?q={}",
|
2022-01-06 12:30:27 +01:00
|
|
|
query.query.to_string()
|
2021-08-19 20:23:57 +02:00
|
|
|
))),
|
|
|
|
)
|
|
|
|
.description("DuckDuckGo Search")
|
|
|
|
.thumb_url("https://duckduckgo.com/assets/logo_header.v108.png")
|
|
|
|
.url("https://duckduckgo.com/about"); // Note: This is the url that will open if they click the thumbnail
|
2021-08-19 06:54:32 +02:00
|
|
|
|
2021-08-19 20:03:53 +02:00
|
|
|
let results = vec![
|
|
|
|
InlineQueryResult::Article(google_search),
|
|
|
|
InlineQueryResult::Article(ddg_search),
|
|
|
|
];
|
2021-08-19 20:23:57 +02:00
|
|
|
|
2021-12-26 15:55:24 +01:00
|
|
|
// Send it off! One thing to note -- the ID we use here must be of the query
|
|
|
|
// we're responding to.
|
2022-01-06 12:30:27 +01:00
|
|
|
let response = bot.answer_inline_query(&query.id, results).send().await;
|
2021-08-19 20:05:56 +02:00
|
|
|
if let Err(err) = response {
|
|
|
|
log::error!("Error in handler: {:?}", err);
|
2021-08-19 19:56:39 +02:00
|
|
|
}
|
2022-01-06 12:30:27 +01:00
|
|
|
respond(())
|
|
|
|
}))
|
2021-08-19 06:54:32 +02:00
|
|
|
})
|
2021-08-19 19:56:39 +02:00
|
|
|
.dispatch()
|
|
|
|
.await;
|
2021-08-19 06:54:32 +02:00
|
|
|
}
|