Created
December 1, 2020 04:32
-
-
Save rwisner/e37d9abf9e5cc88df67974c27358333c to your computer and use it in GitHub Desktop.
Read a Google Sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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