Skip to content

Commit a63c2db

Browse files
Merging pull request #17480
* [NEW COMPONENT] Orshot for dynamic image generation * update: coderabbit review updates * updates * pnpm-lock.yaml * pnpm-lock.yaml --------- Co-authored-by: Michelle Bergeron <[email protected]>
1 parent 62ddde3 commit a63c2db

File tree

10 files changed

+691
-16
lines changed

10 files changed

+691
-16
lines changed

components/orshot/README.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Orshot
2+
3+
[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.
4+
5+
## What is Orshot?
6+
7+
Orshot enables developers and businesses to automatically generate images for:
8+
9+
- [Website Screenshots](https://orshot.com/templates/website-screenshot)
10+
- [Tweet Images](https://orshot.com/templates/tweet-image)
11+
- Social media posts
12+
- Marketing materials
13+
- Dynamic content
14+
- Personalized images
15+
16+
With Orshot, you can create templates once and generate thousands of variations programmatically.
17+
18+
## Authentication
19+
20+
To use Orshot with Pipedream, you'll need an API key:
21+
22+
1. Sign up at [Orshot](https://orshot.com)
23+
2. Navigate to your Workspace → Settings → API Key
24+
3. Copy your API key
25+
4. Add it to your Pipedream workflow when connecting the Orshot app
26+
27+
## Available Actions
28+
29+
### Generate Image from Library Template
30+
31+
Generate dynamic images using pre-designed templates from Orshot's template library.
32+
33+
**Use Cases:**
34+
35+
- Social media post generation
36+
- Marketing material automation
37+
- Dynamic content creation
38+
39+
### Generate Image from Studio Template
40+
41+
Generate images using custom templates created in Orshot Studio.
42+
43+
**Use Cases:**
44+
45+
- Brand-specific image generation
46+
- Custom design automation
47+
- Personalized content creation
48+
49+
### List Templates
50+
51+
Retrieve all available templates from your Orshot account.
52+
53+
**Use Cases:**
54+
55+
- Template discovery
56+
- Dynamic template selection
57+
- Workflow automation
58+
59+
### Get Template Modifications
60+
61+
Get available modification keys for a specific library template.
62+
63+
**Use Cases:**
64+
65+
- Dynamic form generation
66+
- Template customization options
67+
- Workflow configuration
68+
69+
### Get Studio Template Modifications
70+
71+
Get available modification keys for a specific studio template.
72+
73+
**Use Cases:**
74+
75+
- Custom template configuration
76+
- Dynamic parameter discovery
77+
- Advanced workflow setup
78+
79+
## Response Formats
80+
81+
Orshot supports multiple response formats:
82+
83+
- **Base64**: Encoded image data for direct embedding
84+
- **Binary**: Raw image data for file operations
85+
- **URL**: Hosted image URL for immediate use
86+
87+
## Supported Image Formats
88+
89+
- PNG (default)
90+
- JPG/JPEG
91+
- WebP
92+
- PDF
93+
94+
## Example Use Cases
95+
96+
1. **Social Media Automation**: Generate personalized social media posts based on user data
97+
2. **E-commerce**: Create product images with dynamic pricing and offers
98+
3. **Marketing Campaigns**: Generate campaign materials with personalized content
99+
4. **Report Generation**: Create visual reports with dynamic charts and data
100+
5. **Content Personalization**: Generate user-specific images for emails and websites
101+
102+
## Links
103+
104+
- [Orshot Website](https://orshot.com)
105+
- [API Documentation](https://orshot.com/docs)
106+
- [Template Library](https://orshot.com/templates)
107+
- [Get API Key](https://orshot.com/workspace)
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import orshot from "../../orshot.app.mjs";
2+
import {
3+
getMimeType, parseObject,
4+
} from "../../common/utils.mjs";
5+
6+
export default {
7+
key: "orshot-generate-image-library-template",
8+
name: "Generate Image from Library Template",
9+
description: "Generate an image from a pre-designed library template using the Orshot API. [See the documentation](https://orshot.com/docs/api-reference/render-from-template)",
10+
version: "0.0.1",
11+
type: "action",
12+
props: {
13+
orshot,
14+
templateId: {
15+
propDefinition: [
16+
orshot,
17+
"templateId",
18+
],
19+
},
20+
responseType: {
21+
propDefinition: [
22+
orshot,
23+
"responseType",
24+
],
25+
},
26+
responseFormat: {
27+
propDefinition: [
28+
orshot,
29+
"responseFormat",
30+
],
31+
},
32+
modifications: {
33+
propDefinition: [
34+
orshot,
35+
"modifications",
36+
],
37+
optional: true,
38+
},
39+
},
40+
async run({ $ }) {
41+
const {
42+
templateId,
43+
responseType,
44+
responseFormat,
45+
modifications = {},
46+
} = this;
47+
48+
// Input validation
49+
if (!templateId) {
50+
throw new Error("Template ID is required");
51+
}
52+
53+
if (!responseType) {
54+
throw new Error("Response type is required");
55+
}
56+
57+
if (!responseFormat) {
58+
throw new Error("Response format is required");
59+
}
60+
61+
// Validate responseType
62+
const validResponseTypes = [
63+
"base64",
64+
"binary",
65+
"url",
66+
];
67+
if (!validResponseTypes.includes(responseType)) {
68+
throw new Error(
69+
`Invalid response type. Must be one of: ${validResponseTypes.join(
70+
", ",
71+
)}`,
72+
);
73+
}
74+
75+
// Validate responseFormat
76+
const validFormats = [
77+
"png",
78+
"jpg",
79+
"jpeg",
80+
"webp",
81+
];
82+
if (!validFormats.includes(responseFormat.toLowerCase())) {
83+
throw new Error(
84+
`Invalid response format. Must be one of: ${validFormats.join(", ")}`,
85+
);
86+
}
87+
88+
const validModifications = parseObject(modifications);
89+
90+
try {
91+
const response = await this.orshot.generateImageFromLibraryTemplate({
92+
$,
93+
data: {
94+
templateId,
95+
modifications: validModifications,
96+
response: {
97+
type: responseType,
98+
format: responseFormat,
99+
},
100+
},
101+
});
102+
103+
const result = {
104+
templateId,
105+
responseType,
106+
responseFormat,
107+
modifications: validModifications,
108+
timestamp: new Date().toISOString(),
109+
source: "orshot-pipedream",
110+
};
111+
112+
// Handle different response types
113+
switch (responseType) {
114+
case "base64":
115+
result.data = response.data;
116+
result.mimeType = getMimeType(responseFormat);
117+
break;
118+
case "binary":
119+
result.data = response;
120+
result.mimeType = getMimeType(responseFormat);
121+
break;
122+
case "url":
123+
result.data = response.data;
124+
break;
125+
default:
126+
result.data = response.data;
127+
}
128+
129+
$.export(
130+
"$summary",
131+
`Successfully generated image from template ${templateId}`,
132+
);
133+
return result;
134+
} catch (error) {
135+
const errorMessage = error.message || "Unknown error occurred";
136+
throw new Error(`Failed to generate image: ${errorMessage}`);
137+
}
138+
},
139+
};
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import orshot from "../../orshot.app.mjs";
2+
import {
3+
getMimeType, parseObject,
4+
} from "../../common/utils.mjs";
5+
6+
export default {
7+
key: "orshot-generate-image-studio-template",
8+
name: "Generate Image from Studio Template",
9+
description: "Generate an image from an Orshot Studio template using the Orshot API. [See the documentation](https://orshot.com/docs/api-reference/render-from-studio-template)",
10+
version: "0.0.1",
11+
type: "action",
12+
props: {
13+
orshot,
14+
templateId: {
15+
propDefinition: [
16+
orshot,
17+
"studioTemplateId",
18+
],
19+
},
20+
responseType: {
21+
propDefinition: [
22+
orshot,
23+
"responseType",
24+
],
25+
},
26+
responseFormat: {
27+
propDefinition: [
28+
orshot,
29+
"responseFormat",
30+
],
31+
},
32+
modifications: {
33+
propDefinition: [
34+
orshot,
35+
"modifications",
36+
],
37+
optional: true,
38+
},
39+
},
40+
async run({ $ }) {
41+
const {
42+
templateId,
43+
responseType,
44+
responseFormat,
45+
modifications = {},
46+
} = this;
47+
48+
// Input validation
49+
if (!templateId) {
50+
throw new Error("Template ID is required");
51+
}
52+
53+
if (!responseType) {
54+
throw new Error("Response type is required");
55+
}
56+
57+
if (!responseFormat) {
58+
throw new Error("Response format is required");
59+
}
60+
61+
// Validate responseType
62+
const validResponseTypes = [
63+
"base64",
64+
"binary",
65+
"url",
66+
];
67+
if (!validResponseTypes.includes(responseType)) {
68+
throw new Error(
69+
`Invalid response type. Must be one of: ${validResponseTypes.join(
70+
", ",
71+
)}`,
72+
);
73+
}
74+
75+
// Validate responseFormat
76+
const validFormats = [
77+
"png",
78+
"jpg",
79+
"jpeg",
80+
"webp",
81+
];
82+
if (!validFormats.includes(responseFormat.toLowerCase())) {
83+
throw new Error(
84+
`Invalid response format. Must be one of: ${validFormats.join(", ")}`,
85+
);
86+
}
87+
88+
const validModifications = parseObject(modifications);
89+
90+
try {
91+
const response = await this.orshot.generateImageFromStudioTemplate({
92+
$,
93+
data: {
94+
templateId,
95+
modifications: validModifications,
96+
response: {
97+
type: responseType,
98+
format: responseFormat,
99+
},
100+
},
101+
});
102+
103+
const result = {
104+
templateId,
105+
responseType,
106+
responseFormat,
107+
modifications: validModifications,
108+
timestamp: new Date().toISOString(),
109+
source: "orshot-pipedream",
110+
};
111+
112+
// Handle different response types
113+
switch (responseType) {
114+
case "base64":
115+
result.data = response.data;
116+
result.mimeType = getMimeType(responseFormat);
117+
break;
118+
case "binary":
119+
result.data = response;
120+
result.mimeType = getMimeType(responseFormat);
121+
break;
122+
case "url":
123+
result.data = response.data;
124+
break;
125+
default:
126+
result.data = response.data;
127+
}
128+
129+
$.export(
130+
"$summary",
131+
`Successfully generated image from studio template ${templateId}`,
132+
);
133+
return result;
134+
} catch (error) {
135+
const errorMessage = error.message || "Unknown error occurred";
136+
throw new Error(`Failed to generate image: ${errorMessage}`);
137+
}
138+
},
139+
};

0 commit comments

Comments
 (0)