add WebhookNotifierVHSNode

This commit is contained in:
iSuneast
2025-11-25 06:59:45 +09:00
parent bb90e256f5
commit 4637795f5c
3 changed files with 82 additions and 23 deletions
+3 -1
View File
@@ -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
+5 -2
View File
@@ -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"
NODE_DISPLAY_NAME_MAPPINGS["WebhookNotifierNode"] = "Webhook Notifier"
NODE_CLASS_MAPPINGS["WebhookNotifierVHSNode"] = WebhookNotifierVHSNode
NODE_DISPLAY_NAME_MAPPINGS["WebhookNotifierVHSNode"] = "Webhook Notifier (VHS)"
+74 -20
View File
@@ -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 ()
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 ()