Docs/Integrations/Slack & Discord

Slack & Discord Webhooks

Get real-time notifications for policy violations, PII detection, HITL approval requests, and other governance events directly in your team's Slack or Discord channels.

Overview

Tork's webhook integration allows you to receive instant notifications when important governance events occur. Connect your Slack or Discord workspace to stay informed about your AI agents' activities in real-time.

Policy Violations

Get alerted when agents violate defined policies

PII Detection

Notifications when sensitive data is detected

HITL Requests

Approval requests sent directly to your channel

Budget Alerts

Warnings when spending approaches limits

Supported Events
Tork webhooks support the following events: policy.violation, pii.detected, hitl.requested, hitl.approved, hitl.rejected, budget.warning, budget.exceeded, agent.blocked, and circuit_breaker.triggered.

Slack Setup

Follow these steps to connect Tork with your Slack workspace:

1

Create a Slack App

Go to api.slack.com/apps and click "Create New App". Choose "From scratch" and give it a name like "Tork Governance".

2

Enable Incoming Webhooks

In your app settings, navigate to "Incoming Webhooks" and toggle it on. Click "Add New Webhook to Workspace" and select the channel for notifications.

3

Copy Webhook URL

Copy the webhook URL that looks like:
https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX

4

Add to Tork Admin Console

Go to Admin Console → Webhooks → Add Webhook. Paste your Slack webhook URL and select the events you want to receive.

Security Note
Keep your webhook URL secret. Anyone with this URL can post messages to your Slack channel. Rotate the webhook if it's ever exposed.

Discord Setup

Follow these steps to connect Tork with your Discord server:

1

Open Server Settings

Right-click your server name and select "Server Settings", then navigate to "Integrations" in the sidebar.

2

Create Webhook

Click "Webhooks" then "New Webhook". Give it a name like "Tork Alerts" and select the channel where you want notifications to appear.

3

Copy Webhook URL

Click "Copy Webhook URL". It will look like:
https://discord.com/api/webhooks/000000000000000000/XXXXXXXXXXXXXXXXXXXXXXXXXXXX

4

Add to Tork Admin Console

Go to Admin Console → Webhooks → Add Webhook. Paste your Discord webhook URL and select the events you want to receive.

Webhook Payload Format

Tork sends webhook payloads in the following JSON format:

json
{
  "event": "policy.violation",
  "timestamp": "2026-01-19T10:00:00Z",
  "agent_id": "agent-123",
  "agent_name": "Customer Support Bot",
  "severity": "high",
  "details": {
    "policy_id": "pol-456",
    "policy_name": "no-pii-in-responses",
    "action": "blocked",
    "message": "PII detected in agent response",
    "matched_rules": ["email_pattern", "phone_pattern"],
    "context": {
      "user_id": "user-789",
      "session_id": "sess-abc"
    }
  },
  "meta": {
    "request_id": "req-xyz",
    "organization_id": "org-123"
  }
}

Event Types

EventDescriptionSeverity
policy.violationAgent violated a defined policyhigh
pii.detectedPII found in agent input/outputmedium-high
hitl.requestedHuman approval requestedinfo
hitl.approvedAction was approvedinfo
hitl.rejectedAction was rejectedwarning
budget.warningApproaching budget limit (80%)warning
budget.exceededBudget limit exceededcritical
agent.blockedAgent was blocked from actionhigh
circuit_breaker.triggeredCircuit breaker activatedcritical

Code Examples

If you want to send custom notifications programmatically, here are examples for both platforms:

python
import requests

def send_slack_notification(webhook_url: str, event: dict):
    """Send a Tork event to Slack."""

    # Map severity to colors
    colors = {
        "critical": "#dc2626",  # red
        "high": "#f97316",      # orange
        "warning": "#eab308",   # yellow
        "info": "#3b82f6",      # blue
    }

    payload = {
        "attachments": [{
            "color": colors.get(event["severity"], "#6b7280"),
            "blocks": [
                {
                    "type": "header",
                    "text": {
                        "type": "plain_text",
                        "text": f"🚨 {event['event'].replace('.', ' ').title()}"
                    }
                },
                {
                    "type": "section",
                    "fields": [
                        {"type": "mrkdwn", "text": f"*Agent:*\n{event['agent_name']}"},
                        {"type": "mrkdwn", "text": f"*Severity:*\n{event['severity'].upper()}"},
                        {"type": "mrkdwn", "text": f"*Time:*\n{event['timestamp']}"},
                        {"type": "mrkdwn", "text": f"*Action:*\n{event['details']['action']}"},
                    ]
                },
                {
                    "type": "section",
                    "text": {
                        "type": "mrkdwn",
                        "text": f"*Message:*\n{event['details']['message']}"
                    }
                },
                {
                    "type": "actions",
                    "elements": [{
                        "type": "button",
                        "text": {"type": "plain_text", "text": "View in Console"},
                        "url": f"https://app.tork.network/admin/alerts/{event['meta']['request_id']}"
                    }]
                }
            ]
        }]
    }

    response = requests.post(webhook_url, json=payload)
    return response.status_code == 200

API Reference

Manage your Slack and Discord integrations programmatically using the REST API.

GET/api/v1/integrations

List all chat integrations for your organization.

bash
curl https://api.tork.network/v1/integrations \
  -H "Authorization: Bearer YOUR_API_KEY"
POST/api/v1/integrations

Create a new Slack or Discord integration.

bash
curl -X POST https://api.tork.network/v1/integrations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "platform": "slack",
    "name": "Engineering Alerts",
    "slack_webhook_url": "https://hooks.slack.com/services/...",
    "slack_channel_name": "#tork-alerts",
    "events": ["policy.violation", "pii.detected", "hitl.pending"],
    "notification_settings": {
      "include_details": true,
      "mention_on_critical": true,
      "quiet_hours_start": "22:00",
      "quiet_hours_end": "08:00"
    }
  }'
POST/api/v1/integrations/:id/test

Send a test notification to verify your integration works.

bash
curl -X POST https://api.tork.network/v1/integrations/int_xxx/test \
  -H "Authorization: Bearer YOUR_API_KEY"
PATCH/api/v1/integrations/:id

Update an existing integration.

bash
curl -X PATCH https://api.tork.network/v1/integrations/int_xxx \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "events": ["policy.violation", "security.alert"],
    "is_active": true
  }'
DELETE/api/v1/integrations/:id

Delete an integration.

bash
curl -X DELETE https://api.tork.network/v1/integrations/int_xxx \
  -H "Authorization: Bearer YOUR_API_KEY"

Notification Settings

SettingTypeDescription
include_detailsbooleanInclude event data fields in notifications
mention_on_criticalboolean@channel/@everyone for critical events
quiet_hours_startstring (HH:MM)Start of quiet hours (no notifications)
quiet_hours_endstring (HH:MM)End of quiet hours

Troubleshooting

Messages not appearing in Slack/Discord

  • Verify the webhook URL is correct and hasn't been regenerated
  • Check that the webhook is enabled in Tork Admin Console
  • Ensure the selected events match what you're testing
  • Check the Tork webhook delivery logs for errors

Webhook returns 400 or 403 errors

  • The webhook URL may have been revoked - create a new one
  • Check if your Slack app or Discord webhook has the necessary permissions
  • Verify there are no IP restrictions blocking Tork's servers

Rate limiting issues

  • Slack allows ~1 message per second per webhook
  • Discord allows 30 requests per minute per webhook
  • Consider batching notifications for high-volume scenarios
  • Use Tork's built-in rate limiting options in webhook settings

Testing your webhook

Use the Tork Admin Console to send a test notification:

bash
# Or use the CLI
tork webhooks test --id webhook-123 --event policy.violation