From 0a1bdc69febd3edd6a5de6aa7e4f26b4f1d30e2f Mon Sep 17 00:00:00 2001 From: MicroBlock <66859419+MicroCBer@users.noreply.github.com> Date: Sat, 20 Apr 2024 23:03:18 +0800 Subject: [PATCH] fix(telegram): inconsistent media group elements order (#266) --- adapters/telegram/src/utils.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/adapters/telegram/src/utils.ts b/adapters/telegram/src/utils.ts index 9bca6d76..508567ae 100644 --- a/adapters/telegram/src/utils.ts +++ b/adapters/telegram/src/utils.ts @@ -68,11 +68,13 @@ export async function handleUpdate(update: Telegram.Update, bot: TelegramBot) { let thisUpdateTime = new Date() mediaGroupMap.set(update.message.media_group_id, [thisUpdateTime, updates]) - await new Promise(r => setTimeout(r, 800)) + await new Promise(r => setTimeout(r, 1200)) if (mediaGroupMap.get(update.message.media_group_id)[0] === thisUpdateTime) { mediaGroupMap.delete(update.message.media_group_id) // merge all messages - session.event.message.elements = updates.reduce((acc, cur) => acc.concat(cur.elements), []) + session.event.message.elements = updates + .sort((a, b) => a.id - b.id) + .reduce((acc, cur) => acc.concat(cur.elements), []) session.event.message.content = session.event.message.elements.join('') session.event.message.id = Math.min(...updates.map(e => e.id)).toString() session.event._data.mediaGroup = updates.map(e => e.id)