Change AutoResponse Global Template based on time of the day


#1

I have to modify the global template in RT so the AutoResponse via email is
different during office hours and after hours. For Example at 9AM it should
say Thank you for contacting Help-desk etc. , and at 5PM will say that the
office is currently closed, all tickets will be looked at tomorrow morning.
Now, I have achieve this modifying directly using simple MySQL statement in
bash script to insert my text in the rtdb.Templates table Contents field and
injecting the text form the text files. Although it works with Cron jobs
running at 9AM and 5PM, I was wondering if there is a way to do it via API,
since it is more elegant and overall better solution.

View this message in context: http://requesttracker.8502.n7.nabble.com/Change-AutoResponse-Global-Template-based-on-time-of-the-day-tp58824.html


#2

I think (never tried) that it could be possible to write a custom scrip
action that select the template based on a time condition.

This way you have just to use this action where needed and create the
pre-defined templates without changing them dynamically.

You can also write perl conditions in your template, using {}. Thought
too much perl in templates make them often difficult to read/modify.

If you prefer to stay with a cron job you would better write it using
perl and use the RT API to change the template. Writing directly to the
RT DB is always a bad idea imho.

Easter-eggs Sp�cialiste GNU/Linux
44-46 rue de l’Ouest - 75014 Paris - France - M�tro Gait�
Phone: +33 (0) 1 43 35 00 37 - Fax: +33 (0) 1 43 35 00 76
mailto:elacour@easter-eggs.com - http://www.easter-eggs.com


#3

Thank you Emmanuel!
I was looking into it and since Perl is not my first language :wink: I was
thinking on using custom conditions something like listed here:


The idea is to have 2 AutoResponse templates with different messages, one
for daytime own done for after hours. When the ticket is created, this
condition is evaluated and proper AutoResponse Template is used. I was
thinking about something along these lines (snippet from the web):

#!/usr/local/bin/perl

@months = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
@days = qw(Sun Mon Tue Wed Thu Fri Sat Sun);

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
print “$mday $months[$mon] $days[$wday]\n”;

Modifying above script I can get the value of $hour and put it in the
conditional statement:

if ($hour >= 8 && $hour <= 17) return 1
and in second template
if ($hour < 8 && $hour > 17) return 1

Am I on the right track?

Thanks!
Rad

View this message in context: http://requesttracker.8502.n7.nabble.com/Change-AutoResponse-Global-Template-based-on-time-of-the-day-tp58825p58844.html


#4

Le 15/10/2014 19:50, rjandric via rt-users a �crit :

In your custom condition you should be able to finish by:

if ($hours …) {
$self->SetTemplate(“WorkingHoursTemplateName”);

} elsif ($hours …) {
$self->SetTemplate(“NonWorkingHoursTemplateName”);
}

return 1;

Easter-eggs Sp�cialiste GNU/Linux
44-46 rue de l’Ouest - 75014 Paris - France - M�tro Gait�
Phone: +33 (0) 1 43 35 00 37 - Fax: +33 (0) 1 43 35 00 76
mailto:elacour@easter-eggs.com - http://www.easter-eggs.com


#5

OK, I’ve been trying with the following condition:

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
if ($hour >=8 && $hour <=17) {
$self->SetTemplate(“Autoreply”);

} elsif ($hour < 8 && $hour > 17) {
$self->SetTemplate(“AutoReply-AfterHrs”);
}

return 1;
But regardless of the conditions in if/elif I get both replies, from
Autoreply and AutoReply-AfterHrs templates. The logis seems OK, but I can’t
tell where am I making a mistake. I have included a couple of screenshot
http://requesttracker.8502.n7.nabble.com/file/n58870/Screen_Shot_2014-10-20_at_10.png
s for both scrips.
http://requesttracker.8502.n7.nabble.com/file/n58870/Screen_Shot_2014-10-20_at_10.png

View this message in context: http://requesttracker.8502.n7.nabble.com/Change-AutoResponse-Global-Template-based-on-time-of-the-day-tp58825p58870.html


#6

The screenshots seemed to be wrong in my last post, but here they are:
http://requesttracker.8502.n7.nabble.com/file/n58872/Screen_Shot_AfterHrs.png
http://requesttracker.8502.n7.nabble.com/file/n58872/Screen_Shot_Autoreply.png

Both Scrips are using the same condition with and one with 2 different
templates chosen based on the condition, so it should be one or the other,
but not both as in my test…
Any ideas?

Thanks!

View this message in context: http://requesttracker.8502.n7.nabble.com/Change-AutoResponse-Global-Template-based-on-time-of-the-day-tp58825p58872.html


#7

The screenshots seemed to be wrong in my last post, but here they are:
http://requesttracker.8502.n7.nabble.com/file/n58872/Screen_Shot_AfterHrs.png
http://requesttracker.8502.n7.nabble.com/file/n58872/Screen_Shot_Autoreply.png

Both Scrips are using the same condition with and one with 2 different
templates chosen based on the condition, so it should be one or the other,
but not both as in my test…

Custom conditions only run when your Condition is "User Defined"
Your condition is On Create, so your code is never run (you can see
this by adding RT->Logger->error(“Running?”); commands to your code.

-kevin


#8

Hi rjandric and Kevin_Falcone,
I tried your script but still autoresponse the two conditions.

Can you help me check the script.


If I use the “Notify requestors” Action, the script condition works but the problem is if the requestor is not an internal user or a client it doesn’t autoresponse.

Thank you.
Regards,
Karen