A production-ready Node.js Express server for handling CometChat and Telegram integrations with webhook processing, comprehensive logging, and auto-deployment capabilities.
Production URL: https://adityagokula.com/cometchat-integrations/
This project follows a modular architecture with clear separation of concerns:
cometchat-integrations/
βββ app.js # Main application entry point
βββ package.json # Project dependencies
βββ ecosystem.config.js # PM2 configuration
βββ .github/workflows/ # GitHub Actions CI/CD
βββ .env.example # Environment template
βββ src/
βββ config/ # Configuration management
β βββ index.js # Environment variables & settings
βββ controllers/ # Request handlers
β βββ healthController.js # Health checks & status
β βββ rootController.js # API information
β βββ cometChatController.js # CometChat webhook handling
β βββ telegramController.js # Telegram webhook handling
βββ services/ # Business logic
β βββ cometChatService.js # CometChat integration logic
β βββ telegramService.js # Telegram bot logic
βββ middleware/ # Express middleware
β βββ requestLogger.js # Request/response logging
β βββ bodyLogger.js # JSON payload logging
β βββ errorHandler.js # Global error handling
β βββ webhookAuth.js # Webhook authentication
βββ routes/ # Route definitions
β βββ rootRoutes.js # Root API routes
β βββ healthRoutes.js # Health check routes
β βββ cometChatRoutes.js # CometChat webhook routes
β βββ telegramRoutes.js # Telegram webhook routes
βββ utils/ # Utility functions
βββ logger.js # Main logging utility
βββ productionLogger.js # Production output
βββ response.js # Standardized responses
βββ validator.js # Input validation
- Clean Architecture: Modular design with separation of concerns
- Production Logging: PM2-compatible logging with JSON payloads
- Webhook Processing: Handles CometChat and Telegram webhooks
- Auto-deployment: GitHub Actions CI/CD pipeline
- HTTPS/SSL: Let's Encrypt certificates with auto-renewal
- Error Handling: Centralized error handling and recovery
- Input Validation: Request validation and sanitization
- Health Monitoring: Health checks and system status endpoints
- Production Ready: PM2 process management and nginx reverse proxy
GET /- API information and documentationGET /health- Health check with uptime and version infoGET /status- Detailed system status
GET /cometchat- CometChat service informationPOST /cometchat- CometChat webhook endpoint
GET /telegram- Telegram service informationPOST /telegram- Telegram webhook endpoint
Environment variables can be set for configuration:
# Server Configuration
PORT=3000
NODE_ENV=production
# CometChat Configuration
COMETCHAT_APP_ID=your_app_id
COMETCHAT_REGION=us
COMETCHAT_API_KEY=your_api_key
COMETCHAT_WEBHOOK_SECRET=your_webhook_secret
# Telegram Configuration
TELEGRAM_BOT_TOKEN=your_bot_token
TELEGRAM_WEBHOOK_SECRET=your_webhook_secret
# Logging Configuration
LOG_LEVEL=info
ENABLE_FILE_LOGGING=false
# Security Configuration
ENABLE_AUTH=false
JWT_SECRET=your_jwt_secret
CORS_ORIGINS=*-
Clone the repository
git clone https://github.com/adityagokula2210/cometchat-integrations.git cd cometchat-integrations -
Install dependencies
npm install
-
Configure environment variables
# Copy the template and configure your values cp .env.example .env # Edit .env with your actual credentials: # - Get CometChat credentials from: https://app.cometchat.com/ # - Get Telegram bot token from: @BotFather on Telegram nano .env
-
Start development server
npm run dev
-
Start production server
npm start
The project includes a GitHub Actions workflow that automatically deploys to your server when code is pushed to the main branch.
Deployment Flow:
- Push code to
mainbranch - GitHub Actions triggers
- Code is pulled on the server
- Dependencies are installed
- PM2 restarts the application
- Server is live with new changes
Server Requirements:
- Node.js 14+
- PM2 process manager
- nginx reverse proxy
- Git for auto-deployment
PM2 Configuration:
# Start application with PM2
pm2 start ecosystem.config.js --env production
# Monitor application
pm2 status
pm2 logs cometchat-integrationsNginx Configuration:
server {
listen 80;
server_name adityagokula.com;
location /cometchat-integrations/ {
proxy_pass http://localhost:3001/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
}All requests and responses are logged with structured JSON format:
{
"timestamp": "2025-10-04T07:00:00.000Z",
"level": "INFO",
"message": "CometChat webhook received",
"service": "cometchat",
"action": "message_sent",
"messageId": "123",
"sender": "user123"
}- Health checks at
/health - System status at
/status - Process monitoring with PM2
- Auto-restart on failures
- Input validation and sanitization
- Webhook signature verification (configurable)
- Rate limiting (can be added)
- CORS protection
- Proxy trust configuration
- Error message sanitization in production
Test the webhooks locally:
# Test CometChat webhook
curl -X POST "http://localhost:3000/cometchat" \
-H "Content-Type: application/json" \
-d '{
"trigger": "message_sent",
"data": {
"message": {
"id": "123",
"text": "Hello World"
}
},
"appId": "your_app_id"
}'
# Test Telegram webhook
curl -X POST "http://localhost:3000/telegram" \
-H "Content-Type: application/json" \
-d '{
"update_id": 123,
"message": {
"message_id": 456,
"text": "/start",
"from": {"id": 789, "username": "testuser"}
}
}'- Create Service: Add business logic in
src/services/ - Create Controller: Add request handling in
src/controllers/ - Create Routes: Add route definitions in
src/routes/ - Update Main App: Register routes in
app.js - Add Configuration: Update config in
src/config/
- Use structured logging via the logger utility
- Follow the controller β service β response pattern
- Implement proper error handling
- Add input validation for all endpoints
- Use the ResponseHandler for consistent API responses
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the ISC License.
- Production URL: https://adityagokula.com/cometchat-integrations/
- GitHub Repository: https://github.com/adityagokula2210/cometchat-integrations
- CometChat Docs: https://www.cometchat.com/docs/
- Telegram Bot API: https://core.telegram.org/bots/api