Event Bus
Trigger workflows from external events like a new file in a Drive folder.
The Event Bus lets a workflow start in response to an external event instead of only an
explicit HTTP trigger. The first source is Google Drive folder watching; a Gmail (email)
source is also available in staging, and the model is unified and extensible to Slack and more.
Event sources are managed under /api/event-bus/*. Build against the documented
endpoints; treat anything not in the
Event Bus API reference as "coming soon".
Core model
Four pieces move an external change into a running workflow:
- Event source — an external system that emits events: a watched
google_drivefolder, a Gmail mailbox, etc. It owns the watch channel and credentials. Created viaPOST /event-bus/sources. - Event — a normalized record the bus builds from the source's raw notification:
source_type,event_type(e.g.file_created), apayloadof source-specific fields, and a generatedevent_id. Every event is written to the event log (audit trail). - Subscription — links one event source to one workflow (activity), with the
event_typesand optionalfilterit cares about. No subscription, no trigger — the source only watches; the subscription is what fires a workflow. - Dispatch — for each matching subscription, the bus builds the workflow inputs from the
event and queues a workflow execution (
source: "event").
A source watches; a subscription connects that source to a workflow. You almost always create both. See Event-driven automation for the full sequence.
The Drive flow
Drive sends several notifications per upload. TurfAI settles the file (waits until version
and size stop changing) and de-duplicates per (file_id, source) before publishing exactly one
event, so a workflow fires once per file.
Creating a Drive event source
The owner's Google credentials are read from their connected integration — you pass the folder, not tokens.
curl -X POST https://apisandbox.turfai.in/api/event-bus/sources \
-H "Authorization: Bearer $TURFAI_JWT" \
-H "Content-Type: application/json" \
-d '{
"source_type": "google_drive",
"folder_id": "1AbCfolderId",
"folder_name": "Invoices"
}'{
"success": true,
"data": {
"id": 12,
"name": "Invoices",
"source_type": "google_drive",
"drive_item_id": "1AbCfolderId",
"drive_item_type": "folder",
"drive_item_name": "Invoices",
"is_active": true,
"watch_expiry": "2026-06-21T10:00:00.000Z"
}
}If the server's public HTTPS URL isn't configured at creation time the source comes back with
is_active: false (a pending watch). Activate it to register the real Drive push channel:
curl -X POST https://apisandbox.turfai.in/api/event-bus/sources/12/activate \
-H "Authorization: Bearer $TURFAI_JWT"{ "success": true, "data": { "id": 12, "is_active": true, "watch_expiry": "2026-06-21T10:00:00.000Z" } }List sources (GET /event-bus/sources), read the audit trail (GET /event-bus/logs), and view
aggregate stats (GET /event-bus/stats). Delete with DELETE /event-bus/sources/:id — this
calls channels.stop() to tear down the Google watch.
Watch channel renewal & expiry
Google Drive push channels expire after at most 24 hours. TurfAI stores watch_expiry on the
source and an hourly scheduler renews any watch expiring within ~2 hours automatically, so an
active source keeps firing without intervention. If renewal fails, the source is marked
is_active: false with an error_message, and notifications stop until you recreate or
re-activate it. You can force a renewal sweep with POST /event-bus/renew-watches?force=true.
Event inputs in your workflow
When a Drive file is created, the dispatched workflow receives the event metadata plus the file payload as inputs:
{
"trigger_type": "event",
"event_id": "evt_a1b2c3d4",
"event_source": "google_drive",
"event_type": "file_created",
"event_timestamp": "2026-06-20T10:00:00.000Z",
"file_id": "1XyZdriveFileId",
"file_name": "invoice-0420.pdf",
"file_mime_type": "application/pdf",
"file_size": "102400",
"file_url": "gs://turfdms/uploads/...",
"file_web_link": "https://drive.google.com/file/d/1XyZdriveFileId",
"file_document_id": 789,
"folder_id": "1AbCfolderId",
"folder_name": "Invoices",
"change_type": "created"
}Reference these with {{file_id}}, {{file_name}}, etc. in downstream nodes — typically a
google_drive_fetch (or the already-created file_document_id) followed by extraction and a
notification. Other Drive event_types are file_modified, file_removed, and file_deleted.
Prerequisites
Drive watching requires:
- Connected Google access for the source owner (delegated OAuth — see Authentication); the Drive API enabled on the Google project.
- A public HTTPS endpoint with a valid certificate (Google won't push to
http://orlocalhost) and Google domain verification for push notifications.
Build it hands-on in Event-driven automation.
Reference
Event Bus API and the synced Google integrations quick start.