@eclaw/openclaw-channel 1.0.8 → 1.0.9
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/config.js +1 -0
- package/dist/gateway.d.ts +1 -1
- package/dist/gateway.js +35 -18
- package/dist/onboarding.js +6 -0
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
package/dist/config.js
CHANGED
package/dist/gateway.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Gateway lifecycle: start an E-Claw account.
|
|
3
3
|
*
|
|
4
|
-
* 1.
|
|
4
|
+
* 1. Resolve credentials from ctx.account or disk
|
|
5
5
|
* 2. Start a local HTTP server to receive webhook callbacks
|
|
6
6
|
* 3. Register callback URL with E-Claw backend
|
|
7
7
|
* 4. Auto-bind entity if not already bound
|
package/dist/gateway.js
CHANGED
|
@@ -7,21 +7,39 @@ import { resolveAccount } from './config.js';
|
|
|
7
7
|
import { EClawClient } from './client.js';
|
|
8
8
|
import { setClient } from './outbound.js';
|
|
9
9
|
import { createWebhookHandler } from './webhook-handler.js';
|
|
10
|
-
/**
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Resolve account from ctx.
|
|
12
|
+
*
|
|
13
|
+
* OpenClaw may pass a pre-resolved account object in ctx.account,
|
|
14
|
+
* or an empty config. Fall back to reading openclaw.json from disk.
|
|
15
|
+
*/
|
|
16
|
+
function resolveAccountFromCtx(ctx) {
|
|
17
|
+
// Preferred: OpenClaw passes the resolved account in ctx.account
|
|
18
|
+
if (ctx.account?.apiKey) {
|
|
19
|
+
return {
|
|
20
|
+
enabled: ctx.account.enabled ?? true,
|
|
21
|
+
apiKey: ctx.account.apiKey,
|
|
22
|
+
apiSecret: ctx.account.apiSecret,
|
|
23
|
+
apiBase: (ctx.account.apiBase ?? 'https://eclawbot.com').replace(/\/$/, ''),
|
|
24
|
+
entityId: ctx.account.entityId ?? 0,
|
|
25
|
+
botName: ctx.account.botName,
|
|
26
|
+
webhookUrl: ctx.account.webhookUrl,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
// Fallback: read config from disk (OpenClaw passes empty config object)
|
|
12
30
|
const configPath = process.env.OPENCLAW_CONFIG_PATH
|
|
13
31
|
|| join(homedir(), '.openclaw', 'openclaw.json');
|
|
32
|
+
let fullConfig = {};
|
|
14
33
|
try {
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
return {};
|
|
34
|
+
fullConfig = JSON.parse(readFileSync(configPath, 'utf8'));
|
|
19
35
|
}
|
|
36
|
+
catch { /* ignore */ }
|
|
37
|
+
return resolveAccount(fullConfig, ctx.accountId ?? ctx.account?.accountId);
|
|
20
38
|
}
|
|
21
39
|
/**
|
|
22
40
|
* Gateway lifecycle: start an E-Claw account.
|
|
23
41
|
*
|
|
24
|
-
* 1.
|
|
42
|
+
* 1. Resolve credentials from ctx.account or disk
|
|
25
43
|
* 2. Start a local HTTP server to receive webhook callbacks
|
|
26
44
|
* 3. Register callback URL with E-Claw backend
|
|
27
45
|
* 4. Auto-bind entity if not already bound
|
|
@@ -29,10 +47,8 @@ function readFullConfig() {
|
|
|
29
47
|
*/
|
|
30
48
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
49
|
export async function startAccount(ctx) {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
const fullConfig = readFullConfig();
|
|
35
|
-
const account = resolveAccount(fullConfig, accountId);
|
|
50
|
+
const accountId = ctx.accountId ?? ctx.account?.accountId ?? 'default';
|
|
51
|
+
const account = resolveAccountFromCtx(ctx);
|
|
36
52
|
if (!account.enabled || !account.apiKey) {
|
|
37
53
|
console.log(`[E-Claw] Account ${accountId} disabled or missing credentials, skipping`);
|
|
38
54
|
return;
|
|
@@ -42,12 +58,15 @@ export async function startAccount(ctx) {
|
|
|
42
58
|
setClient(accountId, client);
|
|
43
59
|
// Generate per-session callback token
|
|
44
60
|
const callbackToken = randomBytes(32).toString('hex');
|
|
45
|
-
//
|
|
61
|
+
// Webhook URL: account config > env var > warn
|
|
46
62
|
const webhookPort = parseInt(process.env.ECLAW_WEBHOOK_PORT || '0') || 0;
|
|
47
|
-
const publicUrl =
|
|
63
|
+
const publicUrl = account.webhookUrl?.replace(/\/$/, '')
|
|
64
|
+
|| process.env.ECLAW_WEBHOOK_URL?.replace(/\/$/, '');
|
|
48
65
|
if (!publicUrl) {
|
|
49
|
-
console.warn('[E-Claw]
|
|
50
|
-
'
|
|
66
|
+
console.warn('[E-Claw] Webhook URL not configured. ' +
|
|
67
|
+
'Run "openclaw configure" and enter your OpenClaw public URL, ' +
|
|
68
|
+
'or set ECLAW_WEBHOOK_URL env var. ' +
|
|
69
|
+
'Example: https://your-openclaw-domain.com');
|
|
51
70
|
}
|
|
52
71
|
// Create webhook handler
|
|
53
72
|
const handler = createWebhookHandler(callbackToken, accountId);
|
|
@@ -96,11 +115,9 @@ export async function startAccount(ctx) {
|
|
|
96
115
|
}
|
|
97
116
|
else {
|
|
98
117
|
console.log(`[E-Claw] Entity ${account.entityId} already bound`);
|
|
99
|
-
// For already-bound entities, we need to get the botSecret
|
|
100
|
-
// The bind endpoint returns existing credentials for channel-bound entities
|
|
101
118
|
const bindData = await client.bindEntity(account.entityId, account.botName);
|
|
102
119
|
console.log(`[E-Claw] Retrieved credentials for entity ${account.entityId}`);
|
|
103
|
-
void bindData;
|
|
120
|
+
void bindData;
|
|
104
121
|
}
|
|
105
122
|
console.log(`[E-Claw] Account ${accountId} ready!`);
|
|
106
123
|
}
|
package/dist/onboarding.js
CHANGED
|
@@ -47,6 +47,11 @@ export const eclawOnboardingAdapter = {
|
|
|
47
47
|
placeholder: 'My Bot',
|
|
48
48
|
initialValue: resolved.botName ?? '',
|
|
49
49
|
});
|
|
50
|
+
const webhookUrl = await prompter.text({
|
|
51
|
+
message: 'Webhook URL (your OpenClaw public URL, e.g. https://openclaw.example.com)',
|
|
52
|
+
placeholder: 'https://your-openclaw-domain.com',
|
|
53
|
+
initialValue: resolved.webhookUrl ?? '',
|
|
54
|
+
});
|
|
50
55
|
const nextCfg = {
|
|
51
56
|
...cfg,
|
|
52
57
|
channels: {
|
|
@@ -60,6 +65,7 @@ export const eclawOnboardingAdapter = {
|
|
|
60
65
|
apiBase: resolved.apiBase || 'https://eclawbot.com',
|
|
61
66
|
entityId: Number(entityIdStr),
|
|
62
67
|
botName: String(botName).trim() || undefined,
|
|
68
|
+
webhookUrl: String(webhookUrl).trim() || undefined,
|
|
63
69
|
enabled: true,
|
|
64
70
|
},
|
|
65
71
|
},
|
package/dist/types.d.ts
CHANGED