Unanswered Call Notification Script

I made a script for Asternic which is available for purchase. It’s for missed call notifications – when a call is abandoned then you get an email listing the Caller ID of calls that were unanswered so you can easily call them back. Asternic can email you a daily CSV of unanswered calls but can’t do real-time notifications out of the box so this is aimed to be a cost-effective solution to help supervisors who need instant notification of missed calls so they can call the person back straight away.

The script has also been tested with multiple queues failing over to each other and you only get one missed call alert for two queues i.e. the first queue timeout is ten seconds and second queue timeout is five seconds then hangup – the email shows a duration of fifteen seconds while listing only one missed call (no duplicate entries).

Script Name:

Unanswered Call Notification for Asternic with FreePBX / Asterisk Queues – Near Real-Time Emails

Here’s an image of the latest email notification including a UniqueID which can be clicked to look-up the Called number in FreePBX CDR’s – since queue information shows the queue number called instead of the called telephone number – so now you have an easy method to find the number as well.

Here’s an image of the cron job configured to run every minute:

Here’s an image of the script verbose output so you can see its thought process before sending an email notification:

Here are my notes from the beginning of the script source code so you can read what it’s all about including details on how it works:

Author: Graham Keane <grahamkeane@live.co.uk>

Date: 2020-02-23 (this is also the current version – to keep it simple I base the versions on the date the script was last updated)

Requirement: to email the supervisor as soon as there are any abandoned or unanswered calls from the queue
The email contains a list of telephone numbers so the supervisor can easily return their call or ask agents to call them back

Solution: use the Asternic Rest API to check for unanswered calls in the last minute and send an email to the supervisor
To allow Asternic 1 minute to get data – if the current time is 09:30 we check 2 minutes ago 09:28-09:29
The cron job for this script is ran every minute so we are notified within 3 minutes (allowing 1 minute for email to be received)
CLI is formatted as a click-to-call link for easy call-back using your softphone app e.g. Teams, Skype, Lync, Slack, Hangouts

The events we look for are:
“ABANDON” – caller hung up before agent could answer
“EXITWITHTIMEOUT” – caller not answered before queue timeout

Store the script in /root and make it executable: chmod +x /root/unanswered_call_notification.php
Add cron job: * * * * * php /root/unanswered_call_notification.php >/dev/null 2>&1

Settings you can change

Who should receive notification emails? Multiple can be entered comma separated
$supervisor_email = ‘grahamkeane@live.co.uk’;

The unique ID can be clicked to search FreePBX CDR’s (useful to get called number since Asternic doesn’t have that info)
$freepbx_url = ‘http://192.168.1.47/admin/config.php’;

URL for Asternic
$asternic_host = ‘http://192.168.1.47/stats/’;

Asternic Rest API Usernamd and Password
$asternic_rest_api_username = ‘restUser’;
$asternic_rest_api_password = ‘restPassX’;

Time zone used by Asternic
date_default_timezone_set(‘Europe/London’);
The events which define unanswered calls
$events_to_look_for = array(“ABANDON”, “EXITWITHTIMEOUT”);

The script has been thoroughly tested and works very well. If you need any help you can email me for support and bug fixes. The cost is one-off and the PHP source is included with no encrypted or hidden code.

Backlinks: Reddit.