telegram_bot2/__private/
mod.rs

1use async_trait::async_trait;
2
3#[cfg(feature = "daemons")]
4pub mod daemon;
5
6#[cfg(feature = "commands")]
7pub mod command;
8
9use crate::bot::Bot;
10use crate::models::{Update, UpdateType};
11use crate::state::BotState;
12
13pub struct GenericHandler<T>
14where
15    T: Sync,
16{
17    pub rank: usize,
18    pub name: &'static str,
19    pub handler: Box<dyn Handler<T>>,
20    pub updates: Vec<UpdateType>,
21}
22
23/// Handles an incoming update\
24/// This trait should not be manually implemented, instead use the [`handler`](crate::handler) and [`command`](crate::command) macros
25#[async_trait]
26pub trait Handler<T: Sync> {
27    /// Handles an incoming update
28    async fn handle(&self, bot: &Bot, update: &Update, state: Option<&BotState<T>>) -> Result<(), HandlerError>;
29}
30
31/// Error returned by a handler\
32/// This enum should not be used
33#[derive(Debug)]
34pub enum HandlerError {
35    /// Could not parse arguments, delegates to the next handler
36    Parse,
37    /// Parsing successful, but the handler failed, stop the update processing
38    Runtime,
39}