Adiciona ao repo os scripts e configs reais do motor que estavam fora do git,
e remove arquivos legados/abandonados.
Adicionados (30):
- scripts/docker-compose.m5.yml, openwa-compose.yml, minio-compose.yml
- scripts/openwa.env (sem secrets)
- scripts/{entrypoint,saleor-entrypoint,saleor-start}.sh
- scripts/{chatwoot-setup,compliance-check,health-check,resumo-diario}.sh
- scripts/{insert_workflow,telegram_user_login,telegram_user_monitor}.py
- scripts/requirements.txt
- scripts/traefik-conf/{traefik.yml,dynamic-config.yml}
- scripts/compliance/, scripts/calculators/, scripts/backups/
- scripts/{README.md,README-INSTALL.md,WHATSAPP-SETUP.md,.gitignore}
- .gitignore (atualizado)
Removidos (ja' em backup/untracked-lixo-2026-07-06/):
- agents/, crm/, hermes_skills_backup/, api-complive/, docs/ (legados)
- scripts/{wrapper.py,wrapper.sh}
- scripts/docker-compose.m5.yml.backup, traefik-conf/routes.yml.bak2
- scripts/saleor-media/RSA_*.{bak,old_*}
- scripts/n8n-workflows/webhook-saleor.json.bak2
- scripts/backups/20260622_0300/saleor_db.sql
- integracao_completa.sh, monitoramento_vps.sh
- ruvector.db (vazio)
Ignorados via .gitignore:
- vault/ (Obsidian KB)
- skills/ (duplicado de ~/.hermes/skills/)
- scripts/{saleor-media,traefik-acme,yt-pub-livesx,minio,n8n-workflows,skills}/
- scripts/backups/2026*_*/
95 lines
3.5 KiB
Python
95 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Monitora a conta de usuário do Telegram via Telethon.
|
|
Reenvia mensagens recebidas para o Hermes processar.
|
|
Mantém diálogo contínuo em /root/.hermes/telegram_user.session
|
|
"""
|
|
import asyncio
|
|
import logging
|
|
import os
|
|
import sys
|
|
from datetime import datetime
|
|
|
|
# Setup
|
|
API_ID = 35430577
|
|
API_HASH = "bf7926bd5830a1d2ebf502e538a0d816"
|
|
SESSION_FILE = "/root/.hermes/telegram_user.session"
|
|
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format="%(asctime)s [%(levelname)s] %(message)s",
|
|
handlers=[
|
|
logging.FileHandler("/root/.hermes/logs/telegram_user.log"),
|
|
logging.StreamHandler(sys.stdout),
|
|
],
|
|
)
|
|
log = logging.getLogger("telegram_user")
|
|
|
|
# Pasta para salvar state
|
|
STATE_FILE = "/root/.hermes/telegram_user_state.json"
|
|
|
|
|
|
async def main():
|
|
from telethon import TelegramClient
|
|
|
|
client = TelegramClient(SESSION_FILE, API_ID, API_HASH)
|
|
|
|
async with client:
|
|
me = await client.get_me()
|
|
log.info(f"=== Monitorando conta: {me.first_name} (@{me.username}) ===")
|
|
log.info(f"User ID: {me.id}")
|
|
log.info("Aguardando mensagens...")
|
|
|
|
from telethon import events
|
|
|
|
@client.on(events.NewMessage(incoming=True))
|
|
async def handler(event):
|
|
chat = await event.get_chat()
|
|
sender = await event.get_sender()
|
|
|
|
# Ignora bots (inclusive o @Hermes_M5 / @m5onBot)
|
|
if getattr(sender, "bot", False):
|
|
log.info(f"Ignorando mensagem de bot: {getattr(sender, 'username', 'sem username')}")
|
|
return
|
|
|
|
# Ignora mensagens enviadas por nós mesmos
|
|
if event.out:
|
|
return
|
|
|
|
# Texto da mensagem
|
|
if hasattr(event, "message") and event.message:
|
|
text = event.message.text or event.message.message or ""
|
|
if not text:
|
|
return
|
|
else:
|
|
text = str(event)[:100]
|
|
|
|
timestamp = datetime.now().strftime("%d/%m %H:%M")
|
|
chat_name = getattr(chat, "title", None) or getattr(chat, "first_name", "Desconhecido")
|
|
sender_name = f"{getattr(sender, 'first_name', '')} {getattr(sender, 'last_name', '')}".strip()
|
|
username = f"(@{sender.username})" if getattr(sender, "username", None) else ""
|
|
|
|
log.info("")
|
|
log.info(f"╔══════════════════════════════════════════════════════╗")
|
|
log.info(f"║ {timestamp} | {chat_name} ║")
|
|
log.info(f"║ De: {sender_name} {username} ║")
|
|
log.info(f"╠══════════════════════════════════════════════════════╣")
|
|
# Quebra texto em linhas de até 58 chars
|
|
for i in range(0, len(text), 58):
|
|
line = text[i : i + 58]
|
|
log.info(f"║ {line:<58} ║")
|
|
log.info(f"╚══════════════════════════════════════════════════════╝")
|
|
log.info("")
|
|
|
|
# SEM auto-resposta — só loga as mensagens
|
|
# (auto-resposta desativada em 21/jun/2026)
|
|
|
|
await client.run_until_disconnected()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
asyncio.run(main())
|
|
except KeyboardInterrupt:
|
|
log.info("Monitoramento interrompido.")
|