palomabot / app.py
Atualli's picture
Update app.py
509a8e2 verified
import os
import threading
import telebot
import gradio as gr
# --- DIAGNÓSTICO ---
TOKEN = os.environ.get("TELEGRAM_TOKEN")
print(f"STATUS DO TOKEN: {'Encontrado' if TOKEN else 'NÃO ENCONTRADO'}")
# --- BOT TELEGRAM SIMPLES ---
if TOKEN:
bot = telebot.TeleBot(TOKEN)
@bot.message_handler(func=lambda m: True)
def echo(message):
bot.reply_to(message, "Teste OK! O servidor está rodando.")
def runner():
print("Tentando iniciar o polling do Telegram...")
try:
bot.remove_webhook() # Garante que não tenha conflito
bot.infinity_polling()
except Exception as e:
print(f"ERRO CRÍTICO NO TELEGRAM: {e}")
# Inicia em background
threading.Thread(target=runner, daemon=True).start()
else:
print("ERRO: Configure o Secret TELEGRAM_TOKEN nas Settings.")
# --- SITE GRADIO (Só para manter o space vivo) ---
def greet(name):
return "Olá " + name
if __name__ == "__main__":
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch()