- Custom emojis and text
- Write custom functions to set the status how you'd like depending on event properties like colour, title, type
- Doesn't overwrite a user-defined status
- Only updates when a status changes
- Accurate to within 1 minute
- Create a new Google Apps Script project at https://script.google.com
- Add the "Calendar v3" service by clicking '+' next to "Services" on the left
- Paste the code from
Code.gs
- Create a Slack app and go to "OAuth & Permissions"
- Add User Token Scopes of
users.profile:read
andusers.profile:write
- Install to Series Eight
- Copy User OAuth Token
- Add User Token Scopes of
- Populate constants:
CALENDAR_ID
— probably your email address, you can find from Calendar Settings in Google CalendarSLACK_TOKEN
— User token from aboveSLACK_USER
— Slack User ID, go to your profile in Slack, kebab menu, then "Copy Member ID"
- Customise
statuses
andstatusConditions
(see below) - Add a trigger within Apps Script
- "Triggers" on the left (the clock icon)
- "Add Trigger"
- "Choose which function to run" —
main
- "Select type of time-based trigger" —
Minutes timer
- "Select minute interval" —
Every minute
- Save
- Confirm it works and use the "Executions" log to see execution status and any logging
Statuses is an object that defines your Slack statuses. The key is a custom key that is returned by status conditions. The value is an array of emoji and text. The emoji should be in Slack's format of :emoji_name:
. This is easily found by copying+pasting from the Slack message field.
Status conditions is an array of predicate functions that run sequentially. The functions are passed a single parameter of an array of all events running at that time. The first function to return defines the status, so you can choose a priority order if you have multiple events at once. Consider using .find()
with a condition. If a function returns null
, it moved onto the next one in the array.
// clear the status when there are no events
(events) => events.length === 0 ? 'none' : null
// based on the color set within Google Calendar
(events) => {
return events.find(event => event.colorId === '11') ? 'client-call' : null
}
// based on event name
(events) => {
return events.find(event => event.summary.toLowerCase() === 'team social') ? 'social' : null
}
You get the full event object from Google Calendar so you can do loads with it. The easiest way to find what properties you can use for events is to log your events:
const statusConditions = [
(events) => Logger.log(events)
]
You can manually trigger a function within the script editor from the top of the code window. In the dropdown pick the main
function and then click Run and it will force run the script and show the output. Helpful for debugging.
You can also force a cache clear by running the clearCache
function in the same way.
cacheEvents
— to avoid fetching unnecessarily fetching events from Google Calendar every minute we cache them for cacheEvents
number of seconds. This is 10 minutes by default but can be changed if needed.
debug
— default false, this adds additional logging, will set the status every minute instead of only when the status changes and disables the cache.