[Bps-public-commit] rt-extension-notifysms branch, cleanup-initial-release, created. 2dd5beb37cf8ae4903f137b26bf5039203a2e0ad

Craig Kaiser craig at bestpractical.com
Tue Feb 2 16:52:05 EST 2021


The branch, cleanup-initial-release has been created
        at  2dd5beb37cf8ae4903f137b26bf5039203a2e0ad (commit)

- Log -----------------------------------------------------------------
commit 65f66fdf11476b429bb01b370b2f9736e17aeace
Author: craig kaiser <craig at bestpractical.com>
Date:   Thu Jan 21 09:57:12 2021 -0500

    Update Module::Install

diff --git a/META.yml b/META.yml
index 261b79f..62d6fca 100644
--- a/META.yml
+++ b/META.yml
@@ -24,6 +24,6 @@ resources:
   license: http://opensource.org/licenses/gpl-license.php
   repository: https://github.com/bestpractical/rt-extension-NotifySMS
 version: '0.01'
-x_module_install_rtx_version: '0.40'
+x_module_install_rtx_version: '0.42'
 x_requires_rt: 4.4.0
-x_rt_too_new: 4.6.0
+x_rt_too_new: 5.1.0
diff --git a/Makefile.PL b/Makefile.PL
index 7913dbf..55822c9 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -5,7 +5,7 @@ license 'gplv2';
 repository 'https://github.com/bestpractical/rt-extension-NotifySMS';
 
 requires_rt '4.4.0';
-rt_too_new '4.6.0';
+rt_too_new '5.1.0';
 
 sign;
 WriteAll;
diff --git a/inc/Module/Install/RTx.pm b/inc/Module/Install/RTx.pm
index 7cad529..2dd9489 100644
--- a/inc/Module/Install/RTx.pm
+++ b/inc/Module/Install/RTx.pm
@@ -6,9 +6,10 @@ use strict;
 use warnings;
 no warnings 'once';
 
+use Term::ANSIColor qw(:constants);
 use Module::Install::Base;
 use base 'Module::Install::Base';
-our $VERSION = '0.40';
+our $VERSION = '0.42';
 
 use FindBin;
 use File::Glob     ();
@@ -53,7 +54,7 @@ sub RTx {
         my @look = @INC;
         unshift @look, grep {defined and -d $_} @try;
         push @look, grep {defined and -d $_}
-            map { ( "$_/rt4/lib", "$_/lib/rt4", "$_/lib" ) } @prefixes;
+            map { ( "$_/rt5/lib", "$_/lib/rt5", "$_/rt4/lib", "$_/lib/rt4", "$_/lib" ) } @prefixes;
         last if eval {local @INC = @look; require RT; $RT::LocalLibPath};
 
         warn
@@ -76,6 +77,22 @@ sub RTx {
         $self->requires_rt('4.0.0');
     }
 
+    my $package = $name;
+    $package =~ s/-/::/g;
+    if ( $RT::CORED_PLUGINS{$package} ) {
+        my ($base_version) = $RT::VERSION =~ /(\d+\.\d+\.\d+)/;
+        die RED, <<"EOT";
+
+**** Error: Your installed version of RT ($RT::VERSION) already
+            contains this extension in core, so you don't need to
+            install it.
+
+            Check https://docs.bestpractical.com/rt/$base_version/RT_Config.html
+            to configure it.
+
+EOT
+    }
+
     # Installation locations
     my %path;
     my $plugin_path;
@@ -223,7 +240,7 @@ sub requires_rt {
     my @sorted = sort RT::Handle::cmp_version $version,$RT::VERSION;
 
     if ($sorted[-1] eq $version) {
-        die <<"EOT";
+        die RED, <<"EOT";
 
 **** Error: This extension requires RT $version. Your installed version
             of RT ($RT::VERSION) is too old.
@@ -249,12 +266,12 @@ sub requires_rt_plugin {
         unshift @INC, $path;
     } else {
         my $name = $self->name;
-        warn <<"EOT";
+        my $msg = <<"EOT";
 
 **** Warning: $name requires that the $plugin plugin be installed and
               enabled; it does not appear to be installed.
-
 EOT
+        warn RED, $msg, RESET, "\n";
     }
     $self->requires(@_);
 }
@@ -264,9 +281,8 @@ sub rt_too_new {
     my $name = $self->name;
     $msg ||= <<EOT;
 
-**** Error: Your installed version of RT (%s) is too new; this extension
-            only works with versions older than %s.
-
+**** Warning: Your installed version of RT (%s) is too new; this extension
+              has not been tested on your version of RT and may not work as expected.
 EOT
     $self->add_metadata("x_rt_too_new", $version) if $self->is_admin;
 
@@ -274,7 +290,7 @@ EOT
     my @sorted = sort RT::Handle::cmp_version $version,$RT::VERSION;
 
     if ($sorted[0] eq $version) {
-        die sprintf($msg,$RT::VERSION,$version);
+        warn RED, sprintf($msg,$RT::VERSION), RESET, "\n";
     }
 }
 
@@ -297,4 +313,4 @@ sub _load_rt_handle {
 
 __END__
 
-#line 468
+#line 484

commit e350d90f597f557e02fe679e0d461d16c662843e
Author: craig kaiser <craig at bestpractical.com>
Date:   Thu Jan 21 10:57:12 2021 -0500

    Update overlay of NotifySMS::SetRecipients
    
    This change allows for the SetRecipients method to take an arguement of
    'type' which can be 'EmailAddress' ( default ) or 'MobilePhone'. It also
    uses a copy of the RT 5 version of RT::Notify::SetRecipients.

diff --git a/lib/RT/Action/NotifySMS.pm b/lib/RT/Action/NotifySMS.pm
index b210705..6e7aab0 100644
--- a/lib/RT/Action/NotifySMS.pm
+++ b/lib/RT/Action/NotifySMS.pm
@@ -1,22 +1,30 @@
 package RT::Action::NotifySMS;
 
-use base qw(RT::Action);
+use base qw(RT::Action::Notify);
 
 use strict;
 use warnings;
 use LWP::UserAgent;
 
-my @recipients;
-
 sub Prepare {
     my $self = shift;
+    $self->SetRecipients( 'MobilePhone' );
+
+    @{ $self->{'SMS'} } = (
+      @{ $self->{'To'} },
+      @{ $self->{'Cc'} },
+      @{ $self->{'Bcc'} },
+      @{ $self->{'PseudoTo'} }
+    );
 
-    return 0 unless $self->SetRecipients();
-    $self->SUPER::Prepare();
+    return scalar @{ $self->{'SMS'} };
 }
 
+# We overlay the SetRecipients method here in order to get users who may have a
+# Mobile Phone value but no email.
 sub SetRecipients {
     my $self = shift;
+    my $type = shift || 'EmailAddress';
 
     my $ticket = $self->TicketObj;
 
@@ -25,6 +33,7 @@ sub SetRecipients {
 
     my ( @To, @PseudoTo, @Cc, @Bcc );
 
+
     if ( $arg =~ /\bRequestor\b/ ) {
         push @To, $ticket->Requestors->UserMembersObj;
     }
@@ -65,115 +74,130 @@ sub SetRecipients {
                            \b
                            )
                          !x;
-    while ( $arg =~ m/$custom_role_re/g ) {
-        my ( $argument, $role_id, $name, $type ) = ( $1, $2, $3, $4 );
+    while ($arg =~ m/$custom_role_re/g) {
+        my ($argument, $role_id, $name, $type) = ($1, $2, $3, $4);
         my $role;
 
         if ($name) {
-
             # skip anything that is a core Notify argument
-            next
-                if $name eq 'All'
-                || $name eq 'Owner'
-                || $name eq 'Requestor'
-                || $name eq 'AdminCc'
-                || $name eq 'Cc'
-                || $name eq 'OtherRecipients'
-                || $name eq 'AlwaysNotifyActor'
-                || $name eq 'NeverNotifyActor';
+            next if $name eq 'All'
+                 || $name eq 'Owner'
+                 || $name eq 'Requestor'
+                 || $name eq 'AdminCc'
+                 || $name eq 'Cc'
+                 || $name eq 'OtherRecipients'
+                 || $name eq 'AlwaysNotifyActor'
+                 || $name eq 'NeverNotifyActor';
 
             my $roles = RT::CustomRoles->new( $self->CurrentUser );
-            $roles->Limit(
-                FIELD         => 'Name',
-                VALUE         => $name,
-                CASESENSITIVE => 0
-            );
+            $roles->Limit( FIELD => 'Name', VALUE => $name, CASESENSITIVE => 0 );
 
             # custom roles are named uniquely, but just in case there are
             # multiple matches, bail out as we don't know which one to use
             $role = $roles->First;
-            if ($role) {
+            if ( $role ) {
                 $role = undef if $roles->Next;
             }
-        } else {
+        }
+        else {
             $role = RT::CustomRole->new( $self->CurrentUser );
-            $role->Load($role_id);
+            $role->Load( $role_id );
         }
 
-        unless ( $role && $role->id ) {
-            $RT::Logger->debug(
-                "Unable to load custom role from scrip action argument '$argument'"
-            );
+        unless ($role && $role->id) {
+            $RT::Logger->debug("Unable to load custom role from scrip action argument '$argument'");
             next;
         }
 
         my @role_members = (
-            $ticket->RoleGroup( $role->GroupType )->UserMembersObj,
-            $ticket->QueueObj->RoleGroup( $role->GroupType )
-                ->UserMembersObj,
+            $ticket->RoleGroup($role->GroupType)->UserMembersObj,
+            $ticket->QueueObj->RoleGroup($role->GroupType)->UserMembersObj,
         );
-        push @To, @role_members;
+
+        if (!$type || $type eq 'Cc') {
+            push @Cc, @role_members;
+        }
+        elsif ($type eq 'Bcc') {
+            push @Bcc, @role_members;
+        }
+        elsif ($type eq 'To') {
+            push @To, @role_members;
+        }
     }
 
     if ( $arg =~ /\bCc\b/ ) {
-        push( @To, $ticket->Cc->UserMembersObj );
-        push( @To, $ticket->QueueObj->Cc->UserMembersObj );
+
+        #If we have a To, make the Ccs, Ccs, otherwise, promote them to To
+        if (@To) {
+            push ( @Cc, $ticket->Cc->UserMembersObj );
+            push ( @Cc, $ticket->QueueObj->Cc->UserMembersObj  );
+        }
+        else {
+            push ( @Cc, $ticket->Cc->UserMembersObj  );
+            push ( @To, $ticket->QueueObj->Cc->UserMembersObj  );
+        }
     }
+
     if (   $arg =~ /\bOwner\b/
         && $ticket->OwnerObj->id != RT->Nobody->id
-        && not $ticket->OwnerObj->Disabled )
-    {
-        my $role_group = $self->TicketObj->RoleGroup('Owner');
-        push( @To, $role_group->UserMembersObj );
+        && not $ticket->OwnerObj->Disabled
+    ) {
+        # If we're not sending to Ccs or requestors,
+        # then the Owner can be the To.
+        if (@To) {
+            push ( @Bcc, $ticket->OwnerObj );
+        }
+        else {
+            push ( @To, $ticket->OwnerObj );
+        }
+
     }
 
     if ( $arg =~ /\bAdminCc\b/ ) {
-        push( @To, $ticket->AdminCc->UserMembersObj );
-        push( @To, $ticket->QueueObj->AdminCc->UserMembersObj );
+        push ( @Bcc, $ticket->AdminCc->UserMembersObj  );
+        push ( @Bcc, $ticket->QueueObj->AdminCc->UserMembersObj  );
     }
 
     if ( RT->Config->Get('UseFriendlyToLine') ) {
         unless (@To) {
             push @PseudoTo,
-                sprintf RT->Config->Get('FriendlyToLineFormat'), $arg,
-                $ticket->id;
+                sprintf RT->Config->Get('FriendlyToLineFormat'), $arg, $ticket->id;
         }
     }
 
-    my @NoSquelch;
+    my $getUsersAttr = sub {
+      my $collection = shift;
+
+      my @temp = ();
+      foreach my $users ( @{$collection} ) {
+          if ( ref $users eq 'RT::User' ) {
+              next unless $users->$type;
+              push @temp, $users->$type;
+          }
+          else {
+              while ( my $user = $users->Next ) {
+                  next unless $user->$type;
+                  push @temp, $user->$type;
+              }
+          }
+      };
+
+      return @temp;
+    };
+
+    @{ $self->{'To'} }       = &$getUsersAttr ( \@To );
+    @{ $self->{'Cc'} }       = &$getUsersAttr ( \@Cc );
+    @{ $self->{'Bcc'} }      = &$getUsersAttr ( \@Bcc );
+    @{ $self->{'PseudoTo'} } = &$getUsersAttr ( \@PseudoTo );
+
     if ( $arg =~ /\bOtherRecipients\b/ ) {
         if ( my $attachment = $self->TransactionObj->Attachments->First ) {
-            push @NoSquelch, map $_->address,
+            push @{ $self->{'NoSquelch'}{'Cc'} ||= [] }, map $_->address,
                 Email::Address->parse( $attachment->GetHeader('RT-Send-Cc') );
-            push @NoSquelch, map $_->address,
-                Email::Address->parse(
-                $attachment->GetHeader('RT-Send-Bcc') );
-        }
-    }
-
-    # See if we can get some phone numbers from our NoSquelched emails
-    if ( @NoSquelch ) {
-        my $user = RT::User->new(RT->SystemUser);
-        foreach my $email (@NoSquelch) {
-            my ($ret, $msg) = $user->Load($email);
-            RT::Logger->info($msg) unless $ret;
-
-            push @To, $user->MobilePhone unless ! $user->MobilePhone;
+            push @{ $self->{'NoSquelch'}{'Bcc'} ||= [] }, map $_->address,
+                Email::Address->parse( $attachment->GetHeader('RT-Send-Bcc') );
         }
     }
-
-    my $user = RT::User->new( RT->SystemUser );
-    my @recipients;
-
-    foreach my $role (@To) {
-        while (my $user = $role->Next) {
-            push @recipients, $user->MobilePhone
-                unless !$user->MobilePhone;
-        }
-    }
-    return 0 unless scalar @recipients;
-
-    @{ $self->{'Recipients'} } = @recipients;
 }
 
 sub Commit {
@@ -188,9 +212,13 @@ sub Commit {
     }
 
     my $content = $self->TemplateObj->MIMEObj->as_string;
+    unless ( $content ) {
+        RT::Logger->debug( 'No message found, not sending SMS' );
+        return 1;
+    }
 
     my ( $ret, $msg ) = $self->ScripActionObj->Action->SendMessage(
-        Recipients => $self->{Recipients},
+        Recipients => $self->{'SMS'},
         Msg        => $content,
     );
 
diff --git a/lib/RT/Action/NotifyTwilio.pm b/lib/RT/Action/NotifyTwilio.pm
index 483dcfe..0d64695 100644
--- a/lib/RT/Action/NotifyTwilio.pm
+++ b/lib/RT/Action/NotifyTwilio.pm
@@ -39,10 +39,6 @@ sub SendMessage {
             unless RT::Config->Get($config);
     }
 
-    return ( 0, 'Please provide a message to send' ) unless $args{Msg};
-    return ( 0, 'Please provide a recipient' )
-        unless scalar $args{Recipients};
-
     my %Credentials = (
         account_id => RT::Config->Get('TwilioAccounId'),
         auth_token => RT::Config->Get('TwilioAuthToken'),
@@ -61,7 +57,7 @@ sub SendMessage {
         $Credentials{account_id}, $Credentials{auth_token}
     );
 
-    foreach my $to ( $args{Recipients} ) {
+    foreach my $to ( @{$args{'Recipients'}} ) {
         my %text_message = (
             From => $Twilio{'from'},
             To   => $to,

commit 1a109b77350d10d33635203f6b7aadec3394da70
Author: craig kaiser <craig at bestpractical.com>
Date:   Mon Jan 25 12:09:34 2021 -0500

    Parse template object in Prepare method if no MIMEObj exist
    
    A MIMEObj needs to exist in order for preview scrips code to run without
    error.

diff --git a/lib/RT/Action/NotifySMS.pm b/lib/RT/Action/NotifySMS.pm
index 6e7aab0..61a62eb 100644
--- a/lib/RT/Action/NotifySMS.pm
+++ b/lib/RT/Action/NotifySMS.pm
@@ -17,6 +17,15 @@ sub Prepare {
       @{ $self->{'PseudoTo'} }
     );
 
+     unless ( $self->TemplateObj->MIMEObj ) {
+        my ( $ret, $msg ) = $self->TemplateObj->Parse(
+            Argument       => $self->Argument,
+            TicketObj      => $self->TicketObj,
+            TransactionObj => $self->TransactionObj
+        );
+        RT::Logger->error( "Could not parse SMS template: $msg" ) unless $ret;
+    }
+
     return scalar @{ $self->{'SMS'} };
 }
 
@@ -203,14 +212,6 @@ sub SetRecipients {
 sub Commit {
     my $self = shift;
 
-    unless ( $self->TemplateObj->MIMEObj ) {
-        my ( $result, $message ) = $self->TemplateObj->Parse(
-            Argument       => $self->Argument,
-            TicketObj      => $self->TicketObj,
-            TransactionObj => $self->TransactionObj
-        );
-    }
-
     my $content = $self->TemplateObj->MIMEObj->as_string;
     unless ( $content ) {
         RT::Logger->debug( 'No message found, not sending SMS' );

commit 4530878b083b2efdf2bd30cb41feb0c6f08b4eb7
Author: craig kaiser <craig at bestpractical.com>
Date:   Mon Jan 25 15:23:04 2021 -0500

    Make documentation clearer

diff --git a/README b/README
index d63b383..30d29e6 100644
--- a/README
+++ b/README
@@ -1,24 +1,9 @@
 NAME
     RT-Extension-NotifySMS - Provide additional actions to send text
-    messages.
-
-DESCRIPTION
-    Provide additional actions for Scrips, that allow for the sending of
-    messages inplace of email. The new action can be loaded in the web UI
-    from:
-
-        Global -> Actions -> Create
-
-    where the action module is one of the notify option from this extension:
-
-        "NotifyTwilio"
-
-    For the action you can choose to pass the following parameters:
-
-        All, Owner, Requestor, AdminCc, Cc
+    messages
 
 RT VERSION
-    Works with RT 4.4.0
+    Works with RT 5.
 
 INSTALLATION
     perl Makefile.PL
@@ -32,19 +17,69 @@ INSTALLATION
         If you run this twice, you may end up with duplicate data in your
         database.
 
-    Edit your /opt/rt4/etc/RT_SiteConfig.pm
-        If you are using RT 4.4 or greater, add this line:
+    Edit your /opt/rt5/etc/RT_SiteConfig.pm
+        Add this line:
 
             Plugin('RT::Extension::NotifySMS');
 
-        You will also need to set other config values depending on which sms
-        action is being used, see the module for specifications.
+        You will also need to set other config values depending on which SMS
+        action is being used. See CONFIGURATION for details.
 
     Clear your mason cache
-            rm -rf /opt/rt4/var/mason_data/obj
+            rm -rf /opt/rt5/var/mason_data/obj
 
     Restart your webserver
 
+DESCRIPTION
+    Provide additional actions for Scrips, that allow for the sending of SMS
+    messages based on actions in RT.
+
+    Notify SMS actions use the Mobile Phone value from each user record. If
+    the user has no Mobile Phone set, no message is sent.
+
+    After installation you will see new notification actions are available
+    for your RT scrips.
+
+    If notifying a more specific role on a ticket is desired, create a new
+    action in the RT web UI:
+
+        Admin->Global->Actions
+
+    The "Action Module" is "NotifyTwilio". In the "Parameters to Pass"
+    section provide one or more of the following:
+
+        All, Owner, Requestor, AdminCc, Cc
+
+    The content of your outgoing SMS alerts is set using RT templates the
+    same way email notification content is set. One caveat is that SMS
+    notification templates should not have any header values, meaning that
+    they will have a blank line as the first line in the template ( Only
+    applicable for Perl templates ).
+
+    To send "on reply" content via SMS use the following template:
+
+    {$Transaction->Content()}
+
+    With an empty line before the above code.
+
+CONFIGURATION
+    Currently this extension supports the Twilio SMS service.
+
+  Twilio
+    To send a message using the Twilio web API, set the following values in
+    RT_SiteConfig.pm:
+
+            Set( $TwilioAccounId, 'Secret' );
+            Set( $TwilioAuthToken, 'Secret' );
+            Set( $APIURL, 'https://api.twilio.com/2010-04-01/Accounts/' );
+            Set( $APIDomain, 'api.twilio.com:443' );
+            Set( $APIRealm, 'Twilio API' );
+            Set( $MessageSender, '0123456789' );
+
+    To obtain a Twilio AuthToken and AccountId, create a new project of type
+    programmable SMS in the Twilio console. These values can be found in
+    your Twilio account <https://www.twilio.com/console>.
+
 AUTHOR
     Best Practical Solutions, LLC <modules at bestpractical.com>
 
diff --git a/etc/initialdata b/etc/initialdata
index b258949..44fd355 100644
--- a/etc/initialdata
+++ b/etc/initialdata
@@ -1,7 +1,7 @@
 push @ScripActions, (
     {
         Name        => 'Notify Twilio',
-        Description => 'Send SMS messages using Twilio API',
+        Description => 'Send SMS Messages Using Twilio API To All Roles',
         ExecModule  => 'NotifyTwilio',
         Argument    => 'All',
     },
diff --git a/lib/RT/Action/NotifyTwilio.pm b/lib/RT/Action/NotifyTwilio.pm
index 0d64695..6a69832 100644
--- a/lib/RT/Action/NotifyTwilio.pm
+++ b/lib/RT/Action/NotifyTwilio.pm
@@ -7,23 +7,6 @@ use warnings;
 use LWP::UserAgent;
 use JSON qw(decode_json);
 
-=head2 NotifyTwilio
-
-Send a message using the Twilio web api, requires the follow
-config values from RT_SiteConfig.pm:
-
-        Set($TwilioAccounId, 'Secret');
-        Set($TwilioAuthToken, 'Secret');
-        Set($APIURL, 'https://api.twilio.com/2010-04-01/Accounts/');
-        Set($APIDomain, 'api.twilio.com:443');
-        Set($APIRealm, 'Twilio API');
-        Set($MessageSender, '0123456789');
-
-To obtain the Twilio AuthToken and AccountId create a new project of type
-programmable sms. Once done setting up the project you will have access to
-the projects AccountId and AuthToken.
-=cut
-
 sub SendMessage {
     my $self = shift;
     my %args = (
diff --git a/lib/RT/Extension/NotifySMS.pm b/lib/RT/Extension/NotifySMS.pm
index 7ae2953..22e79e7 100644
--- a/lib/RT/Extension/NotifySMS.pm
+++ b/lib/RT/Extension/NotifySMS.pm
@@ -7,26 +7,11 @@ our $VERSION = '0.01';
 
 =head1 NAME
 
-RT-Extension-NotifySMS - Provide additional actions to send text messages.
-
-=head1 DESCRIPTION
-
-Provide additional actions for Scrips, that allow for the sending of messages
-inplace of email. The new action can be loaded in the web UI from:
-
-    Global -> Actions -> Create
-
-where the action module is one of the notify option from this extension:
-
-    "NotifyTwilio"
-
-For the action you can choose to pass the following parameters:
-
-    All, Owner, Requestor, AdminCc, Cc
+RT-Extension-NotifySMS - Provide additional actions to send text messages
 
 =head1 RT VERSION
 
-Works with RT 4.4.0
+Works with RT 5.
 
 =head1 INSTALLATION
 
@@ -47,23 +32,76 @@ Only run this the first time you install this module.
 If you run this twice, you may end up with duplicate data
 in your database.
 
-=item Edit your F</opt/rt4/etc/RT_SiteConfig.pm>
+=item Edit your F</opt/rt5/etc/RT_SiteConfig.pm>
 
-If you are using RT 4.4 or greater, add this line:
+Add this line:
 
     Plugin('RT::Extension::NotifySMS');
 
 You will also need to set other config values depending on which
-sms action is being used, see the module for specifications.
+SMS action is being used. See L<CONFIGURATION> for details.
 
 =item Clear your mason cache
 
-    rm -rf /opt/rt4/var/mason_data/obj
+    rm -rf /opt/rt5/var/mason_data/obj
 
 =item Restart your webserver
 
 =back
 
+
+=head1 DESCRIPTION
+
+Provide additional actions for Scrips, that allow for the sending of SMS
+messages based on actions in RT.
+
+Notify SMS actions use the Mobile Phone value from each user record. If the
+user has no Mobile Phone set, no message is sent.
+
+After installation you will see new notification actions are available for your RT scrips.
+
+If notifying a more specific role on a ticket is desired, create a new
+action in the RT web UI:
+
+    Admin->Global->Actions
+
+The "Action Module" is "NotifyTwilio". In the "Parameters to Pass" section
+provide one or more of the following:
+
+    All, Owner, Requestor, AdminCc, Cc
+
+The content of your outgoing SMS alerts is set using RT templates the same
+way email notification content is set. One caveat is that SMS notification
+templates should not have any header values, meaning that they will have a
+blank line as the first line in the template ( Only applicable for Perl templates ).
+
+To send "on reply" content via SMS use the following template:
+
+{$Transaction->Content()}
+
+With an empty line before the above code.
+
+=head1 CONFIGURATION
+
+Currently this extension supports the Twilio SMS service.
+
+=head2 Twilio
+
+To send a message using the Twilio web API, set the following values in RT_SiteConfig.pm:
+
+        Set( $TwilioAccounId, 'Secret' );
+        Set( $TwilioAuthToken, 'Secret' );
+        Set( $APIURL, 'https://api.twilio.com/2010-04-01/Accounts/' );
+        Set( $APIDomain, 'api.twilio.com:443' );
+        Set( $APIRealm, 'Twilio API' );
+        Set( $MessageSender, '0123456789' );
+
+To obtain a Twilio AuthToken and AccountId, create a new project of type
+programmable SMS in the Twilio console. These values can be found in
+your L<Twilio account|https://www.twilio.com/console>.
+
+=cut
+
 =head1 AUTHOR
 
 Best Practical Solutions, LLC E<lt>modules at bestpractical.comE<gt>

commit a3adbdb138d4b22cb168584dc1821c6553c93b58
Author: craig kaiser <craig at bestpractical.com>
Date:   Thu Jan 28 11:13:41 2021 -0500

    Use RT::Scrip object to call SendMessage
    
    If using rt-crontool the RT ScripActionObj->Action object can be
    undefined.

diff --git a/lib/RT/Action/NotifySMS.pm b/lib/RT/Action/NotifySMS.pm
index 61a62eb..2dc2e32 100644
--- a/lib/RT/Action/NotifySMS.pm
+++ b/lib/RT/Action/NotifySMS.pm
@@ -218,7 +218,7 @@ sub Commit {
         return 1;
     }
 
-    my ( $ret, $msg ) = $self->ScripActionObj->Action->SendMessage(
+    my ( $ret, $msg ) = $self->SendMessage(
         Recipients => $self->{'SMS'},
         Msg        => $content,
     );

commit 0c0c8a6d0b1a1cc37c9829f6e0cb45af402aa504
Author: craig kaiser <craig at bestpractical.com>
Date:   Tue Feb 2 16:36:45 2021 -0500

    Overlay RT::ActionSendEmail->AddressesFromHeader

diff --git a/lib/RT/Action/NotifySMS.pm b/lib/RT/Action/NotifySMS.pm
index 2dc2e32..02e99f8 100644
--- a/lib/RT/Action/NotifySMS.pm
+++ b/lib/RT/Action/NotifySMS.pm
@@ -228,4 +228,16 @@ sub Commit {
     return $ret;
 }
 
+=pod
+We need to overlay this method as our recipients array is an array
+of phone numbers and not emails. Which results in an error if we try
+to call C<Encode::decode("UTF-8",$self->TemplateObj->MIMEObj->head->get($field));>
+=cut
+
+sub AddressesFromHeader {
+    my $self      = shift;
+    my $field     = shift;
+    return (());
+}
+
 1;

commit 2dd5beb37cf8ae4903f137b26bf5039203a2e0ad
Author: craig kaiser <craig at bestpractical.com>
Date:   Tue Feb 2 16:51:29 2021 -0500

    Add example SMS Correspondence template

diff --git a/etc/initialdata b/etc/initialdata
index 44fd355..5fd122e 100644
--- a/etc/initialdata
+++ b/etc/initialdata
@@ -6,3 +6,12 @@ push @ScripActions, (
         Argument    => 'All',
     },
 );
+
+our @Templates = (
+  {
+    Name        => 'SMS Correspondence',
+    Description => 'Correspondence template for SMS alerts.',
+    Content => q{
+{$Transaction->Content()}}
+  }
+);

-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list