iTranslated by AI
Building a Webhook Test System for Filtered Notifications to Google Chat and Slack
Building a Webhook Test System for Notifications (with Filtering) to Google Chat and Slack
Introduction
In this article, I will introduce how to build a system that sends messages generated from a system (specifically a Web GUI + Node server for testing purposes) to Google Chat and Slack via Webhooks, and automatically sorts the destination channels based on the content.
*Note: Since I could not generate a Webhook for Google Chat, verification was conducted only with Slack.
System Overview
- Node.js: Webhook server (receives messages & forwards to Google Apps Script Bot)
- Google Apps Script: Google Chat Bot (sorts and posts to channels based on received content)
- Google Spreadsheet: Management of filtering rules
- Slack: Notification channels
System Architecture Diagram
1. Chat Service Settings
Creating Google Chat Channels
*Note: Available only for paid Google Workspace users.
- Access Google Chat
- Click the "+" button on the left and select "Create space"
- Enter the space name (e.g., Error Notifications, Normal Notifications)
- Click "Create"
- Open the space and issue a Webhook URL via "Manage webhooks"
Slack Channel Settings
- Log in to your Slack workspace
- Create or select the channel where you want to send notifications
- Click the channel name -> "View channel details"
- Go to "Integrations" -> "Add an App" and install "Incoming Webhooks"
- Click "Add to Slack" -> "Add Incoming Webhooks integration"
- Copy the generated Webhook URL
2. Building the Node.js Server
Installing Required Packages
npm install express dotenv ws
Implementing the Server Code
Implementing the Web GUI

Environment Variable Settings
Create a .env file:
BOT_WEBHOOK_URL="<Your GAS Deployment URL>"
PORT=3000
3. Implementing the Google Apps Script Bot
Preparing the Spreadsheet
- Create a new Google Spreadsheet
- Create the following two sheets:
- "Filter Settings" sheet
- Column A: Regex pattern
- Column B: Channel ID
- "Channel Settings" sheet
- Column A: Channel ID
- Column B: Google Chat Webhook URL
- Column C: Slack Webhook URL
- "Filter Settings" sheet
Implementing the Apps Script Code
Deployment Steps
- Open "Project Settings" in the Google Apps Script editor
- Select the "Script Properties" tab
- Click "Add row"
- Add the following setting:
- Property name:
SPREADSHEET_ID - Value: Your spreadsheet ID
- Property name:
- "Deploy" -> "New deployment"
- Select "Web app" for "Select type"
- "Execute as" -> "Me"
- "Who has access" -> "Anyone"
- Deploy and set the displayed URL to
BOT_WEBHOOK_URLin your.envfile
4. Usage
Send a message from the Web page
- Access
http://localhost:3000in your browser - Enter a message in the text area
- Click the "Send" button
Send a message via API
curl -X POST http://localhost:3000/webhook \
-H "Content-Type: application/json" \
-d '{"text": "Error: Server is down"}'
5. Troubleshooting
When a 404 error occurs
-
For Google Chat Webhook URLs:
- Confirm you are a paid Google Workspace user
- Check if the Webhook URL was issued correctly
- Confirm the space type is "Chat"
-
For Slack Webhook URLs:
- Check if the Webhook URL was issued correctly
- Confirm the channel exists
- Check if the app permissions are set correctly
-
For Google Apps Script:
- Check if the deployment was successful
- Check if the deployment URL is correct
- Confirm the access permission is set to "Anyone"
6. Supplementary Information
- There are limits on the number of requests in the free tier of Google Apps Script
- The Google Chat Webhook feature is only available to paid Google Workspace users
- Slack Webhooks are available even on the free plan
- You can dynamically update filtering rules by changing the spreadsheet settings
Summary
By using this system, you can efficiently manage notifications from the system and route them to the appropriate channels. Additionally, by utilizing Google Apps Script and Spreadsheets, configuration changes can be easily made.
Discussion