[examples] add Slack idle-notification policy example#12
Conversation
Adds a `slack-on-idle-notification` custom policy to `examples/policies-advanced/index.js` that uses the `Notification` hook to forward Claude's idle notifications to Slack via a webhook, including project path and session ID in a Block Kit message. Also documents `notification_type` in the Notification event row of `docs/custom-hooks.md` and notes that Notification hooks must always return `allow()`. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughDocumentation for the Changes
Sequence DiagramsequenceDiagram
participant System as Notification System
participant Policy as Custom Policy<br/>(slack-on-idle-notification)
participant Slack as Slack Webhook API
participant Env as Environment<br/>Variables
System->>Policy: Trigger Notification event<br/>(notification_type: "idle")
Policy->>Env: Read SLACK_WEBHOOK_URL
alt Webhook URL exists and type is idle
Policy->>Policy: Construct Block Kit payload<br/>with message & session metadata
Policy->>Slack: fetch(webhook_url, payload)
Slack-->>Policy: Response (may fail)
Policy->>Policy: Suppress errors via .catch()
end
Policy->>System: return allow()
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
Summary
slack-on-idle-notificationpolicy toexamples/policies-advanced/index.jsdemonstrating the
Notificationhookand session ID
SLACK_WEBHOOK_URLenv var; silently no-ops if unsetdocs/custom-hooks.mdto documentnotification_typeand note Notificationhooks must always return
allow()Test plan
examples/policies-advanced/index.jsis validSLACK_WEBHOOK_URL, install example, trigger idle notification, confirm BlockKit message appears in Slack
SLACK_WEBHOOK_URLand confirm policy skips silently🤖 Generated with Claude Code
Summary by CodeRabbit
Documentation
Notificationevent payload documentation with newnotification_typefield and clarified behavior for custom hooks.Examples