adp-openclaw 0.0.47 → 0.0.48
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/package.json +1 -1
- package/src/channel.ts +39 -2
- package/src/monitor.ts +6 -1
- package/src/runtime.ts +12 -0
package/package.json
CHANGED
package/src/channel.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
DEFAULT_ACCOUNT_ID,
|
|
8
8
|
} from "openclaw/plugin-sdk";
|
|
9
9
|
import { adpOpenclawOnboardingAdapter } from "./onboarding.js";
|
|
10
|
+
import { getActiveWebSocket } from "./runtime.js";
|
|
10
11
|
|
|
11
12
|
// Default WebSocket URL for ADP OpenClaw
|
|
12
13
|
const DEFAULT_WS_URL = "wss://wss.lke.cloud.tencent.com/bot/gateway/conn";
|
|
@@ -218,6 +219,42 @@ export const adpOpenclawPlugin: ChannelPlugin<ResolvedAdpOpenclawAccount> = {
|
|
|
218
219
|
});
|
|
219
220
|
},
|
|
220
221
|
},
|
|
221
|
-
//
|
|
222
|
-
|
|
222
|
+
// Outbound message support for the "message" tool
|
|
223
|
+
outbound: {
|
|
224
|
+
send: async ({ text, to, log }) => {
|
|
225
|
+
const ws = getActiveWebSocket();
|
|
226
|
+
if (!ws) {
|
|
227
|
+
log?.error?.("[adp-openclaw] No active WebSocket connection for outbound message");
|
|
228
|
+
return { ok: false, error: "No active WebSocket connection" };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Parse target: expected format is "adp-openclaw:{userId}" or "adp-openclaw:bot"
|
|
232
|
+
// The "to" parameter comes from the message tool with format like "adp-openclaw:user123"
|
|
233
|
+
const targetParts = to.split(":");
|
|
234
|
+
const targetUserId = targetParts.length > 1 ? targetParts.slice(1).join(":") : to;
|
|
235
|
+
|
|
236
|
+
log?.info?.(`[adp-openclaw] Sending outbound message to ${targetUserId}: ${text.slice(0, 50)}...`);
|
|
237
|
+
|
|
238
|
+
try {
|
|
239
|
+
// Generate unique request ID
|
|
240
|
+
const requestId = `outbound-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
241
|
+
|
|
242
|
+
const outMsg = {
|
|
243
|
+
type: "outbound",
|
|
244
|
+
requestId,
|
|
245
|
+
payload: {
|
|
246
|
+
to: targetUserId,
|
|
247
|
+
text: text,
|
|
248
|
+
},
|
|
249
|
+
timestamp: Date.now(),
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
ws.send(JSON.stringify(outMsg));
|
|
253
|
+
return { ok: true };
|
|
254
|
+
} catch (err) {
|
|
255
|
+
log?.error?.(`[adp-openclaw] Failed to send outbound message: ${err}`);
|
|
256
|
+
return { ok: false, error: String(err) };
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
},
|
|
223
260
|
};
|
package/src/monitor.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Supports: API Token auth, conversation tracking for multi-turn dialogues
|
|
3
3
|
|
|
4
4
|
import type { PluginLogger, ClawdbotConfig } from "openclaw/plugin-sdk";
|
|
5
|
-
import { getAdpOpenclawRuntime } from "./runtime.js";
|
|
5
|
+
import { getAdpOpenclawRuntime, setActiveWebSocket } from "./runtime.js";
|
|
6
6
|
import {
|
|
7
7
|
getChatHistory,
|
|
8
8
|
listSessions,
|
|
@@ -176,6 +176,9 @@ async function connectAndHandle(params: ConnectParams): Promise<void> {
|
|
|
176
176
|
|
|
177
177
|
ws.on("open", () => {
|
|
178
178
|
log?.info(`[adp-openclaw] WebSocket connected, authenticating...`);
|
|
179
|
+
|
|
180
|
+
// Save active WebSocket for outbound messaging
|
|
181
|
+
setActiveWebSocket(ws);
|
|
179
182
|
|
|
180
183
|
// Send authentication message with signature (includes timestamp for anti-replay)
|
|
181
184
|
const nonce = generateNonce();
|
|
@@ -691,6 +694,8 @@ async function connectAndHandle(params: ConnectParams): Promise<void> {
|
|
|
691
694
|
ws.on("close", (code, reason) => {
|
|
692
695
|
if (pingInterval) clearInterval(pingInterval);
|
|
693
696
|
abortSignal?.removeEventListener("abort", abortHandler);
|
|
697
|
+
// Clear active WebSocket when connection closes
|
|
698
|
+
setActiveWebSocket(null);
|
|
694
699
|
log?.info(`[adp-openclaw] WebSocket closed: ${code} ${reason.toString()}`);
|
|
695
700
|
resolve();
|
|
696
701
|
});
|
package/src/runtime.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Runtime singleton for adp-openclaw plugin
|
|
2
2
|
import type { PluginRuntime } from "openclaw/plugin-sdk";
|
|
3
|
+
import type { WebSocket } from "ws";
|
|
3
4
|
|
|
4
5
|
let adpOpenclawRuntime: PluginRuntime | null = null;
|
|
5
6
|
|
|
@@ -16,6 +17,17 @@ export type PluginConfig = {
|
|
|
16
17
|
|
|
17
18
|
let pluginConfig: PluginConfig = {};
|
|
18
19
|
|
|
20
|
+
// Active WebSocket connection for outbound messaging
|
|
21
|
+
let activeWebSocket: WebSocket | null = null;
|
|
22
|
+
|
|
23
|
+
export function setActiveWebSocket(ws: WebSocket | null): void {
|
|
24
|
+
activeWebSocket = ws;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function getActiveWebSocket(): WebSocket | null {
|
|
28
|
+
return activeWebSocket;
|
|
29
|
+
}
|
|
30
|
+
|
|
19
31
|
export function setAdpOpenclawRuntime(runtime: PluginRuntime): void {
|
|
20
32
|
adpOpenclawRuntime = runtime;
|
|
21
33
|
}
|