2024-01-23 20:51:42 +07:00

69 lines
1.6 KiB
Python

import os
import json
import datetime
import re
import config
class msg:
def __init__(self, body):
self.body: bytearray = body
self.decode: str = self.body.decode('utf-8')
self.json: json = json.loads(self.decode.replace("\'", "\""))
self.dict: dict = dict(self.json)
def getDirection(self):
try:
return self.dict["direction"]
except:
pass
def isIncoming(self) -> bool:
return True if self.dict["direction"] == "incoming" else False
def isExternal(self) -> bool:
return not self.isIncoming()
def getState(self) -> str:
try:
return self.dict["state"]
except:
pass
def getClient(self) -> str:
return self.dict["from"] if self.isIncoming() else self.dict["to"]
def getTime(self) -> str:
try:
return datetime.datetime.fromtimestamp(self.dict["time"]).strftime('%Y-%m-%d %H:%M:%S')
except:
return None
def getStatus(self) -> int:
pass
def getRecordUrl(self) -> str:
return self.dict["recordUrl"]
def getDuration(self) -> int:
return self.dict["duration"]
def getUUID(self) -> str:
try:
return self.dict["uuid"]
except:
pass
def isAnswered(self) -> bool:
try:
self.dict["callstatus"]
return True
except:
return False
def isImportant(self):
try:
return True if self.getState() == "START" and self.isIncoming() and self.dict["to"] in config.IMPORTANT_LINE else False
except:
pass