52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
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)
|