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
// call.dial's `retry` (LIN-873): the delays between the tries are checked strictly at the boundary.
import { describe, expect, test } from 'vitest'
import { callDial } from './calls.ts'
import { parseRetryDelay, RETRY_PRESETS, retryDelayMinutes } from './outbound-retry.ts'
const dial = { to: '+15035550186', goal: 'Ask if Monday at 8 AM still works.', first_sentence: 'Hello.' }
describe('retry delays', () => {
test('a number and m, h or d', () => {
expect(parseRetryDelay('10m')).toEqual({ amount: 10, unit: 'm' })
expect(parseRetryDelay('1h')).toEqual({ amount: 1, unit: 'h' })
expect(parseRetryDelay('1d')).toEqual({ amount: 1, unit: 'd' })
expect(retryDelayMinutes(parseRetryDelay('2h')!)).toBe(120)
for (const bad of ['', '10', 'm', '10 m', '10M', '1.5h', '-5m', '05m', '1w', '10min', ' 10m', '1h30m'])
expect(parseRetryDelay(bad), bad).toBeNull()
})
test('from 5 minutes to 7 days', () => {
expect(parseRetryDelay('5m')).not.toBeNull()
expect(parseRetryDelay('4m')).toBeNull()
expect(parseRetryDelay('7d')).not.toBeNull()
expect(parseRetryDelay('168h')).not.toBeNull()
expect(parseRetryDelay('8d')).toBeNull()
expect(parseRetryDelay('169h')).toBeNull()
expect(parseRetryDelay('10081m')).toBeNull()
})
test('call.dial takes at most 5, all valid; no retry is the same as none', () => {
expect(callDial.input.safeParse({ ...dial, retry: ['10m', '1h', '1d'] }).success).toBe(true)
expect(callDial.input.safeParse({ ...dial, retry: [] }).success).toBe(true)
expect(callDial.input.safeParse(dial).success).toBe(true)
expect(callDial.input.safeParse({ ...dial, retry: ['10m', '20m', '30m', '1h', '2h'] }).success).toBe(true)
expect(callDial.input.safeParse({ ...dial, retry: ['10m', '20m', '30m', '1h', '2h', '3h'] }).success).toBe(false)
expect(callDial.input.safeParse({ ...dial, retry: ['10m', '1 hour'] }).success).toBe(false)
expect(callDial.input.safeParse({ ...dial, retry: ['1m'] }).success).toBe(false)
expect(callDial.input.safeParse({ ...dial, retry: '10m' }).success).toBe(false)
})
test('the presets of New call are valid delays', () => {
for (const delays of Object.values(RETRY_PRESETS))
for (const d of delays) expect(parseRetryDelay(d), d).not.toBeNull()
})
})