Initial commit
This commit is contained in:
commit
2570726524
|
@ -0,0 +1,2 @@
|
|||
docker-compose.override.yml
|
||||
__pycache__
|
|
@ -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
|
|
@ -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())
|
|
@ -0,0 +1,13 @@
|
|||
version: "3.2"
|
||||
|
||||
services:
|
||||
|
||||
server:
|
||||
build:
|
||||
context: .
|
||||
target: server
|
||||
ports:
|
||||
- 8000:8000
|
||||
environment:
|
||||
- TOKEN=yourtelegramtoken
|
||||
- CHAT_ID=yourchatid
|
|
@ -0,0 +1,4 @@
|
|||
flask[async]~=2.3.2
|
||||
uvicorn~=0.23.2
|
||||
asgiref~=3.7.2
|
||||
python-telegram-bot==20.8
|
Loading…
Reference in New Issue