CannedReplies

From Request Tracker Wiki
Revision as of 22:06, 6 September 2017 by Barton (talk | contribs) (Code reformatting)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Several people have asked on the mailing list about how to get 'canned replies' to appear in a drop-down list on the reply/comment screen. The idea is to make frequently used responses easily accessible.

RTFM gives this capability.

There may be people who don't need the full power (and overhead) of an RTFM installation. For these folks, here is a simple solution that uses a couple of callbacks to provide a canned-reply feature on the reply/comment screen. It uses RT's templates, so the same variable substitutions can be used. One limitation is that the transaction object can't be used in the template - I just pass in a blank transaction object to the template parsing routine.

Users will need ShowTemplate rights in order to send canned replies.

Also note that you can send a canned reply with a quoted messages, but that the textarea will combine them in the style of a top post.


Modified Version

by Kevin "gentgeen" Squire (gentgeen AT wikiak DOT org) on Mar 5, 2010.

One drawback of the original CannedReplies was that it showed all templates in the dropdown. Originally this was fine for our environment, but as we began using RT for more things, and the pool of privileged users became less technical, there was a call to filter out the templates that were not canned replies. This is what I did meet that goal. All of my work is based off of the original done by Stephen Turner(MIT).

Create a SelectCannedReply Admin Element

Bring a copy of the SelectTemplate element over to you local branch and call it SelectCannedReply:

   cp $RTHOME/html/Admin/Elements/SelectTemplate $RTHOME/local/html/Admin/Elements/SelectCannedReply

Modify the SelectCannedReply file. I added a line right before the "OrderBy" line in each of the functions. Mine now looks like this:

   <%INIT>
   my $PrimaryTemplates = RT::Templates->new($session{'CurrentUser'});
   if ($Queue != 0) {
       $PrimaryTemplates->LimitToQueue($Queue);
       $PrimaryTemplates->Limit(FIELD => 'Description', OPERATOR => 'STARTSWITH', VALUE => 'Canned Reply');
       $PrimaryTemplates->OrderBy(FIELD => 'Name');
   }
   my $OtherTemplates = RT::Templates->new($session{'CurrentUser'});
   $OtherTemplates->LimitToGlobal($DefaultQueue);
   $OtherTemplates->Limit(FIELD => 'Description', OPERATOR => 'STARTSWITH', VALUE => 'Canned Reply');
   $OtherTemplates->OrderBy(FIELD => 'Name');
   

Create The Two Callbacks

These are basically identical to the original version, the one major difference was the call is now made to /Admin/Elements/SelectCannedReply instead of /Admin/Elements/SelectTemplate

$RTHOME/local/html/Callbacks/CannedReply/Ticket/Update.html/BeforeMessageBox

Canned-reply: <& /Admin/Elements/SelectCannedReply, Name => "Canned-Template", Queue => $TicketObj->QueueObj->id &>

   

<%init> my $TicketObj = LoadTicket($ARGS{'id'});

$RTHOME/local/html/Callbacks/CannedReply/Elements/MessageBox/Default

identical to the original $RTHOME/local/html/Callbacks/<whatever>/Elements/MessageBox/Default below.

Usage

Like the original, you use RT's templates to create your canned-replies. so the same variable substitutions can be used. You can create your canned-replies as a global template (A canned-reply for use in every queue) or just within the queue (A canned-reply for use in just the one queue). The difference in this setup from the original is that it will limit what is shown to the end-user based on the description of the template. When creating a canned-reply, you will need to make your description begin with "Canned Reply" (case sensitive). This can be altered (Non-English languages for example) by modifying the "STARTSWITH" option in the SelectCannedReply file.

Users will need ShowTemplate rights in order to send canned replies.


Original

by Stephen Turner (MIT) on April 6, 2006.

Here's the code - this involves two new Callback files. Please note that this is just something I've been playing with, and there is probably room for improvement.

$RTHOME/local/html/Callbacks/<whatever>/Ticket/Update.html/BeforeMessageBox

   Canned reply: <& /Admin/Elements/SelectTemplate, Name => "Canned-Template", Queue => $TicketObj->QueueObj->id &>
   
   <%init>
   my $TicketObj = LoadTicket($ARGS{'id'});
   

$RTHOME/local/html/Callbacks//Elements/MessageBox/Default

   %#
   %# Allows use of templates as 'canned replies' in update screen.
   %# Looks up the template specified, parses it and displays the parsed
   %# template content.
   %#
   % if ($content) {
   <% $content %>
   % }
   <%init>
   my $template;
   my $trans = new RT::Transaction( $session{'CurrentUser'} );
   my $content = "";
   if ( $ARGS{'select_template'} ) {
       my $template_id = $ARGS{'Canned-Template'};
       if ($template_id) {
           $template = RT::Template->new($session{'CurrentUser'});
           $template->Load($template_id);
           if ($template->id) {
               my $TicketObj = LoadTicket($ARGS{'id'});
               $template->Parse(TicketObj => $TicketObj,
                                TransactionObj => $trans);
               $content = $template->MIMEObj->stringify;
           }
       }
   }
   


Pretty Variation 1

by Kevin "gentgeen" Squire (gentgeen AT wikiak DOT org)

I really liked the original idea, but I did not like how it was displayed. I wanted the words "Canned reply:" to be directly above the word "Message" and the templates selection and submit button to line up with the other input boxes.

The code above will create a table that looks something like this:

   --------------------------------------------------------------
   |          Bcc: |  INPUTBOX                                  |
   |       Attach: |  INPUTBOX  BUTTON BUTTON                   |
   |      Message: |  Canned Reply: DROPDOWNBOX  BUTTON         |
   |                  INPUTBOX                                  |
   --------------------------------------------------------------


The code below will create a table that looks something like this:

   ------------------------------------------------
   |          Bcc: |  INPUTBOX                    |
   |       Attach: |  INPUTBOX  BUTTON BUTTON     |
   | Canned Reply: |  DROPDOWNBOX  BUTTON         |
   |      Message: |  INPUTBOX                    |
   ------------------------------------------------

First I changed the Update.html page (I copied the original over to my local directory) by adding a call to a callback for "BeforeMessage" (instead of "BeforeMessageBox"

New Update.html

<&|/l&>Attach: <& /Elements/Callback, _CallbackName => 'BeforeMessage', %ARGS &> <&|/l&>Message:

   <& /Elements/Callback, _CallbackName => 'BeforeMessageBox', %ARGS &>


*NOTE:* Since the callback is in the middle of a table, the callback code must be at least 1 table row, with two table data elements

Then I changed the first callback noted above to the following:

$RTHOME/local/html/Callbacks//Ticket/Update.html/BeforeMessage

   %#
   %# Allows use of templates as 'canned replies' in update screen.
   %# Presents a select list of templates.
   %#

Canned reply: <& /Admin/Elements/SelectTemplate, Name => "Canned-Template", Queue => $TicketObj->QueueObj->id &>

   

<%init> my $TicketObj = LoadTicket($ARGS{'id'});

Simpler Pretty Variation

by Jerrad

This uses the original's MessageBox callback, but instead of local/html/Callbacks/Indirection/Ticket/Update.html/BeforeMessageBox we use local/html/Callbacks/Indirection/Ticket/Update.html/BeforeUpdateType with:

   <& /Admin/Elements/SelectTemplate, Name => "Canned-Template", Queue => $TicketObj->QueueObj->id &>
   

<%init> my $TicketObj = LoadTicket($ARGS{'id'});

DefaultCreateContent; yet another version

mailing list post

See Also

StockAnswers