Skip to content

Commit

Permalink
fix(telegram): inconsistent media group elements order (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
std-microblock authored Apr 20, 2024
1 parent df3ba5a commit 0a1bdc6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions adapters/telegram/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0a1bdc6

Please sign in to comment.