Compare commits

...

2 Commits

Author SHA1 Message Date
478b8b4da3 chore(release): publish
- @egg/lark-msg-tool@1.14.0
2024-10-29 06:59:45 +00:00
2bfa241511 feat(lark-msg): 优化event和action的判断方式
All checks were successful
/ release (push) Successful in 53s
2024-10-29 06:58:26 +00:00
4 changed files with 43 additions and 15 deletions

2
package-lock.json generated
View File

@ -12122,7 +12122,7 @@
},
"packages/lark-msg-tool": {
"name": "@egg/lark-msg-tool",
"version": "1.13.2",
"version": "1.14.0",
"license": "ISC",
"dependencies": {
"@egg/logger": "^1.4.4",

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.14.0](http://yingbo.im:3000/zhaoyingbo/egg_tools/compare/@egg/lark-msg-tool@1.13.2...@egg/lark-msg-tool@1.14.0) (2024-10-29)
### Features
- **lark-msg:** 优化event和action的判断方式 ([2bfa241](http://yingbo.im:3000/zhaoyingbo/egg_tools/commits/2bfa241511d2f85ab037ba7908f2dfd4f52d09b7))
## [1.13.2](http://yingbo.im:3000/zhaoyingbo/egg_tools/compare/@egg/lark-msg-tool@1.13.1...@egg/lark-msg-tool@1.13.2) (2024-10-17)
### Bug Fixes

View File

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

View File

@ -2,8 +2,10 @@ import { LarkAction, LarkEvent } from "../types"
class LarkBody {
protected body: LarkEvent.Data | LarkAction.Data
public isEventMsg: boolean = false
public isActionMsg: boolean = false
public isEvent: boolean = false
public isAction: boolean = false
public eventType?: LarkEvent.Data["header"]["event_type"]
public isMessageEvent?: boolean
public msgType?: LarkEvent.Message["message_type"]
public userId?: LarkEvent.UserIdInfo["user_id"]
public msgText: string = ""
@ -26,11 +28,13 @@ class LarkBody {
*/
constructor(body: LarkEvent.Data | LarkAction.Data) {
this.body = body
this.isEventMsg = this.getIsEventMsg(body)
this.isActionMsg = this.getIsActionMsg(body)
this.isEvent = this.getIsEvent(body)
this.isAction = this.getIsAction(body)
if (this.isEventMsg) {
if (this.isEvent) {
const eventBody = body as LarkEvent.Data
this.eventType = this.getEventType(eventBody)
this.isMessageEvent = this.getIsMessageEvent(eventBody)
this.msgType = this.getMsgType(eventBody)
this.userId = this.getUserId(eventBody)
this.msgText = this.getMsgText(eventBody)
@ -39,7 +43,7 @@ class LarkBody {
this.mentions = this.getMentions(eventBody)
}
if (this.isActionMsg) {
if (this.isAction) {
const actionBody = body as LarkAction.Data
this.actionType = this.getActionType(actionBody)
this.actionValue = this.getActionValue(actionBody)
@ -50,13 +54,31 @@ class LarkBody {
this.messageId = this.getMessageId(body)
}
/**
*
* @param body
* @returns
*/
private getEventType(body: LarkEvent.Data) {
return body?.header?.event_type
}
/**
*
* @param body
* @returns
*/
private getIsMessageEvent(body: LarkEvent.Data) {
return body?.header?.event_type === "im.message.receive_v1"
}
/**
*
* @param body
* @returns
*/
private getIsEventMsg(body: any): body is LarkEvent.Data {
return body?.header?.event_type === "im.message.receive_v1"
private getIsEvent(body: any): body is LarkEvent.Data {
return !!body?.event
}
/**
@ -64,7 +86,7 @@ class LarkBody {
* @param body Action消息体
* @returns Action消息
*/
private getIsActionMsg(body: any): body is LarkAction.Data {
private getIsAction(body: any): body is LarkAction.Data {
return !!body?.action
}
@ -171,8 +193,8 @@ class LarkBody {
* @returns Id
*/
private getChatId(body: LarkEvent.Data | LarkAction.Data) {
if (this.getIsEventMsg(body)) return body?.event?.message?.chat_id
if (this.getIsActionMsg(body)) return body?.open_chat_id
if (this.getIsEvent(body)) return body?.event?.message?.chat_id
if (this.getIsAction(body)) return body?.open_chat_id
return ""
}
@ -182,8 +204,8 @@ class LarkBody {
* @returns Id
*/
private getMessageId(body: LarkEvent.Data | LarkAction.Data) {
if (this.getIsEventMsg(body)) return body?.event?.message?.message_id
if (this.getIsActionMsg(body)) return body?.open_message_id
if (this.getIsEvent(body)) return body?.event?.message?.message_id
if (this.getIsAction(body)) return body?.open_message_id
return ""
}
}