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