How to configure Vicidial Sticky Agent

Title : Vicidial Sticky Agent configuration 

    Vicidial is a powerful and feature-rich call center software used by businesses worldwide to manage their inbound and outbound call operations effectively. One of key functionalities missing in the vicidial is the "Sticky Agent" feature, which can significantly improve call routing efficiency and customer experience. In this blog, we will explore what Sticky Agent and guide you through the process of enabling it in your Vicidial setup.

vicidial sticky agent

What is a sticky agent

Sticky agent is a feature in Vicidial that allows a caller to be routed to the same agent every time they call, meaning that subsequent calls from the same customer will be routed to the same agent who handled their previous call(s). This leads to a more personalized experience for customers and increases agent familiarity with each caller's history, enhancing overall customer satisfaction.

Benefits of Sticky Agent

There are several benefits to using sticky agent in Vicidial, including:

Improved customer satisfaction: Customers who are always routed to the same agent are more likely to be satisfied with their interactions with your call center.
Increased efficiency: Sticky agent can help to reduce the amount of time that agents spend transferring calls between each other.
Improved call quality: Sticky agent can help to ensure that calls are handled by the most qualified agent.

Steps to enable Sticky agent in vicidial

    Heres is the steb by step  guide to enable the sticky agent feature in the vicidial. Note this will connect the caller to the same agent whom he connected earlier either caller is connected by outbound dialing or inbound dialing.

Youtube Video Demonstration

Vicidial sticky agent video Tutorial

Pre-Requisites

    Before enabling Sticky Agent in your Vicidial installation, ensure you have the following:

Vicidial System Access: You need administrative access to the Vicidial system to make the necessary configuration changes.

Vicidial Server SSH access: you need the SSH access with root user or other user with root previliges to create agi file and dialplan.

Step 1 :Vicidial Ingroup settings

        For sticky agent option make sure AGENTDIRECT ingroup is avaiable in your vicidial system, this a inbuilt ingroup available in all vicidial systems  also create another ingroup for example INBOUND which we will use it for failover ingroup, if AGENT is busy or not available so the call land to common ingroup where all agents are logged in.

Note INBOUND ingroup is just example, which i used same name in AGI script later in this tutorial,so your ingroup name is different change it accodingly in agi script.

Necessary settings for AGENTDIRECT ingroup

make sure to change below settings accordign to your requirement

Inbound > Show In-Groups

Drop Call Seconds:
Drop Action: Ingroup
Drop Transfer Group:INBOUND
No Agents No Queueing:Y
No Agent No Queue Action: Ingroup
In-Group: INBOUND
Handle Method: Closer
List ID: list id were you need to check the callerid lookup or save the lead.

step 2: Campaign settings 

    Make sure below seetings are enabled in the Campaign ,where the agents will be logged in.

Campaigns > Detail view of your campaign.

Dial Method : Ratio or INBOUND_MAN

       you can select other Options apart from only Manual where you can take inbound calls.

Allow Inbound and Blended: Y

    This is where you can set whether the users of this campaign will have the option to take inbound calls with this campaign.

Allowed Inbound Groups : Select AGENTDIRECT  and INBOUND

Other Optional Campaign settings (enable if required)

Inbound Queue No Dial
Agent Display Queue Count
View Calls in Queue Launch: Auto
Agent Grab Calls in Queue: Y

Step 3: User settings

    Make sure below settings are enabled for each users in your vicidial who want to receive inbound calls and sticky agent calls.

Users > Show Users

Agent Choose Ingroups:1

    Either you can enable this and ask agent to select the ingroups eg: AGENTDIRECT and INBOUND

or As a admin you can select the default ingroups for each agent in user settings

Agent Choose Blended: 1

    This is also optional if campaign is set to blended.

Step 4 : DID settings.

    DID settings is the most important part of our sticky agent configuration, as we are setting the DID route to Custom dialplan extension where we have our agi which query the mysql for the agent ID against the Callerid of the caller and number of hours to consider the caller should sent to sticky agent.

we will be creating a dialplan under default context with the extension 999888777 (which i covered in next step) and  the DID route will be set to exten and mapped to 999888777 

Now Edit you DID and add below settings

DID Route: EXTEN
Extension: 999888777
Extension Context:default

Step 5: Sticky agent AGI script and Dialplan

    In this step we are going to create a AGI file under /var/lib/asterisk/agi-bi/ in the name stickyagent.agi with the below scripts, and creating a dialplan which includes the CALLERID and hours to query the database for the agent id .

Note in the dialplan you can mention the hours to query the agent id ,for 2 days methion as 48, this is used to send the caller to same agent whom he spoke not more than 48 hours.

ssh to your server and create a file named stickyagent.agi under /var/lib/asterisk/agi-bin

cd /var/lib/asterisk/agi-bin/

vi stickagent.agi

copy paste the below script. 

#!/usr/bin/perl
use strict;
use warnings;
use Asterisk::AGI;
use DBI;
# Create a new AGI object
my $agi = new Asterisk::AGI;
# Read MySQL credentials from the configuration file
my $config_file = '/etc/astguiclient.conf';
open(my $conf, $config_file) || die "Can't open $config_file: $!\n";
my @conf = <$conf>;
close($conf);
my %config;
foreach (@conf) {
    chomp;
    my ($key, $value) = split(/\s*=>\s*/, $_, 2);
    $key =~ s/\s*//g;   # Remove any whitespace from the key
    next unless defined $key and defined $value; # Skip empty lines or lines with unexpected formatting
    $config{$key} = $value;
}
my $dbhost = $config{'VARDB_server'};
my $db = $config{'VARDB_database'};
my $dbuser = $config{'VARDB_user'};
my $dbpass = $config{'VARDB_pass'};
my $dbport = $config{'VARDB_port'} || '3306'; # Default to 3306 if VARDB_port is not provided in the config
# DB connect
my $dbh = DBI->connect("DBI:mysql:database=$db;host=$dbhost;port=$dbport", $dbuser, $dbpass) or die "Database connection error: $DBI::errstr";
# End DB connect
my $phone = $ARGV[0];
my $history = $ARGV[1];
# Calculate the time for history hours ago in MySQL format (YYYY-MM-DD HH:MM:SS)
#my $time_x_hours_ago = $dbh->quote("DATE_SUB(NOW(), INTERVAL $history HOUR)");
my $query = "SELECT modify_date, user FROM vicidial_list WHERE phone_number = ? AND modify_date > now() - interval $history hour ORDER BY modify_date DESC LIMIT 1;";
#where order_date > now() - interval 24 hour;
my $result = $dbh->prepare($query);
$result->execute($phone);
#$result->execute($history);
my $agentid = ""; # Initialize the agent_mobile variable
my $ingroup = "INBOUND"; # Set the default value for ingroup
if ($result->rows > 0) {
    my $row = $result->fetchrow_hashref;
    $agentid = $row->{"user"};
    $ingroup = "AGENTDIRECT";
}
$result->finish();
$dbh->disconnect();
# Set the AGI variables for use in Asterisk dialplan
$agi->set_variable("agentid", $agentid);
$agi->set_variable("ingroup", $ingroup);
# Exit the script gracefully
exit 0;

note:  As per this agi script if no result found for the agentid ,then it will assign the INGROUP to INBOUND,change it as per your INGROUP name where you need to send the new callers.

now Give the Permission to the AGI file

chmod 755 stickyagent.agi

Asterisk dialplan for sticky agent

    SSH to your server and add the below dialplan which calls the agi script which we have created in previous step.

cd  /etc/asterisk/

vi extensions.conf

under default context add the below dialplan

exten => 999888777,1,Answer()
exten => 999888777,n,AGI(stickyagent.agi,${CALLERID(num)},48)
exten => 999888777,n,NoOp(my ------------- ${agentid} ----- ${ingroup})
exten => 999888777,n,AGI(agi-VDAD_ALL_inbound.agi,CIDLOOKUP-----LB-----${ingroup}-----60006000-----${CALLERID(num)}-----park----------999-----91----------${agentid})
exten => 999888777,n,Hangup()

Note in line 2 the value 48 represents 2 days data ,change it to 24 if you want past 24 hrs data value. Also the Callerid should be exact phone number without area or country code or any Plus symbol, to avoid that you need to variable manipulation.

exten => 999888777,n,AGI(stickyagent.agi,${CALLERID(num)},48)

Note in line 4, i have mentioned 999 ,which is the LIST ID where CIDLOOKUP will happen, if no result then adds a new LEAD, change it accordingly and 60006000 is my DID change it with your DID value and 91 is my Area/country code change these according to your requirement.

save the extensions.conf file and reload the asterisk

asterisk -rx "dialplan reload"

Testing vicidial Sticky Agent:

    To ensure Sticky Agent is working correctly, perform a few test calls to the campaign you modified. Verify that subsequent calls from the same caller are routed to the same agent who handled the initial call not more than 48hours. If everything is set up correctly, you've successfully enabled Sticky Agent in your Vicidial system.

Conclusion:

Enabling Sticky Agent in Vicidial can significantly improve call routing efficiency and enhance customer interactions. By sticking callers to specific agents, you create a personalized experience for customers and increase agent familiarity with each caller's history. As a result, customer satisfaction and agent productivity are likely to see substantial improvements. So, go ahead and optimize your call center operations by implementing Sticky Agent in Vicidial today!

For professional support reach me on skype or telegram id: striker24x7

1 Comments
  • toxi
    toxi July 10, 2024 at 9:57 AM

    If I have several DID numbers. How did I list them all in the script?
    For example:
    600600
    700700
    800800
    900900

Add Comment
comment url