This is a Deno TypeScript SDK for Call Control, providing an easy way to interact with the Call Control API. The SDK includes methods to manage calls, perform actions like dialing, answering, and hanging up, as well as working with DTMF tones, real-time transcription, and media streaming.
To use this SDK, you'll need to import the CallControl
class into your project
and instantiate it with your baseUrl
and bearerToken
.
import { CallControl, DialResponse } from "https://deno.land/x/[email protected]/mod.ts";
const cc = new CallControl({
baseUrl: "https://your-api-url.com",
bearerToken : "your-bearer-token"
});
After initializing the CallControl
class, you can call its methods to interact
with the Call Control API. For example, to dial a number:
try {
const call = await cc.dial({
to: "+10409992842",
from: "+12994882747",
connection_id: "2299939939jfjj93",
});
} catch (err) {
console.log(err.message);
}
The following methods are available in the CallControl class:
Dials a number or SIP URI from a given connection. Returns a DialResponse
with
a call_leg_id
that can be used to correlate the command with subsequent
webhooks.
Answers an incoming call. The Answer command must be issued before executing
subsequent commands on an incoming call. Returns a CommandResponse
.
Bridges two call control calls. Returns a CommandResponse
.
Puts the call in a queue. Returns a CommandResponse
.
Starts forking the media from a call to a specific target in realtime. This
stream can be used to enable real-time audio analysis for a variety of use
cases, such as fraud detection or AI-generated audio responses. Returns a
CommandResponse
.
Stops forking a call. Returns a CommandResponse
.
Gathers DTMF signals to build interactive menus. The Answer command must be
issued before the gather
command. Returns a CommandResponse
.
Stops the current gather. Returns a CommandResponse
.
Plays an audio file on the call until the required DTMF signals are gathered to
build interactive menus. The Answer command must be issued before the
gatherUsingAudio
command. Returns a CommandResponse
.
Converts text to speech and plays it back on the call to gather DTMF signals.
The Answer command must be issued before the gatherUsingSpeak
command. Returns
a CommandResponse
.
Hangs up the call. Returns a CommandResponse
.
Removes the call from a queue. Returns a CommandResponse
.
Plays an audio file on the call. If multiple play audio commands are issued
consecutively, the audio files will be placed in a queue awaiting playback.
Returns a CommandResponse
.
Stops audio being played on the call. Returns a CommandResponse
.
Pauses recording the call. Recording can be resumed via the Resume recording
command. Returns a CommandResponse
.
Resumes recording the call. Returns a CommandResponse
.
Starts recording the call. Recording will stop on call hang-up or can be
initiated via the Stop Recording command. Returns a CommandResponse
.
Stops recording the call. Returns a CommandResponse
.
Initiates a SIP Refer on a Call Control call. Returns a CommandResponse
.
Rejects an incoming call. Returns a CommandResponse
.
Sends DTMF tones from this leg. DTMF tones will be heard by the other end of the
call. Returns a CommandResponse
.
Converts text to speech and plays it back on the call. If multiple speak text
commands are issued consecutively, the audio files will be placed in a queue
awaiting playback. Returns a CommandResponse
.
Starts streaming the media from a call to a specific WebSocket address in
near-realtime. Audio will be delivered as base64-encoded RTP payload (raw
audio), wrapped in JSON payloads. Returns a CommandResponse
.
Stops streaming a call to a WebSocket. Returns a CommandResponse
.
25. startTranscription(callControlId: string, startTranscriptionRequest?: StartTranscriptionRequest)
Starts real-time transcription. Transcription will stop on call hang-up or can
be initiated via the Transcription stop command. Returns a CommandResponse
.
Stops real-time transcription. Returns a CommandResponse
.
Transfers a call to a new destination. If the transfer is unsuccessful, a
call.hangup
webhook for the other call (Leg B) will be sent indicating that
the transfer could not be completed. The original call will remain active and
may be issued additional commands, potentially transferring the call to an
alternate destination. Returns a CommandResponse
.
Updates client state. Returns a CommandResponse
.
For each method, refer to the SDK's types.ts
for more details on the required
parameters and expected responses.