Skip to content

Kody is live

Watch the launch video — what Kody is, and why it exists.

← Public packages

@kody/blandPublic

src/stop-call.ts

35 lines · 985 B · TypeScript
/**
 * Stop an in-progress Bland call (`POST /v1/calls/{call_id}/stop`).
 * Dry-run by default — pass `confirm: true` to hang up live.
 *
 * @param input - call_id and confirm
 * @returns Stop response or dry-run preview
 *
 * @example
 * import { stopCall } from 'kody:@kody/bland/stop-call'
 * await stopCall({ call_id: '9d404c1b-…', confirm: true })
 */
import { blandRequest, type BlandAuthInput } from './core.ts'

export type StopCallInput = BlandAuthInput & {
	call_id?: string
	callId?: string
	dryRun?: boolean
	confirm?: boolean
}

export async function stopCall(input: StopCallInput = {}) {
	const callId = String(input.call_id ?? input.callId ?? '').trim()
	if (!callId && input.confirm === true && input.dryRun !== true) {
		throw new Error('call_id is required to stop a call.')
	}
	const id = callId || 'call_id'
	return blandRequest({
		...input,
		method: 'POST',
		path: '/v1/calls/' + encodeURIComponent(id) + '/stop',
		body: {},
	})
}

export default stopCall