A Google Apps Script script to take a google form submission, and post a slightly modified version into a named slack channel.
Used to post job adverts into a #jobs channel, but also persist the data to spreadsheet, where it can be dropped into a regular newsletter.
When you post a job using a linked climate Action.tech job form, your submission be shared into a #jobs channel, and also stored in a google spreadsheet, to be included in the next weekly ClimateAction.tech newsletter.
In both cases, there is a link back to the original slack message to allow for comments and questions.
Note: working with appscript is NOT the same as working on a normal node apps, or a web app. The runtime might be v8 like you have in node or a chrome, but the APIs available are different, as is the process for importing/requiring code.
This script is bound to a corresponding Google Sheet container.
You can access it from Tools > Script Editor within the sheet to see the code and make changes there - but please don't.
This repo exists to keep the code in source control, and as much as you can you should use clasp to manage the lifecycle. You can use clasp to manage deployments,to pull down a versions, make changes, run tests, commit to source control, and deploy new versions into a live environment.
- Clone this repo.
- Install dependencies for testing and the like with
npm install
- Check that tests run ok.
- Fetch necessary id from google script
- Pull latest version from live, with
clasp pull LONG_SCRIPT_ID
- Make changes, in a new branch, and tag a moderator.
- Check that tests work locally.
- Push changes to github
- Changes will be merged.
You can check the live Apps Script dashboard for invocations of the functions, and visit the logs.
Merging into main should trigger a new deploy of the code to the Appscript environment.
You should also be able to push changes with a manual deployment too.
You will need a clasp.json file containing information telling clasp what to deploy though. Add this to your project root.
# clasp.json
{
"scriptId": "LONG_SCRIPT_ID",
"rootDir": "dest/"
}
Once you have this you can then trigger a deploy with the following commands.
Appscript doesn't support require
like nodejs, or even import
like some modern browsers.
You need to either have all the files you intend to use in a directory (appscript loads them all into the same context, so all functions and variables are in a 'global' scope)
Or you need a single concatenated file.
This project currently uses gulp to move the relevant files into a dest
directory, before pushing them into the google apps environment. Any third party libraries need to expose objects or functions into the global scope for them to visible to Appscript. This makes importing libraries somewhat complex. See console.dev mailchimp library as an example of using a third party library, URL.js in a project.
# make a build of all the files you want to
# push to the appscript environment
npx gulp build
### push the contents of the dest dir to appscript -
npx clasp push
This is very much inspired by the console.dev approach for running a newsletter, and relying on Appscript to automate tedious tasks.