path parametres
This commit is contained in:
parent
8b9d66f9be
commit
8e02e7e37e
|
@ -10,4 +10,5 @@ logging.basicConfig(
|
||||||
logging.getLogger("httpx").setLevel(logging.WARNING)
|
logging.getLogger("httpx").setLevel(logging.WARNING)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
WEBHOOK = os.getenv('WEBHOOK')
|
WEBHOOK = os.getenv("WEBHOOK")
|
||||||
|
TOKEN = os.getenv("TOKEN")
|
||||||
|
|
20
app/main.py
20
app/main.py
|
@ -8,7 +8,7 @@ from app.constants import *
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
tg = {38: 198225670}
|
tg = {38: 198225670}
|
||||||
TOKEN = "7102273461:AAGi8RXCEvns2ONu3RcG9Up973vcLzTdCJg"
|
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
def read_root():
|
def read_root():
|
||||||
|
@ -40,24 +40,30 @@ async def intgr(request: Request):
|
||||||
return {"status": "success"}
|
return {"status": "success"}
|
||||||
|
|
||||||
|
|
||||||
@app.post("/integration_tg")
|
@app.post("/integration_tg/{bx_id}/{tg_id}")
|
||||||
async def tg_intgr_get(request: Request):
|
async def tg_intgr_get(request: Request):
|
||||||
try:
|
try:
|
||||||
body = await request.body()
|
body = await request.body()
|
||||||
query = parse_qs(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()
|
task_id = query[b"data[FIELDS_AFTER][TASK_ID]"][0].decode()
|
||||||
item_id = query[b"data[FIELDS_AFTER][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 = requests.get(get_comment_hook)
|
||||||
data_json = data.json()
|
data_json = data.json()
|
||||||
comment = data_json["result"]["POST_MESSAGE"]
|
comment = data_json["result"]["POST_MESSAGE"]
|
||||||
|
|
||||||
mentions = re.findall(r"\[USER=(\d*)\]", comment)
|
mentions = re.findall(rf"\[USER=({bx_id})\]", comment)
|
||||||
for mention in mentions:
|
for _ in mentions:
|
||||||
if tg[int(mention)]:
|
requests.get(
|
||||||
requests.get(f'https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={tg[int(mention)]}&text={comment}')
|
f"https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={tg_id}&text={comment}"
|
||||||
|
)
|
||||||
|
|
||||||
return {"status": "success"}
|
return {"status": "success"}
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -4,6 +4,7 @@ services:
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
environment:
|
environment:
|
||||||
- WEBHOOK='https://crm.svs-tech.pro/rest/1/liljl5r1k6dtxt0s/'
|
- WEBHOOK='https://crm.svs-tech.pro/rest/1/liljl5r1k6dtxt0s/'
|
||||||
|
- TOKEN='7102273461:AAGi8RXCEvns2ONu3RcG9Up973vcLzTdCJg'
|
||||||
ports:
|
ports:
|
||||||
- 8099:80
|
- 8099:80
|
||||||
networks:
|
networks:
|
||||||
|
|
Loading…
Reference in New Issue