If you're a recurser, ping me on Zulip for any questions.
If you're a vertical flat plate, ping me on Slack for any questions.
The Daily Leetcode Bot can post questions from leetcode.com to Zulip or Slack every day.
It is primarily intended to be used for the Recurse Center but it can be easily configured to post with any frequency to any Zulip realm or Slack workspace.
To run this bot you must have Node.js v24.0.0 or higher installed.
The bot can be configured by using the following environment variables:
-
Zulip
ZULIP_USERNAME- the e-mail address of your Zulip botZULIP_API_KEY- the API_KEY of your Zulip botZULIP_REALM- your Zulip Realm or the https address of your Zulip instance
You can also place a zuliprc at the root of this repo.
-
Slack
DLB_SLACK_WEBHOOK- the webhook URL for an incoming webhook
-
Bot
- Clone this repo
- Install dependencies
npm install
- Run the bot
npm start
This repository is organized into the following structure:
The main entry point and orchestration logic. Handles:
- Cron job scheduling
- Fetching LeetCode daily problems (with fallback to alfa-leetcode-api)
- Selecting random Grind75 problems
- Fetching Advent of Code problems (during December)
- Coordinating message posting
- Graceful shutdown handling
Zulip client initialization and configuration management. Validates and parses environment variables for Zulip setup.
Message posting logic for both Zulip and Slack. Formats messages with LeetCode, Grind75, and Advent of Code problems.
Utility functions including:
fetchWithRetry()- HTTP requests with exponential backoff retry logicrandom()- Random number generation helper
GraphQL queries for the LeetCode API.
Unfortunately the LeetCode API is not documented but useful information about it can be found here, here, and by searching the intertubez.
TypeScript type definitions for:
- LeetCode API responses (
leetcode.ts) - Grind75 problem data structure (
grind75.ts) - Message data structure (
message.ts) - Zulip-js module declarations (
zulip-js.d.ts)
A JSON dataset containing the problems found here which were compiled by the talented @yangshun.
Please read our Code of Conduct
Please create an issue if you want to submit a PR and link it to your PR with one of these keywords.
Feel free to create issues for any bugs or feature requests. If submitting a bug, please include as many details as possible. Including, but not limited to, reproduction steps, logs, and screenshots that show the problem.
Future improvements and enhancements:
- Structured Logging: Replace
console.log/error/warnwith a structured logging for better log parsing and production observability - Permanent Logs: Log to a file so we can debug if the server crashes
- Health Check Endpoint: Add a simple HTTP server with a health check endpoint for monitoring and alerting
- Error Handling Consistency: Standardize error handling patterns across the codebase for consistent error visibility
- Message Posting Retry Logic: Add retry logic with exponential backoff for message posting failures to prevent silent message loss
- Response Validation: Add runtime validation for API responses (e.g., using Zod) to handle unexpected API response structures gracefully
- Test Suite: Add unit and integration tests for critical paths (fetchWithRetry, message formatting, etc.)
- Rate Limiting: Add rate limiting considerations or documentation for API usage to prevent hitting API rate limits
- Type Safety Improvements: Add runtime type validation for type assertions (e.g., difficulty levels) to catch unexpected API values early
