First, you need to create the out of office/after hours/holiday Auto response in the Admin panel. Make sure it's of the Type (Auto Reply) you need. Auto Reply/new ticket isn't it.
Then you need this --save in bin/my.AutoResponseQueue.pl:
Code: Select all
#!/usr/bin/perl -w
# --
# bin/my.AutoResponseQueue.pl - Assign AutoResponse to Queue from CLI
# modified from OTRS code.
# --
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU AFFERO General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# or see http://www.gnu.org/licenses/agpl.txt.
# --
use strict;
use warnings;
use File::Basename;
use FindBin qw($RealBin);
use lib dirname($RealBin);
use lib dirname($RealBin) . '/Kernel/cpan-lib';
use lib dirname($RealBin) . '/Custom';
use Getopt::Std;
use Kernel::Config;
use Kernel::System::Encode;
use Kernel::System::Time;
use Kernel::System::DB;
use Kernel::System::Log;
use Kernel::System::Queue;
use Kernel::System::AutoResponse;
use Kernel::System::Main;
# get options
my %Opts = ();
getopts( 'hq:r:', \%Opts );
if ( $Opts{h} ) {
print
"my.AutoResponseQueue.pl - assigns autoresponse to a queue \n";
print
"usage: my.AutoResponseQueue.pl -r <AUTORESPONSE> -q <QUEUE>\n";
print "example: my.AutoResponseQueue.pl -r 1 -q Raw\n";
print "You will need to look for the ID from Action=AdminAutoResponse;Subaction=Change;ID=x\n";
exit 1;
}
if ( !$Opts{r} ) {
print STDERR "ERROR: Need -r <AUTORESPONSE> (as a number)\n";
exit 1;
}
if ( !$Opts{q} ) {
print STDERR "ERROR: Need -q <QUEUE> (as a word/phrase, like 'Raw')\n";
exit 1;
}
# create common objects
my %CommonObject = ();
$CommonObject{ConfigObject} = Kernel::Config->new(%CommonObject);
$CommonObject{EncodeObject} = Kernel::System::Encode->new(%CommonObject);
$CommonObject{LogObject} = Kernel::System::Log->new(
LogPrefix => 'MY-my.AutoresponseQueue.pl',
%CommonObject,
);
$CommonObject{MainObject} = Kernel::System::Main->new(%CommonObject);
$CommonObject{DBObject} = Kernel::System::DB->new(%CommonObject);
$CommonObject{QueueObject} = Kernel::System::Queue->new(%CommonObject);
$CommonObject{AutoResponseObject} = Kernel::System::AutoResponse->new(%CommonObject);
# check queue
my $QueueID = $CommonObject{QueueObject}->QueueLookup( Queue => $Opts{q} );
if ( !$QueueID ) {
print STDERR "ERROR: Queue not found for $Opts{q}\n";
exit 1;
}
# check response
my %AutoResponseData
= $CommonObject{AutoResponseObject}->AutoResponseGet( ID => $Opts{r} );
if ( !%AutoResponseData ) {
print STDERR "ERROR: Found no Auto Response for $Opts{r}\n";
exit 1;
}
my @AutoResponseIDs = (split(',',$Opts{r}));
# set queue standard response
if (
!$CommonObject{AutoResponseObject}->AutoResponseQueue(
AutoResponseIDs => \@AutoResponseIDs,
QueueID => $QueueID,
UserID => 1,
)
)
{
print STDERR "ERROR: Can't set AutoResponse!\n";
exit 1;
}
else {
print "Added AutoResponse '$Opts{r}' to Queue '$Opts{q}'.\n";
exit 0;
}
and run otrs.Cron.sh restart
Code: Select all
#every mon-fri at 6:00p after hours
#min hr date month dayOfWeek (5 is after hours response)
0 18 * * mon-fri $HOME/bin/my.AutoResponseQueue.pl -r 5 -q Raw >> /dev/null
#every mon-fri at 7:00a normal (1 is normal autoresponse)
0 7 * * mon-fri $HOME/bin/my.AutoResponseQueue.pl -r 1 -q Raw >> /dev/null
#Christmas (6 is a holiday autoresponse) If the holiday runs on a m-f, you should probably want to make sure it still says holiday and not "open" or "after hours"
0 0 25 12 * $HOME/bin/my.AutoResponseQueue.pl -r 6 -q Raw >> /dev/null
0 7 25 12 * $HOME/bin/my.AutoResponseQueue.pl -r 6 -q Raw >> /dev/null
0 18 25 12 * $HOME/bin/my.AutoResponseQueue.pl -r 6 -q Raw >> /dev/null
It may have bugs. It may not even work. Please don't blame me. Ask questions in the normal forums.
The numbers 1,5,6 are EXAMPLES. Your implementation may vary.
Raw is an EXAMPLE Queue. Your Queue name may vary. Try this out in command line before you try to cron it.