mirror of
https://github.com/langgenius/dify-plugin-sdks.git
synced 2026-07-22 18:35:29 -04:00
Google Drive Trigger Example
This example Trigger plugin demonstrates how to automatically subscribe to Google Drive change notifications using the Drive v3 API. It provisions a webhook channel through OAuth, validates incoming notification headers, and transforms change feed entries into workflow variables.
Features
- OAuth-based subscription constructor that issues a
changes.watchrequest and stores the generated channel metadata (channel ID, resource ID, expiration, verification token). - Trigger implementation that validates Google-signed headers (
X-Goog-*) and ignores sync handshakes. - Event handler that fetches the Drive change feed, persists the most recent
startPageToken, and exposes structured information about each change to workflows. - Optional filters to include removed items, restrict to "My Drive", and tune the number of changes fetched per notification.
Setup
- Create a Google Cloud project with the Google Drive API enabled.
- Configure an OAuth client (type Web application) and add the Dify callback URL as an authorized redirect URI.
- Copy the OAuth client ID and secret into the plugin provider configuration in Dify.
- Deploy this plugin and add the Google Drive Change Detected trigger to your workflow.
- Authenticate with Google Drive via OAuth and select the Drive spaces you want to monitor. The constructor will start a new watch channel automatically.
Testing
Compile-time validation ensures the module imports cleanly:
python -m compileall python/examples/google_drive_trigger
Attention
- Enable the Google Drive API in the Google Cloud Console.