I have an asterisk module setup in a nodejs application for creating call center services. I have a live_call_array variable which stores live calls like :
[
{
caller : "somecaller",
queue : "somequeue",
agent : "someagent", }
]
An asterisk event 'agentconnect' pushes an object with relevant information into the array. Another asterisk event called 'agentcomplete' splices the object from the array. And in each event, a websocket functions is triggered with a payload of the array.
example :
this.ami.on('agentconnect', async (evt) => {
if (this.live_calls.length > 100) {
this.live_calls.shift();
}
const queues = await this.queuesService.findAll();
const matchingQueue = queues.find((queue) => queue.number === evt.queue);
const queueName = matchingQueue ? matchingQueue.name : 'Unknown';
const connectedExtension = evt.destchannel.split('/')[1].split(/[@-]/)[0];
const caller_in_live = this.live_calls.find(
(e) => e.caller == evt.calleridnum,
);
if (caller_in_live) {
this.live_calls.splice(this.live_calls.indexOf(caller_in_live), 1);
}
if (!caller_in_live) {
this.live_calls.unshift({
caller: evt.calleridnum,
queue: queueName,
extension: connectedExtension,
extensionName: evt.connectedlinename,
});
}
this.realtimeGateway.emitData('live-call-array', this.live_calls, [
Role.DASHBOARD,
]);
})
this.ami.on('agentcomplete', async (evt) => {
const caller_in_live = this.live_calls.find(
(e) => e.caller == evt.calleridnum,
);
if (caller_in_live) {
this.live_calls.splice(this.live_calls.indexOf(caller_in_live), 1);
}
this.realtimeGateway.emitData('live-call-array', this.live_calls, [
Role.DASHBOARD,
]);
Normally this works but however sometimes, the array fails to pop out an object after agentcomplete is triggered and the object stays in the live calls array forever. Any solutions or alternative methods for this?
All these things with AMI do not work well.
Look at the vicidial.org dialing platform. They re-ask it multiple times per minute.
Only 100% working thing is CEL/CDR or external counting.
p.s. writing dialler based on asterisk without study similar products and extensive experience with asterisk is just wast of time.