Google Chat Bot / Webhook Notifications Server
Google Authentication:
Step 1: Create a Google Cloud Project
-
Go to Google Cloud Console:
- Visit Google Cloud Console.
-
Create a New Project:
- Click on the project dropdown in the top navigation bar.
- Click on "New Project".
- Enter a project name and select an organization if applicable.
- Click "Create".
Step 2: Enable Google Chat API
-
Navigate to the API Library:
- In the left sidebar, go to "APIs & Services" > "Library".
-
Search for Google Chat API:
- In the search bar, type "Google Chat API".
- Click on "Google Chat API" from the search results.
-
Enable the API:
- Click the "Enable" button.
Step 3: Create a Service Account
-
Go to Service Accounts:
- In the left sidebar, navigate to "APIs & Services" > "Credentials".
-
Create a Service Account:
- Click on "Create Credentials" and select "Service account".
-
Fill in Service Account Details:
- Enter a name and description for the service account.
- Click "Create".
-
Grant Service Account Permissions (Optional):
- Assign roles as needed. For Google Chat API, typically you might need roles like Chat Bot or Editor.
- Click "Continue".
-
Skip the Key Creation Step:
- Click "Done" to finish creating the service account.
Step 4: Create and Download Keys
-
Open Service Account Details:
- Find the newly created service account in the list and click on it.
-
Add Key:
- Go to the "Keys" tab.
- Click on "Add Key" and choose "JSON".
-
Download the Key:
- A JSON file will be automatically downloaded. This file contains your credentials, so keep it secure.
Step 5: Configure the API
-
Set Up OAuth Consent Screen:
- Go to "APIs & Services" > "OAuth consent screen".
- Configure the consent screen as required (for internal or external use).
- Fill out the necessary fields, then save.
-
Use Service Account in Your Application:
- Integrate the service account credentials in your application using the downloaded JSON key. Libraries are available for various programming languages to facilitate this.
Step 6: Test the Google Chat API
-
Make API Calls:
- Use tools like Postman or your application code to make API calls to Google Chat using the service account credentials.
-
Send a Test Message:
- Ensure your service account has the necessary permissions to interact with the Google Chat API and send messages.
Additional Tips
- Secure Your JSON Key: Keep your service account key secure; do not share it publicly.
- Review Quotas and Billing: Monitor your project for API usage and ensure you’re aware of any billing implications.
- Explore Documentation: Check the Google Chat API documentation for further details and code examples.
Google Authentication files required:
- client_secrets.json
- Google Cloud Console > APIs & Services > Credentials > OAuth 2.0 Client IDs
- service_account.json
- Google Cloud Console > IAM & Admin > Service Accounts > Keys
Google Spaces:
- Create a Google Space in Google Chat to send the notifications to. the app must be added into the space with
@Suavecito
Environmental Variables:
# used for gchat verification
PROJECT_NUMBER=
# used for examle routes / controllers
EXAMPLE_SPACE=
EXAMPLE_KEY=
EXAMPLE_TOKEN=
# used to validate requests
SENTRY_CLIENT_SECRET= # get this by creating an internal integration
NETLIFY_CLIENT_SECRET= # generate this secret yourself and add to all notifications in netlify
MONGODB_SECRET= # generate this secret yourself and add to webhook settings in mongodb dashboard
| Method | Endpoint | Description |
|---|---|---|
| POST | /v1/webhook/:space/netlify | Sends a Google Chat Notification Card with the Netlify Deployment / Event information. This route accepts a query param of payload=true, to send the payload in the message. |
| POST | /v1/webhook/:space/sentry | Sends a Google Chat Notification Card with the Sentry Issue / Event information. This route accepts a query param of payload=true, to send the payload in the message |
| POST | /v1/webhook/:space/mongodb | Sends a Google Chat Notification Card with the MongoDB notification information. This route accepts a query param of payload=true, to send the payload in the message |
The app / bot can be added into a space by using the
@Suavecitocommand.
Slash Commands:
| Command | Description |
|---|---|
| /hello | This command returns the message payload as a card message. |
| /uptime | This command returns the server's uptime in HH:MM:SS. |