mirror of
https://github.com/flibusta-apps/book_bot.git
synced 2025-12-06 15:35:35 +01:00
Get webhook port from env
This commit is contained in:
@@ -24,7 +24,8 @@ use tower_http::trace::{self, TraceLayer};
|
|||||||
use tracing::log;
|
use tracing::log;
|
||||||
use tracing::Level;
|
use tracing::Level;
|
||||||
|
|
||||||
use crate::bots_manager::{internal::start_bot, BOTS_DATA, BOTS_ROUTES, SERVER_PORT};
|
use crate::bots_manager::{internal::start_bot, BOTS_DATA, BOTS_ROUTES};
|
||||||
|
use crate::config;
|
||||||
|
|
||||||
pub async fn start_axum_server(stop_signal: Arc<AtomicBool>) {
|
pub async fn start_axum_server(stop_signal: Arc<AtomicBool>) {
|
||||||
async fn telegram_request(
|
async fn telegram_request(
|
||||||
@@ -113,7 +114,7 @@ pub async fn start_axum_server(stop_signal: Arc<AtomicBool>) {
|
|||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
log::info!("Start webserver...");
|
log::info!("Start webserver...");
|
||||||
|
|
||||||
let addr = SocketAddr::from(([0, 0, 0, 0], SERVER_PORT));
|
let addr = SocketAddr::from(([0, 0, 0, 0], config::CONFIG.webhook_port));
|
||||||
|
|
||||||
axum::Server::bind(&addr)
|
axum::Server::bind(&addr)
|
||||||
.serve(router.into_make_service())
|
.serve(router.into_make_service())
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ use crate::config;
|
|||||||
|
|
||||||
use super::closable_sender::ClosableSender;
|
use super::closable_sender::ClosableSender;
|
||||||
use super::utils::tuple_first_mut;
|
use super::utils::tuple_first_mut;
|
||||||
use super::{BotData, SERVER_PORT};
|
use super::BotData;
|
||||||
|
|
||||||
type UpdateSender = mpsc::UnboundedSender<Result<Update, std::convert::Infallible>>;
|
type UpdateSender = mpsc::UnboundedSender<Result<Update, std::convert::Infallible>>;
|
||||||
|
|
||||||
@@ -53,7 +53,11 @@ pub async fn set_webhook(bot_data: &BotData) -> bool {
|
|||||||
|
|
||||||
let token = &bot_data.token;
|
let token = &bot_data.token;
|
||||||
|
|
||||||
let host = format!("{}:{}", &config::CONFIG.webhook_base_url, SERVER_PORT);
|
let host = format!(
|
||||||
|
"{}:{}",
|
||||||
|
&config::CONFIG.webhook_base_url,
|
||||||
|
config::CONFIG.webhook_port
|
||||||
|
);
|
||||||
let url = Url::parse(&format!("{host}/{token}/"))
|
let url = Url::parse(&format!("{host}/{token}/"))
|
||||||
.unwrap_or_else(|_| panic!("Can't parse webhook url!"));
|
.unwrap_or_else(|_| panic!("Can't parse webhook url!"));
|
||||||
|
|
||||||
|
|||||||
@@ -46,8 +46,6 @@ pub static CHAT_DONATION_NOTIFICATIONS_CACHE: Lazy<Cache<ChatId, ()>> = Lazy::ne
|
|||||||
.build()
|
.build()
|
||||||
});
|
});
|
||||||
|
|
||||||
pub static SERVER_PORT: u16 = 8080;
|
|
||||||
|
|
||||||
type StopTokenWithSender = (
|
type StopTokenWithSender = (
|
||||||
StopToken,
|
StopToken,
|
||||||
ClosableSender<Result<Update, std::convert::Infallible>>,
|
ClosableSender<Result<Update, std::convert::Infallible>>,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ pub struct Config {
|
|||||||
pub telegram_bot_api: reqwest::Url,
|
pub telegram_bot_api: reqwest::Url,
|
||||||
|
|
||||||
pub webhook_base_url: String,
|
pub webhook_base_url: String,
|
||||||
|
pub webhook_port: u16,
|
||||||
|
|
||||||
pub admin_id: String,
|
pub admin_id: String,
|
||||||
pub bot_token: String,
|
pub bot_token: String,
|
||||||
@@ -38,6 +39,7 @@ impl Config {
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
webhook_base_url: get_env("WEBHOOK_BASE_URL"),
|
webhook_base_url: get_env("WEBHOOK_BASE_URL"),
|
||||||
|
webhook_port: get_env("WEBHOOK_PORT").parse().unwrap(),
|
||||||
|
|
||||||
admin_id: get_env("ADMIN_ID"),
|
admin_id: get_env("ADMIN_ID"),
|
||||||
bot_token: get_env("BOT_TOKEN"),
|
bot_token: get_env("BOT_TOKEN"),
|
||||||
|
|||||||
Reference in New Issue
Block a user