Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ssl knex #16

Open
wants to merge 284 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
284 commits
Select commit Hold shift + click to select a range
4af9517
Merge pull request #14 from codeforanchorage/data_url_config
NigelKibodeaux Aug 28, 2016
e01865a
First bit of test adjustments in web_test
tescher Aug 28, 2016
71f7fc0
Getting tests to work
tescher Sep 2, 2016
bbed7c9
Removed payable references, fixing more tests
tescher Sep 7, 2016
954fe49
some more test fixes
tescher Sep 7, 2016
9591c5b
More test fixes
tescher Sep 16, 2016
6762ed5
More test fixes
tescher Sep 16, 2016
d3ac3ee
Beginning of wording changes for web.js UI
tescher Sep 17, 2016
d9e88ba
More UI changes
tescher Sep 18, 2016
a60bbae
Fixing tests
tescher Sep 18, 2016
1112bd3
More test work
tescher Sep 19, 2016
97352ad
More tries
tescher Sep 19, 2016
eb3c046
Adding middleware
tescher Sep 19, 2016
3ec1fc4
fixed flow error
NigelKibodeaux Sep 19, 2016
c0afd5e
Middleware fixes
tescher Sep 19, 2016
77c1567
Env load for Travis
tescher Sep 19, 2016
bc3b3e2
travis fixes
tescher Sep 19, 2016
b1fe317
travis fixes
tescher Sep 19, 2016
cc127fd
more travis fixes
tescher Sep 19, 2016
c5b311f
more travis fixes
tescher Sep 19, 2016
5a244bd
travis
tescher Sep 19, 2016
b6c5137
Fix readme and test init
tescher Sep 20, 2016
465ff10
Merge pull request #17 from codeforanchorage/ui_update
tescher Sep 21, 2016
20e9b74
Update reminder text, test for changing reminder date/time.
tescher Sep 27, 2016
2f9c3dd
Fix queued days time-out tests and wording.
tescher Sep 27, 2016
62a2651
Remove console.logs
tescher Sep 27, 2016
6d55b06
Merge pull request #19 from codeforanchorage/reminder_by_citation
NigelKibodeaux Oct 3, 2016
26dcc8c
Additional timezone support (not complete)
btrott18 Oct 5, 2016
f5fd99d
Remove unnecessary comment. Issue is related to use of timezone when…
btrott18 Oct 5, 2016
a3a5875
Merge branch 'master' of https://github.com/codeforanchorage/courtbot…
btrott18 Oct 5, 2016
39e5f6f
don't error if there is no .env file
NigelKibodeaux Oct 5, 2016
607137d
Revert "don't error if there is no .env file"
NigelKibodeaux Oct 5, 2016
f021a0a
temporarily comment out dotenv thin for load data
NigelKibodeaux Oct 5, 2016
f1295bf
fixed npm loaddata script. uncommented red herring fix from load data
NigelKibodeaux Oct 5, 2016
240c1fb
let twilio break apart the messages into multiple texts
NigelKibodeaux Oct 5, 2016
1e34f6a
Cleanup and ensure tests are passing.
btrott18 Oct 5, 2016
af1ad44
Merge branch 'master' of https://github.com/codeforanchorage/courtbot…
btrott18 Oct 5, 2016
844fcb1
Fixed post-merge issues.
btrott18 Oct 5, 2016
7addfd0
Can't use templating...
btrott18 Oct 5, 2016
cab98f4
Updates per PR:
btrott18 Oct 6, 2016
528fa59
Added util for setting a date to UTC moment with anchorage offset.
btrott18 Oct 6, 2016
401a418
Refactored sendReminders code to use common functions.
btrott18 Oct 7, 2016
15e949f
Remove unnecessary log.
btrott18 Oct 7, 2016
713a38b
i think i screwed this up
NigelKibodeaux Oct 7, 2016
a895a59
Merge branch 'master' of https://github.com/codeforanchorage/courtbot…
btrott18 Oct 7, 2016
a09f62a
URL fix
NigelKibodeaux Oct 7, 2016
4394e12
Merge branch 'master' of https://github.com/codeforanchorage/courtbot…
btrott18 Oct 7, 2016
cca4000
Wrapped db/table create and delete logic into new manager.js file.
btrott18 Oct 10, 2016
69bde29
Missing dependency.
btrott18 Oct 10, 2016
f5a2c67
Use correct dependency.
btrott18 Oct 10, 2016
9ffcdd7
1.) Convert dates to UTC format including alaska offset before inser…
btrott18 Nov 8, 2016
3c76ce3
where are we failing a time-related test?
btrott18 Nov 8, 2016
4e72750
Moved knex configuration to common location.
btrott18 Nov 8, 2016
43271e6
debugging.
btrott18 Nov 8, 2016
7e530c8
trying to specify timestamp with timezone.
btrott18 Nov 8, 2016
e1b5865
no message
btrott18 Nov 8, 2016
7f58afb
turning off timekeeper
btrott18 Nov 8, 2016
3045386
timekeeper was not the problem.
btrott18 Nov 8, 2016
a74af59
Use UTC timezone and convert to UTC before comparing in a query.
btrott18 Nov 8, 2016
830e708
Merge pull request #20 from codeforanchorage/timezone-fix
tescher Nov 18, 2016
d4621f2
Added TIMEZONE env variable descriptions
brendanbabb Nov 23, 2016
5c90c0e
Change the verbiage for the reminder message
brendanbabb Dec 11, 2016
bc4d764
Changed verbiage in test for hearing vs. case
brendanbabb Dec 11, 2016
491bd1c
Merge pull request #27 from codeforanchorage/new_verbiage
tescher Dec 11, 2016
b7f9420
Changed court to hearing for reminder messages
brendanbabb Dec 16, 2016
e2c2c0e
Fixed reminder lookup and tests
tescher Jan 6, 2017
1553710
Fixed reminder lookup and tests
tescher Jan 6, 2017
97dc1c2
Fix DST problems, trim spaces, testing mode for tomorrow dates
tescher Jan 7, 2017
12dea47
README tweak
tescher Jan 7, 2017
a8484bc
Merge pull request #29 from codeforanchorage/date_fixes
brendanbabb Jan 12, 2017
b2ec607
Fix TEST_TOMORROW_DATES
tescher Jan 12, 2017
782ffe3
Merge pull request #31 from codeforanchorage/fix_test_tomorrow
brendanbabb Jan 12, 2017
d0a1ff2
Rollbar (#33) (#34)
NigelKibodeaux Mar 8, 2017
9bac012
Merge pull request #1 from codeforanchorage/master
robbiepc30 Mar 8, 2017
edf69e1
updated README.md,
robbiepc30 Mar 9, 2017
15f2e57
added rollbar logging to sendQueued.js and sendReminders.js
robbiepc30 Mar 14, 2017
9acdb7c
updated readme
robbiepc30 Mar 14, 2017
7a239af
Made suggested changes.
robbiepc30 Mar 15, 2017
57408e2
testing with mocha test for sendReminders
robbiepc30 Mar 24, 2017
7ae1436
not working but I think I'm on the right track
robbiepc30 Mar 25, 2017
8d7b1cf
making progress..
robbiepc30 Mar 25, 2017
ab73668
it works!, now I just need to clean up the code...
robbiepc30 Mar 26, 2017
53fc1a1
cleaned up test code... still needs some work on the tests
robbiepc30 Mar 26, 2017
65dfb17
oops
robbiepc30 Mar 26, 2017
06f3e4c
Found the buggit status now just need to fix the test
robbiepc30 Mar 26, 2017
d60fca8
cleaned up test a bit
robbiepc30 Mar 26, 2017
88c0e13
created test for fixed bug
robbiepc30 Mar 27, 2017
777a813
added comment where I fixed the bug to prevent it from happening agai…
robbiepc30 Mar 27, 2017
600ba44
undid some of the autoformating changes from vscode
robbiepc30 Mar 27, 2017
04c3a18
removed comment...
robbiepc30 Mar 27, 2017
cea06a5
fixed some more autoformating...
robbiepc30 Mar 27, 2017
369df0e
clarification of where user can interact with service (#40)
simonv3 Mar 28, 2017
a17e0d9
Add instructions for cloning the repository. (#38)
simonv3 Mar 28, 2017
98e061a
Close #25. Ignore signatures and emoticons in incoming SMS
simonv3 Mar 28, 2017
961c4a7
Fix typos and remove only
simonv3 Mar 28, 2017
7262816
made changes from code review
robbiepc30 Mar 28, 2017
83e09ca
Merge pull request #37 from codeforanchorage/fix-bug-issue36-with-tes…
tescher Apr 7, 2017
596637f
Merge pull request #35 from robbiepc30/update-logging-web.js-robbie
tescher Apr 7, 2017
b1b6724
Fix deprecation error in moment calls
tescher Apr 7, 2017
28f689e
Merge pull request #41 from simonv3/master
tescher Apr 7, 2017
12fcf08
Postgres tools (#42)
jamesfdavis Apr 19, 2017
da004a2
Update node version and fix test timeout
tescher Jul 14, 2017
a16ca71
Fix Travis
tescher Jul 14, 2017
c1929fd
Fix Travis
tescher Jul 14, 2017
07df08a
Merge pull request #44 from codeforanchorage/update_node
tescher Jul 18, 2017
04d8a44
Merge pull request #43 from codeforanchorage/fix-date-deprecation-error
tescher Jul 18, 2017
d56e970
Add tests for same day appointment requests
tescher Jul 29, 2017
ffe1612
Make tests pass.
tescher Jul 29, 2017
d8984a1
Remove some logging.
tescher Jul 29, 2017
cd2ad62
Merge pull request #47 from codeforanchorage/same_day_requests
tescher Aug 1, 2017
37c525e
Refactor to remove extraneous Promise wrappers from functions that al…
mark-meyer Aug 16, 2017
5fe4f75
Removed remaining extraneaous Promise routines. Updated Twilio librar…
mark-meyer Aug 16, 2017
3f16ef3
rolled back to Twilio library v. 1.6. The new version will require si…
mark-meyer Aug 16, 2017
52de13c
Inlcude package-lock.json
mark-meyer Aug 16, 2017
f1a5a05
Remove extraneous Promise
mark-meyer Aug 16, 2017
b99747f
Changing tests to accomodate promises in library
mark-meyer Aug 17, 2017
6b92882
few more changes to test promises
mark-meyer Aug 17, 2017
e95a27d
remove bluebird depnedency
mark-meyer Aug 17, 2017
ef55825
remove bluebird depnedency
mark-meyer Aug 17, 2017
3243b5c
Remove utils/promises.js - it's no longer used anywhere
mark-meyer Aug 17, 2017
a0fa690
change raw sql strings to es6 template strings to ease pain of concat…
mark-meyer Aug 17, 2017
7fbf074
Allow reminder requests same day as original hearing
tescher Aug 26, 2017
5cc5db7
fix escape SQL function
mark-meyer Aug 30, 2017
c94cfcd
escapeSQL() deletes all non-alphanumerica characters
mark-meyer Aug 31, 2017
8ff23a7
Add ability to set seperate DB for test, development, and production
mark-meyer Sep 2, 2017
29347b2
Add db_connections file
mark-meyer Sep 2, 2017
ca1c34c
fix spaceing and add .js to db_connections
mark-meyer Sep 5, 2017
b75a42f
Merge pull request #48 from codeforanchorage/same_day_requests_2
tescher Sep 8, 2017
5564a78
Merge pull request #51 from codeforanchorage/sanitize_fix
tescher Sep 8, 2017
2863041
allow hyphen in citation id
mark-meyer Sep 10, 2017
ea0ad41
Added new escapeSQL function to strip everything except letters, numb…
mark-meyer Sep 10, 2017
656649d
Fixed merge conflicts from master
mark-meyer Sep 10, 2017
a9ef244
return promise to mocha instead of then(done)/catch(done)
mark-meyer Sep 10, 2017
45c6696
Change column type of citation to jsonb and change querries to match
mark-meyer Sep 10, 2017
c49469e
_createIndexForCases wasn't creating index on cases. then() needs to …
mark-meyer Sep 10, 2017
d9890d1
Fix promise code so it returns properly from then()
mark-meyer Sep 10, 2017
e90fb4e
Merge pull request #53 from codeforanchorage/escapeFix
tescher Sep 11, 2017
4080a86
Cleaned up to fix indentation mistake, and remove unnecessary timeout…
mark-meyer Sep 11, 2017
4aade53
Cleaned up to fix indentation mistake, and remove unnecessary timeout…
mark-meyer Sep 11, 2017
ce9936c
remove underscore dependency, which was only being used for _.find an…
mark-meyer Sep 11, 2017
9751001
const requires
mark-meyer Sep 11, 2017
bf28afe
-fix merge conflict
mark-meyer Sep 12, 2017
9519fb4
Merge branch 'master' into test_db
mark-meyer Sep 12, 2017
29cb1e3
add test db to Travis
mark-meyer Sep 12, 2017
4c2416a
take two
mark-meyer Sep 12, 2017
aa3dd62
getting travis to install db
mark-meyer Sep 12, 2017
7747992
Merge pull request #52 from codeforanchorage/test_db
tescher Sep 12, 2017
b3cbb46
merge master changes
mark-meyer Sep 12, 2017
a341e5b
use rollbar, structure like other runners
mfrederickson Sep 14, 2017
978a191
load data using specified extractor method
mfrederickson Sep 14, 2017
7d6cfa7
add criminal cases fixture
mfrederickson Sep 14, 2017
77d2ee9
test both data files
mfrederickson Sep 14, 2017
02a84cd
accomodate mock data urls
mfrederickson Sep 14, 2017
de4b51d
adjust for error object return
mfrederickson Sep 14, 2017
bcb7690
eslint placations, comments
mfrederickson Sep 14, 2017
e179448
style and script like messaging on phone
mfrederickson Sep 14, 2017
774ea70
add COURT_NAME
mfrederickson Sep 15, 2017
982232c
use COURT_NAME env var
mfrederickson Sep 15, 2017
e084ac2
renamed geeting message
mfrederickson Sep 15, 2017
12d4b63
leverage messages.js in web.js and some eslint placations
mfrederickson Sep 15, 2017
c75dbf0
eslint placations
mfrederickson Sep 15, 2017
ee0c50a
use catch
mfrederickson Sep 15, 2017
1d7d3f1
hide internals
mfrederickson Sep 15, 2017
7944e13
unhide findReminders since used in test
mfrederickson Sep 15, 2017
8c04363
eslint placations, consistency
mfrederickson Sep 15, 2017
ab4e238
eslint placations, use catch
mfrederickson Sep 15, 2017
7da808f
revert arrow functions on mocha calls
mfrederickson Sep 15, 2017
711422a
Merge pull request #56 from mfrederickson/load_criminal_cases
mark-meyer Sep 15, 2017
94e83c2
Merge pull request #59 from mfrederickson/web_use_messages
mark-meyer Sep 15, 2017
58a7535
Merge pull request #60 from mfrederickson/send_reminders_eslinting
mark-meyer Sep 15, 2017
94f7571
Fix merge -- use standard gin index instead of custom function
mark-meyer Sep 15, 2017
c8e2199
replace whereRaw querries with where to allow knex to handle user inp…
mark-meyer Sep 15, 2017
8ea36ad
Merge pull request #49 from codeforanchorage/simplePromises
tescher Sep 19, 2017
3c2ee36
Merge branch 'master' into nicer_test_page
mfrederickson Sep 19, 2017
652768a
Simple promises (#65)
mark-meyer Sep 20, 2017
2cf3a3b
Merge remote-tracking branch 'origin/master' into nicer_test_page
mfrederickson Oct 6, 2017
68d04dc
V2 (#69)
mark-meyer Apr 4, 2018
9ee3e9b
change language in outgoing message to include case/ticket ID and use…
mark-meyer Jun 26, 2018
6ff7536
fix some tests to account for message change
mark-meyer Jun 26, 2018
06a1aca
fix tests to reflect new outgoing message
mark-meyer Jun 26, 2018
8f64056
Change response to "yes" to use "verify" instead of "confirm"
mark-meyer Jul 16, 2018
4a1fa75
Merge pull request #74 from codeforanchorage/messageChange
brendanbabb Jul 16, 2018
69e1c7b
add splash page for courtbot (#76)
mark-meyer Aug 8, 2018
7b0cba0
small typo in splash page (#78)
mark-meyer Aug 8, 2018
3301888
Create CNAME
NigelKibodeaux Aug 8, 2018
c97dd1d
Make 'How To' text more prominent and remove 'as is' clause.
mark-meyer Aug 9, 2018
4b9811e
Merge branch 'master' into nicer_test_page
mfrederickson Aug 10, 2018
bc422b9
#58 update font, use newer twilio response fmt
mfrederickson Aug 10, 2018
5d60527
fix typos, use table for schedule
mfrederickson Aug 10, 2018
ff81659
markup for commands
mfrederickson Aug 10, 2018
ec27ccf
fix 'required' typo
mfrederickson Aug 10, 2018
dde3037
Merge pull request #79 from codeforanchorage/splash_edits
brendanbabb Aug 10, 2018
37337ae
Merge branch 'master' into nicer_test_page
brendanbabb Aug 10, 2018
77d6dc5
Merge pull request #58 from mfrederickson/nicer_test_page
brendanbabb Aug 10, 2018
ad1ee8f
Merge branch 'master' into update-typos-and-schedule
brendanbabb Aug 10, 2018
44102ae
Merge pull request #80 from mfrederickson/update-typos-and-schedule
brendanbabb Aug 10, 2018
84357e5
specify versions required for node and pg
mfrederickson Aug 11, 2018
3e232b4
Merge pull request #81 from mfrederickson/update-readme-versions
brendanbabb Aug 11, 2018
daedb1f
Adding instructions for unfollowing an individual case.
brendanbabb Aug 11, 2018
192a34e
Added Google Analtyics Code and shortened individual case desc.
brendanbabb Aug 11, 2018
5dd1169
easier table creation
mfrederickson Aug 16, 2018
8f6d7e4
npm updates for security fixes
mfrederickson Aug 16, 2018
a2b263e
easier table creation
mfrederickson Aug 16, 2018
171d7a0
updates
mfrederickson Aug 16, 2018
f4aa5d8
updates
mfrederickson Aug 16, 2018
6ebcd7e
remove noconsole eslint directive
mfrederickson Aug 16, 2018
2f425e0
update single connection handling
mfrederickson Aug 16, 2018
8fb8af5
close the connection when the stream is done
mfrederickson Aug 16, 2018
6b4dd11
add --exit flag for mocha 4
mfrederickson Aug 16, 2018
c524950
fix indentation
mfrederickson Aug 16, 2018
031ebc8
attach close handler immediately after acquiring
mfrederickson Aug 17, 2018
30f4a7a
fix per comments
mfrederickson Aug 17, 2018
427176f
Merge pull request #82 from mfrederickson/security-updates
brendanbabb Aug 22, 2018
e7d6412
Retry load script on five minute intervals on failure
mark-meyer Sep 27, 2018
5702ac0
add log line when retrying
mark-meyer Sep 27, 2018
b7b4e21
only retry on http errors. DB errors or other bugs should probably no…
mark-meyer Sep 27, 2018
7c8a980
Add Social Media cards
brendanbabb Oct 3, 2018
ad8973b
Add Social Media cards to the correct file
brendanbabb Oct 4, 2018
f13fac4
Merge branch 'master' into retryLoad
mark-meyer Oct 12, 2018
201ec9d
Merge pull request #86 from codeforanchorage/retryLoad
mark-meyer Oct 12, 2018
4e41cef
Adds a module to manage a test case. The test case number should be s…
mark-meyer Oct 24, 2018
bf01811
add files from last commit
mark-meyer Oct 26, 2018
d856c1b
Fix Readme to add missing parts
tescher Oct 31, 2018
eb5b477
Add repository
tescher Oct 31, 2018
4d575d1
Tweak
tescher Oct 31, 2018
fb7a931
Missing comma
tescher Oct 31, 2018
431fd67
More tweaks
tescher Oct 31, 2018
fe9b280
More Postgres clarification
tescher Oct 31, 2018
5668f49
Copy of environment variables
tescher Oct 31, 2018
7c0f176
Sample env
tescher Oct 31, 2018
890f3dd
Merge pull request #88 from codeforanchorage/fix_readme
mark-meyer Nov 14, 2018
e1d25e9
Merge branch 'master' into testcase
mark-meyer Nov 14, 2018
1de3420
Merge pull request #89 from codeforanchorage/testcase
mark-meyer Nov 14, 2018
4275587
add callout box with testcase instructions to splash page
mark-meyer Apr 4, 2019
c321f2a
Merge pull request #93 from codeforanchorage/demo_box
brendanbabb Apr 4, 2019
9e5e908
Bump lodash from 4.17.10 to 4.17.15
dependabot[bot] Jun 10, 2020
61562ac
Bump mixin-deep from 1.3.1 to 1.3.2
dependabot[bot] Jun 10, 2020
905dbd4
Merge pull request #97 from codeforanchorage/dependabot/npm_and_yarn/…
brendanbabb Jun 10, 2020
5552186
Merge branch 'master' into dependabot/npm_and_yarn/lodash-4.17.15
JazonBurnell Jun 10, 2020
0c48fb2
Merge pull request #95 from codeforanchorage/dependabot/npm_and_yarn/…
mark-meyer Jun 10, 2020
978714b
Bump extend from 3.0.1 to 3.0.2
dependabot[bot] Jun 10, 2020
f8ed94a
Bump diff from 3.2.0 to 3.5.0
dependabot[bot] Jun 10, 2020
4e0b9e8
Merge pull request #98 from codeforanchorage/dependabot/npm_and_yarn/…
brendanbabb Jun 10, 2020
103d58b
Merge branch 'master' into dependabot/npm_and_yarn/extend-3.0.2
brendanbabb Jun 10, 2020
5e8371d
Merge pull request #99 from codeforanchorage/dependabot/npm_and_yarn/…
brendanbabb Jun 10, 2020
edf9b95
Bump knex from 0.15.2 to 0.19.5
dependabot[bot] Jun 10, 2020
96168ef
Merge pull request #96 from codeforanchorage/dependabot/npm_and_yarn/…
brendanbabb Jun 10, 2020
2449078
Bump csv package
brendanbabb Jun 10, 2020
f3a9603
update package-lock
mark-meyer Jun 10, 2020
8ad4b23
add ssl to knex connection string
mark-meyer Mar 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
COOKIE_SECRET=insert-random-string
TWILIO_ACCOUNT_SID=add-twilio-sid-here
TWILIO_AUTH_TOKEN=add-auth-token-here
TWILIO_PHONE_NUMBER=+15555555555
PHONE_ENCRYPTION_KEY=insert-random-string
DATABASE_URL=postgres://courtbot:courtbot@localhost:5432/courtbotdb
DATABASE_TEST_URL=postgres://courtbot:courtbot@localhost:5432/courtbotdb_test
DATA_URL=http://courtrecords.alaska.gov/MAJIC/sandbox/acs_mo_event.csv
QUEUE_TTL_DAYS=10
COURT_PUBLIC_URL=http://courts.alaska.gov
COURT_NAME=Alaska State Court System
TZ=America/Anchorage
ADMIN_LOGIN=some_login
ADMIN_PASSWORD=some_password
JWT_SECRET=hash_secret_for_web_token
TEST_CASE_NUMBER=TESTCASE
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ utils/tmp/*
!utils/tmp/.gitkeep
TODO
.idea
.vscode/
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: node_js
node_js:
- "8.6.0"
services:
- postgresql
env:
- DATABASE_TEST_URL=postgres://localhost:5432/courtbotdb_test
before_script:
- psql -c 'create database courtbotdb_test;' -U postgres
- cp .env.sample .env
- npm run dbsetup
- export TZ=America/Anchorage
addons:
postgresql: "9.6"
113 changes: 94 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,79 @@
[![Build Status](https://travis-ci.org/codeforanchorage/courtbot.svg?branch=master)](https://travis-ci.org/codeforanchorage/courtbot)
## Courtbot

Courtbot is a simple web service for handling court case data. It offers a basic HTTP endpoint for integration with websites, and a set of advanced twilio workflows to handle text-based lookup.

Specifically, the twilio features include:

- **Payable Prompt.** If a case can be paid immediately, the app offers a phone number and link to begin payment.
- **Reminders.** If a case requires a court appearance, the app allows users to sign up for reminders, served 24 hours in advance of the case.
- **Queued Cases.** If a case isn't in the system (usually because it takes two weeks for paper citations to be put into the computer), the app allows users to get information when it becomes available. The app continues checking each day for up to 16 days and sends the case information when found (or an apology if not).
- **Requests.** If a case requires a court appearance, the app allows users to sign up for reminders, served 24 hours in advance of the case.
- **Unmatched Cases.** If a case isn't in the system (usually because it takes two weeks for paper citations to be put into the computer), the app allows users to get information when it becomes available. The app continues checking each day for a number of days (set by config QUEUE_TTL_DAYS) and sends the case information when found (or an apology if not).

## Datamodel
The main features of the app use three tables in a PostgreSQL database:
1. hearings | This table has the data about upcoming cases. It is recreated each time *runners/load.js* is exectued from the csv files found at urls set in config variable *DATA_URL*. It is ephemeral — it is recreated from scratch every day so the app must be prepared for cases that are there one day and not there the next. It is possible for the CSV to have duplicate rows. The load script enforces unique *case_ids*.
2. requests | This table stores the requests for notifications. Each row requires a phone number, which is encrypted using config *PHONE_ENCRYPTION_KEY*, and a *case_id*. The table also has columns *known_case* and *active*. *known_case* allows the app to distinguish between cases that we have seen *at some point* in the hearings table. Requests for cases where *known_case* is false will expire after *QUEUE_TTL_DAYS* and *active* will be set to false. If the case appears at anytime before that *known_case* will be set to true and the request will not expire unless a user manually turns it off by texting DELETE after sending the case. The requests table uses the column *updated_at* to determine if an unmatched case has expired rather than *created_at*. These will generally be the same, but it allows for the future possibility of allowing unmatched cases to be extended.
3. notifications | Rows in the notifications table are added whenever the app sends the user a notification. These can include notifications the day before a hearing or notifications that an unmatched case was not found within QUEUE_TTL_DAYS. The table has columns for *case_id* and *phone_number* which link the case to the person recieving the notification. It also has the following columns:
* *created_at* timestamp, which should correspond to the time the notification is sent
* *event_date* the date of the hearing at the time the notification was sent. This may or may not be the date in current versions of the csv as this changes frequently.
* *type* enumeration to distinguish between hearing notifications [reminder], matched [matched] cases, and expired cases that were not found within QUEUE_TTL_DAYS [expired]
* *error* an error string if sending a notification failed (perhaps due to a twilio error or bad phone number).

See *sendReminders.js* and *sendUnmatched.js* for examples of SQL using these tables.

The database also has tables *log_hits* and *log_runners*. These log activity of the app.

## Running Locally

First, install [node](https://github.com/codeforamerica/howto/blob/master/Node.js.md), [postgres](https://github.com/codeforamerica/howto/blob/master/PostgreSQL.md), and [foreman](https://github.com/ddollar/foreman).
First, install [node](https://github.com/codeforamerica/howto/blob/master/Node.js.md) (atleast version 7.6), and [postgres](https://github.com/codeforamerica/howto/blob/master/PostgreSQL.md) (at least version 9.5).

Then clone the repository into a folder called courtbot:

```console
git clone [email protected]:codeforanchorage/courtbot.git courtbot
cd courtbot
```

Since the app uses twilio to send text messages, it requires a bit of configuration. Get a [twilio account](http://www.twilio.com/), create a .env file by running `cp .env.sample .env`, and add your twilio authentication information. While you're there, add a cookie secret and an encryption key (long random strings).

Install node dependencies

```console
npm install
```

Define a new PostgreSQL user account, give it a password. You might have to create a postgres account for yourself first with superuser permissions if you don't have one already, or use sudo -u postgres before these commands.

```
createuser courtbot --pwprompt
```

Create a new PostgreSQL database and a database to run tests.

```
createdb courtbotdb -O courtbot
createdb courtbotdb_test -O courtbot
```

Set up your environment variables. This may require some customization-- especially the DATABASE_TEST_URL.

```
cp .env.sample .env
```

Then, to create the tables and load in initial data:

```console
node utils/createQueuedTable.js
node utils/createRemindersTable.js
node utils/createTables.js
node runners/load.js
```

Since the app uses twilio to send text messages, it requires a bit of configuration. Get a [twilio account](http://www.twilio.com/), create a .env file by running `mv .env.sample .env`, and add your twilio authentication information. While you're there, add a cookie secret and an encryption key (long random strings).

To start the web service:

```console
foreman start
npm start
```

Now you can interact with a mock of the service at http://localhost:5000.

## Deploying to Heroku

First, get a twilio account and auth token as described above. Then:
Expand All @@ -36,23 +82,52 @@ First, get a twilio account and auth token as described above. Then:
heroku create <app name>
heroku addons:add heroku-postgresql
heroku addons:add scheduler
heroku addons:create rollbar:free (only add if you do NOT have another rollbar account you want to use)
heroku config:set COOKIE_SECRET=<random string>
heroku config:set TWILIO_ACCOUNT=<twilio account>
heroku config:set ROLLBAR_ACCESS_TOKEN = <rollbar access token> (only needed if you did NOT use the heroku addon for rollbar)
heroku config:set ROLLBAR_ENDPOINT = <rollbar endpoint> (only needed if you did NOT use the heroku addon for rollbar)
heroku config:set TWILIO_ACCOUNT_SID=<twilio account>
heroku config:set TWILIO_AUTH_TOKEN=<twilio auth token>
heroku config:set TWILIO_PHONE_NUMBER=<twilio phone number>
heroku config:set PHONE_ENCRYPTION_KEY=<random string>
heroku config:set DATA_URL=<court records csv location>
heroku config:set COURT_PUBLIC_URL=<where to send people for more info>
heroku config:set COURT_NAME=<name of court system>
heroku config:set QUEUE_TTL_DAYS=<# days to keep a citation on the search queue>
heroku config:set TZ=<standard timezone ex. America/Anchorage>
heroku config:set TEST_TOMORROW_DATES=<1 if you want all court dates to be tomorrow to test reminders>
heroku config:set ADMIN_LOGIN=<user name for access to admin api>
heroku config:set ADMIN_PASSWORD=<password for access to admin api>
heroku config:set JWT_SECRET=<random string to be used to create json web token when authenticating admin api>
heroku config:set TESTCASE=<case number for testing>
git push heroku master
heroku run node utils/createQueuedTable.js
heroku run node utils/createRemindersTable.js
heroku run node utils/createRequestsTable.js
heroku run node utils/createNotificationsTable.js
heroku run node runners/load.js
heroku open
```

Finally, you'll want to setup scheduler to run the various tasks each day. Here's the recommended config:
The dotenv module will try to load the *.env* file to get the environment variables as an alternative to the above "heroku config" commands.
If you don't have this file, dotenv will throw an ENOENT error, but things will still work. To get rid of this error, do this:
```
heroku run bash --app <APP_NAME>
touch .env
exit
```

### Setting up the Scheduler

Finally, you'll want to set up the [scheduler](https://elements.heroku.com/addons/scheduler) addon to run the various tasks each day. Here's the recommended configuration:

![scheduler settings](https://cloud.githubusercontent.com/assets/1435836/4785655/2893dd9a-5d83-11e4-9618-d743bee27d2f.png)
| Task | Dyno Size | Frequency | At |
| --- | :---: | :--: | :--: |
| `node runners/load.js` | 1X | Daily | 8am |
| `node runners/sendReminders.js` | 1X | Daily | 5pm |
| `node runners/sendUnmatched.js` | 1X | Daily |5:30pm |

## Scheduler Changes
* node runners/load.js
* node runners/sendQueued.js
* node runners/sendReminders.js

## Running Tests

```
npm test
```
Loading