@94ai/softphone 6.0.14 → 6.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.
- package/LICENSE +21 -0
- package/README.md +1296 -943
- package/docs/AI-/350/207/252/345/256/232/344/271/211/350/275/257/347/224/265/350/257/235UI.md +28 -0
- package/docs/OPENAPI-MAPPING.md +61 -0
- package/docs/examples/custom-softphone.html +241 -0
- package/docs/images/94ai-logo.png +0 -0
- package/docs/images/contributors.svg +10 -0
- package/docs/images/microsip.png +0 -0
- package/docs/images/softphone-mobile.png +0 -0
- package/docs/images/softphone-popup.png +0 -0
- package/docs/images/softphone.svg +4 -0
- package/docs/images/yuque/03c05dfbcb8c359c3cfc.png +0 -0
- package/docs/images/yuque/046d6ad35245a245d900.png +0 -0
- package/docs/images/yuque/05e55a7e84dc3ad7f7b5.png +0 -0
- package/docs/images/yuque/08dbaee985daf7bd80e1.png +0 -0
- package/docs/images/yuque/1a73f908d26531cb613f.png +0 -0
- package/docs/images/yuque/1e53410a10e7abcf888f.png +0 -0
- package/docs/images/yuque/201324fd889d7ad22c63.jpg +0 -0
- package/docs/images/yuque/275638b1afe7218d1d69.png +0 -0
- package/docs/images/yuque/2802a63d8f15152b691d.png +0 -0
- package/docs/images/yuque/2c4608987908f772856b.png +0 -0
- package/docs/images/yuque/2c92f4e940bb45cfb779.png +0 -0
- package/docs/images/yuque/2e09de59428daf4f11be.jpg +0 -0
- package/docs/images/yuque/3cebc274ef4d8d02bdb8.png +0 -0
- package/docs/images/yuque/3eb49f422b6f9cdcefb0.png +0 -0
- package/docs/images/yuque/461eead8c9b99e41c1b4.png +0 -0
- package/docs/images/yuque/497df99be4d4f0ec7fde.png +0 -0
- package/docs/images/yuque/4def3f4b4f364ebeabf9.png +0 -0
- package/docs/images/yuque/4ff387aa201250edc3aa.png +0 -0
- package/docs/images/yuque/5170f9c978fb25780653.jpg +0 -0
- package/docs/images/yuque/519d177dbd38f6b752c4.png +0 -0
- package/docs/images/yuque/51dedf650db36fc0124f.png +0 -0
- package/docs/images/yuque/552e7bd0217184f8028d.png +0 -0
- package/docs/images/yuque/659f134f173ae9c2fb50.png +0 -0
- package/docs/images/yuque/6a414dd2cfad842e335c.png +0 -0
- package/docs/images/yuque/701462e7099510885d11.png +0 -0
- package/docs/images/yuque/70c9913a55c3ab8a946d.png +0 -0
- package/docs/images/yuque/7538f81d20c5272a6ce9.png +0 -0
- package/docs/images/yuque/7a0aa195f8ddf88e0f7e.png +0 -0
- package/docs/images/yuque/7bc10835ba5f9ef0cebe.png +0 -0
- package/docs/images/yuque/7efc7bacfaa193c066f6.png +0 -0
- package/docs/images/yuque/86e11ecd398addabc39b.jpg +0 -0
- package/docs/images/yuque/90307badefd296c40a00.png +0 -0
- package/docs/images/yuque/90895ff1b795d42a1692.png +0 -0
- package/docs/images/yuque/97f32b953da0b80b2c4a.png +0 -0
- package/docs/images/yuque/9e3483efaac2a73df37c.png +0 -0
- package/docs/images/yuque/a58edffd8e668b14f4e0.png +0 -0
- package/docs/images/yuque/a888d6ff229df32753fc.png +0 -0
- package/docs/images/yuque/af38a5a6c230ddbcc98c.png +0 -0
- package/docs/images/yuque/b296f519aa91410139ca.jpg +0 -0
- package/docs/images/yuque/b5483e45d6ff9993d88e.png +0 -0
- package/docs/images/yuque/bba6e984e627166b5254.png +0 -0
- package/docs/images/yuque/bc4a5bb369f4357c4401.png +0 -0
- package/docs/images/yuque/bca6eb9eb6a02f329133.png +0 -0
- package/docs/images/yuque/bce249ad8a660edd037b.png +0 -0
- package/docs/images/yuque/c53411e9b69bde11a293.png +0 -0
- package/docs/images/yuque/ca346e914019bc60f095.png +0 -0
- package/docs/images/yuque/cdd3ed74fabf95c2657d.png +0 -0
- package/docs/images/yuque/cfae4c35dd1916611a20.png +0 -0
- package/docs/images/yuque/d56994dbba55ab31ef71.png +0 -0
- package/docs/images/yuque/d9e61a80576c7e8035e0.png +0 -0
- package/docs/images/yuque/db5935ab31217115370a.png +0 -0
- package/docs/images/yuque/e0c6a704f7e57c88f495.png +0 -0
- package/docs/images/yuque/e7c7a3b34435a6db7baa.png +0 -0
- package/docs/images/yuque/f13ca1087454deb734f4.png +0 -0
- package/docs/images/yuque/f68eb1be9c8c83677941.png +0 -0
- package/docs/images/yuque/f970ac96dc58f97c4505.png +0 -0
- package/docs/images/yuque/fed2352c4bb746c231fe.png +0 -0
- package/lib/index.d.ts +1853 -5
- package/lib/softphone.cjs.min.cjs +1 -1
- package/lib/softphone.esm-bundler.min.mjs +1 -1
- package/lib/softphone.umd.min.js +2 -2
- package/package.json +114 -90
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# 自定义软电话 UI 开发任务
|
|
2
|
+
|
|
3
|
+
使用 @94ai/softphone 在当前项目实现自定义软电话组件,沿用项目技术栈与视觉规范。参考下方完整脱敏 HTML,完成实际代码与接入示例。
|
|
4
|
+
|
|
5
|
+
## API 参考
|
|
6
|
+
|
|
7
|
+
以项目安装版本的 TypeScript 类型声明为准,不编造方法或回调。需要补充说明时查阅:
|
|
8
|
+
- SDK 导读:https://oss.xccjh.top/sdk/llms/readme.txt —— 软电话操作、回调、保活和排障,Markdown 纯文本。
|
|
9
|
+
- OpenAPI 使用指南:https://oss.xccjh.top/sdk/llms/openapi.txt —— 授权参数、凭证刷新及业务接口入参与返回值,Markdown 纯文本。
|
|
10
|
+
- 接口对应表:https://oss.xccjh.top/sdk/llms/mapping.txt —— SDK 方法与 OpenAPI 路径、章节编号及地址配置的对应关系,Markdown 纯文本。
|
|
11
|
+
|
|
12
|
+
## 接入要点
|
|
13
|
+
|
|
14
|
+
- 流程:初始化 → 获取坐席状态 → 设置在线 → SIP 签入 → 外呼/来电 → 接听/忽略/挂断。分别维护连接、坐席和会话状态;外呼提交成功不代表通话建立。
|
|
15
|
+
- UserAgentFactory.newUserAgentManager 创建实例;getAgentInfo 查询坐席;toggleNap(false/true) 切换在线/小休;prepareUserAgent(config, event) 签入。onInvite 接收来电,invitation.stateChange 监听 SessionState.Established/Terminated。
|
|
16
|
+
- 通话控制:acceptInvite、ignoreInvite、hangUpInvite、sendStarDtmf。外呼使用 callNumber 或 openApi.importAgentCustomer/importTaskCustomer。按状态禁用按钮并防止重复提交。
|
|
17
|
+
- 音频:接通后将 getStream() 绑定到 audio.srcObject;处理播放被阻止。muteLocalAudio/unMuteLocalAudio 控制麦克风,muteRemoteAudio/unMuteRemoteAudio 控制远端声音。音量与会话记录回调参考示例。
|
|
18
|
+
- 授权:坐席系统 token 与 OpenAPI sign/accessToken 用途不同。支持凭证过期刷新,使用生成凭证时的配套时间戳。手动更新使用 refreshSign(sign, timestamp)、refreshAccessToken(accessToken, accessTokenTimestamp)、refreshToken(token, tokenTimestamp)。
|
|
19
|
+
- 区域与地址:sg/sgOpen 配置实例环境,teleai 用于相关工厂方法;openBaseUrl、openApiGatewayUrl、openGatewayUrl 分别对应 OpenAPI、OpenAPI 网关、坐席系统网关,按类型与文档配置。
|
|
20
|
+
- 卸载或更换坐席时 dispose(),清理监听、计时器和音频资源,阻止旧实例的异步回调更新新界面。
|
|
21
|
+
|
|
22
|
+
## 配置与验证
|
|
23
|
+
|
|
24
|
+
凭证由运行时输入或业务授权服务提供,不硬编码、不记录到日志或存储。示例使用 YOUR_APP_KEY、appSecret: '***'、accessToken: '***' 等占位值,不包含真实密钥、token 或测试号码。
|
|
25
|
+
|
|
26
|
+
通话需要 HTTPS/localhost 和麦克风权限。使用模拟 SDK 验证初始化失败、来电、接听、挂断、静音、过期刷新及卸载清理;浏览器测试使用无头浏览器,真实外呼需另行授权。
|
|
27
|
+
|
|
28
|
+
交付可接入的组件、使用示例与验证结果,明确仍需业务方配置的内容。
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# SDK API 与 OpenAPI 接口对应表
|
|
2
|
+
|
|
3
|
+
来源:API接口文档(全).docx,SHA256:`dc5dc3202e97e0539bd69aa8b5fa5f042b163c1e50c05c746c88edc6f8590e20`。覆盖第二至第七章,共 41 个主动调用接口、9 类服务器回调。
|
|
4
|
+
|
|
5
|
+
所有主动调用接口为 POST,入口为 `sdk.openApi`;完整入参和出参见 [SDK·openAPI使用指南](./SDK·openAPI使用指南.md)。
|
|
6
|
+
|
|
7
|
+
| 章节 | SDK API 或回调类型 | OpenAPI 路径 | 地址配置 | 说明 |
|
|
8
|
+
| --- | --- | --- | --- | --- |
|
|
9
|
+
| 2.1.1 | `sdk.openApi.importTaskCustomer()` | `/v1/task/importTaskCustomer` | `openBaseUrl` | 2.1.1 AI批量任务导入号码接口 |
|
|
10
|
+
| 2.1.2 | `sdk.openApi.importAgentCustomer()` | `/v1/task/importAgentCustomer` | `openBaseUrl` | 2.1.2 坐席外呼导入号码接口 |
|
|
11
|
+
| 2.2.1 | `sdk.openApi.taskCallList()` | `/v1/task/taskCallList` | `openBaseUrl` | 2.2.1 AI批量任务查询外呼记录接口 |
|
|
12
|
+
| 2.2.2 | `sdk.openApi.agentCallList()` | `/v1/task/agentCallList` | `openBaseUrl` | 2.2.2 坐席外呼查询外呼记录接口 |
|
|
13
|
+
| 2.3 | `sdk.openApi.taskCallChats()` | `/v1/task/taskCallChats` | `openBaseUrl` | 2.3 查询聊天记录接口 |
|
|
14
|
+
| 2.4 | 不封装 | 客户服务器回调地址或未提供 | — | 2.4 查询任务列表接口;使用 2.14 taskList 替代 |
|
|
15
|
+
| 2.5 | `sdk.openApi.templateList()` | `/v1/template/list` | `openBaseUrl` | 2.5 话术模板列表查询接口 |
|
|
16
|
+
| 2.6 | `ScreenPopCallback` | 客户服务器回调地址或未提供 | — | 2.6 来电弹屏回调通知接口 |
|
|
17
|
+
| 2.7 | `OutboundResultCallback` | 客户服务器回调地址或未提供 | — | 2.7 外呼结果实时回调 |
|
|
18
|
+
| 2.8.1 | `sdk.openApi.taskCancelCall()` | `/v1/task/taskCancelCall` | `openBaseUrl` | 2.8.1 批量任务取消号码外呼接口 |
|
|
19
|
+
| 2.8.2 | `sdk.openApi.agentCancelCall()` | `/v1/task/agentCancelCall` | `openBaseUrl` | 2.8.2 坐席取消号码外呼接口 |
|
|
20
|
+
| 2.9.1 | `sdk.openApi.taskRecoverCall()` | `/v1/task/taskRecoverCall` | `openBaseUrl` | 2.9.1批量任务恢复号码外呼接口 |
|
|
21
|
+
| 2.9.2 | `sdk.openApi.agentRecoverCall()` | `/v1/task/agentRecoverCall` | `openBaseUrl` | 2.9.2 坐席恢复号码外呼接口 |
|
|
22
|
+
| 2.10 | `sdk.openApi.taskCallInfo()` | `/v1/task/taskCallInfo` | `openBaseUrl` | 2.10 获取任务外呼情况接口 |
|
|
23
|
+
| 2.11 | `sdk.openApi.updateTaskCustomer()` | `/v1/task/updateTaskCustomer` | `openBaseUrl` | 2.11 更新信息接口 |
|
|
24
|
+
| 2.12.1 | `sdk.openApi.taskDetails()` | `/task-aggre/task/details` | `openApiGatewayUrl` | 2.12.1 AI批量任务查询号码状态接口 |
|
|
25
|
+
| 2.13 | `ConversationCallback` | 客户服务器回调地址或未提供 | — | 2.13 对话过程回调 |
|
|
26
|
+
| 2.14 | `sdk.openApi.taskList()` | `/task-aggre/taskList` | `openApiGatewayUrl` | 2.14 分页查询任务列表接口 |
|
|
27
|
+
| 2.15 | `sdk.openApi.taskInfo()` | `/task-aggre/taskInfo` | `openApiGatewayUrl` | 2.15 查询任务详情接口 |
|
|
28
|
+
| 3.1 | `sdk.openApi.getAgent()` | `/v1/agent/getAgent` | `openBaseUrl` | 3.1 查询坐席具体信息接口 |
|
|
29
|
+
| 3.2 | `sdk.openApi.updateAgentStatus()` | `/v1/agent/updateAgentStatus` | `openBaseUrl` | 3.2 修改坐席状态接口 |
|
|
30
|
+
| 3.4 | `sdk.openApi.queryExtensionStatus()` | `/v1/agent/queryExtensionStatus` | `openBaseUrl` | 3.4 分机状态查询接口 |
|
|
31
|
+
| 3.5 | `ExtensionStatusCallback` | 客户服务器回调地址或未提供 | — | 3.5 分机状态回调接口 |
|
|
32
|
+
| 3.6 | `sdk.openApi.getAgentCallInfo()` | `/v1/agent/getAgentCallInfo` | `openBaseUrl` | 3.6 获取坐席最后外呼记录接口 |
|
|
33
|
+
| 3.7 | `sdk.openApi.addAgent()` | `/v1/agent/addAgent` | `openBaseUrl` | 3.7 创建坐席接口 |
|
|
34
|
+
| 3.8 | `sdk.openApi.joinAgentGroup()` | `/v1/agent/joinAgentGroup` | `openBaseUrl` | 3.8 绑定坐席组 |
|
|
35
|
+
| 3.9 | `sdk.openApi.addAgentGroup()` | `/v1/agent/addAgentGroup` | `openBaseUrl` | 3.9 创建坐席组 |
|
|
36
|
+
| 3.10 | `sdk.openApi.agentGroupList()` | `/v1/agent/agentGroupList` | `openBaseUrl` | 3.10 查询企业的坐席组列表 |
|
|
37
|
+
| 3.11 | `sdk.openApi.quitAgentGroup()` | `/v1/agent/quitAgentGroup` | `openBaseUrl` | 3.11 解绑坐席组 |
|
|
38
|
+
| 3.12 | `sdk.openApi.editAgent()` | `/v1/agent/editAgent` | `openBaseUrl` | 3.12 修改坐席基本信息 |
|
|
39
|
+
| 4.1 | `sdk.openApi.addTask()` | `/v1/task/addTask` | `openBaseUrl` | 4.1 创建任务接口 |
|
|
40
|
+
| 4.2 | `sdk.openApi.editTask()` | `/v1/task/editTask` | `openBaseUrl` | 4.2 修改任务接口 |
|
|
41
|
+
| 4.3 | `sdk.openApi.simpleAddTask()` | `/v1/task/simpleAddTask` | `openBaseUrl` | 4.3 创建简单任务接口 |
|
|
42
|
+
| 5.1 | `sdk.openApi.smsTemplateList()` | `/v1/sms/smsTemplateList` | `openBaseUrl` | 5.1 短信模板列表查询 |
|
|
43
|
+
| 5.2 | `sdk.openApi.createSmsTemplate()` | `/v1/sms/createSmsTemplate` | `openBaseUrl` | 5.2 短信模板创建 |
|
|
44
|
+
| 5.3 | `SmsUpstreamCallback` | 客户服务器回调地址或未提供 | — | 5.3 上行短信回调(挂机短信、群发短信、交互短信) |
|
|
45
|
+
| 5.4 | `FlashSmsResultCallback` | 客户服务器回调地址或未提供 | — | 5.4 闪信结果回调 |
|
|
46
|
+
| 5.5 | `sdk.openApi.sendApiSms()` | `/sms-aggre/openapi/apiMsg/send` | `openApiGatewayUrl` | 5.5 API短信发送接口 |
|
|
47
|
+
| 5.6 | `ApiSmsResultCallback` | 客户服务器回调地址或未提供 | — | 5.6 API短信结果回调 |
|
|
48
|
+
| 5.7 | `HangupSmsCallback` | 客户服务器回调地址或未提供 | — | 5.7 挂机短信回调 |
|
|
49
|
+
| 6.1 | `sdk.openApi.companyBalance()` | `/v1/task/companyBalance` | `openBaseUrl` | 6.1 查询余额接口 |
|
|
50
|
+
| 6.2 | `sdk.openApi.blacklistPage()` | `/v1/blacklist/page` | `openBaseUrl` | 6.2 查询企业黑名单 |
|
|
51
|
+
| 6.3 | `sdk.openApi.addBlacklist()` | `/v1/task/addBlacklist` | `openBaseUrl` | 6.3 添加黑名单接口 |
|
|
52
|
+
| 6.4 | `sdk.openApi.getSubCompanyInfos()` | `/v1/proxy/getSubCompanyInfos` | `openBaseUrl` | 6.4查询子企业信息接口 |
|
|
53
|
+
| 6.5 | `sdk.openApi.queryBill()` | `/v1/bill/query` | `openBaseUrl` | 6.5查询账单接口 |
|
|
54
|
+
| 6.6 | `sdk.openApi.reportConversionResult()` | `/task-aggre/conversion/result/report` | `openApiGatewayUrl` | 6.6 主动推送转化结果 |
|
|
55
|
+
| 6.7 | `sdk.openApi.deleteBlacklist()` | `/basic-info-aggre/api/blacklist/delete` | `openApiGatewayUrl` | 6.7 删除黑名单接口 |
|
|
56
|
+
| 6.8 | `sdk.openApi.reportTaskEvent()` | `/call-task/openApi/task/event/report` | `openApiGatewayUrl` | 6.8 埋点数据上报接口 |
|
|
57
|
+
| 7.1 | `sdk.openApi.callInTaskList()` | `/v1/task/callInTaskList` | `openBaseUrl` | 7.1 查询呼入任务列表接口 |
|
|
58
|
+
| 7.2 | `sdk.openApi.callInCallList()` | `/v1/task/callInCallList` | `openBaseUrl` | 7.2 查询智能接待记录接口 |
|
|
59
|
+
| 7.3 | `InboundResultCallback` | 客户服务器回调地址或未提供 | — | 7.3 呼入结果实时回调 |
|
|
60
|
+
|
|
61
|
+
现有快捷方法仍保留:`getAgentInfo()` 对应 3.1,`updateOpenApiAgentStatus()` 和 `toggleNap()` 对应 3.2,`importOpenApiAgentCustomer()` 和 `callNumber()` 对应 2.1.2。它们会使用实例的坐席信息;新命名空间方法逐项传入业务参数。
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>自定义软电话 UI 接入示例</title>
|
|
7
|
+
<style>
|
|
8
|
+
* { box-sizing: border-box; }
|
|
9
|
+
body { margin: 0; background: #f5f7fb; color: #24334b; font: 14px/1.8 system-ui, sans-serif; }
|
|
10
|
+
main { max-width: 1000px; margin: auto; padding: 24px; }
|
|
11
|
+
section { padding: 20px; margin: 16px 0; background: white; border: 1px solid #dce3ee; border-radius: 8px; }
|
|
12
|
+
h1, h2 { margin: 0 0 16px; }
|
|
13
|
+
.fields, .actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
|
|
14
|
+
label { display: grid; gap: 4px; min-width: 0; }
|
|
15
|
+
input, select, button { font: inherit; padding: 8px 12px; border: 1px solid #ccd7e5; border-radius: 5px; max-width: 100%; }
|
|
16
|
+
button { background: #f2f6ff; color: #315ba7; cursor: pointer; }
|
|
17
|
+
button:disabled { opacity: .5; cursor: default; }
|
|
18
|
+
pre { white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
19
|
+
#notice { padding: 12px; background: #eaf1ff; }
|
|
20
|
+
audio { max-width: 100%; }
|
|
21
|
+
</style>
|
|
22
|
+
</head>
|
|
23
|
+
<body>
|
|
24
|
+
<main>
|
|
25
|
+
<h1>自定义软电话 UI</h1>
|
|
26
|
+
<p>基于 SDK HTML 入口示例整理。保存为 Vite 项目的 index.html,安装 @94ai/softphone 后启动。
|
|
27
|
+
使用 HTTPS 或 localhost。所有凭证仅在运行时输入,不保存、不输出到日志。</p>
|
|
28
|
+
<p id="notice" role="status" aria-live="polite">填写配置后点击初始化,页面不会自动外呼或接听。</p>
|
|
29
|
+
<section>
|
|
30
|
+
<h2>1. 配置坐席</h2>
|
|
31
|
+
<form id="configForm">
|
|
32
|
+
<fieldset id="configFields">
|
|
33
|
+
<div class="fields">
|
|
34
|
+
<label>坐席 ID<input id="agentId" type="number" min="1" step="1" required placeholder="YOUR_AGENT_ID" /></label>
|
|
35
|
+
<label>企业 appKey<input id="appKey" required placeholder="YOUR_APP_KEY" autocomplete="off" /></label>
|
|
36
|
+
<label>企业 appSecret<input id="appSecret" type="password" required placeholder="***(运行时输入)" autocomplete="off" /></label>
|
|
37
|
+
<label>区域<select id="region"><option value="0">国内</option><option value="1">海外</option></select></label>
|
|
38
|
+
<label>OpenAPI 授权<select id="authMode"><option value="sign">sign</option><option value="accessToken">accessToken</option></select></label>
|
|
39
|
+
</div>
|
|
40
|
+
</fieldset>
|
|
41
|
+
<p class="actions"><button id="initialize" type="submit">初始化</button><button id="reset" type="button" disabled>释放并重置</button></p>
|
|
42
|
+
</form>
|
|
43
|
+
<pre id="agentInfo">未初始化</pre>
|
|
44
|
+
</section>
|
|
45
|
+
<section>
|
|
46
|
+
<h2>2. 上线与连接</h2>
|
|
47
|
+
<div class="actions">
|
|
48
|
+
<button id="online" disabled>设置在线</button><button id="nap" disabled>进入小休</button>
|
|
49
|
+
<button id="connect" disabled>连接并签入</button><button id="disconnect" disabled>断开并签出</button>
|
|
50
|
+
<button id="check" disabled>检测权限与网络</button>
|
|
51
|
+
</div>
|
|
52
|
+
<p id="connection">未连接</p><pre id="environment"></pre>
|
|
53
|
+
</section>
|
|
54
|
+
<section>
|
|
55
|
+
<h2>3. 发起外呼</h2>
|
|
56
|
+
<div class="fields">
|
|
57
|
+
<label>目标号码<input id="number" type="tel" placeholder="手动输入目标号码,无默认号码" /></label>
|
|
58
|
+
<button id="call" disabled>手动外呼</button>
|
|
59
|
+
<label>任务 ID<input id="taskId" type="number" min="1" step="1" placeholder="YOUR_TASK_ID" /></label>
|
|
60
|
+
<button id="taskCall" disabled>任务外呼</button>
|
|
61
|
+
</div>
|
|
62
|
+
<p>须坐席在线且签入成功;企业的“坐席外呼依赖”等配置也会影响外呼条件。提交成功后等待实际来电。</p>
|
|
63
|
+
</section>
|
|
64
|
+
<section>
|
|
65
|
+
<h2>4. 来电与通话</h2>
|
|
66
|
+
<p id="session">空闲</p>
|
|
67
|
+
<div class="actions">
|
|
68
|
+
<button id="answer" disabled>接听</button><button id="ignore" disabled>忽略</button>
|
|
69
|
+
<button id="hangup" disabled>挂断</button><button id="transfer" disabled>按 * 转人工</button>
|
|
70
|
+
<button id="muteLocal" disabled>关闭麦克风</button><button id="unmuteLocal" disabled>开启麦克风</button>
|
|
71
|
+
<button id="muteRemote" disabled>关闭远端声音</button><button id="unmuteRemote" disabled>开启远端声音</button>
|
|
72
|
+
</div>
|
|
73
|
+
<p>音量强度:<meter id="volume" min="0" max="1" value="0"></meter> <output id="volumeText">0%</output></p>
|
|
74
|
+
<audio id="remoteAudio" autoplay controls></audio>
|
|
75
|
+
<p>如浏览器阻止自动播放,请手动点击音频控件。自定义响铃可另行配置,不能覆盖 remoteAudio 的通话流。</p>
|
|
76
|
+
<pre id="chatInfo">暂无会话记录</pre>
|
|
77
|
+
</section>
|
|
78
|
+
</main>
|
|
79
|
+
<script type="module">
|
|
80
|
+
import { UserAgentFactory, SessionState, VoiceType } from '@94ai/softphone'
|
|
81
|
+
|
|
82
|
+
const $ = id => document.getElementById(id)
|
|
83
|
+
let sdk, config, busy = false, connected = false, agentStatus, phase = 'idle'
|
|
84
|
+
let generation = 0, removeSessionListener
|
|
85
|
+
const sensitiveValues = new Set()
|
|
86
|
+
function notify(message) { $('notice').textContent = message }
|
|
87
|
+
function safeDisplay(value) {
|
|
88
|
+
const serialized = JSON.stringify(value, (key, item) => /secret|password|pwd|token|sign|appkey|authorization|number|phone/i.test(key) ? '***' : item, 2) ?? ''
|
|
89
|
+
let result = serialized
|
|
90
|
+
for (const secret of sensitiveValues) if (secret) result = result.split(String(secret)).join('***')
|
|
91
|
+
return result
|
|
92
|
+
}
|
|
93
|
+
function render() {
|
|
94
|
+
$('configFields').disabled = busy || !!sdk
|
|
95
|
+
$('initialize').disabled = busy || !!sdk
|
|
96
|
+
$('reset').disabled = busy || !sdk
|
|
97
|
+
$('online').disabled = busy || !sdk || agentStatus === 1
|
|
98
|
+
$('nap').disabled = busy || !sdk || agentStatus === 3
|
|
99
|
+
$('connect').disabled = busy || !sdk || connected || agentStatus !== 1
|
|
100
|
+
$('disconnect').disabled = busy || !connected
|
|
101
|
+
$('check').disabled = busy || !sdk
|
|
102
|
+
for (const id of ['call', 'taskCall']) $(id).disabled = busy || !connected || agentStatus !== 1 || phase !== 'idle'
|
|
103
|
+
$('answer').disabled = $('ignore').disabled = busy || phase !== 'incoming'
|
|
104
|
+
$('hangup').disabled = busy || !['incoming', 'established'].includes(phase)
|
|
105
|
+
for (const id of ['transfer', 'muteLocal', 'unmuteLocal', 'muteRemote', 'unmuteRemote']) $(id).disabled = busy || phase !== 'established'
|
|
106
|
+
$('connection').textContent = connected ? '已连接/签入' : '未连接/未签入'
|
|
107
|
+
$('session').textContent = ({ idle: '空闲', incoming: '来电待接听', established: '通话中', submitted: '已提交,等待来电' })[phase]
|
|
108
|
+
}
|
|
109
|
+
function clearSession() {
|
|
110
|
+
removeSessionListener?.(); removeSessionListener = undefined
|
|
111
|
+
phase = 'idle'
|
|
112
|
+
$('remoteAudio').pause(); $('remoteAudio').srcObject = null
|
|
113
|
+
$('volume').value = 0; $('volumeText').textContent = '0%'
|
|
114
|
+
render()
|
|
115
|
+
}
|
|
116
|
+
async function release() {
|
|
117
|
+
generation++
|
|
118
|
+
const previous = sdk
|
|
119
|
+
sdk = undefined; config = undefined; connected = false; agentStatus = undefined
|
|
120
|
+
clearSession()
|
|
121
|
+
try { await previous?.dispose() }
|
|
122
|
+
finally { sensitiveValues.clear(); render() }
|
|
123
|
+
}
|
|
124
|
+
async function action(task) {
|
|
125
|
+
if (busy) return
|
|
126
|
+
busy = true; render()
|
|
127
|
+
try { await task() }
|
|
128
|
+
catch { notify('操作失败,请核对授权、坐席状态、设备权限及网络。请勿输出含凭证的原始错误。') }
|
|
129
|
+
finally { busy = false; render() }
|
|
130
|
+
}
|
|
131
|
+
function checkResponse(response) {
|
|
132
|
+
if (response?.code !== 200) throw new Error('业务请求未成功')
|
|
133
|
+
return response.data
|
|
134
|
+
}
|
|
135
|
+
async function refreshAgent() {
|
|
136
|
+
const data = checkResponse(await sdk.getAgentInfo())
|
|
137
|
+
agentStatus = data.agentStatus
|
|
138
|
+
$('agentInfo').textContent = safeDisplay({ agentStatus })
|
|
139
|
+
}
|
|
140
|
+
$('configForm').addEventListener('submit', event => {
|
|
141
|
+
event.preventDefault()
|
|
142
|
+
void action(async () => {
|
|
143
|
+
const values = { agentId: Number($('agentId').value), appKey: $('appKey').value.trim(), appSecret: $('appSecret').value, teleai: $('region').value === '1' }
|
|
144
|
+
if (!Number.isSafeInteger(values.agentId) || values.agentId <= 0 || !values.appKey || !values.appSecret) throw new Error('配置不完整')
|
|
145
|
+
sensitiveValues.add(values.appKey); sensitiveValues.add(values.appSecret)
|
|
146
|
+
const current = ++generation
|
|
147
|
+
const tokenTimestamp = Date.now()
|
|
148
|
+
const token = await UserAgentFactory.getToken(values)
|
|
149
|
+
if (current !== generation) return
|
|
150
|
+
sensitiveValues.add(token)
|
|
151
|
+
config = values
|
|
152
|
+
sdk = UserAgentFactory.newUserAgentManager({
|
|
153
|
+
...values, sg: values.teleai ? '1' : '0', sgOpen: values.teleai ? '1' : '0', authMode: $('authMode').value,
|
|
154
|
+
token, tokenTimestamp, enableVolumnTrack: true, armsReport: false,
|
|
155
|
+
enableChatInfoPush: [VoiceType.MULTI_AI, VoiceType.MULTI_PRETEST],
|
|
156
|
+
async tokenOverdued() {
|
|
157
|
+
const tokenTimestamp = Date.now()
|
|
158
|
+
const token = await UserAgentFactory.getToken(values)
|
|
159
|
+
sensitiveValues.add(token)
|
|
160
|
+
return { token, tokenTimestamp }
|
|
161
|
+
},
|
|
162
|
+
refreshChat(value) { if (current === generation) $('chatInfo').textContent = safeDisplay(value) },
|
|
163
|
+
refreshChatErrorCallback() { if (current === generation) notify('会话记录获取失败') },
|
|
164
|
+
refreshRequirementCheck(value) { if (current === generation) $('environment').textContent = safeDisplay(value) },
|
|
165
|
+
refreshSpeekVolumn(value) {
|
|
166
|
+
if (current !== generation) return
|
|
167
|
+
// 显示强度以 -60 至 0 dBFS 映射,不修改实际发送音量。
|
|
168
|
+
const level = Math.max(0, Math.min(1, (20 * Math.log10(Math.max(Number(value) || 0, 0.000001)) + 60) / 60))
|
|
169
|
+
$('volume').value = level; $('volumeText').textContent = Math.round(level * 100) + '%'
|
|
170
|
+
},
|
|
171
|
+
errorCallback() { if (current === generation) notify('软电话异常,请核对连接与会话状态') },
|
|
172
|
+
})
|
|
173
|
+
try { await refreshAgent(); notify('初始化完成,请设置在线并连接服务器') }
|
|
174
|
+
catch (error) { await release(); throw error }
|
|
175
|
+
})
|
|
176
|
+
})
|
|
177
|
+
$('online').onclick = () => action(async () => { checkResponse(await sdk.toggleNap(false)); await refreshAgent(); notify('坐席已在线') })
|
|
178
|
+
$('nap').onclick = () => action(async () => { checkResponse(await sdk.toggleNap(true)); await refreshAgent(); notify('坐席已进入小休') })
|
|
179
|
+
$('connect').onclick = () => action(async () => {
|
|
180
|
+
const current = generation
|
|
181
|
+
await sdk.prepareUserAgent({
|
|
182
|
+
registererOptions: { expires: 600 },
|
|
183
|
+
refresh(path, value) {
|
|
184
|
+
if (current !== generation) return
|
|
185
|
+
if (path === 'registerStatus') connected = Boolean(value)
|
|
186
|
+
if (path === 'connectStatus' && !value) connected = false
|
|
187
|
+
render()
|
|
188
|
+
},
|
|
189
|
+
}, {
|
|
190
|
+
onInvite(invitation) {
|
|
191
|
+
if (current !== generation) return
|
|
192
|
+
clearSession(); phase = 'incoming'; notify('收到来电,请手动接听或忽略'); render()
|
|
193
|
+
const onState = state => {
|
|
194
|
+
if (current !== generation) return
|
|
195
|
+
if (state === SessionState.Established) {
|
|
196
|
+
phase = 'established'
|
|
197
|
+
$('remoteAudio').srcObject = sdk.getStream()
|
|
198
|
+
$('remoteAudio').play().catch(() => notify('请点击音频控件播放远端声音'))
|
|
199
|
+
} else if (state === SessionState.Terminated) { clearSession(); notify('通话已结束') }
|
|
200
|
+
render()
|
|
201
|
+
}
|
|
202
|
+
invitation.stateChange.addListener(onState)
|
|
203
|
+
removeSessionListener = () => invitation.stateChange.removeListener?.(onState)
|
|
204
|
+
},
|
|
205
|
+
})
|
|
206
|
+
notify('连接请求完成,请以实际签入状态为准')
|
|
207
|
+
})
|
|
208
|
+
$('disconnect').onclick = () => action(async () => { await release(); notify('已签出,请重新初始化后连接') })
|
|
209
|
+
$('reset').onclick = () => action(async () => { await release(); $('appKey').value = ''; $('appSecret').value = ''; $('agentInfo').textContent = '未初始化'; $('chatInfo').textContent = '暂无会话记录'; $('environment').textContent = ''; notify('旧实例已释放,可输入新配置') })
|
|
210
|
+
$('check').onclick = () => action(async () => { await sdk.softphoneEnvCheck() })
|
|
211
|
+
async function call(task) {
|
|
212
|
+
const number = $('number').value.trim(), taskId = $('taskId').value.trim()
|
|
213
|
+
if (!number || (task && (!/^\d+$/.test(taskId) || Number(taskId) <= 0))) throw new Error('请输入有效号码与任务 ID')
|
|
214
|
+
const data = task
|
|
215
|
+
? { requestId: crypto.randomUUID(), taskId, failReturn: 1, customers: [{ number }] }
|
|
216
|
+
: { agentId: config.agentId, callType: 1001, customers: [{ number }] }
|
|
217
|
+
checkResponse(await sdk.requestOpenApi({ url: task ? '/v1/task/importTaskCustomer' : '/v1/task/importAgentCustomer', type: 'POST', data, auth: {} }))
|
|
218
|
+
// 不能把提交成功当成会话建立;来电也可能先于接口响应到达。
|
|
219
|
+
if (!task && phase === 'idle') phase = 'submitted'
|
|
220
|
+
notify('外呼请求已提交,等待真实来电;长时间无来电可释放后重新初始化')
|
|
221
|
+
}
|
|
222
|
+
$('call').onclick = () => action(() => call(false))
|
|
223
|
+
$('taskCall').onclick = () => action(() => call(true))
|
|
224
|
+
$('answer').onclick = () => action(async () => { await sdk.acceptInvite({ onAck() {}, onAckTimeout() { notify('接听响应超时') } }) })
|
|
225
|
+
$('ignore').onclick = () => action(async () => { await sdk.ignoreInvite(); clearSession() })
|
|
226
|
+
$('hangup').onclick = () => action(async () => { await sdk.hangUpInvite({ scoutResponse: true }); clearSession() })
|
|
227
|
+
$('transfer').onclick = () => action(async () => {
|
|
228
|
+
if (sdk.notNeedSendStarDtmf() && !sdk.getSitOutboundCall()) { notify('当前会话无需转人工'); return }
|
|
229
|
+
await new Promise((resolve, reject) => {
|
|
230
|
+
Promise.resolve(sdk.sendStarDtmf({ requestDelegate: { onAccept: resolve, onReject: reject } })).catch(reject)
|
|
231
|
+
})
|
|
232
|
+
notify('转人工请求成功')
|
|
233
|
+
})
|
|
234
|
+
for (const [id, method] of Object.entries({ muteLocal: 'muteLocalAudio', unmuteLocal: 'unMuteLocalAudio', muteRemote: 'muteRemoteAudio', unmuteRemote: 'unMuteRemoteAudio' })) {
|
|
235
|
+
$(id).onclick = () => action(async () => { await sdk[method]() })
|
|
236
|
+
}
|
|
237
|
+
window.addEventListener('pagehide', () => { void release().catch(() => {}) }, { once: true })
|
|
238
|
+
render()
|
|
239
|
+
</script>
|
|
240
|
+
</body>
|
|
241
|
+
</html>
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="960" height="480" viewBox="0 0 960 480" role="img" aria-labelledby="title desc">
|
|
2
|
+
<title id="title">SDK Contributors</title><desc id="desc">master; 2026-08-23 to 2026-11-23 UTC; SDK directory non-merge commits. Circle area represents commit count; names use initials.</desc>
|
|
3
|
+
<rect width="960" height="480" rx="20" fill="#0b1020"/><g font-family="Arial, Microsoft YaHei, sans-serif">
|
|
4
|
+
<text x="40" y="54" fill="#f8fafc" font-size="30" font-weight="700">SDK Contributors</text>
|
|
5
|
+
<text x="40" y="84" fill="#94a3b8" font-size="14">2026-08-23 → 2026-11-23 · UTC · master</text>
|
|
6
|
+
<text x="44" y="200" fill="#60a5fa" font-size="56" font-weight="700">54</text><text x="44" y="232" fill="#cbd5e1" font-size="16">non-merge commits</text>
|
|
7
|
+
<text x="44" y="304" fill="#f8fafc" font-size="36" font-weight="700">1</text><text x="44" y="334" fill="#cbd5e1" font-size="16">contributors · last 3 months</text>
|
|
8
|
+
<g transform="translate(620 264)"><title>zoujiahe: 54 commits</title><circle r="105" fill="#a3e635" fill-opacity=".18" stroke="#a3e635" stroke-width="2"/><text y="-4" text-anchor="middle" fill="#fff" font-size="30" font-weight="700">ZO</text><text y="52.5" text-anchor="middle" fill="#dbeafe" font-size="13">54</text></g>
|
|
9
|
+
<text x="40" y="452" fill="#94a3b8" font-size="12">@94ai/softphone · Local Git history · Initials, not profile photos</text>
|
|
10
|
+
</g></svg>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="300" height="60" viewBox="0 0 300 60" role="img" aria-labelledby="title">
|
|
2
|
+
<title id="title">softphone</title>
|
|
3
|
+
<text x="0" y="48" fill="#409eff" font-family="Verdana, Geneva, sans-serif" font-weight="600" font-size="48" textLength="286" lengthAdjust="spacingAndGlyphs">softphone</text>
|
|
4
|
+
</svg>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|