Tip - How to announce position in call center queue and make it permanent

Status
Not open for further replies.

TurabG

Member
Aug 25, 2022
77
7
8
44
While I think this should be a default feature, it seems that we need to do it manually for quite a time.

If you want callers to hear announce of their position in the queue with an interval:

First, you will need a script in your switch scripts directory, for example save "callcenter-annouce-position.lua" to /usr/shared/freeswitch/scripts (or wherever your scripts directory is). Content of this file is in FreeSWITCH manual as follows:

Code:
-- callcenter-announce-position.lua
-- Announce queue position to a member in a given mod_callcenter queue.
-- Arguments are, in order: caller uuid, queue_name, interval (in milliseconds).
api = freeswitch.API()
caller_uuid = argv[1]
queue_name = argv[2]
mseconds = argv[3]
if caller_uuid == nil or queue_name == nil or mseconds == nil then
    return
end
while (true) do
    -- Pause between announcements
    freeswitch.msleep(mseconds)
    members = api:executeString("callcenter_config queue list members "..queue_name)
    pos = 1
    exists = false
    for line in members:gmatch("[^\r\n]+") do
        if (string.find(line, "Trying") ~= nil or string.find(line, "Waiting") ~= nil) then
            -- Members have a position when their state is Waiting or Trying
            if string.find(line, caller_uuid, 1, true) ~= nil then
                -- Member still in queue, so script must continue
                exists = true
                api:executeString("uuid_broadcast "..caller_uuid.." ivr/ivr-you_are_number.wav aleg")
                api:executeString("uuid_broadcast "..caller_uuid.." digits/"..pos..".wav aleg")
            end
            pos = pos+1
        end
    end
    -- If member was not found in queue, or it's status is Aborted - terminate script
    if exists == false then
        return
    end
end

Then you need to add this to the queue's dialplan's XML manually (from Dialplans -> Your queue -> XML), right before "callcenter" application:
XML:
        <action application="set" data="result=${luarun(callcenter-announce-position.lua ${uuid} EXTENSION@DOMAIN 15000)}"/>

You will need to change EXTENSION to the extension of the call center queue and the domain to your domain. 15000 figure is the interval in milliseconds at which the caller will hear the announcement, which is 15 seconds in this case. Now this I learnt from this forum BUT, when you make any change in your queue or just save even without any change, your manual XML modification will be lost and you will need to edit it again.

To make is permanent, you need to make sure Fusion adds this line to the XML when anything is changed or when Upgrade -> App Defaults is run.

Open /var/www/fusionpbx/app/call_centers/app_defaults.php find this line:
PHP:
                    $dialplan_xml .= "        <action application=\"callcenter\" data=\"".xml::sanitize($row['queue_extension'])."@".xml::sanitize($row['domain_name'])."\"/>\n";

And before it, add this line:
PHP:
                    $dialplan_xml .= "        <action application=\"set\" data=\"result=\${luarun(callcenter-announce-position.lua \${uuid} ".xml::sanitize($row['queue_extension'])."@".xml::sanitize($row['domain_name'])." 15000)}\"/>\n";
Only thing you need to change here is the interval.

Then open /var/www/fusionpbx/app/call_centers/call_center_queue_edit.php find this line:
PHP:
            $dialplan_xml .= "        <action application=\"callcenter\" data=\"".xml::sanitize($queue_extension)."@".$_SESSION["domain_name"]."\"/>\n";

And before it, add this line:
PHP:
            $dialplan_xml .= "        <action application=\"set\" data=\"result=\${luarun(callcenter-announce-position.lua \${uuid} ".xml::sanitize($queue_extension)."@".$_SESSION['domain_name']." 15000)}\"/>\n";
Again, change interval time per your wish.

Now position announcement will permit if you edit the queue or delete and recreate or reset application defaults. This is of course still a temporary solution. For example if you upgrade source code of Fusion and these files are overwritten by the process, then you need to make proper edits again.

As I said, this should be a feature. When creating or editing the queue, there are already "Announce Sound" and "Announce Frequency" settings. Just put a setting near them to enable or disable position announcement with an interval option or you can even add the option right in the options of "Announce Sound".
 
Last edited:
Status
Not open for further replies.