0

I want to build a Google Assistant app for use within my organization. The app will tell the user the currently available stock of an item. The app will read this data from a Google Spreadsheet. In doc.getInfo(function(err, info) I am getting 'info' as undefined when testing my app in Actions on Google Simulator. Can someone please tell why? I followed these examples to write code below https://www.twilio.com/blog/2017/03/google-spreadsheets-and-javascriptnode-js.html and https://developers.google.com/actions/dialogflow/first-app

'use strict';

process.env.DEBUG = 'actions-on-google:*';
const App = require('actions-on-google').DialogflowApp;
const functions = require('firebase-functions');

// a. the action name from the get_item_name Dialogflow intent
const NAME_ACTION = 'get_item_name';
// b. the parameters that are parsed from the item_name_intent intent 
const ITEM_NAME_ARGUMENT = 'item_name_entity';

var GoogleSpreadsheet = require('google-spreadsheet');
var credentials = require('./factoryStockTeller-77942d.json');

var doc = new GoogleSpreadsheet('17E49xZp_JjylT-oVFS1Q8zzJZ9qGkSgQps');

exports.factoryStockTeller = functions.https.onRequest((request, response) => 
{
   const app = new App({request, response});

  function itemStock(app) 
  {
    let itemName = app.getArgument(ITEM_NAME_ARGUMENT);

    // Authenticate with the Google Spreadsheets API.
    doc.useServiceAccountAuth(credentials, function (err)
    {
        doc.getInfo(function(err, info)
        {
            if(typeof info === "undefined")
               app.tell('UnDefined');
            else
               app.tell('Defined');
        });
    });
  }
  // d. build an action map, which maps intent names to functions
  let actionMap = new Map();
  actionMap.set(NAME_ACTION, itemStock);

app.handleRequest(actionMap);
});
Puneet Jain
  • 21
  • 1
  • 6
  • Haven't tried working with Google Assistant App. But, reading data values in Sheetsv4 is detailed in [Basic Reading](https://developers.google.com/sheets/api/samples/reading) – ReyAnthonyRenacia Jan 10 '18 at 10:55
  • @noogui using google-spreadsheet node module for reading spreadsheets makes the code very concise and in the past, I have successfully worked on other projects using this module. It is only in building Google Assistant App that I am facing some unknown issue. I think my code is not able to get access to spreadsheet due to some authentication problem. – Puneet Jain Jan 10 '18 at 15:00

0 Answers0