import gradio as gr import requests from dotenv import load_dotenv from telegram import Bot # Load environment variables load_dotenv() TELEGRAM_BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN") bot = Bot(token=TELEGRAM_BOT_TOKEN) def send_message_to_user(chat_id, message): """Send a test message to a user via the bot.""" try: bot.send_message(chat_id=chat_id, text=message) return f"Message sent to chat ID {chat_id}" except Exception as e: return f"Failed to send message: {str(e)}" def check_bot_status(): """Check if the bot is online.""" try: response = bot.get_me() return f"Bot is online: {response.username}" except Exception as e: return f"Bot is offline: {str(e)}" # Define the Gradio interface with gr.Blocks() as dashboard: gr.Markdown("# Telegram Bot Admin Dashboard") # Bot status check with gr.Row(): bot_status_button = gr.Button("Check Bot Status") bot_status_output = gr.Textbox(label="Bot Status") bot_status_button.click(check_bot_status, inputs=None, outputs=bot_status_output) # Send a message with gr.Row(): chat_id_input = gr.Textbox(label="Chat ID") message_input = gr.Textbox(label="Message to Send") send_message_button = gr.Button("Send Message") send_message_output = gr.Textbox(label="Send Message Output") send_message_button.click(send_message_to_user, inputs=[chat_id_input, message_input], outputs=send_message_output) # Launch the dashboard dashboard.launch()