feat(payload): remove redundant replaceStatus and add buttons for editing

This commit is contained in:
USO Status 2026-01-26 22:28:47 +01:00
parent 6aec985b1b
commit 89c74e636b
2 changed files with 16 additions and 8 deletions

View File

@ -57,4 +57,6 @@ export type ReplyPayload = {
isStatusMessage?: boolean;
isError?: boolean;
editMessageId?: string;
/** Inline keyboard buttons (reply markup). */
buttons?: Array<Array<{ text: string; callback_data: string }>>;
};

View File

@ -7,7 +7,7 @@ import {
} from "../format.js";
import { chunkMarkdownTextWithMode, type ChunkMode } from "../../auto-reply/chunk.js";
import { splitTelegramCaption } from "../caption.js";
import { recordSentMessage } from "../sent-message-cache.js";
import { getLastSentMessage, recordSentMessage } from "../sent-message-cache.js";
import type { ReplyPayload } from "../../auto-reply/types.js";
import type { ReplyToMode } from "../../config/config.js";
import type { MarkdownTableMode } from "../../config/types.base.js";
@ -83,20 +83,26 @@ export async function deliverReplies(params: {
? [reply.mediaUrl]
: [];
if (mediaList.length === 0) {
let sentMessageId: string | undefined;
const explicitEditId = reply.editMessageId;
// Check if the previous message was a status message.
// If so, we should edit it instead of sending a new message.
const lastSent = getLastSentMessage(chatId);
const shouldEditLast =
lastSent?.isStatus && lastSent.messageId && Date.now() - lastSent.timestamp < 120000; // 2 min threshold
let sentMessageId: string | undefined;
if (shouldEditLast && reply.text) {
const editId = String(lastSent!.messageId);
if (explicitEditId && reply.text) {
// Explicit edit requested by StatusUpdateController/agent-runner
try {
await editMessageTelegram(chatId, explicitEditId, reply.text, {
await editMessageTelegram(chatId, editId, reply.text, {
token: params.token,
accountId: params.accountId,
api: bot.api,
});
sentMessageId = explicitEditId;
sentMessageId = editId;
} catch (err) {
logVerbose(`Telegram explicit edit failed, falling back to new message: ${String(err)}`);
logVerbose(`Telegram edit failed, falling back to new message: ${String(err)}`);
// Fall through to send new message
}
}