Bläddra i källkod

Merge branch 'master' of ssh://gitlab.fuxicarbon.com:1111/client_service/voice-gateway-service

余尚辉 5 månader sedan
förälder
incheckning
42f3ed6e01

+ 38 - 0
sql/libra_bot_c_agent.sql

@@ -0,0 +1,38 @@
+create table c_agent
+(
+    id            bigint unsigned auto_increment comment '主键'
+        primary key,
+    saas_id       varchar(16) default ''                not null comment '租户隔离',
+    agent_num     varchar(32) default ''                not null comment '坐席工号',
+    agent_name    varchar(32) default ''                not null comment '坐席姓名',
+    out_id        varchar(32) default ''                not null comment '外部id',
+    agent_pwd     varchar(64) default ''                not null comment '坐席密码',
+    agent_type    tinyint     default 0                 not null comment '坐席类型 0:普通坐席 ;1:组长:2:主管',
+    phone_num     varchar(32) default '0'               not null comment '分机号',
+    distribute    tinyint     default 1                 not null comment '分配标志  0:不参与排队;1:参与排队',
+    agent_state   tinyint     default 0                 not null comment '账号状态 0:可用;1:禁用',
+    identity_type tinyint     default 0                 not null comment '身份标识',
+    is_delete     tinyint     default 0                 not null comment '删除标识',
+    update_time   timestamp   default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
+    create_time   timestamp   default CURRENT_TIMESTAMP not null comment '创建时间',
+    constraint uniq_vcc_id_agent_num
+        unique (saas_id, agent_num)
+)
+    comment '坐席信息表';
+
+create index idx_vcc_id_out_id
+    on c_agent (saas_id, out_id);
+
+create index idx_vcc_id_phone_num
+    on c_agent (saas_id, phone_num);
+
+INSERT INTO libra_bot.c_agent (id, saas_id, agent_num, agent_name, out_id, agent_pwd, agent_type, phone_num, distribute, agent_state, identity_type, is_delete, update_time, create_time) VALUES (1, 'mdj', '1000', 'user0', '1000', '123456', 0, '1000', 1, 0, 0, 0, '2024-10-08 16:50:08', '2024-10-08 16:46:31');
+INSERT INTO libra_bot.c_agent (id, saas_id, agent_num, agent_name, out_id, agent_pwd, agent_type, phone_num, distribute, agent_state, identity_type, is_delete, update_time, create_time) VALUES (3, 'mdj', '1001', 'user1', '1001', '123456', 0, '1001', 1, 0, 0, 0, '2024-10-08 16:50:08', '2024-10-08 16:49:10');
+INSERT INTO libra_bot.c_agent (id, saas_id, agent_num, agent_name, out_id, agent_pwd, agent_type, phone_num, distribute, agent_state, identity_type, is_delete, update_time, create_time) VALUES (4, 'mdj', '1002', 'user2', '1002', '123456', 0, '1002', 1, 0, 0, 0, '2024-10-08 16:50:08', '2024-10-08 16:49:10');
+INSERT INTO libra_bot.c_agent (id, saas_id, agent_num, agent_name, out_id, agent_pwd, agent_type, phone_num, distribute, agent_state, identity_type, is_delete, update_time, create_time) VALUES (5, 'mdj', '1003', 'user3', '1003', '123456', 0, '1003', 1, 0, 0, 0, '2024-10-08 16:50:08', '2024-10-08 16:49:10');
+INSERT INTO libra_bot.c_agent (id, saas_id, agent_num, agent_name, out_id, agent_pwd, agent_type, phone_num, distribute, agent_state, identity_type, is_delete, update_time, create_time) VALUES (6, 'mdj', '1004', 'user4', '1004', '123456', 0, '1004', 1, 0, 0, 0, '2024-10-08 16:50:08', '2024-10-08 16:49:10');
+INSERT INTO libra_bot.c_agent (id, saas_id, agent_num, agent_name, out_id, agent_pwd, agent_type, phone_num, distribute, agent_state, identity_type, is_delete, update_time, create_time) VALUES (7, 'mdj', '1005', 'user5', '1005', '123456', 0, '1005', 1, 0, 0, 0, '2024-10-08 16:50:08', '2024-10-08 16:49:10');
+INSERT INTO libra_bot.c_agent (id, saas_id, agent_num, agent_name, out_id, agent_pwd, agent_type, phone_num, distribute, agent_state, identity_type, is_delete, update_time, create_time) VALUES (8, 'mdj', '1006', 'user6', '1006', '123456', 0, '1006', 1, 0, 0, 0, '2024-10-08 16:50:08', '2024-10-08 16:49:10');
+INSERT INTO libra_bot.c_agent (id, saas_id, agent_num, agent_name, out_id, agent_pwd, agent_type, phone_num, distribute, agent_state, identity_type, is_delete, update_time, create_time) VALUES (9, 'mdj', '1007', 'user7', '1007', '123456', 0, '1007', 1, 0, 0, 0, '2024-10-08 16:50:08', '2024-10-08 16:49:10');
+INSERT INTO libra_bot.c_agent (id, saas_id, agent_num, agent_name, out_id, agent_pwd, agent_type, phone_num, distribute, agent_state, identity_type, is_delete, update_time, create_time) VALUES (10, 'mdj', '1008', 'user8', '1008', '123456', 0, '1008', 1, 0, 0, 0, '2024-10-08 16:50:08', '2024-10-08 16:49:10');
+INSERT INTO libra_bot.c_agent (id, saas_id, agent_num, agent_name, out_id, agent_pwd, agent_type, phone_num, distribute, agent_state, identity_type, is_delete, update_time, create_time) VALUES (11, 'mdj', '1009', 'user9', '1009', '123456', 0, '1009', 1, 0, 0, 0, '2024-10-08 16:50:08', '2024-10-08 16:49:10');

+ 31 - 0
sql/libra_bot_c_agent_monitor.sql

@@ -0,0 +1,31 @@
+create table c_agent_monitor
+(
+    id             bigint unsigned auto_increment comment '主键'
+        primary key,
+    saas_id        varchar(16) default ''                not null comment '租户隔离',
+    agent_num      varchar(32) default ''                not null comment '坐席工号',
+    out_id         varchar(32) default ''                not null comment '外部id',
+    identity_type  tinyint     default 0                 not null comment '身份标识',
+    check_state    tinyint     default 1                 not null comment '是否签入 0:是 1: 否  默认未签入',
+    check_scene    varchar(16) default ''                not null comment '迁入场景',
+    check_in_time  timestamp   default CURRENT_TIMESTAMP not null comment '签入时间',
+    check_out_time timestamp   default CURRENT_TIMESTAMP not null comment '签出时间',
+    service_state  tinyint     default 0                 not null comment '坐席服务状态 0: 未登录(签出) 1: 置忙 2: 置闲 3: 通话中 4: 后处理 5: 拨号中',
+    busy_time      timestamp   default CURRENT_TIMESTAMP not null comment '置忙时间',
+    idle_time      timestamp   default CURRENT_TIMESTAMP not null comment '置闲时间',
+    call_time      timestamp   default CURRENT_TIMESTAMP not null comment '接通时间',
+    hang_time      timestamp   default CURRENT_TIMESTAMP not null comment '挂断时间',
+    heart_state    tinyint     default 0                 not null comment '心跳状态 0: 默认 1:正常  2: 异常',
+    heart_time     timestamp   default CURRENT_TIMESTAMP not null comment '正常心跳时间',
+    session_id     varchar(64) default ''                not null comment 'sessionId',
+    is_delete      tinyint     default 0                 not null comment '删除标识',
+    update_time    timestamp   default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
+    create_time    timestamp   default CURRENT_TIMESTAMP not null comment '创建时间',
+    constraint uniq_saas_id_agent_num
+        unique (saas_id, agent_num)
+)
+    comment '坐席监控表';
+
+create index idx_saas_id_out_id
+    on c_agent_monitor (saas_id, out_id);
+

+ 29 - 0
sql/libra_bot_c_phone.sql

@@ -0,0 +1,29 @@
+create table c_phone
+(
+    id          bigint unsigned auto_increment
+        primary key,
+    saas_id     varchar(16) default ''                not null,
+    phone_num   varchar(32) default '0'               not null,
+    phone_pwd   varchar(32) default ''                not null,
+    sip_server  varchar(64) default ''                not null,
+    wss_server  varchar(64) default ''                not null,
+    ice_server  varchar(64) default ''                not null,
+    is_delete   tinyint     default 0                 not null,
+    update_time timestamp   default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP,
+    create_time timestamp   default CURRENT_TIMESTAMP not null
+)
+    comment '分机信息表';
+
+create index idx_vcc_id_phone_num
+    on c_phone (saas_id, phone_num);
+
+INSERT INTO libra_bot.c_phone (id, saas_id, phone_num, phone_pwd, sip_server, wss_server, ice_server, is_delete, update_time, create_time) VALUES (1, 'mdj', '1000', 'slibra@#123456', 'sip:1000@pbx.fuxicarbon.com:5060', 'wss://pbx.fuxicarbon.com:7443', 'stun:pbx.fuxicarbon.com:3478', 1, '2024-10-08 16:43:56', '2024-10-08 16:43:56');
+INSERT INTO libra_bot.c_phone (id, saas_id, phone_num, phone_pwd, sip_server, wss_server, ice_server, is_delete, update_time, create_time) VALUES (2, 'mdj', '1001', 'slibra@#123456', 'sip:1001@pbx.fuxicarbon.com:5060', 'wss://pbx.fuxicarbon.com:7443', 'stun:pbx.fuxicarbon.com:3478', 1, '2024-10-08 16:43:56', '2024-10-08 16:43:56');
+INSERT INTO libra_bot.c_phone (id, saas_id, phone_num, phone_pwd, sip_server, wss_server, ice_server, is_delete, update_time, create_time) VALUES (3, 'mdj', '1002', 'slibra@#123456', 'sip:1002@pbx.fuxicarbon.com:5060', 'wss://pbx.fuxicarbon.com:7443', 'stun:pbx.fuxicarbon.com:3478', 1, '2024-10-08 16:43:56', '2024-10-08 16:43:56');
+INSERT INTO libra_bot.c_phone (id, saas_id, phone_num, phone_pwd, sip_server, wss_server, ice_server, is_delete, update_time, create_time) VALUES (4, 'mdj', '1003', 'slibra@#123456', 'sip:1003@pbx.fuxicarbon.com:5060', 'wss://pbx.fuxicarbon.com:7443', 'stun:pbx.fuxicarbon.com:3478', 1, '2024-10-08 16:43:56', '2024-10-08 16:43:56');
+INSERT INTO libra_bot.c_phone (id, saas_id, phone_num, phone_pwd, sip_server, wss_server, ice_server, is_delete, update_time, create_time) VALUES (5, 'mdj', '1004', 'slibra@#123456', 'sip:1004@pbx.fuxicarbon.com:5060', 'wss://pbx.fuxicarbon.com:7443', 'stun:pbx.fuxicarbon.com:3478', 1, '2024-10-08 16:43:56', '2024-10-08 16:43:56');
+INSERT INTO libra_bot.c_phone (id, saas_id, phone_num, phone_pwd, sip_server, wss_server, ice_server, is_delete, update_time, create_time) VALUES (6, 'mdj', '1005', 'slibra@#123456', 'sip:1005@pbx.fuxicarbon.com:5060', 'wss://pbx.fuxicarbon.com:7443', 'stun:pbx.fuxicarbon.com:3478', 1, '2024-10-08 16:43:56', '2024-10-08 16:43:56');
+INSERT INTO libra_bot.c_phone (id, saas_id, phone_num, phone_pwd, sip_server, wss_server, ice_server, is_delete, update_time, create_time) VALUES (7, 'mdj', '1006', 'slibra@#123456', 'sip:1006@pbx.fuxicarbon.com:5060', 'wss://pbx.fuxicarbon.com:7443', 'stun:pbx.fuxicarbon.com:3478', 1, '2024-10-08 16:43:56', '2024-10-08 16:43:56');
+INSERT INTO libra_bot.c_phone (id, saas_id, phone_num, phone_pwd, sip_server, wss_server, ice_server, is_delete, update_time, create_time) VALUES (8, 'mdj', '1007', 'slibra@#123456', 'sip:1007@pbx.fuxicarbon.com:5060', 'wss://pbx.fuxicarbon.com:7443', 'stun:pbx.fuxicarbon.com:3478', 1, '2024-10-08 16:43:56', '2024-10-08 16:43:56');
+INSERT INTO libra_bot.c_phone (id, saas_id, phone_num, phone_pwd, sip_server, wss_server, ice_server, is_delete, update_time, create_time) VALUES (9, 'mdj', '1008', 'slibra@#123456', 'sip:1008@pbx.fuxicarbon.com:5060', 'wss://pbx.fuxicarbon.com:7443', 'stun:pbx.fuxicarbon.com:3478', 1, '2024-10-08 16:43:56', '2024-10-08 16:43:56');
+INSERT INTO libra_bot.c_phone (id, saas_id, phone_num, phone_pwd, sip_server, wss_server, ice_server, is_delete, update_time, create_time) VALUES (10, 'mdj', '1009', 'slibra@#123456', 'sip:1009@pbx.fuxicarbon.com:5060', 'wss://pbx.fuxicarbon.com:7443', 'stun:pbx.fuxicarbon.com:3478', 1, '2024-10-08 16:43:56', '2024-10-08 16:43:56');

+ 1 - 0
src/core/voip/bot.py

@@ -162,6 +162,7 @@ class MyCall(pj.Call):
     def onDtmfDigit(self, prm):
     def onDtmfDigit(self, prm):
         digit = prm.digit
         digit = prm.digit
         print(f"Received DTMF digit: {digit}")
         print(f"Received DTMF digit: {digit}")
+        # self.user_asr_text_queue.put(f"DTMF:{digit}")
 
 
     def onCallState(self, prm):
     def onCallState(self, prm):
         call_info = self.getInfo()
         call_info = self.getInfo()

+ 33 - 0
src/core/voip/constant.py

@@ -0,0 +1,33 @@
+#!/usr/bin/env python3
+# encoding:utf-8
+
+import os
+import mmh3
+import queue
+import pjsua2 as pj
+
+player_script_dir = '/code/src/core/voip/scripts/'
+
+
+def murmur3_32(player_file):
+    return abs(mmh3.hash(player_file))
+
+
+def build_audio_format():
+    fmt = pj.MediaFormatAudio()
+    fmt.type = pj.PJMEDIA_TYPE_AUDIO
+    fmt.id = pj.PJMEDIA_FORMAT_PCM
+    fmt.clockRate = 16000  # 采样率
+    fmt.channelCount = 1  # 通道数
+    fmt.frameTimeUsec = 20000  # 每帧的时间(20 毫秒)
+    fmt.bitsPerSample = 16  # 每个采样的位数
+    return fmt
+
+
+def build_demo_script():
+    res = queue.Queue(maxsize=10)
+    for file in os.listdir(player_script_dir):
+        file = os.path.join(player_script_dir, file)
+        print('build_demo_script::', file)
+        res.put(file)
+    return res