mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-10 22:03:18 +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,3 +1,5 @@
|
|||
import { connectionTestMessage } from './connection-test.mjs';
|
||||
|
||||
function cleanString(value) {
|
||||
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
||||
}
|
||||
|
|
@ -161,6 +163,25 @@ export class TokenBotController {
|
|||
return this.status();
|
||||
}
|
||||
|
||||
async sendConnectionTest(botId) {
|
||||
const config = this.#configStore.get(botId);
|
||||
if (!config) throw new Error(`Unknown ${this.#descriptor.label} bot`);
|
||||
return this.#withBotTransition(botId, async () => {
|
||||
const runtime = this.#runtimes.get(botId);
|
||||
if (!runtime?.status?.ready || typeof runtime.sendConnectionTest !== 'function') {
|
||||
const error = new Error(`${this.#descriptor.label}机器人尚未连接`);
|
||||
error.code = 'test-target-unavailable';
|
||||
throw error;
|
||||
}
|
||||
const cardLabel = `${config.name}(${this.#maskPlatformId(config.platformId)})`;
|
||||
await runtime.sendConnectionTest(connectionTestMessage(
|
||||
cardLabel,
|
||||
`${this.#descriptor.label}机器人`,
|
||||
));
|
||||
return { sent: true };
|
||||
});
|
||||
}
|
||||
|
||||
async deleteBot(botId) {
|
||||
const config = this.#configStore.get(botId);
|
||||
if (!config) throw new Error(`Unknown ${this.#descriptor.label} bot`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue