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.
TypeScript ai-receptionistanswering-serviceappointment-bookinglivekitlocal-firstmcpopen-sourceself-hostedsiptelephonytypescriptvoice-agentvoice-ai
// The checks of the app's sign-in hand-back (app-sign-in.ts) that need no database, so they can be tested alone.
import { createHash } from 'node:crypto'
/** SHA-256 in base64url: how a code is stored and how a challenge is made from its verifier (PKCE S256). */
export const sha256 = (value: string) => createHash('sha256').update(value).digest('base64url')
/** Whether a verifier belongs to the challenge the sign-in started with. */
export const verifierFits = (verifier: string, challenge: string) => sha256(verifier) === challenge
/** From the start to the confirmed sign-in: enough for a slow provider page (2FA). */
export const START_TTL_S = 15 * 60
/** What `/app-sign-in/start` keeps in the browser's signed cookie: the app's challenge and when (ms). */
export type Start = { challenge: string; at: number }
/**
* Whether the browser's session may be handed to the app: made by a sign-in after the start (the provider callback
* comes after it), within the start's lifetime. A session the browser had before never may.
*/
export function sessionFitsStart(sessionCreatedAt: Date, start: Start, now = Date.now()): boolean {
const created = sessionCreatedAt.getTime()
return created >= start.at && created <= now && now - start.at <= START_TTL_S * 1000
}