Initial commit

This commit is contained in:
Thomas Forgione 2024-02-23 14:21:48 +01:00
commit 2570726524
5 changed files with 68 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
docker-compose.override.yml
__pycache__

11
Dockerfile Normal file
View File

@ -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

38
app.py Normal file
View File

@ -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 "<p>Hello, World!</p>"
@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 = '<b>' + title + '</b>\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())

13
docker-compose.yml Normal file
View File

@ -0,0 +1,13 @@
version: "3.2"
services:
server:
build:
context: .
target: server
ports:
- 8000:8000
environment:
- TOKEN=yourtelegramtoken
- CHAT_ID=yourchatid

4
requirements.txt Normal file
View File

@ -0,0 +1,4 @@
flask[async]~=2.3.2
uvicorn~=0.23.2
asgiref~=3.7.2
python-telegram-bot==20.8