Dialogflow填充内联编辑器|请求凭证文件

时间:2019-11-24 14:52:05

标签: dialogflow dialogflow-fulfillment inline-editor

我正在使用Dialogflow创建聊天机器人,为什么我尝试从Google电子表格中获取数据,却出现此错误

  

您的Cloud Function部署失败:功能在以下时间失败   加载用户代码。错误消息:文件index.js中的代码不能   已加载。您是否在package.json中列出了所有必需的模块   依赖?详细的堆栈跟踪:错误:找不到模块   'http://example.com/direactory/cred.json'

这是我添加到dialogflow实现中的代码的一部分,内联编辑器

const GSpreadsheet = require('google-spreadsheet');
const { promisify } = require('util');
const credFile = 'http://example.com/direactory/cred.json';

/* google spreadsheet start */
async function accessSpreadsheet(){
const doc = new GSpreadsheet('SHEET_ID');
await promisify(doc.useServiceAccountAuth)(credFile);
const info = await promisify('doc.getInfo')();
const sheet = info.worksheets[1];
return `Sheet Title: ${sheet.title}`;
}

cred.json文件:

{
  "type": "SERVICE",
  "project_id": "PRODUCT_ID",
  "private_key_id": "PRIVATE_KEY_ID",
  "private_key": "-----BEGIN PRIVATE KEY-----\PRIVATE_KEY\n-----END PRIVATE KEY-----\n",
  "client_email": "CLIENT_EMAIL",
  "client_id": "CLIENT_ID",
  "auth_uri": "AUTH_URI",
  "token_uri": "TOKEY_URI",
  "auth_provider_x509_cert_url": "AUTH_PROVIDER",
  "client_x509_cert_url": "CLIENT_CERT_URL"
}

如何请求http://example.com/direactory/cred.json? 请注意,我在axios文件中的dependencies中有package.json

除此之外,如果我想将凭证JSON代码直接插入index.js内,该怎么做

我发现另一个属于Google日历的代码如下:

// Set up Google Calendar service account credentials
const serviceAccountAuth = new google.auth.JWT({
  email: serviceAccount.client_email,
  key: serviceAccount.private_key,
  scopes: 'https://www.googleapis.com/auth/calendar'
});

我如何使用类似的代码将凭证数据直接包含在index.js中

0 个答案:

没有答案