From 73e4f60b50ee2f832deef84ae18a7f11b00f4195 Mon Sep 17 00:00:00 2001 From: Senya Date: Thu, 25 Apr 2024 17:19:38 +0300 Subject: [PATCH 1/4] todobot --- .gitignore | 1 + run_todobot.py | 4 ++++ todobot/__init__.py | 0 todobot/bot.py | 53 +++++++++++++++++++++++++++++++++++++++++++++ todobot/config.py | 1 + 5 files changed, 59 insertions(+) create mode 100644 run_todobot.py create mode 100644 todobot/__init__.py create mode 100644 todobot/bot.py create mode 100644 todobot/config.py diff --git a/.gitignore b/.gitignore index ab12272..665f880 100644 --- a/.gitignore +++ b/.gitignore @@ -356,3 +356,4 @@ dmypy.json # Cython debug symbols cython_debug/ +todobot/config diff --git a/run_todobot.py b/run_todobot.py new file mode 100644 index 0000000..75fa8ab --- /dev/null +++ b/run_todobot.py @@ -0,0 +1,4 @@ +from todobot.bot import main + +if __name__ == '__main__': + main() diff --git a/todobot/__init__.py b/todobot/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/todobot/bot.py b/todobot/bot.py new file mode 100644 index 0000000..6562c70 --- /dev/null +++ b/todobot/bot.py @@ -0,0 +1,53 @@ +import logging + +from telegram import ForceReply, Update +from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler, filters + +from todobot.config import TELEGRAM_TOKEN + +# Enable logging +logging.basicConfig( + format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO +) +# set higher logging level for httpx to avoid all GET and POST requests being logged +logging.getLogger("httpx").setLevel(logging.WARNING) + +logger = logging.getLogger(__name__) + + +# Define a few command handlers. These usually take the two arguments update and +# context. +async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: + """Send a message when the command /start is issued.""" + user = update.effective_user + await update.message.reply_text('Hello, my dear friends!') + + +async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: + """Send a message when the command /help is issued.""" + await update.message.reply_text("Help!") + + +async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: + """Echo the user message.""" + await update.message.reply_text(update.message.text) + + +def main() -> None: + """Start the bot.""" + # Create the Application and pass it your bot's token. + application = Application.builder().token("TELEGRAM_TOKEN").build() + + # on different commands - answer in Telegram + application.add_handler(CommandHandler("start", start)) + application.add_handler(CommandHandler("help", help_command)) + + # on non command i.e message - echo the message on Telegram + application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo)) + + # Run the bot until the user presses Ctrl-C + application.run_polling(allowed_updates=Update.ALL_TYPES) + + +if __name__ == "__main__": + main() diff --git a/todobot/config.py b/todobot/config.py new file mode 100644 index 0000000..23af294 --- /dev/null +++ b/todobot/config.py @@ -0,0 +1 @@ +TELEGRAM_TOKEN = '6613961171:AAGq3rz4aLjakC6CNZxHrsG-JOxK0izKaXY' From 60bde29266df298687fc12a6f3f5d8a5d9bf68a5 Mon Sep 17 00:00:00 2001 From: Senya Date: Thu, 25 Apr 2024 17:21:09 +0300 Subject: [PATCH 2/4] todobot --- .idea/.gitignore | 3 +++ .idea/inspectionProfiles/profiles_settings.xml | 6 ++++++ .idea/misc.xml | 7 +++++++ .idea/modules.xml | 8 ++++++++ .idea/telegram-bot-tutorial.iml | 12 ++++++++++++ .idea/vcs.xml | 6 ++++++ 6 files changed, 42 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/telegram-bot-tutorial.iml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6bab3e4 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f7fb9db --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/telegram-bot-tutorial.iml b/.idea/telegram-bot-tutorial.iml new file mode 100644 index 0000000..07abf20 --- /dev/null +++ b/.idea/telegram-bot-tutorial.iml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file From eebab19b27d564e89e00d3bdd53af5fa57e656c9 Mon Sep 17 00:00:00 2001 From: Senya Date: Thu, 25 Apr 2024 17:27:28 +0300 Subject: [PATCH 3/4] todobot --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 665f880..b845209 100644 --- a/.gitignore +++ b/.gitignore @@ -356,4 +356,4 @@ dmypy.json # Cython debug symbols cython_debug/ -todobot/config +todobot/config.py From 8744d91b5571cf67f37cbbd97023d64a46be0a23 Mon Sep 17 00:00:00 2001 From: Senya <125271697+lomticksu@users.noreply.github.com> Date: Thu, 25 Apr 2024 17:30:43 +0300 Subject: [PATCH 4/4] Update config.py --- todobot/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/todobot/config.py b/todobot/config.py index 23af294..12b4068 100644 --- a/todobot/config.py +++ b/todobot/config.py @@ -1 +1 @@ -TELEGRAM_TOKEN = '6613961171:AAGq3rz4aLjakC6CNZxHrsG-JOxK0izKaXY' +TELEGRAM_TOKEN = ''