This document provides detailed instructions on how to install and set up the Code Module Cop bot for managing Telegram groups.
Ensure the following tools are installed before proceeding:
- Node.js: Version 20.x or higher.
- npm: Version 6.x or higher.
- Docker: Latest version (if using Docker installation).
- PostgreSQL: (e.g., MariaDB or compatible PostgreSQL database).
You can install and run the bot from source or using Docker.
Clone the project repository from GitHub:
git clone https://github.com/CodeModule-ir/cop.git
cd cop
Run the following command to install the required packages:
npm install
Create a .env
file in the root directory and define the required environment variables. Use the template below for reference:
# Telegram Bot Token
TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here
# Local Database Configuration
DB_USER=your_db_user_here
DB_PASSWORD=your_db_password_here
DB_HOST=localhost
DB_NAME=your_db_name_here
DB_PORT=5432
DB_URL=postgres://your_db_user_here:your_db_password_here@localhost:5432/your_db_name_here
# Remote/Production Database Configuration
DATABASE_URL=postgresql://your_db_user_here:your_db_password_here@your_host_here:your_port_here/your_db_name_here
# Application Port
PORT=3000
# Telegram Web Hook URL
WEB_HOOK=https://your-webhook-url-here
# Node Environment (development or production)
NODE_ENV=development
Refer to the .env.example
file in the repository for more information.
Run the bot with the following command:
npm start
If you're in development, you can use:
npm run dev
Docker simplifies setup and deployment by containerizing the application.
Pull the latest Docker image from Docker Hub:
docker pull codemodule/cop
Run the bot using the pulled Docker image:
docker run -d \
--name cop \
--env-file .env \
codemodule/cop
Ensure the .env
file is created and filled with the required variables as described above.
For easier management of multiple services, use docker-compose.yml
. Copy the example below:
version: '3.8'
services:
bot:
image: codemodule/cop
container_name: cop
env_file:
- .env
restart: unless-stopped
ports:
- "3000:3000"
Start the containers using:
docker-compose up -d
Stop the containers using:
docker-compose down
-
Pull the latest changes:
git pull origin main
-
Install any updated dependencies:
npm install
-
Rebuild the application:
npm run build
-
Restart the bot:
npm start
-
Pull the latest Docker image:
docker pull codemodule/cop
-
Rebuild and restart containers:
docker-compose down && docker-compose up -d
Here’s a list of npm
scripts you can use to manage the bot:
-
Stop Docker Containers:
npm run docker:stop
-
Take Down Docker Containers:
npm run docker:down
-
Build Docker Images:
npm run docker:build
-
Run Docker Containers:
npm run docker:run
-
Start Docker Containers:
npm run docker:start
-
Compile TypeScript Code:
npm run build
-
Clean Distribution Directory:
npm run clean
-
Run the Node Application:
npm run main
# Telegram Bot Token (Set your Telegram bot token here)
TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here
# Database Configuration (Local)
DB_USER=your_db_user_here
DB_PASSWORD=your_db_password_here
DB_HOST=localhost
DB_NAME=your_db_name_here
DB_PORT=5432
DB_URL=postgres://your_db_user_here:your_db_password_here@localhost:5432/your_db_name_here
# Database Configuration (Remote/Production)
DATABASE_URL=postgresql://your_db_user_here:your_db_password_here@your_host_here:your_port_here/your_db_name_here
# Application Configuration
PORT=3000
WEB_HOOK=https://your-webhook-url-here
NODE_ENV=development