@guayaba/workflow-piece-google-docs 0.4.1

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,52 @@
1
+ {
2
+ "Google Docs": "Google Docs",
3
+ "Create and edit documents online": "Создание и редактирование документов онлайн",
4
+ "Create Document": "Создать документ",
5
+ "Edit template file": "Редактировать файл шаблона",
6
+ "Read Document": "Читать документ",
7
+ "Find Document": "Найти документ",
8
+ "Custom API Call": "Пользовательский вызов API",
9
+ "Append text to google docs": "Добавить текст в Google docs",
10
+ "Create a document on Google Docs": "Создать документ на Google Docs",
11
+ "Edit a template file and replace the values with the ones provided": "Отредактируйте файл шаблона и замените введенные значения",
12
+ "Read a document from Google Docs": "Читать документ от Google Docs",
13
+ "Search for document by name.": "Поиск документа по имени.",
14
+ "Make a custom API call to a specific endpoint": "Сделать пользовательский API вызов к определенной конечной точке",
15
+ "Appends text to google docs": "Добавляет текст в Google docs",
16
+ "Document Title": "Заголовок документа",
17
+ "Document Content": "Содержимое документа",
18
+ "Destination File": "Файл назначения",
19
+ "Variables": "Переменные",
20
+ "Images": "Изображения",
21
+ "Placeholder Format": "Формат заполнителя",
22
+ "Document ID": "ID документа",
23
+ "Document Name": "Название документа",
24
+ "Folder": "Папка",
25
+ "Create a new document if not found?": "Создать новый документ, если не найден?",
26
+ "New Document Properties": "Новые свойства документа",
27
+ "Method": "Метод",
28
+ "Headers": "Заголовки",
29
+ "Query Parameters": "Параметры запроса",
30
+ "Body": "Тело",
31
+ "No Error on Failure": "Нет ошибок при ошибке",
32
+ "Timeout (in seconds)": "Таймаут (в секундах)",
33
+ "Text to append": "Текст в добавление",
34
+ "The ID of the file to replace the values": "ID файла для замены значений",
35
+ "Dont include the placeholder format \"[[]]\" or \"{{}}\", only the key name and its value": "Не используйте формат плейсхолдера \"[[]]\" или \"{{}}\", только имя ключа и его значение",
36
+ "Key: Image ID (get it manually from the Read File Action), Value: Image URL": "Ключ: ID изображения (получить вручную из действия чтения файла), значение: URL изображения",
37
+ "Choose the format of placeholders in your template": "Выберите формат заполнителей в вашем шаблоне",
38
+ "The ID of the document to read": "ID документа для чтения",
39
+ "Authorization headers are injected automatically from your connection.": "Заголовки авторизации включаются автоматически из вашего соединения.",
40
+ "The text to append to the document": "Текст для добавления в документ",
41
+ "The ID of the document to append text to": "ID документа для добавления текста в",
42
+ "Curly Braces {{}}": "Изогнутые Наручи {{}}",
43
+ "Square Brackets [[]]": "Квадратные скобки [[]]",
44
+ "GET": "ПОЛУЧИТЬ",
45
+ "POST": "ПОСТ",
46
+ "PATCH": "ПАТЧ",
47
+ "PUT": "ПОКУПИТЬ",
48
+ "DELETE": "УДАЛИТЬ",
49
+ "HEAD": "HEAD",
50
+ "New Document": "Новый документ",
51
+ "Triggers when a new document is added to a specific folder(optional).": "Включает при добавлении нового документа в определенную папку(необязательно)."
52
+ }
@@ -0,0 +1,61 @@
1
+ {
2
+ "Create and edit documents online": "Create and edit documents online",
3
+ "Create Document": "Create Document",
4
+ "Edit template file": "Edit template file",
5
+ "Read Document": "Read Document",
6
+ "Find Document": "Find Document",
7
+ "Custom API Call": "Custom API Call",
8
+ "Append text to google docs": "Append text to google docs",
9
+ "Create a document on Google Docs": "Create a document on Google Docs",
10
+ "Edit a template file and replace the values with the ones provided": "Edit a template file and replace the values with the ones provided",
11
+ "Read a document from Google Docs": "Read a document from Google Docs",
12
+ "Search for document by name.": "Search for document by name.",
13
+ "Make a custom API call to a specific endpoint": "Make a custom API call to a specific endpoint",
14
+ "Appends text to google docs": "Appends text to google docs",
15
+ "Document Title": "Document Title",
16
+ "Document Content": "Document Content",
17
+ "Destination File": "Destination File",
18
+ "Variables": "Variables",
19
+ "Images": "Images",
20
+ "Placeholder Format": "Placeholder Format",
21
+ "Document ID": "Document ID",
22
+ "Document Name": "Document Name",
23
+ "Folder": "Folder",
24
+ "Create a new document if not found?": "Create a new document if not found?",
25
+ "New Document Properties": "New Document Properties",
26
+ "Method": "Method",
27
+ "Headers": "Headers",
28
+ "Query Parameters": "Query Parameters",
29
+ "Body Type": "Body Type",
30
+ "Body": "Body",
31
+ "Response is Binary ?": "Response is Binary ?",
32
+ "No Error on Failure": "No Error on Failure",
33
+ "Timeout (in seconds)": "Timeout (in seconds)",
34
+ "Follow redirects": "Follow redirects",
35
+ "Text to append": "Text to append",
36
+ "The ID of the file to replace the values": "The ID of the file to replace the values",
37
+ "Dont include the placeholder format \"[[]]\" or \"{{}}\", only the key name and its value": "Dont include the placeholder format \"[[]]\" or \"{{}}\", only the key name and its value",
38
+ "Key: Image ID (get it manually from the Read File Action), Value: Image URL": "Key: Image ID (get it manually from the Read File Action), Value: Image URL",
39
+ "Choose the format of placeholders in your template": "Choose the format of placeholders in your template",
40
+ "The ID of the document to read": "The ID of the document to read",
41
+ "Authorization headers are injected automatically from your connection.": "Authorization headers are injected automatically from your connection.",
42
+ "Enable for files like PDFs, images, etc.": "Enable for files like PDFs, images, etc.",
43
+ "The text to append to the document": "The text to append to the document",
44
+ "The ID of the document to append text to": "The ID of the document to append text to",
45
+ "Curly Braces {{}}": "Curly Braces {{}}",
46
+ "Square Brackets [[]]": "Square Brackets [[]]",
47
+ "Single Curly Braces {}": "Single Curly Braces {}",
48
+ "Single Square Brackets []": "Single Square Brackets []",
49
+ "GET": "GET",
50
+ "POST": "POST",
51
+ "PATCH": "PATCH",
52
+ "PUT": "PUT",
53
+ "DELETE": "DELETE",
54
+ "HEAD": "HEAD",
55
+ "None": "None",
56
+ "JSON": "JSON",
57
+ "Form Data": "Form Data",
58
+ "Raw": "Raw",
59
+ "New Document": "New Document",
60
+ "Triggers when a new document is added to a specific folder(optional).": "Triggers when a new document is added to a specific folder(optional)."
61
+ }
@@ -0,0 +1,52 @@
1
+ {
2
+ "Google Docs": "Google Docs",
3
+ "Create and edit documents online": "Create and edit documents online",
4
+ "Create Document": "Create Document",
5
+ "Edit template file": "Edit template file",
6
+ "Read Document": "Read Document",
7
+ "Find Document": "Find Document",
8
+ "Custom API Call": "Custom API Call",
9
+ "Append text to google docs": "Append text to google docs",
10
+ "Create a document on Google Docs": "Create a document on Google Docs",
11
+ "Edit a template file and replace the values with the ones provided": "Edit a template file and replace the values with the ones provided",
12
+ "Read a document from Google Docs": "Read a document from Google Docs",
13
+ "Search for document by name.": "Search for document by name.",
14
+ "Make a custom API call to a specific endpoint": "Make a custom API call to a specific endpoint",
15
+ "Appends text to google docs": "Appends text to google docs",
16
+ "Document Title": "Document Title",
17
+ "Document Content": "Document Content",
18
+ "Destination File": "Destination File",
19
+ "Variables": "Variables",
20
+ "Images": "Images",
21
+ "Placeholder Format": "Placeholder Format",
22
+ "Document ID": "Document ID",
23
+ "Document Name": "Document Name",
24
+ "Folder": "Folder",
25
+ "Create a new document if not found?": "Create a new document if not found?",
26
+ "New Document Properties": "New Document Properties",
27
+ "Method": "Method",
28
+ "Headers": "Headers",
29
+ "Query Parameters": "Query Parameters",
30
+ "Body": "Body",
31
+ "No Error on Failure": "No Error on Failure",
32
+ "Timeout (in seconds)": "Timeout (in seconds)",
33
+ "Text to append": "Text to append",
34
+ "The ID of the file to replace the values": "The ID of the file to replace the values",
35
+ "Dont include the placeholder format \"[[]]\" or \"{{}}\", only the key name and its value": "Dont include the placeholder format \"[[]]\" or \"{{}}\", only the key name and its value",
36
+ "Key: Image ID (get it manually from the Read File Action), Value: Image URL": "Key: Image ID (get it manually from the Read File Action), Value: Image URL",
37
+ "Choose the format of placeholders in your template": "Choose the format of placeholders in your template",
38
+ "The ID of the document to read": "The ID of the document to read",
39
+ "Authorization headers are injected automatically from your connection.": "Authorization headers are injected automatically from your connection.",
40
+ "The text to append to the document": "The text to append to the document",
41
+ "The ID of the document to append text to": "The ID of the document to append text to",
42
+ "Curly Braces {{}}": "Curly Braces {{}}",
43
+ "Square Brackets [[]]": "Square Brackets [[]]",
44
+ "GET": "GET",
45
+ "POST": "POST",
46
+ "PATCH": "PATCH",
47
+ "PUT": "PUT",
48
+ "DELETE": "DELETE",
49
+ "HEAD": "HEAD",
50
+ "New Document": "New Document",
51
+ "Triggers when a new document is added to a specific folder(optional).": "Triggers when a new document is added to a specific folder(optional)."
52
+ }
@@ -0,0 +1,61 @@
1
+ {
2
+ "Create and edit documents online": "Create and edit documents online",
3
+ "Create Document": "Create Document",
4
+ "Edit template file": "Edit template file",
5
+ "Read Document": "Read Document",
6
+ "Find Document": "Find Document",
7
+ "Custom API Call": "自定义 API 呼叫",
8
+ "Append text to google docs": "Append text to google docs",
9
+ "Create a document on Google Docs": "Create a document on Google Docs",
10
+ "Edit a template file and replace the values with the ones provided": "Edit a template file and replace the values with the ones provided",
11
+ "Read a document from Google Docs": "Read a document from Google Docs",
12
+ "Search for document by name.": "Search for document by name.",
13
+ "Make a custom API call to a specific endpoint": "将一个自定义 API 调用到一个特定的终点",
14
+ "Appends text to google docs": "Appends text to google docs",
15
+ "Document Title": "Document Title",
16
+ "Document Content": "Document Content",
17
+ "Destination File": "Destination File",
18
+ "Variables": "Variables",
19
+ "Images": "Images",
20
+ "Placeholder Format": "Placeholder Format",
21
+ "Document ID": "Document ID",
22
+ "Document Name": "Document Name",
23
+ "Folder": "Folder",
24
+ "Create a new document if not found?": "Create a new document if not found?",
25
+ "New Document Properties": "New Document Properties",
26
+ "Method": "方法",
27
+ "Headers": "信头",
28
+ "Query Parameters": "查询参数",
29
+ "Body Type": "Body Type",
30
+ "Body": "正文内容",
31
+ "Response is Binary ?": "Response is Binary ?",
32
+ "No Error on Failure": "失败时没有错误",
33
+ "Timeout (in seconds)": "超时(秒)",
34
+ "Follow redirects": "Follow redirects",
35
+ "Text to append": "Text to append",
36
+ "The ID of the file to replace the values": "The ID of the file to replace the values",
37
+ "Dont include the placeholder format \"[[]]\" or \"{{}}\", only the key name and its value": "Dont include the placeholder format \"[[]]\" or \"{{}}\", only the key name and its value",
38
+ "Key: Image ID (get it manually from the Read File Action), Value: Image URL": "Key: Image ID (get it manually from the Read File Action), Value: Image URL",
39
+ "Choose the format of placeholders in your template": "Choose the format of placeholders in your template",
40
+ "The ID of the document to read": "The ID of the document to read",
41
+ "Authorization headers are injected automatically from your connection.": "授权头自动从您的连接中注入。",
42
+ "Enable for files like PDFs, images, etc.": "Enable for files like PDFs, images, etc.",
43
+ "The text to append to the document": "The text to append to the document",
44
+ "The ID of the document to append text to": "The ID of the document to append text to",
45
+ "Curly Braces {{}}": "Curly Braces {{}}",
46
+ "Square Brackets [[]]": "Square Brackets [[]]",
47
+ "Single Curly Braces {}": "Single Curly Braces {}",
48
+ "Single Square Brackets []": "Single Square Brackets []",
49
+ "GET": "获取",
50
+ "POST": "帖子",
51
+ "PATCH": "PATCH",
52
+ "PUT": "弹出",
53
+ "DELETE": "删除",
54
+ "HEAD": "黑色",
55
+ "None": "无",
56
+ "JSON": "JSON",
57
+ "Form Data": "表单数据",
58
+ "Raw": "原始文件",
59
+ "New Document": "New Document",
60
+ "Triggers when a new document is added to a specific folder(optional).": "Triggers when a new document is added to a specific folder(optional)."
61
+ }
package/src/index.ts ADDED
@@ -0,0 +1,46 @@
1
+ import { createPiece } from '@guayaba/workflows-framework';
2
+
3
+ import { createCustomApiCallAction } from '@guayaba/workflows-common';
4
+ import { PieceCategory } from '@guayaba/workflows-shared';
5
+ import { createDocument } from './lib/actions/create-document';
6
+ import { createDocumentBasedOnTemplate } from './lib/actions/create-document-based-on-template.action';
7
+ import { readDocument } from './lib/actions/read-document.action';
8
+ import { appendText } from './lib/actions/append-text';
9
+ import { findDocumentAction } from './lib/actions/find-document';
10
+ import { newDocumentTrigger } from './lib/triggers/new-document';
11
+ import { googleDocsAuth, getAccessToken, GoogleDocsAuthValue } from './lib/auth';
12
+
13
+ export { googleDocsAuth, getAccessToken, GoogleDocsAuthValue } from './lib/auth';
14
+
15
+ export const googleDocs = createPiece({
16
+ displayName: 'Google Docs',
17
+ description: 'Create and edit documents online',
18
+ minimumSupportedRelease: '0.30.0',
19
+ logoUrl: 'https://cdn.activepieces.com/pieces/google-docs.png',
20
+ categories: [PieceCategory.CONTENT_AND_FILES],
21
+ authors: [
22
+ 'pfernandez98',
23
+ 'kishanprmr',
24
+ 'MoShizzle',
25
+ 'khaledmashaly',
26
+ 'abuaboud',
27
+ 'AbdullahBitar',
28
+ 'Kevinyu-alan'
29
+ ],
30
+ auth: googleDocsAuth,
31
+ actions: [
32
+ createDocument,
33
+ createDocumentBasedOnTemplate,
34
+ readDocument,
35
+ findDocumentAction,
36
+ createCustomApiCallAction({
37
+ baseUrl: () => 'https://docs.googleapis.com/v1',
38
+ auth: googleDocsAuth,
39
+ authMapping: async (auth) => ({
40
+ Authorization: `Bearer ${await getAccessToken(auth as GoogleDocsAuthValue)}`,
41
+ }),
42
+ }),
43
+ appendText,
44
+ ],
45
+ triggers: [newDocumentTrigger],
46
+ });
@@ -0,0 +1,29 @@
1
+ import { docsCommon } from '../common';
2
+ import { googleDocsAuth, getAccessToken } from '../auth';
3
+ import { Property, createAction } from "@guayaba/workflows-framework";
4
+
5
+ export const appendText = createAction({
6
+ auth: googleDocsAuth,
7
+ name: 'append_text',
8
+ description: 'Appends text to google docs',
9
+ displayName: 'Append text to google docs',
10
+ props: {
11
+ text: Property.LongText({
12
+ displayName: 'Text to append',
13
+ description: 'The text to append to the document',
14
+ required: true,
15
+ }),
16
+ documentId: Property.ShortText({
17
+ displayName: 'Document ID',
18
+ description: 'The ID of the document to append text to',
19
+ required: true,
20
+ })
21
+ },
22
+ async run(context) {
23
+ return await docsCommon.writeToDocument(
24
+ context.propsValue.documentId,
25
+ context.propsValue.text,
26
+ await getAccessToken(context.auth)
27
+ );
28
+ },
29
+ });
@@ -0,0 +1,102 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { googleDocsAuth, createGoogleClient } from '../auth';
3
+ import { Property, createAction } from '@guayaba/workflows-framework';
4
+ import { google } from 'googleapis';
5
+
6
+ const PLACEHOLDER_FORMATS: Record<string, string> = {
7
+ 'curly_braces': '{{KEY}}',
8
+ 'square_brackets': '[[KEY]]',
9
+ 'single_curly': '{KEY}',
10
+ 'single_square': '[KEY]',
11
+ '{{KEY}}': '{{KEY}}',
12
+ '[[KEY]]': '[[KEY]]',
13
+ '{KEY}': '{KEY}',
14
+ '[KEY]': '[KEY]',
15
+ };
16
+
17
+ export const createDocumentBasedOnTemplate = createAction({
18
+ auth: googleDocsAuth,
19
+ name: 'create_document_based_on_template',
20
+ description:
21
+ 'Edit a template file and replace the values with the ones provided',
22
+ displayName: 'Edit template file',
23
+ props: {
24
+ template: Property.ShortText({
25
+ displayName: 'Destination File',
26
+ description: 'The ID of the file to replace the values',
27
+ required: true,
28
+ }),
29
+ values: Property.Object({
30
+ displayName: 'Variables',
31
+ description: 'Dont include the placeholder format "[[]]" or "{{}}", only the key name and its value',
32
+ required: true,
33
+ }),
34
+ images: Property.Object({
35
+ displayName: 'Images',
36
+ description:
37
+ 'Key: Image ID (get it manually from the Read File Action), Value: Image URL',
38
+ required: true,
39
+ }),
40
+ placeholder_format: Property.StaticDropdown({
41
+ displayName: 'Placeholder Format',
42
+ description: 'Choose the format of placeholders in your template',
43
+ required: true,
44
+ defaultValue: 'square_brackets',
45
+ options: {
46
+ disabled: false,
47
+ options: [
48
+ { label: 'Curly Braces {{}}', value: 'curly_braces' },
49
+ { label: 'Square Brackets [[]]', value: 'square_brackets' },
50
+ { label: 'Single Curly Braces {}', value: 'single_curly' },
51
+ { label: 'Single Square Brackets []', value: 'single_square' }
52
+ ],
53
+ },
54
+ }),
55
+ },
56
+ async run(context) {
57
+ const documentId: string = context.propsValue.template;
58
+ const values = context.propsValue.values;
59
+ const placeholderType = context.propsValue.placeholder_format;
60
+ const placeholder_format = PLACEHOLDER_FORMATS[placeholderType] || '[[KEY]]';
61
+
62
+ const authClient = await createGoogleClient(context.auth);
63
+ const docs = google.docs('v1');
64
+
65
+ const requests = [];
66
+
67
+ for (const key in values) {
68
+ const value = values[key];
69
+ const new_key = placeholder_format.replace('KEY', key);
70
+
71
+ requests.push({
72
+ replaceAllText: {
73
+ containsText: {
74
+ text: new_key,
75
+ matchCase: true,
76
+ },
77
+ replaceText: String(value),
78
+ },
79
+ });
80
+ }
81
+
82
+ for (const key in context.propsValue.images) {
83
+ const value = context.propsValue.images[key];
84
+ requests.push({
85
+ replaceImage: {
86
+ imageObjectId: key,
87
+ uri: String(value),
88
+ },
89
+ });
90
+ }
91
+
92
+ const res = await docs.documents.batchUpdate({
93
+ auth: authClient,
94
+ documentId,
95
+ requestBody: {
96
+ requests: requests,
97
+ },
98
+ });
99
+
100
+ return res;
101
+ },
102
+ });
@@ -0,0 +1,28 @@
1
+ import { createAction } from '@guayaba/workflows-framework';
2
+ import { docsCommon } from '../common';
3
+ import { googleDocsAuth, getAccessToken } from '../auth';
4
+
5
+ export const createDocument = createAction({
6
+ auth: googleDocsAuth,
7
+ name: 'create_document',
8
+ description: 'Create a document on Google Docs',
9
+ displayName: 'Create Document',
10
+ props: {
11
+ title: docsCommon.title,
12
+ body: docsCommon.body,
13
+ },
14
+ async run(context) {
15
+ const accessToken = await getAccessToken(context.auth);
16
+ const document = await docsCommon.createDocument(
17
+ context.propsValue.title,
18
+ accessToken
19
+ );
20
+ const response = await docsCommon.writeToDocument(
21
+ document.documentId,
22
+ context.propsValue.body,
23
+ accessToken
24
+ );
25
+
26
+ return response;
27
+ },
28
+ });
@@ -0,0 +1,126 @@
1
+ import { googleDocsAuth, createGoogleClient } from '../auth';
2
+ import {
3
+ createAction,
4
+ DynamicPropsValue,
5
+ Property,
6
+ } from '@guayaba/workflows-framework';
7
+ import { google } from 'googleapis';
8
+ import { folderIdProp } from '../common/props';
9
+
10
+ export const findDocumentAction = createAction({
11
+ auth: googleDocsAuth,
12
+ name: 'google-docs-find-document',
13
+ displayName: 'Find Document',
14
+ description: 'Search for document by name.',
15
+ props: {
16
+ name: Property.ShortText({
17
+ displayName: 'Document Name',
18
+ required: true,
19
+ }),
20
+ folderId: folderIdProp,
21
+ createIfNotFound: Property.Checkbox({
22
+ displayName: 'Create a new document if not found?',
23
+ defaultValue: false,
24
+ required: false,
25
+ }),
26
+ newDocumentProps: Property.DynamicProperties({
27
+ auth: googleDocsAuth,
28
+ displayName: 'New Document Properties',
29
+ required: false,
30
+ refreshers: ['createIfNotFound'],
31
+ props: async ({ auth, createIfNotFound }) => {
32
+ if (!auth) return {};
33
+ if (!createIfNotFound) return {};
34
+
35
+ const props: DynamicPropsValue = {};
36
+
37
+ if (createIfNotFound) {
38
+ props['content'] = Property.LongText({
39
+ displayName: 'Document Content',
40
+ required: true,
41
+ });
42
+ }
43
+
44
+ return props;
45
+ },
46
+ }),
47
+ },
48
+ async run(context) {
49
+ const { name: documentName, folderId, createIfNotFound, newDocumentProps } = context.propsValue;
50
+ const newDocumentContent = newDocumentProps?.['content'] as string;
51
+
52
+ const authClient = await createGoogleClient(context.auth);
53
+
54
+ const drive = google.drive({ version: 'v3', auth: authClient });
55
+ const docs = google.docs({ version: 'v1', auth: authClient });
56
+
57
+ // Search for the document in Google Drive
58
+ const query: string[] = [
59
+ `name contains '${documentName}'`,
60
+ `mimeType='application/vnd.google-apps.document'`,
61
+ 'trashed=false',
62
+ ];
63
+
64
+ if (folderId) query.push(`'${folderId}' in parents`);
65
+
66
+ const response = await drive.files.list({
67
+ q: query.join(' and '),
68
+ supportsAllDrives: true,
69
+ fields: '*',
70
+ pageSize: 1,
71
+ includeItemsFromAllDrives: true,
72
+ });
73
+
74
+ const existingFile = response.data.files?.[0];
75
+
76
+ if (existingFile) {
77
+ return { found: true, file: existingFile };
78
+ }
79
+
80
+ // Create a new document if not found
81
+ if (!createIfNotFound) return { found: false, file: {} };
82
+
83
+ //creating new Document
84
+ const createdDoc = await docs.documents.create({ requestBody: { title: documentName } });
85
+ const documentId = createdDoc.data.documentId;
86
+
87
+ if (!documentId) throw new Error('Failed to create document');
88
+
89
+ // Insert content into the new document
90
+ if (newDocumentContent) {
91
+ // appending text
92
+ await docs.documents.batchUpdate({
93
+ documentId,
94
+ requestBody: {
95
+ requests: [{ insertText: { text: newDocumentContent, endOfSegmentLocation: {} } }],
96
+ },
97
+ });
98
+ }
99
+
100
+ // Move the document to the specified folder
101
+ if (folderId) {
102
+ const fileData = await drive.files.get({
103
+ fileId: documentId,
104
+ supportsAllDrives: true,
105
+ fields: 'id, parents',
106
+ });
107
+
108
+ await drive.files.update({
109
+ fileId: documentId,
110
+ fields: 'id, name, parents',
111
+ removeParents: fileData.data.parents?.join(','),
112
+ addParents: folderId,
113
+ supportsAllDrives: true,
114
+ });
115
+ }
116
+
117
+ // Fetch document details
118
+ const finalFile = await drive.files.get({
119
+ fileId: documentId,
120
+ supportsAllDrives: true,
121
+ fields: '*',
122
+ });
123
+
124
+ return { found: false, file: finalFile.data };
125
+ },
126
+ });
@@ -0,0 +1,32 @@
1
+ import { googleDocsAuth, createGoogleClient } from '../auth';
2
+ import { Property, createAction } from '@guayaba/workflows-framework';
3
+ import { google } from 'googleapis';
4
+
5
+ export const readDocument = createAction({
6
+ displayName: 'Read Document',
7
+ auth: googleDocsAuth,
8
+ name: 'read_document',
9
+ description: 'Read a document from Google Docs',
10
+ props: {
11
+ documentId: Property.ShortText({
12
+ displayName: 'Document ID',
13
+ description: 'The ID of the document to read',
14
+ required: true,
15
+ }),
16
+ },
17
+ async run(context) {
18
+ const authClient = await createGoogleClient(context.auth);
19
+
20
+ const docs = google.docs({ version: 'v1', auth: authClient });
21
+ const response = await docs.documents.get({
22
+ documentId: context.propsValue.documentId,
23
+ });
24
+
25
+ if (response.status !== 200) {
26
+ console.error(response);
27
+ throw new Error('Error reading document');
28
+ }
29
+
30
+ return response.data;
31
+ },
32
+ });