implement telegram-bot-api StatefulSet and ClusterIP service
This commit is contained in:
parent
5bc4c47145
commit
ea193a8b0f
3 changed files with 35 additions and 4 deletions
|
|
@ -23,6 +23,19 @@ spec:
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8081
|
- containerPort: 8081
|
||||||
name: tg
|
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:
|
volumeMounts:
|
||||||
- name: tg-data
|
- name: tg-data
|
||||||
mountPath: /app
|
mountPath: /app
|
||||||
|
|
|
||||||
14
k8s/06_tg-service.yml
Normal file
14
k8s/06_tg-service.yml
Normal 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
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
use anyhow;
|
use anyhow;
|
||||||
use rust_i18n::t;
|
use rust_i18n::t;
|
||||||
use std::str;
|
use url::Url;
|
||||||
|
use std::str::{self, FromStr};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use teloxide::dispatching::{dialogue, dialogue::InMemStorage, UpdateHandler};
|
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 teloxide::{prelude::*, update_listeners::Polling, utils::command::BotCommands};
|
||||||
use tracing::{event, Level};
|
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<()> {
|
pub async fn bot_main(db: DbPool) -> anyhow::Result<()> {
|
||||||
event!(Level::INFO, "start");
|
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())
|
let listener = Polling::builder(bot.clone())
|
||||||
.timeout(Duration::from_secs(parse_env("POLLING_TIMEOUT")))
|
.timeout(Duration::from_secs(parse_env("POLLING_TIMEOUT")))
|
||||||
.limit(parse_env("POLLING_LIMIT"))
|
.limit(parse_env("POLLING_LIMIT"))
|
||||||
|
|
@ -129,7 +132,8 @@ enum Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn cmd_test(bot: Bot, msg: Message, _db: DbPool) -> HandlerResult {
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue