0

I am building a Chrome Extension that does Speach-to-Text to a Google Document. The way I made it work is by sending my processed data to a Google Apps Script, so it can be written, modified, calling specific functions inside the GAS, etc.

const callGoogleAPIScript = async (token, functionName, paramToSend) => {

    const postToGoogleScript = `https://script.googleapis.com/v1/scripts/${scriptId}:run`;
    const payload = {
        function: functionName,
        parameters: [paramToSend],
        devMode: true, // Set this to true for testing purposes.
    };
    try {
        await fetch(postLinkGoogleScript, {
            method: 'POST',
            headers: {
                Authorization: `Bearer ${token}`,
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(payload),
        });
    } catch (error) {
        console.log('Something wrong with script:', error);
        return false;
    }
};

The GAS itself is not container-bound to a Google Document, so to access my doc I use

const doc = DocumentApp.openById(docID);

At first, this wasn't a problem, because it has done correctly the data sending and my other features, but I wanted to create a UI to check for user input:

const ui = DocumentApp.getUi()

But as the dev mentioned: A script can only interact with the UI for the current instance of an open spreadsheet, and only if the script is bound ( Note: same goes for docs ).

So is it possible to bind my GAS to the Document knowing its ID? Or a workaround would be to get the ID in my extension and create a GAS with the specific code for that document, so they will be container-bound

VladTbk321
  • 73
  • 8
  • Does this answer your question? [How can I set an app script on a Google Sheet via the API?](https://stackoverflow.com/questions/71753735/how-can-i-set-an-app-script-on-a-google-sheet-via-the-api) – Daniel Apr 03 '23 at 21:19

0 Answers0