telegram-lib 0.1.0

telegram crate for simple use
Documentation
use dptree::case;
use dptree::di::{DependencySupplier, Injectable};
use std::collections::HashMap;
use std::error::Error;
use teloxide::dispatching::UpdateHandler;
use teloxide::prelude::*;
use teloxide::utils::command::BotCommands;

pub type Updater = UpdateHandler<Box<dyn Error + Send + Sync + 'static>>;

pub(crate) fn default_on_message() -> Updater {
    // let command_handler = commands::on_command();
    Update::filter_message()
}

pub struct Handler {
    handlers: Vec<Updater>,
}

impl Handler {
    pub fn new() -> Self {
        Handler {
            handlers: Vec::new(),
        }
    }

    pub fn add_handler(mut self, handler: Updater) -> Self {
        self.handlers.push(handler);
        self
    }

    pub fn build_message(self) -> Updater {
        let mut message_handler = Update::filter_message();
        for handler in self.handlers {
            message_handler = message_handler.branch(handler);
        }
        message_handler
    }

    pub fn build_command<Command>(self) -> Updater
    where
        Command: BotCommands + Send + Sync + 'static,
    {
        let mut command_handler = teloxide::filter_command::<Command, _>();
        for handler in self.handlers {
            command_handler = command_handler.branch(handler);
        }
        command_handler
    }
}