Skip to content

The open-source AI receptionist for businesses. Answers every call, books the appointment and hands over to a person when needed. You own the code and the data.

1.1 KB
Raw Blame
// The two writes of the Outbound calls page, sent directly (they start or steer a phone call; nothing to apply
// locally): call.dial and call.guide. A refusal (409 with the server's reason, e.g. a number abroad) comes back as
// the text to show.
import { confirmErrorText } from '../ui/DangerConfirmDialog.tsx'
import { callAction } from '../settings/settings-api.ts'
import { type DialInput, type DialResult, rememberGoal, type SentInstruction } from './model.ts'

/** Starts the call; the goal is kept in this browser for the list (goalOf). Throws with the reason to show. */
export async function dial(input: DialInput): Promise<DialResult> {
  const result = await callAction<DialResult>('call.dial', input)
  rememberGoal(result.room, input.goal)
  return result
}

/** Sends one instruction to a running call; how it went, for the instruction log. */
export async function sendGuide(
  callId: string,
  instruction: string,
): Promise<Pick<SentInstruction, 'state' | 'error'>> {
  try {
    await callAction('call.guide', { callId, instruction })
    return { state: 'sent' }
  } catch (err) {
    return { state: 'failed', error: confirmErrorText(err) }
  }
}