【发布时间】:2019-07-31 17:36:43
【问题描述】:
我正在使用 Dialogflow 构建一个聊天机器人,我需要为此链接 Google 表格,该表格将充当后端以从表格中检索数据并在触发意图时显示在聊天机器人中。我该如何做任何可以提供帮助的教程或文档?
【问题讨论】:
标签: api google-sheets dialogflow-es webhooks dialogflow-es-fulfillment
我正在使用 Dialogflow 构建一个聊天机器人,我需要为此链接 Google 表格,该表格将充当后端以从表格中检索数据并在触发意图时显示在聊天机器人中。我该如何做任何可以提供帮助的教程或文档?
【问题讨论】:
标签: api google-sheets dialogflow-es webhooks dialogflow-es-fulfillment
如果你使用 NodeJS 作为你的 webhook,
您可以使用Google spreadsheet来存储和获取数据,
const GoogleSpreadsheet = require('google-spreadsheet');
const sheets = new GoogleSpreadsheet(process.env.sheetid);
// sheetid can be found from sheet URL
const config = {
client_email: process.env.client_email,
private_key: process.env.private_key
}
// config detail you need to get from your service account
// share your client_email in your sheet with read and write permission
sheets.useServiceAccountAuth(config, () => {
sheets.getInfo(async (err, info) => {
sheet = info.worksheets
// same way you will be getting your sheet data in sheet variable
await addRows(sheet, 0, rowData)
// rowData => your data
})
});
function addRows(sheet, index, data) { // index is your sheet tab index
return new Promise((resolve, reject) => {
sheet[index].addRow(data, (err, row) => {
if (err) return reject(err)
resolve(row)
})
})
}
【讨论】:
我使用Vodo Drive 执行此操作,尽管目前仅用于操作。
确保您了解如何使用 Google 的 OAuth 从用户那里获得使用 Sheets API 访问其工作表的授权。这是您在使用 Dialogflow 执行此操作之前需要了解的主要内容。
使用 Dialogflow 进行常规机器人集成时遇到的最大问题是能够知道他们正在使用的 Google 帐户(并且您拥有 OAuth 令牌)。如果您正在为操作构建,则可以使用帐户链接。其他集成也可能传递用户信息,但这不能保证。
【讨论】: