mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-17 03:40:46 +08:00
feat: send test messages during bot connection checks
This commit is contained in:
parent
94da24538f
commit
fb61c4235f
78 changed files with 3460 additions and 210 deletions
|
|
@ -1,5 +1,9 @@
|
|||
import { WeixinApiError } from './weixin-api.mjs';
|
||||
import { createWeixinBridgeStatus, WeixinHarnessBridge } from './weixin-bridge.mjs';
|
||||
import {
|
||||
connectionTestTarget,
|
||||
connectionTestTargetUnavailable,
|
||||
} from '../shared/connection-test.mjs';
|
||||
|
||||
const DEFAULT_START_RETRY_DELAYS_MS = Object.freeze([250, 1_000, 3_000]);
|
||||
|
||||
|
|
@ -250,4 +254,25 @@ export class WeixinRuntime {
|
|||
this.#status.weixinConnectionState = 'idle';
|
||||
return this.status;
|
||||
}
|
||||
|
||||
async sendConnectionTest(text) {
|
||||
const remembered = connectionTestTarget(this.#state);
|
||||
const toUserId = typeof remembered?.toUserId === 'string' && remembered.toUserId.trim()
|
||||
? remembered.toUserId.trim()
|
||||
: typeof this.#config.ownerUserId === 'string' && this.#config.ownerUserId.trim()
|
||||
? this.#config.ownerUserId.trim()
|
||||
: null;
|
||||
if (!toUserId) throw connectionTestTargetUnavailable('微信机器人');
|
||||
if (!this.#status.ready || !this.#abortController) {
|
||||
throw new Error('Weixin runtime is not connected');
|
||||
}
|
||||
await this.#api.sendText({
|
||||
baseUrl: this.#config.baseUrl,
|
||||
token: this.#token,
|
||||
toUserId,
|
||||
text,
|
||||
signal: this.#abortController.signal,
|
||||
});
|
||||
return { sent: true };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue