Connect and credential store
Code update to allow connect anything to get notifications anywhere in your flows. And allow stored credentials
This commit is contained in:
@@ -48,17 +48,23 @@ In User field, enter specific device key **or** add group key.
|
||||
|
||||
In ComfyUI:
|
||||
|
||||
1. Drag your image output (e.g., from `VAE Decode`) to the **Send To Http Webhook** node.
|
||||

|
||||
1. Drag your image output (e.g., from `VAE Decode`) to the **Send To Pushover** node.
|
||||

|
||||
2. Configure:
|
||||
- `connect_anything` : connect any output (mandatory to work)
|
||||
- `webhook_url`: default is correct.
|
||||
- `token`: the pushover app token
|
||||
- `token`: the pushover app token (or use stored credentials option, see step 3)
|
||||
- `user`: Your user OR group key.
|
||||
- `image`: if you want an image in your pushover, connect this node and switch on attach_image
|
||||
3. Optional (since version 1.2)
|
||||
create an .env in the same folder as this custom-node, see example folder but rename to '.env'
|
||||
in the node select, 'use stored credentials', any credentials in the node fields will be ignored **even when you enter them!**
|
||||
---
|
||||
|
||||
## 🖼️ UI Example
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
---
|
||||
|
||||
@@ -69,6 +75,8 @@ ComfyUI_UploadToWebHookPushOver/
|
||||
├── __init__.py
|
||||
├── requirements.txt
|
||||
└── install.sh
|
||||
└── pyproject.toml
|
||||
└── .env (optional file see how to use step 3)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
+57
-18
@@ -6,45 +6,71 @@ import base64
|
||||
from PIL import Image
|
||||
import folder_paths
|
||||
|
||||
# wildcard trick is taken from pythongossss's
|
||||
class AnyType(str):
|
||||
def __ne__(self, __value: object) -> bool:
|
||||
return False
|
||||
|
||||
any_typ = AnyType("*")
|
||||
def load_env_variable(file_path, variable_name):
|
||||
# Read the .env file
|
||||
try:
|
||||
with open(file_path, 'r') as env_file:
|
||||
for line in env_file:
|
||||
key_value = line.strip().split('=')
|
||||
if len(key_value) == 2 and key_value[0] == variable_name:
|
||||
return key_value[1].strip()
|
||||
except FileNotFoundError:
|
||||
print(f"Error: The file {file_path} was not found.")
|
||||
except Exception as e:
|
||||
print(f"An error occurred while reading the .env file: {e}")
|
||||
# Return None if the variable is not found
|
||||
return None
|
||||
|
||||
class UploadToPushOver:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"images": ("IMAGE",),
|
||||
"connect_anything": (any_typ,),
|
||||
"webhook_url": ("STRING", {"default": "https://api.pushover.net/1/messages.json"}),
|
||||
"token": ("STRING", {"default": "enter your application key"}),
|
||||
"user": ("STRING", {"default": "enter user or group key"}),
|
||||
"title": ("STRING", {"default": ""}),
|
||||
"title": ("STRING", {"default": "Comfy push title"}),
|
||||
"priority": ("INT", {"default": 0, "lowest": -2, "max": 2}),
|
||||
"sound":(["pushover", "bike", "bugle", "cashregister", "classical", "cosmic", "falling", "gamelan", "incoming", "intermission", "magic", "mechanical", "pianobar", "siren", "spacealarm", "tugboat", "alien", "climb", "persistent", "echo", "updown", "vibrate", "none"],),
|
||||
"attachment_type":("STRING", {"default": "image/png"}),
|
||||
# "attachment_type":("STRING", {"default": "image/png"}),
|
||||
"attach_image": ("BOOLEAN", {"default": True}),
|
||||
"prompt_id": ("STRING", {"default": "Will be your pushover message, when empty: Workflow ready", "multiline": True})
|
||||
},
|
||||
"optional": {
|
||||
"images": ("IMAGE",),
|
||||
"token": ("STRING", {"default": "enter your application key"}),
|
||||
"user": ("STRING", {"default": "enter user or group key"}),
|
||||
"use_stored_credentials": ("BOOLEAN", {"default": False}),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("STRING",)
|
||||
RETURN_TYPES = (any_typ,)
|
||||
OUTPUT_NODE = True
|
||||
CATEGORY = "Notification"
|
||||
FUNCTION = "generate_and_upload_image"
|
||||
|
||||
|
||||
def generate_and_upload_image(
|
||||
self,
|
||||
images,
|
||||
connect_anything,
|
||||
webhook_url: str,
|
||||
use_stored_credentials:False,
|
||||
token: str,
|
||||
title: str,
|
||||
user: str,
|
||||
priority: int,
|
||||
sound: str,
|
||||
attachment_type: str,
|
||||
attach_image: True,
|
||||
save_image=True,
|
||||
attach_image:True,
|
||||
prompt_id: str = "",
|
||||
images: str = "",
|
||||
):
|
||||
output_dir = folder_paths.get_output_directory() if save_image else folder_paths.get_temp_directory()
|
||||
|
||||
output_dir = folder_paths.get_temp_directory()
|
||||
#output_dir = folder_paths.get_output_directory() if save_image else folder_paths.get_temp_directory()
|
||||
# above is old line from original webhook creator
|
||||
(
|
||||
full_output_folder,
|
||||
filename,
|
||||
@@ -59,8 +85,18 @@ class UploadToPushOver:
|
||||
parsed_data["message"] = prompt_id
|
||||
else:
|
||||
parsed_data["message"] = "Workflow ready" # message can't be empty, pushover wont accept it.
|
||||
parsed_data["token"] = token
|
||||
parsed_data["user"] = user
|
||||
## if stored credentials are used load from file else use input fields.
|
||||
if use_stored_credentials:
|
||||
env_file_path = './.env'
|
||||
apptoken = load_env_variable(env_file_path, 'apptoken')
|
||||
usertoken = load_env_variable(env_file_path, 'usertoken')
|
||||
parsed_data["token"] = apptoken
|
||||
parsed_data["user"] = usertoken
|
||||
print(f"env loading: {apptoken}")
|
||||
else:
|
||||
parsed_data["token"] = token
|
||||
parsed_data["user"] = user
|
||||
|
||||
parsed_data["title"] = title
|
||||
parsed_data["priority"] = priority
|
||||
parsed_data["sound"] = sound
|
||||
@@ -71,7 +107,6 @@ class UploadToPushOver:
|
||||
single_image = 255.0 * images[0].cpu().numpy()
|
||||
single_image_pil = Image.fromarray(single_image.astype(np.uint8))
|
||||
single_image_pil.save(single_file_path)
|
||||
|
||||
with open(single_file_path, "rb") as file:
|
||||
encoded_image = base64.b64encode(file.read()).decode("utf-8")
|
||||
if attach_image:
|
||||
@@ -80,10 +115,14 @@ class UploadToPushOver:
|
||||
webhook_url,
|
||||
data=parsed_data
|
||||
)
|
||||
|
||||
else:
|
||||
response = requests.post(
|
||||
webhook_url,
|
||||
data=parsed_data
|
||||
)
|
||||
# Response output
|
||||
if response.status_code == 200 or response.status_code == 201 or response.status_code == 204:
|
||||
print("✅ Successfully uploaded to Webhook.")
|
||||
print("✅ Successfully uploaded to Pushover.")
|
||||
print(f"Response Code: {response.status_code}")
|
||||
print(f"Response Text: {response.text}")
|
||||
else:
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
**Version 1.2.0**
|
||||
-- support for stored credentials.
|
||||
-- accept anything input
|
||||
>> this make you able to connect any output node to start send the notification
|
||||
>>> If you want to include image in the notification then just connect an image output line to the images input.
|
||||
|
||||
**Version 1.0.1**
|
||||
Initial release
|
||||
@@ -0,0 +1,3 @@
|
||||
# specify app key and user/group key if you don't want to set it up in the comfyUI node everytime
|
||||
apptoken=your-app-token-here
|
||||
usertoken=your-user-or-group-token-here
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 43 KiB |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 83 KiB |
+1
-1
@@ -1,7 +1,7 @@
|
||||
[project]
|
||||
name = "UploadToWebhookPushOver"
|
||||
description = "Send generated image to PushOver API webhook choose for only notification or add the image result as well."
|
||||
version = "1.0.1"
|
||||
version = "1.2.0"
|
||||
license = {file = "LICENSE"}
|
||||
dependencies = ["numpy", "requests", "Pillow"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user