@satorijs/adapter-lark 3.5.3 → 3.6.1
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/http.d.ts +7 -7
- package/lib/index.cjs +200 -101
- package/lib/index.cjs.map +2 -2
- package/lib/message.d.ts +7 -9
- package/lib/types/event.d.ts +10 -9
- package/lib/types/message/content.d.ts +201 -22
- package/lib/types/message/index.d.ts +39 -20
- package/lib/utils.d.ts +4 -4
- package/package.json +3 -3
- package/src/http.ts +8 -8
- package/src/message.ts +179 -111
- package/src/types/event.ts +11 -10
- package/src/types/message/content.ts +266 -42
- package/src/types/message/index.ts +39 -23
- package/src/utils.ts +35 -6
package/lib/message.d.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { Context, h, MessageEncoder } from '@satorijs/core';
|
|
2
2
|
import { LarkBot } from './bot';
|
|
3
|
-
import { MessageContent, MessageType } from './types';
|
|
4
|
-
export interface Addition {
|
|
5
|
-
file: MessageContent.MediaContents;
|
|
6
|
-
type: MessageType;
|
|
7
|
-
}
|
|
8
3
|
export declare class LarkMessageEncoder<C extends Context = Context> extends MessageEncoder<C, LarkBot<C>> {
|
|
9
4
|
private quote;
|
|
10
|
-
private
|
|
11
|
-
private
|
|
12
|
-
private
|
|
5
|
+
private textContent;
|
|
6
|
+
private richContent;
|
|
7
|
+
private cardElements;
|
|
8
|
+
private actionElements;
|
|
13
9
|
post(data?: any): Promise<void>;
|
|
10
|
+
private flushText;
|
|
14
11
|
flush(): Promise<void>;
|
|
15
|
-
|
|
12
|
+
createImage(url: string): Promise<string>;
|
|
13
|
+
sendFile(_type: 'video' | 'audio' | 'file', attrs: any): Promise<void>;
|
|
16
14
|
visit(element: h): Promise<void>;
|
|
17
15
|
}
|
|
18
16
|
export { LarkMessageEncoder as FeishuMessageEncoder };
|
package/lib/types/event.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export interface EventHeader<
|
|
1
|
+
export interface EventHeader<K extends keyof Events> {
|
|
2
2
|
event_id: string;
|
|
3
|
-
event_type:
|
|
3
|
+
event_type: K;
|
|
4
4
|
create_time: string;
|
|
5
5
|
token: string;
|
|
6
6
|
app_id: string;
|
|
@@ -9,10 +9,11 @@ export interface EventHeader<T extends string> {
|
|
|
9
9
|
export interface Events {
|
|
10
10
|
}
|
|
11
11
|
export type EventName = keyof Events;
|
|
12
|
-
export type
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
export type EventPayload = {
|
|
13
|
+
[K in keyof Events]: {
|
|
14
|
+
schema: '2.0';
|
|
15
|
+
type: K;
|
|
16
|
+
header: EventHeader<K>;
|
|
17
|
+
event: Events[K];
|
|
18
|
+
};
|
|
19
|
+
}[keyof Events];
|
|
@@ -1,6 +1,31 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
namespace JSX {
|
|
3
|
+
interface IntrinsicElements {
|
|
4
|
+
'lark:share-chat': {
|
|
5
|
+
'chat-id': string;
|
|
6
|
+
};
|
|
7
|
+
'lark:share-user': {
|
|
8
|
+
'user-id': string;
|
|
9
|
+
};
|
|
10
|
+
'lark:system': {
|
|
11
|
+
'need-rollup'?: boolean;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export interface MessageContent {
|
|
17
|
+
text: MessageContent.Text;
|
|
18
|
+
post: MessageContent.RichText;
|
|
19
|
+
image: MessageContent.Image;
|
|
20
|
+
file: MessageContent.File;
|
|
21
|
+
audio: MessageContent.Audio;
|
|
22
|
+
media: MessageContent.Media;
|
|
23
|
+
sticker: MessageContent.Sticker;
|
|
24
|
+
share_chat: MessageContent.ShareChat;
|
|
25
|
+
share_user: MessageContent.ShareUser;
|
|
26
|
+
system: MessageContent.System;
|
|
27
|
+
}
|
|
1
28
|
export declare namespace MessageContent {
|
|
2
|
-
type Contents = Text | Image | ShareChat | ShareUser | Audio | Media | File | Sticker | RichText;
|
|
3
|
-
type MediaContents = Image | Audio | Media | File;
|
|
4
29
|
interface Text {
|
|
5
30
|
text: string;
|
|
6
31
|
}
|
|
@@ -18,7 +43,7 @@ export declare namespace MessageContent {
|
|
|
18
43
|
}
|
|
19
44
|
interface Media {
|
|
20
45
|
file_key: string;
|
|
21
|
-
image_key
|
|
46
|
+
image_key?: string;
|
|
22
47
|
}
|
|
23
48
|
interface File {
|
|
24
49
|
file_key: string;
|
|
@@ -26,44 +51,198 @@ export declare namespace MessageContent {
|
|
|
26
51
|
interface Sticker {
|
|
27
52
|
file_key: string;
|
|
28
53
|
}
|
|
54
|
+
interface System {
|
|
55
|
+
type: 'divider';
|
|
56
|
+
params: {
|
|
57
|
+
divider_text: {
|
|
58
|
+
text: string;
|
|
59
|
+
i18n_text?: Record<string, string>;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
options?: {
|
|
63
|
+
need_rollup?: boolean;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
29
66
|
interface RichText {
|
|
30
67
|
[locale: string]: {
|
|
31
|
-
title
|
|
68
|
+
title?: string;
|
|
32
69
|
content: RichText.Paragraph[];
|
|
33
70
|
};
|
|
34
71
|
}
|
|
35
72
|
namespace RichText {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
tag: string;
|
|
73
|
+
type Style = 'bold' | 'italic' | 'underline' | 'lineThrough';
|
|
74
|
+
interface BaseElement<T extends string = string> {
|
|
75
|
+
tag: T;
|
|
40
76
|
}
|
|
41
|
-
interface
|
|
42
|
-
tag: 'text';
|
|
77
|
+
interface TextElement extends BaseElement<'text'> {
|
|
43
78
|
text: string;
|
|
44
79
|
un_escape?: boolean;
|
|
80
|
+
style?: Style[];
|
|
45
81
|
}
|
|
46
|
-
interface
|
|
47
|
-
tag: 'a';
|
|
82
|
+
interface LinkElement extends BaseElement<'a'> {
|
|
48
83
|
text: string;
|
|
49
84
|
href: string;
|
|
85
|
+
style?: Style[];
|
|
50
86
|
}
|
|
51
|
-
interface
|
|
52
|
-
tag: 'at';
|
|
87
|
+
interface AtElement extends BaseElement<'at'> {
|
|
53
88
|
user_id: string;
|
|
54
|
-
|
|
89
|
+
style?: Style[];
|
|
55
90
|
}
|
|
56
|
-
interface
|
|
57
|
-
tag: 'img';
|
|
91
|
+
interface ImageElement extends BaseElement<'img'> {
|
|
58
92
|
image_key: string;
|
|
59
|
-
height?: number;
|
|
60
|
-
width?: number;
|
|
61
93
|
}
|
|
62
|
-
interface
|
|
63
|
-
tag: 'media';
|
|
94
|
+
interface MediaElement extends BaseElement<'media'> {
|
|
64
95
|
file_key: string;
|
|
65
96
|
image_key?: string;
|
|
66
97
|
}
|
|
67
|
-
|
|
98
|
+
interface EmotionElement extends BaseElement<'emoji'> {
|
|
99
|
+
emoji_type: string;
|
|
100
|
+
}
|
|
101
|
+
interface CodeBlockElement extends BaseElement<'code_block'> {
|
|
102
|
+
language?: string;
|
|
103
|
+
text: string;
|
|
104
|
+
}
|
|
105
|
+
interface HRElement extends BaseElement<'hr'> {
|
|
106
|
+
}
|
|
107
|
+
interface MarkdownElement extends BaseElement<'md'> {
|
|
108
|
+
text: string;
|
|
109
|
+
}
|
|
110
|
+
type InlineElement = TextElement | LinkElement | AtElement | EmotionElement | MarkdownElement;
|
|
111
|
+
type BlockElement = ImageElement | MediaElement | CodeBlockElement | HRElement;
|
|
112
|
+
type Paragraph = InlineElement[] | [BlockElement];
|
|
113
|
+
}
|
|
114
|
+
interface Card {
|
|
115
|
+
config: Card.Config;
|
|
116
|
+
card_link?: Card.URLs;
|
|
117
|
+
elements?: Card.Element[];
|
|
118
|
+
}
|
|
119
|
+
namespace Card {
|
|
120
|
+
/** @see https://open.larksuite.com/document/common-capabilities/message-card/getting-started/card-structure/card-configuration */
|
|
121
|
+
interface Config {
|
|
122
|
+
enable_forward?: boolean;
|
|
123
|
+
update_multi?: boolean;
|
|
124
|
+
}
|
|
125
|
+
interface URLs {
|
|
126
|
+
url: string;
|
|
127
|
+
pc_url?: string;
|
|
128
|
+
ios_url?: string;
|
|
129
|
+
android_url?: string;
|
|
130
|
+
}
|
|
131
|
+
/** @see https://open.larksuite.com/document/common-capabilities/message-card/message-cards-content/card-header */
|
|
132
|
+
interface Header {
|
|
133
|
+
title: I18nPlainTextElement;
|
|
134
|
+
subtitle?: I18nPlainTextElement;
|
|
135
|
+
template?: Header.Template;
|
|
136
|
+
icon?: CustomIconElement;
|
|
137
|
+
ud_icon?: StandardIconElement;
|
|
138
|
+
text_tag_list?: TextTagElement[];
|
|
139
|
+
i18n_text_tag_list?: Record<string, TextTagElement[]>;
|
|
140
|
+
}
|
|
141
|
+
namespace Header {
|
|
142
|
+
type Template = 'blue' | 'wathet' | 'turquoise' | 'green' | 'yellow' | 'orange' | 'red' | 'carmine' | 'violet' | 'purple' | 'indigo' | 'grey' | 'default';
|
|
143
|
+
}
|
|
144
|
+
interface BaseElement<T extends string = string> {
|
|
145
|
+
tag: T;
|
|
146
|
+
}
|
|
147
|
+
type TextSize = 'heading-0' | 'heading-1' | 'heading-2' | 'heading-3' | 'heading-4' | 'heading' | 'normal' | 'notation' | 'xxxx-large' | 'xxx-large' | 'xx-large' | 'x-large' | 'large' | 'medium' | 'small' | 'x-small';
|
|
148
|
+
type TextAlign = 'left' | 'center' | 'right';
|
|
149
|
+
interface PlainTextElement extends BaseElement<'plain_text'> {
|
|
150
|
+
content: string;
|
|
151
|
+
}
|
|
152
|
+
interface I18nPlainTextElement extends PlainTextElement {
|
|
153
|
+
i18n?: Record<string, string>;
|
|
154
|
+
}
|
|
155
|
+
interface DivPlainTextElement extends PlainTextElement {
|
|
156
|
+
text_size?: TextSize;
|
|
157
|
+
text_color?: string;
|
|
158
|
+
text_align?: TextAlign;
|
|
159
|
+
lines?: number;
|
|
160
|
+
icon?: IconElement;
|
|
161
|
+
}
|
|
162
|
+
type IconElement = StandardIconElement | CustomIconElement;
|
|
163
|
+
interface CustomIconElement extends BaseElement<'custom_icon'> {
|
|
164
|
+
img_key: string;
|
|
165
|
+
}
|
|
166
|
+
interface StandardIconElement extends BaseElement<'standard_icon'> {
|
|
167
|
+
token: string;
|
|
168
|
+
color?: string;
|
|
169
|
+
}
|
|
170
|
+
interface TextTagElement extends BaseElement<'text_tag'> {
|
|
171
|
+
text: PlainTextElement;
|
|
172
|
+
color: TextTagElement.Color;
|
|
173
|
+
}
|
|
174
|
+
namespace TextTagElement {
|
|
175
|
+
type Color = 'neutral' | 'blue' | 'torqoise' | 'lime' | 'orange' | 'violet' | 'indigo' | 'wathet' | 'green' | 'yellow' | 'red' | 'purple' | 'carmine';
|
|
176
|
+
}
|
|
177
|
+
interface ImageElement extends BaseElement<'image'> {
|
|
178
|
+
img_key: string;
|
|
179
|
+
alt?: PlainTextElement;
|
|
180
|
+
title?: PlainTextElement;
|
|
181
|
+
custom_width?: number;
|
|
182
|
+
compact_width?: boolean;
|
|
183
|
+
mode?: 'crop_center' | 'fit_horizontal' | 'large' | 'medium' | 'small' | 'tiny';
|
|
184
|
+
preview?: boolean;
|
|
185
|
+
}
|
|
186
|
+
interface HorizontalRuleElement extends BaseElement<'hr'> {
|
|
187
|
+
}
|
|
188
|
+
interface DivElement extends BaseElement<'div'> {
|
|
189
|
+
text?: DivPlainTextElement;
|
|
190
|
+
}
|
|
191
|
+
interface MarkdownElement extends BaseElement<'markdown'> {
|
|
192
|
+
content: string;
|
|
193
|
+
text_size?: TextSize;
|
|
194
|
+
text_align?: TextAlign;
|
|
195
|
+
href?: Record<string, URLs>;
|
|
196
|
+
}
|
|
197
|
+
interface HorizontalRuleElement extends BaseElement<'hr'> {
|
|
198
|
+
}
|
|
199
|
+
interface ActionModule extends BaseElement<'action'> {
|
|
200
|
+
actions: ActionElement[];
|
|
201
|
+
layout?: 'bisected' | 'trisection' | 'flow';
|
|
202
|
+
}
|
|
203
|
+
type ActionElement = ButtonElement;
|
|
204
|
+
type ActionBehavior = OpenURLBehavior | CallbackBehavior;
|
|
205
|
+
interface OpenURLBehavior {
|
|
206
|
+
type: 'open_url';
|
|
207
|
+
default_url: string;
|
|
208
|
+
pc_url?: string;
|
|
209
|
+
ios_url?: string;
|
|
210
|
+
android_url?: string;
|
|
211
|
+
}
|
|
212
|
+
interface CallbackBehavior {
|
|
213
|
+
type: 'callback';
|
|
214
|
+
value: Record<string, string>;
|
|
215
|
+
}
|
|
216
|
+
interface ButtonElement extends BaseElement<'button'> {
|
|
217
|
+
text: PlainTextElement;
|
|
218
|
+
type?: ButtonElement.Type;
|
|
219
|
+
size?: ButtonElement.Size;
|
|
220
|
+
width?: ButtonElement.Width;
|
|
221
|
+
icon?: IconElement;
|
|
222
|
+
hover_tips?: PlainTextElement;
|
|
223
|
+
disabled?: boolean;
|
|
224
|
+
disabled_tips?: PlainTextElement;
|
|
225
|
+
confirm?: {
|
|
226
|
+
title: PlainTextElement;
|
|
227
|
+
text: PlainTextElement;
|
|
228
|
+
};
|
|
229
|
+
behaviors?: ActionBehavior[];
|
|
230
|
+
name?: string;
|
|
231
|
+
required?: boolean;
|
|
232
|
+
action_type?: 'link' | 'request' | 'multi' | 'form_submit' | 'form_reset';
|
|
233
|
+
}
|
|
234
|
+
namespace ButtonElement {
|
|
235
|
+
type Size = 'tiny' | 'small' | 'medium' | 'large';
|
|
236
|
+
type Width = 'default' | 'fill' | string;
|
|
237
|
+
type Type = 'default' | 'primary' | 'danger' | 'text' | 'primary_text' | 'danger_text' | 'primary_filled' | 'danger_filled' | 'laser';
|
|
238
|
+
}
|
|
239
|
+
type Element = DivElement | MarkdownElement | HorizontalRuleElement | ActionModule;
|
|
240
|
+
}
|
|
241
|
+
interface Template {
|
|
242
|
+
type: 'template';
|
|
243
|
+
data: {
|
|
244
|
+
template_id: string;
|
|
245
|
+
template_variable: object;
|
|
246
|
+
};
|
|
68
247
|
}
|
|
69
248
|
}
|
|
@@ -1,26 +1,12 @@
|
|
|
1
|
-
import { Lark } from '..';
|
|
2
|
-
import { MessageContent } from './content';
|
|
1
|
+
import { Lark, MessageContent } from '..';
|
|
3
2
|
export * from './content';
|
|
4
|
-
export type MessageType = 'text' | 'post' | 'image' | 'file' | 'audio' | 'media' | 'sticker' | 'interactive' | 'share_chat' | 'share_user';
|
|
5
|
-
export interface MessageContentMap {
|
|
6
|
-
'text': MessageContent.Text;
|
|
7
|
-
'post': MessageContent.RichText;
|
|
8
|
-
'image': MessageContent.Image;
|
|
9
|
-
'file': MessageContent.File;
|
|
10
|
-
'audio': MessageContent.Audio;
|
|
11
|
-
'media': MessageContent.Media;
|
|
12
|
-
'sticker': MessageContent.Sticker;
|
|
13
|
-
'share_chat': MessageContent.ShareChat;
|
|
14
|
-
'share_user': MessageContent.ShareUser;
|
|
15
|
-
}
|
|
16
|
-
export type MessageContentType<T extends MessageType> = T extends keyof MessageContentMap ? MessageContentMap[T] : any;
|
|
17
3
|
declare module '../event' {
|
|
18
4
|
interface Events {
|
|
19
5
|
/**
|
|
20
6
|
* Receive message event.
|
|
21
7
|
* @see https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message/events/receive
|
|
22
8
|
*/
|
|
23
|
-
'im.message.receive_v1':
|
|
9
|
+
'im.message.receive_v1': {
|
|
24
10
|
sender: {
|
|
25
11
|
sender_id: Lark.UserIds;
|
|
26
12
|
sender_type?: string;
|
|
@@ -33,7 +19,7 @@ declare module '../event' {
|
|
|
33
19
|
create_time: string;
|
|
34
20
|
chat_id: string;
|
|
35
21
|
chat_type: string;
|
|
36
|
-
message_type:
|
|
22
|
+
message_type: keyof MessageContent;
|
|
37
23
|
content: string;
|
|
38
24
|
mentions: {
|
|
39
25
|
key: string;
|
|
@@ -42,18 +28,51 @@ declare module '../event' {
|
|
|
42
28
|
tenant_key: string;
|
|
43
29
|
}[];
|
|
44
30
|
};
|
|
45
|
-
}
|
|
31
|
+
};
|
|
46
32
|
/**
|
|
47
33
|
* Message read event.
|
|
48
34
|
* @see https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message/events/message_read
|
|
49
35
|
*/
|
|
50
|
-
'im.message.message_read_v1':
|
|
36
|
+
'im.message.message_read_v1': {
|
|
51
37
|
reader: {
|
|
52
38
|
reader_id: Lark.UserIds;
|
|
53
39
|
read_time: string;
|
|
54
40
|
tenant_key: string;
|
|
55
41
|
};
|
|
56
42
|
message_id_list: string[];
|
|
57
|
-
}
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Message card callback event.
|
|
46
|
+
* @see https://open.feishu.cn/document/uAjLw4CM/ukzMukzMukzM/feishu-cards/card-callback-communication
|
|
47
|
+
*/
|
|
48
|
+
'card.action.trigger': {
|
|
49
|
+
operator: {
|
|
50
|
+
tenant_key: string;
|
|
51
|
+
user_id: string;
|
|
52
|
+
union_id: string;
|
|
53
|
+
open_id: string;
|
|
54
|
+
};
|
|
55
|
+
token: string;
|
|
56
|
+
action: {
|
|
57
|
+
value: any;
|
|
58
|
+
tag: string;
|
|
59
|
+
timezone?: string;
|
|
60
|
+
name?: string;
|
|
61
|
+
form_value?: any;
|
|
62
|
+
input_value?: string;
|
|
63
|
+
option?: string;
|
|
64
|
+
options?: string[];
|
|
65
|
+
checked?: boolean;
|
|
66
|
+
};
|
|
67
|
+
host: string;
|
|
68
|
+
/** 卡片分发类型,固定取值为 url_preview,表示链接预览卡片。仅链接预览卡片有此字段。 */
|
|
69
|
+
delivery_type?: 'url_preview';
|
|
70
|
+
context: {
|
|
71
|
+
url?: string;
|
|
72
|
+
preview_token?: string;
|
|
73
|
+
open_message_id: string;
|
|
74
|
+
open_chat_id: string;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
58
77
|
}
|
|
59
78
|
}
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Context, Session, Universal } from '@satorijs/core';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { LarkBot } from './bot';
|
|
3
|
+
import { EventPayload, Events, GetImChatResponse, Lark } from './types';
|
|
4
4
|
export type Sender = {
|
|
5
5
|
sender_id: Lark.UserIds;
|
|
6
6
|
sender_type?: string;
|
|
@@ -10,8 +10,8 @@ export type Sender = {
|
|
|
10
10
|
tenant_key: string;
|
|
11
11
|
});
|
|
12
12
|
export declare function adaptSender(sender: Sender, session: Session): Session;
|
|
13
|
-
export declare function adaptMessage(bot:
|
|
14
|
-
export declare function adaptSession<C extends Context>(bot:
|
|
13
|
+
export declare function adaptMessage(bot: LarkBot, data: Events['im.message.receive_v1'], session: Session, details?: boolean): Promise<Session>;
|
|
14
|
+
export declare function adaptSession<C extends Context>(bot: LarkBot<C>, body: EventPayload): Promise<C[typeof import("cordis").Context.session]>;
|
|
15
15
|
export declare function decodeMessage(bot: LarkBot, body: Lark.Message, details?: boolean): Promise<Universal.Message>;
|
|
16
16
|
/**
|
|
17
17
|
* Get ID type from id string
|
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.6.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.cjs",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
],
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@cordisjs/plugin-server": "^0.2.4",
|
|
38
|
-
"@satorijs/core": "^4.2.
|
|
38
|
+
"@satorijs/core": "^4.2.9",
|
|
39
39
|
"cordis": "^3.18.1"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@satorijs/core": "^4.2.
|
|
42
|
+
"@satorijs/core": "^4.2.9"
|
|
43
43
|
}
|
|
44
44
|
}
|
package/src/http.ts
CHANGED
|
@@ -3,29 +3,29 @@ import { ReadableStream } from 'node:stream/web'
|
|
|
3
3
|
import { Adapter, Context, Logger, Schema } from '@satorijs/core'
|
|
4
4
|
import {} from '@cordisjs/plugin-server'
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { LarkBot } from './bot'
|
|
7
|
+
import { EventPayload } from './types'
|
|
8
8
|
import { adaptSession, Cipher } from './utils'
|
|
9
9
|
|
|
10
|
-
export class HttpServer<C extends Context = Context> extends Adapter<C,
|
|
10
|
+
export class HttpServer<C extends Context = Context> extends Adapter<C, LarkBot<C>> {
|
|
11
11
|
static inject = ['server']
|
|
12
12
|
|
|
13
13
|
private logger: Logger
|
|
14
14
|
private ciphers: Record<string, Cipher> = {}
|
|
15
15
|
|
|
16
|
-
constructor(ctx: C, bot:
|
|
16
|
+
constructor(ctx: C, bot: LarkBot<C>) {
|
|
17
17
|
super(ctx)
|
|
18
18
|
this.logger = ctx.logger('lark')
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
fork(ctx: C, bot:
|
|
21
|
+
fork(ctx: C, bot: LarkBot<C>) {
|
|
22
22
|
super.fork(ctx, bot)
|
|
23
23
|
|
|
24
24
|
this._refreshCipher()
|
|
25
25
|
return bot.initialize()
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
async connect(bot:
|
|
28
|
+
async connect(bot: LarkBot) {
|
|
29
29
|
const { path } = bot.config
|
|
30
30
|
bot.ctx.server.post(path, (ctx) => {
|
|
31
31
|
this._refreshCipher()
|
|
@@ -72,10 +72,10 @@ export class HttpServer<C extends Context = Context> extends Adapter<C, FeishuBo
|
|
|
72
72
|
|
|
73
73
|
// dispatch message
|
|
74
74
|
bot.logger.debug('received decryped event: %o', body)
|
|
75
|
-
// @TODO: need await?
|
|
76
75
|
this.dispatchSession(body)
|
|
77
76
|
|
|
78
77
|
// Lark requires 200 OK response to make sure event is received
|
|
78
|
+
ctx.body = {}
|
|
79
79
|
return ctx.status = 200
|
|
80
80
|
})
|
|
81
81
|
|
|
@@ -98,7 +98,7 @@ export class HttpServer<C extends Context = Context> extends Adapter<C, FeishuBo
|
|
|
98
98
|
})
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
async dispatchSession(body:
|
|
101
|
+
async dispatchSession(body: EventPayload) {
|
|
102
102
|
const { header } = body
|
|
103
103
|
if (!header) return
|
|
104
104
|
const { app_id, event_type } = header
|