update task data

This commit is contained in:
Kseninia Mikhaylova 2024-08-20 11:00:49 +03:00
parent ea117e35b8
commit 271febf62d
2 changed files with 44 additions and 18 deletions

View File

@ -53,27 +53,36 @@ async def tg_intgr_get(request: Request):
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 = f"\nhttps://crm.svs-tech.pro/company/personal/user/{bx_id}/tasks/task/view/{task_id}/ \n"
comment_data = data_json["result"]["POST_MESSAGE"]
comment_data = requests.get(get_comment_hook)
comment_data_json = comment_data.json()
mentions = re.findall(
rf"\[USER=({bx_id})\]", comment_data_json["result"]["POST_MESSAGE"]
)
if len(mentions) > 0:
logger.info(f"sending tg mention to {bx_id}")
get_task_hook = (
f"{WEBHOOK}/tasks.task.get.json?taskId={task_id}&select[0]=TITLE"
)
task_data = requests.get(get_task_hook)
task_data_json = task_data.json()
comment_data = comment_data_json["result"]["POST_MESSAGE"]
comment_data = re.sub('"', "", comment_data)
comment_data = re.sub(
r"((\[)(.*?)(]))|\"",
"",
comment_data,
)
comment += " ".join(comment_data.split(" ")[:100])
comment += f'\nот {data_json["result"]["AUTHOR_NAME"]}'
comment = (
f"Упоминание в задаче от {comment_data_json["result"]["AUTHOR_NAME"]}\n"
f"Задача: {task_data_json['result']['task']['id']} {task_data_json['result']['task']['title']}"
"https://crm.svs-tech.pro/company/personal/user/{bx_id}/tasks/task/view/{task_id}/ \n"
" ".join(comment_data.split(" ")[:100])
)
mentions = re.findall(
rf"\[USER=({bx_id})\]", data_json["result"]["POST_MESSAGE"]
)
for _ in mentions:
logger.info(
"https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={tg_id}&text={comment}"
)
requests.get(
f"https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={tg_id}&text={comment}"
)

17
app/test.py Normal file
View File

@ -0,0 +1,17 @@
import re
comment_data = "Еще один \"тестовый комментарий\" [USER=28]Игорь Жабченко[/USER] добавила вывод того, сколько тмц проинвентаризировано по областям [URL=https://toinv.svs-tech.pro/stat]https://toinv.svs-tech.pro/stat[/URL]\nЧто еще надо добавить для работы с сервисом?"
bx_id = 28
mentions = re.findall(rf"\[USER=({bx_id})\]", comment_data)
print(len(mentions)>0)
comment = ''
comment_data = re.sub('"', "", comment_data)
comment_data = re.sub(
r"((\[)(.*?)(]))|\"",
"",
comment_data,
)
comment += " ".join(comment_data.split(" ")[:100])
print(comment)