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.

2.0 KB
Raw Blame
// What the web app and this shell say to each other (the preload's `window.linedeskDesktop`, the IPC channels). The
// web app's side of it: apps/web/src/native/desktop/bridge.ts.

export const CHANNEL = {
  signIn: 'linedesk:sign-in',
  notify: 'linedesk:notify',
  labels: 'linedesk:labels',
  badge: 'linedesk:badge',
  /** Main to page: open this call (a notification was clicked). */
  openCall: 'linedesk:open-call',
  getOpenAtLogin: 'linedesk:get-open-at-login',
  setOpenAtLogin: 'linedesk:set-open-at-login',
} as const

/** A notification about a call; one per call (`id`): a newer one replaces it. */
export type CallNotice = { id: string; title: string; body: string; urgent: boolean }

/**
 * The words of the menus and the tray in the person's language, from the web app (its i18n), so this shell carries
 * none of its own. Until they come, the system's own words (menu roles) and the app's name stand in.
 */
export type Labels = {
  open: string
  settings: string
  quit: string
  back: string
  forward: string
  reload: string
  file: string
  edit: string
  view: string
  window: string
  help: string
  docs: string
  /** macOS, first start outside Applications (install.ts). */
  moveTitle: string
  moveText: string
  moveButton: string
  notNow: string
}

const LABEL_KEYS = [
  'open',
  'settings',
  'quit',
  'back',
  'forward',
  'reload',
  'file',
  'edit',
  'view',
  'window',
  'help',
  'docs',
  'moveTitle',
  'moveText',
  'moveButton',
  'notNow',
] as const

export const isCallNotice = (v: unknown): v is CallNotice => {
  const n = v as CallNotice
  return (
    !!n &&
    typeof n.id === 'string' &&
    n.id.length <= 100 &&
    typeof n.title === 'string' &&
    n.title.length <= 300 &&
    typeof n.body === 'string' &&
    n.body.length <= 1000 &&
    typeof n.urgent === 'boolean'
  )
}

export const isLabels = (v: unknown): v is Labels =>
  !!v &&
  typeof v === 'object' &&
  Object.values(v as object).every(s => typeof s === 'string' && s.length <= 300) &&
  LABEL_KEYS.every(k => k in (v as object))