Skip to content

Commit

Permalink
feat(lark): support bot.editMessage()
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jun 26, 2023
1 parent 2dd501e commit 593a39b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
15 changes: 11 additions & 4 deletions adapters/lark/src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Bot, Context, Logger, Quester, Schema } from '@satorijs/satori'
import { Bot, Context, h, Logger, Quester, Schema } from '@satorijs/satori'

import { HttpServer } from './http'
import { LarkMessageEncoder } from './message'
Expand Down Expand Up @@ -38,12 +38,12 @@ export class LarkBot extends Bot<LarkBot.Config> {
ctx.plugin(HttpServer, this)
}

async initialize(): Promise<void> {
async initialize() {
await this.refreshToken()
this.online()
}

private async refreshToken(): Promise<void> {
private async refreshToken() {
const { tenant_access_token: token } = await this.internal.getTenantAccessToken({
app_id: this.config.appId,
app_secret: this.config.appSecret,
Expand All @@ -66,7 +66,14 @@ export class LarkBot extends Bot<LarkBot.Config> {
this.http.config.headers.Authorization = `Bearer ${v}`
}

async deleteMessage(channelId: string, messageId: string): Promise<void> {
async editMessage(channelId: string, messageId: string, content: h.Fragment) {
await this.internal.updateMessage(messageId, {
content: h.normalize(content).join(''),
msg_type: 'text',
})
}

async deleteMessage(channelId: string, messageId: string) {
await this.internal.deleteMessage(messageId)
}
}
Expand Down
3 changes: 3 additions & 0 deletions adapters/lark/src/types/message/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ declare module '../internal' {
sendMessage(receive_id_type: Lark.ReceiveIdType, message: MessagePayload): Promise<BaseResponse & { data: Message }>
/** @see https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message/reply */
replyMessage(message_id: string, message: MessagePayload): Promise<BaseResponse & { data: Message }>
/** @see https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message/update */
updateMessage(message_id: string, message: Omit<MessagePayload, 'receive_id'>): Promise<BaseResponse & { data: Message }>
/** @see https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message/get */
getMessage(message_id: string): Promise<BaseResponse & { data: Message }>
/** @see https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message/delete */
Expand All @@ -191,6 +193,7 @@ Internal.define({
},
'/im/v1/messages/{message_id}': {
GET: 'getMessage',
PUT: 'updateMessage',
DELETE: 'deleteMessage',
},
'/im/v1/messages/{message_id}/read_users': {
Expand Down

0 comments on commit 593a39b

Please sign in to comment.