Merge branch 'bx-447-tg' of https://git.svs-tech.pro/ksenia_mikhailova/bx-gitea-integration into bx-447-tg
This commit is contained in:
commit
7c49d5091d
|
@ -10,4 +10,5 @@ logging.basicConfig(
|
|||
logging.getLogger("httpx").setLevel(logging.WARNING)
|
||||
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()
|
||||
|
||||
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:
|
||||
|
|
|
@ -3,7 +3,12 @@ services:
|
|||
build:
|
||||
dockerfile: Dockerfile
|
||||
environment:
|
||||
<<<<<<< HEAD
|
||||
- WEBHOOK=https://crm.svs-tech.pro/rest/1/liljl5r1k6dtxt0s/
|
||||
=======
|
||||
- WEBHOOK='https://crm.svs-tech.pro/rest/1/liljl5r1k6dtxt0s/'
|
||||
- TOKEN='7102273461:AAGi8RXCEvns2ONu3RcG9Up973vcLzTdCJg'
|
||||
>>>>>>> 8e02e7e37e90109b71d0bcc7f46211f308e97edb
|
||||
ports:
|
||||
- 8099:80
|
||||
networks:
|
||||
|
|
Loading…
Reference in New Issue