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.

3.7 KB
Raw Blame
// The native plugins the web app calls inside the Linedesk app. Only their interfaces are here (Capacitor's
// registerPlugin finds the native side by name); the plugins themselves are installed in apps/mobile, so the web
// bundle carries none of their code.
import { registerPlugin } from '@capacitor/core'

type Listener = { remove: () => Promise<void> }

/** Our own plugin (apps/mobile: LinedeskAuthPlugin.swift, LinedeskAuthPlugin.java). */
export interface LinedeskAuthPlugin {
  /**
   * Opens `url` (on the app's own server) in the system's sign-in browser (iOS ASWebAuthenticationSession, Android
   * Custom Tabs) and resolves with the address it ends on: the server's own https address at `callbackPath`, which
   * only this app receives (universal link, verified app link). Rejects with `cancelled` when the person closes it.
   */
  start(options: { url: string; callbackPath: string }): Promise<{ url: string }>
}
export const LinedeskAuth = registerPlugin<LinedeskAuthPlugin>('LinedeskAuth')

/** @capacitor/app */
export interface AppPlugin {
  addListener(event: 'backButton', fn: (e: { canGoBack: boolean }) => void): Promise<Listener>
  addListener(event: 'appUrlOpen', fn: (e: { url: string }) => void): Promise<Listener>
  addListener(event: 'resume', fn: () => void): Promise<Listener>
  exitApp(): Promise<void>
  minimizeApp(): Promise<void>
}
export const App = registerPlugin<AppPlugin>('App')

/** @capacitor/browser: links to other sites open in the system's in-app browser. */
export interface BrowserPlugin {
  open(options: { url: string; presentationStyle?: 'fullscreen' | 'popover' }): Promise<void>
}
export const Browser = registerPlugin<BrowserPlugin>('Browser')

/** @capacitor/status-bar */
export interface StatusBarPlugin {
  setStyle(options: { style: 'DARK' | 'LIGHT' | 'DEFAULT' }): Promise<void>
  setBackgroundColor(options: { color: string }): Promise<void>
  setOverlaysWebView(options: { overlay: boolean }): Promise<void>
}
export const StatusBar = registerPlugin<StatusBarPlugin>('StatusBar')

/** @capacitor/splash-screen */
export interface SplashScreenPlugin {
  hide(options?: { fadeOutDuration?: number }): Promise<void>
}
export const SplashScreen = registerPlugin<SplashScreenPlugin>('SplashScreen')

/** @capacitor/haptics */
export interface HapticsPlugin {
  impact(options: { style: 'HEAVY' | 'MEDIUM' | 'LIGHT' }): Promise<void>
  notification(options: { type: 'SUCCESS' | 'WARNING' | 'ERROR' }): Promise<void>
  selectionChanged(): Promise<void>
}
export const Haptics = registerPlugin<HapticsPlugin>('Haptics')

/** @capacitor/keyboard */
export interface KeyboardPlugin {
  setAccessoryBarVisible(options: { isVisible: boolean }): Promise<void>
  addListener(
    event: 'keyboardWillShow' | 'keyboardWillHide',
    fn: (e: { keyboardHeight?: number }) => void,
  ): Promise<Listener>
}
export const Keyboard = registerPlugin<KeyboardPlugin>('Keyboard')

/** @capacitor/push-notifications */
export interface PushNotificationsPlugin {
  checkPermissions(): Promise<{ receive: string }>
  requestPermissions(): Promise<{ receive: string }>
  register(): Promise<void>
  unregister(): Promise<void>
  createChannel(channel: { id: string; name: string; importance?: number; visibility?: number }): Promise<void>
  deleteChannel(channel: { id: string }): Promise<void>
  addListener(event: 'registration', fn: (token: { value: string }) => void): Promise<Listener>
  addListener(event: 'registrationError', fn: (e: { error: string }) => void): Promise<Listener>
  addListener(
    event: 'pushNotificationActionPerformed',
    fn: (action: { notification: { data?: unknown } }) => void,
  ): Promise<Listener>
  removeAllListeners(): Promise<void>
}
export const PushNotifications = registerPlugin<PushNotificationsPlugin>('PushNotifications')