Hi, I’m trying to send an image generated from a pickaxe chat and send it in binary format to a make webhook. Does anyone know if this is possible? I’ve tried using code but it seems that the chat doesn’t save the images it generates? Or am I writing the code wrong? Has anyone been able to do this integration?
Hi @bruno12345,
Everything is possible with Pickaxe (you’re welcome @admin_mike)
What you could do is using Dalle so you get the image as a response to the API and you can send the response to the Make.com webhook.
Here is how:
- Clone the Dalle action
- Use the code below
- You can either hard code the webhook or add an environment variable
- Build the scenario in Make with the webhook and the HTTP Get a file module
- Have fun
import os
import requests
import shutil
import json
def generate_dalle_3_image_own_key_copy(image_prompt: str):
“”"
Allows your Pickaxe to generate DALL·E 3 images.
Args:
image_prompt (string): Prompt for the image to be generated
WEBHOOK_URL (string): make webhook
"""
webhook_url = "https://hook.eu2.make.com/xxxxxxxxxxxxxxxxxxxx" # Replace with your actual Make.com webhook URL
api_key = os.environ["OPENAI_API_KEY"]
api_url = "https://api.openai.com/v1/images/generations"
headers = {
"Content-Type": "application/json",
}
headers["Authorization"] = f"Bearer {api_key}"
data = {
"prompt": image_prompt,
"model": "dall-e-3",
"n": 1,
"size": "1024x1024"
}
response = requests.post(api_url, headers=headers, json=data)
if response.status_code == 200:
image_url = response.json()["data"][0]["url"]
# Download the image
image_response = requests.get(image_url, stream=True)
if image_response.status_code == 200:
with open("generated_image.png", "wb") as f:
image_response.raw.decode_content = True
shutil.copyfileobj(image_response.raw, f)
# Send the JSON response to the Make.com webhook
payload = response.json() # The JSON payload that contains the image URL
webhook_response = requests.post(webhook_url, headers={"Content-Type": "application/json"}, data=json.dumps(payload))
if webhook_response.status_code == 200:
print("JSON response sent to Make.com webhook successfully")
else:
print(f"Failed to send JSON response to Make.com webhook. Status code: {webhook_response.status_code}")
print(f"Webhook response: {webhook_response.text}")
else:
print("Failed to download the image")
else:
print("Failed to generate image")
1 Like
Hey, thank you very much, ab2308, you got me out of a bind.
1 Like