This is a sample repository to show how to setup a website to integrate with Google Sheets and the Wordsmith API.
It's built with node.js, using Express and assumes some familiarity with JavaScript.
- You should have a Wordsmith account.
- You should have a Pusher account.
- You should have a Google Drive account that you can use to create a new Google Sheets file.
- You'll need node.js installed on your local machine.
- You'll want to host the site somewhere so that the Google Apps script can access it via HTTP. For the purposes of this example, we'll use Heroku as an example. It's free, so if you don't have somewhere to host the site, you might want to create an account. If you're hosting your site elsewhere, feel free to ignore this part, and handle your own deployments.
First, generate a random string to use as an APP_SECRET
. There's lots of tools out there for this, such as this one.
- Create a new app.
- Note the
app_id
,key
, andsecret
which you'll need in your app.
- Create a new project.
- Upload a CSV to your project. Use the
resources/wordsmith_data.csv
file in this repo. - Create a new template. Feel free to just enter a single sentence to start with. Add a data variable.
- Create a new Google Sheets file.
- Import the
resources/wordsmith_data.csv
file. (Under File > Import...) - Add a new script. (Tools > Script editor...)
- Copy and paste the contents of
resources/google_app_script.js
into theCode.gs
file. - Replace the value of
WEBSITE_AUTHORIZATION_HEADER
with yourAPP_SECRET
. - Replace the hostname in the
WEBSITE_POST_URL
with your hostname. - In the Google Apps Script editor, open Triggers. (Resources > Current project's triggers)
- Click 'Add a new trigger'. Select 'onEdit' for Run, 'fromSpreadsheet' for Events, and 'On edit' for the trigger type. Save and close.
cp .env.example .env
- Open up your .env file. You should add values as follows:
- APP_SECRET => your newly generated APP_SECRET
- WORDSMITH_API_KEY => grab this from the Wordsmith application here.
- WORDSMITH_PROJECT_NAME => the name of your Wordsmith project.
- WORDSMITH_TEMPLATE_NAME => the name of your Wordmsith template.
- PUSHER_APP_ID => get this from the Pusher application.
- PUSHER_APP_KEY => get this from the Pusher application.
- PUSHER_APP_SECRET => get this from the Pusher application.
- PUSHER_CHANNEL => make up a name, it doesn't matter what it is. Ie, 'test-channel'.
- PUSHER_EVENT => make up a name, it doesn't matter what it is. Ie, 'test-event'.
npm i
- install all dependenciesnpm start
- this will start the application. Open uphttp://localhost:3000/
and you should something that looks like this.
You'll need to deploy the application one time in order to have an endpoint that exists for the Google Apps script.
If you have a server that you're using, feel free to ignore this. Otherwise, we'll use Heroku.
- Create a new Heroku app. Select node.js as your development environment.
- Install the Heroku CLI if you haven't already.
heroku git:remote -a your-app-name
- set your Heroku remote.- Open your app in the Heroku dashboard. Go to Settings.
- Add the nodejs buildpack to your Heroku app.
- Add all of your ENV vars from
.env
to 'Config Variables' in your Heroku dashboard. Make sure you add these or your app won't work properly in production.
git push heroku master
- this will deploy your app to Heroku.
heroku logs --tail
- tail heroku logs to troubleshoot production issues.