如何使用google-spreadsheet节点模块在我的Google智能助理应用中从我的Google电子表格中读取数据?

时间:2018-01-09 19:24:13

标签: node-modules google-sheets-api google-assist-api

我想构建一个Google Assistant应用程序,以便在我的组织内使用。该应用程序将告诉用户当前可用的商品库存。该应用将从Google电子表格中读取此数据。 在doc.getInfo(函数(错误,信息)中,我在Google模拟器上的操作中测试我的应用程序时得到的信息是未定义的。有人可以告诉我为什么吗?我按照这些示例编写了{{ 3}}和https://www.twilio.com/blog/2017/03/google-spreadsheets-and-javascriptnode-js.html

'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);
});

0 个答案:

没有答案
相关问题