Google Docs

docs.google.com

Create, update and delete documents in Google Docs.

Using the Google Docs API with Trigger.dev

You can use Trigger.dev with any existing Node SDK or even just using fetch. Using io.runTask makes your Google Docs background job resumable and appear in our dashboard.

  • Use io.runTask() and the official SDK or fetch.

  • Use our HTTP endpoint to subscribe to webhooks

  • Example code using Google Docs

    Below is a working code example of how you can use Google Docs with Trigger.dev. These samples are open source and maintained by the community, you can copy and paste them into your own projects.

    import { TriggerClient } from "@trigger.dev/sdk";
    // Apps Script Docs: https://developers.google.com/apps-script/reference
    // Triggers Docs: https://developers.google.com/apps-script/guides/triggers
    // Go to https://docs.google.com/document
    // Open a document or create a new one
    // Click on Extensions > Apps Script
    // Add the following code to the script editor:
    // function pushNotification(e) {
    // // get endpoint url and secret key from trigger.dev dashboard
    // var url = ''
    // var secretKey = ''
    // var payloadData = {
    // 'message': 'Google Docs event',
    // 'details': e // This contains information about the edit event
    // };
    // var payload = JSON.stringify(payloadData);
    // var options = {
    // 'method': 'post',
    // 'contentType': 'application/json',
    // 'headers': {
    // 'x-webhook-secret': secretKey
    // },
    // 'payload': payload
    // };
    // UrlFetchApp.fetch(url, options);
    // }
    // Save the script and click on the clock icon (Triggers) in the sidebar to open the Triggers page
    // Click on Add Trigger, which will open a dialog box
    // Choose pushNotification as the function to run
    // Select event type, by default it is set to On open
    // Click Save
    // Set the GOOGLE_DOCS_WEBHOOK_SECRET (Secret) in the .env file.
    // Create an HTTP Endpoint, with the Google Docs details
    const docs = client.defineHttpEndpoint({
    id: "google-docs",
    source: "google-docs",
    icon: "googledocs",
    verify: async (request) => {
    const secret = process.env.GOOGLE_DOCS_WEBHOOK_SECRET;
    if (!secret) return { success: false, reason: "Missing Secret" };
    if (request.headers.get("x-webhook-secret") === secret)
    return { success: true };
    return { success: false, reason: "Webhook Secret Match Failed" };
    },
    });
    client.defineJob({
    id: "http-google-docs",
    name: "HTTP Google Docs",
    version: "1.0.0",
    enabled: true,
    // Create a trigger from the HTTP endpoint
    trigger: docs.onRequest(),
    run: async (request, io, ctx) => {
    const body = await request.json();
    await io.logger.info(`Body`, body);
    },
    });
    ,