diff --git a/Cargo.toml b/Cargo.toml index 01810db7..02aaf40e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,8 +57,8 @@ full = [ ] [dependencies] -teloxide-core = { version = "0.7.0", default-features = false } -#teloxide-macros = { version = "0.6.3", optional = true } +# teloxide-core = { version = "0.7.0", default-features = false } +# teloxide-macros = { version = "0.6.3", optional = true } serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } @@ -66,7 +66,7 @@ serde = { version = "1.0", features = ["derive"] } dptree = "0.3.0" # These lines are used only for development. -# teloxide-core = { git = "https://github.com/teloxide/teloxide-core", rev = "b13393d", default-features = false } +teloxide-core = { git = "https://github.com/teloxide/teloxide-core", rev = "00165e6", default-features = false } teloxide-macros = { git = "https://github.com/teloxide/teloxide-macros", rev = "0e79c37", optional = true } # dptree = { git = "https://github.com/teloxide/dptree", rev = "df578e4" } diff --git a/README.md b/README.md index 8ece9b1b..ae5fdd3d 100644 --- a/README.md +++ b/README.md @@ -92,9 +92,9 @@ async fn main() { pretty_env_logger::init(); log::info!("Starting throw dice bot..."); - let bot = Bot::from_env().auto_send(); + let bot = Bot::from_env(); - teloxide::repl(bot, |message: Message, bot: AutoSend| async move { + teloxide::repl(bot, |message: Message, bot: Bot| async move { bot.send_dice(message.chat.id).await?; respond(()) }) @@ -129,7 +129,7 @@ async fn main() { pretty_env_logger::init(); log::info!("Starting command bot..."); - let bot = Bot::from_env().auto_send(); + let bot = Bot::from_env(); teloxide::commands_repl(bot, answer, Command::ty()).await; } @@ -146,7 +146,7 @@ enum Command { } async fn answer( - bot: AutoSend, + bot: Bot, message: Message, command: Command, ) -> Result<(), Box> { @@ -190,18 +190,18 @@ use teloxide::{dispatching::dialogue::InMemStorage, prelude::*}; type MyDialogue = Dialogue>; type HandlerResult = Result<(), Box>; -#[derive(Clone)] +#[derive(Clone, Default)] pub enum State { + #[default] Start, ReceiveFullName, - ReceiveAge { full_name: String }, - ReceiveLocation { full_name: String, age: u8 }, -} - -impl Default for State { - fn default() -> Self { - Self::Start - } + ReceiveAge { + full_name: String, + }, + ReceiveLocation { + full_name: String, + age: u8, + }, } #[tokio::main] @@ -209,7 +209,7 @@ async fn main() { pretty_env_logger::init(); log::info!("Starting dialogue bot..."); - let bot = Bot::from_env().auto_send(); + let bot = Bot::from_env(); Dispatcher::builder( bot, @@ -229,17 +229,13 @@ async fn main() { .await; } -async fn start(bot: AutoSend, msg: Message, dialogue: MyDialogue) -> HandlerResult { +async fn start(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { bot.send_message(msg.chat.id, "Let's start! What's your full name?").await?; dialogue.update(State::ReceiveFullName).await?; Ok(()) } -async fn receive_full_name( - bot: AutoSend, - msg: Message, - dialogue: MyDialogue, -) -> HandlerResult { +async fn receive_full_name(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { match msg.text() { Some(text) => { bot.send_message(msg.chat.id, "How old are you?").await?; @@ -254,7 +250,7 @@ async fn receive_full_name( } async fn receive_age( - bot: AutoSend, + bot: Bot, msg: Message, dialogue: MyDialogue, full_name: String, // Available from `State::ReceiveAge`. @@ -273,7 +269,7 @@ async fn receive_age( } async fn receive_location( - bot: AutoSend, + bot: Bot, msg: Message, dialogue: MyDialogue, (full_name, age): (String, u8), // Available from `State::ReceiveLocation`. diff --git a/examples/admin.rs b/examples/admin.rs index 298d62b5..db45e3fa 100644 --- a/examples/admin.rs +++ b/examples/admin.rs @@ -58,13 +58,11 @@ async fn main() { pretty_env_logger::init(); log::info!("Starting admin bot..."); - let bot = teloxide::Bot::from_env().auto_send(); + let bot = teloxide::Bot::from_env(); teloxide::commands_repl(bot, action, Command::ty()).await; } -type Bot = AutoSend; - async fn action( bot: Bot, msg: Message, diff --git a/examples/buttons.rs b/examples/buttons.rs index e2a54bfe..f3bf3cba 100644 --- a/examples/buttons.rs +++ b/examples/buttons.rs @@ -23,7 +23,7 @@ async fn main() -> Result<(), Box> { pretty_env_logger::init(); log::info!("Starting buttons bot..."); - let bot = Bot::from_env().auto_send(); + let bot = Bot::from_env(); let handler = dptree::entry() .branch(Update::filter_message().endpoint(message_handler)) @@ -58,11 +58,7 @@ fn make_keyboard() -> InlineKeyboardMarkup { /// Parse the text wrote on Telegram and check if that text is a valid command /// or not, then match the command. If the command is `/start` it writes a /// markup with the `InlineKeyboardMarkup`. -async fn message_handler( - m: Message, - bot: AutoSend, - me: Me, -) -> Result<(), Box> { +async fn message_handler(m: Message, bot: Bot, me: Me) -> Result<(), Box> { if let Some(text) = m.text() { match BotCommands::parse(text, me.username()) { Ok(Command::Help) => { @@ -86,7 +82,7 @@ async fn message_handler( async fn inline_query_handler( q: InlineQuery, - bot: AutoSend, + bot: Bot, ) -> Result<(), Box> { let choose_debian_version = InlineQueryResultArticle::new( "0", @@ -105,10 +101,7 @@ async fn inline_query_handler( /// /// **IMPORTANT**: do not send privacy-sensitive data this way!!! /// Anyone can read data stored in the callback button. -async fn callback_handler( - q: CallbackQuery, - bot: AutoSend, -) -> Result<(), Box> { +async fn callback_handler(q: CallbackQuery, bot: Bot) -> Result<(), Box> { if let Some(version) = q.data { let text = format!("You chose: {version}"); diff --git a/examples/command.rs b/examples/command.rs index 5b30240a..11a2ce55 100644 --- a/examples/command.rs +++ b/examples/command.rs @@ -7,7 +7,7 @@ async fn main() { pretty_env_logger::init(); log::info!("Starting command bot..."); - let bot = Bot::from_env().auto_send(); + let bot = Bot::from_env(); teloxide::commands_repl(bot, answer, Command::ty()).await; } @@ -24,7 +24,7 @@ enum Command { } async fn answer( - bot: AutoSend, + bot: Bot, message: Message, command: Command, ) -> Result<(), Box> { diff --git a/examples/db_remember.rs b/examples/db_remember.rs index 1aed2808..f1e5e4c9 100644 --- a/examples/db_remember.rs +++ b/examples/db_remember.rs @@ -35,7 +35,7 @@ async fn main() { pretty_env_logger::init(); log::info!("Starting DB remember bot..."); - let bot = Bot::from_env().auto_send(); + let bot = Bot::from_env(); let storage: MyStorage = if std::env::var("DB_REMEMBER_REDIS").is_ok() { RedisStorage::open("redis://127.0.0.1:6379", Bincode).await.unwrap().erase() @@ -60,7 +60,7 @@ async fn main() { .await; } -async fn start(bot: AutoSend, msg: Message, dialogue: MyDialogue) -> HandlerResult { +async fn start(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { match msg.text().map(|text| text.parse::()) { Some(Ok(n)) => { dialogue.update(State::GotNumber(n)).await?; @@ -79,7 +79,7 @@ async fn start(bot: AutoSend, msg: Message, dialogue: MyDialogue) -> Handle } async fn got_number( - bot: AutoSend, + bot: Bot, msg: Message, dialogue: MyDialogue, num: i32, @@ -97,7 +97,7 @@ async fn got_number( Ok(()) } -async fn invalid_command(bot: AutoSend, msg: Message) -> HandlerResult { +async fn invalid_command(bot: Bot, msg: Message) -> HandlerResult { bot.send_message(msg.chat.id, "Please, send /get or /reset.").await?; Ok(()) } diff --git a/examples/dialogue.rs b/examples/dialogue.rs index 8e30219d..5fc54b3b 100644 --- a/examples/dialogue.rs +++ b/examples/dialogue.rs @@ -37,7 +37,7 @@ async fn main() { pretty_env_logger::init(); log::info!("Starting dialogue bot..."); - let bot = Bot::from_env().auto_send(); + let bot = Bot::from_env(); Dispatcher::builder( bot, @@ -57,17 +57,13 @@ async fn main() { .await; } -async fn start(bot: AutoSend, msg: Message, dialogue: MyDialogue) -> HandlerResult { +async fn start(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { bot.send_message(msg.chat.id, "Let's start! What's your full name?").await?; dialogue.update(State::ReceiveFullName).await?; Ok(()) } -async fn receive_full_name( - bot: AutoSend, - msg: Message, - dialogue: MyDialogue, -) -> HandlerResult { +async fn receive_full_name(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { match msg.text() { Some(text) => { bot.send_message(msg.chat.id, "How old are you?").await?; @@ -82,7 +78,7 @@ async fn receive_full_name( } async fn receive_age( - bot: AutoSend, + bot: Bot, msg: Message, dialogue: MyDialogue, full_name: String, // Available from `State::ReceiveAge`. @@ -101,7 +97,7 @@ async fn receive_age( } async fn receive_location( - bot: AutoSend, + bot: Bot, msg: Message, dialogue: MyDialogue, (full_name, age): (String, u8), // Available from `State::ReceiveLocation`. diff --git a/examples/dispatching_features.rs b/examples/dispatching_features.rs index dcaf4fcc..1f34dc1d 100644 --- a/examples/dispatching_features.rs +++ b/examples/dispatching_features.rs @@ -14,7 +14,7 @@ async fn main() { pretty_env_logger::init(); log::info!("Starting dispatching features bot..."); - let bot = Bot::from_env().auto_send(); + let bot = Bot::from_env(); let parameters = ConfigParameters { bot_maintainer: UserId(0), // Paste your ID to run this bot. @@ -37,25 +37,23 @@ async fn main() { msg.from().map(|user| user.id == cfg.bot_maintainer).unwrap_or_default() }) .filter_command::() - .endpoint( - |msg: Message, bot: AutoSend, cmd: MaintainerCommands| async move { - match cmd { - MaintainerCommands::Rand { from, to } => { - let mut rng = rand::rngs::OsRng::default(); - let value: u64 = rng.gen_range(from..=to); + .endpoint(|msg: Message, bot: Bot, cmd: MaintainerCommands| async move { + match cmd { + MaintainerCommands::Rand { from, to } => { + let mut rng = rand::rngs::OsRng::default(); + let value: u64 = rng.gen_range(from..=to); - bot.send_message(msg.chat.id, value.to_string()).await?; - Ok(()) - } + bot.send_message(msg.chat.id, value.to_string()).await?; + Ok(()) } - }, - ), + } + }), ) .branch( // Filtering allow you to filter updates by some condition. dptree::filter(|msg: Message| msg.chat.is_group() || msg.chat.is_supergroup()) // An endpoint is the last update handler. - .endpoint(|msg: Message, bot: AutoSend| async move { + .endpoint(|msg: Message, bot: Bot| async move { log::info!("Received a message from a group chat."); bot.send_message(msg.chat.id, "This is a group chat.").await?; respond(()) @@ -64,14 +62,12 @@ async fn main() { .branch( // There are some extension filtering functions on `Message`. The following filter will // filter only messages with dices. - Message::filter_dice().endpoint( - |msg: Message, dice: Dice, bot: AutoSend| async move { - bot.send_message(msg.chat.id, format!("Dice value: {}", dice.value)) - .reply_to_message_id(msg.id) - .await?; - Ok(()) - }, - ), + Message::filter_dice().endpoint(|msg: Message, dice: Dice, bot: Bot| async move { + bot.send_message(msg.chat.id, format!("Dice value: {}", dice.value)) + .reply_to_message_id(msg.id) + .await?; + Ok(()) + }), ); Dispatcher::builder(bot, handler) @@ -119,7 +115,7 @@ enum MaintainerCommands { async fn simple_commands_handler( msg: Message, - bot: AutoSend, + bot: Bot, cmd: SimpleCommand, cfg: ConfigParameters, me: teloxide::types::Me, diff --git a/examples/heroku_ping_pong.rs b/examples/heroku_ping_pong.rs index 6bf7f158..5c8def6a 100644 --- a/examples/heroku_ping_pong.rs +++ b/examples/heroku_ping_pong.rs @@ -27,7 +27,7 @@ async fn main() { pretty_env_logger::init(); log::info!("Starting Heroku ping-pong bot..."); - let bot = Bot::from_env().auto_send(); + let bot = Bot::from_env(); // Heroku auto defines a port value let port: u16 = env::var("PORT") @@ -47,7 +47,7 @@ async fn main() { teloxide::repl_with_listener( bot, - |msg: Message, bot: AutoSend| async move { + |msg: Message, bot: Bot| async move { bot.send_message(msg.chat.id, "pong").await?; respond(()) }, diff --git a/examples/inline.rs b/examples/inline.rs index 837fa30d..f9536b02 100644 --- a/examples/inline.rs +++ b/examples/inline.rs @@ -11,10 +11,10 @@ async fn main() { pretty_env_logger::init(); log::info!("Starting inline bot..."); - let bot = Bot::from_env().auto_send(); + let bot = Bot::from_env(); let handler = Update::filter_inline_query().branch(dptree::endpoint( - |query: InlineQuery, bot: AutoSend| async move { + |query: InlineQuery, bot: Bot| async move { // First, create your actual response let google_search = InlineQueryResultArticle::new( // Each item needs a unique ID, as well as the response container for the diff --git a/examples/ngrok_ping_pong.rs b/examples/ngrok_ping_pong.rs index f44086c6..6f9eefb0 100644 --- a/examples/ngrok_ping_pong.rs +++ b/examples/ngrok_ping_pong.rs @@ -8,7 +8,7 @@ async fn main() { pretty_env_logger::init(); log::info!("Starting ngrok ping-pong bot..."); - let bot = Bot::from_env().auto_send(); + let bot = Bot::from_env(); let addr = ([127, 0, 0, 1], 8443).into(); let url = "Your HTTPS ngrok URL here. Get it by `ngrok http 8443`".parse().unwrap(); @@ -18,7 +18,7 @@ async fn main() { teloxide::repl_with_listener( bot, - |msg: Message, bot: AutoSend| async move { + |msg: Message, bot: Bot| async move { bot.send_message(msg.chat.id, "pong").await?; respond(()) }, diff --git a/examples/purchase.rs b/examples/purchase.rs index 0eac1ad3..79b4e81c 100644 --- a/examples/purchase.rs +++ b/examples/purchase.rs @@ -48,7 +48,7 @@ async fn main() { pretty_env_logger::init(); log::info!("Starting purchase bot..."); - let bot = Bot::from_env().auto_send(); + let bot = Bot::from_env(); Dispatcher::builder(bot, schema()) .dependencies(dptree::deps![InMemStorage::::new()]) @@ -83,34 +83,30 @@ fn schema() -> UpdateHandler> .branch(callback_query_handler) } -async fn start(bot: AutoSend, msg: Message, dialogue: MyDialogue) -> HandlerResult { +async fn start(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { bot.send_message(msg.chat.id, "Let's start! What's your full name?").await?; dialogue.update(State::ReceiveFullName).await?; Ok(()) } -async fn help(bot: AutoSend, msg: Message) -> HandlerResult { +async fn help(bot: Bot, msg: Message) -> HandlerResult { bot.send_message(msg.chat.id, Command::descriptions().to_string()).await?; Ok(()) } -async fn cancel(bot: AutoSend, msg: Message, dialogue: MyDialogue) -> HandlerResult { +async fn cancel(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { bot.send_message(msg.chat.id, "Cancelling the dialogue.").await?; dialogue.exit().await?; Ok(()) } -async fn invalid_state(bot: AutoSend, msg: Message) -> HandlerResult { +async fn invalid_state(bot: Bot, msg: Message) -> HandlerResult { bot.send_message(msg.chat.id, "Unable to handle the message. Type /help to see the usage.") .await?; Ok(()) } -async fn receive_full_name( - bot: AutoSend, - msg: Message, - dialogue: MyDialogue, -) -> HandlerResult { +async fn receive_full_name(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { match msg.text().map(ToOwned::to_owned) { Some(full_name) => { let products = ["Apple", "Banana", "Orange", "Potato"] @@ -130,7 +126,7 @@ async fn receive_full_name( } async fn receive_product_selection( - bot: AutoSend, + bot: Bot, q: CallbackQuery, dialogue: MyDialogue, full_name: String, diff --git a/examples/shared_state.rs b/examples/shared_state.rs index 21a0fcc0..4caf9995 100644 --- a/examples/shared_state.rs +++ b/examples/shared_state.rs @@ -12,11 +12,11 @@ async fn main() { pretty_env_logger::init(); log::info!("Starting shared state bot..."); - let bot = Bot::from_env().auto_send(); + let bot = Bot::from_env(); let messages_total = Arc::new(AtomicU64::new(0)); let handler = Update::filter_message().endpoint( - |msg: Message, bot: AutoSend, messages_total: Arc| async move { + |msg: Message, bot: Bot, messages_total: Arc| async move { let previous = messages_total.fetch_add(1, Ordering::Relaxed); bot.send_message(msg.chat.id, format!("I received {previous} messages in total.")) .await?; diff --git a/examples/throw_dice.rs b/examples/throw_dice.rs index 758778b1..39272378 100644 --- a/examples/throw_dice.rs +++ b/examples/throw_dice.rs @@ -7,9 +7,9 @@ async fn main() { pretty_env_logger::init(); log::info!("Starting throw dice bot..."); - let bot = Bot::from_env().auto_send(); + let bot = Bot::from_env(); - teloxide::repl(bot, |message: Message, bot: AutoSend| async move { + teloxide::repl(bot, |message: Message, bot: Bot| async move { bot.send_dice(message.chat.id).await?; respond(()) }) diff --git a/src/dispatching.rs b/src/dispatching.rs index b650b308..c22cf4b9 100644 --- a/src/dispatching.rs +++ b/src/dispatching.rs @@ -108,7 +108,7 @@ //! Show the endpoints //! //! ```no_run -//! # use teloxide::{Bot, adaptors::AutoSend}; +//! # use teloxide::Bot; //! # use teloxide::types::{Message, CallbackQuery}; //! # use teloxide::dispatching::dialogue::{InMemStorage, Dialogue}; //! # enum State{} @@ -116,32 +116,28 @@ //! type MyDialogue = Dialogue>; //! type HandlerResult = Result<(), Box>; //! -//! async fn start(bot: AutoSend, msg: Message, dialogue: MyDialogue) -> HandlerResult { +//! async fn start(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { //! todo!() //! } //! -//! async fn help(bot: AutoSend, msg: Message) -> HandlerResult { +//! async fn help(bot: Bot, msg: Message) -> HandlerResult { //! todo!() //! } //! -//! async fn cancel(bot: AutoSend, msg: Message, dialogue: MyDialogue) -> HandlerResult { +//! async fn cancel(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { //! todo!() //! } //! -//! async fn invalid_state(bot: AutoSend, msg: Message) -> HandlerResult { +//! async fn invalid_state(bot: Bot, msg: Message) -> HandlerResult { //! todo!() //! } //! -//! async fn receive_full_name( -//! bot: AutoSend, -//! msg: Message, -//! dialogue: MyDialogue, -//! ) -> HandlerResult { +//! async fn receive_full_name(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { //! todo!() //! } //! //! async fn receive_product_selection( -//! bot: AutoSend, +//! bot: Bot, //! q: CallbackQuery, //! dialogue: MyDialogue, //! full_name: String, @@ -153,7 +149,7 @@ //! //! //! Each parameter is supplied as a dependency by teloxide. In particular: -//! - `bot: AutoSend` comes from the dispatcher (see below) +//! - `bot: Bot` comes from the dispatcher (see below) //! - `msg: Message` comes from [`Update::filter_message`] //! - `q: CallbackQuery` comes from [`Update::filter_callback_query`] //! - `dialogue: MyDialogue` comes from [`dialogue::enter`] @@ -170,7 +166,7 @@ //! # fn schema() -> teloxide::dispatching::UpdateHandler> { teloxide::dptree::entry() } //! #[tokio::main] //! async fn main() { -//! let bot = Bot::from_env().auto_send(); +//! let bot = Bot::from_env(); //! //! Dispatcher::builder(bot, schema()) //! .dependencies(dptree::deps![InMemStorage::::new()]) diff --git a/src/dispatching/dialogue.rs b/src/dispatching/dialogue.rs index 724af2e2..1ecffde2 100644 --- a/src/dispatching/dialogue.rs +++ b/src/dispatching/dialogue.rs @@ -38,7 +38,7 @@ //! # type HandlerResult = Result<(), Box>; //! # #[derive(Clone, Debug)] enum State { ReceiveLocation { full_name: String, age: u8 } } //! async fn receive_age( -//! bot: AutoSend, +//! bot: Bot, //! msg: Message, //! dialogue: MyDialogue, //! full_name: String, // Available from `State::ReceiveAge`. @@ -70,7 +70,7 @@ //! # type HandlerResult = Result<(), Box>; //! # #[derive(Clone, Debug)] enum State {} //! async fn receive_location( -//! bot: AutoSend, +//! bot: Bot, //! msg: Message, //! dialogue: MyDialogue, //! (full_name, age): (String, u8), // Available from `State::ReceiveLocation`. diff --git a/src/features.md b/src/features.md index 2c4b2951..c7aa4e6a 100644 --- a/src/features.md +++ b/src/features.md @@ -6,7 +6,7 @@ | `webhooks-axum` | Enables webhook implementation based on axum framework | | `macros` | Re-exports macros from [`teloxide-macros`]. | | `ctrlc_handler` | Enables the [`DispatcherBuilder::enable_ctrlc_handler`] function (**enabled by default**). | -| `auto-send` | Enables the [`AutoSend`](adaptors::AutoSend) bot adaptor (**enabled by default**). | +| `auto-send` | Enables the [`AutoSend`](adaptors::AutoSend) bot adaptor (**enabled by default; DEPRECATED**). | | `throttle` | Enables the [`Throttle`](adaptors::Throttle) bot adaptor. | | `cache-me` | Enables the [`CacheMe`](adaptors::CacheMe) bot adaptor. | | `trace-adaptor` | Enables the [`Trace`](adaptors::Trace) bot adaptor. | diff --git a/src/lib.rs b/src/lib.rs index 21ae0338..aad4c98c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,9 +13,9 @@ //! pretty_env_logger::init(); //! log::info!("Starting throw dice bot..."); //! -//! let bot = Bot::from_env().auto_send(); +//! let bot = Bot::from_env(); //! -//! teloxide::repl(bot, |message: Message, bot: AutoSend| async move { +//! teloxide::repl(bot, |message: Message, bot: Bot| async move { //! bot.send_dice(message.chat.id).await?; //! respond(()) //! }) diff --git a/src/prelude.rs b/src/prelude.rs index 3cbf6ca5..46e4d0b7 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -15,6 +15,7 @@ pub use teloxide_core::types::{ }; #[cfg(feature = "auto-send")] +#[allow(deprecated)] pub use crate::adaptors::AutoSend; #[doc(no_inline)]