Google Apps Script that schedules automated posts to Slack using Spreadsheets
-
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 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.
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.
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.