Voice Chat Server Package

Server-side handlers for voice call log persistence

Overview

@zooly/voice-chat-srv is a server-side package that provides API handlers for creating and updating voice call logs. It sits between the Next.js API routes and the @zooly/app-db access layer.

Package Details

  • Package Name: @zooly/voice-chat-srv
  • Location: packages/voice-chat/srv
  • Type: Server-side API handler library

Dependencies

  • @zooly/app-db — Database access layer (createVoiceCallLog, updateVoiceCallLogMessages, getAccountByUserId)
  • @zooly/types — Shared types (VoiceCallLog, VoiceCallMessage)
  • @zooly/util — Shared utilities (getVerifiedUserInfo)

Exported Handlers

createVoiceCallLogHandler

async function createVoiceCallLogHandler(
  cookieHeader: string,
  agentId: string
): Promise<VoiceCallLog>
  1. Resolves the user from the cookie via getVerifiedUserInfo(cookieHeader)
  2. Looks up the user's account via getAccountByUserId(userInfo.id)
  3. Creates a voice call log record with accountId and agentId
  4. Returns the full VoiceCallLog record (including generated id)

updateVoiceCallLogHandler

async function updateVoiceCallLogHandler(
  id: string,
  voiceCallMessages: VoiceCallMessage[]
): Promise<void>

Updates the voiceCallMessages JSON array and updatedAt timestamp for the given log ID.

Database Schema

The voice_call_log table is defined in @zooly/app-db:

ColumnTypeDescription
idtext (PK)Auto-generated nanoid
account_idtextNullable reference to the account
agent_idtextElevenLabs agent ID (required)
voice_call_messagesjsonbArray of VoiceCallMessage objects
created_attimestamptzCreation timestamp
updated_attimestamptzLast update timestamp

Access Functions (from @zooly/app-db)

  • createVoiceCallLog(accountId, agentId) — Insert a new log
  • updateVoiceCallLogMessages(id, messages) — Update messages and updatedAt
  • getVoiceCallLog(id) — Fetch a log by ID

API Routes

The consuming app creates thin route handlers that delegate to these handlers. See App Integration for the zooly-app routes.

RouteMethodHandler
/api/voice-call-log/createPOSTcreateVoiceCallLogHandler
/api/voice-call-log/updatePUTupdateVoiceCallLogHandler