@satorijs/adapter-lark 3.6.0 → 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.
@@ -1,24 +1,7 @@
1
- import { Lark } from '..'
2
- import { MessageContent } from './content'
1
+ import { Lark, MessageContent } from '..'
3
2
 
4
3
  export * from './content'
5
4
 
6
- export type MessageType = 'text' | 'post' | 'image' | 'file' | 'audio' | 'media' | 'sticker' | 'interactive' | 'share_chat' | 'share_user'
7
-
8
- export interface MessageContentMap {
9
- 'text': MessageContent.Text
10
- 'post': MessageContent.RichText
11
- 'image': MessageContent.Image
12
- 'file': MessageContent.File
13
- 'audio': MessageContent.Audio
14
- 'media': MessageContent.Media
15
- 'sticker': MessageContent.Sticker
16
- 'share_chat': MessageContent.ShareChat
17
- 'share_user': MessageContent.ShareUser
18
- }
19
-
20
- export type MessageContentType<T extends MessageType> = T extends keyof MessageContentMap ? MessageContentMap[T] : any
21
-
22
5
  declare module '../event' {
23
6
  export interface Events {
24
7
  /**
@@ -38,7 +21,7 @@ declare module '../event' {
38
21
  create_time: string
39
22
  chat_id: string
40
23
  chat_type: string
41
- message_type: MessageType
24
+ message_type: keyof MessageContent
42
25
  content: string
43
26
  mentions: {
44
27
  key: string
package/src/utils.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import crypto from 'crypto'
2
2
  import { Context, h, Session, trimSlash, Universal } from '@satorijs/core'
3
- import { FeishuBot, LarkBot } from './bot'
4
- import { EventPayload, Events, GetImChatResponse, Lark, MessageContentType, MessageType } from './types'
3
+ import { LarkBot } from './bot'
4
+ import { EventPayload, Events, GetImChatResponse, Lark } from './types'
5
5
 
6
6
  export type Sender =
7
7
  | {
@@ -22,8 +22,8 @@ export function adaptSender(sender: Sender, session: Session): Session {
22
22
  return session
23
23
  }
24
24
 
25
- export async function adaptMessage(bot: FeishuBot, data: Events['im.message.receive_v1'], session: Session, details = true): Promise<Session> {
26
- const json = JSON.parse(data.message.content) as MessageContentType<MessageType>
25
+ export async function adaptMessage(bot: LarkBot, data: Events['im.message.receive_v1'], session: Session, details = true): Promise<Session> {
26
+ const json = JSON.parse(data.message.content)
27
27
  const assetEndpoint = trimSlash(bot.config.selfUrl ?? bot.ctx.server.config.selfUrl) + bot.config.path + '/assets'
28
28
  const content: (string | h)[] = []
29
29
  switch (data.message.message_type) {
@@ -71,7 +71,7 @@ export async function adaptMessage(bot: FeishuBot, data: Events['im.message.rece
71
71
  return session
72
72
  }
73
73
 
74
- export async function adaptSession<C extends Context>(bot: FeishuBot<C>, body: EventPayload) {
74
+ export async function adaptSession<C extends Context>(bot: LarkBot<C>, body: EventPayload) {
75
75
  const session = bot.session()
76
76
  session.setInternal('lark', body)
77
77
 
@@ -119,7 +119,7 @@ export async function adaptSession<C extends Context>(bot: FeishuBot<C>, body: E
119
119
 
120
120
  // TODO: This function has many duplicated code with `adaptMessage`, should refactor them
121
121
  export async function decodeMessage(bot: LarkBot, body: Lark.Message, details = true): Promise<Universal.Message> {
122
- const json = JSON.parse(body.body.content) as MessageContentType<MessageType>
122
+ const json = JSON.parse(body.body.content)
123
123
  const assetEndpoint = trimSlash(bot.config.selfUrl ?? bot.ctx.server.config.selfUrl) + bot.config.path + '/assets'
124
124
  const content: h[] = []
125
125
  switch (body.msg_type) {