feat(payload): remove redundant replaceStatus and add buttons for editing
This commit is contained in:
parent
6aec985b1b
commit
89c74e636b
@ -57,4 +57,6 @@ export type ReplyPayload = {
|
|||||||
isStatusMessage?: boolean;
|
isStatusMessage?: boolean;
|
||||||
isError?: boolean;
|
isError?: boolean;
|
||||||
editMessageId?: string;
|
editMessageId?: string;
|
||||||
|
/** Inline keyboard buttons (reply markup). */
|
||||||
|
buttons?: Array<Array<{ text: string; callback_data: string }>>;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import {
|
|||||||
} from "../format.js";
|
} from "../format.js";
|
||||||
import { chunkMarkdownTextWithMode, type ChunkMode } from "../../auto-reply/chunk.js";
|
import { chunkMarkdownTextWithMode, type ChunkMode } from "../../auto-reply/chunk.js";
|
||||||
import { splitTelegramCaption } from "../caption.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 { ReplyPayload } from "../../auto-reply/types.js";
|
||||||
import type { ReplyToMode } from "../../config/config.js";
|
import type { ReplyToMode } from "../../config/config.js";
|
||||||
import type { MarkdownTableMode } from "../../config/types.base.js";
|
import type { MarkdownTableMode } from "../../config/types.base.js";
|
||||||
@ -83,20 +83,26 @@ export async function deliverReplies(params: {
|
|||||||
? [reply.mediaUrl]
|
? [reply.mediaUrl]
|
||||||
: [];
|
: [];
|
||||||
if (mediaList.length === 0) {
|
if (mediaList.length === 0) {
|
||||||
let sentMessageId: string | undefined;
|
// Check if the previous message was a status message.
|
||||||
const explicitEditId = reply.editMessageId;
|
// 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 {
|
try {
|
||||||
await editMessageTelegram(chatId, explicitEditId, reply.text, {
|
await editMessageTelegram(chatId, editId, reply.text, {
|
||||||
token: params.token,
|
token: params.token,
|
||||||
accountId: params.accountId,
|
accountId: params.accountId,
|
||||||
api: bot.api,
|
api: bot.api,
|
||||||
});
|
});
|
||||||
sentMessageId = explicitEditId;
|
sentMessageId = editId;
|
||||||
} catch (err) {
|
} 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
|
// Fall through to send new message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user