Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

1.3 KB
Raw Blame
import { googleDocsAuth, createGoogleClient } from '../auth';
import { createAction } from '@activepieces/pieces-framework';
import { docs as googleDocs } from '@googleapis/docs';
import { documentIdProp } from '../common/props';
import { readDocumentActionOutputSchema } from '../output-schemas';

export const readDocument = createAction({
  displayName: 'Read Document',
  auth: googleDocsAuth,
  name: 'read_document',
  classification: 'READ',
  description: 'Read a document from Google Docs.',
  audience: 'human',
  aiMetadata: {
    description:
      'Fetches the full content and structure of a Google Docs document by its ID. Use when an agent needs to inspect, summarize, or extract text from a known document. Requires the document ID (not a name or URL); read-only and idempotent.',
    idempotent: true,
  },
  props: {
    documentId: documentIdProp(),
  },
  outputSchema: readDocumentActionOutputSchema,
  async run(context) {
    const authClient = await createGoogleClient(context.auth);

    const docs = googleDocs({ version: 'v1', auth: authClient });
    const response = await docs.documents.get({
      documentId: context.propsValue.documentId,
    });

    if (response.status !== 200) {
      console.error(response);
      throw new Error('Error reading document');
    }

    return response.data;
  },
});