Skip to main content

What Is a Trigger Plugin?

Triggers were introduced in Dify v1.10.0 as a new type of start node. Unlike functional nodes such as Code, Tool, or Knowledge Retrieval, the purpose of a trigger is to convert third-party events into an input format that Dify can recognize and process.
Trigger Plugin Intro
For example, if you configure Dify as the new email event receiver in Gmail, every time you receive a new email, Gmail automatically sends an event to Dify that can be used to trigger a workflow. However:
  • Gmail’s original event format is not compatible with Dify’s input format.
  • There are thousands of platforms worldwide, each with its own unique event format.
Therefore, we need trigger plugins to define and parse these events from different platforms and in various formats, and to unify them into an input format that Dify can accept.

Technical Overview

Dify triggers are implemented based on webhooks, a widely adopted mechanism across the web. Many mainstream SaaS platforms (like GitHub, Slack, and Linear) support webhooks with comprehensive developer documentation. A webhook can be understood as an HTTP-based event dispatcher. Once an event-receiving address is configured, these SaaS platforms automatically push event data to the target server whenever a subscribed event occurs. To handle webhook events from different platforms in a unified way, Dify defines two core concepts: Subscription and Event.
  • Subscription: Webhook-based event dispatch requires registering Dify’s network address on a third-party platform’s developer console as the target server. In Dify, this configuration process is called a Subscription.
  • Event: A platform may send multiple types of events—such as email received, email deleted, or email marked as read—all of which are pushed to the registered address. A trigger plugin can handle multiple event types, with each event corresponding to a plugin trigger node in a Dify workflow.

Plugin Development

The development process for a trigger plugin is consistent with that of other plugin types (Tool, Data Source, Model, etc.). You can create a development template using the dify plugin init command. The generated file structure follows the standard plugin format specification.
  • manifest.yaml: Describes the plugin’s basic metadata.
  • provider directory: Contains the provider’s metadata, the code for creating subscriptions, and the code for classifying events after receiving webhook requests.
  • events directory: Contains the code for event handling and filtering, which supports local event filtering at the node level. You can create subdirectories to group related events.
For trigger plugins, the minimum required Dify version must be set to 1.10.0, and the SDK version must be >= 0.6.0.
Next, we’ll use GitHub as an example to illustrate the development process of a trigger plugin.

Subscription Creation

Webhook configuration methods vary significantly across mainstream SaaS platforms:
  • Some platforms (such as GitHub) support API-based webhook configuration. For these platforms, once OAuth authentication is completed, Dify can automatically set up the webhook.
  • Other platforms (such as Notion) do not provide a webhook configuration API and may require users to perform manual authentication.
To accommodate these differences, we divide the subscription process into two parts: the Subscription Constructor and the Subscription itself. For platforms like Notion, creating a subscription requires the user to manually copy the callback URL provided by Dify and paste it into their Notion workspace to complete the webhook setup. This process corresponds to the Paste URL to create a new subscription option in the Dify interface.
Paste URL to Create a New Subscription
To implement subscription creation via manual URL pasting, you need to modify two files: github.yaml and github.py.
Since GitHub webhooks use an encryption mechanism, a secret key is required to decrypt and validate incoming requests. Therefore, you need to declare webhook_secret in github.yaml.

Event Handling

Once an event is extracted, the corresponding implementation must filter the original HTTP request and transform it into an input format that Dify workflows can accept. Taking the Issue event as an example, you can define the event and its implementation through events/issues/issues.yaml and events/issues/issues.py, respectively. The event’s output can be defined in the output_schema section of issues.yaml, which follows the same JSON Schema specification as tool plugins.

Event Filtering

To filter out certain events—for example, to focus only on Issue events with a specific label—you can add parameters to the event definition in issues.yaml. Then, in the _on_event method, you can throw an EventIgnoreError exception to filter out events that do not meet the configured criteria.

Subscription Creation via OAuth or API Key

To enable automatic subscription creation via OAuth or API key, you need to modify the github.yaml and github.py files.
In github.yaml, add the following fields.
subscription_constructor is a concept abstracted by Dify to define how a subscription is constructed. It includes the following fields:
  • parameters (optional): Defines the parameters required to create a subscription, such as the event types to subscribe to or the target GitHub repository
  • credentials_schema (optional): Declares the required credentials for creating a subscription with an API key or access token, such as access_tokens for GitHub.
  • oauth_schema (optional): Required for implementing subscription creation via OAuth. For details on how to define it, see Add OAuth Support to Your Tool Plugin.

Once you have modified these two files, you’ll see the Create with API Key option in the Dify interface. Automatic subscription creation via OAuth can also be implemented in the same Constructor class: by adding an oauth_schema field under subscription_constructor, you can enable OAuth authentication.
OAuth & API Key Options

Explore More

The interface definitions and implementation methods of core classes in trigger plugin development are as follows.

Trigger

TriggerSubscriptionConstructor

Event


Edit this page | Report an issue