I'm working with apps script and the plivo api (https://www.plivo.com/docs/sms/api/message#list-all-messages). I'd like to be able to use the plivo node sdk (https://www.plivo.com/docs/sdk/server/node-sdk/) inside apps script. Is there a way to install this or use this from github or some other source directly?
Answer
In a summary you can't install or use plivo by using Apps Script.
You can use your own libraries or a shared library. Third party (external and not shared) libraries in Google Apps Script are not allowed directly.
As per the Google Apps Script documentation says Google Apps Script is a rapid application development platform that makes it fast and easy to create business applications that integrate with G Suite. Apps Script goal is mainly interact with other Google Services/APIs.
Why using third party libraries is not allowed/recommended?
It's possible to use the eval and UrlFetchApp.fetch() function in order to get the content of a specific JS and execute it like:
eval(UrlFetchApp.fetch('http://URL/javascript.js').getContentText());
However, it's adding more computing time when it comes to run an Apps Script and depending on your kind of user there's a limit to successfully execute a script.
External services like plivo or another VOIP services are not allowed due to the reasons I mentioned above. As a workaround I'd suggest to take a look into GCP products like App Engine or Compute Engine and make use of your third party library from there.
Related
I'm trying to find a way to run Google App Script code that's hosted on GHE. I found somewhere that you could get the script as a text string and use eval() to execute it as code, however I've read that it's a very unsecure way to do it and it shouldn't be done. Does anyone know any alternatives ways to run hosted code on Google App Script?
You could:
use this extension: https://chrome.google.com/webstore/detail/google-apps-script-github/lfjcgcmkmjjlieihflfhjopckgpelofo
use git and clasp CLI to push your code to your apps script project
From your specifications, I understand that you want to both host the script in GitHub Enterprise (GHE) and run it from there.
Even though Apps Script API offers a good range of functionalities such as executing functions from your App remotely it is not the best option for this scenario.
With clasp you can also write Apps Script functions remotely but eventually they have to be pushed to an Apps Script project.
So, after considering these limitations I think the best option you would have is to use the right Google API in your script (such as Gmail API for example). Its functional code can all be hosted and run from your application without the need of Apps Script projects and these APIs offer the same and extended functionalities than those offered by Apps Script.
Question:
Can I add the authorization part of my google sheets add-on into my add-on's code or does it need to be a separate thing? What would that code look like? If adding the authorization process into the google app script isn't an option, what would be the next best option and what would that look like?
Premise:
I'm very new to coding or working with an API, google app script, and google cloud platform. I have looked over Google's documentation a dozen times and I'm still unsure how to actually implement the authorization process. Using the HTTP/REST option looks like the best option but I'm really not sure. I've gotten the clientID, secret, URI, etc... that would be required but I don't know where I put that information. Does the code need to be on my website? If so, what would that look like or where can I go to learn more about it?
Thank you in advance!
Approach
When using Apps Script you won't need to insert your credentials anywhere. The Auth flow is managed by the Apps Script environment. Every time you will need extra permissions to run your script, the environment will prompt for your authorization. This will generally require a normal login to the google account you want to use to authorize your script.
Using Google APIs on Apps Script can be done using two different patterns:
Pattern 1: Built-in Google Services
You can use the Apps Script scaffold G Suite Apps classes to work on G Suite Documents, Sheets, Forms, Slides and more. This will feel like programming with native classes and interfaces than using an over-the-internet API.
Pattern 2: Advanced Google Services
Advanced services are essentially thin wrappers around the Google APIs. They You must enable an advanced service before you can use it in a script. To enable the Advanced Services visit the guide here
References:
Built-in Google Services
Advanced Google Services
I was searching for an SDK or API to create and/or edit Google Docs files, but (correct me if I'm wrong) it seems Google Apps Script is the way to integrate your app with G Suite. I'm now trying to grasp the basic workflow for a basic document editing operation.
For instance, say we have a Quote Template document that serves as the template for our business to create quotations for customers. From within our web app system, we would press a button that would duplicate that file with a new name and maybe replace some variables.
Now, here's where I am in a gray area. I'd think we would have to install some sort of SDK (PHP/Js/Ruby library) in our project, that would let us create a new file based on the template, and call some replacePattern(regex, value) method.
However, the more I read, it looks like the approach is different, where you would create a Google Apps Script and, from our web app, we make HTTP calls to a REST API that will run said script. Then, this script would do the creating document and replacing values.
Am I correct in assuming this is the basic workflow to integrate our web app with G Suite products, or am I missing something essential?
Yes, that would be the basic workflow. There is no public Google Docs REST API, so apps script at the moment is the only way to automate docs. If you want to integrate it with a current tool you can expose the script using the Execution API. There are client libraries, though being a REST API they can be accessed from anywhere you can make a http request. Links to the client libraries can be found in their respective quick starts found below:
https://developers.google.com/apps-script/guides/rest/
All of the business logic can be handled by the script such as copying a template, replacing values, and setting permissions to the file.
The DocumentApp service docs can be found at:
https://developers.google.com/apps-script/reference/document/
I have few sheets that have functions bound to the spreadsheet. Each spreadsheet has its own functions and uses SpreadsheetApp.getUi to run html service. I would like to initiate function calls in all the sheets from a master spreadsheet project? is it possible? Something like getting a handle to the spreadsheet project and run a script in that project?
You have two options:
Publish your scripts as libraries and subscribe to each in each other of your script projects.
Publish your scripts as web apps with specific functions as individual pseudo webhooks. Sort of like a distributed API.
There are pros and cons of each. Neither is about maintainability really.
The library option will afford code completion whereas the web app option will enable (if you wish) for you to run code asynchronously.
Both have different speed penalties. Library enabled scripts are slower as described in the documentation. Web apps will be slower because of urlfetch latency.
Library functions will use the runtime allowed for them in the host script, whereas web apps will extend runtime and some quotas.
Documentation:
Publish your scripts as a library
Running apps script as an endpoint
using library seems to me is the fastest and simplest way to protect your code.
for this you need :
1 spreadsheet or any google doc containing Code - SCRIPT A
1 stand-alone script SCRIPT B that you publish as a library.
in the editor of SCRIPT A -
you add the library Key
in the SCRIPT A code you can call the function of SCRIPT B
function callFunctionOfScriptB(){
LibraryIdentifier.functionNameinScriptB()
}
you find LibraryIdentifier when you click on Resources + libraries in the column Identifier of the popup
functionNameinScriptB = the name of the function you want to call in Script B
If you publish a Google Apps Script Library are the script quotas applied per library owner or for the library user?
Libraries are not web services. It goes exactly like when you are using client side lib like Jquery.
When you are using an Apps Script lib, you just add extra code to the one in your code editor. So quota is measured against the lib user.
Otherwise it would be impossible to have libs used by many many users :)
Best,
Romain