After Hours autoreply

Dont create your support topics here! No new topics with questions allowed!

Moderator: crythias

Forum rules
Dont create your support topics here! No new topics with questions allowed!
Post Reply
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

After Hours autoreply

Post by crythias »

"How can I change my autoresponse after hours and when we're closed on holidays?"

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;
}
Then you need a cron job ... stick it in otrs/var/cron/offhours
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
PLEASE PLEASE Test it before assuming it will work for you.
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.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
sgw
Znuny newbie
Posts: 32
Joined: 22 Sep 2011, 16:39
Znuny Version: 5.0.7
Real Name: Stefan Weichinger
Company: oops!
Contact:

Re: After Hours autoreply

Post by sgw »

I want to test your suggested script.
Does anyone already know if it works? :D

What about the "-r" parameter? Should that point to the reply to use?
I don't see any numbers for the reply-templates within the GUI ... how to find or define them?

Thanks!

EDIT: found it .. using the ID from the mysql table ...

But I think your script doesn't work with OTRS 4.x anymore .... the initialization of objects has changed, right?
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: After Hours autoreply

Post by reneeb »

Modified for OTRS4:

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::System::ObjectManager;
# create object manager
local $Kernel::OM = Kernel::System::ObjectManager->new(
    'Kernel::System::Log' => {
        LogPrefix => 'MY-my.AutoresponseQueue.pl',
    },
);

# 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;
}

my $QueueObject        = $Kernel::OM->Get('Kernel::System::Queue');
my $AutoResponseObject = $Kernel::OM->Get('Kernel::System::AutoResponse');

# check queue
my $QueueID = $QueueObject->QueueLookup( Queue => $Opts{q} );
if ( !$QueueID ) {
    print STDERR "ERROR: Queue not found for $Opts{q}\n";
    exit 1;
}

# check response
my %AutoResponseData = $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 (
    !$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;
}

(untested)
Last edited by reneeb on 11 Dec 2014, 16:31, edited 1 time in total.
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
sgw
Znuny newbie
Posts: 32
Joined: 22 Sep 2011, 16:39
Znuny Version: 5.0.7
Real Name: Stefan Weichinger
Company: oops!
Contact:

Re: After Hours autoreply

Post by sgw »

uh, nice!

gives the following error:
sudo -u otrs ./bin/my.AutoResponseQueue.pl -r 9 -q Raw
Can't locate object method "new" via package "Kernel::System::ObjectManager" (perhaps you forgot to load "Kernel::System::ObjectManager"?) at ./bin/my.AutoResponseQueue.pl line 35.
EDIT: Solved by adding "use Kernel::System::ObjectManager;" to the first lines ;-)
Thanks!
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: After Hours autoreply

Post by crythias »

note that the -r numbers are available in the address line of the browser on the response or status line of the browser when hovering over a response.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
sgw
Znuny newbie
Posts: 32
Joined: 22 Sep 2011, 16:39
Znuny Version: 5.0.7
Real Name: Stefan Weichinger
Company: oops!
Contact:

Re: After Hours autoreply

Post by sgw »

OK, didn't know that, thanks.
Will check that out as soon as I set up the replies.
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: After Hours autoreply

Post by reneeb »

sgw wrote:
Can't locate object method "new" via package "Kernel::System::ObjectManager" (perhaps you forgot to load "Kernel::System::ObjectManager"?) at ./bin/my.AutoResponseQueue.pl line 35.
EDIT: Solved by adding "use Kernel::System::ObjectManager;" to the first lines ;-)
Thanks!

Thanks, updated my code accordingly...
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: After Hours autoreply

Post by crythias »

I made a change to the code above so that you can (and you may need to) apply all the autoresponses at once:

Sample:

Code: Select all

0 18 * * mon-fri $HOME/bin/my.AutoResponseQueue.pl -r 5,2 -q Raw >> /dev/null
Change made:

Code: Select all

my @AutoResponseIDs = (split(',',$Opts{r}));
I noticed this after it has clobbered my autoreject.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: After Hours autoreply (4.0+)

Post by crythias »

Due to the new object manager:

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::System::ObjectManager;

local $Kernel::OM = Kernel::System::ObjectManager->new(
        'Kernel::System::Log' => {
                LogPrefix => 'My.AutoResponse'
        }
);

my $QueueObject = $Kernel::OM->Get('Kernel::System::Queue');
my $AutoResponseObject = $Kernel::OM->Get('Kernel::System::AutoResponse');

# 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
# check queue
my $QueueID = $QueueObject->QueueLookup( Queue => $Opts{q} );
if ( !$QueueID ) {
    print STDERR "ERROR: Queue not found for $Opts{q}\n";
    exit 1;
}

# check response
my %AutoResponseData
    = $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 (
    !$AutoResponseObject->AutoResponseQueue(
        AutoResponseIDs => \@AutoResponseIDs,
        QueueID    => $QueueID,
        UserID     => 1,
    )
    )
{
    print STDERR "ERROR: Can't set AutoResponse!\n";
}
else {
    print "Added AutoResponse '$Opts{r}' to Queue '$Opts{q}'.\n";
}

exit (0);

OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
SarahH
Znuny newbie
Posts: 32
Joined: 09 Mar 2016, 12:55
Znuny Version: 5.00.07
Real Name: Sarah

Re: After Hours autoreply

Post by SarahH »

Hi,

does this also work for OTRS 5?

Thanks,

Sarah
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: After Hours autoreply

Post by reneeb »

This should work with OTRS5, too.
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Post Reply