From 0bddf120037a6f281ad12188a55e40220c915cea Mon Sep 17 00:00:00 2001 From: admtracksteel Date: Wed, 29 Apr 2026 10:59:08 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Auto-deploy:=20BotVPS=20atualiza?= =?UTF-8?q?do=20em=2029/04/2026=2010:59:08?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ai_agent.py | 1 + bridge_telegram.py | 34 ++++++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/ai_agent.py b/ai_agent.py index 5240a06..731b80a 100644 --- a/ai_agent.py +++ b/ai_agent.py @@ -59,6 +59,7 @@ DIRETRIZES: {tools_desc} ### REGRAS DE OURO: +- FOCO NO PRESENTE: O histórico é para CONTEXTO. Foque SEMPRE no pedido ATUAL (última mensagem). Se o usuário disser "bom dia" ou mudar de assunto, não repita tarefas técnicas anteriores. - COOLIFY: NUNCA tente adivinhar caminhos de logs ou usar comandos `psql` genéricos. Use SEMPRE a ferramenta `coolify_status`. Ela é a fonte da verdade para deploies. - NUNCA tente instalar pacotes (`apt`, `npm install`, etc) ou usar tokens fictícios como ``. - Se o usuário perguntar sobre o "app mais recente", use `coolify_status` e analise a coluna `application` e `created_at`. diff --git a/bridge_telegram.py b/bridge_telegram.py index 16d718d..6b29f68 100644 --- a/bridge_telegram.py +++ b/bridge_telegram.py @@ -30,9 +30,18 @@ logging.basicConfig( ) logger = logging.getLogger(__name__) +import uuid + # Dicionário global para manter o histórico (Em um sistema de produção, usar Redis ou DB) chat_histories = {} +async def clear_history(update: Update, context: ContextTypes.DEFAULT_TYPE): + """Limpa o histórico do usuário.""" + chat_id = update.effective_chat.id + if chat_id in chat_histories: + chat_histories[chat_id] = [] + await update.message.reply_text("🧹 Histórico de conversa limpo! Como posso ajudar agora?") + async def call_antigravity_api(endpoint: str, payload: dict) -> str: """Faz a chamada para a API interna do BotVPS.""" async with httpx.AsyncClient(timeout=GLOBAL_TIMEOUT) as client: @@ -65,6 +74,13 @@ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE): text = update.message.text logger.info(f"Mensagem recebida de {user_id}: {text}") + # Lógica de reset por texto + cmd_limpar = text.lower().strip() + if cmd_limpar in ["reset", "limpar histórico", "limpar"]: + chat_histories[chat_id] = [] + await update.message.reply_text("🧹 Memória limpa. O que deseja fazer?") + return + # Inicializa histórico se não existir if chat_id not in chat_histories: chat_histories[chat_id] = [] @@ -144,11 +160,12 @@ async def handle_voice(update: Update, context: ContextTypes.DEFAULT_TYPE): user_text = data.get("text", "[Voz não transcrita]") bot_reply = data.get("reply", "Erro no processamento.") audio_url = data.get("audio_url") # Ex: /api/audio/file.mp3 + audio_url = data.get("audio_url") - # Envia transcrição do usuário (sem markdown no conteúdo para evitar bugs) + # Envia transcrição do usuário await update.message.reply_text(f"🎤 *Sua mensagem:* {user_text}") - # Envia resposta em texto com fallback se o Markdown falhar + # Envia resposta em texto try: await update.message.reply_text(bot_reply, parse_mode='Markdown') except Exception as e: @@ -181,14 +198,11 @@ if __name__ == '__main__': # Inicializa o Bot (python-telegram-bot v20+) application = ApplicationBuilder().token(TOKEN).build() - # Adiciona o handler para mensagens de texto - text_handler = MessageHandler(filters.TEXT | filters.COMMAND, handle_message) - application.add_handler(text_handler) - - # Adiciona o handler para mensagens de VOZ - import uuid - voice_handler = MessageHandler(filters.VOICE, handle_voice) - application.add_handler(voice_handler) + # Adiciona handlers + application.add_handler(CommandHandler("limpar", clear_history)) + application.add_handler(CommandHandler("clear", clear_history)) + application.add_handler(MessageHandler(filters.TEXT | filters.COMMAND, handle_message)) + application.add_handler(MessageHandler(filters.VOICE, handle_voice)) logger.info("Bot Ponte Antigravity (Middleware - Texto & Voz) iniciado...") application.run_polling()