Job Scheduler
Schedule one-time or recurring tasks natively.
Built-in Scheduling
WAKit includes a robust JobSchedulerPlugin so you don't need to pull in external dependencies like node-cron or agenda just to send a daily message.
The scheduler handles executing functions at specific times and can be integrated deeply with your bot's logic.
Usage
import { WAKitClient } from '@atharvh01/wakit';
import { JobSchedulerPlugin } from '@atharvh01/wakit/plugins';
const client = new WAKitClient({ sessionName: 'scheduled-bot' });
const scheduler = new JobSchedulerPlugin();
client.plugins.install(scheduler);
await client.initialize();
// Send a good morning message every day at 8:00 AM
scheduler.scheduleCron('0 8 * * *', async () => {
await client.sendMessage('1234567890@s.whatsapp.net', {
text: 'Good morning! Here is your daily update.'
});
});
// Send a reminder in exactly 1 hour
scheduler.scheduleTimeout(3600000, async () => {
await client.sendMessage('1234567890@s.whatsapp.net', {
text: 'This is your 1-hour reminder!'
});
});
[!TIP] The WAKit team is working on offline persistence for the scheduler, so scheduled jobs will survive server reboots in an upcoming release!