готово к запуску

This commit is contained in:
Dev PC
2025-08-03 17:35:11 +03:00
parent ccde82adf3
commit c38929fbb4
33 changed files with 862 additions and 564932 deletions
+100
View File
@@ -0,0 +1,100 @@
import logging
import config
import json
from aiohttp import ClientSession
import aiohttp
def loggingDict(title: str, data: dict) -> None:
logging.info(
f"{title}: %s",
json.dumps(data, indent=4, ensure_ascii=False).encode("utf-8").decode("utf-8"),
)
async def send_post_request(body: dict):
async def post_request(
url: str,
headers: dict = None,
json: dict = None,
**kwargs,
):
try:
async with ClientSession() as session:
async with session.post(
url, json=json, headers=headers, **kwargs
) as response:
response.raise_for_status()
return await response.json()
except aiohttp.ClientError as e:
if config.DEBUG:
logging.error(f"Request failed: {str(e)}")
return None
data = {"call": body}
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {config.MEDODS_TOKEN}",
}
if config.DEBUG:
loggingDict("Sending data to Medods", body)
r = await post_request(url=config.MEDODS_SERVER, headers=headers, json=data)
try:
res = {
"id": r["call"]["id"],
"status": r["call"]["status"],
"call_session_id": r["call"]["call_session_id"],
}
except:
res = {}
loggingDict("Recieved data from Medods:", res)
else:
await post_request(url=config.MEDODS_SERVER, headers=headers, json=data)
async def incoming_call(call_session_id, contact_phone_number, called_phone_number):
body = {
"status": "incoming_call",
"call_session_id": call_session_id,
"contact_phone_number": contact_phone_number,
"called_phone_number": called_phone_number,
}
await send_post_request(body)
async def call_started(call_session_id):
body = {
"status": "call_started",
"call_session_id": call_session_id,
"responsibles": [777],
}
await send_post_request(body)
async def call_finished(call_session_id, duration):
body = {
"status": "call_finished",
"call_session_id": call_session_id,
"duration": duration,
}
await send_post_request(body)
async def call_lost(call_session_id):
body = {
"status": "call_lost",
"call_session_id": call_session_id,
"responsibles": config.OPERATORS,
}
await send_post_request(body)
async def call_record_file(call_session_id, uniqueid):
body = {
"status": "call_record_file",
"call_session_id": call_session_id,
"file_link": f"{config.RECORDS_SERVER}{uniqueid}",
}
await send_post_request(body)