Skip to content

[examples] add Slack idle-notification policy example#12

Merged
NiveditJain merged 1 commit into
mainfrom
ef-15
Apr 6, 2026
Merged

[examples] add Slack idle-notification policy example#12
NiveditJain merged 1 commit into
mainfrom
ef-15

Conversation

@NiveditJain

@NiveditJain NiveditJain commented Apr 6, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds slack-on-idle-notification policy to examples/policies-advanced/index.js
    demonstrating the Notification hook
  • Posts a Block Kit Slack message on idle notifications with Claude's message, project path,
    and session ID
  • Uses SLACK_WEBHOOK_URL env var; silently no-ops if unset
  • Updates docs/custom-hooks.md to document notification_type and note Notification
    hooks must always return allow()

Test plan

  • Verify syntax in examples/policies-advanced/index.js is valid
  • Set SLACK_WEBHOOK_URL, install example, trigger idle notification, confirm Block
    Kit message appears in Slack
  • Unset SLACK_WEBHOOK_URL and confirm policy skips silently

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation

    • Updated Notification event payload documentation with new notification_type field and clarified behavior for custom hooks.
  • Examples

    • Added example policy demonstrating integration for forwarding idle notifications to Slack.

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>
@coderabbitai

coderabbitai Bot commented Apr 6, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Free

Run ID: a395a1f9-31a3-4ce3-a155-5966bcadfffb

📥 Commits

Reviewing files that changed from the base of the PR and between 365f60e and 72aa0f2.

📒 Files selected for processing (2)
  • docs/custom-hooks.md
  • examples/policies-advanced/index.js

📝 Walkthrough

Walkthrough

Documentation for the Notification event payload was updated to include a notification_type field with values such as "idle" and "permission_prompt", noting that custom hooks must always return allow() and cannot block notifications. An example custom policy was added that forwards idle notifications to a Slack webhook.

Changes

Cohort / File(s) Summary
Documentation
docs/custom-hooks.md
Updated Notification event payload documentation to include notification_type field; clarified that custom hooks must always return allow() for notifications and cannot block them.
Slack Integration Example
examples/policies-advanced/index.js
Added slack-on-idle-notification custom policy that listens for Notification events, filters for notification_type === "idle", constructs a Slack Block Kit payload with session metadata, and sends it to a webhook URL via non-blocking fetch with error suppression.

Sequence Diagram

sequenceDiagram
    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()
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A notification arrives, the idle time ticks on,
Custom hooks catch the whisper, send word to Slack—no frown,
Payloads dance through the ether, webhooks gleam bright,
Always returning allow(), never blocking the light!
Documentation clarified, the path now shines clear. ✨


Note

🎁 Summarized by CodeRabbit Free

Your 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 @coderabbitai help to get the list of available commands and usage tips.

@NiveditJain NiveditJain merged commit d23be0d into main Apr 6, 2026
7 of 8 checks passed
@NiveditJain NiveditJain deleted the ef-15 branch April 21, 2026 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant