Here is my piece of code:
let interval = chatType === 'private' ? 1000 : 5000;
let it = 0;
dl.imgs.forEach(function (el, index) {
it += interval * index;
if (index===2) it += 60000;
setTimeout(function () {
console.log(`part #${index+1}; size=${el.length}; timeout=${it}`)
bot.sendMediaGroup(chatId, el, { reply_to_message_id: userMsgId, disable_notification: true, allow_sending_without_reply: true }).catch((err) => {
console.log(err.code);
console.log(err.response.body);
});
}, it);
});
As far as I know, the limits is 20 messages per minute in one group (for private chats limits are different, so I hadle it firstly). And for sendMediaGroup each item counts as a separate message. So I have in total a maximum of 4 chunks of images by 9 items each in variable dl.imgs (It may be only 1 chunk with only 1 image).
What I need is to send first two chunks (18 images) with 5 sec delay, then third after 60 sec delay and last one with 5 sec delay. So I can avoid hitting that error. I wrote a code above, which should do that, but I think I wrongly understood how setTimeout works in this scope.