mirror of
https://github.com/wassname/pi-telegram.git
synced 2026-06-27 16:46:21 +08:00
"message is not modified" fix
This commit is contained in:
@@ -1406,6 +1406,25 @@ export default function (pi: ExtensionAPI) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isTelegramMessageNotModifiedError(error: unknown): boolean {
|
||||||
|
return (
|
||||||
|
error instanceof Error &&
|
||||||
|
error.message.includes("message is not modified")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function editTelegramMessageText(
|
||||||
|
body: Record<string, unknown>,
|
||||||
|
): Promise<"edited" | "unchanged"> {
|
||||||
|
try {
|
||||||
|
await callTelegram("editMessageText", body);
|
||||||
|
return "edited";
|
||||||
|
} catch (error) {
|
||||||
|
if (isTelegramMessageNotModifiedError(error)) return "unchanged";
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function sendRenderedChunks(
|
async function sendRenderedChunks(
|
||||||
chatId: number,
|
chatId: number,
|
||||||
chunks: TelegramRenderedChunk[],
|
chunks: TelegramRenderedChunk[],
|
||||||
@@ -1433,7 +1452,7 @@ export default function (pi: ExtensionAPI) {
|
|||||||
): Promise<number | undefined> {
|
): Promise<number | undefined> {
|
||||||
if (chunks.length === 0) return messageId;
|
if (chunks.length === 0) return messageId;
|
||||||
const [firstChunk, ...remainingChunks] = chunks;
|
const [firstChunk, ...remainingChunks] = chunks;
|
||||||
await callTelegram("editMessageText", {
|
await editTelegramMessageText({
|
||||||
chat_id: chatId,
|
chat_id: chatId,
|
||||||
message_id: messageId,
|
message_id: messageId,
|
||||||
text: firstChunk.text,
|
text: firstChunk.text,
|
||||||
@@ -1508,7 +1527,7 @@ export default function (pi: ExtensionAPI) {
|
|||||||
state.lastSentText = truncated;
|
state.lastSentText = truncated;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await callTelegram("editMessageText", {
|
await editTelegramMessageText({
|
||||||
chat_id: chatId,
|
chat_id: chatId,
|
||||||
message_id: state.messageId,
|
message_id: state.messageId,
|
||||||
text: truncated,
|
text: truncated,
|
||||||
|
|||||||
Reference in New Issue
Block a user