Compare commits

...

2 Commits

Author SHA1 Message Date
3e6cf68869 chore(release): publish
- @egg/lark-msg-tool@1.19.0
2024-12-04 09:50:42 +00:00
617ff977dc feat(lark-msg-tool): 增加 LarkBody 类属性和方法以支持更多消息类型和用户信息
All checks were successful
/ release (push) Successful in 25s
2024-12-04 09:50:17 +00:00
4 changed files with 78 additions and 2 deletions

2
package-lock.json generated
View File

@ -12373,7 +12373,7 @@
},
"packages/lark-msg-tool": {
"name": "@egg/lark-msg-tool",
"version": "1.18.0",
"version": "1.19.0",
"license": "ISC",
"dependencies": {
"@egg/logger": "^1.6.0",

View File

@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [1.19.0](http://yingbo.im:3000/zhaoyingbo/egg_tools/compare/@egg/lark-msg-tool@1.18.0...@egg/lark-msg-tool@1.19.0) (2024-12-04)
### Features
- **lark-msg-tool:** 增加 LarkBody 类属性和方法以支持更多消息类型和用户信息 ([617ff97](http://yingbo.im:3000/zhaoyingbo/egg_tools/commits/617ff977dc0917fde4717222e1ec9733bda5cdd0))
# 1.18.0 (2024-12-02)
### Features

View File

@ -1,6 +1,6 @@
{
"name": "@egg/lark-msg-tool",
"version": "1.18.0",
"version": "1.19.0",
"description": "Lark Msg Tools for Egg projects",
"type": "module",
"main": "src/index.ts",

View File

@ -2,25 +2,83 @@ import { LarkAction, LarkEvent } from "../types"
class LarkBody {
protected body: LarkEvent.Data | LarkAction.Data
/**
*
*/
public isEvent: boolean = false
/**
* Action消息
*/
public isAction: boolean = false
/**
*
*/
public eventType?: LarkEvent.Data["header"]["event_type"]
/**
*
*/
public isMessageEvent?: boolean
/**
*
*/
public msgType?: LarkEvent.Message["message_type"]
/**
* Id
*/
public userId?: LarkEvent.UserIdInfo["user_id"]
/**
* OpenId
*/
public openId?: LarkEvent.UserIdInfo["open_id"]
/**
*
*/
public msgText: string = ""
/**
*
*/
public rawMsgText: string = ""
/**
*
*/
public chatType?: LarkEvent.Message["chat_type"]
/**
* P2P聊天
*/
public isP2P?: boolean
/**
*
*/
public isInGroup?: boolean
/**
*
*/
public mentions?: LarkEvent.Mention[]
/**
*
*/
public mentionedRobot?: LarkEvent.Mention
/**
* Action类型
*/
public actionType?: LarkAction.Data["action"]["tag"]
/**
* Action参数
*/
public actionValue?: LarkAction.Data["action"]["value"]
/**
* Action选项
*/
public actionOption?: LarkAction.Data["action"]["option"]
/**
* Id
*/
public chatId:
| LarkEvent.Message["chat_id"]
| LarkAction.Data["open_chat_id"] = ""
/**
* Id
*/
public messageId:
| LarkEvent.Message["message_id"]
| LarkAction.Data["open_message_id"] = ""
@ -47,6 +105,7 @@ class LarkBody {
this.isP2P = this.chatType === "p2p"
this.isInGroup = this.chatType === "group"
this.mentions = this.getMentions(eventBody)
this.mentionedRobot = this.getMentionedRobot(eventBody)
}
if (this.isAction) {
@ -175,6 +234,17 @@ class LarkBody {
return body?.event?.message?.mentions
}
/**
*
* @param body
* @returns
*/
private getMentionedRobot(body: LarkEvent.Data) {
const mentions = this.getMentions(body)
// 返回第一个没有user_id的mention
return mentions?.find((mention) => !mention.id?.user_id)
}
/**
* Action类型
* @param body Action消息体