gas-cronsheet-slack
gas-cronsheet-slack copied to clipboard
Google Apps Script to use spreadsheet for timed posts to Slack
= gas-cronsheet-slack
Google Apps Script that schedules automated posts to Slack using Spreadsheets
== Installation
- In the Slack channel where you want to post from the sheet, follow "Add a service integration..." in the menu.
- Select "Incoming WebHooks" and create one. Copy the "Webhook URL" and set the value of
WEBHOOK_URL
variable in app.js to it. - Create a https://docs.google.com/spreadsheets/[Google Spreadsheet] with first row contains two cells, "date" and "hour" in this order.
- In the sheet, follow the menu "Tools" > "Script editor...". Replace all of the code there with the contents of app.js.
- In the script, follow the menu "Resources" > "Current project's triggers". "Add a new trigger" with "Run" of
doPost
, "Events" "Time-driven", "Hour timer" and "Every hour". - For the first time, follow the menu "Run" > "doPost" to authorize the script to post to Slack.
== Configuration
The 2nd row and below are the configuration for scheduled posts. They are configured as:
|=== | "Date" | "Hour" | Title1 | Title2 | ...
| Date | Hour | Value1 | Value2 | ... | Date | Hour | Value1 | Value2 | ... |===
The script posts the title-value pairs (column C and rightward) when the time matches the date and hour condition. See examples.
=== Date format
The date (column A) can be one of:
- A date (as spreadsheet recognizes), eg. "2015-08-29".
- A comma-separated set of day names ("sun", "mon", "tue", "wed", "thu", "fri", "sat"), eg. "tue" or "sat,sun".
- "weekday" for a shorthand of "mon,tue,wed,thu,fri".
- "*" for everyday.
=== Hour format
The hour (column B) can be one of:
- A comma-separated set of 24-based hours eg. "3" or "13,14,15".
- "*" for every hour.
== Examples
=== The Sheet
image:doc/sheet.png[]
=== The Slack
image:doc/slack.png[]