mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-12 20:23:21 +08:00
feat: add stable proactive delivery
This commit is contained in:
parent
410cb822d7
commit
31792d7bc8
88 changed files with 6427 additions and 488 deletions
|
|
@ -719,6 +719,30 @@ export class TelegramRuntime {
|
|||
return this.#bridge.sendConnectionTest(text);
|
||||
}
|
||||
|
||||
async sendProactiveText(target, text, options = {}) {
|
||||
if (!this.#status.ready || !this.#bridge) {
|
||||
const error = new Error('Telegram bot is not connected');
|
||||
error.code = 'bot-not-connected';
|
||||
throw error;
|
||||
}
|
||||
const chatIdText = typeof target?.route?.chatId === 'string'
|
||||
? target.route.chatId.trim() : '';
|
||||
const chatId = Number(chatIdText);
|
||||
const messageThreadId = target?.route?.messageThreadId;
|
||||
if (!/^-?\d+$/.test(chatIdText) || !Number.isSafeInteger(chatId)
|
||||
|| (target?.kind !== 'chat' && target?.kind !== 'topic')
|
||||
|| (target.kind === 'topic' && (!Number.isSafeInteger(messageThreadId) || messageThreadId <= 0))
|
||||
|| (target.kind === 'chat' && messageThreadId !== undefined)) {
|
||||
const error = new TypeError('Invalid Telegram proactive delivery target');
|
||||
error.code = 'invalid-target';
|
||||
throw error;
|
||||
}
|
||||
return this.#bridge.sendProactiveText({
|
||||
chatId,
|
||||
...(target.kind === 'topic' ? { messageThreadId } : {}),
|
||||
}, text, options);
|
||||
}
|
||||
|
||||
async start() {
|
||||
if (this.#status.ready && this.#pollTask) return this.status;
|
||||
if (this.#starting) return this.#starting;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue