E
E
Evgeny Koryakin2020-04-17 09:40:36
In contact with
Evgeny Koryakin, 2020-04-17 09:40:36

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

Hello.
The bot is written using https://github.com/node-vk-bot-api/node-vk-bot-api .
I already figured out how to make the basic functionality.
But how do you send emails?
You need to send every 22 hours.
So, according to the algorithm "every Friday at 18:00 Moscow time".

How can this be done in node?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Ageychenko, 2020-04-17
@zettend

Here is an implementation example

const ONE_MIN = 60 * 1000;
const ONE_HOURS = 60 * 60 * 1000;

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

setInterval(() => {
  // Каждую пятницу в 18  часов
  let currentDate = new Date();
  if (currentDate.getDay() == 5 && currentDate.getHours == 18 && !isSentFridayMessage) {
    // do something 
    isSentFridayMessage = true;
  } else {
    isSentFridayMessage = false
  }

  // Каждые 22 часа
  if (startEvery22HoursTimer < new Date(Date.now() - 22 * ONE_HOURS)) {
    startEvery22HoursTimer = new Date();
    // do something
  }

}, ONE_MIN)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question