All checks were successful
Egg Server MIflow / build-image (push) Successful in 1m5s
41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import { LarkServer } from "../../types/larkServer"
|
||
import LarkBaseService from "./base"
|
||
|
||
class LarkMessageService extends LarkBaseService {
|
||
/**
|
||
* 发送卡片
|
||
* @param {LarkServer.ReceiveIDType} receive_id_type 消息接收者id类型 open_id/user_id/union_id/email/chat_id
|
||
* @param {string} receive_id 消息接收者的ID,ID类型应与查询参数receive_id_type 对应
|
||
* @param {MsgType} msg_type 消息类型 包括:text、post、image、file、audio、media、sticker、interactive、share_chat、share_user
|
||
* @param {string} content 消息内容,JSON结构序列化后的字符串。不同msg_type对应不同内容
|
||
*/
|
||
async send(
|
||
receive_id_type: LarkServer.ReceiveIDType,
|
||
receive_id: string,
|
||
msg_type: LarkServer.MsgType,
|
||
content: string
|
||
) {
|
||
const path = `/im/v1/messages?receive_id_type=${receive_id_type}`
|
||
if (msg_type === "text" && !content.includes('"text"')) {
|
||
content = JSON.stringify({ text: content })
|
||
}
|
||
return this.post<LarkServer.BaseRes>(path, {
|
||
receive_id,
|
||
msg_type,
|
||
content,
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 更新卡片
|
||
* @param {string} message_id 消息id
|
||
* @param {string} content 消息内容,JSON结构序列化后的字符串。不同msg_type对应不同内容
|
||
*/
|
||
async update(message_id: string, content: string) {
|
||
const path = `/im/v1/messages/${message_id}`
|
||
return this.patch<LarkServer.BaseRes>(path, { content })
|
||
}
|
||
}
|
||
|
||
export default LarkMessageService
|