Skip to content

Bridge API

The Bridge API is the central orchestration layer connecting EspoCRM to all external services.

Overview

Directory Structure

bridge/
├── server.js              # Express app entry point
├── package.json           # Dependencies
├── Dockerfile             # Container definition

├── config/
│   └── platforms.js       # Platform configuration

├── helpers/
│   ├── ayrshare/          # Social media integration
│   │   ├── analytics.js   # Fetch analytics
│   │   ├── comments.js    # Comment management
│   │   ├── history.js     # Post history
│   │   ├── schedule.js    # Schedule posts
│   │   └── sync.js        # Sync state
│   │
│   ├── boxcast/           # Boxcast integration
│   │   └── sync.js        # Sync broadcasts
│   │
│   ├── bunny/             # CDN integration
│   │   ├── storage.js     # Storage operations
│   │   └── upload.js      # Upload handling
│   │
│   ├── captions/          # Caption generation
│   │   ├── burnCaptions.js
│   │   ├── captionPipeline.js
│   │   └── generateASS.js
│   │
│   ├── claude/            # AI analysis
│   │   ├── analyze-clips.js
│   │   ├── prompts.js
│   │   └── transcript-analysis.js
│   │
│   ├── cron/              # Scheduled jobs
│   │   └── collectAnalytics.js
│   │
│   ├── deepgram/          # Transcription
│   │   └── transcribe.js
│   │
│   ├── assemblyai/        # Transcription (alt)
│   │   └── transcribe.js
│   │
│   ├── espocrm/           # CRM integration
│   │   └── client.js      # API client
│   │
│   ├── ffmpeg/            # Video processing
│   │   ├── compile.js
│   │   ├── extract.js
│   │   ├── filmstrip.js
│   │   └── waveform.js
│   │
│   ├── n8n/               # Workflow automation
│   │   └── triggerWorkflow.js
│   │
│   ├── postgres/          # Analytics database
│   │   ├── client.js      # Connection pool
│   │   └── queries.js     # Query functions
│   │
│   ├── stockmedia/        # Stock media APIs
│   │   ├── runway.js
│   │   ├── shutterstock.js
│   │   └── storyblocks.js
│   │
│   └── xserver/           # Platform automation
│       └── client.js      # X server client

└── routes/
    ├── index.js           # Route registration
    ├── analytics.js       # Analytics endpoints
    ├── ayrshare.js        # Ayrshare proxy
    ├── boxcast.js         # Boxcast operations
    ├── broll.js           # B-roll management
    ├── cdn.js             # CDN operations
    ├── clips.js           # Clip management
    ├── comments.js        # Comment handling
    ├── webhooks.js        # EspoCRM webhooks
    └── xserver.js         # X server proxy

API Endpoints

Health Check

http
GET /health

Response:

json
{
  "ok": true,
  "service": "mediamagic-bridge",
  "timestamp": "2026-02-05T12:00:00.000Z"
}

Webhooks

Receives events from EspoCRM entity changes:

EndpointTrigger Event
POST /webhooks/guest-createdGuestBooking created
POST /webhooks/guest-updatedGuestBooking updated
POST /webhooks/content-createdContentProduction created
POST /webhooks/content-updatedContentProduction updated
POST /webhooks/platform-createdPlatformPublish created
POST /webhooks/platform-updatedPlatformPublish updated
POST /webhooks/clip-createdClip created
POST /webhooks/clip-updatedClip updated
POST /webhooks/social-createdSocialPost created
POST /webhooks/social-updatedSocialPost updated
POST /webhooks/social-deletedSocialPost deleted

Ayrshare Proxy

MethodEndpointDescription
POST/ayrshare/scheduleSchedule a social post
POST/ayrshare/deleteDelete a scheduled post
GET/ayrshare/historyGet post history
GET/ayrshare/analyticsGet post analytics

Analytics

MethodEndpointDescription
GET/analytics/social-metricsQuery social metrics
GET/analytics/followersGet follower trends
GET/analytics/top-postsGet top performing posts
POST/analytics/collectTrigger analytics collection
POST/analytics/content-ingestIngest content metrics
GET/analytics/content-metricsQuery content metrics

Boxcast

MethodEndpointDescription
POST/boxcast/create-broadcastCreate a broadcast
POST/boxcast/delete-broadcastDelete a broadcast

X Server Proxy

MethodEndpointDescription
POST/x/publishForward to x server
POST/x/ayrshare-createCreate via x server
POST/x/ayrshare-deleteDelete via x server
GET/x/statusCheck x server status

Platform Routes Configuration

Located in routes/webhooks.js:

javascript
const PLATFORM_ROUTES = {
  'Rumble': { 
    livestream: '/rumble-create', 
    upload: '/rumble-episode' 
  },
  'YouTube': { 
    livestream: '/youtube-create', 
    upload: null 
  },
  'Boxcast': { 
    livestream: '/boxcast-livestream', 
    upload: '/boxcast-media-upload' 
  },
  'Brighteon': { 
    livestream: '/brighteon-create', 
    upload: '/brighteon-upload' 
  },
  'Odysee': { 
    livestream: '/odysee-create', 
    upload: '/odysee-upload' 
  },
  // ... more platforms
};

Cron Jobs

Analytics Collection

Runs every 6 hours to collect metrics from Ayrshare:

Environment Variables

The Bridge requires these environment variables:

env
# EspoCRM
ESPOCRM_SITE_URL=http://espocrm
ESPOCRM_API_KEY=your_api_key

# PostgreSQL
POSTGRES_HOST=postgres
POSTGRES_PASSWORD=your_password

# External Services
AYRSHARE_API_KEY=your_ayrshare_key
X_SERVER_URL=http://your-x-server:3001
N8N_WEBHOOK_BASE=https://your-n8n.com

# AI & Media
ANTHROPIC_API_KEY=your_claude_key
DEEPGRAM_API_KEY=your_deepgram_key
BUNNY_STORAGE_API_KEY=your_bunny_key

Error Handling

The Bridge handles errors gracefully and updates EspoCRM with error details:

javascript
try {
  const result = await xServerClient.publish(payload);
  await espoClient.update('PlatformPublish', id, {
    status: 'Published',
    platformUrl: result.url,
    platformId: result.id
  });
} catch (error) {
  await espoClient.update('PlatformPublish', id, {
    status: 'Failed',
    apiResponse: JSON.stringify(error.message)
  });
}

Extending the Bridge

Adding a New Route

  1. Create route file in routes/:
javascript
// routes/myfeature.js
import express from 'express';
const router = express.Router();

router.post('/action', async (req, res) => {
  // Implementation
});

export default router;
  1. Register in routes/index.js:
javascript
import myfeature from './myfeature.js';
router.use('/myfeature', myfeature);

Adding a New Helper

  1. Create helper in helpers/myservice/:
javascript
// helpers/myservice/client.js
export async function doSomething(params) {
  // Implementation
}
  1. Import and use in routes:
javascript
import { doSomething } from '../helpers/myservice/client.js';

Next Steps

MediaMagic CRM Documentation