Skip to content

Instantly share code, notes, and snippets.

@rwisner
Created December 1, 2020 04:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwisner/e37d9abf9e5cc88df67974c27358333c to your computer and use it in GitHub Desktop.
Save rwisner/e37d9abf9e5cc88df67974c27358333c to your computer and use it in GitHub Desktop.
Read a Google Sheet
app.handle('sheet_handle', async (conv) => {
// create a response
var response = "";
// setup the package
const { GoogleSpreadsheet } = require('google-spreadsheet');
// the spreadsheet id can be found in the URL of your sheet
const doc = new GoogleSpreadsheet('SHEET_ID_HERE');
// your api key can be found at https://console.cloud.google.com/apis/credentials
doc.useApiKey('API_KEY_HERE');
// wait for the sheet to load
await doc.loadInfo();
// the first tab in your sheet
const sheet = doc.sheetsByIndex[0];
// read rows
const rows = await sheet.getRows();
// read the name and address from the first row
response += rows[0].name;
response += rows[0].address;
// add the response to the conversation
conv.add(response);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment