Skip to content

Commit

Permalink
feat(feishu): add internal api
Browse files Browse the repository at this point in the history
  • Loading branch information
XxLittleCxX committed Aug 29, 2023
1 parent a3ea0c8 commit af36682
Show file tree
Hide file tree
Showing 9 changed files with 27,594 additions and 315 deletions.
10 changes: 5 additions & 5 deletions adapters/lark/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class LarkBot extends Bot<LarkBot.Config> {
}

private async refreshToken() {
const { tenant_access_token: token } = await this.internal.getTenantAccessToken({
const { tenant_access_token: token } = await this.internal.tenantAccessTokenInternalAuth({
app_id: this.config.appId,
app_secret: this.config.appSecret,
})
Expand All @@ -68,14 +68,14 @@ export class LarkBot extends Bot<LarkBot.Config> {
}

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

async deleteMessage(channelId: string, messageId: string) {
await this.internal.deleteMessage(messageId)
await this.internal.deleteImMessage(messageId)
}
}

Expand All @@ -100,14 +100,14 @@ export namespace LarkBot {
Schema.object({
platform: Schema.const('feishu').required(),
}),
Quester.createConfig('https://open.feishu.cn/open-apis/'),
Quester.createConfig('https://open.feishu.cn/'),
HttpServer.createConfig('/feishu'),
]),
Schema.intersect([
Schema.object({
platform: Schema.const('lark').required(),
}),
Quester.createConfig('https://open.larksuite.com/open-apis/'),
Quester.createConfig('https://open.larksuite.com/'),
HttpServer.createConfig('/lark'),
]),
]),
Expand Down
16 changes: 10 additions & 6 deletions adapters/lark/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { h, MessageEncoder, Quester } from '@satorijs/satori'
import FormData from 'form-data'

import { LarkBot } from './bot'
import { BaseResponse, Message, MessageContent, MessageType } from './types'
import { BaseResponse, Message } from './types'
import { extractIdType } from './utils'
import { MessageContent, MessageType } from './types/message'

export interface Addition {
file: MessageContent.MediaContents
Expand All @@ -22,12 +23,14 @@ export class LarkMessageEncoder extends MessageEncoder<LarkBot> {

async post(data?: any) {
try {
let resp: BaseResponse & { data: Message }
let resp: BaseResponse & { data?: Message }
if (this.quote) {
resp = await this.bot.internal?.replyMessage(this.quote, data)
resp = await this.bot.internal?.replyImMessage(this.quote, data)
} else {
data.receive_id = this.channelId
resp = await this.bot.internal?.sendMessage(extractIdType(this.channelId), data)
resp = await this.bot.internal?.createImMessage(data, {
receive_id_type: extractIdType(this.channelId),
})
}
const session = this.bot.session()
session.messageId = resp.data.message_id
Expand Down Expand Up @@ -92,7 +95,7 @@ export class LarkMessageEncoder extends MessageEncoder<LarkBot> {

if (type === 'image') {
payload.append('image_type', 'message')
const { data } = await this.bot.internal.uploadImage(payload)
const { data } = await this.bot.internal.createImImage(payload)
return {
type: 'image',
file: {
Expand All @@ -118,7 +121,7 @@ export class LarkMessageEncoder extends MessageEncoder<LarkBot> {
}
}
payload.append('file_name', filename)
const { data } = await this.bot.internal.uploadFile(payload)
const { data } = await this.bot.internal.createImFile(payload)
return {
type: msgType,
file: {
Expand Down Expand Up @@ -161,6 +164,7 @@ export class LarkMessageEncoder extends MessageEncoder<LarkBot> {
if (attrs.url) {
await this.flush()
this.addition = await this.sendFile(type, attrs.url)
await this.flush()
}
break
case 'figure': // FIXME: treat as message element for now
Expand Down
Loading

0 comments on commit af36682

Please sign in to comment.