|
import gradio as gr |
|
from telegram.ext import Updater, MessageHandler, Filters, CommandHandler, CallbackContext |
|
|
|
|
|
TELEGRAM_BOT_TOKEN = "6516533220:AAEoq0ohv4xAraIw7lB7BZVHKyUg85wo3mI" |
|
|
|
|
|
def greet(bot, update): |
|
message = update.message.text |
|
bot.send_message(chat_id=update.message.chat_id, text=f"Hello, you said: {message}") |
|
|
|
|
|
gr.Interface(fn=greet, inputs="text", outputs="text").launch(share=True) |
|
|
|
|
|
updater = Updater(token=TELEGRAM_BOT_TOKEN, use_context=True) |
|
dispatcher = updater.dispatcher |
|
|
|
|
|
def start(update, context): |
|
context.bot.send_message(chat_id=update.message.chat_id, text="Hello! I'm your Gradio Telegram Bot. Send me a message!") |
|
|
|
start_handler = CommandHandler('start', start) |
|
dispatcher.add_handler(start_handler) |
|
|
|
|
|
def echo(update, context): |
|
context.bot.send_message(chat_id=update.message.chat_id, text=update.message.text) |
|
|
|
message_handler = MessageHandler(Filters.text & ~Filters.command, echo) |
|
dispatcher.add_handler(message_handler) |
|
|
|
|
|
updater.start_polling() |
|
updater.idle() |
|
|