Repository navigation
Expand file tree
/
Copy pathindex.ts
More file actions
87 lines (81 loc) · 2.79 KB
/
Copy pathindex.ts
File metadata and controls
87 lines (81 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import type { OpenClawPluginApi } from "openclaw/plugin-sdk/feishu";
import { awadaPlugin } from "./src/channel.js";
import { setAwadaRuntime } from "./src/runtime.js";
import { registerCustomerDb, type CustomerDbConfig } from "./src/customerdb.js";
export { monitorAwadaProvider } from "./src/monitor.js";
export { probeAwada } from "./src/probe.js";
export { sendTextToAwada, encodeAwadaTo, decodeAwadaTo } from "./src/send.js";
export { publishTextToAwada } from "./src/publisher.js";
export { awadaPlugin } from "./src/channel.js";
type AwadaPluginConfig = {
/**
* When set, activates the built-in CustomerDB feature:
* injects customer context into LLM prompts and registers silent sales
* commands (payment_success, club_join).
*
* Example openclaw.json:
* "plugins": {
* "entries": {
* "awada": {
* "config": {
* "customerdb": {
* "agentId": "sales-cs",
* "workspaceDir": "/home/user/.openclaw/workspace-sales-cs"
* }
* }
* }
* }
* }
*/
customerdb?: CustomerDbConfig & { enabled?: boolean };
};
// Custom config schema that allows the `customerdb` field.
// Using emptyPluginConfigSchema() would reject any config key (additionalProperties: false).
const awadaConfigSchema = {
safeParse(
value: unknown,
): { success: true; data: unknown } | { success: false; error: string } {
if (value === undefined) return { success: true, data: undefined };
if (!value || typeof value !== "object" || Array.isArray(value)) {
return { success: false, error: "expected config object" };
}
const obj = value as Record<string, unknown>;
const allowed = new Set(["customerdb"]);
const extra = Object.keys(obj).filter((k) => !allowed.has(k));
if (extra.length > 0) {
return { success: false, error: `unknown config keys: ${extra.join(", ")}` };
}
return { success: true, data: obj };
},
jsonSchema: {
type: "object",
additionalProperties: false,
properties: {
customerdb: {
type: "object",
additionalProperties: false,
properties: {
enabled: { type: "boolean" },
agentId: { type: "string" },
workspaceDir: { type: "string" },
},
},
},
},
};
const plugin = {
id: "awada",
name: "Awada",
description: "Awada channel plugin — WeChat via Redis bridge",
configSchema: awadaConfigSchema,
register(api: OpenClawPluginApi) {
setAwadaRuntime(api.runtime);
api.registerChannel({ plugin: awadaPlugin });
const pluginCfg = (api.pluginConfig ?? {}) as AwadaPluginConfig;
const cdbCfg = pluginCfg.customerdb;
if (cdbCfg && cdbCfg.enabled !== false && cdbCfg.agentId) {
registerCustomerDb(api, cdbCfg);
}
},
};
export default plugin;