diff --git a/__init__.py b/__init__.py index 129a15e..0312984 100644 --- a/__init__.py +++ b/__init__.py @@ -1,9 +1,9 @@ -from .whatsapp_notify_node import WhatsAppNotifyNode +from .notify_whatsapp_twilio import WhatsAppNotifyNodeTwilio NODE_CLASS_MAPPINGS = { - "WhatsAppNotifyNode": WhatsAppNotifyNode, + "WhatsAppNotifyNodeTwilio": WhatsAppNotifyNodeTwilio, } NODE_DISPLAY_NAME_MAPPINGS = { - "WhatsAppNotifyNode": "📲 WhatsApp Notify", + "WhatsAppNotifyNodeTwilio": "📲 WhatsApp (Twilio)", } \ No newline at end of file diff --git a/__pycache__/__init__.cpython-312.pyc b/__pycache__/__init__.cpython-312.pyc index 3bedd6e..01dd697 100644 Binary files a/__pycache__/__init__.cpython-312.pyc and b/__pycache__/__init__.cpython-312.pyc differ diff --git a/__pycache__/notify_whatsapp_twilio.cpython-312.pyc b/__pycache__/notify_whatsapp_twilio.cpython-312.pyc new file mode 100644 index 0000000..214bc93 Binary files /dev/null and b/__pycache__/notify_whatsapp_twilio.cpython-312.pyc differ diff --git a/__pycache__/whatsapp_notify_node.cpython-312.pyc b/__pycache__/whatsapp_notify_node.cpython-312.pyc index e8e9bfd..88132bb 100644 Binary files a/__pycache__/whatsapp_notify_node.cpython-312.pyc and b/__pycache__/whatsapp_notify_node.cpython-312.pyc differ diff --git a/notify_whatsapp_twilio.py b/notify_whatsapp_twilio.py new file mode 100644 index 0000000..0e1a346 --- /dev/null +++ b/notify_whatsapp_twilio.py @@ -0,0 +1,40 @@ +from twilio.rest import Client + +class WhatsAppNotifyNodeTwilio: + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "img": ("IMAGE",), + "message": ("STRING", {"default": "✅ Workflow completed!"}), + "sid": ("STRING", {"default": "Your Twilio SID here"}), + "token": ("STRING", {"default": "Your Twilio Auth Token"}), + "from_number": ("STRING", {"default": "whatsapp:+14155238886"}), # Twilio Sandbox + "to_number": ("STRING", {"default": "whatsapp:+YOUR_PHONE_NUMBER"}), # Your verified number + } + } + + RETURN_TYPES = ("IMAGE",) + FUNCTION = "notify" + CATEGORY = "Notifications" + + def notify(self, img, message, sid, token, from_number, to_number): + try: + # Basic validation + required_fields = [sid, token, from_number, to_number] + if any(v.strip() == "" or "Twilio" in v for v in required_fields): + raise ValueError("One or more required fields are missing or still set to default.") + + client = Client(sid.strip(), token.strip()) + sent = client.messages.create( + from_=from_number.strip(), + body=message.strip(), + to=to_number.strip() + ) + print(f"[📲 WhatsAppNotifyNodeTwilio] ✅ WhatsApp message sent. SID: {sent.sid}") + + except Exception as e: + print("❌ WhatsAppNotifyNodeTwilio Error: ", str(e).split('\n')[0]) + + return (img,) + diff --git a/requirements.txt b/requirements.txt index e69de29..105a686 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1 @@ +twilio diff --git a/whatsapp_notify_node.py b/whatsapp_notify_node.py deleted file mode 100644 index f8846be..0000000 --- a/whatsapp_notify_node.py +++ /dev/null @@ -1,17 +0,0 @@ -class WhatsAppNotifyNode: - @classmethod - def INPUT_TYPES(cls): - return { - "required": { - "img": ("IMAGE",), - "message": ("STRING", {"default": "✅ Workflow completed!"}), - } - } - - RETURN_TYPES = ("IMAGE",) - FUNCTION = "notify" - CATEGORY = "Notifications" - - def notify(self, img, message: str): - print(f"[📲 WhatsAppNotifyNode] Message to send: {message}") - return (img,) # Pass image forward so node isn't "useless"