add WebhookNotifierAnyNode
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
+5
-2
@@ -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"
|
||||
NODE_DISPLAY_NAME_MAPPINGS["WebhookNotifierNode"] = "Webhook Notifier"
|
||||
|
||||
NODE_CLASS_MAPPINGS["WebhookNotifierAnyNode"] = WebhookNotifierAnyNode
|
||||
NODE_DISPLAY_NAME_MAPPINGS["WebhookNotifierAnyNode"] = "Webhook Notifier (Any)"
|
||||
+55
-4
@@ -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 ()
|
||||
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 ()
|
||||
Reference in New Issue
Block a user