“Fatal Error? What the %#@& Does That Mean?” · “Automating Custom Patron Notices and...
Transcript of “Fatal Error? What the %#@& Does That Mean?” · “Automating Custom Patron Notices and...
“Fatal Error? What the %#@& Does That Mean?”
Building a Home-Brew Text Message Notification System for Sierra
R.C. Miessler, Systems Librarian Gettysburg College
MAIUG 2015, Cairn University
October 12, 2015
About Gettysburg College
• Private, 4-year liberal arts school • 2,600 students • Sierra platform since 2013 • Library/IT are NOT merged (and don’t like
talking about it) • I am THE library systems person and I am
NOT a developer
MAIUG 2015
“I’m Not a Developer …”
MAIUG 2015
… Fatal Error!
MAIUG 2015
TXT ME PLZ KTHXBY
• Students want text reminders since using email isn’t “cool”
• We want to provide text message reminders, but can’t afford the text message product (sorry III reps)
• Can’t use the “send an email to [email protected]” solution because of how our patron load is set up
MAIUG 2015
Solution?
Foundation – David Noe’s IUG 2015 presentation
“Automating Custom Patron Notices and Messages Using SQL”
– New Twilio text notification add-on for ILLiad Idea
– Use PHP to execute SQL query, then pass along to Twilio to send text messages
MAIUG 2015
Challenges …
So how do we … – Develop the right SQL query? – Build the %#@& thing without IT/developer
assistance? – Find a server to run the PHP script? – Get patrons signed up?
MAIUG 2015
Reclaim Hosting • Built for educators/institutions • Great technical support • $25/$45 a year depending on how much
storage you need • Needed for: running and scheduling PHP
script • Ask for:
– PostgreSQL-enabled server – Whitelist your database server IP
MAIUG 2015
SierraDNA
• Our PHP script runs a PostgreSQL query, so need to be able to talk to the database server
• Contact III for access • Needed for: pulling patron/item data • Recommend dedicated login for this with
Sierra SQL Access application the only thing assigned
MAIUG 2015
Twilio
• $1/month/number • $0.0075/text message sent/received • Excellent documentation and examples • Needed for: sending/receiving texts • Security/outside vendor review?
MAIUG 2015
Tools • Text editor
– Sublime Text (free, but bugs you for $70) – Notepad++ (free) – Brackets.io (free)
• Terminal emulator – PuTTY (free) – Terminal utility (native on Macs)
• FTP client – FileZilla (free)
MAIUG 2015
Resources • Manuals
– PHP.net – postgresql.org – techdocs.iii.com/sierradna/
• Forums – stackoverflow.com – Reddit
• /r/phphelp • /r/learnsql
• Tutorials & Classes – codeacademy.com – W3schools.com
• Peers – Listservs, Twitter, email, phone
• Repositories – GitHub
MAIUG 2015
Workflow Issues
• No consistent data in TELEPHONE/TELEPHONE2 fields in patron record
• No way for patrons to self-opt-in to the service through patron account in WebPAC
• Best bet? Manual process (meh)
MAIUG 2015
Local Workflow Outside Sierra 1. Patrons sign up via web
form on the library’s website
2. Notification emails sent to group who manually update the patron records
3. Patron record manually updated by library staff
4. Confirmation text message sent to patron via custom back-end HTML+PHP web form that connects with Twilio service
MAIUG 2015
Local Workflow in Sierra • Patron record manually updated
– PCODE2 = y – NOTE field inserted with mobile number
• Formatted as +17175551234
• Modify patron load profile – @ov_protect V104 (NOTE), F45 (PCODE2)
MAIUG 2015
Adding Link to WebPAC
Edit patronview_web.html to include a link to the signup form under a new <div class=“patActionItem”>
MAIUG 2015
Good artists copy, great artists steal. - Unknown, generally attributed to Picasso
MAIUG 2015
(awesome artists license their work as CC-BY)
<?php
• This code will eventually be on github.com/rmiessle/sierra-sms and the IUG Clearinghouse in a heavily documented form
• Comments are removed for the presentation to make it easier to show
• Want it sooner? Email me! • Also have a script for non-hourly items
MAIUG 2015
The Code
MAIUG 2015
Function Junction
Functions are just blocks of code that can be called up at any time, saves having to have the same block of code in multiple places writeLog() outputs the number of notices sent into a file that is defined by the variable $logFile and then closes the connection the SQL server Example output: 10-06-2015 15:45:02 - 1 notices sent
MAIUG 2015
$variables, etc.
• Set the timezone (not really a variable) – (http://php.net/manual/en/timezones.php)
• $messageCount – notices sent starts at 0 • $logFile - what the log file is called (for
our writeLog() function) • $fromNumber - our Twilio number • $messageBody – the message we send
MAIUG 2015
SQL Credentials
This is a special variable that sets up your credentials to connect to your SQL database server
– host (database URL) – port (usually 1032) – dbname (usually iii) – user (Sierra user with Sierra SQL Access application) – password (anyone who has access to this file can
see it) – sslmode (require for security)
MAIUG 2015
No Records Found?
If no results are found after running the query, run the writeLog() function
– This just makes a note in the log file that 0 messages were sent
MAIUG 2015
SQL Query
• Pulls the note from the patron record (mobile) and the item barcode (barcode)
• Matches the note field and checkout record to the patron record, and the checkout record to the item record
MAIUG 2015
SQL Query (Continued)
• Additional conditions: • The patron record must have a NOTE field (x) • PCODE2 must be y • The NOTE field must:
– Start with +1 – 3rd character must be 2-9 – 9 more digits (0-9) – Be 12 characters long (+1 = 2, telephone with area code = 10)
• The due timestamp must be between now and 15 minutes from now (900 seconds)
MAIUG 2015
Run Query, Send Results to Twilio • Creates an array $people
containing each row returned by the SQL query with columns mobile and barcode
• Loads the Twilio helper library (Twilio.php) to simplify sending the messages
• For each row of the array, sends a text message that contains the message body and barcode for the item due
MAIUG 2015
Send the Results to Twilio (Cont.)
• Redacts the message body in the Twilio logs
• Adds 1 to the message count
• Repeat until all rows are accounted for
• When done, runs the writeLog() function to say how many notifications were sent
MAIUG 2015
?>
• 56 lines of code (without comments) • NOTHING works right the first time • Test as much as you can before going live • Capture error messages and Google them • Ask for help!!!
MAIUG 2015
/PATH/TO/
• Files have to live somewhere on the server
• It’s a good practice to not put the files in /public_html/ or /www/ folders on your server (if possible)
MAIUG 2015
ChRONo Trigger • CRON job –executes PHP script on a schedule • Runs every 15 minutes for hourly items • Configured through Reclaim Hosting cPanel
interface • */15 * * * php /PATH/TO/script.php
– */15 = Run every 15 minutes – 2nd * = Run every hour – 3rd * = Run every day – 4th * = Run every month – Command to execute the script
• Email sent every time it’s triggered
MAIUG 2015
*Ding*
MAIUG 2015
Who’s Talking to Whom
MAIUG 2015
Reclaim Web
Server Twilio
Sierra DB
Success? • 72 patrons signed up since launch • September signup drive – entered students into
a $10 gift card drawing • Marketing committee push (balloons and candy) • 1st generation iPad at Circulation Desk with
shortcut to the form
MAIUG 2015
Future?
• Integration with Sierra 2.0 Patron API? – Haven’t moved to SP3 yet …
• Hold shelf notifications? – Need to find right SQL query
MAIUG 2015
Will This Work For You?
• Budget for web hosting & Twilio service – Depending on volume of messages, probably
less than $100/year • Unafraid of PHP, SQL, web servers • No institutional issues with using 3rd party
providers • Sense that patrons want this service
MAIUG 2015
Recommended Reading
“What is Code?” by Paul Ford – http://www.bloomberg.com/graphics/2015-
paul-ford-what-is-code/
MAIUG 2015
Links to Resources • reclaimhosting.com • twilio.com
– twilio.com/docs/php/install - PHP Helper Library • techdocs.iii.com/sierradna/ • “Automating Custom Patron Notices and Messages
Using SQL” – IUG 2015 – http://innovativeusers.org/conferences/search-
presentations.html • Gettysburg College web form
– https://www.gettysburg.edu/library/services/text-notifications.dot (please don’t spam us)
MAIUG 2015