|
| 1 | +--- |
| 2 | +description: How do I trigger scripts and flows from Nextcloud or Google Drive/Calendar events in Windmill? |
| 3 | +--- |
| 4 | + |
| 5 | +import DocCard from '@site/src/components/DocCard'; |
| 6 | + |
| 7 | +# Native triggers |
| 8 | + |
| 9 | +Native triggers allow external services to push events directly to Windmill and trigger [scripts](../../script_editor/index.mdx) and [flows](../../flows/1_flow_editor.mdx). Unlike [scheduled polls](../../flows/10_flow_trigger.mdx), native triggers receive real-time push notifications from the external service via webhooks or watch channels, so your runnables execute as soon as events occur. |
| 10 | + |
| 11 | +Native triggers is a [self-hosted Enterprise](/pricing) feature. |
| 12 | + |
| 13 | +Currently supported services: |
| 14 | + |
| 15 | +- [Nextcloud](#nextcloud-triggers) - file and folder change events |
| 16 | +- [Google Drive](#google-drive-triggers) - file and folder change events |
| 17 | +- [Google Calendar](#google-calendar-triggers) - calendar event changes |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## How it works |
| 22 | + |
| 23 | +Native triggers use OAuth to authenticate with the external service. Each trigger registers a webhook or watch channel on the external service, which sends notifications to Windmill when events occur. Windmill then executes the configured script or flow with the event data. |
| 24 | + |
| 25 | +The general setup follows two steps: |
| 26 | + |
| 27 | +1. **Connect the service** via workspace settings (OAuth authentication) |
| 28 | +2. **Create a trigger** on a script or flow, selecting the service and configuring which events to watch |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +## Setup |
| 33 | + |
| 34 | +### Workspace integration |
| 35 | + |
| 36 | +Before creating native triggers, you need to connect the external service in your workspace settings. |
| 37 | + |
| 38 | +1. Go to **Workspace settings** > **Integrations** |
| 39 | +2. Select the service you want to connect (Nextcloud or Google) |
| 40 | +3. Provide the OAuth credentials (client ID and client secret) |
| 41 | +4. Complete the OAuth authorization flow |
| 42 | + |
| 43 | +<!-- TODO: add screenshot of workspace integrations page --> |
| 44 | + |
| 45 | +For Google triggers, instance admins can optionally share OAuth credentials across workspaces, so individual workspace admins don't need to create their own Google OAuth app. |
| 46 | + |
| 47 | +For Nextcloud, you also need to provide the base URL of your Nextcloud instance. |
| 48 | + |
| 49 | +### Create a trigger |
| 50 | + |
| 51 | +Once the workspace integration is configured: |
| 52 | + |
| 53 | +1. Open the script or flow you want to trigger |
| 54 | +2. Go to the **Triggers** tab |
| 55 | +3. Select **Native trigger** and choose the service |
| 56 | +4. Configure the service-specific options (see sections below) |
| 57 | +5. Save the trigger |
| 58 | + |
| 59 | +<!-- TODO: add screenshot of trigger creation --> |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +## Nextcloud triggers |
| 64 | + |
| 65 | +Nextcloud native triggers watch for file and folder changes on a [Nextcloud](https://nextcloud.com/) instance and trigger a script or flow when events occur. |
| 66 | + |
| 67 | +### Prerequisites |
| 68 | + |
| 69 | +- A Nextcloud instance with OAuth2 configured |
| 70 | +- The Nextcloud OAuth2 app enabled and a client registered |
| 71 | + |
| 72 | +### Configuration |
| 73 | + |
| 74 | +When creating a Nextcloud trigger, configure: |
| 75 | + |
| 76 | +- **Events** - select which event types to watch (e.g. file created, file updated, file deleted) |
| 77 | + |
| 78 | +<!-- TODO: add screenshot of Nextcloud trigger configuration --> |
| 79 | + |
| 80 | +--- |
| 81 | + |
| 82 | +## Google Drive triggers |
| 83 | + |
| 84 | +Google Drive native triggers watch for changes to files or folders in [Google Drive](https://drive.google.com/) and trigger a script or flow when modifications occur. |
| 85 | + |
| 86 | +### Prerequisites |
| 87 | + |
| 88 | +- A Google Cloud project with the Google Drive API enabled |
| 89 | +- OAuth 2.0 credentials (client ID and client secret) configured with the appropriate scopes |
| 90 | + |
| 91 | +### Configuration |
| 92 | + |
| 93 | +When creating a Google Drive trigger, configure: |
| 94 | + |
| 95 | +- **File or folder** - select a file or folder from your Google Drive to watch for changes. You can browse My Drive, Shared with me, and Shared drives. |
| 96 | + |
| 97 | +<!-- TODO: add screenshot of Google Drive trigger configuration with file picker --> |
| 98 | + |
| 99 | +Google Drive triggers use push notifications via [watch channels](https://developers.google.com/drive/api/guides/push). Channels expire after 24 hours and Windmill automatically renews them before expiration. |
| 100 | + |
| 101 | +--- |
| 102 | + |
| 103 | +## Google Calendar triggers |
| 104 | + |
| 105 | +Google Calendar native triggers watch for changes to events in a [Google Calendar](https://calendar.google.com/) and trigger a script or flow when calendar events are created, updated, or deleted. |
| 106 | + |
| 107 | +### Prerequisites |
| 108 | + |
| 109 | +- A Google Cloud project with the Google Calendar API enabled |
| 110 | +- OAuth 2.0 credentials (client ID and client secret) configured with the appropriate scopes |
| 111 | + |
| 112 | +### Configuration |
| 113 | + |
| 114 | +When creating a Google Calendar trigger, configure: |
| 115 | + |
| 116 | +- **Calendar** - select a calendar from your Google account to watch for event changes |
| 117 | + |
| 118 | +<!-- TODO: add screenshot of Google Calendar trigger configuration with calendar picker --> |
| 119 | + |
| 120 | +Google Calendar triggers use push notifications via [watch channels](https://developers.google.com/calendar/api/guides/push). Channels expire after 7 days and Windmill automatically renews them before expiration. |
| 121 | + |
| 122 | +--- |
| 123 | + |
| 124 | +## Implementation examples |
| 125 | + |
| 126 | +### Basic script |
| 127 | + |
| 128 | +The trigger passes event data as arguments to your script. The payload format depends on the service. |
| 129 | + |
| 130 | +```typescript |
| 131 | +export async function main(payload: object) { |
| 132 | + console.log("Received event:", JSON.stringify(payload)); |
| 133 | + return { processed: true }; |
| 134 | +} |
| 135 | +``` |
| 136 | + |
| 137 | +### Using a preprocessor |
| 138 | + |
| 139 | +If you configure a [preprocessor](../43_preprocessors/index.mdx), you can transform the event data before it reaches the main function. |
| 140 | + |
| 141 | +```typescript |
| 142 | +export async function preprocessor( |
| 143 | + event: { |
| 144 | + kind: 'google' | 'nextcloud', |
| 145 | + payload: object, |
| 146 | + } |
| 147 | +) { |
| 148 | + if (event.kind === 'google') { |
| 149 | + return { |
| 150 | + payload: event.payload, |
| 151 | + }; |
| 152 | + } |
| 153 | + |
| 154 | + throw new Error(`Expected google or nextcloud trigger kind, got: ${event.kind}`); |
| 155 | +} |
| 156 | +``` |
| 157 | + |
| 158 | +Then your `main` function receives the processed data: |
| 159 | + |
| 160 | +```typescript |
| 161 | +export async function main(payload: object) { |
| 162 | + console.log("Processed event:", JSON.stringify(payload)); |
| 163 | +} |
| 164 | +``` |
| 165 | + |
| 166 | +## Error handling |
| 167 | + |
| 168 | +Native triggers support local error handlers that override workspace error handlers for specific triggers. See the [error handling documentation](../10_error_handling/index.mdx#trigger-error-handlers) for configuration details and examples. |
0 commit comments