feat(lark-msg-tool): 重构用户Id和OpenId获取方法以支持事件和动作消息体
All checks were successful
/ release (push) Successful in 25s

This commit is contained in:
zhaoyingbo 2024-12-17 11:41:02 +00:00
parent 404d45842a
commit fc8399e10b

View File

@ -101,8 +101,6 @@ class LarkBody {
this.eventType = this.getEventType(eventBody)
this.isMessageEvent = this.getIsMessageEvent(eventBody)
this.msgType = this.getMsgType(eventBody)
this.userId = this.getUserId(eventBody)
this.openId = this.getOpenId(eventBody)
this.msgText = this.getMsgText(eventBody)
this.rawMsgText = this.getRawMsgText(eventBody)
this.chatType = this.getChatType(eventBody)
@ -121,6 +119,8 @@ class LarkBody {
this.chatId = this.getChatId(body)
this.messageId = this.getMessageId(body)
this.userId = this.getUserId(body)
this.openId = this.getOpenId(body)
this.isLarkBody = this.isEvent || this.isAction
}
@ -169,24 +169,6 @@ class LarkBody {
return body?.event?.message?.message_type
}
/**
* Id
* @param body
* @returns Id
*/
private getUserId(body: LarkEvent.Data) {
return body?.event?.sender?.sender_id?.user_id
}
/**
* OpenId
* @param body
* @returns OpenId
*/
private getOpenId(body: LarkEvent.Data) {
return body?.event?.sender?.sender_id?.open_id
}
/**
*
* @param body
@ -299,6 +281,28 @@ class LarkBody {
return ""
}
/**
* Id
* @param body
* @returns Id
*/
private getUserId(body: LarkEvent.Data | LarkAction.Data) {
if (this.getIsEvent(body)) return body?.event?.sender?.sender_id?.user_id
if (this.getIsAction(body)) return body?.user_id
return ""
}
/**
* OpenId
* @param body
* @returns OpenId
*/
private getOpenId(body: LarkEvent.Data | LarkAction.Data) {
if (this.getIsEvent(body)) return body?.event?.sender?.sender_id?.open_id
if (this.getIsAction(body)) return body?.open_id
return ""
}
/**
*
* @param name