diff --git a/app/constants.py b/app/constants.py index 73d4e8b..9ca7be5 100644 --- a/app/constants.py +++ b/app/constants.py @@ -10,4 +10,5 @@ logging.basicConfig( logging.getLogger("httpx").setLevel(logging.WARNING) logger = logging.getLogger(__name__) -WEBHOOK = os.getenv('WEBHOOK') \ No newline at end of file +WEBHOOK = os.getenv("WEBHOOK") +TOKEN = os.getenv("TOKEN") diff --git a/app/main.py b/app/main.py index 49b64f0..223f8d9 100644 --- a/app/main.py +++ b/app/main.py @@ -8,7 +8,7 @@ from app.constants import * app = FastAPI() tg = {38: 198225670} -TOKEN = "7102273461:AAGi8RXCEvns2ONu3RcG9Up973vcLzTdCJg" + @app.get("/") def read_root(): @@ -40,24 +40,30 @@ async def intgr(request: Request): return {"status": "success"} -@app.post("/integration_tg") +@app.post("/integration_tg/{bx_id}/{tg_id}") async def tg_intgr_get(request: Request): try: body = await request.body() query = parse_qs(body) + bx_id = request.path_params["bx_id"] + tg_id = request.path_params["tg_id"] + task_id = query[b"data[FIELDS_AFTER][TASK_ID]"][0].decode() item_id = query[b"data[FIELDS_AFTER][ID]"][0].decode() - get_comment_hook = f"https://crm.svs-tech.pro/rest/38/7ufrqnfpncmt279p/task.commentitem.get.json?taskId={task_id}&ITEMID={item_id}" + get_comment_hook = ( + f"{WEBHOOK}/task.commentitem.get.json?taskId={task_id}&ITEMID={item_id}" + ) data = requests.get(get_comment_hook) data_json = data.json() comment = data_json["result"]["POST_MESSAGE"] - mentions = re.findall(r"\[USER=(\d*)\]", comment) - for mention in mentions: - if tg[int(mention)]: - requests.get(f'https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={tg[int(mention)]}&text={comment}') + mentions = re.findall(rf"\[USER=({bx_id})\]", comment) + for _ in mentions: + requests.get( + f"https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={tg_id}&text={comment}" + ) return {"status": "success"} except: diff --git a/compose.yml b/compose.yml index 9ca6d6f..c3a035b 100644 --- a/compose.yml +++ b/compose.yml @@ -4,6 +4,7 @@ services: dockerfile: Dockerfile environment: - WEBHOOK='https://crm.svs-tech.pro/rest/1/liljl5r1k6dtxt0s/' + - TOKEN='7102273461:AAGi8RXCEvns2ONu3RcG9Up973vcLzTdCJg' ports: - 8099:80 networks: