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.5 KB
Raw Blame
// The call quality levels as the assistant editor shows them (voice.options `callQuality`,
// packages/actions/src/usage-level.ts): their names and, where there are prices, the price a minute.
import { CALL_QUALITY_LABELS, type CallQuality, type CallQualityLevelOption } from '@linedesk/actions'
import { i18n } from '../i18n/index.tsx'
import { isNativeApp } from '../native/mobile/platform.ts'

/** The value of the "Default" option (the server's model for the level). */
export const DEFAULT_CHOICE = ''

/** A price a minute, given in cents as the prices are decided, shown in dollars ("$0.10"), never with the cent sign. */
export const pricePerMinute = (cents: number) => i18n().format.rate(cents / 100, 'USD')

/** A level's name: a product name, the same in every language. */
export const levelName = (level: CallQuality) => CALL_QUALITY_LABELS[level]

/**
 * A level's price per minute as the page may show it: none in the store apps (no prices or buying there: a higher
 * level costs more from the balance, which is bought on the web).
 */
export const shownCentsPerMinute = (cents: number | null | undefined) => (isNativeApp() ? null : (cents ?? null))

/** "$0.10 a minute", or nothing where there are no prices (a partner's client, no bill, self-hosted, the apps). */
export const levelPrice = (option: Pick<CallQualityLevelOption, 'centsPerMinute'>) =>
  shownCentsPerMinute(option.centsPerMinute) === null
    ? undefined
    : i18n().t('settings.voice.quality.perMinute', { price: pricePerMinute(option.centsPerMinute!) })