This is a bot designed for the Khmer Coders community, supporting both Telegram and Discord platforms. Its primary function is to track message counts for members within a group and generate leaderboards.
Before running the bot, ensure you have Node.js and npm installed.
-
Clone the Repository:
git clone https://github.com/KhmerCoders/khmercoders-bot.git cd khmercoders-bot -
Install Dependencies:
npm install
Create .dev.vars:
In the root directory, create a file named .dev.vars with the following structure:
TELEGRAM_BOT_TOKEN="YOUR_TELEGRAM_BOT_TOKEN_HERE"
DEV_MODE=1
Important
Replace YOUR_TELEGRAM_BOT_TOKEN_HERE with the actual token you receive from BotFather (see "Telegram Bot Setup" below). This file is ignored by Git, so your token will not be committed to the repository.
DEV_MODE only needed for development.
To start the bot locally:
npm run devThis command starts the Cloudflare worker on your local machine, accessible at http://localhost:8787.
This project utilizes Cloudflare D1 for database storage, with the schema defined within the migrations directory.
To apply migrations to your local development database:
npm run migrate:devTo apply migrations to the production database:
npm run migrate:prodTo integrate with Telegram:
- Create Your Bot: Message @BotFather on Telegram.
- Use
/newbot: Follow the prompts to create a new bot, choosing a name and username. - Save Bot Token: BotFather will provide you with a unique bot token. Save this token, as it's required for the
config.jsonfile.
After deploying your Cloudflare Worker, you must inform Telegram where to send updates. Set the webhook URL using the following command:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook?url=https://your-worker-url.workers.dev/telegram/webhookRemember to replace:
<YOUR_BOT_TOKEN>with your actual Telegram bot token.https://your-worker-url.workers.dev/telegram/webhookwith the URL of your deployed Cloudflare Worker.
To test the webhook functionality with a sample Telegram message against your local development server:
npm run test:webhookThis will send a test message to your local webhook endpoint.
This bot utilizes a Cloudflare AI Gateway named khmercoders-bot-summary-gw for specific AI functionalities. You will need to create this gateway in your Cloudflare account to ensure the bot operates correctly.
We welcome contributions from the community! Please follow these steps:
- Fork the Repository: Create your own copy of the repository.
- Create a New Branch: Branch off from
mainormasterfor your new feature or bug fix. - Implement Your Changes: Write your code, ensuring it adheres to the existing project standards.
- Write/Update Tests: Add or update tests to cover your changes.
- Submit a Pull Request: Create a pull request to merge your changes back into the main repository.
- Code Style: Adhere to the established code style and patterns within the project.
- Documentation: Add comments for complex logic to improve readability.
- Maintainability: Strive for clean, well-structured, and maintainable code.
- Commit Messages: Write clear and descriptive commit messages.
If you have any questions or suggestions, feel free to open an issue or reach out to the community!