implement telegram-bot-api StatefulSet and ClusterIP service

This commit is contained in:
mykola2312 2024-03-16 10:48:56 +02:00
parent 2ba2b6cb0b
commit b6f0eb82fb
3 changed files with 35 additions and 4 deletions

View file

@ -23,6 +23,19 @@ spec:
ports:
- containerPort: 8081
name: tg
env:
- name: API_ID
valueFrom:
secretKeyRef:
name: secret
key: BOT_API_ID
- name: API_HASH
valueFrom:
secretKeyRef:
name: secret
key: BOT_API_HASH
- name: HTTP_PORT
value: "8081"
volumeMounts:
- name: tg-data
mountPath: /app

14
k8s/06_tg-service.yml Normal file
View file

@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: tg-service
namespace: mk-dl-bot
spec:
selector:
app: mk-dl-bot
service: tg
type: ClusterIP
ports:
- name: tg
protocol: TCP
port: 8081

View file

@ -1,9 +1,10 @@
use anyhow;
use rust_i18n::t;
use std::str;
use url::Url;
use std::str::{self, FromStr};
use std::time::Duration;
use teloxide::dispatching::{dialogue, dialogue::InMemStorage, UpdateHandler};
use teloxide::types::{Me, MessageKind, MessageNewChatMembers, UpdateKind};
use teloxide::types::{InputFile, InputMediaVideo, Me, MessageKind, MessageNewChatMembers, UpdateKind};
use teloxide::{prelude::*, update_listeners::Polling, utils::command::BotCommands};
use tracing::{event, Level};
@ -24,7 +25,9 @@ use super::start::{cmd_start, handle_my_chat_member};
pub async fn bot_main(db: DbPool) -> anyhow::Result<()> {
event!(Level::INFO, "start");
let bot = Bot::new(unwrap_env("BOT_TOKEN"));
let bot = Bot::new(unwrap_env("BOT_TOKEN"))
.set_api_url(Url::from_str(&unwrap_env("BOT_API_URL"))?);
let listener = Polling::builder(bot.clone())
.timeout(Duration::from_secs(parse_env("POLLING_TIMEOUT")))
.limit(parse_env("POLLING_LIMIT"))
@ -129,7 +132,8 @@ enum Command {
}
async fn cmd_test(bot: Bot, msg: Message, _db: DbPool) -> HandlerResult {
bot.send_message(msg.chat.id, t!("test_response")).await?;
//bot.send_message(msg.chat.id, t!("test_response")).await?;
bot.send_video(msg.chat.id, InputFile::url(Url::from_str("http://mkdlbot.ddns.net/output3.mp4")?)).await?;
Ok(())
}