use poem::http::StatusCode; use telegram_bot::TelegramBot; use poem::web::{Data,IntoResponse, Json}; use poem::{handler, Response}; use redis; use telegram_bot::telegram_types::TelegramUpdate; use sea_orm::DatabaseConnection; use google_sheets4 as sheets4; use sheets4::{Sheets, hyper_rustls, hyper_util}; #[derive(Clone)] pub struct AppState { pub conn: DatabaseConnection, pub templates: tera::Tera, pub redis_client: redis::Client, pub tg_bot: TelegramBot, pub gs_hub: Sheets>, pub sheet_id: String, } #[handler] pub async fn tg_bot_handler(state: Data<&AppState>, req: Json) -> impl IntoResponse { let tg_bot = &state.tg_bot; if tg_bot.check_if_handled(req.update_id).unwrap() { return Response::builder() .status(StatusCode::ALREADY_REPORTED) .body(()); } msg_handler::handle_message( &req.message, &tg_bot, &state.conn, &state.gs_hub, &state.sheet_id ).await; match tg_bot.mark_as_handled(req.update_id) { Ok(_) => { return Response::builder() .status(StatusCode::OK) .body(()); }, Err(_) => return Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(()) } }