Fixed a whole lot of brokenness in Inbox SMS/Email notifications

WebGUI::Inbox::Message::create now passes isInbox flag to WebGUI::Mail::Send::create
so that per-user notification settings get used

SMS Gateway setting field is now 'text' instead of 'email' so that user can enter a
properly formed value (such as 'myemailgateway.com', which is not an email address).

Added SMS notification template as distinct from email notification template because
SMSs should not be HTML and in general you will want to make your SMS notification
message a lot shorter than your html email notification message (160 char limits in
many countries). As a result, SMSs are now sent as separate emails to gateway rather
than being CCd on email notification.

Added smsGatewaySubject setting because many SMS Gateways use email subject for
authentication. For consistency, also added Email notification email subject.

Fixed handling of different combinations of site-wide sendInboxNotificationsOnly with
per-user receiveInboxEmailNotifications and receiveInboxSmsEmailNotifications.
 * sendInboxNotificationsOnly && receiveInboxEmailNotifications = email notification
 * sendInboxNotificationsOnly && !receiveInboxEmailNotifications = no email
 * !sendInboxNotificationsOnly = ignore receiveInboxEmailNotifications
 * In all cases, SMS is optional and only dependent on receiveInboxSmsEmailNotifications

Updated tests and i18n
This commit is contained in:
Patrick Donelan 2009-08-16 09:42:35 +00:00
parent 3cc02af6bb
commit 388a0b1267
12 changed files with 264 additions and 109 deletions

View file

@ -97,6 +97,18 @@ Email message to use rather than inbox message contents.
Email subject to use rather than inbox message subject.
=head4 smsMessage
SMS notification message to send to C<smsAddress>
=head4 smsSubject
SMS notification subject (typically used for SMS Gateway authentication)
=head4 smsAddress
Email address that SMS notification is sent to (typically the user's C<cellPhone> C<@> C<smsGateway>)
=head3 options
A hash reference containing options for handling the message.
@ -106,6 +118,17 @@ A hash reference containing options for handling the message.
If no_email is true, then no email will be made or sent. Only
the inbox message will be made.
=head4 no_sms
If no_sms is true, then no attempt to sms notifications will be sent.
=head4 overridePerUserDelivery
If true, then the C<isInbox> flag will not be passed to L<WebGUI::Mail::Send::Create>, and thus the
per-user settings for email delivery will not be used. Useful if you want to force this message to
be sent as an Email rather than allowing the user's C<receiveInboxEmailNotifications> setting to
take effect.
=cut
sub create {
@ -127,6 +150,9 @@ sub create {
$self->{_properties}{userId} = $session->user->userId;
}
my $status = $self->{_properties}{status};
my $smsMessage = $properties->{smsMessage};
my $smsSubject = $properties->{smsSubject};
my $smsAddress = $properties->{smsAddress};
if ($status eq "completed") {
$self->{_properties}{completedBy} = $session->user->userId;
@ -158,13 +184,15 @@ sub create {
);
}
}
if ( $options->{ to_email } ) {
my $subject = (defined $properties->{emailSubject}) ? $properties->{emailSubject} : $self->{_properties}{subject};
unless ( $options->{ no_email } ) {
my $subject = (defined $properties->{emailSubject}) ? $properties->{emailSubject} : $self->{_properties}{subject};
my $mail = WebGUI::Mail::Send->create($session, {
toUser=>$self->{_properties}{userId},
toGroup=>$self->{_properties}{groupId},
subject=>$subject,
});
},
$options->{overridePerUserDelivery} ? undef : 'isInbox',
);
my $preface = "";
my $fromUser = WebGUI::User->new($session, $properties->{sentBy});
#Don't append prefaces to the visitor users or messages that don't specify a user (default case)
@ -177,6 +205,23 @@ sub create {
$mail->addFooter;
$mail->queue;
}
unless ( $options->{ no_sms } ) {
# If smsAddress provided, send smsMessage too
if ( $smsAddress && $smsMessage) {
my $sms = WebGUI::Mail::Send->create(
$session,
{ to => $smsAddress,
subject => $smsSubject,
}
);
if ($sms) {
$sms->addText($smsMessage);
$sms->queue;
}
}
}
$self->{_session} = $session;
bless $self, $class;
}