@94ai/softphone 5.0.15 → 5.0.17

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.
@@ -89,9 +89,32 @@ const nfSoftPhone1 = (new SoftphoneManager()).initSoftphone({ // 👈 当多实
89
89
  softphoneSessionStateChangeCallBack: (data) => {console.log('softphone-session-state-change')},// 👈 会话状态改变回调
90
90
  softphoneIncomingCallBack: (data) => {console.log('softphone-incoming')},// 👈 来电回调
91
91
  softphoneSendDtmfCallBack: (data) => {console.log('softphone-send-dtmf')},// 👈 转人工回调
92
- softphoneConnectRegisteredCallBack: (data) => {console.log('softphone-connect-registered')},// 👈 动态绑定动作完成回调(在这之后才能执行动作类总线通讯)
92
+ softphoneConnectRegisteredCallBack: async (data) => {
93
+ getAgentInfo()
94
+ console.log('softphone-connect-registered', data)
95
+ },// 👈 动态绑定动作完成回调(在这之后才能执行动作类总线通讯)
93
96
  });
94
97
 
98
+ const getAgentInfo = async () => {
99
+ const signRes = await nfSoftPhone1.requestOpenApi({
100
+ url: '/v1/agent/getAgent',
101
+ data: {
102
+ agentTag: agentTag1,
103
+ // timestamp, // 单独授权参数
104
+ // appKey: appKey1, // 单独授权参数
105
+ // sign // 单独授权参数
106
+ }
107
+ })
108
+ const secretRes = await nfSoftPhone1.requestOpenApi({
109
+ url: '/v1/agent/getAgent',
110
+ data: {
111
+ agentTag: agentTag1,
112
+ appKey: appKey1, // 单独授权参数
113
+ appSecret: appSecret1 // 单独授权参数
114
+ }
115
+ })
116
+ console.log(signRes, secretRes)
117
+ }
95
118
  // setTimeout(() => {
96
119
  // nfSoftPhone1.destroy()
97
120
  // }, 3000)
@@ -55,6 +55,8 @@ class SoftphoneManager {
55
55
 
56
56
  instanceMap: {},
57
57
 
58
+ requestOpenApiCallBackMap: {},
59
+
58
60
  softphoneConnectCallBack: () => {console.log('softphone-connect')},
59
61
  softphoneCallRefreshCallBack: () => {console.log('softphone-call-refresh')},
60
62
  softphoneSeatStatusChangeCallBack: () => {console.log('softphone-seats-status-change')},
@@ -72,6 +74,23 @@ class SoftphoneManager {
72
74
  sign: undefined
73
75
  })
74
76
  },
77
+ softphoneRequestOpenApiCallBack: async (data) => {
78
+ // data: {
79
+ // origin
80
+ // ancestorOrigin
81
+ // destinationOrigin
82
+ // type: 'softphone-request-open-api'
83
+ // uuid
84
+ // code
85
+ // message
86
+ // data: {
87
+ // type: 'manual',
88
+ // param,
89
+ // res
90
+ // }
91
+ // }
92
+ await this.option.requestOpenApiCallBackMap[data.uuid](data)
93
+ },
75
94
  }
76
95
 
77
96
 
@@ -166,6 +185,8 @@ class SoftphoneManager {
166
185
  this.option.softphoneSendDtmfCallBack?.(data)
167
186
  } else if (data.type === 'softphone-connect-registered') {
168
187
  this.option.softphoneConnectRegisteredCallBack?.(data)
188
+ } else if (data.type === 'softphone-request-open-api') {
189
+ this.option.softphoneRequestOpenApiCallBack?.(data)
169
190
  } else if (data.type === 'softphone-sign-overdued') {
170
191
  const done = (data) => {
171
192
  const {
@@ -411,7 +432,7 @@ class SoftphoneManager {
411
432
  return this
412
433
  }
413
434
 
414
- postMessageCommunicate = (type, status) => {
435
+ postMessageCommunicate = (type, status, param) => {
415
436
  const iframe = this.getSoftphoneDomElement('.nf-softphone-iframe')
416
437
  if (iframe) {
417
438
  iframe.contentWindow.postMessage(JSON.stringify({
@@ -421,7 +442,8 @@ class SoftphoneManager {
421
442
  type,
422
443
  data: {
423
444
  status,
424
- type: 'manual'
445
+ type: 'manual',
446
+ param,
425
447
  }
426
448
  }), '*')
427
449
  }
@@ -451,6 +473,37 @@ class SoftphoneManager {
451
473
  sendDtmf = () => {
452
474
  this.postMessageCommunicate('softphone-send-dtmf')
453
475
  }
476
+ requestOpenApi = async (param) => {
477
+ return new Promise(((resolve, reject) => {
478
+ const uuid = generateUUID()
479
+ this.option.requestOpenApiCallBackMap[uuid] = async (result) => {
480
+ // result: {
481
+ // origin
482
+ // ancestorOrigin
483
+ // destinationOrigin
484
+ // type: 'softphone-request-open-api'
485
+ // uuid
486
+ // code: 200,
487
+ // message: '成功',
488
+ // data: {
489
+ // type: 'manual',
490
+ // param: {}, // 请求参数
491
+ // res // 响应结果
492
+ // }
493
+ // }
494
+ if (result.code === 200) {
495
+ resolve(result.data.res)
496
+ } else {
497
+ reject(result)
498
+ }
499
+ delete this.option.requestOpenApiCallBackMap[uuid]
500
+ }
501
+ this.postMessageCommunicate('softphone-request-open-api', undefined, {
502
+ uuid,
503
+ param
504
+ })
505
+ }))
506
+ }
454
507
 
455
508
  removeTimer = () => {
456
509
  clearTimeout(this.timer)
@@ -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>
@@ -180,9 +184,8 @@
180
184
  * - 相当于: userAgentManager.requestOpenApi({
181
185
  * url: '/v1/agent/updateAgentStatus',
182
186
  * data: {
183
- * agentTag: 'xxx',
184
187
  * agentId: 'xxx',
185
- * agentStatus: 3, // 3: 小休 1: 在线
188
+ * agentStatus: 3, // 3: 小休 1: 在线 0: 离线
186
189
  * }
187
190
  * })
188
191
  * - example3:获取当前坐席信息,也可以直接使用`const angentInfo = await userAgentManager.getAgentInfo()`
@@ -283,7 +286,10 @@ document.addEventListener('DOMContentLoaded', async (event) => {
283
286
  const hangUp = document.getElementById('hangUp')
284
287
  const connectToServer = document.getElementById('connectToServer')
285
288
  const call = document.getElementById('call')
289
+ const taskCall = document.getElementById('taskCall')
290
+ const taskPhoneCall = document.getElementById('taskPhoneCall')
286
291
  const callButton = document.getElementById('callButton')
292
+ const taskButton = document.getElementById('taskButton')
287
293
  const nap = document.getElementById('nap')
288
294
  const chatInfo = document.getElementById('chatInfo')
289
295
  const online = document.getElementById('online')
@@ -315,10 +321,9 @@ document.addEventListener('DOMContentLoaded', async (event) => {
315
321
  // appSecret: '9fb4aac7b1dbfbb21696bcd7a30cb382', // 测试线 企业维度定位
316
322
 
317
323
  /**
318
- * 1. 如果是海外环境新增这三个参数
324
+ * 1. 如果是海外环境新增这两个参数
319
325
  * sgOpen: '1',
320
326
  * sg: '1',
321
- * openBaseUrl: '1',
322
327
  * 2. 为了appSecret安全性,通过sign初始化,记得注册过期回调刷新sign
323
328
  * sign: 'xxx', // 代替appSecret
324
329
  * timestamp: 'xxx',
@@ -338,30 +343,59 @@ document.addEventListener('DOMContentLoaded', async (event) => {
338
343
  * }
339
344
  * },
340
345
  */
346
+
347
+ const agentTag = '15018707394' // 国内生产线 坐席维度定位
348
+ const appKey = '032d44009bff1752' // 国内生产线 企业维度定位
349
+ const appSecret = '4c7304c94c5e8725613516d4d6db679b' // 国内生产线 企业维度定位
350
+ // const agentId = '6897' // 海外生产线 坐席维度定位
351
+ // const appKey = '1f3a67d0affd2699' // 海外生产线 企业维度定位
352
+ // const appSecret = 'a62ac746d916e1da5f645783c587bae6' // 海外生产线 企业维度定位
353
+ const timestamp = Date.now()
354
+ const sign = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA1(appKey + timestamp, appSecret))
355
+
341
356
  const userAgentManager = UserAgentFactory.getUserAgentManager({
342
- // sgOpen: '1',
343
- // sg: '1',
344
- // openBaseUrl: '1',
357
+ // optionsPingAttempts: 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
+ appSecret,
375
+ // timestamp,
376
+ // sign,
377
+ // signOverdued() {
378
+ // console.log('==sign已过期==')
379
+ // const timestamp = Date.now()
380
+ // const sign = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA1(appKey + timestamp, appSecret))
381
+ // console.log('==重新生成sign==', sign)
382
+ // return {
383
+ // timestamp,
384
+ // sign,
385
+ // }
386
+ // },
349
387
  // logLevel: 'debug', // 日志等级,默认error
350
- openXhrIntercept(xhr) {
388
+ openXhrIntercept(xhr) { // 设置接口语言
351
389
  // xhr.setRequestHeader('language', 'es-ES')
352
390
  xhr.setRequestHeader('language', 'zh-CN')
353
391
  // xhr.setRequestHeader('language', 'en-US')
354
392
  },
355
- agentTag: '15018707394', // 国内生产线 坐席维度定位
356
- appKey: '032d44009bff1752', // 国内生产线 企业维度定位
357
- appSecret: '4c7304c94c5e8725613516d4d6db679b', // 国内生产线 企业维度定位 这里直接使用appSecret做演示
358
-
359
393
  // refreshSpeekVolumn(value) { // 当来电接通时,实时查看坐席说话的音量实际传送到给对方的音量大小
360
394
  // volumn.innerText = value
361
395
  // },
362
- // refreshRequirementCheck(value) { // 权限网络检测
363
- // browserSoftphoneEnv.innerText = JSON.stringify(value, null, 2)
364
- // },
396
+ refreshRequirementCheck(value) { // 权限网络检测
397
+ browserSoftphoneEnv.innerText = JSON.stringify(value, null, 2)
398
+ },
365
399
  // refreshChat(info) { // 刷新会话记录
366
400
  // chatInfo.innerText = JSON.stringify(info, null, 2)
367
401
  // },
@@ -470,29 +504,33 @@ document.addEventListener('DOMContentLoaded', async (event) => {
470
504
 
471
505
  /** 方式二:extensionNumber + extPassword + wsProtocol + wsRegisterAddress 获取软电话链接代理实例 */
472
506
  // 即直接通过【分机号】和【分机密码】以及【外呼服务器地址】实现软电话的直接签入
473
- // 九四的同学:测试环境不能访问openAPI,可以采用决策系统内部接口获取分机信息接入外呼服务器
474
- // 生产环境如果采用分机维度的分机信息可以通过agentTag调用openapi获取
507
+ // 下述分机信息可以通过agentTag/agentId调用openapi获取
475
508
  // const extensionNumber = '2839' // 测试线 分机账号
476
509
  // const extPassword = 'zjh13542240708' // 测试线 分机密码
477
510
  // const wsProtocol = 'ws' // 测试线外呼服务器地址协议
478
511
  // const wsRegisterAddress = '192.168.31.239:5066' // 测试线 外呼服务器地址
512
+ //
479
513
  // const sipServerHost = `sip:${extensionNumber}@${wsRegisterAddress}` // fs地址
480
514
  // const wsAddress = `${wsProtocol}://${wsRegisterAddress}` // socket地址
481
515
 
516
+
482
517
  // const extensionNumber = '2510' // 生产线 分机账号
483
518
  // const extPassword = 'zengrongzhi123' // 生产线 分机密码
484
519
  // const wsProtocol = 'ws' // 生产线 外呼服务器地址协议
485
520
  // const wsRegisterAddress = '192.168.31.239:5066' // 生产线 外呼服务器地址
521
+ //
486
522
  // const sipServerHost = `sip:${extensionNumber}@${wsRegisterAddress}` // fs地址
487
523
  // const wsAddress = `${wsProtocol}://${wsRegisterAddress}` // socket地址
488
524
 
525
+
489
526
  // const extensionNumber = '1001' // 生产线 分机账号
490
527
  // const extPassword = '946666' // 生产线 分机密码
491
528
  // const wsProtocol = 'ws' // 生产线 外呼服务器地址协议
492
529
  // const wsRegisterAddress = '192.168.0.92:5066' // 生产线 外呼服务器地址
530
+ //
493
531
  // const sipServerHost = `sip:${extensionNumber}@${wsRegisterAddress}` // fs地址
494
532
  // const wsAddress = `${wsProtocol}://${wsRegisterAddress}` // socket地址
495
- //
533
+
496
534
  // const userAgentManager = UserAgentFactory.getUserAgentManager({
497
535
  // authorizationPassword: extPassword, // 分机密码
498
536
  // authorizationUsername: extensionNumber, // 分机账号
@@ -504,25 +542,18 @@ document.addEventListener('DOMContentLoaded', async (event) => {
504
542
  // // viaHost, // fp.umd.min.js生成的唯一值,用来配查呼叫问题,可以不传,内部会自动生成
505
543
  // contactName: extensionNumber, // sip协议要求,同分机账号即可,注意类型为string, 不传默认同分机账号
506
544
  // 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
545
+ // reClusterRegisterTimeout: 4000,
546
+ // reClusterConnectTimeout: 4000,
547
+ // refreshSpeekVolumn(value) { // 当来电接通时,实时查看坐席说话的音量实际传送到给对方的音量大小
548
+ // volumn.innerText = value
549
+ // },
550
+ // refreshRequirementCheck(value) { // 权限网络检测
551
+ // browserSoftphoneEnv.innerText = JSON.stringify(value, null, 2)
552
+ // },
522
553
  // })
523
554
 
524
555
  /**
525
- * 获取坐席当前状态信息(注意牵扯到openAPI的信息需要angentId,即方式一。如果通过方式二需要手动使用userAgentManager.requestOpenApi获取,即上述example3
556
+ * 获取坐席当前状态信息(注意牵扯到openAPI的方法需要使用方式一初始化软电话实例。如果通过方式二需要手动使用userAgentManager.requestOpenApi获取,即上述example3,参看index-open.html的278行 getAgentInfo
526
557
  */
527
558
  const angentInfo = await userAgentManager.getAgentInfo()
528
559
  if (angentInfo.code === 200) { // 正确响应
@@ -560,9 +591,16 @@ document.addEventListener('DOMContentLoaded', async (event) => {
560
591
  // taskId: userAgentManager.businessAttribute.taskId, // 如果不是任务外呼不用传
561
592
  // })
562
593
  // console.log(info, '========')
563
- setTimeout(() => {
564
- acceptInvite()
565
- }, 0)
594
+ if (userAgentManager.businessAttribute.voiceType == 4) { // 主动外呼
595
+ setTimeout(() => {
596
+ acceptInvite()
597
+ }, 0)
598
+ } else { // 非主动导号
599
+ alert('坐席来电中,确定接听')
600
+ setTimeout(() => {
601
+ acceptInvite()
602
+ }, 0)
603
+ }
566
604
  console.log(userAgentManager.getSenders)
567
605
  console.log(userAgentManager.businessAttribute)
568
606
  phoneRings() // 播放模拟来电响铃
@@ -841,27 +879,69 @@ document.addEventListener('DOMContentLoaded', async (event) => {
841
879
  * })
842
880
  *
843
881
  */
844
- const callPhone = async () => {
845
- // const callInfo = await userAgentManager.callNumber(call.value) // 👈 一键
846
- const callInfo = await userAgentManager.requestOpenApi({ // 主动外呼
847
- url: '/v1/task/importAgentCustomer',
848
- data: {
849
- agentTag: '15018707394',
850
- callType: 1001,
851
- customers: [{
852
- tag: '测试tag',
853
- number: 18617381945
854
- }]
855
- }
856
- })
882
+
883
+ function generateUUID() { // Public Domain/MIT
884
+ var d = Date.now();
885
+ if (typeof performance !== 'undefined' && typeof performance.now === 'function'){
886
+ d += performance.now(); //use high-precision timer if available
887
+ }
888
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
889
+ var r = (d + Math.random() * 16) % 16 | 0;
890
+ d = Math.floor(d / 16);
891
+ return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
892
+ });
893
+ }
894
+
895
+ // 任务外呼: 先桥接手机侧,手机侧接通后,再桥接坐席
896
+ const taskPhone = async () => {
897
+ const callInfo = await userAgentManager.requestOpenApi({ // 任务外呼
898
+ url: '/v1/task/importTaskCustomer',
899
+ data: {
900
+ "requestId": generateUUID(), // 请求id,具有唯一性,用来做请求幂等处理,一个请求id有效期10分钟。不传则不做幂等处理
901
+ "taskId": taskCall.value || 93726, // 测试任务
902
+ "failReturn": 1, // 可选值:0,1,默认1。如导入的数据中有部分验证不通过数据:0表示导入验证成功的,返回失败的数据;1表示全部数据(包括验证成功及失败的)都不导入;
903
+ "customers":[
904
+ {
905
+ "tag": "xx", // 自定义透传参数,来电坐席电话端软电话sip头可以直接获取
906
+ "clientUrl": "xx", // 自定义来电弹屏显示的第三方页面,用来展示来电具体信息
907
+ "number": taskPhoneCall.value || 15018707394, // 外呼号码
908
+ "properties": { // 自定义透传参数,可以通过[挂断回调]回调给第三方后端,前端主动获取需要调用gateway接口
909
+ "尊称": "先生",
910
+ "姓名": "张三"
911
+ }
912
+ }
913
+ ]
914
+ }
915
+ })
857
916
  if (callInfo.code === 200) { // 正确响应
858
- alert('呼叫成功')
917
+ alert('导号成功')
859
918
  } else {
860
919
  alert(callInfo.message)
861
920
  }
921
+ }
922
+
923
+ // 主动外呼: 先桥接坐席,坐席接通后, 再桥接手机侧
924
+ const callPhone = async () => {
862
925
  // await userAgentManager.invite({
863
- // extension: call.value
926
+ // extension: call.value // 分机号外呼
864
927
  // })
928
+ const callInfo = await userAgentManager.callNumber(call.value || 18617381945) // 👈 一键手机号外呼
929
+ // const callInfo = await userAgentManager.requestOpenApi({ // 主动手机号外呼
930
+ // url: '/v1/task/importAgentCustomer',
931
+ // data: {
932
+ // agentTag: '15018707394',
933
+ // callType: 1001,
934
+ // customers: [{
935
+ // tag: '测试tag',
936
+ // number: call.value || 18617381945
937
+ // }]
938
+ // }
939
+ // })
940
+ if (callInfo.code === 200) { // 正确响应
941
+ alert('呼叫成功')
942
+ } else {
943
+ alert(callInfo.message)
944
+ }
865
945
  }
866
946
 
867
947
  /**
@@ -910,7 +990,8 @@ document.addEventListener('DOMContentLoaded', async (event) => {
910
990
  remoteSoundAccess.addEventListener('click', muteLocalAudio) // 关闭本地声音发送
911
991
  localSoundDisconnection.addEventListener('click', unMuteRemoteAudio) // 打开远端声音接收
912
992
  remoteSoundDisconnection.addEventListener('click', muteRemoteAudio) // 关闭远端声音接收
913
- callButton.addEventListener('click', callPhone) // 呼叫
993
+ callButton.addEventListener('click', callPhone) // 手动呼叫
994
+ taskButton.addEventListener('click', taskPhone) // 任务呼叫
914
995
  nap.addEventListener('click', toggleNap) // 切换坐席进入小休
915
996
  online.addEventListener('click', toggleOnline) // 切换坐席进入在线
916
997
  check.addEventListener('click', envCheck) // 执行软电话必备的权限&网络环境检测
@@ -0,0 +1,168 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport"
6
+ content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
8
+ <title>microphone</title>
9
+ </head>
10
+ <body>
11
+ <style>
12
+ #dragable {
13
+ padding: 20px 0;
14
+ background: pink;
15
+ width: 660px!important;
16
+ height: auto!important;
17
+ transform: none!important;
18
+ cursor: move;
19
+ }
20
+ </style>
21
+
22
+ <div id="dragable">
23
+ <div style="min-width: 700px;" id="softphone-container"></div> <!-- 👈 软电话容器 -->
24
+ <br/>
25
+ <button id="taskButton" style="margin-left: 20px">任务呼叫</button>
26
+ : <input id="taskCall" placeholder="请输入任务id, 空值用测试任务" style="width: 180px"/> <input id="taskPhoneCall" placeholder="请输入手机号, 空值用测试手机号" style="width: 180px"/>
27
+ </div>
28
+
29
+ </body>
30
+ <script src="./util.js"></script>
31
+ <script src="./qiankun.js"></script>
32
+ <script src="./wujie.js"></script>
33
+ <script src="./CryptoJS.js"></script>
34
+ <script src="./microphone.js"></script>
35
+ <script src="./draggable.js"></script>
36
+ <script>
37
+ let nfSoftPhoneInstance
38
+ document.addEventListener('DOMContentLoaded', async (event) => {
39
+ new window.Draggable(document.getElementById('dragable'))
40
+
41
+ let sign = ''
42
+ const timestamp = Date.now()
43
+ // 国内
44
+ // const agentTag = 'zoujh-test'
45
+ // const appKey = '032d44009bff1752'
46
+ // const appSecret = '4c7304c94c5e8725613516d4d6db679b'
47
+ // 海外
48
+ const agentId = '2357'
49
+ const appKey = 'a52e61f0d9ff1527'
50
+ const appSecret = '7ed1d78fbe214ba8b8e6a2dc9c6955aa'
51
+
52
+ const str = appKey + timestamp
53
+ const sha1 = CryptoJS.HmacSHA1(str, appSecret)
54
+ sign = CryptoJS.enc.Base64.stringify(sha1)
55
+
56
+ let commonSoftphone // 软电话sdk实例
57
+
58
+ /**
59
+ 👈 拿到实例后可以手动触发软电话实例的各种动作,如签入,签出,接听,忽略,挂断等等,注意这个实例不是软电话实例,是链接软电话通讯的实例
60
+ */
61
+ nfSoftPhoneInstance = softphoneManager.initSoftphone({
62
+ el: document.getElementById('softphone-container'), // 👈 软电话容器
63
+ ancestorOrigin: 'nf-softphone1', // origin,ancestorOrigin,destinationOrigin具体含义参见下文,如果是单实例,可以写死origin=ai-softphone&destinationOrigin=nf-softphone&ancestorOrigin=nf-softphone
64
+ destinationOrigin: 'nf-softphone1',
65
+ name: 'nf-softphone1',
66
+
67
+ muteShow: '0', // 👈 屏蔽静音功能
68
+
69
+ // agentTag, // 👈 坐席唯一标志
70
+ agentId, // 👈 坐席唯一标志
71
+ appKey, // 👈 企业appKey
72
+ sign, // 👈 授权sign
73
+ timestamp,
74
+
75
+ /**
76
+ * start - 海外特有参数
77
+ */
78
+ sgGateway: '1', // 设置gatewayApi前缀调用地址, 默认undefined, 可选:'0'|'1'|string。示例: 'https://gateway.xxx.com'。 传'1'使用默认海外地址;传'0'或不传使用国内默认地址
79
+ sgBase: '1', // 设置baseApi前缀调用地址, 默认undefined, 可选:'0'|'1'|string。 示例: 'https://www.xxx.com/api'。 传'1'使用默认海外地址;传'0'或不传使用国内默认地址
80
+ sgOpen: '1', // 设置openApi前缀调用地址, 默认undefined, 可选:'0'|'1'|string。示例: 'https://www.xxx.com/openapi'。 传'1'使用默认海外地址;传'0'或不传使用国内默认地址
81
+
82
+ sgDomain: '1', // 切换海外环境代理, 默认undefined 可选:'0'|'1'。 传'1'切换海外;传'0'或不传使用国内
83
+ env: 'sg', // 切换海外环境微前端调用, 可选: 'dev' | 'test' | 'sg' | 'gray' | 'prod'
84
+ /**
85
+ * end - 海外特有参数
86
+ */
87
+
88
+ extStatus: '1', // 👈 初始化是否处于小休状态, 非1 小休 1 在线
89
+
90
+ softphoneConnectCallBack: async (data) => {
91
+ // if (data.status) {
92
+ // commonSoftphone = data.commonSoftphone
93
+ // const userAgentManager = await commonSoftphone.getUserAgentManager()
94
+ // const agentInfo = await userAgentManager.getAgentInfo()
95
+ // if (agentInfo.agentStatus != 1) {
96
+ // nfSoftPhoneInstance.seatsStatusChange(false)
97
+ // }
98
+ // }
99
+ }, // 👈 签入签出回调
100
+ softphoneAutoIgnoreCallback: (data) => {console.log('softphone-auto-ignore-callback', data)}, // 👈 自动忽略回调
101
+ softphoneCallRefreshCallBack: (data) => {console.log('softphone-call-refresh', data)}, // 👈 来电刷新来电记录列表回调
102
+ softphoneSeatStatusChangeCallBack: (data) => {console.log('softphone-seats-status-change', data)},// 👈 小休和在线切换回调
103
+ softphoneAcceptCallBack: (data) => {console.log('softphone-accept', data)},// 👈 接听回调
104
+ softphoneIgnoreCallBack: (data) => {console.log('softphone-ignore', data)},// 👈 忽略回调
105
+ softphoneHangupCallBack: (data) => {console.log('softphone-hangup', data)},// 👈 挂断回调
106
+ softphoneSessionStateChangeCallBack: (data) => {console.log('softphone-session-state-change', data)},// 👈 会话状态改变回调
107
+ softphoneIncomingCallBack: (data) => {console.log('softphone-incoming', data)},// 👈 来电回调
108
+ softphoneSendDtmfCallBack: (data) => {console.log('softphone-send-dtmf', data)},// 👈 转人工回调
109
+ softphoneConnectRegisteredCallBack: async (data) => {
110
+ // console.log('softphone-connect-registered', data)
111
+ // commonSoftphone = data.commonSoftphone
112
+ // const userAgentManager = await commonSoftphone.getUserAgentManager()
113
+ // const agentInfo = await userAgentManager.getAgentInfo()
114
+ // if (agentInfo.agentStatus != 1) {
115
+ // nfSoftPhoneInstance.seatsStatusChange(false)
116
+ // }
117
+ },// 👈 动态绑定动作完成回调(在这之后才能执行动作类总线通讯)
118
+ softphoneSignOverduedCallBack: (done) => { // 👈 注册sign过期后重新刷新sign逻辑
119
+ const timestamp = Date.now()
120
+ done({
121
+ timestamp,
122
+ sign: window.CryptoJS.enc.Base64.stringify(window.CryptoJS.HmacSHA1(appKey + timestamp, appSecret))
123
+ })
124
+ },
125
+ });
126
+
127
+ const taskButton = document.getElementById('taskButton')
128
+ const taskCall = document.getElementById('taskCall')
129
+ const taskPhoneCall = document.getElementById('taskPhoneCall')
130
+
131
+ // 任务外呼: 先桥接手机侧,手机侧接通后,再桥接坐席
132
+ const taskPhone = async () => {
133
+ const callInfo = await (await commonSoftphone.getUserAgentManager()).requestOpenApi({ // 任务外呼
134
+ url: '/v1/task/importTaskCustomer',
135
+ data: {
136
+ "requestId": generateUUID(), // 请求id,具有唯一性,用来做请求幂等处理,一个请求id有效期10分钟。不传则不做幂等处理
137
+ "taskId": taskCall.value || 93726, // 测试任务
138
+ "failReturn": 1, // 可选值:0,1,默认1。如导入的数据中有部分验证不通过数据:0表示导入验证成功的,返回失败的数据;1表示全部数据(包括验证成功及失败的)都不导入;
139
+ "customers":[
140
+ {
141
+ "tag": "xx", // 自定义透传参数,来电坐席电话端软电话sip头可以直接获取
142
+ "clientUrl": "xx", // 自定义来电弹屏显示的第三方页面,用来展示来电具体信息
143
+ "number": taskPhoneCall.value || 15018707394, // 外呼号码
144
+ "properties": { // 自定义透传参数,可以通过[挂断回调]回调给第三方后端,前端主动获取需要调用gateway接口
145
+ "尊称": "先生",
146
+ "姓名": "张三"
147
+ }
148
+ }
149
+ ]
150
+ }
151
+ })
152
+ if (callInfo.code === 200) { // 正确响应
153
+ alert('导号成功')
154
+ } else {
155
+ alert(callInfo.message)
156
+ }
157
+ }
158
+
159
+ taskButton.addEventListener('click', taskPhone) // 任务呼叫
160
+
161
+ })
162
+
163
+ document.addEventListener('unload', () => {
164
+ nfSoftPhoneInstance.destory()
165
+ })
166
+ </script>
167
+
168
+ </html>