This is a step by step instruction page on how to set up a custom slack slash-function that is integrated with a google sheet to log when lab members check in and out of the lab. I developed this app based on this tutorial. I am not a professional app developer, so please be understanding if something isn’t working exactly how you want it to. However, I tried my best to make it customizable and easy to use and I am always happy to help.
This script provides a simple way for lab members to check into and out of a specific lab station (i.e. Blue) and shift number (i.e. 2) with a slack slash command (i.e. /check-in Rosalind blue 2
). It records these check-in and check-out events in a google sheet in 2 ways. One is a sheet called Current Day which is a quick overview of who has checked into and out of each station during the current day and the previous day.
The second recording is an event log that records every check-in and check-out event forever (or until your google sheet runs out of cells). This could be useful in the event that contact tracing is necessary.
If you do not need to have shifts and stations, check out a second version of this code that was developed by Dr Karen Fleming from Johns Hopkins University. This version of the code tracks who is checking in and checking out as well the total number of people in the lab at once. For this version of the code head to the lab_count_version folder in this project
The script also has optional functionality that sends messages to a slack channel every time someone checks in and checks out or if someone does not check-out of their shift. This can provide real-time updates to groups who have safety concerns of people working late at night or want to make sure everyone makes it through their shift safely.
The script is currently configured to have 4 stations and 3 shifts. It is easily customizable to have more or less stations and more or less shifts (up to 5).
This guide and the scripts were developed by Sophie Shoemaker, for any problems, please create a github issue. I am happy to help with set-up issues and minor customization issues. However, if you are requesting custom functionality I may decline your request out of time constraints.
If you find that this tool is really useful for your lab and you think that under non-pandemic times you might have offered to buy me a coffee, feel free to pass that sentiment on by buying me a virtual coffee. From now until the end of July, all donations received will be re-donated to Community Resources for Science which is an amazing organization that provides resources and support for schools in the Bay Area to facilitate science experiences for students, especially for low-income schools. In this time of distance learning and inequity in STEM, their mission is of utmost importance. Help me help them!
- Copy the format of this google sheet. Make sure you get both tabs (‘Current Day’ and ‘Event Log’). If you want to change the name of your stations, you can on the ‘Current Day’ tab, but later you will have to also make a change within the script. Ensure you DO NOT change the positions of the columns or rows, this will break the script. Even if you have less than 5 shifts, make sure to leave all of the rows under each date (i.e. yesterdays date should be in A8 because you did not move anything). The dates in cells A1 and A8 can be changed to the current days date and will continually update with the new dates.
- Instructions on how to add more or less stations or shifts are at the bottom of this tutorial
- In the google sheet you just set up, create a new script in Tools>Script Editor.
- Delete all of the text in the existing script (function MyFunction … etc) and copy in this script.
- You can name this script at the top anything you want. It is not important.
- Save this
- This is the place that if you want to rename your stations, you should do it now. You will see these lines starting at line 7:
- Leave the variable names (BLUE, RED, YELLOW, GREEN) but change the part in the quotes. The order they are in is the order they appear in the sheet. So if you wanted your stations to be named Alanine, Tyrosine, Leucine and Proline you would want to change these lines to look like the following picture. DO NOT CHANGE ANY OTHER LINES.
- If you make these changes make sure to save your script.
- Go to Publish>Deploy as web app and a window should pop up
- Fill it out to look like this (make sure it says “Anyone, even anonymous” under “Who has access to this app:")
- Click deploy (it may ask you to login to your account to check permissions)
- Copy the URL in the box and click okay.
- Go to the Slack API homepage and click “Start Building”
- Give your app a name (e.g. “Check In Tool”)
- Click “Add features and functionality”
- Click “Slash Commands”
- Click “Create New Command”
- Fill it out to look like this, pasting in the URL that you copied in step 4 of this part:
- Click Save
- Click “Create New Command”
- Fill it out to look like this, pasting in the URL that you copied in step 4 of this part:
- Click Save
- On the left hand side click ‘Basic Information’
- Click on “Install your app to your workspace” (middle of page) and then click on the big green button that says “Install App to Workspace”
- You should be taken to a new page requesting permission to access the Slack workspace. Click “Allow”
- Go to your slack workspace. From ANY CHANNEL (would recommend either your Slackbot channel or your Direct message to yourself to reduce clutter)
- Put in a test check-in
- Go to the Google Sheet and see if your entry was logged on BOTH the “Current Day” and “Event Log” tabs.
- If you do not see these changes in your sheet, something is wrong. Maybe go back through the steps to make sure you didn’t miss something. Otherwise create a github issue.
- Similarly test your /check-out function (same way as above, but with the /check-out command). You should get a check-out message that says “See you next time”
- Naturally at the end of the day, we will want to shift down responses on the “Current Day” sheet (so we have a 1 day log of who was where) so we are ready for the next day.
- Go back to your Google Sheets App (created in Step 2)
- In the tool bar click the “Current Triggers” button (it looks like a clock speech bubble)
- This should take you to the “Triggers” page which currently should be empty.
- Click “+ Add Trigger”
- Fill out the “Add Trigger for Testing” with the following parameters:
- Click Save
- To test this part, I would recommend making some check-in’s and outs and then tomorrow morning checking the sheet to make sure that the daily entries were moved down to the previous spot. The dates on the sheet should also be updated. 1. Note this functionality does not change anything on the “Event Log” tab
- This is optional, it just has messages sent to a slack channel in your workspace alerting people to who is checking into what station when.
- In your slack workspace, create a slack channel where you want these messages to go to (mine is named #lab-check-in-log) Set the const variable at the top of Google Sheets Script called “SEND_TO_SLACK” to true
- Change the const variable at the top of Google Sheets Script called “CHECK_IN_CHANNEL” to be the name of this channel (including the #)
- Go to the slack incoming webhooks page
- In the Post to Channel drop down select the channel you created. Click “Add integration”
- Copy the Webhook URL
- At the top of the google sheets script there is a variable called url, paste in the url you just copied.
- Test this out by checking someone in or out and see if it is posted to the channel you set up.
- This is an optional function that will check after each shift to make sure everyone has checked out and if they have not send a warning message to the same slack channel as in step 6. If you only want step 7 functionality and not step 6, follow the instructions of step 6 except for part 3.
- Set the const variable WARN_IF_NO_CHECK_OUT at the top of the script to true.
- Starting in line 20, you will see const variables that are the times that each shift ends. Change these to be the times that you want to check if each shift has checked out. 1. If you add more shifts (instructions to do that is near the end), add additional variables (i.e. const CHECKOUT_4 = 23) and then also add them to the const CHECKOUT_TIMES list. (i.e. const CHECKOUT_TIMES = [CHECKOUT_1, CHECKOUT_2, CHECKOUT_3, CHECKOUT_4]
- Now you need to set triggers for checking similar to what you did in Step 5 with the autoClear.
- First go to triggers
- Click the “+ Add Trigger” button in the bottom right corner.
- Fill out the options to look like this:
- Change the “Select time of day” to match the hour at which your shift ends
- Repeat b and c for the other times that your shifts end. (i.e. if you have 3 shifts, you will need 3 triggers, one at each shift end time)
- You will need to save the script and publish it as described before.
- You should test this by signing yourself in and not out and then wait to see if the slack message is sent to the channel
- So what happens if someone signs into the wrong station and then the other person needs to sign in. This is not a huge deal, because regardless of what the “Current Day” Sheet says, all of the check-in and check-out events are recorded in the Event Log, so you can sort out issues later. But you can decide how you want to handle what happens when this occurs.
- By default the WARN option is initialized. This means that if Rosalind accidentally signs into Blue shift 1 (which is really Barbara’s shift), when Barbara goes to sign in she will get a message that says “You overrode Rosalind's check in to this station. Please check the schedule and make sure this is correct”. Barbara will realize what happened and let Rosalind know she made an error so she can fix it. Or if it was truly Rosalind’s shift and Barbara made the error, Barbara can apologize to Rosalind and sign Rosalind back in and sign herself into the correct shift. They can then also manually fix the entries in the event log or let someone know about the issue.
- Another option is ALLOW. This would just allow Barbara to override Rosalind’s check-in, without alerting her. Then when Rosalind goes to check-out she will find she’s unable to and then will have to work with Barbara to figure out how to fix the event log.
- The last option is FORBID. This would tell Barbara that “You cannot check into this station because Rosalind is checked in”. Barbara would then have to figure out what went wrong with Rosalind and then contact whoever has editing permission on the google sheet and ask them to fix the blunder. This is the best option if you only want a supervisor to be allowed to override people through the google sheet.
- Choose an option, if it is ALLOW or FORBID, change the const variable “OVERRIDE_OPT” at the top of the shet.
- This is a bit more involved. If you want less stations, it’s fairly simple. Just delete the extra const variables (start with GREEN, then YELLOW, then RED) and then also delete them from the var stations list. This should just not allow anyone to check into the other stations. You can then delete these columns from the google sheet. So the top of the script should look like this with your station names.
- If you want to add stations you will have to add more const variables for the stations and then add them to the list. You will also have to add the column that this station should report to in a variable called something like PURPLE_COL. Then in the getStationColumn function you will have to add the station name and column to the switch statement. So for example if I added 1 station my script would look like this starting at line 7:
- Then you would just need to add the new column headers for the new station starting at column 14 (N).
Currently this script only supports numbers of shifts between 1 and 5. Simply change the NUM_SHIFTS variable in line 13 to reflect the number of shifts you want. Then make sure to change the row titles in your Google Sheet.
If you want more than 5 shifts, you can try to figure out the code to how to add more. It’s not overly complicated but you’ll have to figure out where all of the writing to each set comes from. If you would like help doing this, contact me and I may be able to help.