🚀 Auto-deploy: BotVPS atualizado em 29/04/2026 10:59:08

This commit is contained in:
2026-04-29 10:59:08 +00:00
parent cc7ecaf5ba
commit 0bddf12003
2 changed files with 25 additions and 10 deletions

View File

@@ -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 `<YOUR_TOKEN>`.
- Se o usuário perguntar sobre o "app mais recente", use `coolify_status` e analise a coluna `application` e `created_at`.

View File

@@ -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()