cxC5Server
Auto-generated documentation from JSDoc comments
Classes¶
- cxC5Server ⇐
EventEmitter
Functions¶
- get(key) ⇒
Promise.<*> - set(key, value) ⇒
Promise.<void> - header(key, value) ⇒
Promise.<void> - answer() ⇒
Promise.<void> - tts(text, [opts]) ⇒
Promise.<void> - stopMedia() ⇒
Promise.<void> - echo([delay]) ⇒
Promise.<void> - ivr(file, timeout, min, max, [terminators], [opts]) ⇒
Promise.<string> - hangup() ⇒
Promise.<void> - play(file) ⇒
Promise.<void> - bridge(destination, [server], [continue_on], [originate_timeout]) ⇒
Promise.<void> - blockDtmf([digits]) ⇒
Promise.<void> - unblockDtmf([digits]) ⇒
Promise.<void> - record(file, [maxSeconds], [silenceThreshold], [silenceSeconds], [beep], [opts]) ⇒
Promise.<void> - deltaLogPayload(payload) ⇒
Promise.<void> - transcribeStart([opts]) ⇒
Promise.<void> - transcribeStop() ⇒
Promise.<void> - waitFor(match, quit, [timeout], [debounce]) ⇒
Promise.<*> - waitForHangup([ignore]) ⇒
Promise.<void>
cxC5Server ⇐ EventEmitter¶
Class 5 Server for handling real-time call control, media operations, and telephony events. Extends EventEmitter to provide event-driven call handling capabilities.
Events¶
dtmf- Emitted when DTMF digits are receivedplayback_start- Emitted when media playback startsplayback_stop- Emitted when media playback stopschannel_hangup- Emitted when channel hangs upclose- Emitted when connection closesgoogle_transcription- Emitted when Google transcription is receivedend_of_utterance- Emitted at end of speech utteranceno_audio_detected- Emitted when no audio is detectedtranscription- Emitted when transcription data is received
Example¶
import cxC5Server from '@connexcs/cxC5Server';
async function main(data) {
const server = new cxC5Server(data.socketId);
await server.answer();
await server.tts('Hello, welcome to our service');
server.on('dtmf', (digit) => console.log('Pressed:', digit));
}
Kind: global class
Extends: EventEmitter
new cxC5Server()¶
Class 5 Server Control
get(key) ⇒ Promise.<*>¶
Get a session variable value
Kind: global function
Returns: Promise.<*> - The value of the variable
| Param | Type | Description |
|---|---|---|
| key | string |
The variable name to retrieve |
Example
const value = await server.get('caller_id');
set(key, value) ⇒ Promise.<void>¶
Set a session variable value
Kind: global function
| Param | Type | Description |
|---|---|---|
| key | string |
The variable name to set |
| value | * |
The value to assign |
Example
await server.set('custom_var', 'myValue');
header(key, value) ⇒ Promise.<void>¶
Set a SIP header value
Kind: global function
| Param | Type | Description |
|---|---|---|
| key | string |
The header name |
| value | string |
The header value |
Example
await server.header('X-Custom-Header', 'value');
answer() ⇒ Promise.<void>¶
Answer the incoming call
Kind: global function
Example
await server.answer();
tts(text, [opts]) ⇒ Promise.<void>¶
Play text-to-speech audio to the caller
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| text | string |
The text to convert to speech | |
| [opts] | object |
{} |
TTS options |
| [opts.voice] | string |
Voice to use for TTS | |
| [opts.language] | string |
Language code for TTS |
Example
await server.tts('Hello, how can I help you?', { voice: 'en-US-Wavenet-D' });
stopMedia() ⇒ Promise.<void>¶
Stop any currently playing media
Kind: global function
Example
await server.stopMedia();
echo([delay]) ⇒ Promise.<void>¶
Enable echo mode for the call (plays back caller's audio)
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| [delay] | number |
0 |
Delay in milliseconds before echoing |
Example
await server.echo(500); // Echo with 500ms delay
ivr(file, timeout, min, max, [terminators], [opts]) ⇒ Promise.<string>¶
Play an IVR menu and collect DTMF input
Kind: global function
Returns: Promise.<string> - The collected DTMF digits
| Param | Type | Default | Description |
|---|---|---|---|
| file | string |
Audio file to play | |
| timeout | number |
Timeout in seconds to wait for input | |
| min | number |
Minimum number of digits to collect | |
| max | number |
Maximum number of digits to collect | |
| [terminators] | string |
"'#'" |
Characters that terminate input collection |
| [opts] | object |
{} |
Additional IVR options |
Example
const digits = await server.ivr('menu.wav', 10, 1, 4, '#');
hangup() ⇒ Promise.<void>¶
Hang up the call
Kind: global function
Example
await server.hangup();
play(file) ⇒ Promise.<void>¶
Play an audio file to the caller
Kind: global function
| Param | Type | Description |
|---|---|---|
| file | string |
Path or URL to the audio file |
Example
await server.play('welcome.wav');
bridge(destination, [server], [continue_on], [originate_timeout]) ⇒ Promise.<void>¶
Bridge the call to another destination
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| destination | string |
The destination to bridge to | |
| [server] | string | boolean |
false |
Server to use for bridging |
| [continue_on] | boolean |
false |
Continue script execution after bridge ends |
| [originate_timeout] | number |
30 |
Timeout in seconds for the outbound leg |
Example
await server.bridge('sip:[email protected]', false, true, 60);
blockDtmf([digits]) ⇒ Promise.<void>¶
Block specific DTMF digits from being processed
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| [digits] | string |
"'0123456789'" |
DTMF digits to block |
Example
await server.blockDtmf('*#'); // Block only * and #
unblockDtmf([digits]) ⇒ Promise.<void>¶
Unblock specific DTMF digits
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| [digits] | string |
"'0123456789'" |
DTMF digits to unblock |
Example
await server.unblockDtmf('*#');
record(file, [maxSeconds], [silenceThreshold], [silenceSeconds], [beep], [opts]) ⇒ Promise.<void>¶
Record audio from the call
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| file | string |
Filename to save the recording | |
| [maxSeconds] | number |
3600 |
Maximum recording duration in seconds |
| [silenceThreshold] | number |
30 |
Silence threshold level |
| [silenceSeconds] | number |
5 |
Seconds of silence before stopping |
| [beep] | boolean |
true |
Play a beep before recording starts |
| [opts] | object |
{} |
Additional recording options |
Example
await server.record('message.wav', 60, 30, 3, true);
deltaLogPayload(payload) ⇒ Promise.<void>¶
Add additional payload data to the call log
Kind: global function
| Param | Type | Description |
|---|---|---|
| payload | object |
Data to append to the call log |
Example
await server.deltaLogPayload({ customField: 'value' });
transcribeStart([opts]) ⇒ Promise.<void>¶
Start real-time speech transcription
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| [opts] | object |
{} |
Transcription options |
| [opts.language] | string |
Language code for transcription | |
| [opts.model] | string |
Transcription model to use |
Example
await server.transcribeStart({ language: 'en-US' });
server.on('transcription', (data) => console.log(data.text));
transcribeStop() ⇒ Promise.<void>¶
Stop real-time speech transcription
Kind: global function
Example
await server.transcribeStop();
waitFor(match, quit, [timeout], [debounce]) ⇒ Promise.<*>¶
Wait for a specific event or condition
Kind: global function
Returns: Promise.<*> - The matched event data
| Param | Type | Default | Description |
|---|---|---|---|
| match | string | RegExp |
Pattern to match against incoming events | |
| quit | string | RegExp |
Pattern that triggers exit from waiting | |
| [timeout] | number |
60 |
Timeout in seconds |
| [debounce] | number |
0 |
Debounce time in milliseconds |
Example
const result = await server.waitFor(/^[0-9]$/, '#', 30);
waitForHangup([ignore]) ⇒ Promise.<void>¶
Wait for the call to hang up
Kind: global function
Returns: Promise.<void> - Resolves when the call hangs up
| Param | Type | Default | Description |
|---|---|---|---|
| [ignore] | string |
"'outbound'" |
Direction to ignore ('outbound' or 'inbound') |
Example
await server.waitForHangup();
console.log('Call ended');