fix: delete /personality message after sending to reduce chat clutter
This commit is contained in:
parent
27f9849507
commit
8f4b1126da
@ -189,9 +189,17 @@ async function switchTelegram(name: string) {
|
|||||||
body: JSON.stringify({ chat_id: chatId, text: `/personality ${displayName}` }),
|
body: JSON.stringify({ chat_id: chatId, text: `/personality ${displayName}` }),
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await resp.json() as { ok: boolean; description?: string };
|
const result = await resp.json() as { ok: boolean; description?: string; result?: { message_id: number } };
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
console.log(`Sent /personality ${displayName} to chat ${chatId}`);
|
console.log(`Sent /personality ${displayName} to chat ${chatId}`);
|
||||||
|
// Delete the message so it doesn't clutter the chat
|
||||||
|
if (result.result?.message_id) {
|
||||||
|
await fetch(`https://api.telegram.org/bot${token}/deleteMessage`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ chat_id: chatId, message_id: result.result.message_id }),
|
||||||
|
}).catch(() => {});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error(`Telegram API error: ${result.description}`);
|
console.error(`Telegram API error: ${result.description}`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user