Socket Connection

MeetStream provides real-time two-way WebSocket communication for controlling bots during meetings. This allows you to send messages and audio chunks to bots in real-time.

Overview

When creating a bot, you can specify a socket_connection_url field that accepts a WebSocket URL (wss://). Once the bot joins the meeting, it will establish a WebSocket connection to your server for real-time communication.

Connection Flow

  1. Bot Creation: Include socket_connection_url in your bot creation request
  2. Bot Joins Meeting: Bot connects to your WebSocket server
  3. Ready Event: Bot sends a ready confirmation
  4. Real-time Commands: Send messages and audio chunks to the bot

Connection Events

Ready Event

When the bot successfully connects to your WebSocket server, it sends a ready confirmation:
{
  "type": "ready",
  "bot_id": "your_bot_id",
  "message": "Ready to receive messages"
}
After receiving this message, you can start sending commands to the bot.

Commands

Send Chat Message

Send a text message to be displayed by the bot in the meeting:
{
  "command": "sendmsg",
  "message": "Hello Dropping message from server",
  "bot_id": "your_bot_id"
}

Send Audio Chunks

Send audio data to be played by the bot in the meeting:
{
  "command": "sendaudio",
  "audiochunk": "base64_encoded_audio_data"
}
The audiochunk should be base64-encoded audio data.

Audio Implementation Example

Here’s a Python example showing how to send audio chunks from files:
import os
import base64
import json
import asyncio
from websockets import connect

async def send_audio_chunks(websocket, audio_folder_path, bot_id):
    try:
        # Get all files in the folder
        files = os.listdir(audio_folder_path)
        for file in files:
            with open(os.path.join(audio_folder_path, file), 'rb') as pcm_file:
                while True:
                    chunk = pcm_file.read(64000)
                    if not chunk:  # End of file
                        break
                    base64_audio = base64.b64encode(chunk).decode('utf-8')
                    await websocket.send_text(json.dumps({
                        "command": "sendaudio",
                        "audiochunk": base64_audio
                    }))
                    print(f"[Audio chunk sent] {len(base64_audio)}")
                    print("sending audio")
                print(f"[Audio sent] to {bot_id}")
    except Exception as e:
        print(f"[Audio error] {bot_id}: {e}")

# Usage example
async def main():
    async with connect("wss://your-websocket-server.com") as websocket:
        # Wait for ready event
        ready_event = await websocket.recv()
        ready_data = json.loads(ready_event)
        bot_id = ready_data["bot_id"]
        
        # Send a message
        await websocket.send_text(json.dumps({
            "command": "sendmsg",
            "message": "Hello from server!",
            "bot_id": bot_id
        }))
        
        # Send audio chunks
        await send_audio_chunks(websocket, "/path/to/audio/folder", bot_id)

# Run the example
asyncio.run(main())

Bot Creation with Socket URL

When creating a bot, include the socket_connection_url field:
{
  "meeting_link": "https://zoom.us/j/123456789",
  "audio_required": true,
  "video_required": false,
  "socket_connection_url": "wss://your-websocket-server.com/bot-connection"
}

WebSocket Server Requirements

Your WebSocket server should:
  1. Accept wss:// connections (secure WebSocket)
  2. Handle the ready event from the bot
  3. Process incoming commands (sendmsg, sendaudio)
  4. Send responses back to the bot
  5. Handle connection errors gracefully

Error Handling

  • Connection failures: Bot will retry connection attempts
  • Invalid commands: Bot will ignore malformed JSON or unknown commands
  • Audio format errors: Bot will skip invalid audio chunks
  • Network issues: Bot will attempt to reconnect automatically