loopzero-gateway-feishu-lark 0.0.0-stage → 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/CHANGELOG.md +32 -0
- package/LICENSE +201 -0
- package/README.md +107 -2
- package/dist/index.cjs +399 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +242 -0
- package/dist/index.d.ts +242 -0
- package/dist/index.js +395 -0
- package/dist/index.js.map +1 -0
- package/package.json +73 -3
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { BasePlatformAdapter, OutboundMessage, SendResult, MessageEvent } from 'loopzero-gateway';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options and seams for `FeishuLarkAdapter`.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* What one open-platform call answered: `code` 0 is success, anything else is Lark's own error
|
|
10
|
+
* code with its `msg`.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
interface LarkApiResult {
|
|
15
|
+
readonly code: number;
|
|
16
|
+
readonly msg?: string;
|
|
17
|
+
/** The created or replied message's id, on a successful send. */
|
|
18
|
+
readonly messageId?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Callbacks the long connection reports to.
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
interface LarkConnectionHandlers {
|
|
26
|
+
/** One `im.message.receive_v1` event, as the SDK's dispatcher hands it over. Must not throw. */
|
|
27
|
+
readonly onMessage: (data: unknown) => void;
|
|
28
|
+
/** The SDK gave up: initial connect refused for good, or its reconnects exhausted (D7). */
|
|
29
|
+
readonly onError: (err: Error) => void;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The part of the Lark open platform the adapter uses. The default is built from
|
|
33
|
+
* `@larksuiteoapi/node-sdk`; tests pass a scripted one.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
interface LarkTransport {
|
|
38
|
+
/** Fetch a tenant access token, which proves the app id and secret. */
|
|
39
|
+
tenantToken(): Promise<LarkApiResult>;
|
|
40
|
+
/** Open the long connection; resolves once it is up, rejects when the first connect fails. */
|
|
41
|
+
start(handlers: LarkConnectionHandlers): Promise<void>;
|
|
42
|
+
/** Send `text` as a new message to the chat `chatId`. */
|
|
43
|
+
createMessage(chatId: string, text: string): Promise<LarkApiResult>;
|
|
44
|
+
/** Send `text` as a reply to the message `messageId`. */
|
|
45
|
+
replyMessage(messageId: string, text: string): Promise<LarkApiResult>;
|
|
46
|
+
/** Close the long connection. Idempotent. */
|
|
47
|
+
close(): void;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Construction options for `FeishuLarkAdapter`.
|
|
51
|
+
*
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
interface FeishuLarkAdapterOptions {
|
|
55
|
+
/** The app's App ID, `cli_` followed by 16 hex characters. */
|
|
56
|
+
readonly appId: string;
|
|
57
|
+
/**
|
|
58
|
+
* The feishu-lark app's App Secret. With the App ID it fetches the tenant access token every call
|
|
59
|
+
* uses and authenticates the long connection.
|
|
60
|
+
*
|
|
61
|
+
* @platform-term App Secret
|
|
62
|
+
* @issued-at the Feishu or Lark developer console, Credentials & Basic Info page of the custom app
|
|
63
|
+
*/
|
|
64
|
+
readonly appSecret: string;
|
|
65
|
+
/** Which open platform the app lives on: `"feishu"` (open.feishu.cn, the default) or `"lark"` (open.larksuite.com). */
|
|
66
|
+
readonly domain?: "feishu" | "lark";
|
|
67
|
+
/** Test seam: the open-platform transport. Default one built from `@larksuiteoapi/node-sdk`. */
|
|
68
|
+
readonly transport?: LarkTransport;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* `FeishuLarkAdapter` — `BasePlatformAdapter` over the Feishu/Lark open platform: events from the
|
|
73
|
+
* SDK's long connection, replies through `im.message.create` and `im.message.reply`.
|
|
74
|
+
*
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Feishu/Lark adapter for one custom app.
|
|
80
|
+
*
|
|
81
|
+
* `connect()` fetches a tenant access token, which proves the App ID and Secret, then opens the
|
|
82
|
+
* long connection; it answers `false`, never a throw, when either fails or 10000 ms pass. Each
|
|
83
|
+
* `im.message.receive_v1` text message from a user becomes a `FeishuLarkMessageEvent` once (the
|
|
84
|
+
* last 1000 event ids are remembered, so Lark's redelivery is not answered twice), delivered after
|
|
85
|
+
* the dispatcher has returned, so the SDK acknowledges it inside Lark's window. The SDK's own
|
|
86
|
+
* reconnect stays on; when it gives up, the adapter logs one line and reads as disconnected (D7).
|
|
87
|
+
*
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
declare class FeishuLarkAdapter extends BasePlatformAdapter {
|
|
91
|
+
readonly platform: "feishu_lark";
|
|
92
|
+
private readonly transport;
|
|
93
|
+
private readonly seen;
|
|
94
|
+
private handler;
|
|
95
|
+
private connected;
|
|
96
|
+
private connecting;
|
|
97
|
+
private warnedAboutHtml;
|
|
98
|
+
/** Bumped by every `disconnect()` and every connect that gave up, so a late answer is dropped. */
|
|
99
|
+
private generation;
|
|
100
|
+
/** @throws Error when `appId` is not `cli_` followed by 16 hex characters */
|
|
101
|
+
constructor(opts: FeishuLarkAdapterOptions);
|
|
102
|
+
connect(): Promise<boolean>;
|
|
103
|
+
disconnect(): Promise<void>;
|
|
104
|
+
sendMessage(out: OutboundMessage): Promise<SendResult>;
|
|
105
|
+
private sendText;
|
|
106
|
+
onInbound(handler: (event: MessageEvent) => Promise<void>): () => void;
|
|
107
|
+
/** Deliver an event that arrived out of band, through `runHandler`. */
|
|
108
|
+
deliver(event: MessageEvent): Promise<"ok" | "no_handler" | "handler_threw">;
|
|
109
|
+
/** The text to send: markdown loses its markers, html goes as is with one warning. */
|
|
110
|
+
protected outboundText(out: OutboundMessage): string;
|
|
111
|
+
/**
|
|
112
|
+
* Prove the credentials, then open the long connection. An attempt overtaken by `disconnect()`,
|
|
113
|
+
* or by its own deadline, stops at the next step and leaves nothing open.
|
|
114
|
+
*/
|
|
115
|
+
private openSession;
|
|
116
|
+
private onConnectionLost;
|
|
117
|
+
/** Runs inside the SDK's dispatcher: it must return at once and never throw. */
|
|
118
|
+
private onMessage;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* `feishuLarkChannel` — the Feishu/Lark channel described as data, with environment bindings.
|
|
123
|
+
*
|
|
124
|
+
* Typed locally on purpose: the object is structurally a `ChannelDescriptor`, but a published
|
|
125
|
+
* `.d.ts` must not name core types an older peer lacks.
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
type Config = Readonly<Record<string, unknown>>;
|
|
129
|
+
/** One configuration field, shaped like the core's `ChannelConfigField` (typed locally). */
|
|
130
|
+
interface ConfigField {
|
|
131
|
+
readonly key: string;
|
|
132
|
+
readonly required: boolean;
|
|
133
|
+
readonly secret: boolean;
|
|
134
|
+
readonly description: string;
|
|
135
|
+
readonly env: string;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The Feishu/Lark channel: it opens its own long connection in `connect()`, so it needs no
|
|
139
|
+
* webhook route.
|
|
140
|
+
*
|
|
141
|
+
* `create` refuses a missing or wrongly typed value, a malformed `appId` and an unknown `domain`
|
|
142
|
+
* with `GatewayConfigurationError` (prefix `gateway-feishu-lark`) (code `invalid_config`, the key in the message); it
|
|
143
|
+
* performs no network call.
|
|
144
|
+
*
|
|
145
|
+
* @public
|
|
146
|
+
*/
|
|
147
|
+
declare const feishuLarkChannel: {
|
|
148
|
+
platform: "feishu_lark";
|
|
149
|
+
transport: "socket";
|
|
150
|
+
senderIdentity: "authenticated";
|
|
151
|
+
config: readonly ConfigField[];
|
|
152
|
+
create(config: Config): FeishuLarkAdapter;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* The default `LarkTransport`, over `@larksuiteoapi/node-sdk`'s `Client` and long-connection
|
|
157
|
+
* `WSClient`. The SDK is an optional peer, loaded on first use.
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
interface SdkApiAnswer {
|
|
161
|
+
readonly code?: number;
|
|
162
|
+
readonly msg?: string;
|
|
163
|
+
readonly data?: {
|
|
164
|
+
readonly message_id?: string;
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/** The part of `@larksuiteoapi/node-sdk` this transport uses. */
|
|
168
|
+
interface LarkSdk {
|
|
169
|
+
readonly Domain: {
|
|
170
|
+
readonly Feishu: number;
|
|
171
|
+
readonly Lark: number;
|
|
172
|
+
};
|
|
173
|
+
readonly Client: new (params: {
|
|
174
|
+
appId: string;
|
|
175
|
+
appSecret: string;
|
|
176
|
+
domain: number;
|
|
177
|
+
}) => {
|
|
178
|
+
readonly auth: {
|
|
179
|
+
readonly tenantAccessToken: {
|
|
180
|
+
internal(payload: {
|
|
181
|
+
data: {
|
|
182
|
+
app_id: string;
|
|
183
|
+
app_secret: string;
|
|
184
|
+
};
|
|
185
|
+
}): Promise<SdkApiAnswer>;
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
readonly im: {
|
|
189
|
+
readonly message: {
|
|
190
|
+
create(payload: {
|
|
191
|
+
params: {
|
|
192
|
+
receive_id_type: "chat_id";
|
|
193
|
+
};
|
|
194
|
+
data: {
|
|
195
|
+
receive_id: string;
|
|
196
|
+
msg_type: "text";
|
|
197
|
+
content: string;
|
|
198
|
+
};
|
|
199
|
+
}): Promise<SdkApiAnswer>;
|
|
200
|
+
reply(payload: {
|
|
201
|
+
path: {
|
|
202
|
+
message_id: string;
|
|
203
|
+
};
|
|
204
|
+
data: {
|
|
205
|
+
msg_type: "text";
|
|
206
|
+
content: string;
|
|
207
|
+
};
|
|
208
|
+
}): Promise<SdkApiAnswer>;
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
readonly WSClient: new (params: {
|
|
213
|
+
appId: string;
|
|
214
|
+
appSecret: string;
|
|
215
|
+
domain: number;
|
|
216
|
+
onReady?: () => void;
|
|
217
|
+
onError?: (err: Error) => void;
|
|
218
|
+
}) => {
|
|
219
|
+
start(params: {
|
|
220
|
+
eventDispatcher: unknown;
|
|
221
|
+
}): Promise<void>;
|
|
222
|
+
close(): void;
|
|
223
|
+
};
|
|
224
|
+
readonly EventDispatcher: new (params: Record<string, never>) => {
|
|
225
|
+
register(handles: Record<string, (data: unknown) => Promise<void>>): unknown;
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
/** Options the default transport needs. */
|
|
229
|
+
interface LarkTransportOptions {
|
|
230
|
+
readonly appId: string;
|
|
231
|
+
readonly appSecret: string;
|
|
232
|
+
readonly domain?: "feishu" | "lark";
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Build the transport over the SDK. `load` is the test seam: it returns the SDK module.
|
|
236
|
+
*
|
|
237
|
+
* The long connection keeps the SDK's own reconnect (`autoReconnect` left at its default): the SDK
|
|
238
|
+
* retries on the interval Feishu's servers send, and the adapter runs no loop of its own (plan D7).
|
|
239
|
+
*/
|
|
240
|
+
declare function createLarkTransport(options: LarkTransportOptions, load?: () => Promise<LarkSdk>): LarkTransport;
|
|
241
|
+
|
|
242
|
+
export { FeishuLarkAdapter, type FeishuLarkAdapterOptions, type LarkApiResult, type LarkConnectionHandlers, type LarkSdk, type LarkTransport, type LarkTransportOptions, createLarkTransport, feishuLarkChannel };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { BasePlatformAdapter, OutboundMessage, SendResult, MessageEvent } from 'loopzero-gateway';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options and seams for `FeishuLarkAdapter`.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* What one open-platform call answered: `code` 0 is success, anything else is Lark's own error
|
|
10
|
+
* code with its `msg`.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
interface LarkApiResult {
|
|
15
|
+
readonly code: number;
|
|
16
|
+
readonly msg?: string;
|
|
17
|
+
/** The created or replied message's id, on a successful send. */
|
|
18
|
+
readonly messageId?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Callbacks the long connection reports to.
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
interface LarkConnectionHandlers {
|
|
26
|
+
/** One `im.message.receive_v1` event, as the SDK's dispatcher hands it over. Must not throw. */
|
|
27
|
+
readonly onMessage: (data: unknown) => void;
|
|
28
|
+
/** The SDK gave up: initial connect refused for good, or its reconnects exhausted (D7). */
|
|
29
|
+
readonly onError: (err: Error) => void;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The part of the Lark open platform the adapter uses. The default is built from
|
|
33
|
+
* `@larksuiteoapi/node-sdk`; tests pass a scripted one.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
interface LarkTransport {
|
|
38
|
+
/** Fetch a tenant access token, which proves the app id and secret. */
|
|
39
|
+
tenantToken(): Promise<LarkApiResult>;
|
|
40
|
+
/** Open the long connection; resolves once it is up, rejects when the first connect fails. */
|
|
41
|
+
start(handlers: LarkConnectionHandlers): Promise<void>;
|
|
42
|
+
/** Send `text` as a new message to the chat `chatId`. */
|
|
43
|
+
createMessage(chatId: string, text: string): Promise<LarkApiResult>;
|
|
44
|
+
/** Send `text` as a reply to the message `messageId`. */
|
|
45
|
+
replyMessage(messageId: string, text: string): Promise<LarkApiResult>;
|
|
46
|
+
/** Close the long connection. Idempotent. */
|
|
47
|
+
close(): void;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Construction options for `FeishuLarkAdapter`.
|
|
51
|
+
*
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
interface FeishuLarkAdapterOptions {
|
|
55
|
+
/** The app's App ID, `cli_` followed by 16 hex characters. */
|
|
56
|
+
readonly appId: string;
|
|
57
|
+
/**
|
|
58
|
+
* The feishu-lark app's App Secret. With the App ID it fetches the tenant access token every call
|
|
59
|
+
* uses and authenticates the long connection.
|
|
60
|
+
*
|
|
61
|
+
* @platform-term App Secret
|
|
62
|
+
* @issued-at the Feishu or Lark developer console, Credentials & Basic Info page of the custom app
|
|
63
|
+
*/
|
|
64
|
+
readonly appSecret: string;
|
|
65
|
+
/** Which open platform the app lives on: `"feishu"` (open.feishu.cn, the default) or `"lark"` (open.larksuite.com). */
|
|
66
|
+
readonly domain?: "feishu" | "lark";
|
|
67
|
+
/** Test seam: the open-platform transport. Default one built from `@larksuiteoapi/node-sdk`. */
|
|
68
|
+
readonly transport?: LarkTransport;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* `FeishuLarkAdapter` — `BasePlatformAdapter` over the Feishu/Lark open platform: events from the
|
|
73
|
+
* SDK's long connection, replies through `im.message.create` and `im.message.reply`.
|
|
74
|
+
*
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Feishu/Lark adapter for one custom app.
|
|
80
|
+
*
|
|
81
|
+
* `connect()` fetches a tenant access token, which proves the App ID and Secret, then opens the
|
|
82
|
+
* long connection; it answers `false`, never a throw, when either fails or 10000 ms pass. Each
|
|
83
|
+
* `im.message.receive_v1` text message from a user becomes a `FeishuLarkMessageEvent` once (the
|
|
84
|
+
* last 1000 event ids are remembered, so Lark's redelivery is not answered twice), delivered after
|
|
85
|
+
* the dispatcher has returned, so the SDK acknowledges it inside Lark's window. The SDK's own
|
|
86
|
+
* reconnect stays on; when it gives up, the adapter logs one line and reads as disconnected (D7).
|
|
87
|
+
*
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
declare class FeishuLarkAdapter extends BasePlatformAdapter {
|
|
91
|
+
readonly platform: "feishu_lark";
|
|
92
|
+
private readonly transport;
|
|
93
|
+
private readonly seen;
|
|
94
|
+
private handler;
|
|
95
|
+
private connected;
|
|
96
|
+
private connecting;
|
|
97
|
+
private warnedAboutHtml;
|
|
98
|
+
/** Bumped by every `disconnect()` and every connect that gave up, so a late answer is dropped. */
|
|
99
|
+
private generation;
|
|
100
|
+
/** @throws Error when `appId` is not `cli_` followed by 16 hex characters */
|
|
101
|
+
constructor(opts: FeishuLarkAdapterOptions);
|
|
102
|
+
connect(): Promise<boolean>;
|
|
103
|
+
disconnect(): Promise<void>;
|
|
104
|
+
sendMessage(out: OutboundMessage): Promise<SendResult>;
|
|
105
|
+
private sendText;
|
|
106
|
+
onInbound(handler: (event: MessageEvent) => Promise<void>): () => void;
|
|
107
|
+
/** Deliver an event that arrived out of band, through `runHandler`. */
|
|
108
|
+
deliver(event: MessageEvent): Promise<"ok" | "no_handler" | "handler_threw">;
|
|
109
|
+
/** The text to send: markdown loses its markers, html goes as is with one warning. */
|
|
110
|
+
protected outboundText(out: OutboundMessage): string;
|
|
111
|
+
/**
|
|
112
|
+
* Prove the credentials, then open the long connection. An attempt overtaken by `disconnect()`,
|
|
113
|
+
* or by its own deadline, stops at the next step and leaves nothing open.
|
|
114
|
+
*/
|
|
115
|
+
private openSession;
|
|
116
|
+
private onConnectionLost;
|
|
117
|
+
/** Runs inside the SDK's dispatcher: it must return at once and never throw. */
|
|
118
|
+
private onMessage;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* `feishuLarkChannel` — the Feishu/Lark channel described as data, with environment bindings.
|
|
123
|
+
*
|
|
124
|
+
* Typed locally on purpose: the object is structurally a `ChannelDescriptor`, but a published
|
|
125
|
+
* `.d.ts` must not name core types an older peer lacks.
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
type Config = Readonly<Record<string, unknown>>;
|
|
129
|
+
/** One configuration field, shaped like the core's `ChannelConfigField` (typed locally). */
|
|
130
|
+
interface ConfigField {
|
|
131
|
+
readonly key: string;
|
|
132
|
+
readonly required: boolean;
|
|
133
|
+
readonly secret: boolean;
|
|
134
|
+
readonly description: string;
|
|
135
|
+
readonly env: string;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The Feishu/Lark channel: it opens its own long connection in `connect()`, so it needs no
|
|
139
|
+
* webhook route.
|
|
140
|
+
*
|
|
141
|
+
* `create` refuses a missing or wrongly typed value, a malformed `appId` and an unknown `domain`
|
|
142
|
+
* with `GatewayConfigurationError` (prefix `gateway-feishu-lark`) (code `invalid_config`, the key in the message); it
|
|
143
|
+
* performs no network call.
|
|
144
|
+
*
|
|
145
|
+
* @public
|
|
146
|
+
*/
|
|
147
|
+
declare const feishuLarkChannel: {
|
|
148
|
+
platform: "feishu_lark";
|
|
149
|
+
transport: "socket";
|
|
150
|
+
senderIdentity: "authenticated";
|
|
151
|
+
config: readonly ConfigField[];
|
|
152
|
+
create(config: Config): FeishuLarkAdapter;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* The default `LarkTransport`, over `@larksuiteoapi/node-sdk`'s `Client` and long-connection
|
|
157
|
+
* `WSClient`. The SDK is an optional peer, loaded on first use.
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
interface SdkApiAnswer {
|
|
161
|
+
readonly code?: number;
|
|
162
|
+
readonly msg?: string;
|
|
163
|
+
readonly data?: {
|
|
164
|
+
readonly message_id?: string;
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/** The part of `@larksuiteoapi/node-sdk` this transport uses. */
|
|
168
|
+
interface LarkSdk {
|
|
169
|
+
readonly Domain: {
|
|
170
|
+
readonly Feishu: number;
|
|
171
|
+
readonly Lark: number;
|
|
172
|
+
};
|
|
173
|
+
readonly Client: new (params: {
|
|
174
|
+
appId: string;
|
|
175
|
+
appSecret: string;
|
|
176
|
+
domain: number;
|
|
177
|
+
}) => {
|
|
178
|
+
readonly auth: {
|
|
179
|
+
readonly tenantAccessToken: {
|
|
180
|
+
internal(payload: {
|
|
181
|
+
data: {
|
|
182
|
+
app_id: string;
|
|
183
|
+
app_secret: string;
|
|
184
|
+
};
|
|
185
|
+
}): Promise<SdkApiAnswer>;
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
readonly im: {
|
|
189
|
+
readonly message: {
|
|
190
|
+
create(payload: {
|
|
191
|
+
params: {
|
|
192
|
+
receive_id_type: "chat_id";
|
|
193
|
+
};
|
|
194
|
+
data: {
|
|
195
|
+
receive_id: string;
|
|
196
|
+
msg_type: "text";
|
|
197
|
+
content: string;
|
|
198
|
+
};
|
|
199
|
+
}): Promise<SdkApiAnswer>;
|
|
200
|
+
reply(payload: {
|
|
201
|
+
path: {
|
|
202
|
+
message_id: string;
|
|
203
|
+
};
|
|
204
|
+
data: {
|
|
205
|
+
msg_type: "text";
|
|
206
|
+
content: string;
|
|
207
|
+
};
|
|
208
|
+
}): Promise<SdkApiAnswer>;
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
readonly WSClient: new (params: {
|
|
213
|
+
appId: string;
|
|
214
|
+
appSecret: string;
|
|
215
|
+
domain: number;
|
|
216
|
+
onReady?: () => void;
|
|
217
|
+
onError?: (err: Error) => void;
|
|
218
|
+
}) => {
|
|
219
|
+
start(params: {
|
|
220
|
+
eventDispatcher: unknown;
|
|
221
|
+
}): Promise<void>;
|
|
222
|
+
close(): void;
|
|
223
|
+
};
|
|
224
|
+
readonly EventDispatcher: new (params: Record<string, never>) => {
|
|
225
|
+
register(handles: Record<string, (data: unknown) => Promise<void>>): unknown;
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
/** Options the default transport needs. */
|
|
229
|
+
interface LarkTransportOptions {
|
|
230
|
+
readonly appId: string;
|
|
231
|
+
readonly appSecret: string;
|
|
232
|
+
readonly domain?: "feishu" | "lark";
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Build the transport over the SDK. `load` is the test seam: it returns the SDK module.
|
|
236
|
+
*
|
|
237
|
+
* The long connection keeps the SDK's own reconnect (`autoReconnect` left at its default): the SDK
|
|
238
|
+
* retries on the interval Feishu's servers send, and the adapter runs no loop of its own (plan D7).
|
|
239
|
+
*/
|
|
240
|
+
declare function createLarkTransport(options: LarkTransportOptions, load?: () => Promise<LarkSdk>): LarkTransport;
|
|
241
|
+
|
|
242
|
+
export { FeishuLarkAdapter, type FeishuLarkAdapterOptions, type LarkApiResult, type LarkConnectionHandlers, type LarkSdk, type LarkTransport, type LarkTransportOptions, createLarkTransport, feishuLarkChannel };
|