'Telegram bot with node.js: how can I sequentially handle all received photos?

I'm developing bot with node-telegram-bot-api and sequelize. It must poll users and create a questionnaire with all results. But when I ask users for photos I receive many messages with photos at one time (photos are in the same media group).

  bot.on("photo", async msg => {
    await photoHandler(msg);
  });

Many photoHandlers work in parallel, not sequentially. How can I handle photos one by one and do action after the last message with photo (in the same mediaGroup)?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source