Skip to content

[NEW COMPONENT] Orshot #17480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 9, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions components/orshot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Orshot

[Orshot](https://orshot.com) is an automated image generation API that allows you to generate dynamic images from pre-designed templates and AI-generated templates.

## What is Orshot?

Orshot enables developers and businesses to automatically generate images for:

- [Website Screenshots](https://orshot.com/templates/website-screenshot)
- [Tweet Images](https://orshot.com/templates/tweet-image)
- Social media posts
- Marketing materials
- Dynamic content
- Personalized images

With Orshot, you can create templates once and generate thousands of variations programmatically.

## Authentication

To use Orshot with Pipedream, you'll need an API key:

1. Sign up at [Orshot](https://orshot.com)
2. Navigate to your Workspace → Settings → API Key
3. Copy your API key
4. Add it to your Pipedream workflow when connecting the Orshot app

## Available Actions

### Generate Image from Library Template

Generate dynamic images using pre-designed templates from Orshot's template library.

**Use Cases:**

- Social media post generation
- Marketing material automation
- Dynamic content creation

### Generate Image from Studio Template

Generate images using custom templates created in Orshot Studio.

**Use Cases:**

- Brand-specific image generation
- Custom design automation
- Personalized content creation

### List Templates

Retrieve all available templates from your Orshot account.

**Use Cases:**

- Template discovery
- Dynamic template selection
- Workflow automation

### Get Template Modifications

Get available modification keys for a specific library template.

**Use Cases:**

- Dynamic form generation
- Template customization options
- Workflow configuration

### Get Studio Template Modifications

Get available modification keys for a specific studio template.

**Use Cases:**

- Custom template configuration
- Dynamic parameter discovery
- Advanced workflow setup

## Response Formats

Orshot supports multiple response formats:

- **Base64**: Encoded image data for direct embedding
- **Binary**: Raw image data for file operations
- **URL**: Hosted image URL for immediate use

## Supported Image Formats

- PNG (default)
- JPG/JPEG
- WebP
- PDF

## Example Use Cases

1. **Social Media Automation**: Generate personalized social media posts based on user data
2. **E-commerce**: Create product images with dynamic pricing and offers
3. **Marketing Campaigns**: Generate campaign materials with personalized content
4. **Report Generation**: Create visual reports with dynamic charts and data
5. **Content Personalization**: Generate user-specific images for emails and websites

## Links

- [Orshot Website](https://orshot.com)
- [API Documentation](https://orshot.com/docs)
- [Template Library](https://orshot.com/templates)
- [Get API Key](https://orshot.com/workspace)
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
import orshot from "../app/orshot.app.mjs";

export default {
key: "orshot-generate-image-library-template",
name: "Generate Image from Library Template",
description:
"Generate an image from a pre-designed library template using the Orshot API",
version: "0.1.1",
type: "action",
props: {
orshot,
templateId: {
propDefinition: [
orshot,
"templateId",
],
},
responseType: {
propDefinition: [
orshot,
"responseType",
],
},
responseFormat: {
propDefinition: [
orshot,
"responseFormat",
],
},
modifications: {
propDefinition: [
orshot,
"modifications",
],
optional: true,
},
},
async run({ $ }) {
const {
templateId,
responseType,
responseFormat,
modifications = {},
} = this;

// Input validation
if (!templateId) {
throw new Error("Template ID is required");
}

if (!responseType) {
throw new Error("Response type is required");
}

if (!responseFormat) {
throw new Error("Response format is required");
}

// Validate responseType
const validResponseTypes = [
"base64",
"binary",
"url",
];
if (!validResponseTypes.includes(responseType)) {
throw new Error(
`Invalid response type. Must be one of: ${validResponseTypes.join(
", ",
)}`,
);
}

// Validate responseFormat
const validFormats = [
"png",
"jpg",
"jpeg",
"webp",
];
if (!validFormats.includes(responseFormat.toLowerCase())) {
throw new Error(
`Invalid response format. Must be one of: ${validFormats.join(", ")}`,
);
}

// Validate modifications if provided
if (modifications && typeof modifications !== "object") {
throw new Error("Modifications must be an object");
}

// Ensure modifications is not null
const validModifications = modifications || {};

try {
const response = await this.orshot.generateImageFromLibraryTemplate({
$,
templateId,
modifications: validModifications,
responseType,
responseFormat,
});

const result = {
templateId,
responseType,
responseFormat,
modifications: validModifications,
timestamp: new Date().toISOString(),
source: "orshot-pipedream",
};

// Handle different response types
switch (responseType) {
case "base64":
result.data = response;
result.mimeType = this._getMimeType(responseFormat);
break;
case "binary":
result.data = response;
result.mimeType = this._getMimeType(responseFormat);
break;
case "url":
result.data = response;
break;
default:
result.data = response;
}

$.export(
"$summary",
`Successfully generated image from template ${templateId}`,
);
return result;
} catch (error) {
const errorMessage = error.message || "Unknown error occurred";
const errorResult = {
error: errorMessage,
templateId,
responseType,
responseFormat,
modifications: validModifications,
timestamp: new Date().toISOString(),
source: "orshot-pipedream",
};

// Enhanced error handling for different error types
if (error.response) {
errorResult.httpStatus = error.response.status;
errorResult.httpStatusText = error.response.statusText;

try {
errorResult.apiError =
typeof error.response.data === "string"
? JSON.parse(error.response.data)
: error.response.data;
} catch (parseError) {
errorResult.rawResponse = error.response.data;
errorResult.parseError = parseError.message;
}
} else if (error.code) {
// Handle network/connection errors
errorResult.errorCode = error.code;
errorResult.errorType = "network";
} else if (error.name) {
// Handle other types of errors
errorResult.errorName = error.name;
errorResult.errorType = "application";
}

throw new Error(`Failed to generate image: ${errorMessage}`);
}
},
methods: {
/**
* Get the MIME type for a given file format
* @param {string} format - The file format (e.g., 'png', 'jpg')
* @returns {string} The corresponding MIME type
*/
_getMimeType(format) {
if (!format || typeof format !== "string") {
return "application/octet-stream";
}

const mimeTypes = {
png: "image/png",
jpg: "image/jpeg",
jpeg: "image/jpeg",
webp: "image/webp",
};

const normalizedFormat = format.toLowerCase().trim();
return mimeTypes[normalizedFormat] || "application/octet-stream";
},
},
};
Loading