diff --git a/README.md b/README.md index 90dd781..56cceb4 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,13 @@ Plays a chime sound to notify the user. + +## Webhook + +Send a webhook to the specified URL. Supports customizing JSON body with the `json_format` template. + + + ## Unified Notification Supports multiple notification types in one node for convenience. diff --git a/__init__.py b/__init__.py index 4f82269..9e086d3 100644 --- a/__init__.py +++ b/__init__.py @@ -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" diff --git a/assets/webhook_node.jpg b/assets/webhook_node.jpg new file mode 100644 index 0000000..1313ae3 Binary files /dev/null and b/assets/webhook_node.jpg differ diff --git a/nodes/webhook.py b/nodes/webhook.py new file mode 100644 index 0000000..966f7b4 --- /dev/null +++ b/nodes/webhook.py @@ -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": ""}'}), + "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) + payload = json.loads(payload) + res = requests.post(webhook_url, json=payload, timeout=timeout) + res.raise_for_status() + return (0, )