Adds webhook node.

This commit is contained in:
Royce Schultz
2024-05-20 22:57:50 -06:00
parent bd144ef25d
commit fcebd3ee84
4 changed files with 40 additions and 0 deletions
+7
View File
@@ -19,6 +19,13 @@ Plays a chime sound to notify the user.
<img src="assets/play_sound_node.jpg" width="400"/>
## Webhook
Send a webhook to the specified URL. Supports customizing JSON body with the `json_format` template.
<img src="assets/webhook_node.jpg" width="400"/>
## Unified Notification
Supports multiple notification types in one node for convenience.
+3
View File
@@ -1,17 +1,20 @@
from .nodes.play_sound import PlaySound
from .nodes.system_notification import SystemNotification
from .nodes.unified_notification import UnifiedNotification
from .nodes.webhook import Webhook
NODE_CLASS_MAPPINGS = {
"Notif-PlaySound": PlaySound,
"Notif-SystemNotification": SystemNotification,
"Notif-UnifiedNotification": UnifiedNotification,
"Notif-Webhook": Webhook,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"Notif-PlaySound": "Play Sound",
"Notif-SystemNotification": "System Notification",
"Notif-UnifiedNotification": "Unified Notification",
"Notif-Webhook": "Webhook",
}
WEB_DIRECTORY = "./web"
Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

+30
View File
@@ -0,0 +1,30 @@
import requests
import json
from .util import ComfyAnyType
class Webhook:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"any": (ComfyAnyType("*"), {}),
# "mode": (["always", "on empty queue"], {}), # TODO: Need a way to get queue status from main.py
"webhook_url": ("STRING", {'default': 'http://localhost:5000/'}),
"notification_text": ('STRING', {'default': 'Your notification has triggered.'}),
"json_format": ('STRING', {'default': '{"text": "<notification_text>"}'}),
"timeout": ('FLOAT', {'default': 3, 'min': 0, 'max': 60}),
},
}
FUNCTION = 'hook'
OUTPUT_NODE = True
RETURN_TYPES = tuple()
CATEGORY = "notifications"
def hook(self, any, webhook_url, notification_text, json_format, timeout):
payload = json_format.replace("<notification_text>", notification_text)
payload = json.loads(payload)
res = requests.post(webhook_url, json=payload, timeout=timeout)
res.raise_for_status()
return (0, )