commit 2570726524da408968197b71046c05c958d2596c Author: Thomas Forgione Date: Fri Feb 23 14:21:48 2024 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b36cc2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +docker-compose.override.yml +__pycache__ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..71329f3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.11 AS server + +WORKDIR /app + +COPY ./requirements.txt /app + +RUN pip install -r requirements.txt + +COPY ./app.py /app + +CMD python app.py diff --git a/app.py b/app.py new file mode 100644 index 0000000..5774292 --- /dev/null +++ b/app.py @@ -0,0 +1,38 @@ +import os +import asyncio +import telegram +from flask import Flask, request +import uvicorn +from asgiref.wsgi import WsgiToAsgi + +async def main(): + app = Flask(__name__) + + chat = os.environ["CHAT_ID"] + bot = telegram.Bot(os.environ["TOKEN"]) + async with bot: + + @app.route("/") + def hello_world(): + return "

Hello, World!

" + + @app.route("/push", methods = ["POST"]) + async def push(): + title = request.form.get('title', 'No title') + body = request.form.get('body', 'No body') + await bot.send_message(chat, text = '' + title + '\n\n' + body, parse_mode = 'html') + return 'ok' + + webserver = uvicorn.Server( + config=uvicorn.Config( + app=WsgiToAsgi(app), + port=os.environ.get("PORT", 8000), + use_colors=False, + host="0.0.0.0", + ) + ) + + await webserver.serve() + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4118728 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +version: "3.2" + +services: + + server: + build: + context: . + target: server + ports: + - 8000:8000 + environment: + - TOKEN=yourtelegramtoken + - CHAT_ID=yourchatid diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..270b8e4 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +flask[async]~=2.3.2 +uvicorn~=0.23.2 +asgiref~=3.7.2 +python-telegram-bot==20.8