Zum Hauptinhalt springen

Vodia PBX JavaScript IVR Functions Reference

Call Object Functions

FunctionDescriptionParametersExample
call.say()Text-to-speech playbacktext (string) or object with text and background propertiescall.say('Welcome to our service'); or call.say({ text: 'Hello', background: false });
call.dtmf()Capture DTMF digitsCallback functioncall.dtmf(onDtmfHandler);
call.play()Play audioObject with audio, codec, direction properties or urlcall.play({ direction: "out", codec: codec, audio: audio });
call.stream()Start/stop audio streamingObject with codec, interval, callback or empty to stopcall.stream({ codec: "g711_ulaw", interval: 0.5, callback: streamHandler });
call.transfer()Transfer call to extensionExtension number (string)call.transfer('700');
call.mute()Mute the callNonecall.mute();
call.hangup()Hang up the callNonecall.hangup();
call.sms()Send SMS messageString (text only) or object with text, from, to, name properties (optional)call.sms("Hello"); or call.sms({ text: "hello", from: "+16171234567", to: "+12121234567", name: "Customer" });
call.log()Log message to consoleMessage (string)call.log("Script started");
call.callidGet call ID (property)N/A - propertyvar callId = call.callid;
call.langGet call language (property)N/A - propertyvar language = call.lang;

System Object Functions

FunctionDescriptionParametersExample
system.http()Make HTTP requestObject with method, url, header, body, callback, timeoutsystem.http({ method: 'POST', url: 'http://...', callback: handler });
system.email()Send emailObject with to, from, subject, bodysystem.email({ to: recipient, from: sender, subject: 'Test', body: 'Message' });
system.parseEmailAdr()Parse email addressEmail stringvar addr = system.parseEmailAdr('test@example.com');

Tables Object Functions

FunctionDescriptionParametersExample
tables['cobjs'].get()Get call object datacallid, field name (e.g., 'from', 'to')var from = tables['cobjs'].get(call.callid, 'from');
tables['adrbook'].search()Search address bookField name, search valuevar results = tables['adrbook'].search('number', phoneNumber);
tables['adrbook'].get()Get address book entryEntry ID, field name or '*' for allvar fax = tables['adrbook'].get(entryId, 'fax');
tables['adrbook'].count()Count address book entriesNonevar count = tables['adrbook'].count();

WebSocket Functions

FunctionDescriptionParametersExample
new Websocket()Create WebSocket connectionWebSocket URL (string)var ws = new Websocket("wss://api.example.com");
ws.header()Set WebSocket headersArray of header objects with name, value, optional secretws.header([{ name: "Authorization", value: "Bearer " + token, secret: true }]);
ws.on()Register event handlerEvent name ('open', 'close', 'message'), callback functionws.on('message', function(message) { ... });
ws.send()Send data through WebSocketData (string, typically JSON)ws.send(JSON.stringify(data));
ws.connect()Connect WebSocketNonews.connect();
ws.close()Close WebSocket connectionNonews.close();

Utility Functions

FunctionDescriptionParametersExample
toBase64String()Convert data to base64Data (buffer/string)var b64 = toBase64String(audioData);
fromBase64String()Convert base64 to dataBase64 stringvar data = fromBase64String(b64String);
setTimeout()Execute function after delayCallback function, delay in millisecondssetTimeout(function() { call.hangup(); }, 5000);
clearTimeout()Cancel scheduled timeoutTimer referenceclearTimeout(timer);
console.log()Log to consoleMessage (string)console.log("Debug message");

Common Patterns and Usage

DTMF Collection Pattern

var digits = '';
call.dtmf(onDtmf);

function onDtmf(digit) {
digits += digit;
if (digits.length == 4) {
processDigits(digits);
digits = '';
}
}

HTTP Request Pattern

var args = {
method: 'POST',
url: 'http://example.com/webhook',
header: [{ name: 'Content-Type', value: 'application/json' }],
body: JSON.stringify({ key: 'value' }),
callback: function(code, response, headers) {
console.log('Response code: ' + code);
var data = JSON.parse(response);
// Process response
}
};
system.http(args);

WebSocket Streaming Pattern (OpenAI Realtime)

var ws = new Websocket("wss://api.openai.com/v1/realtime?model=...");

ws.on('open', function() {
console.log("Connected");
});

ws.on('message', function(message) {
var msg = JSON.parse(message);
if (msg.type == "response.audio.delta") {
var audio = fromBase64String(msg.delta);
call.play({ direction: "out", codec: "g711_ulaw", audio: audio });
}
});

call.stream({
codec: "g711_ulaw",
interval: 0.5,
callback: function(audio) {
ws.send(JSON.stringify({
type: "input_audio_buffer.append",
audio: toBase64String(audio)
}));
}
});

ws.connect();

Table Lookup Pattern

// Get caller information
var from = tables['cobjs'].get(call.callid, 'from');
var to = tables['cobjs'].get(call.callid, 'to');

// Search address book
var results = tables['adrbook'].search('number', from);
if (results && results.length > 0) {
var entryId = results[0];
var extension = tables['adrbook'].get(entryId, 'fax');
call.transfer(extension);
}

Call Transfer with Delay Pattern

call.say('Transferring your call now.');
setTimeout(function() {
call.transfer('700');
}, 3000);

SMS Sending Pattern

// Simple SMS
call.sms("Thank you for calling. Your reference number is 12345.");

// Advanced SMS with custom from/to numbers
call.sms({
text: "Your appointment is confirmed for tomorrow at 2 PM.",
from: "+16171234567",
to: "+12121234567",
name: "Customer"
});

Audio Codecs

Supported audio codecs for call.play() and call.stream():

  • "g711_ulaw" - G.711 μ-law (most common)
  • "g711_alaw" - G.711 A-law
  • "pcm16" - 16-bit PCM
  • "mp3" - MP3 (for playback only)

Version Information

These functions are documented based on Vodia PBX version 69.5.19+. Function availability and behavior may vary in different versions.

For more information on Vodia's JavaScript capabilities, refer to: Vodia Backend JavaScript Documentation