How to set the interval of sending messages from the bot?

Hello.
The bot is written using https://github.com/node-vk-bot-api/node-vk-bot-api.
How to make the basic functionality I already have.
But how to send the newsletter?
You need to do the sending times in 22 hours.
So the same algorithm "every Friday at 18:00 GMT".

How this can be implemented on node?
April 19th 20 at 12:28
1 answer
April 19th 20 at 12:30
Here is an example implementation
const ONE_MIN = 60 * 1000;
const ONE_HOURS = 60 * 60 * 1000;

let isSentFridayMessage = false;
let startEvery22HoursTimer = new Date();

setInterval(() => {
 // Every Friday at 18 o'clock
 let currentDate = new Date();
 if (currentDate.getDay() == 5 && currentDate.getHours == 18 && !isSentFridayMessage) {
 // do something 
 isSentFridayMessage = true;
 } else {
 isSentFridayMessage = false
}

 // Every 22 hours
 if (startEvery22HoursTimer < new Date(Date.now() - 22 * ONE_HOURS)) {
 startEvery22HoursTimer = new Date();
 // do something
}

}, ONE_MIN)
Why not cron? Why keep running the process if most of the time it is not used? - Wilhelm_OConne commented on April 19th 20 at 12:33
How to specify relative what time will start the countdown 22 hours? - marquis_Effertz commented on April 19th 20 at 12:36

Find more questions by tags Node.jsVKontakte