From 4637795f5c6c2e04e615139156fcfab05eb40b8c Mon Sep 17 00:00:00 2001 From: iSuneast Date: Tue, 25 Nov 2025 06:59:45 +0900 Subject: [PATCH] add WebhookNotifierVHSNode --- README.md | 4 +- __init__.py | 7 +++- webhook_notifier.py | 94 +++++++++++++++++++++++++++++++++++---------- 3 files changed, 82 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 6a198cf..4850d05 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 generating images - Supports custom JSON data in notifications -- Simple to use, just connect to an `IMAGE` output or `VHS_FILENAMES` output as a trigger (the actual data is ignored) +- Provides two nodes: + - `Webhook Notifier`: connect to an `IMAGE` output as a trigger + - `Webhook Notifier (VHS)`: connect to a `VHS_FILENAMES` output as a trigger ## Installation diff --git a/__init__.py b/__init__.py index e033b2a..05316de 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, WebhookNotifierVHSNode 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["WebhookNotifierVHSNode"] = WebhookNotifierVHSNode +NODE_DISPLAY_NAME_MAPPINGS["WebhookNotifierVHSNode"] = "Webhook Notifier (VHS)" \ No newline at end of file diff --git a/webhook_notifier.py b/webhook_notifier.py index 63dfd60..d6ba9e5 100644 --- a/webhook_notifier.py +++ b/webhook_notifier.py @@ -1,15 +1,33 @@ import requests import json -import time import threading + +def send_webhook_request(webhook_url, payload): + """ + 发送 webhook 请求的通用函数,供各个节点复用。 + """ + try: + response = requests.post( + webhook_url, + json=payload, + headers={"Content-Type": "application/json"} + ) + + if response.status_code >= 400: + print(f"Webhook notification failed: {response.status_code} - {response.text}") + else: + print(f"Webhook notification successful: {response.status_code}") + except Exception as e: + print(f"Error sending webhook: {str(e)}") + class WebhookNotifierNode: @classmethod def INPUT_TYPES(cls): return { "required": { - # 接收图像结果或 VHS 节点输出的文件名列表,用于作为触发输入 - "images": ("IMAGE", "VHS_FILENAMES"), + # 接收图像结果,用于作为触发输入 + "images": ("IMAGE",), "webhook_url": ("STRING", {"default": "https://example.com/webhook"}) }, "optional": { @@ -26,21 +44,6 @@ class WebhookNotifierNode: FUNCTION = "notify" CATEGORY = "utils" - def send_webhook(self, webhook_url, payload): - try: - response = requests.post( - webhook_url, - json=payload, - headers={"Content-Type": "application/json"} - ) - - if response.status_code >= 400: - print(f"Webhook notification failed: {response.status_code} - {response.text}") - else: - print(f"Webhook notification successful: {response.status_code}") - except Exception as e: - print(f"Error sending webhook: {str(e)}") - def notify(self, images, webhook_url, additional_info="{}"): try: # Try to parse additional information @@ -56,7 +59,7 @@ class WebhookNotifierNode: # Start the webhook sending in a background thread threading.Thread( - target=self.send_webhook, + target=send_webhook_request, args=(webhook_url, payload), daemon=True ).start() @@ -66,4 +69,55 @@ class WebhookNotifierNode: print(f"Error preparing webhook: {str(e)}") # No return value - return () \ No newline at end of file + return () + + +class WebhookNotifierVHSNode: + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + # 接收 VHS/VideoHelperSuite 等节点输出的文件名列表,用于作为触发输入 + "vhs_filenames": ("VHS_FILENAMES",), + "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, vhs_filenames, webhook_url, additional_info="{}"): + try: + # 解析附加信息 + try: + extra_info = json.loads(additional_info) if additional_info else {} + except json.JSONDecodeError: + extra_info = {} + + # 构建 payload(默认不发送具体文件名,仅作为触发) + payload = { + **extra_info + } + + # 在后台线程中发送 webhook + threading.Thread( + target=send_webhook_request, + args=(webhook_url, payload), + daemon=True + ).start() + print("Webhook notification (VHS) started in background") + + except Exception as e: + print(f"Error preparing webhook (VHS): {str(e)}") + + # 无返回值 + return () \ No newline at end of file