@satorijs/adapter-lark 3.6.2 → 3.7.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/index.cjs +54 -37
- package/lib/index.cjs.map +1 -1
- package/lib/types/api.d.ts +3071 -4373
- package/lib/types/internal.d.ts +2 -2
- package/lib/utils.d.ts +1 -1
- package/package.json +4 -4
- package/src/bot.ts +13 -13
- package/src/message.ts +22 -7
- package/src/types/api.ts +2506 -3987
- package/src/types/internal.ts +10 -10
- package/src/utils.ts +3 -3
- package/lib/types/auth.d.ts +0 -40
- package/lib/types/guild.d.ts +0 -59
- package/lib/types/message/asset.d.ts +0 -40
- package/lib/types/user.d.ts +0 -78
- package/lib/types/utils.d.ts +0 -9
package/src/types/internal.ts
CHANGED
|
@@ -15,17 +15,15 @@ type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
|
|
|
15
15
|
export class Internal {
|
|
16
16
|
constructor(private bot: LarkBot) {}
|
|
17
17
|
|
|
18
|
-
private
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
throw new Error(`HTTP response with non-zero status (${code}) with message "${msg}"`)
|
|
25
|
-
}
|
|
18
|
+
private assertResponse(response: HTTP.Response<BaseResponse>) {
|
|
19
|
+
if (!response.data.code) return
|
|
20
|
+
this.bot.logger.debug('response: %o', response.data)
|
|
21
|
+
const error = new HTTP.Error(`request failed`)
|
|
22
|
+
error.response = response
|
|
23
|
+
throw error
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
static define(routes: Dict<Partial<Record<Method, string | string[]
|
|
26
|
+
static define(routes: Dict<Partial<Record<Method, string | string[]>>>, extractData = true) {
|
|
29
27
|
for (const path in routes) {
|
|
30
28
|
for (const key in routes[path]) {
|
|
31
29
|
const method = key as Method
|
|
@@ -49,7 +47,9 @@ export class Internal {
|
|
|
49
47
|
} else if (args.length > 1) {
|
|
50
48
|
throw new Error(`too many arguments for ${path}, received ${raw}`)
|
|
51
49
|
}
|
|
52
|
-
|
|
50
|
+
const response = await this.bot.http(method, url, config)
|
|
51
|
+
this.assertResponse(response)
|
|
52
|
+
return extractData ? response.data.data : response.data
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
}
|
package/src/utils.ts
CHANGED
|
@@ -123,9 +123,9 @@ export async function adaptSession<C extends Context>(bot: LarkBot<C>, body: Eve
|
|
|
123
123
|
session.channelId = body.event.context.open_chat_id
|
|
124
124
|
session.guildId = body.event.context.open_chat_id
|
|
125
125
|
session.userId = body.event.operator.open_id
|
|
126
|
-
const
|
|
126
|
+
const chat = await bot.internal.getImChat(session.channelId)
|
|
127
127
|
// TODO: add channel data
|
|
128
|
-
session.isDirect =
|
|
128
|
+
session.isDirect = chat.chat_mode === 'p2p'
|
|
129
129
|
}
|
|
130
130
|
break
|
|
131
131
|
}
|
|
@@ -201,7 +201,7 @@ export function extractIdType(id: string): Lark.ReceiveIdType {
|
|
|
201
201
|
return 'user_id'
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
-
export function decodeChannel(channelId: string, guild: GetImChatResponse
|
|
204
|
+
export function decodeChannel(channelId: string, guild: GetImChatResponse): Universal.Channel {
|
|
205
205
|
return {
|
|
206
206
|
id: channelId,
|
|
207
207
|
type: Universal.Channel.Type.TEXT,
|
package/lib/types/auth.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { BaseResponse } from '.';
|
|
2
|
-
/**
|
|
3
|
-
* Lark defines three types of token:
|
|
4
|
-
* - app_access_token: to access the API in an app (published on App Store).
|
|
5
|
-
* - tenant_access_token: to access the API as an enterprise or a team (tenant).
|
|
6
|
-
* *We commonly use this one*
|
|
7
|
-
* - user_access_token: to access the API as the specific user.
|
|
8
|
-
*
|
|
9
|
-
* @see https://open.larksuite.com/document/ukTMukTMukTM/uMTNz4yM1MjLzUzM
|
|
10
|
-
*/
|
|
11
|
-
export interface AppCredentials {
|
|
12
|
-
app_id: string;
|
|
13
|
-
app_secret: string;
|
|
14
|
-
}
|
|
15
|
-
export interface AppAccessToken extends BaseResponse {
|
|
16
|
-
/** access token */
|
|
17
|
-
app_access_token: string;
|
|
18
|
-
/** expire time in seconds. e.g: 7140 (119 minutes) */
|
|
19
|
-
expire: number;
|
|
20
|
-
}
|
|
21
|
-
export interface TenantAccessToken extends BaseResponse {
|
|
22
|
-
/** access token */
|
|
23
|
-
tenant_access_token: string;
|
|
24
|
-
/** expire time in seconds. e.g: 7140 (119 minutes) */
|
|
25
|
-
expire: number;
|
|
26
|
-
}
|
|
27
|
-
declare module './internal' {
|
|
28
|
-
interface Internal {
|
|
29
|
-
/**
|
|
30
|
-
* Returns the app_access_token for the bot.
|
|
31
|
-
* @see https://open.larksuite.com/document/ukTMukTMukTM/ukDNz4SO0MjL5QzM/auth-v3/auth/app_access_token_internal
|
|
32
|
-
*/
|
|
33
|
-
getAppAccessToken(data: AppCredentials): Promise<AppAccessToken>;
|
|
34
|
-
/**
|
|
35
|
-
* Returns the tenant_access_token for the bot.
|
|
36
|
-
* @see https://open.larksuite.com/document/ukTMukTMukTM/ukDNz4SO0MjL5QzM/auth-v3/auth/tenant_access_token_internal
|
|
37
|
-
*/
|
|
38
|
-
getTenantAccessToken(data: AppCredentials): Promise<TenantAccessToken>;
|
|
39
|
-
}
|
|
40
|
-
}
|
package/lib/types/guild.d.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { Dict } from '@satorijs/satori';
|
|
2
|
-
import { Lark } from '.';
|
|
3
|
-
import { Paginated, Pagination } from './utils';
|
|
4
|
-
declare module '.' {
|
|
5
|
-
namespace Lark {
|
|
6
|
-
interface Guild {
|
|
7
|
-
avatar: string;
|
|
8
|
-
name: string;
|
|
9
|
-
description: string;
|
|
10
|
-
i18n_names: Dict<string>;
|
|
11
|
-
add_member_permission: string;
|
|
12
|
-
share_card_permission: string;
|
|
13
|
-
at_all_permission: string;
|
|
14
|
-
edit_permission: string;
|
|
15
|
-
owner_id_type: string;
|
|
16
|
-
owner_id: string;
|
|
17
|
-
chat_id: string;
|
|
18
|
-
chat_mode: string;
|
|
19
|
-
chat_type: string;
|
|
20
|
-
chat_tag: string;
|
|
21
|
-
join_message_visibility: string;
|
|
22
|
-
leave_message_visibility: string;
|
|
23
|
-
membership_approval: string;
|
|
24
|
-
moderation_permission: string;
|
|
25
|
-
external: boolean;
|
|
26
|
-
tenant_key: string;
|
|
27
|
-
user_count: string;
|
|
28
|
-
bot_count: string;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
export interface GuildMember {
|
|
33
|
-
member_id_type: Lark.UserIdType;
|
|
34
|
-
member_id: string;
|
|
35
|
-
name: string;
|
|
36
|
-
tenant_key: string;
|
|
37
|
-
}
|
|
38
|
-
declare module './internal' {
|
|
39
|
-
interface Internal {
|
|
40
|
-
/** @see https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/list */
|
|
41
|
-
getCurrentUserGuilds(params?: Pagination<{
|
|
42
|
-
user_id_type?: Lark.UserIdType;
|
|
43
|
-
}>): Promise<{
|
|
44
|
-
data: Paginated<Lark.Guild>;
|
|
45
|
-
}>;
|
|
46
|
-
/** @see https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/get */
|
|
47
|
-
getGuildInfo(chat_id: string, params?: {
|
|
48
|
-
user_id_type?: string;
|
|
49
|
-
}): Promise<BaseResponse & {
|
|
50
|
-
data: Lark.Guild;
|
|
51
|
-
}>;
|
|
52
|
-
/** @see https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat-members/get */
|
|
53
|
-
getGuildMembers(chat_id: string, params?: Pagination<{
|
|
54
|
-
member_id_type?: Lark.UserIdType;
|
|
55
|
-
}>): Promise<{
|
|
56
|
-
data: Paginated<GuildMember>;
|
|
57
|
-
}>;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { BaseResponse } from '..';
|
|
2
|
-
export interface Asset<T> extends BaseResponse {
|
|
3
|
-
data: T;
|
|
4
|
-
}
|
|
5
|
-
export type Image = Asset<{
|
|
6
|
-
image_key: string;
|
|
7
|
-
}>;
|
|
8
|
-
export type File = Asset<{
|
|
9
|
-
file_key: string;
|
|
10
|
-
}>;
|
|
11
|
-
declare module '../internal' {
|
|
12
|
-
interface Internal {
|
|
13
|
-
/**
|
|
14
|
-
* Upload an image to obtain an `image_key` for use in sending messages or changing the avatar.
|
|
15
|
-
*
|
|
16
|
-
* The data should contain:
|
|
17
|
-
* - `image_type`: 'message' | 'avatar'
|
|
18
|
-
* - `image': Buffer
|
|
19
|
-
* @see https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/image/create
|
|
20
|
-
*/
|
|
21
|
-
uploadImage(data: FormData): Promise<Image>;
|
|
22
|
-
/**
|
|
23
|
-
* Upload a file to obtain a `file_key` for use in sending messages.
|
|
24
|
-
*
|
|
25
|
-
* The data should contain:
|
|
26
|
-
* - `file_type`: 'opus' | 'mp4' | 'pdf' | 'xls' | 'ppt' | 'stream'
|
|
27
|
-
* - `opus`: Opus audio file
|
|
28
|
-
* - `mp4`: MP4 video file
|
|
29
|
-
* - `pdf`: PDF file
|
|
30
|
-
* - `xls`: Excel file
|
|
31
|
-
* - `ppt`: PowerPoint file
|
|
32
|
-
* - `stream`: Stream file, or any other file not listed above
|
|
33
|
-
* - `file_name`: string, include extension
|
|
34
|
-
* - `duration`?: number, the duration of audio/video file in milliseconds
|
|
35
|
-
* - `file`: Buffer
|
|
36
|
-
* @see https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/file/create
|
|
37
|
-
*/
|
|
38
|
-
uploadFile(data: FormData): Promise<File>;
|
|
39
|
-
}
|
|
40
|
-
}
|
package/lib/types/user.d.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { Lark } from '.';
|
|
2
|
-
declare module '.' {
|
|
3
|
-
namespace Lark {
|
|
4
|
-
interface User {
|
|
5
|
-
union_id: string;
|
|
6
|
-
user_id?: string;
|
|
7
|
-
open_id: string;
|
|
8
|
-
name?: string;
|
|
9
|
-
en_name?: string;
|
|
10
|
-
nickname?: string;
|
|
11
|
-
email?: string;
|
|
12
|
-
mobile?: string;
|
|
13
|
-
mobile_visible: boolean;
|
|
14
|
-
gender?: Gender;
|
|
15
|
-
avatar?: AvatarInfo;
|
|
16
|
-
status?: UserStatus;
|
|
17
|
-
department_ids?: string[];
|
|
18
|
-
leader_user_id?: string;
|
|
19
|
-
city?: string;
|
|
20
|
-
country?: string;
|
|
21
|
-
work_station?: string;
|
|
22
|
-
join_time?: number;
|
|
23
|
-
is_tenant_manager?: boolean;
|
|
24
|
-
employee_no?: string;
|
|
25
|
-
employee_type?: number;
|
|
26
|
-
orders?: UserOrder[];
|
|
27
|
-
custom_attrs?: any;
|
|
28
|
-
enterprise_email?: string;
|
|
29
|
-
job_title?: string;
|
|
30
|
-
geo?: string;
|
|
31
|
-
job_level_id?: string;
|
|
32
|
-
job_family_id?: string;
|
|
33
|
-
assign_info?: any;
|
|
34
|
-
department_path?: DepartmentDetail[];
|
|
35
|
-
}
|
|
36
|
-
enum Gender {
|
|
37
|
-
SECRET = 0,
|
|
38
|
-
MALE = 1,
|
|
39
|
-
FEMALE = 2
|
|
40
|
-
}
|
|
41
|
-
interface AvatarInfo {
|
|
42
|
-
avatar_72: string;
|
|
43
|
-
avatar_240: string;
|
|
44
|
-
avatar_640: string;
|
|
45
|
-
avatar_origin: string;
|
|
46
|
-
}
|
|
47
|
-
interface UserStatus {
|
|
48
|
-
is_frozen: boolean;
|
|
49
|
-
is_resigned: boolean;
|
|
50
|
-
is_activated: boolean;
|
|
51
|
-
is_exited: boolean;
|
|
52
|
-
is_unjoin: boolean;
|
|
53
|
-
}
|
|
54
|
-
interface UserOrder {
|
|
55
|
-
department_id: string;
|
|
56
|
-
user_order: number;
|
|
57
|
-
department_order: number;
|
|
58
|
-
is_primary_dept: boolean;
|
|
59
|
-
}
|
|
60
|
-
interface DepartmentDetail {
|
|
61
|
-
dotted_line_leader_user_ids: string[];
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
export interface GuildMember {
|
|
66
|
-
member_id_type: Lark.UserIdType;
|
|
67
|
-
member_id: string;
|
|
68
|
-
name: string;
|
|
69
|
-
tenant_key: string;
|
|
70
|
-
}
|
|
71
|
-
declare module './internal' {
|
|
72
|
-
interface Internal {
|
|
73
|
-
/** @see https://open.larksuite.com/document/server-docs/contact-v3/user/get */
|
|
74
|
-
getContactUser(user_id: string, user_id_type?: Lark.UserIdType, department_id_type?: Lark.DepartmentIdType): Promise<BaseResponse & {
|
|
75
|
-
data: Lark.User;
|
|
76
|
-
}>;
|
|
77
|
-
}
|
|
78
|
-
}
|