How do I take the body of text from a google doc into openai chat?

I’d like to take the body of text from a google doc then put it through openai chat with a prompt. I have the workflow after that set up the way I want.
My main issue is with the initial trigger and then somehow getting that google doc text from my google drive into openai.
I can’t tell if I’m referencing the wrong path or if I’m using the steps wrong. I’ve tried a bunch of different steps and variations, but still can’t cite that original body of text into the openai.

Hi @ryandecinque,

To achieve this, you can follow these steps:

  1. Use the “Google Drive - Get File” action to get the file metadata from your Google Drive. You’ll need to provide the file ID, which you can find in the Google Drive URL of the document.

  2. Use the “Google Docs - Get Document Content” action to get the content of the Google Doc. Pass the file ID from the previous step as an input.

  3. Extract the text from the Google Doc content.

  4. Use the OpenAI (ChatGPT) “Chat” action to send the extracted text along with your prompt to OpenAI.

Here’s an example Pipedream component to help you get started:

import { axios } from "@pipedream/platform";

export default defineComponent({
  props: {
    google: {
      type: "app",
      app: "google",
    },
    openai: {
      type: "app",
      app: "openai",
    },
    fileId: {
      type: "string",
      label: "Google Doc File ID",
    },
    prompt: {
      type: "string",
      label: "OpenAI Prompt",
    },
  },
  async run({ $ }) {
    // Get Google Doc content
    const docContent = await this.google.sdk.docs.documents.get({
      documentId: this.fileId,
    });

    // Extract text from Google Doc content
    const text = docContent.data.body.content
      .map((content) => content.paragraph?.elements?.[0]?.textRun?.content)
      .join("");

    // Send text and prompt to OpenAI ChatGPT
    const response = await axios($, {
      method: "POST",
      url: "https://api.openai.com/v1/engines/davinci-codex/completions",
      headers: {
        Authorization: `Bearer ${this.openai.$auth.oauth_access_token}`,
        "Content-Type": "application/json",
      },
      data: {
        prompt: `${this.prompt}\n${text}`,
        max_tokens: 100,
        n: 1,
        stop: null,
        temperature: 0.5,
      },
    });

    return response.data.choices[0].text;
  },
});

Replace fileId and prompt with the appropriate values for your use case. This component will get the content of the Google Doc, extract the text, and send it to OpenAI ChatGPT with the provided prompt. The response from OpenAI will be returned as the output of the component.
I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double check my answers and code! Learn how to build your own.

@ryandecinque Have you seen these events docs? Take a look also at video 0.4 on Pipedream University. That should give you a good overview of how this works. Let me know if that helps.

Hey! Thank you for the help!
I’m so sorry. I wasn’t specific enough.
Basically, I want to take any new Google Doc that is created in my Google Drive folder and put it through ChatGPT.
So far, for the trigger, I have New Files (Instant) so it emits every new file that appears in that Google Drive Folder.
In the next step, I do the Google Docs - Get Document to extract the body of the text. For the Document, I reference the Trigger id with “steps.trigger.event.id” so that it can consistently reference the id of whatever new file appears instead of referencing a specific file.
However, if I do that, I get this Error " This operation is not supported for this document".

Hi @ryandecinque,

I can get the document fine following your steps. I think this might be because you don’t have the permission to the document.

Would you mind confirming that the account you connected to Pipedream has all the permission to the uploaded Google doc, and could you try reconnecting your Google Doc account on Pipedream?


The image above shows my error message.

The image below shows my permissions for my google doc.

Hi @ryandecinque,

Would you mind confirming that the account you connected to Pipedream has all the permission to the uploaded Google doc?

I put an image above showing my permissions. I reconnected all my Drive and Docs permissions within pipedream. Is there a different way to confirm my permissions?
Thank you for your help. This has been a problem for me all week. lol.

Hi @ryandecinque, sorry for not being clear. I mean could you confirm if your account connected to Pipedream can access the Google Doc file, read/write data to it?

In my case, since I’m the owner of the doc, so I can get more detail on it

Where do you find this permission page? Is it in google drive or in pipedream? I uploaded an image of the permissions in pipedream above as well, but it looks nothing like your image. I’m sorry, I’m really incompetent.

I checked my google drive permissions and it says it has permission.

This is the log for the error:

  at Gaxios._request (/tmp/__pdg__/dist/code/fd51e54142dde71e2cad9d490dcd5f3eecdef42cdfb87512f89c982bf68be8b5/node_modules/.pnpm/gaxios@5.1.0/node_modules/gaxios/build/src/gaxios.js:130:23)
    at process.processTicksAndRejections (internal/process/task_queues.js:95:5)
    at OAuth2Client.requestAsync (/tmp/__pdg__/dist/code/fd51e54142dde71e2cad9d490dcd5f3eecdef42cdfb87512f89c982bf68be8b5/node_modules/.pnpm/google-auth-library@8.8.0/node_modules/google-auth-library/build/src/auth/oauth2client.js:382:18)
    at Object.getDocument (file:///tmp/__pdg__/dist/code/fd51e54142dde71e2cad9d490dcd5f3eecdef42cdfb87512f89c982bf68be8b5/code/google_docs/google_docs.app.mjs:104:24)
    at global.executeComponent (/var/task/launch_worker.js:139:22)
    at MessagePort.messageHandler (/var/task/launch_worker.js:598:28)

Hi @ryandecinque,

I think your permission for Pipedream to Google Drive and Google Doc is correct. I’m asking the permission of your Google account to the Google doc. Are your Google Account the owner of the Google Doc, are you able to read/write data to it? You can select the file in your Google Drive to check for you permission

If you can, could you try to use another Google Account, connect it with Pipedream, create a new Google Doc file in your own Drive, and try the Pipedream action?


I have access. I also have another workflow that copies this one exactly. I just tried the other email in this exact workflow. I have the same error.

I have the same question, I want to create a transcript of a sort from a google doc that I can feed into OpenAI.

I have a working flow for audio->transcript->openai-> meeting notes.

Now I want to just take audio frontend out and replace with reading google doc and feed into OpenAI.

How do I get the transcript out of above step to pipe into openai chat?

My next step fails…as it says no text has been provided…

Is anyone even tracking this help forum?

I’m following up on this issue as I have just hit the exact issue trying to solve the exact problem. If anyone has made headway on this I’d appreciate some insight. Thank you.

Hi all,

I’m Pierce, I made a short video that describes how to build this workflow end to end, and I gave some troubleshooting tips that I think @ryandecinque @janidb and @justinrock might find helpful:

Also, here’s a link to the workflow so you can just copy it to your own Pipedream accounts:

1 Like

Thanks Pierce! This was a huge help. Let me google that for you :wink:

1 Like