name: google-chat description: Send messages to Google Chat spaces and users via webhooks or OAuth. Use when you need to send notifications, alerts, or messages to Google Chat channels (spaces) or direct messages to specific users. Supports both incoming webhooks (for predefined channels) and OAuth 2.0 (for dynamic messaging to any space or user).
Send messages to Google Chat using two methods:
Send to a pre-configured channel:
python3 scripts/send_webhook.py "$WEBHOOK_URL" "Your message here"
Example with threading:
python3 scripts/send_webhook.py "$WEBHOOK_URL" "Reply message" --thread_key "unique-thread-id"
Configuration: Store webhooks in google-chat-config.json:
{ "webhooks": { "acs_engineering_network": "https://chat.googleapis.com/v1/spaces/...", "general": "https://chat.googleapis.com/v1/spaces/..." } }本技能来自小葱技能站7w4.net。
Read config and send:
WEBHOOK_URL=$(jq -r '.webhooks.acs_engineering_network' google-chat-config.json)
python3 scripts/send_webhook.py "$WEBHOOK_URL" "Deploy completed ✅"
First-time setup:
google-chat-oauth-credentials.json)python3 scripts/send_oauth.py \
--credentials google-chat-oauth-credentials.json \
--token google-chat-token.json \
--space "General" \
"Test message"
Send to a space by name:
python3 scripts/send_oauth.py \
--credentials google-chat-oauth-credentials.json \
--token google-chat-token.json \
--space "Engineering Network" \
"Deploy completed"
Note: OAuth messages automatically include 🤖 emoji prefix. Use --no-emoji to disable this:
python3 scripts/send_oauth.py \
--credentials google-chat-oauth-credentials.json \
--token google-chat-token.json \
--space "Engineering Network" \
"Message without emoji" \
--no-emoji
List available spaces:
python3 scripts/send_oauth.py \
--credentials google-chat-oauth-credentials.json \
--token google-chat-token.json \
--list-spaces
Send to a DM (requires existing space ID):
# Note: Google Chat API doesn't support creating new DMs by email
# You need the space ID of an existing DM conversation
python3 scripts/send_oauth.py \
--credentials google-chat-oauth-credentials.json \
--token google-chat-token.json \
--space-id "spaces/xxxxx" \
"The report is ready"
Send to space by ID (faster):
python3 scripts/send_oauth.py \
--credentials google-chat-oauth-credentials.json \
--token google-chat-token.json \
--space-id "spaces/AAAALtlqgVA" \
"Direct message to space"
Install required Python packages:
pip install google-auth-oauthlib google-auth-httplib2 google-api-python-client
Required OAuth Scopes:
- https://www.googleapis.com/auth/chat.messages - Send messages
- https://www.googleapis.com/auth/chat.spaces - Access space information
- https://www.googleapis.com/auth/chat.memberships.readonly - List space members (for DM identification)
If OAuth credentials don't exist yet:
google-chat-oauth-credentials.jsonThe credentials JSON should look like:
{
"installed": {
"client_id": "...apps.googleusercontent.com",
"client_secret": "GOCSPX-...",
"redirect_uris": ["http://localhost"],
...
}
}
To create a webhook for a Google Chat space:
google-chat-config.jsonUse Webhooks when: - Sending to the same channels repeatedly - Messages should appear as a bot/service - Speed is important (no OAuth handshake) - Configuration is static
Use OAuth when: - Sending to different spaces dynamically - Messages should appear from your configured Google Chat App - Space names are determined at runtime - Need to list and discover available spaces
OAuth Limitations:
- Cannot create new DMs by email address (Google Chat API restriction)
- To send DMs, you need the space ID of an existing conversation
- Use --list-spaces to find available DM space IDs
Both methods support simple text. For advanced formatting (cards, buttons), construct JSON payloads:
Webhook with card:
import json
import urllib.request
payload = {
"cardsV2": [{
"cardId": "unique-card-id",
"card": {
"header": {"title": "Deploy Status"},
"sections": [{
"widgets": [{
"textParagraph": {"text": "Production deploy completed successfully"}
}]
}]
}
}]
}
data = json.dumps(payload).encode("utf-8")
req = urllib.request.Request(webhook_url, data=data, headers={"Content-Type": "application/json"})
urllib.request.urlopen(req)
Webhook errors: - Verify webhook URL is correct and active - Check space still exists and webhook wasn't deleted - Ensure message isn't empty
OAuth errors: - Run authentication flow again if token expired - Verify Google Chat API is enabled in Cloud Console - Check user has access to the target space - For DMs, ensure user email is correct and in same workspace
Permission errors: - Webhooks: Must be member of the space - OAuth: Must have access to target space or user - Corporate Workspace: Some features may be restricted by admin policies
Deploy notification to engineering channel:
WEBHOOK=$(jq -r '.webhooks.acs_engineering_network' google-chat-config.json)
python3 scripts/send_webhook.py "$WEBHOOK" "🚀 Production deploy v2.1.0 completed"
Alert specific user about task:
python3 scripts/send_oauth.py \
--credentials google-chat-oauth-credentials.json \
--token google-chat-token.json \
--dm juan@empresa.com \
"Your report is ready for review: https://docs.company.com/report"
Thread multiple messages together (webhook):
WEBHOOK=$(jq -r '.webhooks.general' google-chat-config.json)
THREAD_KEY="deploy-$(date +%s)"
python3 scripts/send_webhook.py "$WEBHOOK" "Starting deploy..." --thread_key "$THREAD_KEY"
# ... deployment happens ...
python3 scripts/send_webhook.py "$WEBHOOK" "Deploy completed ✅" --thread_key "$THREAD_KEY"
这个 Skill 质量不错,功能齐全,能满足向 Google Chat 发送消息的基本需求。文档清晰详细,新手也能快速上手。Webhook 发送快速可靠,OAuth 方式支持动态发送到任意群组。不过通过 OAuth 发送私信功能目前无法正常使用,依赖安装的包较多。建议优先使用 Webhook 方式,如果需要发私信,建议直接使用空间 ID。