Skip to content

Commit 44cb3b9

Browse files
committed
☕ chore: update readme info
1 parent e346f97 commit 44cb3b9

File tree

1 file changed

+126
-6
lines changed

1 file changed

+126
-6
lines changed

README.md

Lines changed: 126 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![release workflow](https://img.shields.io/github/actions/workflow/status/wgtechlabs/unthread-webhook-server/release.yml?branch=main&style=flat-square&logo=github&labelColor=181717&label=release)](https://github.com/wgtechlabs/unthread-webhook-server/actions/workflows/release.yml) [![build workflow](https://img.shields.io/github/actions/workflow/status/wgtechlabs/unthread-webhook-server/build.yml?branch=dev&style=flat-square&logo=github&labelColor=181717&label=build)](https://github.com/wgtechlabs/unthread-webhook-server/actions/workflows/build.yml) [![node](https://img.shields.io/badge/node-%3E%3D20-green.svg?style=flat-square&labelColor=181717&logo=node.js&logoColor=white)](https://nodejs.org/) [![typescript](https://img.shields.io/badge/typescript-5.x-blue.svg?style=flat-square&labelColor=181717&logo=typescript&logoColor=white)](https://www.typescriptlang.org/) [![sponsors](https://img.shields.io/badge/sponsor-%E2%9D%A4-%23db61a2.svg?&logo=github&logoColor=white&labelColor=181717&style=flat-square)](https://github.com/sponsors/wgtechlabs) [![version](https://img.shields.io/github/release/wgtechlabs/unthread-webhook-server.svg?logo=github&labelColor=181717&color=green&style=flat-square&label=version)](https://github.com/wgtechlabs/unthread-webhook-server/releases) [![star](https://img.shields.io/github/stars/wgtechlabs/unthread-webhook-server.svg?&logo=github&labelColor=181717&color=yellow&style=flat-square)](https://github.com/wgtechlabs/unthread-webhook-server/stargazers) [![license](https://img.shields.io/github/license/wgtechlabs/unthread-webhook-server.svg?&logo=github&labelColor=181717&style=flat-square)](https://github.com/wgtechlabs/unthread-webhook-server/blob/main/license)
44

5-
A reliable, production-ready Node.js server for processing Unthread.io webhooks with signature verification and smart platform handling. Built with TypeScript, Express.js, and Redis, this webhook server provides secure HMAC-SHA256 signature validation, intelligent event deduplication, and seamless integration with multiple platforms including Discord and Telegram. The server automatically detects event sources, processes various webhook events (conversations, messages, status updates), and efficiently queues them through Redis for downstream consumption by your bot applications, ensuring reliable and scalable webhook processing for your Unthread.io integrations.
5+
A reliable, production-ready Node.js server for processing Unthread.io webhooks with signature verification and smart platform handling. Built with TypeScript, Express.js, and Redis, this webhook server provides secure HMAC-SHA256 signature validation, intelligent event deduplication, seamless integration with multiple platforms including Discord and Telegram, and **advanced file attachment correlation** that accurately detects source platforms for file uploads. The server automatically detects event sources, processes various webhook events (conversations, messages, status updates), correlates file attachments with their originating platforms, and efficiently queues them through Redis for downstream consumption by your bot applications, ensuring reliable and scalable webhook processing for your Unthread.io integrations.
66

77
## 🤗 Special Thanks
88

@@ -45,6 +45,30 @@ Server runs on `http://localhost:3000` with endpoints:
4545
- `GET /health` - Health check
4646
- `POST /unthread-webhook` - Webhook endpoint
4747

48+
## ✨ Features
49+
50+
### 🔐 Security & Reliability
51+
- **HMAC-SHA256 Signature Verification**: Secure webhook authentication
52+
- **Event Deduplication**: Redis-based TTL cache prevents duplicate processing
53+
- **Rate Limiting**: Built-in protection against spam and abuse
54+
55+
### 🎯 Smart Platform Detection
56+
- **Intelligent Source Identification**: Automatically detects Dashboard vs. target platform events
57+
- **File Attachment Correlation**: Revolutionary system that links file uploads with their true source platforms
58+
- **Multi-Platform Support**: Discord, Telegram, and extensible for other platforms
59+
60+
### 📎 Advanced File Handling
61+
- **Source Platform Accuracy**: Eliminates "unknown" file sources through intelligent correlation
62+
- **Rich Metadata Generation**: Automatic file summaries with counts, sizes, types, and names
63+
- **Multi-Event Buffering**: Handles multiple file attachments with timeout-based processing
64+
- **Memory-Based Correlation**: 15-second correlation windows with automatic fallbacks
65+
66+
### 🚀 Production-Ready Architecture
67+
- **Redis Queue Integration**: Efficient FIFO event processing
68+
- **Comprehensive Logging**: Detailed operation logs with emoji indicators
69+
- **Health Monitoring**: Built-in health checks for system status
70+
- **TypeScript**: Full type safety throughout the codebase
71+
4872
## 🚂 One-Click Deploy
4973

5074
Deploy instantly to Railway with a single click:
@@ -98,7 +122,7 @@ Required variables:
98122
| `UNTHREAD_WEBHOOK_SECRET` | Your Unthread.io signing secret | - ||
99123
| `NODE_ENV` | Environment mode | `development` ||
100124
| `PORT` | Server port | `3000` ||
101-
| `TARGET_PLATFORM` | Platform identifier (e.g., telegram, discord) | `telegram` | |
125+
| `TARGET_PLATFORM` | Platform identifier (e.g., telegram, discord) | - | |
102126
| `REDIS_URL` | Redis connection URL | `redis://localhost:6379` ||
103127

104128
### Getting Your Unthread Signing Secret
@@ -116,7 +140,18 @@ For local testing, use [ngrok](https://ngrok.com/): `ngrok http 3000`
116140
2. **Security**: Validates HMAC-SHA256 signatures using your webhook secret
117141
3. **Deduplication**: Prevents duplicate event processing with Redis TTL cache
118142
4. **Platform Detection**: Identifies if events come from dashboard or target platform
119-
5. **Queue Publishing**: Sends processed events to Redis `unthread-events` queue
143+
5. **File Attachment Correlation**: Smart correlation system that links file attachments with their source platforms instead of marking them as "unknown"
144+
6. **Queue Publishing**: Sends processed events to Redis `unthread-events` queue with enhanced attachment metadata
145+
146+
### 🎯 File Attachment Intelligence
147+
148+
This server features advanced file attachment correlation that:
149+
150+
- **Eliminates "Unknown" Sources**: Automatically correlates file upload events with their originating platform (Dashboard, Telegram, Discord, etc.)
151+
- **Memory-Based Correlation**: Uses intelligent caching to match message events with subsequent file upload events
152+
- **Rich Metadata Generation**: Provides comprehensive attachment summaries including file count, total size, MIME types, and file names
153+
- **Multi-Event Buffering**: Handles multiple file attachments in a single conversation with timeout-based processing
154+
- **Backwards Compatibility**: Existing integrations continue to work without modification
120155

121156
## 📊 Event Processing
122157

@@ -128,7 +163,8 @@ For local testing, use [ngrok](https://ngrok.com/): `ngrok http 3000`
128163
- `message_created` - New messages
129164

130165
### Redis Queue Format
131-
Events are queued with this structure:
166+
167+
Events are queued with this enhanced structure:
132168

133169
```json
134170
{
@@ -140,12 +176,34 @@ Events are queued with this structure:
140176
"eventId": "evt_123456789",
141177
"conversationId": "conv_abc123",
142178
"content": "Hello from support!",
143-
"eventTimestamp": 1733097600000
179+
"eventTimestamp": 1733097600000,
180+
"files": [
181+
{
182+
"id": "F123ABC456",
183+
"name": "document.pdf",
184+
"size": 524288,
185+
"mimetype": "application/pdf"
186+
}
187+
]
188+
},
189+
"attachments": {
190+
"hasFiles": true,
191+
"fileCount": 1,
192+
"totalSize": 524288,
193+
"types": ["application/pdf"],
194+
"names": ["document.pdf"]
144195
},
145196
"timestamp": 1733097600000
146197
}
147198
```
148199

200+
**New Enhancement**: Events with file attachments now include an `attachments` metadata object providing:
201+
- `hasFiles`: Boolean indicating presence of files
202+
- `fileCount`: Total number of attached files
203+
- `totalSize`: Combined size of all files in bytes
204+
- `types`: Array of unique MIME types (deduplicated)
205+
- `names`: Array of all file names (maintains order)
206+
149207
## 💻 Development
150208

151209
### Build Commands
@@ -164,11 +222,21 @@ yarn start # Run production build
164222
src/
165223
├── app.ts # Main application entry
166224
├── config/ # Configuration files
225+
│ ├── env.ts # Environment validation
226+
│ └── redis.ts # Redis configuration
167227
├── controllers/ # Request handlers
228+
│ └── webhookController.ts
168229
├── middleware/ # Auth & validation
230+
│ ├── auth.ts # HMAC signature verification
231+
│ └── validation.ts # Request validation
169232
├── services/ # Business logic
233+
│ ├── redisService.ts # Redis operations
234+
│ └── webhookService.ts # Webhook processing
170235
├── types/ # TypeScript types
236+
│ └── index.ts # All type definitions
171237
└── utils/ # Helper functions
238+
├── signature.ts # HMAC utilities
239+
└── fileAttachmentCorrelation.ts # File correlation system
172240
```
173241

174242
## 🔍 Monitoring
@@ -200,22 +268,74 @@ curl http://localhost:3000/health
200268
### Troubleshooting
201269

202270
**Redis Connection Issues:**
271+
203272
- Verify Redis is running: `redis-cli ping`
204273
- Check `REDIS_URL` in your `.env` file
205274
- Review server logs for connection errors
206275

207276
**Platform Detection Issues:**
277+
208278
- Check logs for detection summary details
209279
- Verify event structure matches Unthread format
210280
- Events may be classified as "unknown" for edge cases
211281

282+
**File Attachment Correlation Issues:**
283+
284+
- Verify `TARGET_PLATFORM` is set correctly in your `.env` file
285+
- Check correlation logs for timing and buffering details
286+
- File events without correlation data will fall back to "unknown" source
287+
- Correlation window is 15 seconds - events outside this window may not correlate
288+
289+
**Common Solutions:**
290+
291+
- Restart the server if platform detection seems inconsistent
292+
- Clear Redis cache if experiencing correlation issues: `redis-cli FLUSHDB`
293+
- Enable debug logging by setting `NODE_ENV=development` for detailed correlation logs
294+
295+
## 🚀 Integration Benefits
296+
297+
### For Bot Developers
298+
299+
- **Accurate Source Detection**: No more "unknown" file attachment sources - get precise platform identification
300+
- **Rich File Metadata**: Access file counts, sizes, types, and names without parsing complex file arrays
301+
- **Simplified Integration**: Use the `attachments` metadata for quick file handling logic
302+
- **Backwards Compatibility**: Existing code continues to work unchanged
303+
304+
### For Production Systems
305+
306+
- **Reliable Correlation**: Memory-based correlation system with 15-second timing windows and automatic fallbacks
307+
- **Robust Error Handling**: Comprehensive timeout management and duplicate prevention
308+
- **Scalable Architecture**: Efficient Redis-based queuing with TTL cleanup and deduplication
309+
- **Production-Ready**: Extensive logging, monitoring, and error recovery mechanisms
310+
212311
## 🎯 Contributing
213312

214313
Contributions are welcome, create a pull request to this repo and I will review your code. Please consider to submit your pull request to the `dev` branch. Thank you!
215314

216315
When contributing, please ensure your code follows the existing TypeScript patterns and includes appropriate error handling.
217316

218-
## 🙏 Sponsor
317+
## � Recent Updates
318+
319+
### v1.0.0-beta.5.2 - File Attachment Intelligence
320+
321+
**Major Enhancement**: Revolutionary file attachment correlation system that eliminates "unknown" source platforms.
322+
323+
**New Features:**
324+
- **Smart File Correlation**: Memory-based system that links file uploads with their originating platforms
325+
- **Rich Attachment Metadata**: Automatic generation of file summaries for easier integration
326+
- **Multi-Event Buffering**: Handles multiple files per conversation with robust timeout management
327+
- **Enhanced Platform Detection**: Required `TARGET_PLATFORM` configuration for improved accuracy
328+
- **Production-Ready**: Comprehensive error handling, logging, and resource cleanup
329+
330+
**Breaking Changes:**
331+
- `TARGET_PLATFORM` is now required (no default value)
332+
- Enhanced Redis queue format includes `attachments` metadata object
333+
334+
**Migration Guide:**
335+
- Set `TARGET_PLATFORM` in your `.env` file (e.g., `telegram`, `discord`)
336+
- Existing integrations will continue to work - new `attachments` field is additive
337+
338+
## �🙏 Sponsor
219339

220340
Like this project? **Leave a star**! ⭐⭐⭐⭐⭐
221341

0 commit comments

Comments
 (0)