Vodia PBX JavaScript IVR Functions Reference
Call Object Functions
| Function | Description | Parameters | Example |
|---|---|---|---|
call.say() | Text-to-speech playback | text (string) or object with text and background properties | call.say('Welcome to our service'); or call.say({ text: 'Hello', background: false }); |
call.dtmf() | Capture DTMF digits | Callback function | call.dtmf(onDtmfHandler); |
call.play() | Play audio | Object with audio, codec, direction properties or url | call.play({ direction: "out", codec: codec, audio: audio }); |
call.stream() | Start/stop audio streaming | Object with codec, interval, callback or empty to stop | call.stream({ codec: "g711_ulaw", interval: 0.5, callback: streamHandler }); |
call.transfer() | Transfer call to extension | Extension number (string) | call.transfer('700'); |
call.mute() | Mute the call | None | call.mute(); |
call.hangup() | Hang up the call | None | call.hangup(); |
call.sms() | Send SMS message | String (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 console | Message (string) | call.log("Script started"); |
call.callid | Get call ID (property) | N/A - property | var callId = call.callid; |
call.lang | Get call language (property) | N/A - property | var language = call.lang; |
System Object Functions
| Function | Description | Parameters | Example |
|---|---|---|---|
system.http() | Make HTTP request | Object with method, url, header, body, callback, timeout | system.http({ method: 'POST', url: 'http://...', callback: handler }); |
system.email() | Send email | Object with to, from, subject, body | system.email({ to: recipient, from: sender, subject: 'Test', body: 'Message' }); |
system.parseEmailAdr() | Parse email address | Email string | var addr = system.parseEmailAdr('test@example.com'); |
Tables Object Functions
| Function | Description | Parameters | Example |
|---|---|---|---|
tables['cobjs'].get() | Get call object data | callid, field name (e.g., 'from', 'to') | var from = tables['cobjs'].get(call.callid, 'from'); |
tables['adrbook'].search() | Search address book | Field name, search value | var results = tables['adrbook'].search('number', phoneNumber); |
tables['adrbook'].get() | Get address book entry | Entry ID, field name or '*' for all | var fax = tables['adrbook'].get(entryId, 'fax'); |
tables['adrbook'].count() | Count address book entries | None | var count = tables['adrbook'].count(); |
WebSocket Functions
| Function | Description | Parameters | Example |
|---|---|---|---|
new Websocket() | Create WebSocket connection | WebSocket URL (string) | var ws = new Websocket("wss://api.example.com"); |
ws.header() | Set WebSocket headers | Array of header objects with name, value, optional secret | ws.header([{ name: "Authorization", value: "Bearer " + token, secret: true }]); |
ws.on() | Register event handler | Event name ('open', 'close', 'message'), callback function | ws.on('message', function(message) { ... }); |
ws.send() | Send data through WebSocket | Data (string, typically JSON) | ws.send(JSON.stringify(data)); |
ws.connect() | Connect WebSocket | None | ws.connect(); |
ws.close() | Close WebSocket connection | None | ws.close(); |
Utility Functions
| Function | Description | Parameters | Example |
|---|---|---|---|
toBase64String() | Convert data to base64 | Data (buffer/string) | var b64 = toBase64String(audioData); |
fromBase64String() | Convert base64 to data | Base64 string | var data = fromBase64String(b64String); |
setTimeout() | Execute function after delay | Callback function, delay in milliseconds | setTimeout(function() { call.hangup(); }, 5000); |
clearTimeout() | Cancel scheduled timeout | Timer reference | clearTimeout(timer); |
console.log() | Log to console | Message (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