antenna-openclaw-plugin 1.2.21 → 1.2.22

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.
Files changed (2) hide show
  1. package/index.ts +28 -5
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -124,24 +124,35 @@ function cronJobId(deviceA: string, deviceB: string): string {
124
124
  }
125
125
 
126
126
  /** Send a real-time notification to a user via openclaw message send */
127
- function notifyUser(
127
+ async function notifyUser(
128
128
  channel: string,
129
129
  userId: string,
130
130
  message: string,
131
131
  logger: any,
132
- ): void {
132
+ ): Promise<void> {
133
133
  const deviceId = `${channel}:${userId}`;
134
- const chatId = _channelContext.get(deviceId);
134
+ let chatId = _channelContext.get(deviceId);
135
+
136
+ // Fallback: read from DB if not in memory
137
+ if (!chatId) {
138
+ try {
139
+ const cfg = getConfig(api);
140
+ const sb = getSupabase(cfg);
141
+ const { data } = await sb.rpc("get_profile", { p_device_id: deviceId });
142
+ if (data?.last_chat_id) {
143
+ chatId = data.last_chat_id;
144
+ _channelContext.set(deviceId, chatId);
145
+ }
146
+ } catch {}
147
+ }
135
148
 
136
149
  try {
137
150
  if (chatId) {
138
- // Use message send with known chat context
139
151
  execSync(
140
152
  `openclaw message send --channel ${channel} --target ${chatId} -m ${JSON.stringify(message)}`,
141
153
  { timeout: 30_000, encoding: "utf-8" },
142
154
  );
143
155
  } else {
144
- // Fallback: try deliver
145
156
  execSync(
146
157
  `openclaw agent` +
147
158
  ` --message ${JSON.stringify(message)}` +
@@ -156,6 +167,12 @@ function notifyUser(
156
167
  logger.warn(`Antenna: notify failed for ${channel}:${userId}: ${err.message}`);
157
168
  }
158
169
  }
170
+ }
171
+ logger.info(`Antenna: notified ${channel}:${userId} (chat=${chatId || 'deliver'})`);
172
+ } catch (err: any) {
173
+ logger.warn(`Antenna: notify failed for ${channel}:${userId}: ${err.message}`);
174
+ }
175
+ }
159
176
 
160
177
  function startFollowUpCron(
161
178
  deviceId: string,
@@ -1412,6 +1429,12 @@ export default function register(api: any) {
1412
1429
  const deviceId = `${ch}:${senderId}`;
1413
1430
  _channelContext.set(deviceId, chatId);
1414
1431
  _knownDeviceIds.add(deviceId);
1432
+ // Persist to DB
1433
+ try {
1434
+ const cfg = getConfig(api);
1435
+ const sb = getSupabase(cfg);
1436
+ sb.rpc("upsert_profile", { p_device_id: deviceId, p_last_chat_id: chatId }).then(() => {}).catch(() => {});
1437
+ } catch {}
1415
1438
  }
1416
1439
 
1417
1440
  // --- Auto-scan on location ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "antenna-openclaw-plugin",
3
- "version": "1.2.21",
3
+ "version": "1.2.22",
4
4
  "description": "Antenna — agent-mediated nearby people discovery for OpenClaw",
5
5
  "openclaw": {
6
6
  "extensions": ["./index.ts"]