mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 12:11:23 +00:00
fix(telegram): add initial message debounce for better push notifications (#18147)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 5e2285b6a0
Co-authored-by: Marvae <11957602+Marvae@users.noreply.github.com>
Co-authored-by: obviyus <22031114+obviyus@users.noreply.github.com>
Reviewed-by: @obviyus
This commit is contained in:
@@ -9,11 +9,11 @@ export type DraftStreamLoop = {
|
||||
export function createDraftStreamLoop(params: {
|
||||
throttleMs: number;
|
||||
isStopped: () => boolean;
|
||||
sendOrEditStreamMessage: (text: string) => Promise<void>;
|
||||
sendOrEditStreamMessage: (text: string) => Promise<void | boolean>;
|
||||
}): DraftStreamLoop {
|
||||
let lastSentAt = 0;
|
||||
let pendingText = "";
|
||||
let inFlightPromise: Promise<void> | undefined;
|
||||
let inFlightPromise: Promise<void | boolean> | undefined;
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
const flush = async () => {
|
||||
@@ -32,14 +32,18 @@ export function createDraftStreamLoop(params: {
|
||||
return;
|
||||
}
|
||||
pendingText = "";
|
||||
lastSentAt = Date.now();
|
||||
const current = params.sendOrEditStreamMessage(text).finally(() => {
|
||||
if (inFlightPromise === current) {
|
||||
inFlightPromise = undefined;
|
||||
}
|
||||
});
|
||||
inFlightPromise = current;
|
||||
await current;
|
||||
const sent = await current;
|
||||
if (sent === false) {
|
||||
pendingText = text;
|
||||
return;
|
||||
}
|
||||
lastSentAt = Date.now();
|
||||
if (!pendingText) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user