diff --git a/PythonCode/bot.update.py b/PythonCode/bot.update.py deleted file mode 100644 index bfbac14..0000000 --- a/PythonCode/bot.update.py +++ /dev/null @@ -1,28 +0,0 @@ -#Подключение к боту -from telegram.ext import Updater -updater = Updater(token='1903048555:AAFK-d7prKvOvwwXo0IPzeRwJ1ZcuOT5ty8', use_context=True) - -dispatcher = updater.dispatcher - -import logging -logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', - level=logging.INFO) - -#Стартовое сообщение (к команде /start) -def start(update, context): - context.bot.send_message(chat_id=update.effective_chat.id, text="Hello World! Это не просто копипаста, я вот что-то подправил даже") - -from telegram.ext import CommandHandler -start_handler = CommandHandler('start', start) -dispatcher.add_handler(start_handler) - -#Ответ на не командное сообщение (отвечает тем же сообщением) -def echo(update, context): - context.bot.send_message(chat_id=update.effective_chat.id, text=update.message.text) - -from telegram.ext import MessageHandler, Filters -echo_handler = MessageHandler(Filters.text & (~Filters.command), echo) -dispatcher.add_handler(echo_handler) - -#Начало работы бота -updater.start_polling() \ No newline at end of file diff --git a/TelegramBot/Dockerfile b/TelegramBot/Dockerfile new file mode 100644 index 0000000..f5e5e93 --- /dev/null +++ b/TelegramBot/Dockerfile @@ -0,0 +1,23 @@ +# For more information, please refer to https://aka.ms/vscode-docker-python +FROM python:3.8-slim-buster + +# Keeps Python from generating .pyc files in the container +ENV PYTHONDONTWRITEBYTECODE=1 + +# Turns off buffering for easier container logging +ENV PYTHONUNBUFFERED=1 + +# Install pip requirements +COPY requirements.txt . +RUN python -m pip install -r requirements.txt + +WORKDIR /app +COPY . /app + +# Creates a non-root user with an explicit UID and adds permission to access the /app folder +# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers +RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app +USER appuser + +# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug +CMD ["python", "bot.py"] diff --git a/TelegramBot/bot.py b/TelegramBot/bot.py new file mode 100644 index 0000000..9044c94 --- /dev/null +++ b/TelegramBot/bot.py @@ -0,0 +1,47 @@ +import logging +import os +import platform +import time + +from telegram.ext import Updater +from telegram.ext import CommandHandler +from telegram.ext import MessageHandler, Filters + +TOKEN = "1903048555:AAFK-d7prKvOvwwXo0IPzeRwJ1ZcuOT5ty8" # os.environ["TOKEN"] + +logging.basicConfig( + format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO +) + +updater = Updater(token=TOKEN, use_context=True) +dispatcher = updater.dispatcher + +# ================================================================ BOT COMMANDS + +# Стартовое сообщение (к команде /start) +def start(update, context): + + context.bot.send_message( + chat_id=update.effective_chat.id, + text=f"Hello World! It's {time.time()}\n" \ + f"{platform.platform()}\n\n" + ) + +# Ответ на не командное сообщение (отвечает тем же сообщением) +def echo(update, context): + context.bot.send_message( + chat_id=update.effective_chat.id, + text=update.message.text + ) + + +# ==================================================================== HANDLERS + +start_handler = CommandHandler("start", start) +echo_handler = MessageHandler(Filters.text & (~Filters.command), echo) + +dispatcher.add_handler(start_handler) +dispatcher.add_handler(echo_handler) + +# Начало работы бота +updater.start_polling() diff --git a/TelegramBot/requirements.txt b/TelegramBot/requirements.txt new file mode 100644 index 0000000..5b5d3aa --- /dev/null +++ b/TelegramBot/requirements.txt @@ -0,0 +1 @@ +python-telegram-bot==13.7 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 8cfddd6..4b234a2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,4 +9,11 @@ services: environment: SECRETKEY: "HELLO-WORLD-@21XX 15AF" volumes: - - ./SpreadsheetsService:/app:Z \ No newline at end of file + - ./SpreadsheetsService:/app + telegrambot: + container_name: "carolyn-telegrambot" + build: ./TelegramBot + environment: + TOKEN: "1903048555:AAFK-d7prKvOvwwXo0IPzeRwJ1ZcuOT5ty8" + volumes: + - ./TelegramBot:/app \ No newline at end of file