Skip to content

Commit

Permalink
feat(lark): reply in thread when button clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 3, 2025
1 parent 037cc8b commit ac0e32b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
2 changes: 1 addition & 1 deletion adapters/lark/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@satorijs/adapter-lark",
"description": "Lark (飞书) Adapter for Satorijs",
"version": "3.8.5",
"version": "3.8.6",
"type": "module",
"main": "lib/index.cjs",
"types": "lib/index.d.ts",
Expand Down
25 changes: 18 additions & 7 deletions adapters/lark/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,22 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
try {
let resp: Lark.Message
let quote = this.quote
const payload = this.options?.session?.lark
if (!quote && payload?.type === 'im.message.receive_v1' && payload.event.message.thread_id) {
quote = {
id: payload.event.message.message_id,
replyInThread: true,
if (!quote) {
const payload = this.options?.session?.lark
if (payload?.type === 'im.message.receive_v1' && payload.event.message.thread_id) {
quote = {
id: payload.event.message.message_id,
replyInThread: true,
}
} else if (payload?.type === 'card.action.trigger') {
// cannot determine whether the card is in thread or not
const { items: [message] } = await this.bot.internal.getImMessage(payload.event.context.open_message_id)
if (message?.thread_id) {
quote = {
id: payload.event.context.open_message_id,
replyInThread: true,
}
}
}
}
if (this.editMessageIds) {
Expand Down Expand Up @@ -49,8 +60,8 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
session.messageId = resp.message_id
session.timestamp = Number(resp.create_time) * 1000
session.userId = resp.sender.id
session.channelId = this.channelId
session.guildId = this.guildId
session.channelId = this.session.channelId
session.guildId = this.session.guildId
session.app.emit(session, 'send', session)
this.results.push(session.event.message)
} catch (e) {
Expand Down
15 changes: 14 additions & 1 deletion adapters/lark/src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ declare module './internal' {
* 获取指定消息的内容
* @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message/get
*/
getImMessage(message_id: string): Promise<GetImMessageResponse>
getImMessage(message_id: string, query?: GetImMessageQuery): Promise<GetImMessageResponse>
/**
* 发送应用内加急
* @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message/urgent_app
Expand Down Expand Up @@ -5428,6 +5428,8 @@ declare module '.' {
root_id?: string
/** 父消息的id open_message_id */
parent_id?: string
/** 消息所属的话题 ID */
thread_id?: string
/** 消息类型 text post card image等等 */
msg_type?: string
/** 消息生成的时间戳(毫秒) */
Expand Down Expand Up @@ -16752,6 +16754,17 @@ export interface GetImMessageResourceQuery {
/** 资源类型,可选"image, file“; image对应消息中的 图片,富文本消息中的图片。 file对应消息中的 文件、音频、视频、(表情包除外) */
type: string
}
export interface GetImMessageQuery {
/**
* 用户 ID 类型
*
* - `open_id`:标识一个用户在某个应用中的身份。同一个用户在不同应用中的 Open ID 不同。
* - `union_id`:标识一个用户在某个应用开发商下的身份。同一用户在同一开发商下的应用中的 Union ID 是相同的,在不同开发商下的应用中的 Union ID 是不同的。通过 Union ID,应用开发商可以把同个用户在多个应用中的身份关联起来。
* - `user_id`:标识一个用户在某个租户内的身份。同一个用户在租户 A 和租户 B 内的 User ID 是不同的。在同一个租户内,一个用户的 User ID 在所有应用(包括商店应用)中都保持一致。User ID 主要用于在不同的应用间打通用户数据。
* @default 'open_id'
*/
user_id_type?: 'open_id' | 'user_id' | 'union_id'
}
export interface UrgentAppImMessageRequest {
/** 该字段标识目标用户的id类型 */
user_id_list: string[]
Expand Down

0 comments on commit ac0e32b

Please sign in to comment.