Skip to content

Commit d3b9341

Browse files
committed
Add "Generate Document" action.
1 parent 8f23625 commit d3b9341

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import app from "../docugenerate.app.mjs";
2+
3+
export default {
4+
key: "docugenerate-generate-document",
5+
name: "Generate Document",
6+
description: "Generates a document from a template",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
templateId: {
12+
propDefinition: [
13+
app,
14+
"templateId",
15+
],
16+
},
17+
name: {
18+
type: "string",
19+
label: "Name",
20+
description: "Name of the generated document. Defaults to the template’s name.",
21+
},
22+
format: {
23+
type: "string",
24+
label: "Format",
25+
description: "Output format of the generated document. Defaults to .docx.",
26+
options: [
27+
{ label: 'Microsoft Word (.docx)', value: '.docx' },
28+
{ label: 'Microsoft Word 2007 (.doc)', value: '.doc' },
29+
{ label: 'OpenDocument Format (.odt)', value: '.odt' },
30+
{ label: 'PDF (.pdf)', value: '.pdf' },
31+
{ label: 'Plain Text (.txt)', value: '.txt' },
32+
{ label: 'PNG (.png)', value: '.png' },
33+
],
34+
},
35+
data: {
36+
type: "object",
37+
label: "Template Data",
38+
description: "Data that is used to generate the document.",
39+
},
40+
},
41+
async run({ $ }) {
42+
const body = {
43+
template_id: this.templateId,
44+
name: this.name,
45+
format: this.format,
46+
data: this.data,
47+
};
48+
49+
const response = await this.app.generateDocument($, body);
50+
51+
$.export("$summary", `Successfully generated document with ID: ${response.id}`);
52+
return response;
53+
},
54+
};

components/docugenerate/docugenerate.app.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,13 @@ export default {
8787
path: `/document/${documentId}`,
8888
});
8989
},
90+
async generateDocument($ = this, body) {
91+
return this.makeRequest({
92+
$,
93+
method: "POST",
94+
path: "/document",
95+
data: body,
96+
});
97+
},
9098
},
9199
};

0 commit comments

Comments
 (0)