import os from telegram.ext import Application, CommandHandler from threading import Thread import schedule import time # Função de exemplo para o comando /start async def start(update, context): await update.message.reply_text('Hello! I am Hypercycle Bot.') # Função para tarefas agendadas def scheduled_task(): print("Running scheduled task...") # Substitua por sua lógica # Função principal do bot def main(): # Obtém o token do Telegram das variáveis de ambiente TELEGRAM_TOKEN = os.environ.get('TELEGRAM_TOKEN') if not TELEGRAM_TOKEN: raise ValueError("TELEGRAM_TOKEN not set in environment variables") # Configura o bot application = Application.builder().token(TELEGRAM_TOKEN).build() # Adiciona handlers de comandos application.add_handler(CommandHandler("start", start)) # Inicia o bot print("Bot is starting...") application.run_polling() # Função para rodar o agendador em uma thread separada def run_scheduler(): schedule.every(10).seconds.do(scheduled_task) # Exemplo: tarefa a cada 10s while True: schedule.run_pending() time.sleep(1) if __name__ == '__main__': # Inicia o agendador em uma thread Thread(target=run_scheduler).start() # Inicia o bot main()