mirror of
https://github.com/teloxide/teloxide.git
synced 2024-10-24 09:57:18 +02:00
Remove unused dispatcher variable, Bot to AutoSend
This commit is contained in:
parent
ea5b2df251
commit
93c8e00086
1 changed files with 70 additions and 60 deletions
|
@ -1,4 +1,11 @@
|
||||||
use teloxide::{Bot, payloads::AnswerInlineQuery, prelude::*, types::{InlineQueryResult, InlineQueryResultArticle, InputMessageContent, InputMessageContentText}};
|
use teloxide::{
|
||||||
|
payloads::AnswerInlineQuery,
|
||||||
|
prelude::*,
|
||||||
|
types::{
|
||||||
|
InlineQueryResult, InlineQueryResultArticle, InputMessageContent, InputMessageContentText,
|
||||||
|
},
|
||||||
|
Bot,
|
||||||
|
};
|
||||||
use tokio_stream::wrappers::UnboundedReceiverStream;
|
use tokio_stream::wrappers::UnboundedReceiverStream;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
@ -7,67 +14,70 @@ async fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run() {
|
async fn run() {
|
||||||
let bot = Bot::from_env();
|
let bot = Bot::from_env().auto_send();
|
||||||
// Create a new dispatcher to handle incoming messages
|
// Create a new dispatcher to handle incoming messages
|
||||||
let dp = Dispatcher::new(bot);
|
Dispatcher::new(bot)
|
||||||
dp.inline_queries_handler(|rx: DispatcherHandlerRx<Bot, InlineQuery>| {
|
.inline_queries_handler(|rx: DispatcherHandlerRx<AutoSend<Bot>, InlineQuery>| {
|
||||||
UnboundedReceiverStream::new(rx).for_each_concurrent(None, |msg| async move {
|
UnboundedReceiverStream::new(rx).for_each_concurrent(None, |msg| async move {
|
||||||
// First, create your actual response
|
// First, create your actual response
|
||||||
let google_search = InlineQueryResultArticle::new(
|
let google_search = InlineQueryResultArticle::new(
|
||||||
// Each item needs a unique ID, as well as the response container for the items.
|
// 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.
|
// These can be whatever, as long as they don't conflict.
|
||||||
"01".to_string(),
|
"01".to_string(),
|
||||||
// What the user will actually see
|
// What the user will actually see
|
||||||
"Google Search",
|
"Google Search",
|
||||||
// What message will send when clicked/tapped
|
// What message will send when clicked/tapped
|
||||||
InputMessageContent::Text(InputMessageContentText::new(format!(
|
InputMessageContent::Text(InputMessageContentText::new(format!(
|
||||||
"https://www.google.com/search?q={}",
|
"https://www.google.com/search?q={}",
|
||||||
msg.update.query,
|
msg.update.query,
|
||||||
))),
|
))),
|
||||||
);
|
);
|
||||||
// You can also construct them from the struct itself, if you want a little more control.
|
// You can also construct them from the struct itself, if you want a little more control.
|
||||||
// Please refer to the documentation for more detailed information about each field.
|
// Please refer to the documentation for more detailed information about each field.
|
||||||
// https://docs.rs/teloxide/0.5.1/teloxide/types/struct.InlineQueryResultArticle.html
|
// https://docs.rs/teloxide/0.5.1/teloxide/types/struct.InlineQueryResultArticle.html
|
||||||
let ddg_search = InlineQueryResultArticle {
|
let ddg_search = InlineQueryResultArticle {
|
||||||
id: "02".to_string(), // again, anything -- as long as it's unique in this context
|
id: "02".to_string(), // again, anything -- as long as it's unique in this context
|
||||||
title: "DuckDuckGo Search".to_string(),
|
title: "DuckDuckGo Search".to_string(),
|
||||||
input_message_content: InputMessageContent::Text(InputMessageContentText::new(
|
input_message_content: InputMessageContent::Text(InputMessageContentText::new(
|
||||||
format!("https://duckduckgo.com/?q={}", msg.update.query.to_string()),
|
format!("https://duckduckgo.com/?q={}", msg.update.query.to_string()),
|
||||||
)),
|
)),
|
||||||
reply_markup: None,
|
reply_markup: None,
|
||||||
url: Some("https://duckduckgo.com/about".to_string()), // Note: This is the url that will open if they click the thumbnail
|
url: Some("https://duckduckgo.com/about".to_string()), // Note: This is the url that will open if they click the thumbnail
|
||||||
hide_url: None,
|
hide_url: None,
|
||||||
description: Some("DuckDuckGo Search".to_string()),
|
description: Some("DuckDuckGo Search".to_string()),
|
||||||
thumb_url: Some(
|
thumb_url: Some(
|
||||||
"https://duckduckgo.com/assets/logo_header.v108.png".to_string(),
|
"https://duckduckgo.com/assets/logo_header.v108.png".to_string(),
|
||||||
),
|
),
|
||||||
thumb_width: Some(64),
|
thumb_width: Some(64),
|
||||||
thumb_height: Some(64),
|
thumb_height: Some(64),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Now put those responses into a "Result"
|
// Now put those responses into a "Result"
|
||||||
// https://docs.rs/teloxide/0.5.1/teloxide/payloads/struct.AnswerInlineQuery.html
|
// https://docs.rs/teloxide/0.5.1/teloxide/payloads/struct.AnswerInlineQuery.html
|
||||||
let all_results = AnswerInlineQuery {
|
let all_results = AnswerInlineQuery {
|
||||||
inline_query_id: "03".to_string(), // again, anything -- as long as it's unique in this context
|
inline_query_id: "03".to_string(), // again, anything -- as long as it's unique in this context
|
||||||
results: vec![InlineQueryResult::Article(google_search), InlineQueryResult::Article(ddg_search)],
|
results: vec![
|
||||||
cache_time: None,
|
InlineQueryResult::Article(google_search),
|
||||||
is_personal: None,
|
InlineQueryResult::Article(ddg_search),
|
||||||
next_offset: None,
|
],
|
||||||
switch_pm_text: None,
|
cache_time: None,
|
||||||
switch_pm_parameter: None,
|
is_personal: None,
|
||||||
};
|
next_offset: None,
|
||||||
|
switch_pm_text: None,
|
||||||
|
switch_pm_parameter: None,
|
||||||
|
};
|
||||||
|
|
||||||
// Send it off! One thing to note -- the ID we use here must be of the message we're responding to.
|
// Send it off! One thing to note -- the ID we use here must be of the message we're responding to.
|
||||||
let response = msg
|
let response = msg
|
||||||
.requester
|
.requester
|
||||||
.answer_inline_query(msg.update.id.to_string(), all_results.results)
|
.answer_inline_query(msg.update.id.to_string(), all_results.results)
|
||||||
.send()
|
.send()
|
||||||
.await;
|
.await;
|
||||||
if response.is_err() {
|
if response.is_err() {
|
||||||
dbg!(response);
|
dbg!(response);
|
||||||
}
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
.dispatch()
|
||||||
.dispatch()
|
.await;
|
||||||
.await;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue