@emotion-machine/claw-messenger 0.1.8 → 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/dist/outbound/send.js +24 -2
- 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);
|
package/dist/outbound/send.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as pluginSdk from "openclaw/plugin-sdk";
|
|
2
2
|
function stripLegacyNamespacePrefix(target) {
|
|
3
3
|
let normalized = target.trim();
|
|
4
4
|
while (normalized.startsWith("claw-messenger:") || normalized.startsWith("linq:")) {
|
|
@@ -10,11 +10,33 @@ function stripLegacyNamespacePrefix(target) {
|
|
|
10
10
|
}
|
|
11
11
|
return normalized;
|
|
12
12
|
}
|
|
13
|
+
function fallbackNormalizeE164(input) {
|
|
14
|
+
if (!input)
|
|
15
|
+
return null;
|
|
16
|
+
const stripped = input.trim().replace(/[\s\-().]/g, "");
|
|
17
|
+
if (/^\+\d{10,15}$/.test(stripped))
|
|
18
|
+
return stripped;
|
|
19
|
+
if (/^\d{10,15}$/.test(stripped))
|
|
20
|
+
return `+${stripped}`;
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
function normalizeE164Compat(input) {
|
|
24
|
+
const sdkNormalize = typeof pluginSdk.normalizeE164 === "function" ? pluginSdk.normalizeE164 : null;
|
|
25
|
+
if (sdkNormalize) {
|
|
26
|
+
try {
|
|
27
|
+
return sdkNormalize(input);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// Older OpenClaw builds may not expose a callable normalizeE164 helper yet.
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return fallbackNormalizeE164(input);
|
|
34
|
+
}
|
|
13
35
|
export function normalizeDirectTarget(target) {
|
|
14
36
|
const stripped = stripLegacyNamespacePrefix(target);
|
|
15
37
|
if (!stripped)
|
|
16
38
|
return null;
|
|
17
|
-
return
|
|
39
|
+
return normalizeE164Compat(stripped) ?? stripped;
|
|
18
40
|
}
|
|
19
41
|
export async function sendText(ws, to, text, service) {
|
|
20
42
|
return sendMessage(ws, to, [{ type: "text", value: text }], service);
|