Official Telegram Bot for LicenseChain - License management and customer support through Telegram.
- π License Management - Validate, create, and manage licenses
- π€ User Support - Handle customer inquiries and support tickets
- π Analytics - View usage statistics and performance metrics
- π Notifications - Real-time license events and alerts
- π« Ticket System - Create and manage support tickets
- π Reporting - Generate reports and analytics
- π‘οΈ Security - Secure authentication and authorization
- π οΈ Easy Setup - Simple configuration and deployment
# Clone the repository
git clone https://github.com/LicenseChain/LicenseChain-TG-Bot.git
cd LicenseChain-TG-Bot
# Install dependencies
npm install
# Start the bot
npm start
# Build the Docker image
docker build -t licensechain-telegram-bot .
# Run the container
docker run -p 3000:3000 licensechain-telegram-bot
- Download the latest release from GitHub Releases
- Extract to your project directory
- Install dependencies:
npm install
- Configure environment variables
- Start the bot:
npm start
# Clone the repository
git clone https://github.com/LicenseChain/LicenseChain-TG-Bot.git
cd LicenseChain-TG-Bot
# Install dependencies
npm install
# Copy environment file
cp .env.example .env
# Edit environment variables
nano .env
# Start the bot
npm start
Create a .env
file with the following variables:
# Telegram Configuration
TELEGRAM_TOKEN=your-telegram-bot-token
TELEGRAM_WEBHOOK_URL=your-webhook-url
# LicenseChain API
LICENSECHAIN_API_KEY=your-api-key
LICENSECHAIN_APP_NAME=your-app-name
LICENSECHAIN_APP_VERSION=1.0.0
LICENSECHAIN_BASE_URL=https://api.licensechain.com
# Bot Configuration
BOT_DEBUG=false
BOT_OWNER_ID=your-telegram-user-id
# Database Configuration
DATABASE_URL=your-database-url
# Webhook Configuration
WEBHOOK_URL=your-webhook-url
WEBHOOK_SECRET=your-webhook-secret
# Validate a license
/validate <license-key>
# Get license information
/info <license-key>
# List user's licenses
/m licenses
# Create a new license
/create <user-id> <features> <expires>
# Update a license
/update <license-key> <field> <value>
# Revoke a license
/revoke <license-key>
# Get user information
/user <user-id>
# Get user's licenses
/licenses <user-id>
# Get user's analytics
/analytics <user-id>
# Ban a user
/ban <user-id> <reason>
# Unban a user
/unban <user-id>
# Create a support ticket
/ticket <subject> <description>
# List support tickets
/tickets
# Get ticket details
/ticket <ticket-id>
# Update ticket status
/update <ticket-id> <status>
# Close a ticket
/close <ticket-id>
# Get usage analytics
/usage [timeframe]
# Get license analytics
/licenses [timeframe]
# Get performance metrics
/performance
# Get error statistics
/errors
# Get bot status
/status
# Get bot statistics
/stats
# Reload commands
/reload
# Set bot status
/setstatus <status>
# Get bot logs
/logs [lines]
Configure the bot through environment variables or a configuration file:
// config/bot.js
module.exports = {
telegram: {
token: process.env.TELEGRAM_TOKEN,
webhookUrl: process.env.TELEGRAM_WEBHOOK_URL
},
licensechain: {
apiKey: process.env.LICENSECHAIN_API_KEY,
appName: process.env.LICENSECHAIN_APP_NAME,
version: process.env.LICENSECHAIN_APP_VERSION,
baseUrl: process.env.LICENSECHAIN_BASE_URL
},
bot: {
debug: process.env.BOT_DEBUG === 'true',
ownerId: process.env.BOT_OWNER_ID
}
};
Configure commands and their permissions:
// config/commands.js
module.exports = {
'validate': {
permission: 'user',
cooldown: 5000,
description: 'Validate a license key'
},
'create': {
permission: 'admin',
cooldown: 10000,
description: 'Create a new license'
},
'status': {
permission: 'owner',
cooldown: 0,
description: 'Get bot status'
}
};
The bot supports multiple database types:
// PostgreSQL
DATABASE_URL=postgresql://username:password@localhost:5432/licensechain
// MySQL
DATABASE_URL=mysql://username:password@localhost:3306/licensechain
// SQLite
DATABASE_URL=sqlite://./database.sqlite
- Telegram user verification
- Role-based command permissions
- User authentication system
- Secure API key management
- Command-level permissions
- User role validation
- Admin-only commands
- Owner-only functions
- Input validation and sanitization
- SQL injection prevention
- XSS protection
- Secure logging
// Track command usage
bot.on('message', async (ctx) => {
if (ctx.message.text.startsWith('/')) {
analytics.track('command_used', {
command: ctx.message.text.split(' ')[0],
user: ctx.from.id,
chat: ctx.chat.id,
timestamp: new Date()
});
}
});
// Monitor command execution time
const start = Date.now();
await command.execute(ctx);
const duration = Date.now() - start;
metrics.record('command_execution_time', duration);
// Track command errors
try {
await command.execute(ctx);
} catch (error) {
errorTracker.captureException(error, {
command: ctx.message.text.split(' ')[0],
user: ctx.from.id,
chat: ctx.chat.id
});
}
// Custom error classes
class CommandError extends Error {
constructor(message) {
super(message);
this.name = 'CommandError';
}
}
class PermissionError extends Error {
constructor(message) {
super(message);
this.name = 'PermissionError';
}
}
// Global error handler
bot.catch((err, ctx) => {
console.error('Bot error:', err);
errorTracker.captureException(err);
ctx.reply('An error occurred. Please try again later.');
});
process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
errorTracker.captureException(reason);
});
# Run tests
npm test
# Run tests with coverage
npm run test:coverage
# Run tests in watch mode
npm run test:watch
# Test with real Telegram API
npm run test:integration
# Test complete command flows
npm run test:e2e
See the examples/
directory for complete examples:
basic-setup.js
- Basic bot setupcustom-commands.js
- Custom command exampleswebhook-integration.js
- Webhook handlingdeployment.js
- Deployment configuration
We welcome contributions! Please see our Contributing Guide for details.
- Clone the repository
- Install Node.js 16 or later
- Install dependencies:
npm install
- Set up environment variables
- Start development server:
npm run dev
This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: https://docs.licensechain.com/telegram-bot
- Issues: GitHub Issues
- Discord: LicenseChain Discord
- Email: support@licensechain.com
Made with β€οΈ for the Telegram community