- Signal: Use base64Attachments field in signal-cli-rest-api - WhatsApp: Implement Baileys attachment sending for images, videos, audio, and documents - Both channels retrieve attachments from Zammad Store model - Support multiple attachments per message |
||
|---|---|---|
| .. | ||
| lib | ||
| tasks | ||
| .dockerignore | ||
| crontab | ||
| docker-entrypoint.sh | ||
| Dockerfile | ||
| graphile.config.ts | ||
| index.ts | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
Bridge Worker
Background job processor for handling asynchronous tasks in the CDR Link communication bridge system.
Overview
Bridge Worker uses Graphile Worker to process queued jobs for message handling, media conversion, webhook notifications, and scheduled tasks. It manages the flow of messages between various communication channels (Signal, WhatsApp, Facebook, Voice) and the Zammad ticketing system.
Features
- Message Processing: Handle incoming/outgoing messages for all supported channels
- Media Conversion: Convert audio/video files between formats
- Webhook Notifications: Notify external systems of events
- Scheduled Tasks: Cron-based job scheduling
- Job Queue Management: Reliable job processing with retries
- Multi-Channel Support: Signal, WhatsApp, Facebook, Voice (Twilio)
Development
Prerequisites
- Node.js >= 20
- npm >= 10
- PostgreSQL database
- Redis (for caching)
- FFmpeg (for media conversion)
Setup
# Install dependencies
npm install
# Build TypeScript
npm run build
# Run development server with auto-reload
npm run dev
# Start production worker
npm run start
Environment Variables
Required environment variables:
DATABASE_URL- PostgreSQL connection stringGRAPHILE_WORKER_CONCURRENCY- Number of concurrent jobs (default: 10)GRAPHILE_WORKER_POLL_INTERVAL- Job poll interval in ms (default: 1000)ZAMMAD_URL- Zammad instance URLZAMMAD_API_TOKEN- Zammad API tokenTWILIO_ACCOUNT_SID- Twilio account SIDTWILIO_AUTH_TOKEN- Twilio auth tokenSIGNAL_CLI_URL- Signal CLI REST API URLWHATSAPP_SERVICE_URL- WhatsApp bridge service URLFACEBOOK_APP_SECRET- Facebook app secretFACEBOOK_PAGE_ACCESS_TOKEN- Facebook page token
Available Scripts
npm run build- Compile TypeScriptnpm run dev- Development mode with watchnpm run start- Start production worker
Task Types
Signal Tasks
receive-signal-message- Process incoming Signal messagessend-signal-message- Send outgoing Signal messagesfetch-signal-messages- Fetch messages from Signal CLI
WhatsApp Tasks
receive-whatsapp-message- Process incoming WhatsApp messagessend-whatsapp-message- Send outgoing WhatsApp messages
Facebook Tasks
receive-facebook-message- Process incoming Facebook messagessend-facebook-message- Send outgoing Facebook messages
Voice Tasks
receive-voice-message- Process incoming voice calls/messagessend-voice-message- Send voice messages via Twiliotwilio-recording- Handle Twilio call recordingsvoice-line-audio-update- Update voice line audiovoice-line-delete- Delete voice linevoice-line-provider-update- Update voice provider settings
Common Tasks
notify-webhooks- Send webhook notifications
Leafcutter Tasks
import-leafcutter- Import data to Leafcutterimport-label-studio- Import Label Studio annotations
Architecture
Job Processing
Jobs are queued in PostgreSQL using Graphile Worker:
await addJob('send-signal-message', {
to: '+1234567890',
message: 'Hello world'
})
Cron Schedule
Scheduled tasks are configured in crontab:
- Periodic message fetching
- Cleanup tasks
- Health checks
Error Handling
- Automatic retries with exponential backoff
- Dead letter queue for failed jobs
- Comprehensive logging with winston
Media Handling
Supports conversion between formats:
- Audio: MP3, OGG, WAV, M4A
- Uses fluent-ffmpeg for processing
- Automatic format detection
Integration Points
- Zammad: Creates/updates tickets via API
- Signal CLI: REST API for Signal messaging
- WhatsApp Bridge: HTTP API for WhatsApp
- Twilio: Voice and SMS capabilities
- Facebook: Graph API for Messenger
Docker Support
# Build image
docker build -t link-stack/bridge-worker .
# Run with docker-compose
docker-compose -f docker/compose/bridge.yml up
The worker includes cron support via built-in crontab.