RT::Action::SendEmail / RT::Action::Notify example?

Hi,

I have written a Perl script run by cron that sends out emails
based on ticket states, e.g.:

  1. ticket is due in <= 48h and I haven’t notified the owner
  2. ticket is new/open but has no activity in the past week
  3. ticket is stalled and its Starts date has lapsed

Currently it uses RT::Action::RecordComment to do this, because
I want some sort of record on the ticket that the email was
generated.

I’d prefer to use RT::Action::SendEmail or RT::Action::Notify
to do this, because then these notifications don’t clutter up
the ticket view as much: RT users will just see an “outgoing
mail recorded” line and a link instead (if permitted).

The APIs for all three RT::Action modules seem quite similar,
but the SendEmail and Notify modules seem to require a
Transaction object while the RecordComment one doesn’t. I
don’t know how I might go about fetching a Transaction object
or creating one.

Does anyone have a usage example of the SendEmail or Notify
modules to offer here? Failing that, a way to get a
Transaction object from a ticket might be enough (but I admit
that I barely know what I’m doing at this early stage).

Here’s what I’m doing to generate the comment:

 my $id = $ticket->Id;
 my $action_obj = RT::Action::RecordComment->new(
     Argument       => undef,
     CurrentUser    => $user,
     ScripActionObj => $void_scrip_action,
     ScripObj       => $void_scrip,
     TemplateObj    => $template,
     TicketObj      => $ticket,
     TransactionObj => undef,
 );
 warn "$id: preparation failed\n"
     if not $action_obj->Prepare;
 warn "$id: commit failed\n"
     if not $action_obj->Commit;

Cheers,
Alex

Alex Peters, Fri, 26 Mar 2010 11:51:50 +1100:

Does anyone have a usage example of the SendEmail or Notify
modules to offer here? Failing that, a way to get a
Transaction object from a ticket might be enough (but I admit
that I barely know what I’m doing at this early stage).

Here’s what I’m doing to generate the comment:

my $id = $ticket->Id;
my $action_obj = RT::Action::RecordComment->new(
    Argument       => undef,
    CurrentUser    => $user,
    ScripActionObj => $void_scrip_action,
    ScripObj       => $void_scrip,
    TemplateObj    => $template,
    TicketObj      => $ticket,
    TransactionObj => undef,
);
warn "$id: preparation failed\n"
    if not $action_obj->Prepare;
warn "$id: commit failed\n"
    if not $action_obj->Commit;

I’ve had some more time to look into this, and I’m now using
the RT::Action::Notify module in this way from my external
script:

 my $id = $ticket->Id;
 my (undef, undef, $trans_obj)
     = $ticket->_NewTransaction( Type => '' );
 my $action_obj = RT::Action::Notify->new(
     Argument       => 'Owner,AdminCc',
     CurrentUser    => $user,
     ScripActionObj => $void_scrip_action,
     ScripObj       => $void_scrip,
     TemplateObj    => $template,
     TicketObj      => $ticket,
     TransactionObj => $trans_obj,
 );
 warn "$id: preparation failed\n"
     if not $action_obj->Prepare;
 warn "$id: commit failed\n"
     if not $action_obj->Commit;

I’m sure that using a private method is not the best way to
achieve the outcome of sending an email and noting it in the
ticket. Can anyone offer a cleaner solution than this?

Cheers,
Alex