Google Chat webhooks allow you to send messages directly to Google Chat spaces (rooms or direct messages) from external applications. This guide will help you set up a Google Chat webhook URL and configure it for use in your project.
- Open Google Chat: Go to Google Chat and sign in with your Google account.
- Create a New Space (if you don't have one):
- Click on the "+" button next to "Spaces" in the left sidebar.
- Select "Create Space".
- Enter a Space Name (e.g.,
Chatz Notifications
). - Add members if needed (optional).
- Click "Create".
-
Open Space Settings:
- Once the space is created, click on the space name at the top of the chat window.
- Click on "Manage Webhooks". If you do not see this option, make sure you have the necessary permissions or try creating a new space.
-
Create a New Webhook:
- Click on "Configure Webhook".
- Enter a Webhook Name (e.g.,
Chatz Webhook
). - Optionally, upload an image URL to customize the webhook avatar.
-
Generate the Webhook URL:
- After entering the details, click "Save".
- Copy the generated Webhook URL. It will look something like this:
https://chat.googleapis.com/v1/spaces/XXXXXX/messages?key=XXXXXXXX&token=XXXXXXXX
-
Set Up Environment Variables:
- Store the Webhook URL in an environment variable for easy access. For example, add the following line to your
~/.chatz.ini
file:[default] PROVIDER=google WEB_HOOK_URL=https://chat.googleapis.com/v1/spaces/XXXXXX/messages?key=XXXXXXXX&token=XXXXXXXX
- Store the Webhook URL in an environment variable for easy access. For example, add the following line to your
-
Example Configuration in Chatz:
- Ensure your application reads the webhook URL correctly from the environment variables and is configured to send messages to Google Chat.
- Send a Test Message:
chatz -o "Test message."
- Invalid Webhook URL: Double-check the URL for any errors, such as missing characters or incorrect tokens.
- Insufficient Permissions: Ensure you have the correct permissions to create and manage webhooks in your Google Chat space.
- Message Not Sent: Verify that your payload is correctly formatted as JSON and that you are using the correct headers.
- Keep your Google Chat webhook URL secret. Never expose it in public repositories or share it openly.
- If the webhook URL is compromised, delete it and generate a new one.