Compare commits
2 Commits
@egg/lark-
...
@egg/lark-
Author | SHA1 | Date | |
---|---|---|---|
fda12dd90b | |||
0e0c0512ce |
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.12.0",
|
||||
"version": "1.13.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.13.0](http://yingbo.im:3000/zhaoyingbo/egg_tools/compare/@egg/lark-msg-tool@1.12.0...@egg/lark-msg-tool@1.13.0) (2024-10-16)
|
||||
|
||||
### Features
|
||||
|
||||
- **lark-msg:** 修改注入变量的位置 ([0e0c051](http://yingbo.im:3000/zhaoyingbo/egg_tools/commits/0e0c0512ce7272ef9f7940031d0654a9c5279ffe))
|
||||
|
||||
# [1.12.0](http://yingbo.im:3000/zhaoyingbo/egg_tools/compare/@egg/lark-msg-tool@1.11.1...@egg/lark-msg-tool@1.12.0) (2024-10-15)
|
||||
|
||||
### Features
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@egg/lark-msg-tool",
|
||||
"version": "1.12.0",
|
||||
"version": "1.13.0",
|
||||
"description": "Lark Msg Tools for Egg projects",
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
|
@ -100,23 +100,35 @@ class LarkCard<
|
||||
} else if (_.isArray(obj)) {
|
||||
return obj.map(traverseAndReplace)
|
||||
} else if (_.isObject(obj)) {
|
||||
// 给 value 字段注入公共变量
|
||||
if ((obj as any).value) {
|
||||
;(obj as any).value = {
|
||||
...variables,
|
||||
...((obj as any).value || {}),
|
||||
}
|
||||
}
|
||||
return _.mapValues(obj, traverseAndReplace)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
const content = traverseAndReplace(card)
|
||||
|
||||
// 递归遍历content,遇到key是"value"的Object,将variables注入
|
||||
const injectVariables = (obj: { value: any }): any => {
|
||||
if (_.isObject(obj) && !_.isArray(obj)) {
|
||||
if (_.has(obj, "value") && _.isObject(obj.value)) {
|
||||
return {
|
||||
...obj,
|
||||
value: { ...obj.value, ...finalVariables },
|
||||
}
|
||||
}
|
||||
return _.mapValues(obj, injectVariables)
|
||||
} else if (_.isArray(obj)) {
|
||||
return obj.map(injectVariables)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
const finalContent = injectVariables(content)
|
||||
|
||||
this.logger.debug(
|
||||
`Card ${String(cardKey)} final content: ${JSON.stringify(content)}`
|
||||
`Card ${String(cardKey)} final content: ${JSON.stringify(finalContent)}`
|
||||
)
|
||||
return this.stringify ? JSON.stringify(content) : content
|
||||
return this.stringify ? JSON.stringify(finalContent) : finalContent
|
||||
}
|
||||
|
||||
genSuccessCard(content: any) {
|
||||
|
51
test/inject.ts
Normal file
51
test/inject.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import { has, isArray, isObject, mapValues } from "lodash"
|
||||
|
||||
const variables = {
|
||||
content: "分析中,请稍等...",
|
||||
requestId: "1988fcc0-6ca8-4015-b256-b19945c33117",
|
||||
xName: "Group Agent",
|
||||
xAuthor: "AI创新应用组",
|
||||
xIcon: "🔥",
|
||||
}
|
||||
|
||||
const content = {
|
||||
config: { update_multi: true },
|
||||
elements: [
|
||||
{ tag: "markdown", content: "分析中,请稍等..." },
|
||||
{ tag: "hr" },
|
||||
{
|
||||
tag: "note",
|
||||
elements: [
|
||||
{
|
||||
tag: "plain_text",
|
||||
content:
|
||||
"💡 功能由AI创新应用组提供支持,Rid:1988fcc0-6ca8-4015-b256-b19945c33117",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
header: {
|
||||
template: "purple",
|
||||
title: { content: "🔥 感谢使用 Group Agent", tag: "plain_text" },
|
||||
},
|
||||
}
|
||||
|
||||
const injectVariables = (obj: any): any => {
|
||||
type Obj = { value: any }
|
||||
console.log("🚀 ~ obj:", obj)
|
||||
if (isObject(obj) && !isArray((obj as Obj))) {
|
||||
if (has(obj, "value") && isObject(obj.value)) {
|
||||
return {
|
||||
...obj,
|
||||
value: { ...(obj as Obj).value, ...variables },
|
||||
}
|
||||
}
|
||||
return mapValues(obj, injectVariables)
|
||||
} else if (isArray(obj)) {
|
||||
return obj.map(injectVariables)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
const finalContent = injectVariables(content)
|
||||
console.log("🚀 ~ finalContent:", finalContent)
|
Loading…
x
Reference in New Issue
Block a user