import requests from PIL import Image import numpy as np import io def send_msg(token, chat_id, text): url_req = "https://api.telegram.org/bot" + token + "/sendMessage" + "?chat_id=" + chat_id + "&text=" + text results = requests.get(url_req) print(results.json()) def send_photo(token, chat_id, image, text): data = {"chat_id": chat_id, "caption": text} url = "https://api.telegram.org/bot%s/sendPhoto" % token ret = requests.post(url, data=data, files={"photo": image}) print(ret.json()) class TelegramNotification: def __init__(self): pass @classmethod def INPUT_TYPES(s): return { "required": { "images": ("IMAGE",), "telegram_bot_token": ("STRING", { "multiline": False, "default": "" }), "group_id": ("STRING", { "multiline": False, "default": "" }) }, } RETURN_TYPES = () FUNCTION = "notify" OUTPUT_NODE = True CATEGORY = "Example" def notify(self, images, telegram_bot_token, group_id): for image in images: i = 255. * image.cpu().numpy() img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8)) with io.BytesIO() as output: img.save(output, format="PNG") contents = output.getvalue() send_photo(telegram_bot_token, group_id, contents, "Generation finished") return (images, ) NODE_CLASS_MAPPINGS = { "TelegramNotify": TelegramNotification } NODE_DISPLAY_NAME_MAPPINGS = { "TelegramNotify": "Example Node" }