From 47973f6b5eee2c78df2ac7839941b70ca86b79e4 Mon Sep 17 00:00:00 2001 From: iSuneast Date: Fri, 19 Dec 2025 14:16:36 +0900 Subject: [PATCH] add WebhookNotifierAnyNode --- README.md | 28 +++++++++++++++++---- __init__.py | 7 ++++-- webhook_notifier.py | 59 ++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 83 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 92c5d2f..c3fc912 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,9 @@ Webhook notification plugin for ComfyUI, used to send webhook notifications when - Automatically sends webhook notifications after workflow execution - Supports custom JSON data in notifications -- Accepts any input type as trigger (IMAGE, STRING, LATENT, VHS_FILENAMES, etc.) +- Provides two nodes: + - `Webhook Notifier`: connects to an `IMAGE` output as trigger + - `Webhook Notifier (Any)`: accepts any input type as trigger (IMAGE, STRING, LATENT, VHS_FILENAMES, etc.) ## Installation @@ -27,11 +29,24 @@ pip install -r requirements.txt ## Usage -The plugin provides a Webhook Notifier node that can be connected to any output to send notifications when execution is complete. +The plugin provides two Webhook Notifier nodes: -Parameter description: +### Webhook Notifier + +Connects to an `IMAGE` output to send notifications when image generation is complete. + +Parameters: +- `images`: Trigger input (required, connects to an `IMAGE` output; the data is **not** read or sent, only used as a trigger) +- `webhook_url`: Webhook URL address (required, default is "https://example.com/webhook") +- `additional_info`: Additional information in JSON format (optional, default is empty) + +### Webhook Notifier (Any) + +Accepts any input type to send notifications when execution is complete. + +Parameters: +- `any_input`: Trigger input (required, accepts any type such as IMAGE, STRING, LATENT, VHS_FILENAMES, etc.; the data is **not** read or sent, only used as a trigger) - `webhook_url`: Webhook URL address (required, default is "https://example.com/webhook") -- `any_input`: Trigger input (optional, accepts any type such as IMAGE, STRING, LATENT, VHS_FILENAMES, etc.; the data is **not** read or sent, only used as a trigger) - `additional_info`: Additional information in JSON format (optional, default is empty) ## Webhook Notification Format @@ -52,7 +67,10 @@ This exact JSON will be sent to the webhook URL. If the additional_info field is ## Example -Connect any output (IMAGE, STRING, LATENT, VHS_FILENAMES, etc.) to the WebhookNotifier node's `any_input`, set your webhook URL, and optionally provide additional information in JSON format. When the upstream node completes execution, the webhook will send a POST request to the specified URL with your custom data. +- **Webhook Notifier**: Connect an image output to the `images` input, set your webhook URL, and optionally provide additional information in JSON format. +- **Webhook Notifier (Any)**: Connect any output (IMAGE, STRING, LATENT, VHS_FILENAMES, etc.) to the `any_input`, set your webhook URL, and optionally provide additional information. + +When the upstream node completes execution, the webhook will send a POST request to the specified URL with your custom data. ## Debugging diff --git a/__init__.py b/__init__.py index 91cbb23..eb0ab80 100644 --- a/__init__.py +++ b/__init__.py @@ -4,7 +4,10 @@ import os NODE_CLASS_MAPPINGS = {} NODE_DISPLAY_NAME_MAPPINGS = {} -from .webhook_notifier import WebhookNotifierNode +from .webhook_notifier import WebhookNotifierNode, WebhookNotifierAnyNode NODE_CLASS_MAPPINGS["WebhookNotifierNode"] = WebhookNotifierNode -NODE_DISPLAY_NAME_MAPPINGS["WebhookNotifierNode"] = "Webhook Notifier" \ No newline at end of file +NODE_DISPLAY_NAME_MAPPINGS["WebhookNotifierNode"] = "Webhook Notifier" + +NODE_CLASS_MAPPINGS["WebhookNotifierAnyNode"] = WebhookNotifierAnyNode +NODE_DISPLAY_NAME_MAPPINGS["WebhookNotifierAnyNode"] = "Webhook Notifier (Any)" \ No newline at end of file diff --git a/webhook_notifier.py b/webhook_notifier.py index dfdc9f6..0f36e23 100644 --- a/webhook_notifier.py +++ b/webhook_notifier.py @@ -31,11 +31,11 @@ class WebhookNotifierNode: def INPUT_TYPES(cls): return { "required": { + # 接收图像结果,用于作为触发输入 + "images": ("IMAGE",), "webhook_url": ("STRING", {"default": "https://example.com/webhook"}) }, "optional": { - # 通配符,接受任意类型作为触发输入 - "any_input": ("*",), "additional_info": ("STRING", {"default": "{}", "multiline": True}) }, "hidden": { @@ -49,7 +49,7 @@ class WebhookNotifierNode: FUNCTION = "notify" CATEGORY = "utils" - def notify(self, webhook_url, any_input=None, additional_info="{}"): + def notify(self, images, webhook_url, additional_info="{}"): try: # Try to parse additional information try: @@ -74,4 +74,55 @@ class WebhookNotifierNode: print(f"Error preparing webhook: {str(e)}") # No return value - return () \ No newline at end of file + return () + + +class WebhookNotifierAnyNode: + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + # 通配符,接受任意类型作为触发输入 + "any_input": ("*",), + "webhook_url": ("STRING", {"default": "https://example.com/webhook"}) + }, + "optional": { + "additional_info": ("STRING", {"default": "{}", "multiline": True}) + }, + "hidden": { + } + } + + OUTPUT_NODE = True + + RETURN_TYPES = () + RETURN_NAMES = () + FUNCTION = "notify" + CATEGORY = "utils" + + def notify(self, any_input, webhook_url, additional_info="{}"): + try: + # Try to parse additional information + try: + extra_info = json.loads(additional_info) if additional_info else {} + except json.JSONDecodeError: + extra_info = {} + + # Construct payload + payload = { + **extra_info + } + + # Start the webhook sending in a background thread + threading.Thread( + target=send_webhook_request, + args=(webhook_url, payload), + daemon=True + ).start() + print("Webhook notification started in background") + + except Exception as e: + print(f"Error preparing webhook: {str(e)}") + + # No return value + return () \ No newline at end of file