簡體   English   中英

如何將Google表格鏈接到Google Dialogflow以從表格中檢索數據?

[英]How to link Google Sheets to Google Dialogflow to retrieve data from sheets?

我正在用Dialogflow構建一個聊天機器人,我需要為其鏈接Google表格,該表格將充當后端以從表格中檢索數據並在觸發意圖時顯示在聊天機器人中。 我該如何做任何有幫助的教程或文檔?

如果您使用NodeJS作為webhook,

您可以使用Google電子表格存儲和獲取數據,

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進行此操作,盡管目前僅用於Actions。

確保您了解如何使用Google的OAuth從用戶獲取授權以使用Sheets API訪問其工作表。 在使用Dialogflow進行此操作之前,這是您需要了解的主要內容。

使用Dialogflow進行一般的bot集成時,您將遇到的最大問題是能夠知道他們正在使用的Google帳戶(並且您擁有OAuth令牌)。 如果要構建操作,則可以使用帳戶鏈接。 其他集成也可能會傳遞用戶信息,但這不能保證。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM