From 60f14d6a94cdc8172ca22849d872218829b72ced Mon Sep 17 00:00:00 2001 From: zhaoyingbo Date: Sat, 25 Jan 2025 09:30:29 +0000 Subject: [PATCH] =?UTF-8?q?feat(net-tool):=20=E9=87=8D=E6=9E=84=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=9B=9E=E5=A4=8D=E9=80=BB=E8=BE=91=EF=BC=8C=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E8=AE=BE=E7=BD=AE=E5=9B=9E=E5=A4=8D=E6=B6=88=E6=81=AF?= =?UTF-8?q?ID=E5=92=8C=E7=B1=BB=E5=9E=8B=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/net-tool/src/larkServer/message.ts | 41 ++++++++++++--------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/packages/net-tool/src/larkServer/message.ts b/packages/net-tool/src/larkServer/message.ts index b8480f6..617413f 100644 --- a/packages/net-tool/src/larkServer/message.ts +++ b/packages/net-tool/src/larkServer/message.ts @@ -144,28 +144,35 @@ class LarkMessageService extends LarkBaseService { return this.reply(messageId, "interactive", content) } + private repliedMessageId: string = ""; + private replyMessageId: string = ""; + private replyMsgType: "text" | "interactive" = "interactive"; + /** - * 更新或回复消息 + * 设置回复消息的ID和类型 * @param messageId 消息ID * @param msgType 消息类型 包括:text、interactive - * @returns 一个异步函数,用于更新或回复消息 */ - updateReplyMessage( - messageId: string, - msgType: "text" | "interactive" = "interactive" - ) { - let repliedMessageId = "" - return async (content: string) => { - if (repliedMessageId) { - await this.update(repliedMessageId, content, msgType === "text") - return repliedMessageId - } - const res = await this.reply(messageId, msgType, content) - if ("data" in res) { - repliedMessageId = res.data.message_id - } - return repliedMessageId + setReplyMessage(messageId: string, msgType: "text" | "interactive" = "interactive") { + this.replyMessageId = messageId; + this.replyMsgType = msgType; + } + + /** + * 更新或回复消息 + * @param content 消息内容 + * @returns 更新或回复的消息ID + */ + async updateOrReplyMessage(content: string) { + if (this.repliedMessageId) { + await this.update(this.repliedMessageId, content, this.replyMsgType === "text") + return this.repliedMessageId } + const res = await this.reply(this.replyMessageId, this.replyMsgType, content) + if ("data" in res) { + this.repliedMessageId = res.data.message_id + } + return this.repliedMessageId } }