@aka_openclaw_plugin/mychat 0.1.15 → 0.1.17
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/api.js +1 -1
- package/{channel-CxT4NkH-.js → channel-BQOyywVd.js} +22 -18
- package/channel-plugin-api.js +1 -1
- package/package.json +1 -1
- package/setup-entry.js +1 -1
package/api.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as tryGetMychatRuntime, i as setMychatRuntime, n as init_runtime, t as getMychatRuntime } from "./runtime-PfFuZ2Rm.js";
|
|
2
|
-
import { t as mychatPlugin } from "./channel-
|
|
2
|
+
import { t as mychatPlugin } from "./channel-BQOyywVd.js";
|
|
3
3
|
//#region api.ts
|
|
4
4
|
init_runtime();
|
|
5
5
|
//#endregion
|
|
@@ -166,6 +166,9 @@ function createMychatHttpClient(params) {
|
|
|
166
166
|
const qs = searchParams.toString();
|
|
167
167
|
return (await request("GET", `/api/bot/messages${qs ? `?${qs}` : ""}`))?.messages ?? [];
|
|
168
168
|
},
|
|
169
|
+
async listConversations() {
|
|
170
|
+
return (await request("GET", "/api/bot/conversations"))?.conversations?.map((c) => c.id) ?? [];
|
|
171
|
+
},
|
|
169
172
|
async addReaction(messageId, body) {
|
|
170
173
|
return request("POST", `/api/bot/messages/${messageId}/reactions`, body);
|
|
171
174
|
},
|
|
@@ -208,9 +211,6 @@ function createMychatHttpClient(params) {
|
|
|
208
211
|
return null;
|
|
209
212
|
}
|
|
210
213
|
},
|
|
211
|
-
async reportStatus(status) {
|
|
212
|
-
return await request("POST", "/api/bot/status", { status }) !== null;
|
|
213
|
-
},
|
|
214
214
|
async healthCheck() {
|
|
215
215
|
const url = `${base}/health`;
|
|
216
216
|
const start = Date.now();
|
|
@@ -3813,14 +3813,6 @@ function createMychatWsClient(params) {
|
|
|
3813
3813
|
connected = true;
|
|
3814
3814
|
currentDelay = initialDelay;
|
|
3815
3815
|
logger?.info(`${prefix} connected botSelfId=${botSelfId ?? "none"}`);
|
|
3816
|
-
if (botSelfId) {
|
|
3817
|
-
const subMsg = JSON.stringify({
|
|
3818
|
-
type: "subscribe",
|
|
3819
|
-
body: { subscribe: { conversationId: botSelfId } }
|
|
3820
|
-
});
|
|
3821
|
-
logger?.info(`${prefix} subscribing to conversationId=${botSelfId}`);
|
|
3822
|
-
ws?.send(subMsg);
|
|
3823
|
-
}
|
|
3824
3816
|
});
|
|
3825
3817
|
ws.on("message", (data) => {
|
|
3826
3818
|
try {
|
|
@@ -3853,9 +3845,22 @@ function createMychatWsClient(params) {
|
|
|
3853
3845
|
ws?.close();
|
|
3854
3846
|
ws = null;
|
|
3855
3847
|
}
|
|
3848
|
+
function subscribe(conversationId) {
|
|
3849
|
+
if (!ws || !connected) {
|
|
3850
|
+
logger?.warn(`${prefix} cannot subscribe, not connected`);
|
|
3851
|
+
return;
|
|
3852
|
+
}
|
|
3853
|
+
const subMsg = JSON.stringify({
|
|
3854
|
+
type: "subscribe",
|
|
3855
|
+
body: { subscribe: { conversationId } }
|
|
3856
|
+
});
|
|
3857
|
+
logger?.info(`${prefix} subscribing to conversationId=${conversationId}`);
|
|
3858
|
+
ws.send(subMsg);
|
|
3859
|
+
}
|
|
3856
3860
|
return {
|
|
3857
3861
|
connect,
|
|
3858
3862
|
disconnect,
|
|
3863
|
+
subscribe,
|
|
3859
3864
|
onMessage(handler) {
|
|
3860
3865
|
handlers.add(handler);
|
|
3861
3866
|
return () => {
|
|
@@ -4195,20 +4200,19 @@ async function monitorMychatProvider(ctx) {
|
|
|
4195
4200
|
});
|
|
4196
4201
|
logger?.info(`${prefix} bot connected botId=${readyBotSelf.botId}`);
|
|
4197
4202
|
try {
|
|
4198
|
-
await httpClient.
|
|
4199
|
-
logger?.info(`${prefix}
|
|
4203
|
+
const conversations = await httpClient.listConversations();
|
|
4204
|
+
logger?.info(`${prefix} found ${conversations.length} conversations to subscribe`);
|
|
4205
|
+
for (const convId of conversations) wsClient.subscribe(convId);
|
|
4200
4206
|
} catch (err) {
|
|
4201
|
-
logger?.warn(`${prefix} failed to
|
|
4207
|
+
logger?.warn(`${prefix} failed to list conversations: ${err}`);
|
|
4202
4208
|
}
|
|
4203
|
-
ctx.abortSignal?.addEventListener("abort",
|
|
4209
|
+
ctx.abortSignal?.addEventListener("abort", () => {
|
|
4204
4210
|
logger?.info(`${prefix} abort signal received, shutting down`);
|
|
4205
|
-
await httpClient.reportStatus("offline").catch(() => {});
|
|
4206
4211
|
lifecycle.shutdown();
|
|
4207
4212
|
setStatus({ connected: false });
|
|
4208
4213
|
});
|
|
4209
|
-
return { unsubscribe
|
|
4214
|
+
return { unsubscribe() {
|
|
4210
4215
|
logger?.info(`${prefix} unsubscribe called, shutting down`);
|
|
4211
|
-
await httpClient.reportStatus("offline").catch(() => {});
|
|
4212
4216
|
lifecycle.shutdown();
|
|
4213
4217
|
setStatus({ connected: false });
|
|
4214
4218
|
} };
|
package/channel-plugin-api.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as mychatPlugin } from "./channel-
|
|
1
|
+
import { t as mychatPlugin } from "./channel-BQOyywVd.js";
|
|
2
2
|
export { mychatPlugin };
|
package/package.json
CHANGED
package/setup-entry.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as mychatPlugin } from "./channel-
|
|
1
|
+
import { t as mychatPlugin } from "./channel-BQOyywVd.js";
|
|
2
2
|
export { mychatPlugin };
|