diff options
-rw-r--r-- | bot.py | 8 | ||||
-rw-r--r-- | contrib/docker-compose.yaml | 11 | ||||
-rw-r--r-- | contrib/krakend.json | 90 |
3 files changed, 104 insertions, 5 deletions
@@ -8,7 +8,7 @@ from config import BOT_TOKEN, TELEGRAM_WEBHOOK_URL, HEALTHCHECK_URL, FEDI_LOGIN_ | |||
8 | import uvicorn | 8 | import uvicorn |
9 | from starlette.applications import Starlette | 9 | from starlette.applications import Starlette |
10 | from starlette.requests import Request | 10 | from starlette.requests import Request |
11 | from starlette.responses import PlainTextResponse, Response | 11 | from starlette.responses import PlainTextResponse, Response, JSONResponse |
12 | from starlette.routing import Route | 12 | from starlette.routing import Route |
13 | from telegram import Update | 13 | from telegram import Update |
14 | from telegram.ext import ( | 14 | from telegram.ext import ( |
@@ -188,12 +188,12 @@ async def main() -> None: | |||
188 | await application.bot.set_webhook(url=f"{BOT_DOMAIN}{TELEGRAM_WEBHOOK_URL}") | 188 | await application.bot.set_webhook(url=f"{BOT_DOMAIN}{TELEGRAM_WEBHOOK_URL}") |
189 | 189 | ||
190 | # Set up webserver | 190 | # Set up webserver |
191 | async def telegram_webhook(request: Request) -> Response: | 191 | async def telegram_webhook(request: Request) -> JSONResponse: |
192 | """Handle incoming Telegram updates by putting them into the `update_queue`""" | 192 | """Handle incoming Telegram updates by putting them into the `update_queue`""" |
193 | await application.update_queue.put( | 193 | await application.update_queue.put( |
194 | Update.de_json(data=await request.json(), bot=application.bot) | 194 | Update.de_json(data=await request.json(), bot=application.bot) |
195 | ) | 195 | ) |
196 | return Response() | 196 | return JSONResponse({'OK': 200}) |
197 | 197 | ||
198 | async def fedi_oauth_login_callback(request: Request) -> PlainTextResponse: | 198 | async def fedi_oauth_login_callback(request: Request) -> PlainTextResponse: |
199 | """ | 199 | """ |
@@ -221,7 +221,7 @@ async def main() -> None: | |||
221 | routes=[ | 221 | routes=[ |
222 | Route(TELEGRAM_WEBHOOK_URL, telegram_webhook, methods=["POST"]), | 222 | Route(TELEGRAM_WEBHOOK_URL, telegram_webhook, methods=["POST"]), |
223 | Route(HEALTHCHECK_URL, healthcheck, methods=["GET"]), | 223 | Route(HEALTHCHECK_URL, healthcheck, methods=["GET"]), |
224 | Route(FEDI_LOGIN_CALLBACK_URL, fedi_oauth_login_callback, methods=["POST", "GET"]), | 224 | Route(FEDI_LOGIN_CALLBACK_URL, fedi_oauth_login_callback, methods=["GET"]), |
225 | ] | 225 | ] |
226 | ) | 226 | ) |
227 | webserver = uvicorn.Server( | 227 | webserver = uvicorn.Server( |
diff --git a/contrib/docker-compose.yaml b/contrib/docker-compose.yaml index 7ba8c2d..3ca7981 100644 --- a/contrib/docker-compose.yaml +++ b/contrib/docker-compose.yaml | |||
@@ -1,6 +1,6 @@ | |||
1 | version: '3' | 1 | version: '3' |
2 | services: | 2 | services: |
3 | checkin.bot: | 3 | checkinbot: |
4 | image: "clarkzjw/checkin.bot:latest" | 4 | image: "clarkzjw/checkin.bot:latest" |
5 | restart: always | 5 | restart: always |
6 | volumes: | 6 | volumes: |
@@ -9,5 +9,14 @@ services: | |||
9 | ports: | 9 | ports: |
10 | - "8080:8080" | 10 | - "8080:8080" |
11 | 11 | ||
12 | krakend: | ||
13 | image: "devopsfaith/krakend:latest" | ||
14 | restart: always | ||
15 | ports: | ||
16 | - "8081:8080" | ||
17 | - "9091:9091" | ||
18 | volumes: | ||
19 | - "./krakend.json:/etc/krakend/krakend.json" | ||
20 | |||
12 | volumes: | 21 | volumes: |
13 | sqlite3: | 22 | sqlite3: |
diff --git a/contrib/krakend.json b/contrib/krakend.json new file mode 100644 index 0000000..1f89340 --- /dev/null +++ b/contrib/krakend.json | |||
@@ -0,0 +1,90 @@ | |||
1 | { | ||
2 | "$schema": "https://www.krakend.io/schema/v3.json", | ||
3 | "version": 3, | ||
4 | "name": "Checkin.bot API", | ||
5 | "extra_config": { | ||
6 | "telemetry/opencensus": { | ||
7 | "sample_rate": 100, | ||
8 | "reporting_period": 0, | ||
9 | "exporters": { | ||
10 | "prometheus": { | ||
11 | "port": 9091, | ||
12 | "namespace": "krakend", | ||
13 | "tag_host": false, | ||
14 | "tag_path": true, | ||
15 | "tag_method": true, | ||
16 | "tag_statuscode": false | ||
17 | } | ||
18 | } | ||
19 | }, | ||
20 | "telemetry/metrics": { | ||
21 | "collection_time": "60s", | ||
22 | "proxy_disabled": false, | ||
23 | "router_disabled": false, | ||
24 | "backend_disabled": false, | ||
25 | "endpoint_disabled": false, | ||
26 | "listen_address": ":8090" | ||
27 | } | ||
28 | }, | ||
29 | "timeout": "3000ms", | ||
30 | "cache_ttl": "300s", | ||
31 | "output_encoding": "json", | ||
32 | "debug_endpoint": true, | ||
33 | "endpoints": [ | ||
34 | { | ||
35 | "endpoint": "/checkinbot/webhook", | ||
36 | "method": "POST", | ||
37 | "output_encoding": "json", | ||
38 | "backend": [ | ||
39 | { | ||
40 | "url_pattern": "/checkinbot/webhook", | ||
41 | "encoding": "json", | ||
42 | "sd": "static", | ||
43 | "method": "POST", | ||
44 | "host": [ | ||
45 | "http://checkinbot:8080" | ||
46 | ], | ||
47 | "disable_host_sanitize": false | ||
48 | } | ||
49 | ] | ||
50 | }, | ||
51 | { | ||
52 | "endpoint": "/checkinbot/healthcheck", | ||
53 | "method": "GET", | ||
54 | "output_encoding": "string", | ||
55 | "backend": [ | ||
56 | { | ||
57 | "url_pattern": "/checkinbot/healthcheck", | ||
58 | "encoding": "string", | ||
59 | "sd": "static", | ||
60 | "method": "GET", | ||
61 | "host": [ | ||
62 | "http://checkinbot:8080" | ||
63 | ], | ||
64 | "disable_host_sanitize": false | ||
65 | } | ||
66 | ] | ||
67 | }, | ||
68 | { | ||
69 | "endpoint": "/checkinbot/fedi_login_callback", | ||
70 | "method": "GET", | ||
71 | "output_encoding": "string", | ||
72 | "backend": [ | ||
73 | { | ||
74 | "url_pattern": "/checkinbot/fedi_login_callback", | ||
75 | "encoding": "string", | ||
76 | "sd": "static", | ||
77 | "method": "GET", | ||
78 | "disable_host_sanitize": false, | ||
79 | "host": [ | ||
80 | "http://checkinbot:8080" | ||
81 | ] | ||
82 | } | ||
83 | ], | ||
84 | "input_query_strings": [ | ||
85 | "code", | ||
86 | "state" | ||
87 | ] | ||
88 | } | ||
89 | ] | ||
90 | } \ No newline at end of file | ||