@pipedream/google_slides 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import app from "../../google_slides.app.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
key: "google_slides-merge-data",
|
|
5
|
+
name: "Merge Data",
|
|
6
|
+
description: "Merge data into a presentation. [See the docs here](https://developers.google.com/slides/api/guides/merge)",
|
|
7
|
+
version: "0.0.1",
|
|
8
|
+
type: "action",
|
|
9
|
+
props: {
|
|
10
|
+
app,
|
|
11
|
+
drive: {
|
|
12
|
+
propDefinition: [
|
|
13
|
+
app,
|
|
14
|
+
"watchedDrive",
|
|
15
|
+
],
|
|
16
|
+
description: "The drive to select a presentation from. If you are connected with any [Google Shared Drives](https://support.google.com/a/users/answer/9310351), you can select it here.",
|
|
17
|
+
},
|
|
18
|
+
presentationId: {
|
|
19
|
+
propDefinition: [
|
|
20
|
+
app,
|
|
21
|
+
"presentationId",
|
|
22
|
+
(c) => ({
|
|
23
|
+
driveId: app.methods.getDriveId(c.drive),
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
26
|
+
description: "Select the presentation to make a copy of.",
|
|
27
|
+
},
|
|
28
|
+
title: {
|
|
29
|
+
type: "string",
|
|
30
|
+
label: "Title",
|
|
31
|
+
description: "The title of the new presentation.",
|
|
32
|
+
},
|
|
33
|
+
placeholdersAndTexts: {
|
|
34
|
+
type: "object",
|
|
35
|
+
label: "Placeholders And Texts",
|
|
36
|
+
description: "The placeholders and texts to be merged into the presentation. So the key should be the placeholder ID and the value should be the text to be merged. As a placeholder example you can use `{{name}}` and the value can be `John Doe`.",
|
|
37
|
+
},
|
|
38
|
+
placeholdersAndImageUrls: {
|
|
39
|
+
type: "object",
|
|
40
|
+
label: "Placeholders And Image URLs",
|
|
41
|
+
description: "The placeholders and image URLs to be merged into the presentation. So the key should be the placeholder ID and the value should be the image URL to be merged. As a placeholder example you can use `{{image}}` and the value can be `https://example.com/image.jpg`.",
|
|
42
|
+
optional: true,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
methods: {
|
|
46
|
+
getTextRequests(placeholdersAndTexts = {}) {
|
|
47
|
+
return Object.entries(placeholdersAndTexts)
|
|
48
|
+
.map(([
|
|
49
|
+
key,
|
|
50
|
+
value,
|
|
51
|
+
]) => ({
|
|
52
|
+
replaceAllText: {
|
|
53
|
+
containsText: {
|
|
54
|
+
text: key,
|
|
55
|
+
matchCase: true,
|
|
56
|
+
},
|
|
57
|
+
replaceText: value,
|
|
58
|
+
},
|
|
59
|
+
}));
|
|
60
|
+
},
|
|
61
|
+
getImageRequests(placeholdersAndImageUrls = {}) {
|
|
62
|
+
return Object.entries(placeholdersAndImageUrls)
|
|
63
|
+
.map(([
|
|
64
|
+
key,
|
|
65
|
+
value,
|
|
66
|
+
]) => ({
|
|
67
|
+
replaceAllShapesWithImage: {
|
|
68
|
+
imageUrl: value,
|
|
69
|
+
replaceMethod: "CENTER_INSIDE",
|
|
70
|
+
containsText: {
|
|
71
|
+
text: key,
|
|
72
|
+
matchCase: true,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
}));
|
|
76
|
+
},
|
|
77
|
+
batchUpdate(args = {}) {
|
|
78
|
+
const slides = this.app.slides();
|
|
79
|
+
return slides.presentations.batchUpdate(args);
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
async run({ $ }) {
|
|
83
|
+
const {
|
|
84
|
+
app,
|
|
85
|
+
batchUpdate,
|
|
86
|
+
presentationId,
|
|
87
|
+
title,
|
|
88
|
+
placeholdersAndTexts,
|
|
89
|
+
placeholdersAndImageUrls,
|
|
90
|
+
getTextRequests,
|
|
91
|
+
getImageRequests,
|
|
92
|
+
} = this;
|
|
93
|
+
|
|
94
|
+
const presentation = await app.copyPresentation(presentationId, title);
|
|
95
|
+
|
|
96
|
+
const { data: response } = await batchUpdate({
|
|
97
|
+
presentationId: presentation.id,
|
|
98
|
+
resource: {
|
|
99
|
+
requests: [
|
|
100
|
+
...getTextRequests(placeholdersAndTexts),
|
|
101
|
+
...getImageRequests(placeholdersAndImageUrls),
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
$.export("$summary", `Successfully merged data into presentation with ID: ${response.presentationId}`);
|
|
107
|
+
|
|
108
|
+
return response;
|
|
109
|
+
},
|
|
110
|
+
};
|