NCEAS / awards-bot

Award management bot for Arctic Data Center management
6 stars 8 forks source link

awardsBot

R build status

The NSF awards bot regularly contacts principal investigators with reminders on their project specific deadlines. Please read the schedule readme for more detailed information on automated correspondences.

How the bot works

Every 24 hours the bot queries NSF's award API for newly awarded grants and stores this information in a pre-existing database. When it finds a new award it creates a new ticket in Request Tracker and sends an initial correspondence that outlines project-specific expectations and deadlines. It sends reminders to submit annual reports, submit data for Arctic Observing Network (AON) projects, and that the award is expiring soon. The bot sends a summary of the number of each type of correspondence sent and error messages to a slack channel.

Setup

Running

Run the bot cron script every 24 hours.
Example crontab: 0 15 * * * Rscript ~/home/awardsBot/main_cron_script.R

How the database works

The awards bot uses a csv file as a database. It stores metadata about each award harvested from NSF's award API, along with dates at which specific correspondences should be sent. For instance, the database includes the column contact_3mo, which lists the date when the bot should send a reminder that there are 3 months remaining until an award expires. This value is initialized to 3 months before the expDate field. Each time the bot runs, it checks whether the system date is equivalent to contact_3mo and sends a reminder email if this is true. For recurring correspondences, such as annual report reminders, the database contains previous and next response columns. For example, contact_annual_report_next specifies what date to send the reminder, and when contact_annual_report_previous is equivalent to contact_annual_report_next it will update the latter field forward by one year.

Adding a correspondence

In this example we will assume the submission policies changed to require an initial metadata submission within the first two years of an award startDate. The following steps illustrate how to send a one-time correspondence. In order to send a recurring correspondence copy the logic used by set_first_aon_data_due_date() and update_aon_data_due_date(), in addition to the following steps.

Testing the bot

The awards-bot package contains modular unit tests, however, many of these don't run, by default, unless the R session is connected to RT and Slack. A thorough test of the bot would involve signing in to RT and Slack, and running devtools::check(); although, if the test_main unit test passes it's generally safe to assume the more modular tests will pass as well.

General notes:

Testing Locally

Please follow this closely so no emails are sent to researchers by mistake while testing.

  1. Add the following lines to the .Renviron (can be accessed by usethis::edit_r_environ())

    SLACK_WEBHOOK_URL="{URL}"                # Your Slack webhook URL
    SLACK_OAUTH_TOKEN="TOKEN"
    RT_BASE_URL="https://example.com/rt"          # The URL of your RT install
    RT_USER="your_rt_user"                   # Your RT username
    RT_PASSWORD="your_rt_password"               # Your RT password
  2. Set up slackbot: slackr::slackr_setup(channel = "#awardbot", username = 'awardbot', incoming_webhook_url = Sys.getenv("SLACK_WEBHOOK_URL"), token = Sys.getenv("SLACK_OAUTH_TOKEN"))

  3. Login to RT: rt::rt_login()

  4. Run devtools::load_all() to source the scripts for testing so you can run the test file line by line

  5. Run the test_main unit test locally, ideally line by line.

  6. Two test tickets should be created in RT.

Style

Code generally follows the tidyverse style conventions, with the following specific style preferences:

Acknowledgements

Work on this package was supported by:

Additional support was provided by the National Center for Ecological Analysis and Synthesis, a Center funded by the University of California, Santa Barbara, and the State of California.