Calls helpers
mv.calls.waitUntilEnded() waits until a call reaches a final status and returns it. With waitForAnalysisMs it also waits for the summary and the outcome, which arrive a few seconds after the call. It follows the call’s event stream when the API offers one and polls GET /v1/calls/{id} otherwise; it throws a WaitTimeoutError after timeoutMs.
In production, prefer the call.ended and call.analyzed webhooks: waiting suits scripts, tests and test mode.
// Place a test call and wait for it to end, then for its summary. A test key (mv_test_sk_…) never dials:// +972500000001 answers on the virtual carrier and talks to your assistant.import MoreVoice from "@morevoice/sdk";
const mv = new MoreVoice(); // reads MOREVOICE_API_KEY
const call = await mv.calls.create({ to: "+972500000001", assistant_id: process.env.ASSISTANT_ID!, purpose: "service" });const ended = await mv.calls.waitUntilEnded(call.id, { timeoutMs: 5 * 60_000, waitForAnalysisMs: 30_000, // the summary and outcome arrive a few seconds after the call onUpdate: (c) => console.log(c.status),});console.log(ended.end_reason, ended.duration_ms, ended.summary?.outcome);Exported from @morevoice/sdk (source: packages/sdk-ts/src/lib/calls.ts).
CallLike
Section titled “CallLike”The call fields the helper reads. The facade returns the full generated Call type.
interface CallLike { id: string; status?: string | null; ended_at?: string | null; summary?: unknown; [field: string]: unknown;}FINAL_CALL_STATUSES
Section titled “FINAL_CALL_STATUSES”Statuses after which a call never changes again (besides its post-call analysis).
const FINAL_CALL_STATUSES: readonly string[];isCallEnded()
Section titled “isCallEnded()”True when the call is over: a final status, or an ended_at.
function isCallEnded(call: CallLike): boolean;WaitUntilEndedOptions
Section titled “WaitUntilEndedOptions”interface WaitUntilEndedOptions { /** Give up after this long (default 10 minutes), with a WaitTimeoutError. */ timeoutMs?: number; /** Stops waiting; the promise rejects with the signal's reason. */ signal?: AbortSignal; /** After the call ends, wait up to this long for its summary (`call.analyzed`). Default 0: resolve at once. */ waitForAnalysisMs?: number; /** First polling interval (default 1000 ms); it grows ×1.5 per poll up to `maxPollIntervalMs`. */ pollIntervalMs?: number; /** Longest polling interval (default 10 000 ms). */ maxPollIntervalMs?: number; /** Called with every state the helper sees (each poll, and the final one). */ onUpdate?: (call: CallLike) => void;}CallStreamEventLike
Section titled “CallStreamEventLike”A stream event the helper reacts to (the C9 envelope; only type is read).
interface CallStreamEventLike { type?: string;}WaitDeps
Section titled “WaitDeps”What waitUntilEnded needs from the client.
interface WaitDeps<C extends CallLike> { /** GET /v1/calls/{id}. */ retrieve(callId: string, options: { signal: AbortSignal }): Promise<C>; /** The call's event stream, when the API offers one; it should end after `call.ended`. */ stream?: (callId: string, options: { signal: AbortSignal; types: string[] }) => AsyncIterable<CallStreamEventLike>;}DEFAULT_WAIT_TIMEOUT_MS
Section titled “DEFAULT_WAIT_TIMEOUT_MS”const DEFAULT_WAIT_TIMEOUT_MS = 600_000;waitUntilEnded()
Section titled “waitUntilEnded()”Wait for a call to end. See the file header.
function waitUntilEnded<C extends CallLike>(deps: WaitDeps<C>, callId: string, options: WaitUntilEndedOptions = {}): Promise<C>;