Any contributions are welcome, encouraged, and valued. See the following information below for different ways to help and details about how this project handles them. Please make sure to read the relevant section before making your contribution. It will make it a lot easier for the maintainer and smooth out the experience for all involved. The community looks forward to your contributions. πββ¨
This project and everyone participating in it is governed by the project's Code of Conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to opensource@wgtechlabs.com.
There are many ways to contribute to this open source project. Any contributions are welcome and appreciated. Be sure to read the details of each section for you to start contributing.
If you can write code then create a pull request to this repo and I will review your code. Please consider submitting your pull request to the dev branch. I will auto reject if you submit your pull request to the main branch.
To get started with development:
-
Fork and clone the repository
git clone https://github.com/your-username/unthread-webhook-server.git cd unthread-webhook-server -
Install dependencies
pnpm install
β οΈ Important: This project enforces the use of pnpm. npm and yarn install will be blocked automatically. -
Set up environment variables
- Copy
.env.exampleto.env - Fill in the required information as described in the README
cp .env.example .env
- Copy
-
Start Redis
# Choose one option based on your setup redis-server # Local installation brew services start redis # macOS sudo systemctl start redis-server # Linux docker run -d -p 6379:6379 redis:alpine # Docker # OR for full Docker setup with proper naming: docker network create unthread-integration-network docker-compose up -d redis-webhook
-
Start the project in development mode
pnpm dev
Please refer to the README for more detailed setup instructions.
# Development with auto-reload
pnpm dev
# Build for production
pnpm build
# Type checking only
pnpm type-check
# Linting
pnpm lint # Run ESLint on all source files
pnpm lint:fix # Run ESLint with auto-fix
pnpm lint:security # Focus on security-related issues
pnpm lint:ci # CI-friendly linting (fails on warnings)
# Clean build artifacts
pnpm clean
# Start production build
pnpm start
# Run tests
pnpm test # Run all tests once
pnpm test:watch # Run tests in watch mode
pnpm test:ui # Interactive test UI
pnpm test:coverage # Generate coverage reportsrc/
βββ app.ts # Main application entry point
βββ config/ # Configuration files
β βββ env.ts # Environment configuration
β βββ redis.ts # Redis configuration
βββ controllers/ # Request handlers
β βββ webhookController.ts
βββ middleware/ # Express middleware
β βββ auth.ts # HMAC signature verification
β βββ validation.ts # Request validation
βββ services/ # Business logic
β βββ redisService.ts
β βββ webhookService.ts
βββ types/ # TypeScript type definitions
β βββ index.ts
βββ utils/ # Helper functions
βββ signature.ts # HMAC signature utilities
- TypeScript First: All code must be written in TypeScript with strict type checking
- Code Quality: Follow ESLint rules and security best practices enforced by automated linting
- Structured Logging: Use
@wgtechlabs/log-enginefor all logging with built-in PII protection and security features - Error Handling: Implement comprehensive error handling with detailed logging
- Package Manager: Use pnpm exclusively (enforced via preinstall script)
- Code Style: Follow existing patterns and maintain consistency
- Environment: Use Node.js 22+ for development
- Redis Integration: Ensure Redis connectivity for all webhook-related features
- Webhook Integration: Ensure compatibility with
wgtechlabs/unthread-telegram-bot
This project uses ESLint with comprehensive security plugins to maintain code quality and prevent common security vulnerabilities.
Security Plugins Enabled:
- eslint-plugin-security - Detects common security vulnerabilities
- eslint-plugin-no-secrets - Prevents hardcoded secrets and credentials
- eslint-plugin-n - Node.js best practices and deprecated API detection
- eslint-plugin-import - Validates ES6 import/export syntax
- eslint-plugin-promise - Ensures proper promise handling
Running Linting:
# Check for issues
pnpm lint
# Automatically fix issues
pnpm lint:fix
# Security-focused check
pnpm lint:security
# CI mode (fails on warnings)
pnpm lint:ciComprehensive ESLint Configuration:
This project uses a modern flat config format (eslint.config.js) with the following capabilities:
- TypeScript-first: Full TypeScript-ESLint integration with strict type checking
- Security-focused: Multiple security plugins working together to prevent vulnerabilities
- Customizable: Tailored rules for webhook server security requirements
- IDE Integration: Works seamlessly with VSCode ESLint extension
For complete configuration details, see eslint.config.js.
Key Security Rules:
- No hardcoded secrets - Detects API keys, tokens, passwords, webhook secrets in code
- Safe regular expressions - Prevents ReDoS attacks
- Secure random generation - Enforces crypto.randomBytes over Math.random
- Object injection protection - Warns about unsafe object property access
- Child process security - Flags potentially unsafe child process usage
- Promise handling - Ensures all promises are properly handled
Best Practices:
- Fix all linting errors before submitting PRs (required)
- Address security warnings unless there's a documented reason to ignore them
- Use ESLint disable comments sparingly and only with proper justification
- Run
pnpm lint:fixto auto-fix style issues before committing - Test security rules with
pnpm lint:securityfor security-focused checks - VSCode users get automatic linting and auto-fix on save with ESLint extension
- Document any rule disables in code comments explaining why they're necessary
When to Disable Rules:
// β
Good - documented reason
// eslint-disable-next-line security/detect-object-injection
const value = obj[key]; // key is from typed enum, safe
// β Bad - no justification
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const data: any = response;This project uses Vitest for automated testing. When contributing:
Automated Testing:
- Write tests for new features and bug fixes
- Ensure all tests pass:
pnpm test - Maintain minimum 80% code coverage:
pnpm test:coverage - Follow co-located test patterns (e.g.,
signature.tsβsignature.test.ts) - Use
pnpm test:watchfor development,pnpm test:uifor interactive testing
Manual Testing:
- Test your changes using tools like ngrok for webhook testing
- Verify Redis connectivity and queue operations
- Test HMAC signature verification with valid Unthread events
- Ensure proper error handling for edge cases
- Verify platform source detection accuracy
-
Pre-submission checks:
- Code builds without errors (
pnpm build) - TypeScript type checking passes (
pnpm type-check) - Linting passes without errors (
pnpm lint) - All tests pass (
pnpm test) - Coverage requirements met (
pnpm test:coverage) - Development server starts successfully (
pnpm dev) - Redis integration works properly
- Error handling is comprehensive
- No security warnings from
pnpm lint:security
- Code builds without errors (
-
Pull Request Requirements:
- Target the
devbranch (PRs tomainwill be rejected) - Include clear description of changes
- Follow existing code patterns and ESLint rules
- Update documentation if needed
- Add/update tests for changes
- Test webhook functionality manually
- All linting issues resolved or properly justified
- Target the
Improvements to documentation are always welcome! This includes:
- README updates
- Code comments
- API documentation
- Configuration examples
- Troubleshooting guides
- Fixing typos or clarifying existing documentation
For any security bugs or issues, please create a private security advisory through GitHub's security advisory feature.
For other bugs, please create an issue with:
- Clear description of the problem
- Steps to reproduce
- Expected vs actual behavior
- Environment details (Node.js version, Redis version, OS)
- Relevant logs or error messages
We welcome suggestions for new features! Please create an issue with:
- Clear description of the feature
- Use case and benefits
- Any implementation considerations
- Examples or mockups if applicable
This project uses @wgtechlabs/log-engine for enterprise-grade logging with built-in security features and comprehensive PII protection.
Zero Configuration PII Protection:
- Automatic Redaction: Passwords, tokens, emails, API keys, and 50+ sensitive patterns are automatically protected
- Deep Object Scanning: Recursively scans nested objects and arrays for sensitive data
- Content Truncation: Large payloads are automatically truncated to prevent log bloat
- Environment-Based Control: Security automatically adapts based on NODE_ENV settings
Built-in Patterns Protected:
- Authentication:
password,token,apiKey,secret,jwt,auth,sessionId - Personal Info:
email,phone,ssn,firstName,lastName,address - Financial:
creditCard,cvv,bankAccount,routingNumber - System:
clientSecret,privateKey,webhookSecret,unthreadSecret
Custom Enterprise Protection:
import { LogEngine } from '@wgtechlabs/log-engine';
// Add custom patterns for enterprise-specific data
LogEngine.addCustomRedactionPatterns([
/internal.*/i, // Matches any field starting with "internal"
/company.*/i, // Matches any field starting with "company"
/webhook.*/i, // Matches webhook-specific fields
/unthread.*/i // Matches unthread-specific fields
]);
// Add dynamic sensitive field names
LogEngine.addSensitiveFields([
'webhookSecret',
'unthreadWebhookSecret',
'unthreadApiKey',
'redisPassword'
]);Secure Logging Examples:
// β
Automatic protection - no configuration needed
LogEngine.info('Webhook authentication', {
webhookId: '123456789', // β
Visible
webhookSecret: 'secret123', // β [REDACTED]
targetPlatform: 'telegram', // β
Visible
unthreadApiKey: 'key_123' // β [REDACTED]
});
// β
Event processing protection
LogEngine.info('Event processing', {
eventType: 'message_created', // β
Visible
eventId: 'evt_001', // β
Visible
signature: 'sha256=...', // β [REDACTED]
payload: { /* large data */ } // Automatically truncated
});
// β
Redis queue security
LogEngine.info('Queue publishing', {
queueName: 'unthread-events', // β
Visible
platform: 'unthread', // β
Visible
redisUrl: 'redis://localhost', // β [REDACTED]
eventCount: 5 // β
Visible
});Production Security (Recommended):
NODE_ENV=production # Full PII protection enabled
LOG_REDACTION_TEXT="[SECURE]" # Custom redaction text
LOG_MAX_CONTENT_LENGTH=150 # Truncate large contentDevelopment Debugging:
NODE_ENV=development # Redaction disabled for debugging
LOG_REDACTION_DISABLED=true # Explicit disable
DEBUG_FULL_PAYLOADS=true # Show complete dataCustom Security Configuration:
# Custom sensitive fields (comma-separated)
LOG_SENSITIVE_FIELDS="webhookSecret,unthreadSecret,redisPassword"
# Custom redaction patterns (JSON array)
LOG_CUSTOM_PATTERNS='["/internal.*/i", "/company.*/i"]'
# Truncation settings
LOG_MAX_CONTENT_LENGTH=200
LOG_TRUNCATION_TEXT="... [CONFIDENTIAL_TRUNCATED]"Raw Logging for Development:
// β οΈ Use with caution - bypasses all redaction
LogEngine.debugRaw('Full webhook payload', {
password: 'visible', // β οΈ Visible (not redacted)
apiKey: 'full-key-visible' // β οΈ Visible (not redacted)
});
// Temporary redaction bypass
LogEngine.withoutRedaction().info('Debug mode', sensitiveData);
// Test field redaction
const isRedacted = LogEngine.testFieldRedaction('webhookSecret'); // true
const currentConfig = LogEngine.getRedactionConfig();Security Compliance:
- GDPR Ready: Automatic PII protection for European compliance
- Data Minimization: Only necessary data is logged
- Audit Trails: Complete security event logging with timestamps
- Incident Response: Quick identification of security events
Operational Benefits:
- Color-Coded Output: Easy visual identification of log levels (π΅ INFO, π‘ WARN, π΄ ERROR)
- Structured Logging: Consistent format across all webhook components
- Performance Optimized: Minimal overhead with intelligent processing
- TypeScript Support: Full type safety and IDE integration
π» with β€οΈ by Waren Gonzaga, WG Technology Labs, and Him π