A production-ready Google Apps Script (V8 runtime) integration with Slack and Google Sheets. It provides two automated workflows:
- Bi-Directional Roster Sync Bot (
RosterWorkflow): Synchronizes workspace member profiles and custom metadata between Google Sheets and Slack profiles usingusers.listandusers.profile.set. - Interactive Timed Polling Bot (
PollWorkflow): Supports slash commands (/poll), Block Kit interactive voting with dynamic vote-tally bars (⦿/○), instant in-channel replacement (sub-second response), and automatic poll expiration with thread summaries.
├── config.js # Environment variable access, sheet column mapping, and Slack field IDs
├── core.js # Sheet manager (auto-headers) and Slack API HTTP client (token routing)
├── workflows.js # RosterWorkflow and PollWorkflow logic
├── main.js # doPost webhook entrypoint, triggers, and spreadsheet custom menu
├── appsscript.json # Apps Script manifest and OAuth scopes
├── .clasp.json.example # Clasp configuration template
└── README.md # Documentation and setup instructions
- PULL (
pullSlackData):- Fetches workspace members via
users.list(ignores bots andUSLACKBOT). - Maps standard profile fields and custom profile metadata.
- Preserves existing sheet data if corresponding Slack fields are blank.
- Upserts by Slack User ID and marks account status (
Active/Deactivated).
- Fetches workspace members via
- PUSH (
bulkPushToSlack):- Iterates active members in Google Sheets and pushes edits to Slack via
users.profile.set. - Gracefully skips deactivated accounts and handles admin/owner permission boundaries (
cannot_update_admin_user). - Stamps updated timestamp in Column K (
Updated At).
- Iterates active members in Google Sheets and pushes edits to Slack via
- Daily Sync (
runDailySync):- Runs both push and pull routines and broadcasts an aggregated report to your configured summary channel.
- Slash Command (
/poll):- Syntax:
/poll "Question" "Option 1" "Option 2" [duration](e.g.30m,2h, defaulting to24h). - Supports smart/curly quotes (
“,”) and standard double quotes ("). - Sends Block Kit message with
<!channel>broadcast and records state inActivePolls.
- Syntax:
- Interactive Button Voting:
- Single-choice voting with toggle-off support (clicking the same option removes your vote; clicking a different option switches your vote).
- Parses current voter state directly from
payload.message.blockswith zero database read latency and immediately updates Slack viapayload.response_url(~200ms execution), followed by background persistence toActivePolls.
- Auto-Expiration:
- Minute-level time-driven trigger (
minuteTrigger). - Closes expired polls, disables buttons (
🔒 *CLOSED*), and posts final tallies with voter mentions into the message thread.
- Minute-level time-driven trigger (
git clone https://github.com/<your-username>/<your-repo-name>.git
cd <your-repo-name>
cp .clasp.json.example .clasp.jsonEdit .clasp.json and insert your Google Apps Script scriptId.
Push files to your Apps Script project:
npx clasp login
npx clasp push(Alternatively, you can copy the .js files directly into the Apps Script online editor).
- Go to api.slack.com/apps and create a New App (From scratch).
- Go to OAuth & Permissions:
- Bot Token Scopes (
xoxb-...):commandschat:writechannels:join(Allows the bot to auto-join public channels to trigger@channelnotifications)users:readusers.profile:read
- User Token Scopes (
xoxp-...):users.profile:write(Authorize as Primary Workspace Owner to enable editing all member profiles).
- Bot Token Scopes (
- Install the app to your workspace and copy the tokens.
In the Google Apps Script editor, navigate to Project Settings (⚙️) > Script Properties and add:
| Property Name | Description | Example |
|---|---|---|
SLACK_TOKEN |
Bot User OAuth Token | xoxb-... |
USER_TOKEN |
User OAuth Token (Primary Owner) | xoxp-... |
SUMMARY_CHANNEL_ID |
Channel ID for sync summaries | C0123456789 |
- In Apps Script, click Deploy > New deployment.
- Select Web app:
- Execute as:
Me - Who has access:
Anyone
- Execute as:
- Copy the Web App URL.
- In Slack App Settings:
- Interactivity & Shortcuts: Enable Interactivity and paste the Web App URL into Request URL.
- Slash Commands: Create
/poll, paste the Web App URL into Request URL.
In Google Apps Script, click the Triggers (⏰) icon and add two triggers:
| Function | Event Source | Type | Interval |
|---|---|---|---|
minuteTrigger |
Time-driven | Minutes timer | Every minute |
runDailySync |
Time-driven | Day timer | Midnight to 1am (or preferred time) |
User IDReal NameDisplay NameEmailPhoneChapter(Slack FieldXf09MGK1C86Q)Age Range(Slack FieldXf09N7BMLJTS)Membership(Slack FieldXf09NKRWFND6)Member Group(Slack FieldXf0A772PKPK9)Title(Slack FieldXf06NT787AG3)Updated AtStatus
Poll IDQuestionStatus(Open/Closed)Created AtExpires AtChannel IDMessage TSVote State(JSON array)
MIT