mirror of
https://github.com/langgenius/dify-plugin-sdks.git
synced 2026-07-22 10:25:23 -04:00
6220b50946
- Bumped version from 1.3.0 to 1.3.1 in the manifest. - Removed deprecated issue comment events: issue_comment_created, issue_comment_edited, issue_comment_deleted. - Consolidated issue comment handling into a unified structure for better maintainability. - Updated README to reflect changes in event handling and provide clearer setup instructions.
34 lines
978 B
Python
34 lines
978 B
Python
from __future__ import annotations
|
|
|
|
from collections.abc import Mapping
|
|
from typing import Any
|
|
|
|
from werkzeug import Request
|
|
|
|
from dify_plugin.errors.trigger import EventIgnoreError
|
|
|
|
|
|
def load_json_payload(request: Request) -> Mapping[str, Any]:
|
|
"""Load JSON payload from request, raising if missing."""
|
|
payload = request.get_json()
|
|
if not payload:
|
|
raise ValueError("No payload received")
|
|
return payload
|
|
|
|
|
|
def ensure_action(payload: Mapping[str, Any], expected_action: str | None) -> None:
|
|
"""Ensure payload action matches expected."""
|
|
if not expected_action:
|
|
return
|
|
|
|
if payload.get("action") != expected_action:
|
|
raise EventIgnoreError()
|
|
|
|
|
|
def require_mapping(payload: Mapping[str, Any], key: str) -> Mapping[str, Any]:
|
|
"""Require that payload contains a mapping under given key."""
|
|
value = payload.get(key)
|
|
if not isinstance(value, Mapping):
|
|
raise ValueError(f"No {key} data in payload")
|
|
return value
|