constant.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/usr/bin/env python3
  2. # encoding:utf-8
  3. import json
  4. from src.core.callcenter.enumeration import CallStage
  5. saasId = "mdj"
  6. UTF_8 = "UTF-8"
  7. SPACE = " "
  8. EMPTY = ""
  9. LF = "\n"
  10. CR = "\r"
  11. AT = "@"
  12. CO = ":"
  13. UNDER_LINE = "_"
  14. POINT = "."
  15. SK = "/"
  16. LINE = "-"
  17. JSON = ".json"
  18. XML = ".xml"
  19. HTTP = "http://"
  20. HTTPS = "https://"
  21. #vip等级进线
  22. VIP_LEVEL = "vipLevel"
  23. START_TIME = "startTime"
  24. QUEUE_TIME = "queueTime"
  25. #指定坐席
  26. DESIGNATE_AGENT = "desiganteAgent"
  27. #当前空闲时间
  28. LONG_READY = "longReady"
  29. #空闲次数
  30. READY_TIMES = "readyTimes"
  31. #服务次数
  32. SEREVICE_TIMES = "serviceTimes"
  33. HOLD_MUSIC_PATH = '/freeswitch/music/hold.wav'
  34. WaitingHangupMusicPath = '/freeswitch/music/sorry.wav'
  35. BASE_RECORD_PATH = '/freeswitch/record/'
  36. EMPTY = ""
  37. DEFAULT_KEY = ""
  38. #坐席状态相关
  39. AGENT_STATE_KEY = "STATE"
  40. AGENT_LOG_KEY = "LOG"
  41. DEVOCE_KEY = "DEVICE"
  42. DETAIL_KEY = "DETAIL"
  43. CALLLOG_KEY = "CALLLOG"
  44. AGENT_STATE_EXCHANGE = "AGENT-STATE-EXCHANGE"
  45. CALL_LOG_EXCHANGE = "CALL-LOG-EXCHANGE"
  46. #话单相关
  47. CALL_DEVICE_QUEUE = "CALL-DEVICE-QUEUE"
  48. CALL_LOG_QUEUE = "CALL-LOG-QUEUE"
  49. CALL_DETAIL_QUEUE = "CALL-DETAIL-QUEUE"
  50. AGENT_STATE_QUEUE = "AGENT-STATE-QUEUE"
  51. AGENT_LOG_QUEUE = "AGENT-LOG-QUEUE"
  52. #配置变更相关
  53. CC_CONFIG_EXCHANGE = "CC-CONFIG-EXCHANGE"
  54. CC_CONFIG_QUEUE = "CC-CONFIG-QUEUE"
  55. AGENT_TOKEN = "AGENT_TOKEN:"
  56. AGENT_INFO = "AGENT_INFO:"
  57. ADMIN_TOKEN = "ADMIN_TOKEN:"
  58. ADMIN_INFO = "ADMIN_INFO:"
  59. CALL_INFO = "CALL_INFO:"
  60. START_AGENT_NUM = "1000"
  61. DELAY_ACTION_BATCH_SIZE = 10
  62. CTI_ENGINE_DELAY_ACTION = "DELAY:ACTION:%s"
  63. CTI_ENGINE_DELAY_ACTION_LOCK = "DELAY:ACTION:LOCK:%s"
  64. NEED_PLAY_HOLD_MUSIC = "CTI:ENGINE:NEED:HOLD:%s"
  65. AFTER_PLAY_HOLD_MUSIC = "CTI:ENGINE:AFTER:HOLD:%s"
  66. CTI_MANAGE_CENTER_CALL_END_KEY = "CTI:MANAGE:CENTER:CALL:END:KEY:%s"
  67. CTI_AGENT_MANUAL_ANSWER = "AGENT:MANUAL:ANSWER:%s:%s"
  68. def get_json_dict(json_text=None):
  69. if isinstance(json_text, str):
  70. _data = json.loads(json_text)
  71. elif isinstance(json_text, bytes):
  72. json_string = json_text.decode('UTF-8')
  73. _data = json.loads(json_string)
  74. else:
  75. _data = json_text
  76. return _data
  77. def success_response(data=None, code=0, msg=""):
  78. response = json.dumps({"code": code, "msg": msg, "data": data})
  79. return response, 200, {"Content-Type": "application/json"}
  80. def error_response(msg, data=None, code=1, http_code=200):
  81. print("liuwei::debubgger::error_response:code=%s, msg=%s, data=%s" % (code, msg, data), flush=True)
  82. response = json.dumps({"code": code, "msg": msg, "data": data})
  83. return response, http_code, {"Content-Type": "application/json"}
  84. def format_time_millis(time_millis, pattern='%Y%m%d'):
  85. from datetime import datetime
  86. dt = datetime.utcfromtimestamp(time_millis)
  87. return dt.strftime(pattern)
  88. # def get_record_prefix(call):
  89. # return BASE_RECORD_PATH + call.call_type + '/' + call.saas_id + '/' + call.caller + '/' + format_time_millis(call.call_time)
  90. def get_record_prefix(call):
  91. # 确保所有的值都是字符串类型
  92. return BASE_RECORD_PATH + str(call.call_type) + '/' + str(call.saas_id) + '/' + str(call.caller) + '/' + format_time_millis(call.call_time)
  93. def get_record_file_name(call_id, stage: CallStage):
  94. if stage.ROBOT == stage:
  95. return call_id + '_0'
  96. if stage.AGENT == stage:
  97. return call_id + '_1'
  98. return call_id