Files
dify-plugin-sdks/python/examples/github_trigger/triggers/ping.py
T
Harry c67ef57f10 feat(trigger): introduce new error class and enhance event payload handling
- Added `TriggerIgnoreEventError` to handle cases where events should be ignored based on filter criteria.
- Updated various GitHub trigger files to return relevant payload fields directly, improving data accessibility for event handling.
- Enhanced the handling of event filtering in triggers to ensure only relevant events are processed.

These changes improve the robustness and clarity of the GitHub trigger integration, allowing for better error management and data handling.
2025-09-19 13:17:59 +08:00

36 lines
1.1 KiB
Python

from collections.abc import Mapping
from typing import Any
from werkzeug import Request
from dify_plugin.entities.trigger import Event
from dify_plugin.errors.trigger import TriggerIgnoreEventError
from dify_plugin.interfaces.trigger import TriggerEvent
class PingTrigger(TriggerEvent):
"""
GitHub Ping Event Trigger
This trigger handles GitHub ping events and extracts relevant
information from the webhook payload to provide as variables to the workflow.
"""
def _trigger(self, request: Request, parameters: Mapping[str, Any]) -> Event:
"""
Handle GitHub ping event trigger
"""
# Get the event payload
payload = request.get_json()
if not payload:
raise ValueError("No payload received")
# Return the relevant payload fields directly
return Event(variables={
"zen": payload.get("zen"),
"hook_id": payload.get("hook_id"),
"hook": payload.get("hook"),
"repository": payload.get("repository"),
"sender": payload.get("sender"),
})