refactor: Update credential synchronization to async Gitea fetch and simplify root HTML serving.
This commit is contained in:
21
bot_logic.py
21
bot_logic.py
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import asyncio
|
||||
import re
|
||||
import logging
|
||||
from telegram import Update
|
||||
from telegram.ext import Application, CommandHandler, MessageHandler, filters, ContextTypes
|
||||
from orchestrator import (
|
||||
@@ -12,6 +13,13 @@ import speech_recognition as sr
|
||||
from pydub import AudioSegment
|
||||
from gtts import gTTS
|
||||
|
||||
# Configuração de logging
|
||||
logging.basicConfig(
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
level=logging.INFO
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
|
||||
ALLOWED_CHAT_ID = os.getenv("TELEGRAM_CHAT_ID")
|
||||
|
||||
@@ -74,8 +82,9 @@ async def handle_text(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
else:
|
||||
# Fallback AI Agent
|
||||
from config import get_config
|
||||
from ai_agent import query_agent_async
|
||||
cfg = get_config()
|
||||
reply = query_agent(user_msg, override_provider=cfg.get("active_provider"))
|
||||
reply = await query_agent_async(user_msg, override_provider=cfg.get("active_provider"))
|
||||
await update.message.reply_text(reply)
|
||||
|
||||
async def handle_voice(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
@@ -94,6 +103,10 @@ def get_telegram_app():
|
||||
return app
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = get_telegram_app()
|
||||
print("Bot iniciando...")
|
||||
app.run_polling(drop_pending_updates=True)
|
||||
logger.info("Bot começando a inicialização...")
|
||||
try:
|
||||
app = get_telegram_app()
|
||||
logger.info("Bot online. Iniciando polling...")
|
||||
app.run_polling(drop_pending_updates=True)
|
||||
except Exception as e:
|
||||
logger.error(f"Erro fatal ao iniciar bot: {e}")
|
||||
|
||||
4
main.py
4
main.py
@@ -10,7 +10,7 @@ from fastapi.templating import Jinja2Templates
|
||||
from dotenv import load_dotenv
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
from ai_agent import query_agent
|
||||
from ai_agent import query_agent_async
|
||||
from config import get_config, save_config
|
||||
from credential_manager import fetch_from_gitea_repo_async
|
||||
from orchestrator import (
|
||||
@@ -58,7 +58,7 @@ async def get_system_status(is_auth: bool = Depends(verify_password)):
|
||||
async def web_chat(message: dict, is_auth: bool = Depends(verify_password)):
|
||||
user_text = message.get("text", "")
|
||||
if not user_text: return {"reply": "Vazio."}
|
||||
reply = query_agent(user_text)
|
||||
reply = await query_agent_async(user_text)
|
||||
return {"reply": reply}
|
||||
|
||||
@app.post("/api/orchestrate")
|
||||
|
||||
14
start.sh
14
start.sh
@@ -1,13 +1,15 @@
|
||||
#!/bin/bash
|
||||
# Tenta limpar processos conflitantes no host se tiver acesso privilégido
|
||||
# Tenta limpar processos conflitantes no host se tiver acesso privilegiado
|
||||
if [ -d "/host_root" ]; then
|
||||
echo "Limpando processos conflitantes no HOST..."
|
||||
chroot /host_root /bin/bash -c "pkill -f telegram_bot.js" || true
|
||||
chroot /host_root /bin/bash -c "pkill -f bot_logic.py" || true
|
||||
chroot /host_root /bin/bash -c "pkill -9 -f telegram_bot.js" || true
|
||||
chroot /host_root /bin/bash -c "pkill -9 -f bot_logic.py" || true
|
||||
fi
|
||||
|
||||
# Inicia o serviço web
|
||||
# Inicia o serviço web com log unbuffered
|
||||
echo "Iniciando Uvicorn..."
|
||||
uvicorn main:app --host 0.0.0.0 --port 8000 &
|
||||
|
||||
# Inicia o Polling do Bot
|
||||
python bot_logic.py
|
||||
# Inicia o Polling do Bot com log unbuffered
|
||||
echo "Iniciando Bot (bot_logic.py)..."
|
||||
python3 -u bot_logic.py
|
||||
|
||||
Reference in New Issue
Block a user