(Explainable) Data-Centric AI: what are you explaininhg, and to whom?
Automating Google Workspace (GWS) & more with Apps Script
1. Automating Google Workspace
(GWS) & more with Apps Script:
Making the most of Gmail, Google Drive, Calendar,
Docs, Sheets, Slides, Forms, Chat & other services
Wesley Chun - @wescpy@
Principal, CyberWeb
3
Principal Consultant, CyberWeb
● Mission: produce accelerated Python
developers, enable developers to be
successful using Google Cloud and
other Google developer tools & APIs
● Focus: Python, Google Cloud (GCP) &
Google Workspace (GWS) APIs; GAE
migrations; Google X-product sol'ns
● Services: technical consulting,
training, engineering, speaking, code
samples, hands-on tutorials, public
technical content (blogs, social, etc.)
About the speaker
Previous experience / background
● Software Engineer & Developer Advocate
○ Google, Sun, HP, Cisco, EMC, Xilinx &
○ Original Yahoo!Mail engineer/SWE
● Technical trainer, teacher, instructor
○ Teaching Math, Linux, Python since '83
○ Adjunct CS Faculty at local SV colleges
● Python community member
○ Popular Core Python series author
○ Python Software Foundation Fellow
● AB (Math/CS) & CMP (Music/Piano), UC
Berkeley and MSCS, UC Santa Barbara
● Adjunct Computer Science Faculty, Foothill
College (Silicon Valley)
GWS Dev Show
goo.gl/JpBQ40
GAE migration
bit.ly/3xk2Swi
2. Apps Script: why & agenda
● Google provides APIs giving programmatic access to its technologies
○ Its use can be challenging: REST, OAuth2, HTTP, authentication, etc.
● Apps Script: a developer "tool for everyone;" high-level API access
○ "Low code" solution via customized serverless, JavaScript runtime
○ Lets you automate & extend GWS, and ultimately, get the job done
Cloud
computing
review
1
Google
serverless
platforms
2
Introduction to
Apps Script
3
Coding with
Apps Script
4 5
Advanced
topics
7
Wrap-up
6
Inspiration
01
Cloud computing
overview
All you need to know about the cloud
3. What is cloud computing?
spar
Google Compute Engine, Cloud Storage
AWS EC2 & S3; Rackspace; Joyent
Cloud service levels/"pillars"
SaaS
Software as a Service
PaaS
Platform as a Service
IaaS
Infrastructure as a Service
Google BigQuery, Cloud SQL, Vertex AI,
Cloud Datastore, NL, Vision, Pub/Sub
AWS Kinesis, RDS; Windows Azure SQL, Docker
Google Apps Script
Salesforce Platform (formerly force.com)
Google Workspace (was G Suite/Google Apps)
Yahoo!Mail, Hotmail, Salesforce, Netsuite, Office 365
Google App Engine, Cloud Functions
Heroku, Cloud Foundry, Engine Yard, AWS Lambda
4. Google Compute Engine, Cloud Storage
AWS EC2 & S3; Rackspace; Joyent
Outsourcing of apps (SaaS)
SaaS
Software as a Service
PaaS
Platform as a Service
IaaS
Infrastructure as a Service
Google BigQuery, Cloud SQL, Vertex AI,
Cloud Datastore, NL, Vision, Pub/Sub
AWS Kinesis, RDS; Windows Azure SQL, Docker
Google Apps Script
Salesforce Platform (formerly force.com)
Google App Engine, Cloud Functions
Heroku, Cloud Foundry, Engine Yard, AWS Lambda
Google Workspace (was G Suite/Google Apps)
Yahoo!Mail, Hotmail, Salesforce, Netsuite, Office 365
Google Compute Engine, Cloud Storage
AWS EC2 & S3; Rackspace; Joyent
Outsourcing of hardware (IaaS)
SaaS
Software as a Service
PaaS
Platform as a Service
IaaS
Infrastructure as a Service
Google BigQuery, Cloud SQL, Vertex AI,
Cloud Datastore, NL, Vision, Pub/Sub
AWS Kinesis, RDS; Windows Azure SQL, Docker
Google Apps Script
Salesforce Platform (formerly force.com)
Google Workspace (was G Suite/Google Apps)
Yahoo!Mail, Hotmail, Salesforce, Netsuite, Office 365
Google App Engine, Cloud Functions
Heroku, Cloud Foundry, Engine Yard, AWS Lambda
5. Google Compute Engine, Cloud Storage
AWS EC2 & S3; Rackspace; Joyent
Outsourcing of logic-hosting (PaaS)
SaaS
Software as a Service
PaaS
Platform as a Service
IaaS
Infrastructure as a Service
Google BigQuery, Cloud SQL, Vertex AI,
Cloud Datastore, NL, Vision, Pub/Sub
AWS Kinesis, RDS; Windows Azure SQL, Docker
Google Apps Script
Salesforce Platform (formerly force.com)
Google Workspace (was G Suite/Google Apps)
Yahoo!Mail, Hotmail, Salesforce, Netsuite, Office 365
Google App Engine, Cloud Functions
Heroku, Cloud Foundry, Engine Yard, AWS Lambda
Google BigQuery, Cloud SQL, Vertex AI,
Cloud Datastore, NL, Vision, Pub/Sub
AWS Kinesis, RDS; Windows Azure SQL, Docker
Google Compute Engine, Cloud Storage
AWS EC2 & S3; Rackspace; Joyent
IaaS/PaaS gray area (DataB/S/P-aaS?)
SaaS
Software as a Service
PaaS
Platform as a Service
IaaS
Infrastructure as a Service
Google Apps Script
Salesforce Platform (formerly force.com)
Google Workspace (was G Suite/Google Apps)
Yahoo!Mail, Hotmail, Salesforce, Netsuite, Office 365
Google App Engine, Cloud Functions
Heroku, Cloud Foundry, Engine Yard, AWS Lambda
6. Google Compute Engine, Cloud Storage
AWS EC2 & S3; Rackspace; Joyent
SaaS/PaaS gray area
SaaS
Software as a Service
PaaS
Platform as a Service
IaaS
Infrastructure as a Service
Google BigQuery, Cloud SQL, Vertex AI,
Cloud Datastore, NL, Vision, Pub/Sub
AWS Kinesis, RDS; Windows Azure SQL, Docker
Google Workspace (was G Suite/Google Apps)
Yahoo!Mail, Hotmail, Salesforce, Netsuite, Office 365
Google App Engine, Cloud Functions
Heroku, Cloud Foundry, Engine Yard, AWS Lambda
Google Apps Script
Salesforce Platform (formerly force.com)
Summary of responsibility
SaaS
Software as a Service
Applications
Data
Runtime
Middleware
OS
Virtualization
Servers
Storage
Networking
Applications
Data
Runtime
Middleware
OS
Virtualization
Servers
Storage
Networking
IaaS
Infrastructure as a Service
Applications
Data
Runtime
Middleware
OS
Virtualization
Servers
Storage
Networking
PaaS
Platform as a Service
Managed by YOU Managed by cloud vendor
Applications
Data
Runtime
Middleware
OS
Virtualization
Servers
Storage
Networking
on-prem
all you, no cloud
8. ● GWS developer home: developers.google.com/gsuite
● GWS developer intro: youtu.be/NqumcYgj5LI
● GWS REST APIs: youtu.be/2VpvWhDdXsI
● GWS Apps Script: youtu.be/xDovB0pu4OU
● Comprehensive overview: youtu.be/kkp0aNGlynw
Google Workspace
(formerly G Suite and Google Apps)
(GWS) APIs
Know your serverless compute platforms
● Google App Engine — deploy source-based web applications or
mobile backends to the cloud without concerns of servers or
autoscaling (PaaS—app-hosting in the cloud)
● Cloud Functions — for scenarios where you may not have an entire
app; great for microservices, one-off utilities, or event-driven
functions (FaaS/PaaS—function-hosting in the cloud)
● Cloud Run — serverless containers (any language, library, binary) along
with convenience of serverless; use with Docker or "containerless"
w/Cloud Buildpacks (CaaS—container-hosting in the cloud)
● Google Apps Script — Customized JavaScript runtime for automation,
and extension & integration with Workspace plus other Google &
external services ("restricted" PaaS)
9. Google Compute Engine, Google Cloud Storage
AWS EC2 & S3; Rackspace; Joyent
SaaS
Software as a Service
PaaS
Platform as a Service
IaaS
Infrastructure as a Service
Google Workspace (was G Suite/Google Apps)
Yahoo!Mail, Hotmail, Salesforce, Netsuite, Office 365
Google App Engine, Cloud Functions
Heroku, Cloud Foundry, Engine Yard, AWS Lambda
Google BigQuery, Cloud SQL,
Cloud Datastore, NL, Vision, Pub/Sub
AWS Kinesis, RDS; Windows Azure SQL, Docker
Serverless: PaaS-y compute/processing
Google Apps Script
Salesforce Platform (formerly force.com)
03
Introduction to
Google Apps Script
Automate & extend Workspace apps
and other Google & external services
11. JS
But it's not your Daddy's JavaScript...
Google Apps Script is a serverless
JavaScript runtime for automation, and
extension & integration with Google
Workspace (formerly G Suite), Google,
or other external services.
12. What can you do with Apps Script?
Simple, < 10 lines Complex, > 1000 lines
Sheets
function
Web app that sends email,
creates calendar invites, &
sends out customized
docs
Anything in between
For Google services...
13. … each is a JavaScript class
Workspace, other Google, and external services
Google Workspace
Admin SDK
Calendar
Classroom
Contacts
Docs
Drive
Forms
Gmail
Groups
Sites
Sheets
Tasks
Other Google services
AdSense
Analytics
BigQuery
Data Studio
Doubleclick Campaigns
Maps
Mirror (Glass)
People
Shopping Content
Tag Manager
Translate (Language)
YouTube
External services
UrlFetch
JDBC
… and more…
14. Types of Apps Scripts
● Standalone scripts
○ script.google.com
○ Drive: +New ⇒ More ⇒ Google Apps Script
● Add-ons and document-bound scripts
○ Extensions ⇒ Apps Script
○ Extensions ⇒ Add-ons ⇒ Get/Manage add-ons
● Simple web apps and classic Sites-bound gadgets
○ More ⇒ Manage Site ⇒ Apps Script ⇒ Add new script
Document-bound scripts
Tied to specific documents, i.e., Google
Docs, Sheets, Slides, and Forms. Calls
unique to doc types:
● getActiveCell() — Sheets
● getCursor() — Docs
● createPresentation() — Slides
Add-ons: specific type of document-
bound scripts. Gmail is special.
Gmail Add-ons not tied to documents
but individual email threads.
15. Use case categories
Enterprise workflows
Resource management
Automation
Reporting
Third-party integrations
Domain administration
Document approval, purchase orders
Timekeeping, helpdesk, project tracking, billing
Calendaring, mail merge, complex spreadsheets
Dashboards, automated report generation
CRM, accounting, marketing, telephony, HR, social
User management, provisioning, and reset
Teachers’ tools(i.e., GFormIt, Flubaroo, Doctopus)
25. Accessing maps from
spreadsheets?!?
goo.gl/oAzBN9
This… with help from Google Maps & Gmail
function sendMap() {
var sheet = SpreadsheetApp.getActiveSheet();
var address = sheet.getRange("A2").getValue();
var map = Maps.newStaticMap().addMarker(address);
GmailApp.sendEmail('friend@example.com', 'Map',
'See below.', {attachments:[map]});
}
JS
g.co/codelabs/apps-script-intro
26. 05
Advanced topics
Add-ons, Chat bots/apps,
Advanced services, UrlFetch, etc.
● Extend functionality of GWS apps
● Embed your app within Google's!
● 2014: Google Docs, Sheets, Forms
● 2017: Google Slides, Gmail
● 2018: Google Chat (apps/bots)
● Apps Script also powers Looker/Data
Studio community connectors, and
Google Ads scripts
Apps Script powers add-ons… and more!
27. Converting bound script to add-on
// When the document is opened...
function onOpen(e) {
DocumentApp.getUi().createAddonMenu()
.addItem('Start', 'showSidebar')
.addToUi();
}
// When the add-on is installed...
function onInstall(e) {
onOpen(e);
}
// Open sidebar in document with add-on UI
function showSidebar() {
var ui = HtmlService.createHtmlOutputFromFile('Sidebar')
.setTitle('Translate');
DocumentApp.getUi().showSidebar(ui);
}
// ...everything else in your document-bound script...
Developer caveat
● Understand authorization lifecycle
● developers.google.com/apps-script/add-ons/lifecycle
Generating Google Slides from images
28. var NAME = "My favorite images";
var deck = SlidesApp.getActivePresentation();
function addImageSlide(link, index) {
var slide = deck.appendSlide(SlidesApp.PredefinedLayout.BLANK);
var image = slide.insertImage(link);
}
function main() {
var images = [
"http://www.google.com/services/images/phone-animation-results_2x.png",
"http://www.google.com/services/images/section-work-card-img_2x.jpg",
"http://gsuite.google.com/img/icons/product-lockup.png",
"http://gsuite.google.com/img/home-hero_2x.jpg",
];
var [title, subtitle] = deck.getSlides()[0].getPageElements();
title.asShape().getText().setText(NAME);
subtitle.asShape().getText().setText("Google Apps ScriptnSlides Service demo");
images.forEach(addImageSlide);
}
Introducing
Slides Add-ons
goo.gl/sYL5AM
Generating Google Slides from images
Expense
reports...
● Expense reports
● Can't we do them
without leaving Gmail?
● On Web AND mobile?
29. ● At your desk or on the road
● One place to complete
your expense report
● One code base
Gmail Add-ons
Expediting expense
reports
goo.gl/KUVCDu
● Not just for conversations
● Create microservice utilities
● Build chat bots to...
○ Automate workflows
○ Query for information
○ Other heavy-lifting
● Plain text or rich UI "cards"
● Very flexible ("any")
development environment
○ POST to HTTP port
Google Chat bots
(bot framework & API)
30. “I got to work deploying a
light-weight Flask app server…
and in less than an hour had a
working chatbot.”
Greg Meyers, Motorola Solutions CIO
goo.gl/1QeG51
Build bots for anyone, your org or your team… FAST
Traditional API workflow
Traditional APIs vs. Bot architecture
OAuth2
Bot architecture
31. "Hello World" (echo bot)
JavaScript: Google Apps Script
function onMessage(m) {
return {
'text': 'Hi ' + m.sender.displayName + '. You sent: ' + m.text,
'thread': {'name': m.thread.name}
};
}
Google Chat bots
goo.gl/jt3FqK
function onMessage(e) {
return createMessage(e.user.displayName, 0);
}
function onCardClick(e) {
// Create a new vote card when 'NEW' button is clicked.
if (e.action.actionMethodName === 'newvote') {
return createMessage(e.user.displayName, 0);
}
// Updates the card in-place when '+1' or '-1' button is clicked.
var voteCount = +e.action.parameters[0].value;
e.action.actionMethodName === 'upvote' ? ++voteCount : --voteCount;
return createMessage(e.user.displayName, voteCount, true);
}
Simple vote bot
JavaScript: Google Apps Script
32. }, {
textButton: {
text: '-1',
onClick: {
action: {
actionMethodName: 'downvote',
parameters: parameters
}
}
}
}, {
textButton: {
text: 'NEW',
onClick: {
action: {
actionMethodName: 'newvote'
}
}
}
}]
}]
}]
}]
};
}
function createMessage(voter, voteCount, shouldUpdate) {
var parameters = [{key: 'count', value: voteCount.toString()}];
return {
actionResponse: {
type: shouldUpdate ? 'UPDATE_MESSAGE' : 'NEW_MESSAGE'
},
cards: [{
header: {
title: 'Last vote by ' + voter + '!'
},
sections: [{
widgets: [{
textParagraph: {
text: voteCount + ' votes!'
}
}, {
buttons: [{
textButton: {
text: '+1',
onClick: {
action: {
actionMethodName: 'upvote',
parameters: parameters
}
}
}
Google Chat bots
goo.gl/jt3FqK
Vote bot interactive card
● Job: track your corporate
video performance
● Do you really want to go to
every video on YouTube &
write down the view count?
● NO WAY! Automate stats
gathering with Apps Script!
A day at the office counting up YouTube statistics
Automating YT stats
goo.gl/nKfBQi
goo.gl/SVxoCt
33. function getVideoInfo() {
var sheet = SpreadsheetApp.getActiveSheet();
var vid = sheet.getRange("A2").getValue();
var data = YouTube.Videos.list(
'snippet, statistics', {id: vid});
var item = data.items[0];
var info = [
item.snippet.title, item.statistics.viewCount];
sheet.getRange("B2:C2").setValues([info]);
}
Automating YouTube stats with Apps Script
const PROMPT = 'Describe a cat in a few sentences';
const MODEL = 'gemini-pro';
const scriptProperties = PropertiesService.getScriptProperties();
const apiKey = scriptProperties.getProperty('API_KEY');
const GEM_API_URL = 'https://generativelanguage.googleapis.com/' +
`v1beta/models/${MODEL}:generateContent?key=${apiKey}`;
function helloGemini() {
console.log(`** GenAI text: "${MODEL}" model & prompt "${PROMPT}"`);
const payload = {contents: [{parts: [{text: PROMPT}]}]};
const options = {payload: JSON.stringify(payload), contentType: "application/json"};
const response = UrlFetchApp.fetch(GEM_API_URL, options);
const obj = JSON.parse(response.getContentText());
if (obj.candidates.length > 0 && obj.candidates[0].content.parts.length > 0) {
console.log(obj.candidates[0].content.parts[0].text);
}
}
Google AI: Gemini API (Apps Script)
34. Apps Script
& Gemini API
● Command-line interface
● Integrate with git plus
your local IDE/dev env.
● Actions
○ Create
○ Pull
○ Push
○ Clone
○ Deploy
○ View logs
● Built on Apps Script API
● developers.google.com/a
pps-script/guides/clasp
Professional workflow with clasp tool
35. 06
Inspiration
What you can build with Apps
Script & Google APIs
Big data analysis to slide presentation
Access GCP tools from Google Workspace (formerly G Suite)
39. Supercharge Workspace (G Suite) with GCP
Workspace (G Suite) GCP
BigQuery
Apps Script
Slides Sheets
Application
request
Big data
analytics
App summary
● Leverage GCP and build the "final mile" with Google Workspace (formerly G Suite)
● Driven by Google Apps Script
● Google BigQuery for data analysis
● Google Sheets for visualization
● Google Slides for presentable results
● "Glued" together w/Google Workspace (formerly G Suite) serverless
● Build this app (codelab): g.co/codelabs/bigquery-sheets-slides
● Video and blog post: bit.ly/2OcptaG
● Application source code: github.com/googlecodelabs/bigquery-sheets-slides
● Presented at Google Cloud NEXT (Jul 2018 [DEV229] & Apr 2019 [DEV212])
● cloud.withgoogle.com/next18/sf/sessions/session/156878
● cloud.withgoogle.com/next/sf/sessions?session=DEV212
41. Sheets
Lightweight inventory management system
Cloud
Functions
Cloud
Vision
Google Workspace
(formerly G Suite)
GCP
Export
data
Cloud
Functions
Apps Script
Cloud
Storage
Get
inventory
Cloud
Pub/Sub
Analyze
image
Store
image
Update
shoe
CRUD
inventory
Cloud
SQL
App summary
● Motivation
● Help sales floor staff with store inventory information
● GCP helps Sheets scale and provide machine learning capabilities
● Web interface for scale and convenience
● Use Google Workspace (formerly G Suite) and GCP APIs to:
● Build friendly web interface (mobile or computer)
● Export Sheets data into Cloud SQL
● Allow users to make information requests
● Add intelligence to data and enhance user experience
● Cloud Functions microservices leveraging Sheets as "glue tool" for user experience
● Application source code: github.com/asrivas/Next2019
● "Serverless from the Ground Up with GCP & Google Workspace" (Cloud NEXT '19)
● youtu.be/NvCM7OC_5pA
42. 07
Wrap-up
Summary & resources
Apps Script summary
● It’s just JavaScript
● Access to Google plus other online resources
● No API complexity… use authenticated, built-in services
● Serverless… no setup nor deployment required
● Variety of use cases
● Execution as scripts or add-ons
● No longer Google's best kept secret?!?
43. Apps Script references + next steps
● Introductory Apps Script codelab
○ g.co/codelabs/apps-script-intro
● Creating your own (custom) functions
○ developers.google.com/apps-script/guides/sheets/functions
● Developer videos, guides, and tutorials
○ developers.google.com/apps-script/guides/videos
● High-level introductory video
○ youtu.be/xDovB0pu4OU
● Official documentation site
○ developers.google.com/apps-script
● Alternative: Google Workspace APIs
○ developers.google.com/gsuite
Other Google APIs & platforms
● GCP (cloud-based compute, storage, networking, AI/ML, data analysis tools!)
○ cloud.google.com
● Firebase (mobile development platform and RT DB plus ML-Kit)
○ firebase.google.com and firebase.google.com/docs/ml-kit
● Google Data Studio (data visualization, dashboards, etc.)
○ datastudio.google.com/overview
○ goo.gle/datastudio-course
● Actions on Google/Assistant/DialogFlow (voice apps)
○ developers.google.com/actions
● YouTube (Data, Analytics, and Livestreaming APIs)
○ developers.google.com/youtube
● Google Maps (Maps, Routes, and Places APIs)
○ developers.google.com/maps
● Flutter (native apps [Android, iOS, web] w/1 code base[!])
○ flutter.dev
44. Bring me to your organization
... it is my job to help you!
● Engineering consulting
● Software development
● Technical seminars/tech talks
● Hands-on workshops
● Technical training courses
● Migration strategy & planning
● cyberwebconsulting.com
● appenginemigrations.com
Slides
you're looking at
them now
Work
cyberwebconsulting.com
Books
corepython.com
Blog
dev.to/wescpy
Intro post+video
t.co/rqHT2gYN6z
Automate YT stats
goo.gl/nKfBQi
goo.gl/SVxoCt
Big data ⇒ slides
bit.ly/2O9KqDd
Progress bars
goo.gl/69EJVw
Thank you! Questions?
Wesley Chun
Principal Consultant, CyberWeb
Python, GCP & GWS specialist
CONTACT: @wescpy@