@aka_openclaw_plugin/mychat 0.1.16 → 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-Cjn7oWbb.js → channel-BQOyywVd.js} +23 -8
- 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
|
},
|
|
@@ -3810,14 +3813,6 @@ function createMychatWsClient(params) {
|
|
|
3810
3813
|
connected = true;
|
|
3811
3814
|
currentDelay = initialDelay;
|
|
3812
3815
|
logger?.info(`${prefix} connected botSelfId=${botSelfId ?? "none"}`);
|
|
3813
|
-
if (botSelfId) {
|
|
3814
|
-
const subMsg = JSON.stringify({
|
|
3815
|
-
type: "subscribe",
|
|
3816
|
-
body: { subscribe: { conversationId: botSelfId } }
|
|
3817
|
-
});
|
|
3818
|
-
logger?.info(`${prefix} subscribing to conversationId=${botSelfId}`);
|
|
3819
|
-
ws?.send(subMsg);
|
|
3820
|
-
}
|
|
3821
3816
|
});
|
|
3822
3817
|
ws.on("message", (data) => {
|
|
3823
3818
|
try {
|
|
@@ -3850,9 +3845,22 @@ function createMychatWsClient(params) {
|
|
|
3850
3845
|
ws?.close();
|
|
3851
3846
|
ws = null;
|
|
3852
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
|
+
}
|
|
3853
3860
|
return {
|
|
3854
3861
|
connect,
|
|
3855
3862
|
disconnect,
|
|
3863
|
+
subscribe,
|
|
3856
3864
|
onMessage(handler) {
|
|
3857
3865
|
handlers.add(handler);
|
|
3858
3866
|
return () => {
|
|
@@ -4191,6 +4199,13 @@ async function monitorMychatProvider(ctx) {
|
|
|
4191
4199
|
lastError: null
|
|
4192
4200
|
});
|
|
4193
4201
|
logger?.info(`${prefix} bot connected botId=${readyBotSelf.botId}`);
|
|
4202
|
+
try {
|
|
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);
|
|
4206
|
+
} catch (err) {
|
|
4207
|
+
logger?.warn(`${prefix} failed to list conversations: ${err}`);
|
|
4208
|
+
}
|
|
4194
4209
|
ctx.abortSignal?.addEventListener("abort", () => {
|
|
4195
4210
|
logger?.info(`${prefix} abort signal received, shutting down`);
|
|
4196
4211
|
lifecycle.shutdown();
|
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 };
|