# Tavus-Zoom RTMS Bridge

A server-side bridge that connects Tavus AI agents to Zoom meetings using Zoom's RTMS (Realtime Media Streams) SDK.

## 🚀 Quick Start

### Prerequisites

1. **Node.js 18+** installed
2. **Zoom App** configured in Zoom Marketplace
3. **Tavus API** credentials
4. **RTMS SDK** access (contact Zoom for C SDK files)

### Installation

1. **Install dependencies:**
   ```bash
   cd tavus-zoom-bridge
   pnpm install
   ```

2. **Configure environment variables:**
   ```bash
   # Copy from parent .env.example and add your credentials
   cp ../.env.example .env
   ```

3. **Add your credentials to `.env`:**
   ```bash
   # Tavus API Configuration
   TAVUS_API_KEY="your_tavus_api_key_here"
   TAVUS_API_KEY_NO_CREDITS="your_tavus_test_api_key_here"
   TAVUS_REPLICA_ID="your_replica_id"
   TAVUS_PERSONA_ID="your_persona_id"

   # Zoom SDK Configuration
   ZOOM_SDK_KEY="MUqY_o3_theid"
   ZOOM_SDK_SECRET="WgU8oZW5theSecret"

   # Bridge Configuration
   BRIDGE_PORT="3001"
   BRIDGE_NODE_ENV="development"
   ```

### Running the Demo

1. **Start the bridge server:**
   ```bash
   pnpm run dev
   ```

2. **Join a real Zoom meeting:**
   ```bash
   # Using command line arguments
   pnpm run working-demo -- --meeting-id=123456789 --password=abc123 --name="Tavus AI Assistant"
   
   # Or using environment variables (add to .env)
   ZOOM_MEETING_ID="123456789"
   ZOOM_MEETING_PASSWORD="abc123"
   ZOOM_PARTICIPANT_NAME="BuzzTrail AI Assistant"
   pnpm run working-demo
   ```

3. **For testing without consuming credits:**
   ```bash
   pnpm run demo:test -- --meeting-uuid=abc123 --rtms-stream-id=xyz789
   ```

4. **Using the API endpoint:**
   ```bash
   curl -X POST http://localhost:3001/api/bridge/start \
     -H "Content-Type: application/json" \
     -d '{
       "meetingUuid": "123456789",
       "rtmsStreamId": "stream-123456789",
       "meetingPassword": "abc123",
       "participantName": "BuzzTrail AI Assistant",
       "options": {
         "replicaId": "rf4703150052",
         "personaId": "p48fdf065d6b"
       }
     }'
   ```

## 📁 Project Structure

```
tavus-zoom-bridge/
├── src/
│   ├── index.ts              # Express server with API endpoints
│   ├── rtms-bridge.ts        # Main bridge coordination
│   ├── rtms-manager.ts       # Zoom RTMS SDK integration
│   └── tavus-bridge-manager.ts # Tavus API integration
├── scripts/
│   ├── demo.ts               # Demo execution script
│   └── generate-jwt.ts       # JWT token generation
├── jwt-auth-server/
│   └── index.js              # JWT authentication server
├── package.json
├── tsconfig.json
└── README.md
```

## 🔧 API Endpoints

### Bridge Server (Port 3001)

- `GET /health` - Health check
- `POST /api/bridge/start` - Start bridge
- `POST /api/bridge/stop` - Stop bridge
- `GET /api/bridge/status` - Get bridge status
- `GET /api/bridge/config` - Get configuration

### JWT Auth Server (Port 4000)

- `GET /health` - Health check
- `POST /generate-jwt` - Generate JWT token

## 🎯 Usage Examples

### Start Bridge via API

```bash
curl -X POST http://localhost:3001/api/bridge/start \
  -H "Content-Type: application/json" \
  -d '{
    "meetingUuid": "abc123",
    "rtmsStreamId": "xyz789",
    "options": {
      "useTestKey": true
    }
  }'
```

### Check Bridge Status

```bash
curl http://localhost:3001/api/bridge/status
```

### Generate JWT Token

```bash
curl -X POST http://localhost:4000/generate-jwt
```

## 🔍 Troubleshooting

### Common Issues

1. **"Missing Zoom SDK credentials"**
   - Ensure `ZOOM_SDK_KEY` and `ZOOM_SDK_SECRET` are set in `.env`

2. **"Tavus API key not configured"**
   - Add your Tavus API key to `TAVUS_API_KEY` in `.env`

3. **"RTMS connection failed"**
   - Verify you have RTMS SDK access from Zoom
   - Check that meeting UUID and RTMS stream ID are correct

4. **"MediaStreamTrackProcessor not available"**
   - This is expected in Node.js environment
   - The bridge will use fallback media handling

### Debug Mode

Run with debug logging:
```bash
DEBUG=* npm run dev
```

## 🔐 Security Notes

- JWT tokens expire after 1 hour
- Keep API keys secure and never commit them to version control
- Use test API keys for development to avoid consuming credits

## 📚 Documentation

- [Zoom RTMS SDK Documentation](https://github.com/zoom/rtms)
- [Tavus API Documentation](https://docs.tavus.io/api-reference/overview)
- [Bridge Architecture](../documentation/join-google-meet.md)

## 🤝 Contributing

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests if applicable
5. Submit a pull request

## 📄 License

MIT License - see LICENSE file for details
