Skip to content

Commit 04b406d

Browse files
authored
πŸš€ release: v1.0.0-beta.4 - Merge pull request #26 from wgtechlabs/dev
2 parents 13e4f35 + c2cbd43 commit 04b406d

File tree

4 files changed

+89
-10
lines changed

4 files changed

+89
-10
lines changed

β€ŽCONTRIBUTING.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,46 @@ DATABASE_SSL_VALIDATE=false
285285
- **Production**: Set `NODE_ENV=production` and use secure connection strings
286286
- **Enterprise**: The same `.env` file works seamlessly across all deployment methods
287287

288+
#### **Railway SSL Configuration**
289+
290+
Railway's managed PostgreSQL uses self-signed SSL certificates. The bot automatically handles this:
291+
292+
**Automatic Detection:**
293+
294+
- The bot detects Railway environment by checking for `railway.internal` in service URLs (`PLATFORM_REDIS_URL`, `WEBHOOK_REDIS_URL`, or `POSTGRES_URL`)
295+
- When Railway is detected, SSL encryption is maintained but certificate validation is relaxed
296+
- No manual configuration needed - works out-of-the-box
297+
298+
**SSL Priority Logic:**
299+
300+
```typescript
301+
// 1. Railway environment (highest priority)
302+
if (isRailwayEnvironment()) {
303+
return { rejectUnauthorized: false }; // Accept Railway's self-signed certs
304+
}
305+
306+
// 2. Production environment
307+
if (isProduction) {
308+
return { rejectUnauthorized: true }; // Strict SSL validation
309+
}
310+
311+
// 3. Development environment
312+
// Uses DATABASE_SSL_VALIDATE environment variable
313+
```
314+
315+
**Railway SSL Behavior:**
316+
317+
- βœ… SSL encryption always enabled for secure data transmission
318+
- βœ… Accepts Railway's self-signed certificates automatically
319+
- βœ… Railway detection overrides `DATABASE_SSL_VALIDATE` environment variable
320+
- βœ… Maintains security while working with Railway's infrastructure
321+
322+
**Environment Variable Impact:**
323+
324+
- `DATABASE_SSL_VALIDATE=false` is **ignored** on Railway (Railway-specific SSL is used)
325+
- `DATABASE_SSL_VALIDATE=true` is **ignored** on Railway (Railway-specific SSL is used)
326+
- Only affects non-Railway environments (local, other cloud providers)
327+
288328
### πŸ”— Webhook Server Integration
289329

290330
This bot works in conjunction with the [`wgtechlabs/unthread-webhook-server`](https://github.com/wgtechlabs/unthread-webhook-server) to enable real-time bidirectional communication.

β€ŽREADME.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,13 @@ PLATFORM_REDIS_URL=redis://redis-platform:6379
145145

146146
> **πŸ’‘ Pro Tip**: The Docker setup includes PostgreSQL and Redis automatically - no separate installation needed!
147147
148-
### **πŸ”§ Need Help?**
148+
### **πŸ›€οΈ Railway Deployment**
149149

150-
- **Quick Questions**: Check our [Community Discussions](https://github.com/wgtechlabs/unthread-telegram-bot/discussions)
151-
- **Technical Setup**: See our detailed [Contributing Guide](./CONTRIBUTING.md)
152-
- **Issues**: Report bugs in our [Issue Tracker](https://github.com/wgtechlabs/unthread-telegram-bot/issues)
153-
- No manual migration scripts needed
150+
For detailed information about Railway's managed PostgreSQL and SSL handling, please refer to the [Railway Deployment section in the README](README.md#πŸ›€οΈ-railway-deployment).
151+
- βœ… **Environment Override**: Railway detection takes precedence over all other SSL settings
152+
- βœ… **No Configuration**: Works out-of-the-box without manual SSL setup
153+
154+
> **πŸ”’ Security Note**: Railway's self-signed certificates are secure within their managed infrastructure. The bot maintains SSL encryption while accommodating Railway's certificate setup.
154155
155156
## πŸ•ΉοΈ Usage
156157

β€Žpackage.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "unthread-telegram-bot",
3-
"version": "1.0.0-beta.3",
3+
"version": "1.0.0-beta.4",
44
"description": "Turn private Telegram groups into real-time support ticket hubs β€” powered by Unthread.io.",
55
"keywords": [
66
"telegram",

β€Žsrc/database/connection.ts

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,14 @@ export class DatabaseConnection {
8484
}); LogEngine.info('Database connection pool initialized', {
8585
maxConnections: 10,
8686
sslEnabled: sslConfig !== false,
87-
sslValidation: isProduction ? 'enabled' : (
88-
process.env.DATABASE_SSL_VALIDATE === 'false' ? 'disabled' :
89-
process.env.DATABASE_SSL_VALIDATE === 'true' ? 'enabled' : 'enabled-no-validation'
87+
sslValidation: this.isRailwayEnvironment() ? 'railway-compatible' : (
88+
isProduction ? 'enabled' : (
89+
process.env.DATABASE_SSL_VALIDATE === 'false' ? 'disabled' :
90+
process.env.DATABASE_SSL_VALIDATE === 'true' ? 'enabled' : 'enabled-no-validation'
91+
)
9092
),
9193
environment: process.env.NODE_ENV || 'development',
92-
provider: 'Railway'
94+
provider: this.isRailwayEnvironment() ? 'Railway' : 'Unknown'
9395
});
9496
}
9597

@@ -254,11 +256,47 @@ export class DatabaseConnection {
254256
throw error;
255257
}
256258
} /**
259+
* Check if running on Railway platform
260+
* @returns True if detected Railway environment
261+
*/
262+
private isRailwayEnvironment(): boolean {
263+
// Check Redis URLs and PostgreSQL URL that are available to this service
264+
const platformRedis = process.env.PLATFORM_REDIS_URL;
265+
const webhookRedis = process.env.WEBHOOK_REDIS_URL;
266+
const postgresUrl = process.env.POSTGRES_URL;
267+
// Railway internal services use 'railway.internal' in their hostnames
268+
const isRailwayHost = (url: string | undefined): boolean => {
269+
if (!url || url.trim() === '') return false;
270+
try {
271+
const parsedUrl = new URL(url);
272+
return parsedUrl.hostname.toLowerCase().includes('railway.internal');
273+
} catch {
274+
return false; // Invalid URL
275+
}
276+
};
277+
278+
return (
279+
isRailwayHost(platformRedis) ||
280+
isRailwayHost(webhookRedis) ||
281+
isRailwayHost(postgresUrl)
282+
);
283+
}
284+
285+
/**
257286
* Configure SSL settings based on environment
258287
* @param isProduction - Whether running in production environment
259288
* @returns SSL configuration object, or false to disable SSL entirely
260289
*/
261290
private getSSLConfig(isProduction: boolean): any {
291+
// Check if we're on Railway first - they use self-signed certificates
292+
if (this.isRailwayEnvironment()) {
293+
return {
294+
rejectUnauthorized: false, // Accept Railway's self-signed certificates
295+
// SSL encryption is still enabled for secure data transmission
296+
ca: process.env.DATABASE_SSL_CA || undefined
297+
};
298+
}
299+
262300
// In production, always validate SSL certificates for security
263301
if (isProduction) {
264302
return {

0 commit comments

Comments
Β (0)