The PbxAccountApi provides access to account information for applications connected to the PBX system.
All app objects have default access to this API.
The API is designed for incremental retrieval of account information.
Applications request the current account state using the AccountInfo request, and upon receiving an AccountInfoResult, they may issue the next request to obtain updated data.
{
"api": "PbxAccountApi",
"src": string,
"mt": string
}
Retrieves account information associated with the current PBX session. If this is the initial request (no guid available yet), the response will contain only the newly assigned guid.
Request message
{
"api": "PbxAccountApi",
"src": string,
"mt": "AccountInfo",
"guid": string,
"usn": string,
"ausn": string
}
Result message
{
"api": "PbxAccountApi",
"src": string,
"mt": "AccountInfoResult",
"usn": string,
"ausn": string,
"account-guid" :string,
"account-h323" : string,
"info":{} : Returns the info Object of the user
}
This example will check each 2 minutes for changes or new users by using PbxAccountApi and send request to it
new PbxApi("PbxAccountApi").onconnected(function (conn) {
var guid = null;
var usn = null;
var ausn = null;
log("Connected to PbxAccountApi with connection: " + JSON.stringify(conn));
function sendAccountInfo() {
conn.send(JSON.stringify({ api: "PbxAccountApi", mt: "AccountInfo", guid, usn, ausn }));
}
sendAccountInfo();
// As example repeat this task every 120 Seconds
var intervalId = Timers.setInterval(function () {
sendAccountInfo();
}, 120000);
conn.onmessage(function (msg) {
var obj;
try {
obj = JSON.parse(msg);
} catch (e) {
log("Error parsing message: " + e);
return;
}
if (obj.mt == "AccountInfoResult") {
if (obj.guid && !guid) {
guid = obj.guid;
conn.send(JSON.stringify({ mt: "AccountInfo", api: "PbxAccountApi", guid }));
}
if (obj["account-guid"]) {
conn.send(JSON.stringify({ mt: "AccountInfo", api: "PbxAccountApi", guid, usn: obj.usn, ausn: obj.ausn }));
usn = obj.usn;
ausn = obj.ausn;
}
}
});
conn.onclose(function () {
Timers.clearInterval(intervalId);
log("Connection closed, interval cleared.");
});
});