Commit d29efac4 authored by Ian Walls's avatar Ian Walls Committed by Paul Poulain

Talking Tech Support - Phase I

Implements support for Talking Tech I-tiva phone notification for OVERDUE, PREDUE and HOLD notifications.
Overdues respect triggers as configured for the patron's branch.
Predue and Holds notifications respect patron's messaging preference choices.
A new column for phone notification is added if the TalkingTechItivaPhoneNotification system preference is turned on

Record of phone messages being sent to patrons is added to the patron's Notices
tab; notice of success or failure can be retrieved from I-tiva.

See the TalkingTech.README for installation and set-up instructions.

Aside from the control system preference, and the necessary changes to Messaging Preferences
forms to make use of phone notifications, the bulk of the code resides in external
cronjobs.

TalkingTech_itiva_outbound.pl generates the Spec C file to send to I-tiva.  Actual transmission
of the file must be handled by the system administrator.

TalkingTech_itiva_inbound.pl processes the received Results file from I-tiva.  Getting the
file from I-tiva to Koha is the job of the system administrator, as well.

Both scripts have a --help option with full documentation.

The only necessary change to core Koha behavior is in C4::Letters::EnqueueLetter.  The return
value was changed from 0 or 1 (successful addition of letter to message_queue or not), to the actual
insert ID of the letter.  This was required by the outbound script to present a unique Transaction ID
for the notice added to the patron's record (so a 'sent' or 'failed' status could be updated).  Since
the dbh and sth are not shared, and the last_insert_id() command is table-specific, this should be thread-safe.
No changes are necessary to any parts of Koha, as all usage of EnqueueLetter currently ignores the return value.

To Test:

1. Turn on TalkingTechItivaPhoneNotification system preference
2. Verify that 'phone' is now a valid notification option for patrons on both staff and OPAC side
3. Attempt to set a 'phone' preference for PREDUE or HOLD messaging; attempt should succeed
4. Set up the patron for notices to triggers:
   a. include checked out items due in a range of days, including the value set up in their messaging preferences.
   b. place several holds, some in position, others waiting for pickup, others in transit.
   c. set the patron up to have overdues, overdue by a range of days that includes the delay values for
the patrons branch and categorycode
5. Run TalkingTech_itiva_outbound.pl --type=RESERVE --type=PREOVERDUE --type=OVERDUE --outfile=/tmp/talkingtechtest.csv

The resulting talkingtechtest.csv file should include all the items due on X days (where X is the patrons' preference),
and none of the ones due in other increments.  Similarly, overdues messages should be added for each item due by a delay
value as configured; overdues of other numbers of days should be ignore.  Holds that are waiting pick up or in transit should
have messages, those still pending should not.

Messages should be added to the patron's notices tab for each issue sent.  Verify these messages exist, and all Notices
tokens are replaced with appropriate information.

Repeat, this time with 4c making use of the default branch overdue triggers, instead of branch-specific triggers.

To test the inbound script, create a CSV with rows in the format "<<Message_id>>","<<SUCCESS or FAIL>>"
Message ID should correspond to the final column of the talkingtechtest.csv file (the transaction id) for the message.

Primary Authorship: Ian Walls
Additional modifications: Kyle M Hall

http://bugs.koha-community.org/show_bug.cgi?id=4246Signed-off-by: default avatarNicole C. Engard <nengard@bywatersolutions.com>

Tested and in use in production by two public libraries : Middletown
and Washoe. Both have given their sign off, but don't have git to
actually sign off.
Signed-off-by: default avatarPaul Poulain <paul.poulain@biblibre.com>
parent 68b30468
......@@ -661,7 +661,7 @@ places a letter in the message_queue database table, which will
eventually get processed (sent) by the process_message_queue.pl
cronjob when it calls SendQueuedMessages.
return true on success
return message_id on success
=cut
......@@ -703,7 +703,7 @@ ENDSQL
$params->{'from_address'}, # from_address
$params->{'letter'}->{'content-type'}, # content_type
);
return $result;
return $dbh->last_insert_id(undef,undef,'message_queue', undef);
}
=head2 SendQueuedMessages ([$hashref])
......
......@@ -112,8 +112,9 @@ if ($op eq 'add_form') {
hidelostitems => $data->{'hidelostitems'},
category_type => $data->{'category_type'},
DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
SMSSendDriver => C4::Context->preference("SMSSendDriver"),
TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"),
"type_".$data->{'category_type'} => 1,
SMSSendDriver => C4::Context->preference("SMSSendDriver")
);
if (C4::Context->preference('EnhancedMessagingPreferences')) {
C4::Form::MessagingPreferences::set_form_values({ categorycode => $categorycode } , $template);
......
#! /usr/bin/perl
use strict;
use warnings;
use C4::Context;
my $dbh = C4::Context->dbh;
# add phone message transport type
$dbh->do("INSERT INTO message_transport_types (message_transport_type) VALUES ('phone')");
# adds HOLD_PHONE and PREDUE_PHONE letters (as placeholders)
$dbh->do("INSERT INTO letter (module, code, name, title, content) VALUES
('reserves', 'HOLD_PHONE', 'Item Available for Pick-up (phone notice)', 'Item Available for Pick-up (phone notice)', 'Your item is available for pickup'),
('circulation', 'PREDUE_PHONE', 'Advance Notice of Item Due (phone notice)', 'Advance Notice of Item Due (phone notice)', 'Your item is due soon'),
('circulation', 'OVERDUE_PHONE', 'Overdue Notice (phone notice)', 'Overdue Notice (phone notice)', 'Your item is overdue')
");
# add phone notifications to patron message preferences options
$dbh->do("INSERT INTO message_transports
(message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) VALUES
(4, 'phone', 0, 'reserves', 'HOLD_PHONE'),
(2, 'phone', 0, 'circulation', 'PREDUE_PHONE')
");
# add TalkingTechItivaPhoneNotification syspref
$dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('TalkingTechItivaPhoneNotification',0,'If ON, enables Talking Tech I-tiva phone notifications',NULL,'YesNo');");
print "Upgrade done (Support for Talking Tech i-tiva phone notification system)\n";
......@@ -21,6 +21,7 @@
<tr><th></th>
<th>Days in advance</th>
[% IF ( SMSSendDriver ) %]<th>SMS</th>[% END %]
[% IF ( TalkingTechItivaPhone ) %]<th>Phone</th>[% END %]
<th>Email</th><th>Digests only?</th>
<!-- <th>RSS</th> -->
[% UNLESS ( messaging_form_inactive ) %]<th>Do not notify</th>[% END %]
......@@ -83,6 +84,34 @@
<td>-</td>
[% END %]
[% IF ( TalkingTechItivaPhone ) %]<td>
[% IF ( messaging_form_inactive ) %]
[% IF ( messaging_preference.transports_phone ) %]
<input type="checkbox"
id="phone[% messaging_preference.message_attribute_id %]"
name="[% messaging_preference.message_attribute_id %]"
value="phone" checked="checked" disabled="disabled" />
[% ELSE %]
<input type="checkbox"
id="phone[% messaging_preference.message_attribute_id %]"
name="[% messaging_preference.message_attribute_id %]"
value="phone" disabled="disabled" />
[% END %]
[% ELSE %]
[% IF ( messaging_preference.transports_phone ) %]
<input type="checkbox"
id="phone[% messaging_preference.message_attribute_id %]"
name="[% messaging_preference.message_attribute_id %]"
value="phone" checked="checked" onclick = "$('#none'+'[% messaging_preference.message_attribute_id %]').attr('checked','');" />
[% ELSE %]
<input type="checkbox"
id="phone[% messaging_preference.message_attribute_id %]"
name="[% messaging_preference.message_attribute_id %]"
value="phone" onclick = "$('#none'+'[% messaging_preference.message_attribute_id %]').attr('checked','');" />
[% END %]
[% END %]
</td>[% END %]
[% IF ( messaging_preference.transport_email ) %]
<td>
[% IF ( messaging_form_inactive ) %]
......
......@@ -121,3 +121,9 @@ Patrons:
choices:
now: current date.
dateexpiry: current membership expiry date.
-
- pref: TalkingTechItivaPhoneNotification
choices:
yes: Enable
no: Disable
- patron phone notifications using Talking Tech i-tiva (overdues, predues and holds notices currently supported).
......@@ -36,7 +36,7 @@
<div class="dialog message"><h3>Settings updated</h3></div>
[% END %]
<table style="margin-right:1em;">
<tr><th>&nbsp;</th><th>Days in advance</th>[% IF ( SMSSendDriver ) %]<th>SMS</th>[% END %]<th>Email</th><th>Digests only?</th><!-- <th>RSS</th> --><th>Do not notify</th></tr>
<tr><th>&nbsp;</th><th>Days in advance</th>[% IF ( SMSSendDriver ) %]<th>SMS</th>[% END %][% IF ( TalkingTechItivaPhone ) %]<th>Phone</th>[% END %]<th>Email</th><th>Digests only?</th><!-- <th>RSS</th> --><th>Do not notify</th></tr>
[% FOREACH messaging_preference IN messaging_preferences %]
<tr>
<td>[% IF ( messaging_preference.Item_Due ) %]Item due
......@@ -75,7 +75,22 @@
</td>
[% END %]
[% ELSE %]
<td>-</td>
<td>--</td>
[% END %]
[% IF ( TalkingTechItivaPhone ) %]
<td>
[% IF ( messaging_preference.transports_phone ) %]
<input type="checkbox"
id="phone[% messaging_preference.message_attribute_id %]"
name="[% messaging_preference.message_attribute_id %]"
value="phone" checked="checked" onclick = "document.opacmessaging.none[% messaging_preference.message_attribute_id %].checked=false;" />
[% ELSE %]
<input type="checkbox"
id="phone[% messaging_preference.message_attribute_id %]"
name="[% messaging_preference.message_attribute_id %]"
value="phone" onclick = "document.opacmessaging.none[% messaging_preference.message_attribute_id %].checked=false;" />
[% END %]
</td>
[% END %]
[% IF ( messaging_preference.transport_email ) %]
......
......@@ -688,6 +688,7 @@ if (C4::Context->preference('EnhancedMessagingPreferences')) {
}
$template->param(SMSSendDriver => C4::Context->preference("SMSSendDriver"));
$template->param(SMSnumber => defined $data{'smsalertnumber'} ? $data{'smsalertnumber'} : $data{'mobile'});
$template->param(TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"));
}
$template->param( "showguarantor" => ($category_type=~/A|I|S|X/) ? 0 : 1); # associate with step to know where you are
......
......@@ -398,6 +398,7 @@ if (C4::Context->preference('EnhancedMessagingPreferences')) {
$template->param(messaging_form_inactive => 1);
$template->param(SMSSendDriver => C4::Context->preference("SMSSendDriver"));
$template->param(SMSnumber => defined $data->{'smsalertnumber'} ? $data->{'smsalertnumber'} : $data->{'mobile'});
$template->param(TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"));
}
# in template <TMPL_IF name="I"> => instutitional (A for Adult, C for children)
......
Installation and Setup instructions for Talking Tech I-tiva phone notification
=============================
Be sure you've run installer/data/mysql/atomicupdate/Bug-4246-Talking-Tech-itiva-phone-notifications.pl
to install the required data pack (new syspref, notice placeholders and messaging transport preferences)
To use, TalkingTechItivaPhoneNotification syspref must be turned on.
If you wish to process PREOVERDUE or RESERVES messages, you'll need the EnhancedMessagingPreferences
system preference turned on, and patrons to have filled in a perference for receiving these notices by phone.
For OVERDUE messages, overdue notice triggers must be configured under Koha -> Tools -> Overdue Notice Triggers.
Either branch-specific triggers or the default level triggers may be used (script will select whichever is appropriate).
Sending Notices file to I-tiva:
=============================
1. Add the TalkingTech_itiva_outbound.pl script to your crontab
2. Add an FTP/SFTP or other transport method to send the output file to the I-tiva server
3. If you wish, archive the sent notices file in another directory after sending
Run TalkingTech_itiva_outbound.pl --help for more information
Receiving Results file from I-tiva:
=============================
1. Add an FTP/SFTP or other transport method to send the Results file to a known directory on your Koha server
2. Add the TalkingTech_itiva_inbound.pl script to your crontab, aimed at that directory
3. If you wish, archive the results file in another directory after processing
Run TalkingTech_itiva_inbound.pl --help for more information
#!/usr/bin/perl
#
# Copyright (C) 2011 ByWater Solutions
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
use warnings;
BEGIN {
# find Koha's Perl modules
# test carefully before changing this
use FindBin;
eval { require "$FindBin::Bin/../kohalib.pl" };
}
use Getopt::Long;
use Pod::Usage;
use C4::Context;
sub usage {
pod2usage( -verbose => 2 );
exit;
}
die "TalkingTechItivaPhoneNotification system preference not activated... dying\n" unless (C4::Context->preference("TalkingTechItivaPhoneNotification"));
# Database handle
my $dbh = C4::Context->dbh;
# Benchmarking
my $updated= 0;
my $total = 0;
# Options
my $verbose;
my $help;
my $infile;
GetOptions(
'i|input:s' => \$infile,
'v' => \$verbose,
'help|h' => \$help,
);
die pod2usage() if $help;
# initialize the input data, either file or query
if (defined $infile) {
open(IN, $infile) || die ("Cannot open input file");
print "Opening $infile\n" if (defined $verbose);
while (<IN>) {
# data should take to form "<Transaction ID>","<SUCCESS or FAIL>"
s/["\n]//g; # strip quotes and newlines: they're unnecessary
my @data = split(/,/);
my $result = update_notice(@data);
$updated += $result;
$total++;
}
} else {
die pod2usage( -verbose => 1 );
}
print "$updated of $total results lines processed\n" if (defined $verbose);
=head1 NAME
TalkingTech_itiva_inbound.pl
=head1 SYNOPSIS
TalkingTech_itiva_inbound.pl
TalkingTech_itiva_inbound.pl -v --input=/tmp/talkingtech/results.csv
Script to process received Results files for Talking Tech i-tiva
phone notification system.
=over 8
=item B<--help> B<-h>
Prints this help
=item B<-v>
Provide verbose log information.
=item B<--input> B<-i>
REQUIRED. Path to incoming results file.
=back
=cut
sub update_notice {
my $message_id = shift;
my $status = shift;
if ($status =~ m/SUCCESS/i) {
$status = 'sent';
} elsif ($status =~ m/FAIL/i) {
$status = 'failed';
} else {
warn "unexpected status $status for message ID $message_id\n";
return 0;
}
my $query = "UPDATE message_queue SET status = ? WHERE message_id = ? and status = 'pending'";
my $sth = $dbh->prepare($query);
my $result = $sth->execute($status,$message_id);
return $result;
}
This diff is collapsed.
......@@ -67,6 +67,7 @@ C4::Form::MessagingPreferences::set_form_values({ borrowernumber => $borrowe
$template->param( BORROWER_INFO => [ $borrower ],
messagingview => 1,
SMSnumber => defined $borrower->{'smsalertnumber'} ? $borrower->{'smsalertnumber'} : $borrower->{'mobile'},
SMSSendDriver => C4::Context->preference("SMSSendDriver") );
SMSSendDriver => C4::Context->preference("SMSSendDriver"),
TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification") );
output_html_with_http_headers $query, $cookie, $template->output;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment