chatboty 0.1.0
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 +162 -0
- package/README.md +119 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/src/chatboty.d.ts +93 -0
- package/dist/cjs/src/chatboty.d.ts.map +1 -0
- package/dist/cjs/src/chatboty.js +204 -0
- package/dist/cjs/src/chatboty.js.map +1 -0
- package/dist/cjs/src/client.d.ts +84 -0
- package/dist/cjs/src/client.d.ts.map +1 -0
- package/dist/cjs/src/client.js +298 -0
- package/dist/cjs/src/client.js.map +1 -0
- package/dist/cjs/src/entity/contact.d.ts +25 -0
- package/dist/cjs/src/entity/contact.d.ts.map +1 -0
- package/dist/cjs/src/entity/contact.js +34 -0
- package/dist/cjs/src/entity/contact.js.map +1 -0
- package/dist/cjs/src/entity/friendship.d.ts +13 -0
- package/dist/cjs/src/entity/friendship.d.ts.map +1 -0
- package/dist/cjs/src/entity/friendship.js +19 -0
- package/dist/cjs/src/entity/friendship.js.map +1 -0
- package/dist/cjs/src/entity/message.d.ts +61 -0
- package/dist/cjs/src/entity/message.d.ts.map +1 -0
- package/dist/cjs/src/entity/message.js +150 -0
- package/dist/cjs/src/entity/message.js.map +1 -0
- package/dist/cjs/src/entity/room.d.ts +21 -0
- package/dist/cjs/src/entity/room.d.ts.map +1 -0
- package/dist/cjs/src/entity/room.js +43 -0
- package/dist/cjs/src/entity/room.js.map +1 -0
- package/dist/cjs/src/mod.d.ts +17 -0
- package/dist/cjs/src/mod.d.ts.map +1 -0
- package/dist/cjs/src/mod.js +41 -0
- package/dist/cjs/src/mod.js.map +1 -0
- package/dist/cjs/src/types.d.ts +122 -0
- package/dist/cjs/src/types.d.ts.map +1 -0
- package/dist/cjs/src/types.js +55 -0
- package/dist/cjs/src/types.js.map +1 -0
- package/dist/esm/src/chatboty.d.ts +93 -0
- package/dist/esm/src/chatboty.d.ts.map +1 -0
- package/dist/esm/src/chatboty.js +200 -0
- package/dist/esm/src/chatboty.js.map +1 -0
- package/dist/esm/src/client.d.ts +84 -0
- package/dist/esm/src/client.d.ts.map +1 -0
- package/dist/esm/src/client.js +291 -0
- package/dist/esm/src/client.js.map +1 -0
- package/dist/esm/src/entity/contact.d.ts +25 -0
- package/dist/esm/src/entity/contact.d.ts.map +1 -0
- package/dist/esm/src/entity/contact.js +30 -0
- package/dist/esm/src/entity/contact.js.map +1 -0
- package/dist/esm/src/entity/friendship.d.ts +13 -0
- package/dist/esm/src/entity/friendship.d.ts.map +1 -0
- package/dist/esm/src/entity/friendship.js +15 -0
- package/dist/esm/src/entity/friendship.js.map +1 -0
- package/dist/esm/src/entity/message.d.ts +61 -0
- package/dist/esm/src/entity/message.d.ts.map +1 -0
- package/dist/esm/src/entity/message.js +146 -0
- package/dist/esm/src/entity/message.js.map +1 -0
- package/dist/esm/src/entity/room.d.ts +21 -0
- package/dist/esm/src/entity/room.d.ts.map +1 -0
- package/dist/esm/src/entity/room.js +39 -0
- package/dist/esm/src/entity/room.js.map +1 -0
- package/dist/esm/src/mod.d.ts +17 -0
- package/dist/esm/src/mod.d.ts.map +1 -0
- package/dist/esm/src/mod.js +17 -0
- package/dist/esm/src/mod.js.map +1 -0
- package/dist/esm/src/types.d.ts +122 -0
- package/dist/esm/src/types.d.ts.map +1 -0
- package/dist/esm/src/types.js +50 -0
- package/dist/esm/src/types.js.map +1 -0
- package/package.json +52 -0
- package/src/chatboty.ts +228 -0
- package/src/client.ts +310 -0
- package/src/entity/contact.ts +32 -0
- package/src/entity/friendship.ts +16 -0
- package/src/entity/message.ts +147 -0
- package/src/entity/room.ts +42 -0
- package/src/mod.ts +19 -0
- package/src/types.ts +142 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work; and
|
|
103
|
+
|
|
104
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
105
|
+
distribution, then any Derivative Works that You distribute must
|
|
106
|
+
include a readable copy of the attribution notices contained
|
|
107
|
+
within such NOTICE file.
|
|
108
|
+
|
|
109
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
110
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
111
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
112
|
+
this License, without any additional terms or conditions.
|
|
113
|
+
|
|
114
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
115
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
116
|
+
except as required for reasonable and customary use in describing the
|
|
117
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
118
|
+
|
|
119
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed
|
|
120
|
+
to in writing, Licensor provides the Work (and each Contributor
|
|
121
|
+
provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES
|
|
122
|
+
OR CONDITIONS OF ANY KIND, either express or implied, including,
|
|
123
|
+
without limitation, any warranties or conditions of TITLE,
|
|
124
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
|
|
125
|
+
PURPOSE. You are solely responsible for determining the
|
|
126
|
+
appropriateness of using or redistributing the Work and assume any
|
|
127
|
+
risks associated with Your exercise of permissions under this License.
|
|
128
|
+
|
|
129
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
130
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
131
|
+
unless required by applicable law (such as deliberate and grossly
|
|
132
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
133
|
+
liable to You for damages, including any direct, indirect, special,
|
|
134
|
+
incidental, or consequential damages of any character arising as a
|
|
135
|
+
result of this License or out of the use or inability to use the
|
|
136
|
+
Work.
|
|
137
|
+
|
|
138
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
139
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
140
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
141
|
+
or other liability obligations and/or rights consistent with this
|
|
142
|
+
License. However, in accepting such obligations, You may act only
|
|
143
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
144
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
145
|
+
defend, and hold each Contributor harmless for any liability
|
|
146
|
+
incurred by, or claims asserted against, such Contributor.
|
|
147
|
+
|
|
148
|
+
END OF TERMS AND CONDITIONS
|
|
149
|
+
|
|
150
|
+
Copyright 2026 chatboty
|
|
151
|
+
|
|
152
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
153
|
+
you may not use this file except in compliance with the License.
|
|
154
|
+
You may obtain a copy of the License at
|
|
155
|
+
|
|
156
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
157
|
+
|
|
158
|
+
Unless required by applicable law or agreed to in writing, software
|
|
159
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
160
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
161
|
+
See the License for the specific language governing permissions and
|
|
162
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# chatboty
|
|
2
|
+
|
|
3
|
+
企业微信(WeCom)IM 自动化 SDK —— **自研全生态框架**,零外部框架依赖。
|
|
4
|
+
|
|
5
|
+
用一个订阅 token,即可在 Node 里收发消息、管理群、监听群事件、读联系人。SDK 自动向平台发证、连接到分配给你的探针实例。
|
|
6
|
+
|
|
7
|
+
> 概念(Contact / Room / Message / 事件)类似业界常见的聊天机器人框架,但 chatboty 为**完全自研实现**。
|
|
8
|
+
|
|
9
|
+
## 安装
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install chatboty
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
要求 Node.js >= 18。
|
|
16
|
+
|
|
17
|
+
## 快速上手
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { Chatboty } from 'chatboty'
|
|
21
|
+
|
|
22
|
+
const bot = new Chatboty({
|
|
23
|
+
token: 'cbt_你的订阅token', // 来自 chatboty 控制台
|
|
24
|
+
// atlasUrl: 'https://api.chatboty.ai', // 平台地址(默认本地开发地址)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
bot.on('message', async (m) => {
|
|
28
|
+
if (m.self()) return // 跳过自己发的
|
|
29
|
+
console.log(`${m.talker()?.name()}: ${m.text()}`)
|
|
30
|
+
if (m.text() === 'ping') await m.say('pong')
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
bot.on('room-join', (e) => {
|
|
34
|
+
const names = e.contactList.map(c => c.name()).join('、')
|
|
35
|
+
e.room.say(`欢迎 ${names} 加入!`)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
await bot.start()
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
就这样——`token` 决定连到哪个企业微信实例,平台负责路由与隔离。
|
|
42
|
+
|
|
43
|
+
## 事件
|
|
44
|
+
|
|
45
|
+
| 事件 | 回调参数 | 说明 |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| `message` | `Message` | 收到消息(文本/图片/文件/链接/小程序/系统) |
|
|
48
|
+
| `room-join` | `{ room, contactList, idList, timestamp }` | 有人进群(含外部客户完整信息) |
|
|
49
|
+
| `room-leave` | `{ room, contactList, idList, timestamp }` | 有人退群/被移除 |
|
|
50
|
+
| `room-topic` | `{ room, topic, oldTopic, timestamp }` | 群改名 |
|
|
51
|
+
| `friendship` | `Friendship` | 加好友/删好友 |
|
|
52
|
+
| `login` / `logout` | `self?` / — | 登录态变化 |
|
|
53
|
+
| `scan` | `{ qrcode, status }` | 登录二维码 |
|
|
54
|
+
| `error` | `{ error }` | 探针/代理侧错误信号(不中断运行, 仅上报) |
|
|
55
|
+
| `heartbeat` | `{ state }` | 探针心跳(~30s), 供存活/掉线判定 |
|
|
56
|
+
|
|
57
|
+
## 实体 API(节选)
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
// Message
|
|
61
|
+
m.text(); m.type(); m.self(); m.talker(); m.room(); m.file(); m.say(sayable)
|
|
62
|
+
m.mentionSelf(); // 本条是否 @ 了我/@所有人(布尔, 纯文本判定)
|
|
63
|
+
await m.mentionList(); // 被 @ 的 Contact[](best-effort: 解析正文@名→就近解析通讯录)
|
|
64
|
+
await m.toFileBox(); // 取媒体/文件字节 → FileBox{dataUrl,mime,name,size}; 别名 m.download()
|
|
65
|
+
// await m.forward(to); // ⚠️ 未实现(需逆向企微转发服务), 调用抛错
|
|
66
|
+
|
|
67
|
+
// Contact
|
|
68
|
+
c.id(); c.name(); c.alias(); c.avatar(); c.type(); c.say(sayable)
|
|
69
|
+
// 注: 企微通讯录未采集性别 → 不提供 gender()
|
|
70
|
+
|
|
71
|
+
// Room
|
|
72
|
+
r.id(); r.topic(); r.say(sayable); r.rename(topic); r.memberAll(); r.owner()
|
|
73
|
+
|
|
74
|
+
// Bot
|
|
75
|
+
bot.roomList(); bot.contactList(); bot.roomCreate(memberIds, topic)
|
|
76
|
+
await bot.contactFind({ name: '张三' }); // 或 contactFind('关键词') → Contact | undefined
|
|
77
|
+
await bot.contactFindAll('关键词'); // → Contact[](本地通讯录过滤)
|
|
78
|
+
await bot.currentUser(); bot.self; // 当前登录者(Contact) / 缓存的 self getter
|
|
79
|
+
await bot.logout(); // 干净登出(回扫码页, 不重启探针)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## 发送内容(Sayable)
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
await contact.say('纯文本')
|
|
86
|
+
await room.say({ image: 'https://.../pic.png' }) // 图片(URL/本地路径/base64)
|
|
87
|
+
await room.say({ file: '/path/to/doc.pdf' }) // 文件
|
|
88
|
+
await room.say({ url: 'https://...', title: '标题', description: '摘要', thumbUrl: '...' }) // 链接卡片
|
|
89
|
+
await room.say({ miniProgram: { appid: '...', title: '...', path: '...', thumb: '...' } }) // 小程序卡片
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## 服务发现接入(推荐)
|
|
93
|
+
|
|
94
|
+
除 `token` 直连外,也可用**服务令牌 + 服务发现端点**接入。SDK 会先向发现端点换取一个短 TTL 的接入凭据,再连网关,并在过期前自动刷新:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
const bot = new Chatboty({
|
|
98
|
+
serviceToken: '你的服务令牌', // 长期令牌
|
|
99
|
+
serviceAuthority: 'https://discovery.chatboty.ai', // 发现端点(权威 URL)
|
|
100
|
+
})
|
|
101
|
+
await bot.start()
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
流程:`POST {serviceAuthority}`(`Authorization: Bearer {serviceToken}`)→ `{ endpoint, accessToken, expiresIn }` → 连 `wss://{endpoint}/client?access={accessToken}`(网关验 RS256 → seatId)。accessToken 到期前约 30s 自动重新发现刷新;断线按指数退避自愈重连。仅给 `{ token, endpoint }` 时维持既有 `?token=` 直连行为不变。
|
|
105
|
+
|
|
106
|
+
## 仅用传输层(高级)
|
|
107
|
+
|
|
108
|
+
不想要框架封装,只要底层连接?
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import { ChatbotyClient } from 'chatboty/client'
|
|
112
|
+
const c = new ChatbotyClient({ token: 'cbt_...' })
|
|
113
|
+
await c.start()
|
|
114
|
+
const rooms = await c.roomList()
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
Apache-2.0
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chatboty — 自研机器人主类(零外部框架依赖)。
|
|
3
|
+
* 封装 ChatbotyClient(发证+连网关传输), 把 wire 事件/结果映射成实体类(Message/Contact/Room/Friendship),
|
|
4
|
+
* 对外暴露 typed 事件与便捷 API。这是 chatboty 全生态框架的核心。
|
|
5
|
+
*/
|
|
6
|
+
import { type ChatbotyClientOptions } from './client.js';
|
|
7
|
+
import { type BotApi, type Sayable, type ContactPayload, type ContactQueryFilter } from './types.js';
|
|
8
|
+
import { Message } from './entity/message.js';
|
|
9
|
+
import { Contact } from './entity/contact.js';
|
|
10
|
+
import { Room } from './entity/room.js';
|
|
11
|
+
import { Friendship } from './entity/friendship.js';
|
|
12
|
+
export type ChatbotyOptions = ChatbotyClientOptions;
|
|
13
|
+
export declare class Chatboty implements BotApi {
|
|
14
|
+
private readonly client;
|
|
15
|
+
private readonly listeners;
|
|
16
|
+
private _self?;
|
|
17
|
+
constructor(options: ChatbotyOptions);
|
|
18
|
+
/** 该接入授权的探针实例 id。 */
|
|
19
|
+
get accountId(): string | undefined;
|
|
20
|
+
/** 当前登录者(self)。start 后异步热身; 未就绪时 undefined(用 {@link currentUser} 主动拉取)。 */
|
|
21
|
+
get self(): Contact | undefined;
|
|
22
|
+
start(): Promise<void>;
|
|
23
|
+
stop(): Promise<void>;
|
|
24
|
+
on(event: 'message', l: (m: Message) => void): this;
|
|
25
|
+
on(event: 'friendship', l: (f: Friendship) => void): this;
|
|
26
|
+
on(event: 'room-join' | 'room-leave', l: (p: {
|
|
27
|
+
room: Room;
|
|
28
|
+
contactList: Contact[];
|
|
29
|
+
idList: string[];
|
|
30
|
+
timestamp?: number;
|
|
31
|
+
}) => void): this;
|
|
32
|
+
on(event: 'room-topic', l: (p: {
|
|
33
|
+
room: Room;
|
|
34
|
+
topic?: string;
|
|
35
|
+
oldTopic?: string;
|
|
36
|
+
timestamp?: number;
|
|
37
|
+
}) => void): this;
|
|
38
|
+
on(event: 'login', l: (self?: any) => void): this;
|
|
39
|
+
on(event: 'scan', l: (p: {
|
|
40
|
+
qrcode?: string;
|
|
41
|
+
status?: any;
|
|
42
|
+
}) => void): this;
|
|
43
|
+
on(event: 'login-phase', l: (p: {
|
|
44
|
+
phase: string;
|
|
45
|
+
label?: string;
|
|
46
|
+
}) => void): this;
|
|
47
|
+
on(event: 'error', l: (p: {
|
|
48
|
+
error: string;
|
|
49
|
+
}) => void): this;
|
|
50
|
+
on(event: 'heartbeat', l: (p: {
|
|
51
|
+
state?: string;
|
|
52
|
+
}) => void): this;
|
|
53
|
+
on(event: 'logout' | 'ready' | 'stop' | 'disconnected', l: () => void): this;
|
|
54
|
+
private emit;
|
|
55
|
+
private wire;
|
|
56
|
+
private toContactPayload;
|
|
57
|
+
private toMessage;
|
|
58
|
+
private toMemberEvent;
|
|
59
|
+
private toFriendship;
|
|
60
|
+
command(cmd: string, args?: Record<string, any>): Promise<any>;
|
|
61
|
+
/** 登录扫码后若企微要求验证码, 用此提交(配合 on('login-phase') 的 need-verify 阶段)。 */
|
|
62
|
+
enterVerifyCode(code: string): Promise<any>;
|
|
63
|
+
/** BotApi: 当前登录者 payload(供实体做本机 self 判定, 如 Message.mentionSelf)。 */
|
|
64
|
+
selfContact(): ContactPayload | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* 干净登出(回到扫码页, 不重启探针进程)。冷调 LoginServiceImpl 登出链,
|
|
67
|
+
* 完成后探针会推 'logout' 事件并转为出新二维码的扫码态。
|
|
68
|
+
*/
|
|
69
|
+
logout(): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* 拉取当前登录者(self)为完整 Contact, 并缓存到 {@link self}。
|
|
72
|
+
* @returns 当前登录者 Contact; 未登录/会话未加载时 undefined。
|
|
73
|
+
*/
|
|
74
|
+
currentUser(): Promise<Contact | undefined>;
|
|
75
|
+
sayTo(conversationId: string, sayable: Sayable): Promise<any>;
|
|
76
|
+
roomList(): Promise<Room[]>;
|
|
77
|
+
contactList(): Promise<Contact[]>;
|
|
78
|
+
/**
|
|
79
|
+
* 在【已加载的全量通讯录】按条件查找联系人(本地过滤, 非服务端搜陌生人)。
|
|
80
|
+
* @param query 关键词字符串(匹配 name/alias/phone/title/vid 子串), 或 { name?, alias?, id? } 精确匹配。
|
|
81
|
+
* @returns 命中的 Contact 列表(可能为空)。
|
|
82
|
+
*/
|
|
83
|
+
contactFindAll(query?: ContactQueryFilter): Promise<Contact[]>;
|
|
84
|
+
/**
|
|
85
|
+
* 查找单个联系人(取 {@link contactFindAll} 第一个命中)。
|
|
86
|
+
* @param query 关键词字符串或 { name?, alias?, id? }。
|
|
87
|
+
* @returns 命中的第一个 Contact; 无则 undefined。
|
|
88
|
+
*/
|
|
89
|
+
contactFind(query: ContactQueryFilter): Promise<Contact | undefined>;
|
|
90
|
+
/** 建群(成员 vid 列表)。 */
|
|
91
|
+
roomCreate(memberIdList: string[], topic?: string): Promise<Room | undefined>;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=chatboty.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chatboty.d.ts","sourceRoot":"","sources":["../../../src/chatboty.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAkB,KAAK,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACxE,OAAO,EACL,KAAK,MAAM,EAAE,KAAK,OAAO,EAAuB,KAAK,cAAc,EAAE,KAAK,kBAAkB,EAE7F,MAAM,YA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C,GAAG,CAAC;IAIzE,kEAAkE;IAC5D,eAAe,CAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAIlD,oEAAoE;IACpE,WAAW,IAAK,cAAc,GAAG,SAAS;IAE1C;;;OAGG;IACG,MAAM,IAAK,OAAO,CAAC,IAAI,CAAC;IAK9B;;;OAGG;IACG,WAAW,IAAK,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;IAQ5C,KAAK,CAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC;IAU9D,QAAQ,IAAK,OAAO,CAAC,IAAI,EAAE,CAAC;IAM5B,WAAW,IAAK,OAAO,CAAC,OAAO,EAAE,CAAC;IAMxC;;;;OAIG;IACG,cAAc,CAAE,KAAK,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAerE;;;;OAIG;IACG,WAAW,CAAE,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;IAK3E,qBAAqB;IACf,UAAU,CAAE,YAAY,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC;CAKrF"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Chatboty = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Chatboty — 自研机器人主类(零外部框架依赖)。
|
|
6
|
+
* 封装 ChatbotyClient(发证+连网关传输), 把 wire 事件/结果映射成实体类(Message/Contact/Room/Friendship),
|
|
7
|
+
* 对外暴露 typed 事件与便捷 API。这是 chatboty 全生态框架的核心。
|
|
8
|
+
*/
|
|
9
|
+
const client_js_1 = require("./client.js");
|
|
10
|
+
const types_js_1 = require("./types.js");
|
|
11
|
+
const message_js_1 = require("./entity/message.js");
|
|
12
|
+
const contact_js_1 = require("./entity/contact.js");
|
|
13
|
+
const room_js_1 = require("./entity/room.js");
|
|
14
|
+
const friendship_js_1 = require("./entity/friendship.js");
|
|
15
|
+
class Chatboty {
|
|
16
|
+
constructor(options) {
|
|
17
|
+
this.listeners = new Map();
|
|
18
|
+
this.client = new client_js_1.ChatbotyClient(options);
|
|
19
|
+
}
|
|
20
|
+
/** 该接入授权的探针实例 id。 */
|
|
21
|
+
get accountId() { return this.client.account; }
|
|
22
|
+
/** 当前登录者(self)。start 后异步热身; 未就绪时 undefined(用 {@link currentUser} 主动拉取)。 */
|
|
23
|
+
get self() { return this._self; }
|
|
24
|
+
async start() {
|
|
25
|
+
this.wire();
|
|
26
|
+
await this.client.start();
|
|
27
|
+
this.emit('ready');
|
|
28
|
+
// 热身 self(供 message.mentionSelf/self 判定); 失败不致命(未登录时拉不到)。
|
|
29
|
+
void this.currentUser().catch(() => undefined);
|
|
30
|
+
}
|
|
31
|
+
async stop() { this.client.stop(); this.emit('stop'); }
|
|
32
|
+
on(event, l) {
|
|
33
|
+
if (!this.listeners.has(event))
|
|
34
|
+
this.listeners.set(event, new Set());
|
|
35
|
+
this.listeners.get(event).add(l);
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
emit(event, ...args) {
|
|
39
|
+
this.listeners.get(event)?.forEach((l) => { try {
|
|
40
|
+
l(...args);
|
|
41
|
+
}
|
|
42
|
+
catch { /* 隔离回调异常 */ } });
|
|
43
|
+
}
|
|
44
|
+
wire() {
|
|
45
|
+
this.client.on('message', (w) => this.emit('message', this.toMessage(w)));
|
|
46
|
+
this.client.on('room-join', (w) => this.emit('room-join', this.toMemberEvent(w, w.inviteeIdList, w.inviteeList)));
|
|
47
|
+
this.client.on('room-leave', (w) => this.emit('room-leave', this.toMemberEvent(w, w.removeeIdList, w.removeeList)));
|
|
48
|
+
this.client.on('room-topic', (w) => this.emit('room-topic', {
|
|
49
|
+
room: new room_js_1.Room(this, { id: w.roomId, topic: w.topic }), topic: w.topic, oldTopic: w.oldTopic, timestamp: w.timestamp,
|
|
50
|
+
}));
|
|
51
|
+
this.client.on('friendship', (w) => this.emit('friendship', this.toFriendship(w)));
|
|
52
|
+
this.client.on('login', (w) => this.emit('login', w.self));
|
|
53
|
+
this.client.on('logout', () => { this._self = undefined; this.emit('logout'); });
|
|
54
|
+
this.client.on('scan', (w) => this.emit('scan', { qrcode: w.qrcode, status: w.status }));
|
|
55
|
+
this.client.on('login-phase', (w) => this.emit('login-phase', { phase: w.phase, label: w.label }));
|
|
56
|
+
this.client.on('disconnected', () => this.emit('disconnected'));
|
|
57
|
+
this.client.on('error', (w) => this.emit('error', { error: w.error }));
|
|
58
|
+
this.client.on('heartbeat', (w) => this.emit('heartbeat', { state: w.state }));
|
|
59
|
+
}
|
|
60
|
+
/* ---------------- wire → 实体 ---------------- */
|
|
61
|
+
toContactPayload(u) {
|
|
62
|
+
return {
|
|
63
|
+
id: u.userId ?? u.id, name: u.name, alias: u.alias, avatar: u.avatar,
|
|
64
|
+
phone: u.phone, title: u.title, corpId: u.corpId, unionId: u.unionId, conversationId: u.conversationId,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
toMessage(w) {
|
|
68
|
+
const conv = w.conversationId;
|
|
69
|
+
const room = (0, types_js_1.isRoomId)(conv);
|
|
70
|
+
const talker = w.talkerUser
|
|
71
|
+
? this.toContactPayload(w.talkerUser)
|
|
72
|
+
: (w.talkerId ? { id: w.talkerId, name: w.talker } : undefined);
|
|
73
|
+
const payload = {
|
|
74
|
+
id: w.msgId,
|
|
75
|
+
type: (0, types_js_1.toMessageType)(w.type, w.typeRaw),
|
|
76
|
+
text: w.text,
|
|
77
|
+
talkerId: talker?.id ?? w.talkerId,
|
|
78
|
+
roomId: room ? conv : undefined,
|
|
79
|
+
conversationId: conv,
|
|
80
|
+
timestamp: w.timestamp,
|
|
81
|
+
self: !!w.self,
|
|
82
|
+
talker,
|
|
83
|
+
file: w.file ?? null,
|
|
84
|
+
miniProgram: w.miniProgram ?? null,
|
|
85
|
+
urlLink: w.urlLink ?? null,
|
|
86
|
+
};
|
|
87
|
+
return new message_js_1.Message(this, payload);
|
|
88
|
+
}
|
|
89
|
+
toMemberEvent(w, idList, userList) {
|
|
90
|
+
return {
|
|
91
|
+
room: new room_js_1.Room(this, { id: w.roomId }),
|
|
92
|
+
idList: idList || [],
|
|
93
|
+
contactList: (userList || []).filter(Boolean).map((u) => new contact_js_1.Contact(this, this.toContactPayload(u))),
|
|
94
|
+
timestamp: w.timestamp,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
toFriendship(w) {
|
|
98
|
+
const kind = w.kind === 'add' ? 'add' : w.kind === 'delete' ? 'delete' : w.kind === 'receive' ? 'receive' : 'confirm';
|
|
99
|
+
return new friendship_js_1.Friendship(this, {
|
|
100
|
+
contactId: w.vid || w.contactId,
|
|
101
|
+
contact: w.user ? this.toContactPayload(w.user) : undefined,
|
|
102
|
+
kind,
|
|
103
|
+
hello: w.hello,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/* ---------------- BotApi(实体动作底座) ---------------- */
|
|
107
|
+
async command(cmd, args = {}) {
|
|
108
|
+
return this.client.command(cmd, args);
|
|
109
|
+
}
|
|
110
|
+
/** 登录扫码后若企微要求验证码, 用此提交(配合 on('login-phase') 的 need-verify 阶段)。 */
|
|
111
|
+
async enterVerifyCode(code) {
|
|
112
|
+
return this.client.command('enterVerifyCode', { code });
|
|
113
|
+
}
|
|
114
|
+
/** BotApi: 当前登录者 payload(供实体做本机 self 判定, 如 Message.mentionSelf)。 */
|
|
115
|
+
selfContact() { return this._self?.payload; }
|
|
116
|
+
/**
|
|
117
|
+
* 干净登出(回到扫码页, 不重启探针进程)。冷调 LoginServiceImpl 登出链,
|
|
118
|
+
* 完成后探针会推 'logout' 事件并转为出新二维码的扫码态。
|
|
119
|
+
*/
|
|
120
|
+
async logout() {
|
|
121
|
+
await this.command('logout');
|
|
122
|
+
this._self = undefined;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* 拉取当前登录者(self)为完整 Contact, 并缓存到 {@link self}。
|
|
126
|
+
* @returns 当前登录者 Contact; 未登录/会话未加载时 undefined。
|
|
127
|
+
*/
|
|
128
|
+
async currentUser() {
|
|
129
|
+
let r;
|
|
130
|
+
try {
|
|
131
|
+
r = await this.command('self');
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return this._self;
|
|
135
|
+
}
|
|
136
|
+
if (!r || !(r.userId || r.id))
|
|
137
|
+
return this._self;
|
|
138
|
+
this._self = new contact_js_1.Contact(this, this.toContactPayload(r));
|
|
139
|
+
return this._self;
|
|
140
|
+
}
|
|
141
|
+
async sayTo(conversationId, sayable) {
|
|
142
|
+
if (typeof sayable === 'string')
|
|
143
|
+
return this.client.command('sendText', { conversationId, text: sayable });
|
|
144
|
+
if ('image' in sayable)
|
|
145
|
+
return this.client.command('sendImage', { conversationId, url: sayable.image });
|
|
146
|
+
if ('file' in sayable)
|
|
147
|
+
return this.client.command('sendFile', { conversationId, url: sayable.file });
|
|
148
|
+
if ('url' in sayable)
|
|
149
|
+
return this.client.command('sendUrlLink', { conversationId, url: sayable.url, title: sayable.title, desc: sayable.description, thumb: sayable.thumbUrl });
|
|
150
|
+
if ('miniProgram' in sayable)
|
|
151
|
+
return this.client.command('sendWeAppCard', { conversationId, ...sayable.miniProgram });
|
|
152
|
+
throw new Error('不支持的发送内容');
|
|
153
|
+
}
|
|
154
|
+
/* ---------------- 查询/工厂 ---------------- */
|
|
155
|
+
async roomList() {
|
|
156
|
+
const r = await this.command('roomList');
|
|
157
|
+
const arr = (r && (r.rooms || r.list || (Array.isArray(r) ? r : []))) || [];
|
|
158
|
+
return arr.map((x) => new room_js_1.Room(this, { id: x.conversationId || x.id, topic: x.name || x.topic }));
|
|
159
|
+
}
|
|
160
|
+
async contactList() {
|
|
161
|
+
const r = await this.command('contactList');
|
|
162
|
+
const arr = (r && (r.contacts || r.list || (Array.isArray(r) ? r : []))) || [];
|
|
163
|
+
return arr.map((u) => new contact_js_1.Contact(this, this.toContactPayload(u)));
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* 在【已加载的全量通讯录】按条件查找联系人(本地过滤, 非服务端搜陌生人)。
|
|
167
|
+
* @param query 关键词字符串(匹配 name/alias/phone/title/vid 子串), 或 { name?, alias?, id? } 精确匹配。
|
|
168
|
+
* @returns 命中的 Contact 列表(可能为空)。
|
|
169
|
+
*/
|
|
170
|
+
async contactFindAll(query) {
|
|
171
|
+
const keyword = typeof query === 'string'
|
|
172
|
+
? query
|
|
173
|
+
: (query?.name ?? query?.alias ?? query?.id ?? '');
|
|
174
|
+
const r = await this.command('contactSearch', { keyword });
|
|
175
|
+
const arr = (r && (r.contacts || r.list || (Array.isArray(r) ? r : []))) || [];
|
|
176
|
+
let list = arr.map((u) => new contact_js_1.Contact(this, this.toContactPayload(u)));
|
|
177
|
+
if (query && typeof query !== 'string') { // 对象条件: 在子串命中基础上再做精确收窄
|
|
178
|
+
if (query.id)
|
|
179
|
+
list = list.filter((c) => c.id() === query.id);
|
|
180
|
+
if (query.alias)
|
|
181
|
+
list = list.filter((c) => c.alias() === query.alias);
|
|
182
|
+
if (query.name)
|
|
183
|
+
list = list.filter((c) => c.name() === query.name);
|
|
184
|
+
}
|
|
185
|
+
return list;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* 查找单个联系人(取 {@link contactFindAll} 第一个命中)。
|
|
189
|
+
* @param query 关键词字符串或 { name?, alias?, id? }。
|
|
190
|
+
* @returns 命中的第一个 Contact; 无则 undefined。
|
|
191
|
+
*/
|
|
192
|
+
async contactFind(query) {
|
|
193
|
+
const all = await this.contactFindAll(query);
|
|
194
|
+
return all[0];
|
|
195
|
+
}
|
|
196
|
+
/** 建群(成员 vid 列表)。 */
|
|
197
|
+
async roomCreate(memberIdList, topic) {
|
|
198
|
+
const r = await this.command('roomCreate', { userList: memberIdList, topic });
|
|
199
|
+
const id = r && (r.conversationId || r.roomId || r.id);
|
|
200
|
+
return id ? new room_js_1.Room(this, { id, topic }) : undefined;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
exports.Chatboty = Chatboty;
|
|
204
|
+
//# sourceMappingURL=chatboty.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chatboty.js","sourceRoot":"","sources":["../../../src/chatboty.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,2CAAwE;AACxE,yCAGmB;AACnB,oDAA6C;AAC7C,oDAA6C;AAC7C,8CAAuC;AACvC,0DAAmD;AAMnD,MAAa,QAAQ;IAKnB,YAAa,OAAwB;QAHpB,cAAS,GAAG,IAAI,GAAG,EAAyB,CAAA;QAI3D,IAAI,CAAC,MAAM,GAAG,IAAI,0BAAc,CAAC,OAAO,CAAC,CAAA;IAC3C,CAAC;IAED,qBAAqB;IACrB,IAAI,SAAS,KAA0B,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAA,CAAC,CAAC;IAEnE,2EAA2E;IAC3E,IAAI,IAAI,KAA2B,OAAO,IAAI,CAAC,KAAK,CAAA,CAAC,CAAC;IAEtD,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,IAAI,EAAE,CAAA;QACX,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;QACzB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAClB,0DAA0D;QAC1D,KAAK,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;IAChD,CAAC;IAED,KAAK,CAAC,IAAI,KAAqB,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,CAAC,CAAC;IAgBtE,EAAE,CAAE,KAAa,EAAE,CAAW;QAC5B,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC;YAA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