From 71fab4f998aae23ff538c3544317d26fecc8ee6c Mon Sep 17 00:00:00 2001 From: PavanTeja2005 <98730339+PavanTeja2005@users.noreply.github.com> Date: Wed, 9 Oct 2024 16:56:52 +0000 Subject: [PATCH 1/2] telegrambot --- sample.py | 4 ++++ telegram_bot.py | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 sample.py create mode 100644 telegram_bot.py diff --git a/sample.py b/sample.py new file mode 100644 index 0000000..c8828c9 --- /dev/null +++ b/sample.py @@ -0,0 +1,4 @@ +from telegram_bot import * +from threading import Thread +t = Thread(target = main) +t.start() diff --git a/telegram_bot.py b/telegram_bot.py new file mode 100644 index 0000000..6e45394 --- /dev/null +++ b/telegram_bot.py @@ -0,0 +1,21 @@ +from telegram import Update +from telegram.ext import ApplicationBuilder, CommandHandler, MessageHandler, filters, CallbackContext + +async def start(update: Update, context: CallbackContext) -> None: + """Send a welcome message when the /start command is issued.""" + await update.message.reply_text('Hello! I am your bot. Send me any message and I will echo it back!') + +async def echo(update: Update, context: CallbackContext) -> None: + """Echo the received message.""" + await update.message.reply_text(update.message.text) + +def main() -> None: + app = ApplicationBuilder().token("YOUR_API").build() + + app.add_handler(CommandHandler("start", start)) + app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo)) + + app.run_polling() + +if __name__ == '__main__': + main() From 2c1dbb78c31be3ec72242174cf86535707de43b7 Mon Sep 17 00:00:00 2001 From: PavanTeja2005 <98730339+PavanTeja2005@users.noreply.github.com> Date: Wed, 9 Oct 2024 17:01:31 +0000 Subject: [PATCH 2/2] final --- sample.py | 4 ---- telegram_bot.py | 26 ++++++++++++++------------ 2 files changed, 14 insertions(+), 16 deletions(-) delete mode 100644 sample.py diff --git a/sample.py b/sample.py deleted file mode 100644 index c8828c9..0000000 --- a/sample.py +++ /dev/null @@ -1,4 +0,0 @@ -from telegram_bot import * -from threading import Thread -t = Thread(target = main) -t.start() diff --git a/telegram_bot.py b/telegram_bot.py index 6e45394..2656801 100644 --- a/telegram_bot.py +++ b/telegram_bot.py @@ -1,21 +1,23 @@ from telegram import Update from telegram.ext import ApplicationBuilder, CommandHandler, MessageHandler, filters, CallbackContext -async def start(update: Update, context: CallbackContext) -> None: - """Send a welcome message when the /start command is issued.""" - await update.message.reply_text('Hello! I am your bot. Send me any message and I will echo it back!') +def telebot(): + async def start(update: Update, context: CallbackContext) -> None: + """Send a welcome message when the /start command is issued.""" + await update.message.reply_text('Hello! I am your bot. Send me any message and I will echo it back!') -async def echo(update: Update, context: CallbackContext) -> None: - """Echo the received message.""" - await update.message.reply_text(update.message.text) + async def echo(update: Update, context: CallbackContext) -> None: + """Echo the received message.""" + await update.message.reply_text(update.message.text) -def main() -> None: - app = ApplicationBuilder().token("YOUR_API").build() + def main() -> None: + app = ApplicationBuilder().token("7854626087:AAF5ls0oB8XR3SvQhWkxmea42e7FSf0yKTE").build() - app.add_handler(CommandHandler("start", start)) - app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo)) + app.add_handler(CommandHandler("start", start)) + app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo)) - app.run_polling() + app.run_polling() + main() if __name__ == '__main__': - main() + telebot()