@satorijs/adapter-lark 3.11.8 → 3.12.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/lib/bot.d.ts +5 -5
- package/lib/http.d.ts +6 -3
- package/lib/index.cjs +634 -261
- package/lib/types/acs.d.ts +4 -1
- package/lib/types/aily.d.ts +3 -3
- package/lib/types/apaas.d.ts +190 -28
- package/lib/types/application.d.ts +20 -4
- package/lib/types/approval.d.ts +0 -13
- package/lib/types/attendance.d.ts +11 -5
- package/lib/types/authen.d.ts +8 -2
- package/lib/types/bitable.d.ts +25 -4
- package/lib/types/board.d.ts +56 -0
- package/lib/types/calendar.d.ts +71 -5
- package/lib/types/cardkit.d.ts +2 -2
- package/lib/types/compensation.d.ts +400 -0
- package/lib/types/contact.d.ts +55 -12
- package/lib/types/corehr.d.ts +1287 -79
- package/lib/types/directory.d.ts +3 -41
- package/lib/types/docx.d.ts +23 -0
- package/lib/types/drive.d.ts +107 -90
- package/lib/types/ehr.d.ts +11 -2
- package/lib/types/helpdesk.d.ts +15 -6
- package/lib/types/hire.d.ts +52 -3
- package/lib/types/human_authentication.d.ts +1 -1
- package/lib/types/im.d.ts +77 -21
- package/lib/types/index.d.ts +1670 -105
- package/lib/types/mail.d.ts +106 -16
- package/lib/types/payroll.d.ts +117 -81
- package/lib/types/performance.d.ts +1 -1
- package/lib/types/search.d.ts +4 -1
- package/lib/types/security_and_compliance.d.ts +254 -1
- package/lib/ws.d.ts +30 -0
- package/package.json +6 -3
- package/src/bot.ts +28 -15
- package/src/http.ts +10 -4
- package/src/types/acs.ts +4 -1
- package/src/types/aily.ts +3 -3
- package/src/types/apaas.ts +237 -38
- package/src/types/application.ts +20 -4
- package/src/types/approval.ts +0 -15
- package/src/types/attendance.ts +11 -5
- package/src/types/authen.ts +8 -2
- package/src/types/bitable.ts +25 -4
- package/src/types/board.ts +75 -2
- package/src/types/calendar.ts +88 -5
- package/src/types/cardkit.ts +2 -2
- package/src/types/compensation.ts +485 -0
- package/src/types/contact.ts +55 -12
- package/src/types/corehr.ts +1480 -123
- package/src/types/directory.ts +3 -53
- package/src/types/docx.ts +29 -0
- package/src/types/drive.ts +129 -112
- package/src/types/ehr.ts +11 -2
- package/src/types/helpdesk.ts +15 -6
- package/src/types/hire.ts +66 -3
- package/src/types/human_authentication.ts +1 -1
- package/src/types/im.ts +77 -21
- package/src/types/index.ts +1751 -107
- package/src/types/mail.ts +106 -16
- package/src/types/payroll.ts +146 -103
- package/src/types/performance.ts +1 -1
- package/src/types/search.ts +4 -1
- package/src/types/security_and_compliance.ts +292 -1
- package/src/ws.ts +183 -0
- package/lib/types/api.d.ts +0 -28510
- package/lib/types/internal.d.ts +0 -21
- package/lib/types/message/content.d.ts +0 -433
- package/lib/types/message/index.d.ts +0 -95
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Lark from '.';
|
|
2
|
-
import { Paginated } from '../internal';
|
|
2
|
+
import { Paginated, Pagination } from '../internal';
|
|
3
3
|
declare module '../internal' {
|
|
4
4
|
interface Internal {
|
|
5
5
|
securityAndCompliance: SecurityAndCompliance.Methods;
|
|
@@ -7,8 +7,261 @@ declare module '../internal' {
|
|
|
7
7
|
}
|
|
8
8
|
export declare namespace SecurityAndCompliance {
|
|
9
9
|
interface Methods {
|
|
10
|
+
deviceRecord: DeviceRecord.Methods;
|
|
11
|
+
deviceApplyRecord: DeviceApplyRecord.Methods;
|
|
10
12
|
openapiLog: OpenapiLog.Methods;
|
|
11
13
|
}
|
|
14
|
+
namespace DeviceRecord {
|
|
15
|
+
interface Methods {
|
|
16
|
+
/**
|
|
17
|
+
* 获取客户端设备认证信息
|
|
18
|
+
* @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/security_and_compliance-v2/device_record/mine
|
|
19
|
+
*/
|
|
20
|
+
mine(): Promise<MineResponse>;
|
|
21
|
+
/**
|
|
22
|
+
* 新增设备
|
|
23
|
+
* @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/security_and_compliance-v2/device_record/create
|
|
24
|
+
*/
|
|
25
|
+
create(body: CreateRequest, query?: CreateQuery): Promise<CreateResponse>;
|
|
26
|
+
/**
|
|
27
|
+
* 查询设备信息
|
|
28
|
+
* @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/security_and_compliance-v2/device_record/list
|
|
29
|
+
*/
|
|
30
|
+
list(query?: ListQuery): Paginated<Lark.DeviceRecord>;
|
|
31
|
+
/**
|
|
32
|
+
* 获取设备信息
|
|
33
|
+
* @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/security_and_compliance-v2/device_record/get
|
|
34
|
+
*/
|
|
35
|
+
get(device_record_id: string, query?: GetQuery): Promise<GetResponse>;
|
|
36
|
+
/**
|
|
37
|
+
* 更新设备
|
|
38
|
+
* @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/security_and_compliance-v2/device_record/update
|
|
39
|
+
*/
|
|
40
|
+
update(device_record_id: string, body: UpdateRequest, query?: UpdateQuery): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* 删除设备
|
|
43
|
+
* @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/security_and_compliance-v2/device_record/delete
|
|
44
|
+
*/
|
|
45
|
+
delete(device_record_id: string): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
const enum MineResponseDeviceOwnership {
|
|
48
|
+
/** 未知设备 */
|
|
49
|
+
Unknown = 0,
|
|
50
|
+
/** 个人设备 */
|
|
51
|
+
Personal = 1,
|
|
52
|
+
/** 企业设备 */
|
|
53
|
+
Company = 2
|
|
54
|
+
}
|
|
55
|
+
const enum MineResponseDeviceStatus {
|
|
56
|
+
/** 未知状态 */
|
|
57
|
+
Unknown = 0,
|
|
58
|
+
/** 信任设备 */
|
|
59
|
+
Trusted = 1,
|
|
60
|
+
/** 非信任设备 */
|
|
61
|
+
Untrusted = 2
|
|
62
|
+
}
|
|
63
|
+
interface MineResponse {
|
|
64
|
+
/** 设备认证编码 */
|
|
65
|
+
device_record_id?: string;
|
|
66
|
+
/** 设备归属 */
|
|
67
|
+
device_ownership?: MineResponseDeviceOwnership;
|
|
68
|
+
/** 可信状态 */
|
|
69
|
+
device_status?: MineResponseDeviceStatus;
|
|
70
|
+
}
|
|
71
|
+
const enum CreateRequestDeviceSystem {
|
|
72
|
+
/** Windows */
|
|
73
|
+
Windows = 1,
|
|
74
|
+
/** macOS */
|
|
75
|
+
MacOS = 2,
|
|
76
|
+
/** Linux */
|
|
77
|
+
Linux = 3,
|
|
78
|
+
/** Android */
|
|
79
|
+
Android = 4,
|
|
80
|
+
/** iOS */
|
|
81
|
+
IOS = 5,
|
|
82
|
+
/** OpenHarmony */
|
|
83
|
+
OpenHarmony = 6
|
|
84
|
+
}
|
|
85
|
+
const enum CreateRequestDeviceOwnership {
|
|
86
|
+
/** 未知设备 */
|
|
87
|
+
Unknown = 0,
|
|
88
|
+
/** 个人设备 */
|
|
89
|
+
Personal = 1,
|
|
90
|
+
/** 企业设备 */
|
|
91
|
+
Company = 2
|
|
92
|
+
}
|
|
93
|
+
const enum CreateRequestDeviceStatus {
|
|
94
|
+
/** 未知状态 */
|
|
95
|
+
Unknown = 0,
|
|
96
|
+
/** 信任设备 */
|
|
97
|
+
Trusted = 1,
|
|
98
|
+
/** 非信任设备 */
|
|
99
|
+
Untrusted = 2
|
|
100
|
+
}
|
|
101
|
+
interface CreateRequest {
|
|
102
|
+
/** 操作系统 */
|
|
103
|
+
device_system: CreateRequestDeviceSystem;
|
|
104
|
+
/** 生产序列号 */
|
|
105
|
+
serial_number?: string;
|
|
106
|
+
/** 硬盘序列号 */
|
|
107
|
+
disk_serial_number?: string;
|
|
108
|
+
/** 主板UUID */
|
|
109
|
+
uuid?: string;
|
|
110
|
+
/** MAC地址 */
|
|
111
|
+
mac_address?: string;
|
|
112
|
+
/** Android标识符 */
|
|
113
|
+
android_id?: string;
|
|
114
|
+
/** iOS供应商标识符 */
|
|
115
|
+
idfv?: string;
|
|
116
|
+
/** Harmony供应商标识符 */
|
|
117
|
+
aaid?: string;
|
|
118
|
+
/** 设备归属 */
|
|
119
|
+
device_ownership: CreateRequestDeviceOwnership;
|
|
120
|
+
/** 可信状态 */
|
|
121
|
+
device_status: CreateRequestDeviceStatus;
|
|
122
|
+
/** 最近登录用户ID */
|
|
123
|
+
latest_user_id?: string;
|
|
124
|
+
/** 设备指纹列表 */
|
|
125
|
+
dids?: string[];
|
|
126
|
+
}
|
|
127
|
+
interface CreateQuery {
|
|
128
|
+
/** 此次调用中使用的用户ID的类型 */
|
|
129
|
+
user_id_type?: 'user_id' | 'union_id' | 'open_id';
|
|
130
|
+
}
|
|
131
|
+
interface CreateResponse {
|
|
132
|
+
/** 设备认证编码 */
|
|
133
|
+
device_record_id?: string;
|
|
134
|
+
}
|
|
135
|
+
const enum ListQueryDeviceOwnership {
|
|
136
|
+
/** 未知设备 */
|
|
137
|
+
Unknown = 0,
|
|
138
|
+
/** 个人设备 */
|
|
139
|
+
Personal = 1,
|
|
140
|
+
/** 企业设备 */
|
|
141
|
+
Company = 2
|
|
142
|
+
}
|
|
143
|
+
const enum ListQueryDeviceStatus {
|
|
144
|
+
/** 未知状态 */
|
|
145
|
+
Unknown = 0,
|
|
146
|
+
/** 信任设备 */
|
|
147
|
+
Trusted = 1,
|
|
148
|
+
/** 非信任设备 */
|
|
149
|
+
Untrusted = 2
|
|
150
|
+
}
|
|
151
|
+
const enum ListQueryDeviceTerminalType {
|
|
152
|
+
/** 未知 */
|
|
153
|
+
Unknown = 0,
|
|
154
|
+
/** 移动端 */
|
|
155
|
+
Mobile = 1,
|
|
156
|
+
/** 桌面端 */
|
|
157
|
+
PC = 2
|
|
158
|
+
}
|
|
159
|
+
const enum ListQueryOs {
|
|
160
|
+
/** 未知 */
|
|
161
|
+
Unknown = 0,
|
|
162
|
+
/** Windows */
|
|
163
|
+
Windows = 1,
|
|
164
|
+
/** macOS */
|
|
165
|
+
MacOS = 2,
|
|
166
|
+
/** Linux */
|
|
167
|
+
Linux = 3,
|
|
168
|
+
/** Android */
|
|
169
|
+
Android = 4,
|
|
170
|
+
/** iOS */
|
|
171
|
+
IOS = 5,
|
|
172
|
+
/** 鸿蒙 */
|
|
173
|
+
OpenHarmony = 6
|
|
174
|
+
}
|
|
175
|
+
interface ListQuery extends Pagination {
|
|
176
|
+
/** 设备认证编码 */
|
|
177
|
+
device_record_id?: string;
|
|
178
|
+
/** 当前登录用户ID */
|
|
179
|
+
current_user_id?: string;
|
|
180
|
+
/** 此次调用中使用的用户ID的类型 */
|
|
181
|
+
user_id_type?: 'open_id' | 'union_id' | 'user_id';
|
|
182
|
+
/** 设备名称 */
|
|
183
|
+
device_name?: string;
|
|
184
|
+
/** 生产序列号 */
|
|
185
|
+
serial_number?: string;
|
|
186
|
+
/** 硬盘序列号 */
|
|
187
|
+
disk_serial_number?: string;
|
|
188
|
+
/** MAC地址 */
|
|
189
|
+
mac_address?: string;
|
|
190
|
+
/** Android标识符 */
|
|
191
|
+
android_id?: string;
|
|
192
|
+
/** 主板UUID */
|
|
193
|
+
uuid?: string;
|
|
194
|
+
/** iOS供应商标识符 */
|
|
195
|
+
idfv?: string;
|
|
196
|
+
/** Harmony供应商标识符 */
|
|
197
|
+
aaid?: string;
|
|
198
|
+
/** 设备归属 */
|
|
199
|
+
device_ownership?: ListQueryDeviceOwnership;
|
|
200
|
+
/** 可信状态 */
|
|
201
|
+
device_status?: ListQueryDeviceStatus;
|
|
202
|
+
/** 设备类型 */
|
|
203
|
+
device_terminal_type?: ListQueryDeviceTerminalType;
|
|
204
|
+
/** 设备操作系统 */
|
|
205
|
+
os?: ListQueryOs;
|
|
206
|
+
/** 最近登录用户ID */
|
|
207
|
+
latest_user_id?: string;
|
|
208
|
+
/** 设备指纹 */
|
|
209
|
+
did?: string;
|
|
210
|
+
}
|
|
211
|
+
interface GetQuery {
|
|
212
|
+
/** 此次调用中使用的用户ID的类型 */
|
|
213
|
+
user_id_type?: 'user_id' | 'union_id' | 'open_id';
|
|
214
|
+
}
|
|
215
|
+
interface GetResponse {
|
|
216
|
+
/** 设备记录 */
|
|
217
|
+
device_record?: Lark.DeviceRecord;
|
|
218
|
+
}
|
|
219
|
+
const enum UpdateRequestDeviceOwnership {
|
|
220
|
+
/** 未知设备 */
|
|
221
|
+
Unknown = 0,
|
|
222
|
+
/** 个人设备 */
|
|
223
|
+
Personal = 1,
|
|
224
|
+
/** 企业设备 */
|
|
225
|
+
Company = 2
|
|
226
|
+
}
|
|
227
|
+
const enum UpdateRequestDeviceStatus {
|
|
228
|
+
/** 未知状态 */
|
|
229
|
+
Unknown = 0,
|
|
230
|
+
/** 信任设备 */
|
|
231
|
+
Trusted = 1,
|
|
232
|
+
/** 非信任设备 */
|
|
233
|
+
Untrusted = 2
|
|
234
|
+
}
|
|
235
|
+
interface UpdateRequest {
|
|
236
|
+
/** 设备归属 */
|
|
237
|
+
device_ownership: UpdateRequestDeviceOwnership;
|
|
238
|
+
/** 可信状态 */
|
|
239
|
+
device_status: UpdateRequestDeviceStatus;
|
|
240
|
+
/** 最近登录用户ID */
|
|
241
|
+
latest_user_id?: string;
|
|
242
|
+
/** 设备指纹列表 */
|
|
243
|
+
dids?: string[];
|
|
244
|
+
}
|
|
245
|
+
interface UpdateQuery {
|
|
246
|
+
/** 版本号 */
|
|
247
|
+
version: string;
|
|
248
|
+
/** 此次调用中使用的用户ID的类型 */
|
|
249
|
+
user_id_type?: 'user_id' | 'union_id' | 'open_id';
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
namespace DeviceApplyRecord {
|
|
253
|
+
interface Methods {
|
|
254
|
+
/**
|
|
255
|
+
* 审批设备申报
|
|
256
|
+
* @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/security_and_compliance-v2/device_apply_record/update
|
|
257
|
+
*/
|
|
258
|
+
update(device_apply_record_id: string, body: UpdateRequest): Promise<void>;
|
|
259
|
+
}
|
|
260
|
+
interface UpdateRequest {
|
|
261
|
+
/** 是否审批通过 */
|
|
262
|
+
is_approved: boolean;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
12
265
|
namespace OpenapiLog {
|
|
13
266
|
interface Methods {
|
|
14
267
|
/**
|
package/lib/ws.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Adapter, Context, Schema } from '@satorijs/core';
|
|
2
|
+
import { LarkBot } from './bot';
|
|
3
|
+
import pb from 'protobufjs/light';
|
|
4
|
+
interface FrameSegment {
|
|
5
|
+
message_id: string;
|
|
6
|
+
sum: number;
|
|
7
|
+
seq: number;
|
|
8
|
+
data: Uint8Array;
|
|
9
|
+
}
|
|
10
|
+
export declare class WsClient<C extends Context = Context> extends Adapter.WsClient<C, LarkBot<C, LarkBot.BaseConfig & WsClient.Options>> {
|
|
11
|
+
_deviceId: string;
|
|
12
|
+
_serviceId: number;
|
|
13
|
+
_pingInterval: number;
|
|
14
|
+
_ping: NodeJS.Timeout;
|
|
15
|
+
_cache: Record<string, FrameSegment[]>;
|
|
16
|
+
_frame: pb.Type;
|
|
17
|
+
constructor(ctx: C, bot: LarkBot<C, LarkBot.BaseConfig & WsClient.Options>);
|
|
18
|
+
prepare(): Promise<WebSocket>;
|
|
19
|
+
ping(): void;
|
|
20
|
+
accept(): Promise<void>;
|
|
21
|
+
send(frame: any): void;
|
|
22
|
+
retrieve(seg: FrameSegment): Uint8Array | undefined;
|
|
23
|
+
}
|
|
24
|
+
export declare namespace WsClient {
|
|
25
|
+
interface Options extends Adapter.WsClientConfig {
|
|
26
|
+
protocol: 'ws';
|
|
27
|
+
}
|
|
28
|
+
const Options: Schema<Options>;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@satorijs/adapter-lark",
|
|
3
3
|
"description": "Lark (飞书) Adapter for Satorijs",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.12.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.cjs",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
@@ -34,13 +34,16 @@
|
|
|
34
34
|
"chat"
|
|
35
35
|
],
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@cordisjs/plugin-server": "^0.2.
|
|
37
|
+
"@cordisjs/plugin-server": "^0.2.9",
|
|
38
38
|
"@satorijs/core": "^4.5.2",
|
|
39
39
|
"cordis": "^3.18.1",
|
|
40
|
-
"cosmokit": "^1.
|
|
40
|
+
"cosmokit": "^1.8.1",
|
|
41
41
|
"dedent": "^1.5.3"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"@satorijs/core": "^4.5.2"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"protobufjs": "^8.0.0"
|
|
45
48
|
}
|
|
46
49
|
}
|
package/src/bot.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Bot, Context, h, HTTP, Schema, Time, Universal } from '@satorijs/core'
|
|
2
2
|
import { Im } from './types'
|
|
3
3
|
import { HttpServer } from './http'
|
|
4
|
+
import { WsClient } from './ws'
|
|
4
5
|
import { LarkMessageEncoder } from './message'
|
|
5
6
|
import { Internal } from './internal'
|
|
6
7
|
import * as Utils from './utils'
|
|
@@ -14,7 +15,7 @@ const fileTypeMap: Record<Exclude<Im.File.CreateForm['file_type'], 'stream'>, st
|
|
|
14
15
|
ppt: ['application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
export class LarkBot<C extends Context = Context> extends Bot<C,
|
|
18
|
+
export class LarkBot<C extends Context = Context, T extends LarkBot.Config = LarkBot.Config> extends Bot<C, T> {
|
|
18
19
|
static inject = ['server', 'http']
|
|
19
20
|
static MessageEncoder = LarkMessageEncoder
|
|
20
21
|
|
|
@@ -23,7 +24,7 @@ export class LarkBot<C extends Context = Context> extends Bot<C, LarkBot.Config>
|
|
|
23
24
|
assetsQuester: HTTP
|
|
24
25
|
internal: Internal<C>
|
|
25
26
|
|
|
26
|
-
constructor(ctx: C, config:
|
|
27
|
+
constructor(ctx: C, config: T) {
|
|
27
28
|
super(ctx, config, 'lark')
|
|
28
29
|
|
|
29
30
|
this.http = ctx.http.extend({
|
|
@@ -32,7 +33,11 @@ export class LarkBot<C extends Context = Context> extends Bot<C, LarkBot.Config>
|
|
|
32
33
|
this.assetsQuester = ctx.http
|
|
33
34
|
this.internal = new Internal(this)
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
if (config.protocol === 'http') {
|
|
37
|
+
ctx.plugin(HttpServer, this)
|
|
38
|
+
} else if (config.protocol === 'ws') {
|
|
39
|
+
ctx.plugin(WsClient, this as any)
|
|
40
|
+
}
|
|
36
41
|
|
|
37
42
|
this.defineInternalRoute('/*path', async ({ params, method, headers, body, query }) => {
|
|
38
43
|
const response = await this.http('/' + params.path, {
|
|
@@ -78,6 +83,7 @@ export class LarkBot<C extends Context = Context> extends Bot<C, LarkBot.Config>
|
|
|
78
83
|
// 剩余有效期小于 30 分钟时,调用本接口会返回一个新的 tenant_access_token,此时会同时存在两个有效的 tenant_access_token。
|
|
79
84
|
// 剩余有效期大于等于 30 分钟时,调用本接口会返回原有的 tenant_access_token。
|
|
80
85
|
// 初次获得 token 后的半小时内必须刷新一次,因为初次获得的 token 可能是 1.5 小时前生成的。
|
|
86
|
+
if (!this.isActive) return
|
|
81
87
|
let timeout = Time.minute * 20
|
|
82
88
|
try {
|
|
83
89
|
const { tenant_access_token: token } = await this.internal.auth.tenantAccessTokenInternal({
|
|
@@ -170,35 +176,42 @@ export class LarkBot<C extends Context = Context> extends Bot<C, LarkBot.Config>
|
|
|
170
176
|
}
|
|
171
177
|
|
|
172
178
|
export namespace LarkBot {
|
|
173
|
-
export interface
|
|
179
|
+
export interface BaseConfig extends HTTP.Config {
|
|
174
180
|
appId: string
|
|
175
181
|
appSecret: string
|
|
176
|
-
encryptKey?: string
|
|
177
|
-
verificationToken?: string
|
|
178
182
|
}
|
|
179
183
|
|
|
184
|
+
export type Config = BaseConfig & (HttpServer.Options | WsClient.Options)
|
|
185
|
+
|
|
180
186
|
export const Config: Schema<Config> = Schema.intersect([
|
|
181
187
|
Schema.object({
|
|
182
|
-
platform: Schema.union(['feishu', 'lark']).
|
|
188
|
+
platform: Schema.union(['feishu', 'lark']).default('feishu').description('平台名称。'),
|
|
183
189
|
appId: Schema.string().required().description('机器人的应用 ID。'),
|
|
184
190
|
appSecret: Schema.string().role('secret').required().description('机器人的应用密钥。'),
|
|
185
|
-
|
|
186
|
-
|
|
191
|
+
protocol: process.env.KOISHI_ENV === 'browser'
|
|
192
|
+
? Schema.const('ws').default('ws')
|
|
193
|
+
: Schema.union(['http', 'ws']).description('选择要使用的协议。').default('http'),
|
|
187
194
|
}),
|
|
188
195
|
Schema.union([
|
|
189
196
|
Schema.intersect([
|
|
190
197
|
Schema.object({
|
|
191
|
-
platform: Schema.const('
|
|
198
|
+
platform: Schema.const('lark').required(),
|
|
192
199
|
}),
|
|
193
|
-
HTTP.createConfig('https://open.
|
|
194
|
-
|
|
200
|
+
HTTP.createConfig('https://open.larksuite.com/open-apis'),
|
|
201
|
+
Schema.union([
|
|
202
|
+
HttpServer.createConfig('/lark'),
|
|
203
|
+
WsClient.Options,
|
|
204
|
+
]),
|
|
195
205
|
]),
|
|
196
206
|
Schema.intersect([
|
|
197
207
|
Schema.object({
|
|
198
|
-
platform: Schema.const('
|
|
208
|
+
platform: Schema.const('feishu') as any,
|
|
199
209
|
}),
|
|
200
|
-
HTTP.createConfig('https://open.
|
|
201
|
-
|
|
210
|
+
HTTP.createConfig('https://open.feishu.cn/open-apis'),
|
|
211
|
+
Schema.union([
|
|
212
|
+
HttpServer.createConfig('/feishu'),
|
|
213
|
+
WsClient.Options,
|
|
214
|
+
]),
|
|
202
215
|
]),
|
|
203
216
|
]),
|
|
204
217
|
])
|
package/src/http.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {} from '@cordisjs/plugin-server'
|
|
|
3
3
|
import { LarkBot } from './bot'
|
|
4
4
|
import { adaptSession, Cipher, EventPayload } from './utils'
|
|
5
5
|
|
|
6
|
-
export class HttpServer<C extends Context = Context> extends Adapter<C, LarkBot<C>> {
|
|
6
|
+
export class HttpServer<C extends Context = Context> extends Adapter<C, LarkBot<C, LarkBot.BaseConfig & HttpServer.Options>> {
|
|
7
7
|
static inject = ['server']
|
|
8
8
|
|
|
9
9
|
private logger: Logger
|
|
@@ -14,14 +14,14 @@ export class HttpServer<C extends Context = Context> extends Adapter<C, LarkBot<
|
|
|
14
14
|
this.logger = ctx.logger('lark')
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
fork(ctx: C, bot: LarkBot<C>) {
|
|
17
|
+
fork(ctx: C, bot: LarkBot<C, LarkBot.BaseConfig & HttpServer.Options>) {
|
|
18
18
|
super.fork(ctx, bot)
|
|
19
19
|
|
|
20
20
|
this._refreshCipher()
|
|
21
21
|
return bot.initialize()
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
async connect(bot: LarkBot) {
|
|
24
|
+
async connect(bot: LarkBot<C, LarkBot.BaseConfig & HttpServer.Options>) {
|
|
25
25
|
const { path } = bot.config
|
|
26
26
|
bot.ctx.server.post(path, (ctx) => {
|
|
27
27
|
this._refreshCipher()
|
|
@@ -70,7 +70,7 @@ export class HttpServer<C extends Context = Context> extends Adapter<C, LarkBot<
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
// dispatch message
|
|
73
|
-
bot.logger.debug('received
|
|
73
|
+
bot.logger.debug('received decrypted event: %o', body)
|
|
74
74
|
this.dispatchSession(body)
|
|
75
75
|
|
|
76
76
|
// Lark requires 200 OK response to make sure event is received
|
|
@@ -124,15 +124,21 @@ export class HttpServer<C extends Context = Context> extends Adapter<C, LarkBot<
|
|
|
124
124
|
|
|
125
125
|
export namespace HttpServer {
|
|
126
126
|
export interface Options {
|
|
127
|
+
protocol: 'http'
|
|
127
128
|
selfUrl?: string
|
|
128
129
|
path?: string
|
|
130
|
+
encryptKey?: string
|
|
131
|
+
verificationToken?: string
|
|
129
132
|
verifyToken?: boolean
|
|
130
133
|
verifySignature?: boolean
|
|
131
134
|
}
|
|
132
135
|
|
|
133
136
|
export const createConfig = (path: string): Schema<Options> => Schema.object({
|
|
137
|
+
protocol: Schema.const('http'),
|
|
134
138
|
path: Schema.string().role('url').description('要连接的服务器地址。').default(path),
|
|
135
139
|
selfUrl: Schema.string().role('link').description('服务器暴露在公网的地址。缺省时将使用全局配置。'),
|
|
140
|
+
encryptKey: Schema.string().role('secret').description('机器人的 Encrypt Key。'),
|
|
141
|
+
verificationToken: Schema.string().description('事件推送的验证令牌。'),
|
|
136
142
|
verifyToken: Schema.boolean().description('是否验证令牌。'),
|
|
137
143
|
verifySignature: Schema.boolean().description('是否验证签名。'),
|
|
138
144
|
}).description('服务端设置')
|
package/src/types/acs.ts
CHANGED
|
@@ -226,7 +226,10 @@ export namespace Acs {
|
|
|
226
226
|
export interface ListQuery extends Pagination {
|
|
227
227
|
/** 记录开始时间,单位秒 */
|
|
228
228
|
from: number
|
|
229
|
-
/**
|
|
229
|
+
/**
|
|
230
|
+
* 记录结束时间,单位秒,
|
|
231
|
+
* 时间跨度不能超过30天
|
|
232
|
+
*/
|
|
230
233
|
to: number
|
|
231
234
|
/** 门禁设备 ID */
|
|
232
235
|
device_id?: string
|
package/src/types/aily.ts
CHANGED
|
@@ -71,17 +71,17 @@ export namespace Aily {
|
|
|
71
71
|
export namespace AilyMessage {
|
|
72
72
|
export interface Methods {
|
|
73
73
|
/**
|
|
74
|
-
*
|
|
74
|
+
* 发送 Aily 消息
|
|
75
75
|
* @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/aily-v1/aily_session-aily_message/create
|
|
76
76
|
*/
|
|
77
77
|
create(aily_session_id: string, body: CreateRequest): Promise<CreateResponse>
|
|
78
78
|
/**
|
|
79
|
-
*
|
|
79
|
+
* 获取 Aily 消息
|
|
80
80
|
* @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/aily-v1/aily_session-aily_message/get
|
|
81
81
|
*/
|
|
82
82
|
get(aily_session_id: string, aily_message_id: string): Promise<GetResponse>
|
|
83
83
|
/**
|
|
84
|
-
*
|
|
84
|
+
* 列出 Aily 消息
|
|
85
85
|
* @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/aily-v1/aily_session-aily_message/list
|
|
86
86
|
*/
|
|
87
87
|
list(aily_session_id: string, query?: ListQuery): Paginated<Lark.AilyMessage, 'messages'>
|