I am making a Telegram bot with Telegraf framework in JavaScript with nodeJS. I want to send a message to the user every Monday morning at 9.00 AM. How can I make this time based trigger in telegraf js?
Question posted in Telegram API
A comprehensive official documentation can be found here.
A comprehensive official documentation can be found here.
2
Answers
Telegraf doesn’t provide you with such abilities out-of-the-box since it’s a bot framework with the goal of abstracting API calls. You should instead schedule the task with task scheduling libraries (like node-cron).
An example with node-cron
If you want to learn a bit more about it, please refer this tutorial
If you don’t want to use any other libraries, try using
Date
object.And use
if
to checkDate.now()
:For sending message weekly (below code is just an example, you can also use hour and minute to specify time):
You can refer to this link for more details on
Date
.