> ## Documentation Index
> Fetch the complete documentation index at: https://moonshadow-ep3.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Configure Automated Notifications in Moonshadow

> Set up rules to automatically notify your team via Slack, email, or webhook when specific events occur in your connected integrations.

Moonshadow notification rules let you define when and how your team gets alerted about events from connected integrations. You can create rules that match specific event types, apply filters, and deliver notifications through Slack, email, or custom webhooks.

## Create a Notification Rule

A notification rule connects event triggers to delivery channels. When an event matches the rule conditions, Moonshadow sends the notification through every configured channel.

```bash theme={null}
curl -X POST https://api.moonshadow.dev/v1/notifications/rules \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "workspace_id": "ws_1234567890abcdef",
    "name": "Critical Slack Alerts",
    "enabled": true,
    "triggers": [
      {
        "event_type": "event.created",
        "filters": {
          "integration_type": "github",
          "payload.action": "opened",
          "payload.pull_request.draft": false
        }
      }
    ],
    "channels": [
      {
        "type": "slack",
        "config": {
          "channel": "#engineering-alerts"
        }
      },
      {
        "type": "email",
        "config": {
          "recipients": ["team@moonshadow.dev"]
        }
      }
    ]
  }'
```

Response:

```json theme={null}
{
  "id": "nr_abc123def456",
  "workspace_id": "ws_1234567890abcdef",
  "name": "Critical Slack Alerts",
  "enabled": true,
  "triggers": [
    {
      "event_type": "event.created",
      "filters": {
        "integration_type": "github",
        "payload.action": "opened",
        "payload.pull_request.draft": false
      }
    }
  ],
  "channels": [
    {
      "type": "slack",
      "config": {
        "channel": "#engineering-alerts"
      }
    },
    {
      "type": "email",
      "config": {
        "recipients": ["team@moonshadow.dev"]
      }
    }
  ],
  "created_at": "2024-01-15T10:30:00Z",
  "updated_at": "2024-01-15T10:30:00Z"
}
```

<ParamField body="workspace_id" type="string" required>
  The workspace that owns this notification rule.
</ParamField>

<ParamField body="name" type="string" required>
  A human-readable name for the rule.
</ParamField>

<ParamField body="triggers" type="array" required>
  List of trigger conditions. Each trigger specifies an event type and optional filters.
</ParamField>

<ParamField body="channels" type="array" required>
  List of delivery channels. Moonshadow sends to all channels when triggers match.
</ParamField>

## Trigger Conditions

Triggers define which events activate the notification rule. Each trigger has an `event_type` and optional `filters` that narrow down matching events.

### Event Types

You can trigger on any event type that occurs in your workspace:

* `event.created` - any event from a connected integration
* `automation.completed` - an automation workflow finished
* `integration.connected` - a new integration was added
* `integration.disconnected` - an integration was removed
* `user.invited` - a new user was invited to the workspace

### Filters

Filters use dot notation to match values inside the event payload. Only events that satisfy all filters trigger the notification.

| Filter Example                           | Matches                              |
| ---------------------------------------- | ------------------------------------ |
| `integration_type: "github"`             | Events from GitHub only              |
| `payload.action: "opened"`               | Payload action field equals "opened" |
| `payload.pull_request.draft: false`      | Non-draft pull requests              |
| `payload.severity: ["high", "critical"]` | Severity is high or critical         |

<Tip>
  Filters support exact matching, arrays for OR conditions, and nested dot notation. Use them to avoid noisy notifications.
</Tip>

## Delivery Channels

Each rule can deliver to one or more channels. Moonshadow supports Slack, email, and webhook channels.

### Slack

Sends a formatted message to a Slack channel. Requires a connected Slack integration.

```json theme={null}
{
  "type": "slack",
  "config": {
    "channel": "#engineering-alerts",
    "mention": "@here"
  }
}
```

### Email

Sends an email to one or more recipients.

```json theme={null}
{
  "type": "email",
  "config": {
    "recipients": ["team@moonshadow.dev", "alerts@moonshadow.dev"],
    "subject": "Moonshadow Alert: {{event.type}}"
  }
}
```

### Webhook

POSTs the event payload to a custom URL.

```json theme={null}
{
  "type": "webhook",
  "config": {
    "url": "https://your-app.com/alerts",
    "headers": {
      "X-Custom-Header": "value"
    }
  }
}
```

## Muting and Snoozing

You can temporarily disable a rule without deleting it. This is useful during maintenance windows or when a service is down.

### Disable a Rule

```bash theme={null}
curl -X PATCH https://api.moonshadow.dev/v1/notifications/rules/nr_abc123def456 \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"enabled": false}'
```

### Snooze a Rule

Snoozing disables a rule for a fixed duration and re-enables it automatically.

```bash theme={null}
curl -X POST https://api.moonshadow.dev/v1/notifications/rules/nr_abc123def456/snooze \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "duration_minutes": 60,
    "reason": "Deploying critical fix"
  }'
```

<Note>
  Snoozed rules show a countdown in the dashboard. You can cancel a snooze early by re-enabling the rule manually.
</Note>

## Full Example: GitHub Pull Request Alerts

This complete example creates a rule that alerts the team when a non-draft pull request is opened in GitHub.

```bash theme={null}
API_KEY="YOUR_API_KEY"
WORKSPACE_ID="ws_1234567890abcdef"

curl -X POST https://api.moonshadow.dev/v1/notifications/rules \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"workspace_id\": \"$WORKSPACE_ID\",
    \"name\": \"GitHub PR Opened Alerts\",
    \"enabled\": true,
    \"triggers\": [
      {
        \"event_type\": \"event.created\",
        \"filters\": {
          \"integration_type\": \"github\",
          \"payload.action\": \"opened\",
          \"payload.pull_request.draft\": false
        }
      }
    ],
    \"channels\": [
      {
        \"type\": \"slack\",
        \"config\": {
          \"channel\": \"#pull-requests\",
          \"mention\": \"@here\"
        }
      },
      {
        \"type\": \"email\",
        \"config\": {
          \"recipients\": [\"team@moonshadow.dev\"],
          \"subject\": \"New PR: {{payload.pull_request.title}}\"
        }
      }
    ]
  }"
```

<Warning>
  Notification rules apply at the workspace level. Every event in the workspace is evaluated against all enabled rules, so keep filter specificity high to prevent redundant notifications.
</Warning>

## Next Steps

* <Card title="First Integration" icon="plug" href="/guides/first-integration">
    Connect Slack or another integration to enable Slack notifications
  </Card>
* <Card title="Webhooks" icon="webhook" href="/guides/webhooks">
    Build custom delivery pipelines with webhook channels
  </Card>
* <Card title="API Reference" icon="code" href="/api-reference/introduction">
    Explore all notification rule endpoints and parameters
  </Card>
