This repository has been archived by the owner on Sep 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
52 lines (44 loc) · 1.56 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from command.command import Command
from command.donate import DonateCommand
from command.help import HelpCommand
from command.subscribe import SubscribeCommand
from command.unsubscribe import UnsubscribeCommand
from command.unknown import UnknownCommand
from command.personal_update import PersonalUpdateCommand
from database import User
from fastapi import FastAPI
from typing import Dict
from price import get_price_updates_for_users
app: FastAPI = FastAPI()
@app.get("/healthcheck")
def root_get() -> str:
print("Test log for Hello world")
return "Hello world!"
@app.post("/")
def receive_webhook(payload: dict):
chat_id: int = int(payload["message"]["chat"]["id"])
first_name: str = payload["message"]["chat"]["first_name"]
last_name: str = payload["message"]["chat"]["last_name"]
command_map: Dict[str, Command] = {
"/subscribe": SubscribeCommand(
chat_id,
name=f'{first_name} {last_name}'
),
"/unsubscribe": UnsubscribeCommand(chat_id),
"/update": PersonalUpdateCommand(chat_id),
"/start": HelpCommand(chat_id),
"/help": HelpCommand(chat_id),
"/donate": DonateCommand(chat_id)
}
command_str: str = payload["message"]["text"]
if command_str not in command_map:
UnknownCommand(chat_id).execute()
return
command: Command = command_map[command_str]
command.execute()
return "Done"
@app.post("/prices")
def get_price_update():
chat_ids = [int(u.id) for u in User.select(User.id)]
get_price_updates_for_users(chat_ids)
return "Done"