Compare commits
2 Commits
@egg/lark-
...
@egg/lark-
Author | SHA1 | Date | |
---|---|---|---|
478b8b4da3 | |||
2bfa241511 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -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",
|
||||
|
@ -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
|
||||
|
@ -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",
|
||||
|
@ -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 ""
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user