Signals and Signal Sources: Receive signals through a webhook
Back to Signals and Signal Sources.
Receive signals through a webhook
Section titled “Receive signals through a webhook”Select webhook as the source driver and create the source through the normal resource API or SPA. After creation,
Brezel generates a unique webhook_url. Enable the source before sending data. Send JSON or form data to that URL with POST:
curl -X POST 'https://example.test/system/public/signal/orders/GENERATED_TOKEN' \ -H 'Content-Type: application/json' \ -H 'Idempotency-Key: order-event-42' \ -d '{"order":{"id":42},"status":"created"}'The endpoint returns 202 Accepted and queues classification. Reusing the same Idempotency-Key for the same source
returns 200 with status: duplicate; without an event identity, every request is treated as a new signal. The signal
type defaults to webhook.received and can be overridden with X-Brezel-Signal-Type or X-Event-Type. To derive the
identity from a JSON field instead, set event_id_field in the source’s generic configuration field.
The token is never stored in clear text. Treat the generated URL like a credential and restrict access to the signal source module accordingly.
Seed an IMAP source
Section titled “Seed an IMAP source”Keep credentials in the system environment and reference them from a detached Bakery entity. Cursor and health fields
are runtime state. A synchronized source can reapply capability defaults such as cursor = {} and status = idle,
resetting the polling position even when those fields are omitted from the seed.
Use detach so the source becomes runtime-owned after it is created:
[ { "resource_entity": "signal_source_inbox", "depends_on": "resource_module.signal_sources", "policy": "detach", "resource": { "module": "signal_sources", "client": "${resource_client.global_client}", "fields": { "source_identifier": "main-inbox", "title": "Main Inbox", "driver": "imap", "enabled": "${env('SIGNAL_IMAP_ENABLED', false)}", "host": "${env('SIGNAL_IMAP_HOST', '')}", "port": "${env('SIGNAL_IMAP_PORT', 993)}", "username": "${env('SIGNAL_IMAP_USERNAME', '')}", "password": "${env('SIGNAL_IMAP_PASSWORD', '')}", "encryption": "${env('SIGNAL_IMAP_ENCRYPTION', 'ssl')}", "validate_cert": "${env('SIGNAL_IMAP_VALIDATE_CERT', true)}", "folders": [{"value": "INBOX"}], "bootstrap_days": 7, "max_messages_per_poll": 25, "configuration": {} } } }]Do not switch a live source to policy: sync. To change its connection settings later, edit the source in Brezel or
recreate it deliberately after preserving or resetting its cursor. Keep cursor, status, last_polled_at, and
last_error out of the seed as an additional safeguard and to make their runtime ownership explicit.
In systems/example/.env:
SIGNAL_IMAP_ENABLED=falseSIGNAL_IMAP_HOST=imap.example.comSIGNAL_IMAP_PORT=993SIGNAL_IMAP_USERNAME=inbox@example.comSIGNAL_IMAP_PASSWORD=change-meSIGNAL_IMAP_ENCRYPTION=sslSIGNAL_IMAP_VALIDATE_CERT=trueApply the module while the source is disabled. Enable it only after the connection values, queue, and scheduler have been verified.
IMAP driver configuration
Section titled “IMAP driver configuration”| Key | Default | Notes |
|---|---|---|
host | none | Required by the IMAP server. |
port | 993 | Cast to an integer. |
username | none | IMAP login. |
password | none | IMAP password or application password. |
encryption | ssl | ssl, tls, or none. none is converted to no encryption. |
validate_cert | true | Keep enabled outside controlled local development. |
timeout | 30 | Connection timeout in seconds; normally supplied through configuration. |
folders | ["INBOX"] | List values or a comma-separated string. List records may use {"value":"INBOX"}. |
bootstrap_days | 7 | Lookback used when no valid UID cursor exists. 0 starts at the current UTC day. |
max_messages_per_poll | 25 | Per-folder limit, clamped to 1..100. |
The driver:
- uses
directorytree/imapengine; - fetches messages in ascending UID order;
- leaves messages unread;
- stores a cursor per folder with UID, UIDVALIDITY, and message time;
- resets to the configured lookback when UIDVALIDITY changes;
- uses
Message-ID, or folder and UID as fallback, for stable transport keys; - stores the original text or HTML body, capped at 50,000 characters, together with
body_format; - disconnects the mailbox even when polling fails.
The normalized mail.received payload contains message_id, uid, folder, from, from_name, to, cc,
subject, body, body_format, and sent_at.
The persisted payload remains the audit source and is never mutated for AI use. Immediately before classification,
Brezel creates a model-only copy: HTML structure, styles, scripts, hidden content, CSS fragments, tracking whitespace,
and excessive blank lines are removed from body. The 50,000-character model limit is applied after this cleanup.
Keeping the raw payload allows later retries to benefit from improved preprocessing without fetching the mail again.