Event Recorder
Time-travel debugging and analytics for your WhatsApp bot.
Why Event Recording?
When building bots, debugging complex multi-step interactions can be a nightmare. WAKit's EventRecorderPlugin solves this by seamlessly intercepting and saving all normalized events into memory or a database.
This allows you to:
- Replay past events to reproduce bugs locally.
- Build analytics dashboards for bot usage.
- Export interaction logs for compliance or auditing.
Setup
import { WAKitClient } from '@atharvh01/wakit';
import { EventRecorderPlugin } from '@atharvh01/wakit/plugins';
const client = new WAKitClient({ sessionName: 'recorder-bot' });
const recorder = new EventRecorderPlugin({ maxEvents: 1000 });
client.plugins.install(recorder);
await client.initialize();
Time-Travel Replay
Once the recorder has captured events, you can "replay" them against your bot's logic. This is incredibly useful for testing.
// Replay all events that happened in the last 10 minutes
recorder.replayEvents({
startTime: Date.now() - (10 * 60 * 1000),
endTime: Date.now()
});
// The WAKitClient will rapidly re-emit the 'message' events
// as if they were just received from the network!
[!WARNING] Use
replayEvents()with caution in production. Replaying a command that sends an automated reply will cause your bot to actually send that reply again! It is best used in staging environments or with dummy logic.