File size: 1,224 Bytes
a10ad30
ac0f7a4
a10ad30
ac0f7a4
 
a10ad30
ac0f7a4
 
 
 
a10ad30
ac0f7a4
 
a10ad30
ac0f7a4
 
 
a10ad30
ac0f7a4
 
 
a10ad30
ac0f7a4
 
 
 
 
 
a10ad30
ac0f7a4
 
a10ad30
ac0f7a4
a10ad30
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import gradio as gr
from telegram.ext import Updater, MessageHandler, Filters, CommandHandler, CallbackContext

# Define your Telegram bot token here
TELEGRAM_BOT_TOKEN = "6516533220:AAEoq0ohv4xAraIw7lB7BZVHKyUg85wo3mI"

# Create a Gradio interface
def greet(bot, update):
    message = update.message.text
    bot.send_message(chat_id=update.message.chat_id, text=f"Hello, you said: {message}")

# Create a Gradio interface
gr.Interface(fn=greet, inputs="text", outputs="text").launch(share=True)

# Set up the Telegram bot
updater = Updater(token=TELEGRAM_BOT_TOKEN, use_context=True)
dispatcher = updater.dispatcher

# Define a Telegram command handler
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)

# Define a Telegram message 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)

# Start the Telegram bot
updater.start_polling()
updater.idle()