@94ai/softphone 5.0.14 → 5.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -80,6 +80,7 @@ const nfSoftPhone1 = (new SoftphoneManager()).initSoftphone({ // 👈 当多实
80
80
  softphoneConnectCallBack: (data) => {
81
81
  console.log('softphone-connect')
82
82
  }, // 👈 签入签出回调
83
+ softphoneAutoIgnoreCallback: (data) => {console.log('softphone-auto-ignore-callback', data)}, // 👈 自动忽略回调
83
84
  softphoneCallRefreshCallBack: (data) => {console.log('softphone-call-refresh')}, // 👈 来电刷新来电记录列表回调
84
85
  softphoneSeatStatusChangeCallBack: (data) => {console.log('softphone-seats-status-change')},// 👈 小休和在线切换回调
85
86
  softphoneAcceptCallBack: (data) => {console.log('softphone-accept')},// 👈 接听回调
@@ -88,7 +89,9 @@ const nfSoftPhone1 = (new SoftphoneManager()).initSoftphone({ // 👈 当多实
88
89
  softphoneSessionStateChangeCallBack: (data) => {console.log('softphone-session-state-change')},// 👈 会话状态改变回调
89
90
  softphoneIncomingCallBack: (data) => {console.log('softphone-incoming')},// 👈 来电回调
90
91
  softphoneSendDtmfCallBack: (data) => {console.log('softphone-send-dtmf')},// 👈 转人工回调
91
- softphoneConnectRegisteredCallBack: (data) => {console.log('softphone-connect-registered')},// 👈 动态绑定动作完成回调(在这之后才能执行动作类总线通讯)
92
+ softphoneConnectRegisteredCallBack: async (data) => {
93
+ console.log('softphone-connect-registered', data)
94
+ },// 👈 动态绑定动作完成回调(在这之后才能执行动作类总线通讯)
92
95
  });
93
96
 
94
97
  // setTimeout(() => {
@@ -61,6 +61,7 @@ class SoftphoneManager {
61
61
  softphoneAcceptCallBack: () => {console.log('softphone-accept')},
62
62
  softphoneIgnoreCallBack: () => {console.log('softphone-ignore')},
63
63
  softphoneHangupCallBack: () => {console.log('softphone-hangup')},
64
+ softphoneAutoIgnoreCallback: () => {console.log('softphone-auto-ignore-callback')},
64
65
  softphoneSessionStateChangeCallBack: () => {console.log('softphone-session-state-change')},
65
66
  softphoneIncomingCallBack: () => {console.log('softphone-incoming')},
66
67
  softphoneSendDtmfCallBack: () => {console.log('softphone-send-dtmf')},
@@ -155,6 +156,8 @@ class SoftphoneManager {
155
156
  this.option.softphoneIgnoreCallBack?.(data)
156
157
  } else if (data.type === 'softphone-hangup') {
157
158
  this.option.softphoneHangupCallBack?.(data)
159
+ } else if (data.type === 'softphone-auto-ignore-callback') {
160
+ this.option.softphoneAutoIgnoreCallback?.(data)
158
161
  } else if (data.type === 'softphone-session-state-change') {
159
162
  this.option.softphoneSessionStateChangeCallBack?.(data)
160
163
  } else if (data.type === 'softphone-incoming') {
@@ -201,6 +201,14 @@ document.addEventListener('DOMContentLoaded', async (event) => {
201
201
  getMedia
202
202
  } = softphone // 👈 sdk
203
203
 
204
+ const agentTag = '15018707394' // 生产线 坐席维度定位
205
+ const appKey = '032d44009bff1752' // 生产线 企业维度定位
206
+ const appSecret = '4c7304c94c5e8725613516d4d6db679b' // 生产线 企业维度定位
207
+
208
+ const timestamp = Date.now()
209
+ const sign = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA1(appKey + timestamp, appSecret))
210
+
211
+
204
212
  const extensionNumber = '9288' // 生产线 分机账号
205
213
  const extPassword = 'zjh13542240708' // 生产线 分机密码
206
214
  const wsProtocol = 'ws' // 生产线 外呼服务器地址协议
@@ -267,6 +275,31 @@ document.addEventListener('DOMContentLoaded', async (event) => {
267
275
  },
268
276
  })
269
277
 
278
+ const getAgentInfo = async () => {
279
+ // UserAgentFactory.getUserAgentManager实例 授权参数 优先级高于 单独授权参数
280
+ // 即如果UserAgentFactory.getUserAgentManager实例已完全授权(初始化传入sign或appSecret), requestOpenApi同时传入授权参数, 授权过期 以 UserAgentFactory.getUserAgentManager实例的授权参数做过期检测
281
+ // requestOpenApi单独临时授权不做过期检测, 不对UserAgentFactory.getUserAgentManager实例更新授权
282
+ const signRes = await userAgentManager.requestOpenApi({
283
+ url: '/v1/agent/getAgent',
284
+ data: {
285
+ agentTag,
286
+ timestamp, // 单独授权参数
287
+ appKey, // 单独授权参数
288
+ sign // 单独授权参数
289
+ }
290
+ })
291
+ const secretRes = await userAgentManager.requestOpenApi({
292
+ url: '/v1/agent/getAgent',
293
+ data: {
294
+ agentTag,
295
+ appKey, // 单独授权参数
296
+ appSecret // 单独授权参数
297
+ }
298
+ })
299
+ console.log(signRes, secretRes)
300
+ }
301
+
302
+ getAgentInfo()
270
303
 
271
304
  /**
272
305
  * 签入
@@ -89,7 +89,11 @@
89
89
  <br>
90
90
  <br>
91
91
  <button id="callButton">3. 手动呼叫</button>
92
- : <input id="call" />
92
+ : <input id="call" placeholder="请输入, 空值用测试手机号" style="width: 180px"/>
93
+ <br>
94
+ <br>
95
+ <button id="taskButton">任务呼叫</button>
96
+ : <input id="taskCall" placeholder="请输入任务id, 空值用测试任务" style="width: 180px"/> <input id="taskPhoneCall" placeholder="请输入手机号, 空值用测试手机号" style="width: 180px"/>
93
97
  <br>
94
98
  <br>
95
99
  <button id="ignore" disabled>忽略</button>
@@ -283,7 +287,10 @@ document.addEventListener('DOMContentLoaded', async (event) => {
283
287
  const hangUp = document.getElementById('hangUp')
284
288
  const connectToServer = document.getElementById('connectToServer')
285
289
  const call = document.getElementById('call')
290
+ const taskCall = document.getElementById('taskCall')
291
+ const taskPhoneCall = document.getElementById('taskPhoneCall')
286
292
  const callButton = document.getElementById('callButton')
293
+ const taskButton = document.getElementById('taskButton')
287
294
  const nap = document.getElementById('nap')
288
295
  const chatInfo = document.getElementById('chatInfo')
289
296
  const online = document.getElementById('online')
@@ -315,10 +322,9 @@ document.addEventListener('DOMContentLoaded', async (event) => {
315
322
  // appSecret: '9fb4aac7b1dbfbb21696bcd7a30cb382', // 测试线 企业维度定位
316
323
 
317
324
  /**
318
- * 1. 如果是海外环境新增这三个参数
325
+ * 1. 如果是海外环境新增这两个参数
319
326
  * sgOpen: '1',
320
327
  * sg: '1',
321
- * openBaseUrl: '1',
322
328
  * 2. 为了appSecret安全性,通过sign初始化,记得注册过期回调刷新sign
323
329
  * sign: 'xxx', // 代替appSecret
324
330
  * timestamp: 'xxx',
@@ -338,30 +344,57 @@ document.addEventListener('DOMContentLoaded', async (event) => {
338
344
  * }
339
345
  * },
340
346
  */
347
+
348
+ // const agentTag = '15018707394' // 国内生产线 坐席维度定位
349
+ // const appKey = '032d44009bff1752' // 国内生产线 企业维度定位
350
+ // const appSecret = '4c7304c94c5e8725613516d4d6db679b' // 国内生产线 企业维度定位
351
+ const agentId = '2357' // 海外生产线 坐席维度定位
352
+ const appKey = 'a52e61f0d9ff1527' // 海外生产线 企业维度定位
353
+ const appSecret = '7ed1d78fbe214ba8b8e6a2dc9c6955aa' // 海外生产线 企业维度定位
354
+ const timestamp = Date.now()
355
+ const sign = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA1(appKey + timestamp, appSecret))
356
+
341
357
  const userAgentManager = UserAgentFactory.getUserAgentManager({
342
- // sgOpen: '1',
343
- // sg: '1',
344
- // openBaseUrl: '1',
358
+ /**
359
+ * start - 海外特有参数
360
+ */
361
+ sgOpen: '1', // 是否切换海外代理, 默认'0'为国内
362
+ sg: '1', // 是否切换海外环境, 默认'0'为国内
363
+ /**
364
+ * end - 海外特有参数
365
+ */
366
+ // openBaseUrl: '', // 自定义第三方环境, 默认undefined, 示例:'https://www.xxx.com/openapi'
367
+
345
368
  // agentId: '2357', // 海外生产线 坐席维度定位
346
369
  // appKey: 'a52e61f0d9ff1527', // 海外生产线 企业维度定位
347
370
  // appSecret: '7ed1d78fbe214ba8b8e6a2dc9c6955aa', // 海外生产线 企业维度定位 这里直接使用appSecret做演示
348
-
371
+ // agentTag,
372
+ agentId,
373
+ appKey,
374
+ timestamp,
375
+ sign,
376
+ signOverdued() {
377
+ console.log('==sign已过期==')
378
+ const timestamp = Date.now()
379
+ const sign = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA1(appKey + timestamp, appSecret))
380
+ console.log('==重新生成sign==', sign)
381
+ return {
382
+ timestamp,
383
+ sign,
384
+ }
385
+ },
349
386
  // logLevel: 'debug', // 日志等级,默认error
350
- openXhrIntercept(xhr) {
387
+ openXhrIntercept(xhr) { // 设置接口语言
351
388
  // xhr.setRequestHeader('language', 'es-ES')
352
389
  xhr.setRequestHeader('language', 'zh-CN')
353
390
  // xhr.setRequestHeader('language', 'en-US')
354
391
  },
355
- agentTag: '15018707394', // 国内生产线 坐席维度定位
356
- appKey: '032d44009bff1752', // 国内生产线 企业维度定位
357
- appSecret: '4c7304c94c5e8725613516d4d6db679b', // 国内生产线 企业维度定位 这里直接使用appSecret做演示
358
-
359
392
  // refreshSpeekVolumn(value) { // 当来电接通时,实时查看坐席说话的音量实际传送到给对方的音量大小
360
393
  // volumn.innerText = value
361
394
  // },
362
- // refreshRequirementCheck(value) { // 权限网络检测
363
- // browserSoftphoneEnv.innerText = JSON.stringify(value, null, 2)
364
- // },
395
+ refreshRequirementCheck(value) { // 权限网络检测
396
+ browserSoftphoneEnv.innerText = JSON.stringify(value, null, 2)
397
+ },
365
398
  // refreshChat(info) { // 刷新会话记录
366
399
  // chatInfo.innerText = JSON.stringify(info, null, 2)
367
400
  // },
@@ -470,29 +503,33 @@ document.addEventListener('DOMContentLoaded', async (event) => {
470
503
 
471
504
  /** 方式二:extensionNumber + extPassword + wsProtocol + wsRegisterAddress 获取软电话链接代理实例 */
472
505
  // 即直接通过【分机号】和【分机密码】以及【外呼服务器地址】实现软电话的直接签入
473
- // 九四的同学:测试环境不能访问openAPI,可以采用决策系统内部接口获取分机信息接入外呼服务器
474
- // 生产环境如果采用分机维度的分机信息可以通过agentTag调用openapi获取
506
+ // 下述分机信息可以通过agentTag/agentId调用openapi获取
475
507
  // const extensionNumber = '2839' // 测试线 分机账号
476
508
  // const extPassword = 'zjh13542240708' // 测试线 分机密码
477
509
  // const wsProtocol = 'ws' // 测试线外呼服务器地址协议
478
510
  // const wsRegisterAddress = '192.168.31.239:5066' // 测试线 外呼服务器地址
511
+ //
479
512
  // const sipServerHost = `sip:${extensionNumber}@${wsRegisterAddress}` // fs地址
480
513
  // const wsAddress = `${wsProtocol}://${wsRegisterAddress}` // socket地址
481
514
 
515
+
482
516
  // const extensionNumber = '2510' // 生产线 分机账号
483
517
  // const extPassword = 'zengrongzhi123' // 生产线 分机密码
484
518
  // const wsProtocol = 'ws' // 生产线 外呼服务器地址协议
485
519
  // const wsRegisterAddress = '192.168.31.239:5066' // 生产线 外呼服务器地址
520
+ //
486
521
  // const sipServerHost = `sip:${extensionNumber}@${wsRegisterAddress}` // fs地址
487
522
  // const wsAddress = `${wsProtocol}://${wsRegisterAddress}` // socket地址
488
523
 
524
+
489
525
  // const extensionNumber = '1001' // 生产线 分机账号
490
526
  // const extPassword = '946666' // 生产线 分机密码
491
527
  // const wsProtocol = 'ws' // 生产线 外呼服务器地址协议
492
528
  // const wsRegisterAddress = '192.168.0.92:5066' // 生产线 外呼服务器地址
529
+ //
493
530
  // const sipServerHost = `sip:${extensionNumber}@${wsRegisterAddress}` // fs地址
494
531
  // const wsAddress = `${wsProtocol}://${wsRegisterAddress}` // socket地址
495
- //
532
+
496
533
  // const userAgentManager = UserAgentFactory.getUserAgentManager({
497
534
  // authorizationPassword: extPassword, // 分机密码
498
535
  // authorizationUsername: extensionNumber, // 分机账号
@@ -504,25 +541,18 @@ document.addEventListener('DOMContentLoaded', async (event) => {
504
541
  // // viaHost, // fp.umd.min.js生成的唯一值,用来配查呼叫问题,可以不传,内部会自动生成
505
542
  // contactName: extensionNumber, // sip协议要求,同分机账号即可,注意类型为string, 不传默认同分机账号
506
543
  // clusterMode: true,
507
- // reClusterRegisterTimeout: 1000,
508
- // reClusterConnectTimeout: 1000,
509
- // // refreshSpeekVolumn(value) { // 当来电接通时,实时查看坐席说话的音量实际传送到给对方的音量大小
510
- // // volumn.innerText = value
511
- // // },
512
- // // refreshRequirementCheck(value) { // 权限网络检测
513
- // // browserSoftphoneEnv.innerText = JSON.stringify(value, null, 2)
514
- // // },
515
- // // refreshChat(info) {
516
- // // chatInfo.innerText = JSON.stringify(info, null, 2)
517
- // // },
518
- // // refreshChatErrorCallback(e) {
519
- // // console.log(e)
520
- // // },
521
- // // enableChatInfoPush: true // 开启会话记录实时推送,开启后,当任务外呼时,可以实时获取通话记录信息,实时回调到refreshChat,中途出现任何异常会回调refreshChatErrorCallback
544
+ // reClusterRegisterTimeout: 4000,
545
+ // reClusterConnectTimeout: 4000,
546
+ // refreshSpeekVolumn(value) { // 当来电接通时,实时查看坐席说话的音量实际传送到给对方的音量大小
547
+ // volumn.innerText = value
548
+ // },
549
+ // refreshRequirementCheck(value) { // 权限网络检测
550
+ // browserSoftphoneEnv.innerText = JSON.stringify(value, null, 2)
551
+ // },
522
552
  // })
523
553
 
524
554
  /**
525
- * 获取坐席当前状态信息(注意牵扯到openAPI的信息需要angentId,即方式一。如果通过方式二需要手动使用userAgentManager.requestOpenApi获取,即上述example3
555
+ * 获取坐席当前状态信息(注意牵扯到openAPI的方法需要使用方式一初始化软电话实例。如果通过方式二需要手动使用userAgentManager.requestOpenApi获取,即上述example3,参看index-open.html的278行 getAgentInfo
526
556
  */
527
557
  const angentInfo = await userAgentManager.getAgentInfo()
528
558
  if (angentInfo.code === 200) { // 正确响应
@@ -560,9 +590,16 @@ document.addEventListener('DOMContentLoaded', async (event) => {
560
590
  // taskId: userAgentManager.businessAttribute.taskId, // 如果不是任务外呼不用传
561
591
  // })
562
592
  // console.log(info, '========')
563
- setTimeout(() => {
564
- acceptInvite()
565
- }, 0)
593
+ if (userAgentManager.businessAttribute.voiceType == 4) { // 主动外呼
594
+ setTimeout(() => {
595
+ acceptInvite()
596
+ }, 0)
597
+ } else { // 非主动导号
598
+ alert('坐席来电中,确定接听')
599
+ setTimeout(() => {
600
+ acceptInvite()
601
+ }, 0)
602
+ }
566
603
  console.log(userAgentManager.getSenders)
567
604
  console.log(userAgentManager.businessAttribute)
568
605
  phoneRings() // 播放模拟来电响铃
@@ -841,16 +878,61 @@ document.addEventListener('DOMContentLoaded', async (event) => {
841
878
  * })
842
879
  *
843
880
  */
881
+
882
+ function generateUUID() { // Public Domain/MIT
883
+ var d = Date.now();
884
+ if (typeof performance !== 'undefined' && typeof performance.now === 'function'){
885
+ d += performance.now(); //use high-precision timer if available
886
+ }
887
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
888
+ var r = (d + Math.random() * 16) % 16 | 0;
889
+ d = Math.floor(d / 16);
890
+ return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
891
+ });
892
+ }
893
+
894
+ // 任务外呼: 先桥接手机侧,手机侧接通后,再桥接坐席
895
+ const taskPhone = async () => {
896
+ const callInfo = await userAgentManager.requestOpenApi({ // 任务外呼
897
+ url: '/v1/task/importTaskCustomer',
898
+ data: {
899
+ "requestId": generateUUID(), // 请求id,具有唯一性,用来做请求幂等处理,一个请求id有效期10分钟。不传则不做幂等处理
900
+ "taskId": taskCall.value || 93726, // 测试任务
901
+ "failReturn": 1, // 可选值:0,1,默认1。如导入的数据中有部分验证不通过数据:0表示导入验证成功的,返回失败的数据;1表示全部数据(包括验证成功及失败的)都不导入;
902
+ "customers":[
903
+ {
904
+ "tag": "xx", // 自定义透传参数,来电坐席电话端软电话sip头可以直接获取
905
+ "clientUrl": "xx", // 自定义来电弹屏显示的第三方页面,用来展示来电具体信息
906
+ "number": taskPhoneCall.value || 15018707394, // 外呼号码
907
+ "properties": { // 自定义透传参数,可以通过[挂断回调]回调给第三方后端,前端主动获取需要调用gateway接口
908
+ "尊称": "先生",
909
+ "姓名": "张三"
910
+ }
911
+ }
912
+ ]
913
+ }
914
+ })
915
+ if (callInfo.code === 200) { // 正确响应
916
+ alert('导号成功')
917
+ } else {
918
+ alert(callInfo.message)
919
+ }
920
+ }
921
+
922
+ // 主动外呼: 先桥接坐席,坐席接通后, 再桥接手机侧
844
923
  const callPhone = async () => {
845
- // const callInfo = await userAgentManager.callNumber(call.value) // 👈 一键
846
- const callInfo = await userAgentManager.requestOpenApi({ // 主动外呼
924
+ // await userAgentManager.invite({
925
+ // extension: call.value // 分机号外呼
926
+ // })
927
+ // const callInfo = await userAgentManager.callNumber(call.value) // 👈 一键手机号外呼
928
+ const callInfo = await userAgentManager.requestOpenApi({ // 主动手机号外呼
847
929
  url: '/v1/task/importAgentCustomer',
848
930
  data: {
849
931
  agentTag: '15018707394',
850
932
  callType: 1001,
851
933
  customers: [{
852
934
  tag: '测试tag',
853
- number: 18617381945
935
+ number: call.value || 18617381945
854
936
  }]
855
937
  }
856
938
  })
@@ -859,9 +941,6 @@ document.addEventListener('DOMContentLoaded', async (event) => {
859
941
  } else {
860
942
  alert(callInfo.message)
861
943
  }
862
- // await userAgentManager.invite({
863
- // extension: call.value
864
- // })
865
944
  }
866
945
 
867
946
  /**
@@ -910,7 +989,8 @@ document.addEventListener('DOMContentLoaded', async (event) => {
910
989
  remoteSoundAccess.addEventListener('click', muteLocalAudio) // 关闭本地声音发送
911
990
  localSoundDisconnection.addEventListener('click', unMuteRemoteAudio) // 打开远端声音接收
912
991
  remoteSoundDisconnection.addEventListener('click', muteRemoteAudio) // 关闭远端声音接收
913
- callButton.addEventListener('click', callPhone) // 呼叫
992
+ callButton.addEventListener('click', callPhone) // 手动呼叫
993
+ taskButton.addEventListener('click', taskPhone) // 任务呼叫
914
994
  nap.addEventListener('click', toggleNap) // 切换坐席进入小休
915
995
  online.addEventListener('click', toggleOnline) // 切换坐席进入在线
916
996
  check.addEventListener('click', envCheck) // 执行软电话必备的权限&网络环境检测
@@ -9,6 +9,10 @@
9
9
  </head>
10
10
  <body>
11
11
  <div style="min-width: 700px;" id="softphone-container"></div> <!-- 👈 软电话容器 -->
12
+ <br/>
13
+ <button id="taskButton" style="margin-left: 20px">任务呼叫</button>
14
+ : <input id="taskCall" placeholder="请输入任务id, 空值用测试任务" style="width: 180px"/> <input id="taskPhoneCall" placeholder="请输入手机号, 空值用测试手机号" style="width: 180px"/>
15
+
12
16
  </body>
13
17
  <script src="./util.js"></script>
14
18
  <script src="./qiankun.js"></script>
@@ -33,6 +37,8 @@ document.addEventListener('DOMContentLoaded', async (event) => {
33
37
  const sha1 = CryptoJS.HmacSHA1(str, appSecret)
34
38
  sign = CryptoJS.enc.Base64.stringify(sha1)
35
39
 
40
+ let commonSoftphone // 软电话sdk实例
41
+
36
42
  /**
37
43
  👈 拿到实例后可以手动触发软电话实例的各种动作,如签入,签出,接听,忽略,挂断等等,注意这个实例不是软电话实例,是链接软电话通讯的实例
38
44
  */
@@ -53,11 +59,12 @@ document.addEventListener('DOMContentLoaded', async (event) => {
53
59
  /**
54
60
  * start - 海外特有参数
55
61
  */
56
- sgGateway: '1',
57
- sgBase: '1',
58
- sgOpen: '1',
59
- sgDomain: '1',
60
- env: 'sg',
62
+ sgGateway: '1', // 设置gatewayApi前缀调用地址, 默认undefined, 可选:'0'|'1'|string。示例: 'https://gateway.xxx.com'。 传'1'使用默认海外地址;传'0'或不传使用国内默认地址
63
+ sgBase: '1', // 设置baseApi前缀调用地址, 默认undefined, 可选:'0'|'1'|string。 示例: 'https://www.xxx.com/api'。 传'1'使用默认海外地址;传'0'或不传使用国内默认地址
64
+ sgOpen: '1', // 设置openApi前缀调用地址, 默认undefined, 可选:'0'|'1'|string。示例: 'https://www.xxx.com/openapi'。 传'1'使用默认海外地址;传'0'或不传使用国内默认地址
65
+
66
+ sgDomain: '1', // 切换海外环境代理, 默认undefined 可选:'0'|'1'。 传'1'切换海外;传'0'或不传使用国内
67
+ env: 'sg', // 切换海外环境微前端调用, 可选: 'dev' | 'test' | 'sg' | 'gray' | 'prod'
61
68
  /**
62
69
  * end - 海外特有参数
63
70
  */
@@ -65,16 +72,16 @@ document.addEventListener('DOMContentLoaded', async (event) => {
65
72
  extStatus: '1', // 👈 初始化是否处于小休状态, 非1 小休 1 在线
66
73
 
67
74
  softphoneConnectCallBack: async (data) => {
68
- console.log(await (await data.commonSoftphone.getUserAgentManager()).getAgentInfo())
69
- // const userAgent = await data.commonSoftphone.getUserAgentManager()
70
- // console.log(await userAgent.getAgentInfo())
71
- // console.log(await userAgent.requestOpenApi({
72
- // url: '/v1/agent/getAgent',
73
- // data: {
74
- // agentTag,
75
+ // if (data.status) {
76
+ // commonSoftphone = data.commonSoftphone
77
+ // const userAgentManager = await commonSoftphone.getUserAgentManager()
78
+ // const agentInfo = await userAgentManager.getAgentInfo()
79
+ // if (agentInfo.agentStatus != 1) {
80
+ // nfSoftPhoneInstance.seatsStatusChange(false)
75
81
  // }
76
- // }))
82
+ // }
77
83
  }, // 👈 签入签出回调
84
+ softphoneAutoIgnoreCallback: (data) => {console.log('softphone-auto-ignore-callback', data)}, // 👈 自动忽略回调
78
85
  softphoneCallRefreshCallBack: (data) => {console.log('softphone-call-refresh', data)}, // 👈 来电刷新来电记录列表回调
79
86
  softphoneSeatStatusChangeCallBack: (data) => {console.log('softphone-seats-status-change', data)},// 👈 小休和在线切换回调
80
87
  softphoneAcceptCallBack: (data) => {console.log('softphone-accept', data)},// 👈 接听回调
@@ -83,7 +90,15 @@ document.addEventListener('DOMContentLoaded', async (event) => {
83
90
  softphoneSessionStateChangeCallBack: (data) => {console.log('softphone-session-state-change', data)},// 👈 会话状态改变回调
84
91
  softphoneIncomingCallBack: (data) => {console.log('softphone-incoming', data)},// 👈 来电回调
85
92
  softphoneSendDtmfCallBack: (data) => {console.log('softphone-send-dtmf', data)},// 👈 转人工回调
86
- softphoneConnectRegisteredCallBack: (data) => {console.log('softphone-connect-registered', data)},// 👈 动态绑定动作完成回调(在这之后才能执行动作类总线通讯)
93
+ softphoneConnectRegisteredCallBack: async (data) => {
94
+ // console.log('softphone-connect-registered', data)
95
+ // commonSoftphone = data.commonSoftphone
96
+ // const userAgentManager = await commonSoftphone.getUserAgentManager()
97
+ // const agentInfo = await userAgentManager.getAgentInfo()
98
+ // if (agentInfo.agentStatus != 1) {
99
+ // nfSoftPhoneInstance.seatsStatusChange(false)
100
+ // }
101
+ },// 👈 动态绑定动作完成回调(在这之后才能执行动作类总线通讯)
87
102
  softphoneSignOverduedCallBack: (done) => { // 👈 注册sign过期后重新刷新sign逻辑
88
103
  const timestamp = Date.now()
89
104
  done({
@@ -92,6 +107,41 @@ document.addEventListener('DOMContentLoaded', async (event) => {
92
107
  })
93
108
  },
94
109
  });
110
+
111
+ const taskButton = document.getElementById('taskButton')
112
+ const taskCall = document.getElementById('taskCall')
113
+ const taskPhoneCall = document.getElementById('taskPhoneCall')
114
+
115
+ // 任务外呼: 先桥接手机侧,手机侧接通后,再桥接坐席
116
+ const taskPhone = async () => {
117
+ const callInfo = await (await commonSoftphone.getUserAgentManager()).requestOpenApi({ // 任务外呼
118
+ url: '/v1/task/importTaskCustomer',
119
+ data: {
120
+ "requestId": generateUUID(), // 请求id,具有唯一性,用来做请求幂等处理,一个请求id有效期10分钟。不传则不做幂等处理
121
+ "taskId": taskCall.value || 93726, // 测试任务
122
+ "failReturn": 1, // 可选值:0,1,默认1。如导入的数据中有部分验证不通过数据:0表示导入验证成功的,返回失败的数据;1表示全部数据(包括验证成功及失败的)都不导入;
123
+ "customers":[
124
+ {
125
+ "tag": "xx", // 自定义透传参数,来电坐席电话端软电话sip头可以直接获取
126
+ "clientUrl": "xx", // 自定义来电弹屏显示的第三方页面,用来展示来电具体信息
127
+ "number": taskPhoneCall.value || 15018707394, // 外呼号码
128
+ "properties": { // 自定义透传参数,可以通过[挂断回调]回调给第三方后端,前端主动获取需要调用gateway接口
129
+ "尊称": "先生",
130
+ "姓名": "张三"
131
+ }
132
+ }
133
+ ]
134
+ }
135
+ })
136
+ if (callInfo.code === 200) { // 正确响应
137
+ alert('导号成功')
138
+ } else {
139
+ alert(callInfo.message)
140
+ }
141
+ }
142
+
143
+ taskButton.addEventListener('click', taskPhone) // 任务呼叫
144
+
95
145
  })
96
146
 
97
147
  document.addEventListener('unload', () => {
@@ -80,6 +80,9 @@ class SoftphoneManager {
80
80
  softphoneAcceptCallBack: () => {
81
81
  console.log('softphone-accept')
82
82
  },
83
+ softphoneAutoIgnoreCallback: () => {
84
+ console.log('softphone-auto-ignore-callback')
85
+ },
83
86
  softphoneIgnoreCallBack: () => {
84
87
  console.log('softphone-ignore')
85
88
  },
@@ -290,12 +293,12 @@ class SoftphoneManager {
290
293
  }
291
294
  if (sgOpen === '1') {
292
295
  if (sgDomain === '1') {
293
- return 'https://seat.teleai.com/sgopenapi'
296
+ return 'https://seat.teleai.com/teleaiopenapi'
294
297
  }
295
298
  return 'https://seat.teleai.com/openapi'
296
299
  } else {
297
300
  if (sgDomain === '1') {
298
- return 'https://seat.94ai.com/sgopenapi'
301
+ return 'https://seat.94ai.com/teleaiopenapi'
299
302
  }
300
303
  return 'https://seat.94ai.com/openapi'
301
304
  }
@@ -473,17 +476,17 @@ class SoftphoneManager {
473
476
  }
474
477
 
475
478
  seatsStatusChange(status) {
476
- this.microCommunicat('softphone-connect', {
479
+ this.microCommunicat('softphone-seats-status-change', {
477
480
  status
478
481
  })
479
482
  }
480
483
 
481
484
  accept() {
482
- this.microCommunicat('softphone-connect')
485
+ this.microCommunicat('oftphone-accept')
483
486
  }
484
487
 
485
488
  ignore() {
486
- this.microCommunicat('softphone-hangup')
489
+ this.microCommunicat('softphone-ignore')
487
490
  }
488
491
 
489
492
  hangup() {
@@ -721,6 +724,9 @@ class SoftphoneManager {
721
724
  'softphone-accept': (data) => {
722
725
  props.softphoneAcceptCallBack?.(data)
723
726
  },
727
+ 'softphone-auto-ignore-callback': (data) => {
728
+ props.softphoneAutoIgnoreCallback?.(data)
729
+ },
724
730
  'softphone-seats-status-change': (data) => {
725
731
  props.softphoneSeatStatusChangeCallBack?.(data)
726
732
  },
@@ -18,3 +18,16 @@ function isDomainOrIP(str) {
18
18
  }
19
19
  return domainPattern.test(str)
20
20
  }
21
+
22
+ function generateUUID() { // Public Domain/MIT
23
+ var d = Date.now();
24
+ if (typeof performance !== 'undefined' && typeof performance.now === 'function'){
25
+ d += performance.now(); //use high-precision timer if available
26
+ }
27
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
28
+ var r = (d + Math.random() * 16) % 16 | 0;
29
+ d = Math.floor(d / 16);
30
+ return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
31
+ });
32
+ }
33
+