twindex-openclaw-plugin 0.6.0 → 0.6.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "twindex-openclaw-plugin",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Music intelligence for AI agents. Tours, merch drops, releases, presales.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -36,6 +36,32 @@ export default function register(api: any) {
36
36
  const pollService = createNotificationService(api);
37
37
  api.registerService?.(pollService);
38
38
 
39
+ // ── Auto-detect chatTarget from Telegram channel config ─────────
40
+ function inferChatTarget(): string | undefined {
41
+ const config = cfg();
42
+ if (config.chatTarget) return config.chatTarget;
43
+
44
+ // Infer from Telegram allowFrom list (first allowed chat ID)
45
+ const telegramAllow = api.config?.channels?.telegram?.allowFrom;
46
+ if (Array.isArray(telegramAllow) && telegramAllow.length > 0) {
47
+ return String(telegramAllow[0]);
48
+ }
49
+
50
+ // Infer from Slack channel config
51
+ const slackChannel = api.config?.channels?.slack?.channel;
52
+ if (slackChannel) return slackChannel;
53
+
54
+ return undefined;
55
+ }
56
+
57
+ function inferChatChannel(): string {
58
+ const config = cfg();
59
+ if (config.chatChannel) return config.chatChannel;
60
+ if (api.config?.channels?.telegram?.allowFrom?.length > 0) return "telegram";
61
+ if (api.config?.channels?.slack?.channel) return "slack";
62
+ return "telegram";
63
+ }
64
+
39
65
  // ── Auto-bootstrap: register + subscribe ────────────────────────
40
66
 
41
67
  (async () => {
@@ -60,7 +86,16 @@ export default function register(api: any) {
60
86
  }
61
87
  }
62
88
 
63
- persistConfig({ apiKey });
89
+ // Auto-detect chatTarget from channel config if not explicitly set
90
+ const updates: Record<string, any> = { apiKey };
91
+ const chatTarget = inferChatTarget();
92
+ if (chatTarget) {
93
+ updates.chatTarget = chatTarget;
94
+ updates.chatChannel = inferChatChannel();
95
+ api.logger?.info?.(`Twindex: auto-detected chatTarget=${chatTarget}`);
96
+ }
97
+
98
+ persistConfig(updates);
64
99
  pollService.start();
65
100
  api.logger?.info?.(
66
101
  "Twindex: auto-bootstrap complete. Delivery via polling.",
@@ -42,10 +42,19 @@ export function createNotificationService(api: any) {
42
42
 
43
43
  function getChatTarget(): string | undefined {
44
44
  const raw = api.config?.plugins?.entries?.twindex?.config?.chatTarget;
45
- if (!raw) return undefined;
46
- // Strip channel prefix if agent included it (e.g. "telegram:123" → "123")
47
- const colonIdx = raw.indexOf(":");
48
- return colonIdx >= 0 ? raw.slice(colonIdx + 1) : raw;
45
+ if (raw) {
46
+ // Strip channel prefix if agent included it (e.g. "telegram:123" → "123")
47
+ const colonIdx = raw.indexOf(":");
48
+ return colonIdx >= 0 ? raw.slice(colonIdx + 1) : raw;
49
+ }
50
+
51
+ // Fallback: infer from Telegram allowFrom
52
+ const telegramAllow = api.config?.channels?.telegram?.allowFrom;
53
+ if (Array.isArray(telegramAllow) && telegramAllow.length > 0) {
54
+ return String(telegramAllow[0]);
55
+ }
56
+
57
+ return undefined;
49
58
  }
50
59
 
51
60
  function getChatChannel(): string {
@@ -53,7 +62,14 @@ export function createNotificationService(api: any) {
53
62
  // Infer channel from prefix if present (e.g. "telegram:123" → "telegram")
54
63
  const colonIdx = raw.indexOf(":");
55
64
  if (colonIdx > 0) return raw.slice(0, colonIdx);
56
- return api.config?.plugins?.entries?.twindex?.config?.chatChannel ?? "telegram";
65
+
66
+ const explicit = api.config?.plugins?.entries?.twindex?.config?.chatChannel;
67
+ if (explicit) return explicit;
68
+
69
+ // Fallback: infer from which channel is configured
70
+ if (api.config?.channels?.telegram?.allowFrom?.length > 0) return "telegram";
71
+ if (api.config?.channels?.slack?.channel) return "slack";
72
+ return "telegram";
57
73
  }
58
74
 
59
75
  const logger = api.logger;