@emotion-machine/claw-messenger 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/channel.d.ts +1 -1
- package/dist/channel.js +30 -6
- package/package.json +1 -1
package/dist/channel.d.ts
CHANGED
package/dist/channel.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as pluginSdk from "openclaw/plugin-sdk";
|
|
2
2
|
import { ClawMessengerConfigSchema } from "./config.js";
|
|
3
3
|
import { getRuntime } from "./runtime.js";
|
|
4
4
|
import { WsClient } from "./ws/client.js";
|
|
@@ -14,10 +14,34 @@ const EMOJI_TO_REACTION = {
|
|
|
14
14
|
function emojiToReaction(emoji) {
|
|
15
15
|
return EMOJI_TO_REACTION[emoji];
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
// -- Account resolution --
|
|
18
|
+
const FALLBACK_ACCOUNT_ID = "default";
|
|
19
|
+
function hasAccountId(value) {
|
|
20
|
+
if (typeof value !== "string")
|
|
21
|
+
return false;
|
|
22
|
+
const trimmed = value.trim();
|
|
23
|
+
return Boolean(trimmed) && trimmed !== "undefined" && trimmed !== "null";
|
|
24
|
+
}
|
|
25
|
+
function normalizeAccountIdCompat(accountId) {
|
|
26
|
+
const fallback = hasAccountId(accountId) ? accountId.trim() : FALLBACK_ACCOUNT_ID;
|
|
27
|
+
const normalize = pluginSdk.normalizeAccountId;
|
|
28
|
+
if (typeof normalize === "function") {
|
|
29
|
+
try {
|
|
30
|
+
const normalized = normalize(fallback);
|
|
31
|
+
if (hasAccountId(normalized))
|
|
32
|
+
return normalized.trim();
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
// Older OpenClaw SDKs can expose helpers differently when plugins are globally installed.
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return fallback;
|
|
39
|
+
}
|
|
40
|
+
const DEFAULT_ACCOUNT_ID = normalizeAccountIdCompat(pluginSdk.DEFAULT_ACCOUNT_ID);
|
|
41
|
+
function resolveAccount(cfg, accountId) {
|
|
18
42
|
const cloudConfig = (cfg.channels?.["claw-messenger"] ?? {});
|
|
19
43
|
return {
|
|
20
|
-
accountId: DEFAULT_ACCOUNT_ID,
|
|
44
|
+
accountId: normalizeAccountIdCompat(accountId ?? DEFAULT_ACCOUNT_ID),
|
|
21
45
|
enabled: cloudConfig.enabled !== false,
|
|
22
46
|
apiKey: cloudConfig.apiKey ?? "",
|
|
23
47
|
serverUrl: cloudConfig.serverUrl ?? "wss://claw-messenger.onrender.com",
|
|
@@ -80,7 +104,7 @@ export const clawMessengerPlugin = {
|
|
|
80
104
|
const ws = wsClients.get(account.accountId);
|
|
81
105
|
if (!ws)
|
|
82
106
|
throw new Error("Not connected to claw-messenger");
|
|
83
|
-
await sendText(ws, id, PAIRING_APPROVED_MESSAGE, account.preferredService);
|
|
107
|
+
await sendText(ws, id, pluginSdk.PAIRING_APPROVED_MESSAGE, account.preferredService);
|
|
84
108
|
},
|
|
85
109
|
},
|
|
86
110
|
capabilities: {
|
|
@@ -92,7 +116,7 @@ export const clawMessengerPlugin = {
|
|
|
92
116
|
blockStreaming: true,
|
|
93
117
|
},
|
|
94
118
|
reload: { configPrefixes: ["channels.claw-messenger"] },
|
|
95
|
-
configSchema: buildChannelConfigSchema(ClawMessengerConfigSchema),
|
|
119
|
+
configSchema: pluginSdk.buildChannelConfigSchema(ClawMessengerConfigSchema),
|
|
96
120
|
config: {
|
|
97
121
|
listAccountIds: () => [DEFAULT_ACCOUNT_ID],
|
|
98
122
|
resolveAccount: (cfg, accountId) => resolveAccount(cfg, accountId),
|
|
@@ -126,7 +150,7 @@ export const clawMessengerPlugin = {
|
|
|
126
150
|
allowFrom: account.config.allowFrom ?? [],
|
|
127
151
|
policyPath: "channels.claw-messenger.dmPolicy",
|
|
128
152
|
allowFromPath: "channels.claw-messenger.",
|
|
129
|
-
approveHint: formatPairingApproveHint("claw-messenger"),
|
|
153
|
+
approveHint: pluginSdk.formatPairingApproveHint("claw-messenger"),
|
|
130
154
|
}),
|
|
131
155
|
collectWarnings: ({ cfg }) => {
|
|
132
156
|
const account = resolveAccount(cfg);
|