Skip to content
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

feat(robolly): generate image action #3589

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions packages/pieces/robolly/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"extends": [
"../../../.eslintrc.json"
],
"ignorePatterns": [
"!**/*"
],
"overrides": [
{
"files": [
"*.ts",
"*.tsx",
"*.js",
"*.jsx"
],
"rules": {}
},
{
"files": [
"*.ts",
"*.tsx"
],
"rules": {}
},
{
"files": [
"*.js",
"*.jsx"
],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions packages/pieces/robolly/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# pieces-robolly

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build pieces-robolly` to build the library.
4 changes: 4 additions & 0 deletions packages/pieces/robolly/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@activepieces/piece-robolly",
"version": "0.0.1"
}
43 changes: 43 additions & 0 deletions packages/pieces/robolly/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "pieces-robolly",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/pieces/robolly/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": [
"{options.outputPath}"
],
"options": {
"outputPath": "dist/packages/pieces/robolly",
"tsConfig": "packages/pieces/robolly/tsconfig.lib.json",
"packageJson": "packages/pieces/robolly/package.json",
"main": "packages/pieces/robolly/src/index.ts",
"assets": [
"packages/pieces/robolly/*.md"
],
"buildableProjectDepsInPackageJsonType": "dependencies",
"updateBuildableProjectDepsInPackageJson": true
}
},
"publish": {
"command": "node tools/scripts/publish.mjs pieces-robolly {args.ver} {args.tag}",
"dependsOn": [
"build"
]
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": [
"{options.outputFile}"
],
"options": {
"lintFilePatterns": [
"packages/pieces/robolly/**/*.ts"
]
}
}
},
"tags": []
}
31 changes: 31 additions & 0 deletions packages/pieces/robolly/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

import { createPiece, PieceAuth } from "@activepieces/pieces-framework";
import { generateImage } from "./lib/actions/generate-image.action";

const markdownDescription = `
Follow these instructions to get your API Key:
1. Visit the following website: https://robolly.com/dashboard/account/
2. Once on the website, locate and copy your API Key.
Please, take into consideration: We don't test your API Key validity in order to save you some generations, so make sure this is the correct one.
`;

export const robollyAuth = PieceAuth.SecretText({
description: markdownDescription,
displayName: 'API Key',
required: true,
validate: async () => {
return {
valid: true,
}
}
});

export const robolly = createPiece({
displayName: "Robolly",
auth: robollyAuth,
minimumSupportedRelease: '0.9.0',
logoUrl: "https://cdn.activepieces.com/pieces/robolly.png",
authors: ["PFernandez98"],
actions: [generateImage],
triggers: [],
});
68 changes: 68 additions & 0 deletions packages/pieces/robolly/src/lib/actions/generate-image.action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { HttpMethod, httpClient } from "@activepieces/pieces-common";
import { Property, createAction } from "@activepieces/pieces-framework";

export const generateImage = createAction({
description: 'Generate an image using Robolly',
displayName: 'Generate Image',
name: 'generate_image',
props: {
template_id: Property.ShortText({
displayName: 'Template ID',
required: true,
description: 'The ID of the template to use.'
}),
format: Property.StaticDropdown({
displayName: 'Format',
required: true,
description: 'The format of the image to generate.',
defaultValue: 'jpg',
options: {
"options" : [
{
"label": "JPG",
"value": 'jpg',
},
{
"label": "PNG",
"value": 'png',
},
{
"label": "PDF",
"value": 'pdf',
}
]
}
}),
modifications: Property.Object({
displayName: 'Modifications',
description: 'The modifications (fields) to apply to the image.',
required: true,

})
},
async run({ auth, propsValue }){

const queryParams: Record<string, string> = {
};

queryParams['json'] = ""

for (const key in propsValue.modifications) {
const value = propsValue.modifications[key];
queryParams[key as string] = value as string;
}

const request = await httpClient.sendRequest({
method: HttpMethod.GET,
queryParams: queryParams,
url: `https://api.robolly.com/templates/${propsValue.template_id}/render/${propsValue.format}`,
headers: {
'Authorization': `Bearer ${auth}`
},
body: propsValue.modifications
});


return request.body;
}
});
19 changes: 19 additions & 0 deletions packages/pieces/robolly/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
}
]
}
11 changes: 11 additions & 0 deletions packages/pieces/robolly/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
"include": ["src/**/*.ts"]
}
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
],
"@activepieces/piece-retable": ["packages/pieces/retable/src/index.ts"],
"@activepieces/piece-retune": ["packages/pieces/retune/src/index.ts"],
"@activepieces/piece-robolly": ["packages/pieces/robolly/src/index.ts"],
"@activepieces/piece-rss": ["packages/pieces/rss/src/index.ts"],
"@activepieces/piece-salesforce": [
"packages/pieces/salesforce/src/index.ts"
Expand Down