1

I'm trying to create a custom Google action to turn on machines in a facility and log who is using them and for how long. How do I access Google sheets without using a service account?

So far, I've essentially just copy pasted from this. Specifically, lines 17, 20, 21, 23, 26, 28, 29, 30, 31, and 32. (I did also replace things like "client_email", which as far as I can tell will only work with a service account which I can't use for financial reasons.)

<code>
'use strict';

const functions = require('firebase-functions')
const {dialogflow} = require('actions-on-google')
const {google} = require('googleapis')
const {WebHookClient} = require('dialogflow-fulfillment')

const sheets = google.sheets('v4')

const WELCOME_INTENT = 'Default Welcome Intent'
const FALLBACK_INTENT = 'Default Fallback Intent'
const MACHINE_OFF_INTENT = 'Machine off'
const MACHINE_ON_INTENT = 'Machine on'
const MACHINE_TYPE_ENTITY = 'machine'
const MEMBER_NUM_ENTITY = 'number-sequence'


const app = dialogflow()

app.intent(FALLBACK_INTENT, (conv) => {
 conv.ask("I didn't understand your request")
})

app.intent(MACHINE_OFF_INTENT, (conv) => {
    const machine_type = conv.parameters[MACHINE_TYPE_ENTITY].toLowerCase();
    const member_number = conv.parameters[MEMBER_NUM_ENTITY];
  const spreadsheetID =  "1n5VTSy5e8ger8FeKvKXymFMf2DGLK2lAKe_Qw2iG7Vc";
  const appl = SpreadsheetApp;
  const ss = appl.openById(spreadsheetID);
  const sheet = ss.getSheetByName("Authorizations");
  var engraverAuth = sheet.getRange("A1:A100");
  var woodshopAuth = sheet.getRange("B1:B100");
  var metalshopAuth = sheet.getRange("C1:C100");
  var allAuth = sheet.getRange("D1:D100");
  switch(machine_type){
        case "laser engraver":
        if (member_number.constructor == engraverAuth || member_number.constructor == allAuth) {

        }
      else {
       conv.ask("You are not authorized to use that machine"); 
      }
        break;
        case "woodshop":
          if (member_number.constructor ==woodshopAuth || member_number.constructor == allAuth) {

          }
            else {
       conv.ask("You are not authorized to use that machine"); 
      }
          break;
        case "metalshop":
          if (member_number.constructor ==metalshopAuth || member_number.constructor == allAuth) {

          }
            else {
       conv.ask("You are not authorized to use that machine");
      }
          break;
        default:

      }
})

exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app)
</code>

It just outputs error 500 (internal server error) which I guess is because I'm not authorizing it to use sheets? I'm new to all this and learning as I go so I'm certain there are several fundamental flaws going on here that would be obvious to most people, so help of any kind is appreciated.

player0
  • 124,011
  • 12
  • 67
  • 124

0 Answers0