Compare commits
4 Commits
@egg/net-t
...
@egg/net-t
Author | SHA1 | Date | |
---|---|---|---|
6019819123 | |||
b52682b96d | |||
94005549bf | |||
ee271ed4cc |
4
package-lock.json
generated
4
package-lock.json
generated
@ -12258,7 +12258,7 @@
|
||||
},
|
||||
"packages/lark-msg-tool": {
|
||||
"name": "@egg/lark-msg-tool",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.1",
|
||||
"license": "ISC"
|
||||
},
|
||||
"packages/logger": {
|
||||
@ -12272,7 +12272,7 @@
|
||||
},
|
||||
"packages/net-tool": {
|
||||
"name": "@egg/net-tool",
|
||||
"version": "1.6.3",
|
||||
"version": "1.6.4",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@egg/logger": "^1.4.2",
|
||||
|
@ -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.2.1 (2024-09-24)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- **logger:** 修复正式环境下也输出彩色日志的问题 ([3290875](http://yingbo.im:3000/zhaoyingbo/egg_tools/commits/329087504de42b31adb35998b911fa509e1d8fd9))
|
||||
|
||||
# [1.2.0](http://yingbo.im:3000/zhaoyingbo/egg_tools/compare/@egg/lark-msg-tool@1.1.0...@egg/lark-msg-tool@1.2.0) (2024-08-21)
|
||||
|
||||
### Features
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@egg/lark-msg-tool",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.1",
|
||||
"description": "Lark Msg Tools for Egg projects",
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
|
@ -2,64 +2,64 @@ import { LarkAction, LarkEvent } from "./types"
|
||||
|
||||
/**
|
||||
* 是否为事件消息
|
||||
* @param {LarkEvent.Data} body - 事件消息体
|
||||
* @returns {boolean} 是否为事件消息
|
||||
* @param body 事件消息体
|
||||
* @returns 是否为事件消息
|
||||
*/
|
||||
export const getIsEventMsg = (body: LarkEvent.Data): boolean => {
|
||||
export const getIsEventMsg = (body: LarkEvent.Data) => {
|
||||
return body?.header?.event_type === "im.message.receive_v1"
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取事件文本类型
|
||||
* @param {LarkEvent.Data} body - 事件消息体
|
||||
* @returns {string | undefined} 事件文本类型
|
||||
* @param body 事件消息体
|
||||
* @returns 事件文本类型
|
||||
*/
|
||||
export const getMsgType = (body: LarkEvent.Data): string | undefined => {
|
||||
export const getMsgType = (body: LarkEvent.Data) => {
|
||||
return body?.event?.message?.message_type
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对话流Id
|
||||
* @param {LarkEvent.Data} body - 事件消息体
|
||||
* @returns {string | undefined} 对话流Id
|
||||
* @param body 事件消息体
|
||||
* @returns 对话流Id
|
||||
*/
|
||||
export const getChatId = (body: LarkEvent.Data): string | undefined => {
|
||||
export const getChatId = (body: LarkEvent.Data) => {
|
||||
return body?.event?.message?.chat_id
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户Id
|
||||
* @param {LarkEvent.Data} body - 事件消息体
|
||||
* @returns {string | undefined} 用户Id
|
||||
* @param body 事件消息体
|
||||
* @returns 用户Id
|
||||
*/
|
||||
export const getUserId = (body: LarkEvent.Data): string | undefined => {
|
||||
export const getUserId = (body: LarkEvent.Data) => {
|
||||
return body?.event?.sender?.sender_id?.user_id
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为Action消息
|
||||
* @param {LarkAction.Data} body - Action消息体
|
||||
* @returns {boolean} 是否为Action消息
|
||||
* @param body Action消息体
|
||||
* @returns 是否为Action消息
|
||||
*/
|
||||
export const getIsActionMsg = (body: LarkAction.Data): boolean => {
|
||||
export const getIsActionMsg = (body: LarkAction.Data) => {
|
||||
return !!body?.action
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Action类型
|
||||
* @param {LarkAction.Data} body - Action消息体
|
||||
* @returns {string | undefined} Action类型
|
||||
* @param body Action消息体
|
||||
* @returns Action类型
|
||||
*/
|
||||
export const getActionType = (body: LarkAction.Data): string | undefined => {
|
||||
export const getActionType = (body: LarkAction.Data) => {
|
||||
return body?.action?.tag
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文本内容并剔除艾特信息
|
||||
* @param {LarkEvent.Data} body - 事件消息体
|
||||
* @returns {string} 文本内容
|
||||
* @param body 事件消息体
|
||||
* @returns 文本内容
|
||||
*/
|
||||
export const getMsgText = (body: LarkEvent.Data): string => {
|
||||
export const getMsgText = (body: LarkEvent.Data) => {
|
||||
try {
|
||||
const { text }: { text: string } = JSON.parse(body?.event?.message?.content)
|
||||
// 去掉@_user_1相关的内容,例如 '@_user_1 测试' -> '测试'
|
||||
@ -72,19 +72,19 @@ export const getMsgText = (body: LarkEvent.Data): string => {
|
||||
|
||||
/**
|
||||
* 获取聊天类型
|
||||
* @param {LarkEvent.Data} body - 事件消息体
|
||||
* @returns {string | undefined} 聊天类型
|
||||
* @param body 事件消息体
|
||||
* @returns 聊天类型
|
||||
*/
|
||||
export const getChatType = (body: LarkEvent.Data): string | undefined => {
|
||||
export const getChatType = (body: LarkEvent.Data) => {
|
||||
return body?.event?.message?.chat_type
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取艾特信息
|
||||
* @param {LarkEvent.Data} body - 事件消息体
|
||||
* @returns {Array | undefined} 艾特信息
|
||||
* @param body 事件消息体
|
||||
* @returns 艾特信息
|
||||
*/
|
||||
export const getMentions = (body: LarkEvent.Data): Array<any> | undefined => {
|
||||
export const getMentions = (body: LarkEvent.Data) => {
|
||||
return body?.event?.message?.mentions
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,17 @@ export namespace LarkEvent {
|
||||
* 消息类型
|
||||
* @example text、post、image、file、audio、media、sticker、interactive、share_chat、share_user
|
||||
*/
|
||||
message_type: string
|
||||
message_type:
|
||||
| "text"
|
||||
| "post"
|
||||
| "image"
|
||||
| "file"
|
||||
| "audio"
|
||||
| "media"
|
||||
| "sticker"
|
||||
| "interactive"
|
||||
| "share_chat"
|
||||
| "share_user"
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,6 +3,10 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.6.4](http://yingbo.im:3000/zhaoyingbo/egg_tools/compare/@egg/net-tool@1.6.3...@egg/net-tool@1.6.4) (2024-09-24)
|
||||
|
||||
**Note:** Version bump only for package @egg/net-tool
|
||||
|
||||
## [1.6.3](http://yingbo.im:3000/zhaoyingbo/egg_tools/compare/@egg/net-tool@1.6.2...@egg/net-tool@1.6.3) (2024-09-23)
|
||||
|
||||
**Note:** Version bump only for package @egg/net-tool
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@egg/net-tool",
|
||||
"version": "1.6.3",
|
||||
"version": "1.6.4",
|
||||
"description": "Net Tools for Egg projects",
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
|
@ -468,7 +468,9 @@ class NetTool extends NetToolBase {
|
||||
* @returns 一个表示200 OK的响应对象。
|
||||
*/
|
||||
ok(data?: any) {
|
||||
this.logger.info(`return a ok response: ${JSON.stringify(data)}`)
|
||||
this.logger.info(
|
||||
`return a ok response${data ? ": " + JSON.stringify(data) : ""}`
|
||||
)
|
||||
return Response.json({
|
||||
code: 0,
|
||||
message: "success",
|
||||
|
Loading…
x
Reference in New Issue
Block a user