[英]How to create table in dialogflow-fulfillment
在 actions-on-google 中,我們可以添加如下表格:
const {dialogflow, Table} = require('actions-on-google');
const request = require('request');
const conv = new DialogflowConversation(request);
conv.ask('This is a simple table example.');
conv.ask(new Table({
dividers: true,
columns: ['header 1', 'header 2', 'header 3'],
rows: [
['row 1 item 1', 'row 1 item 2', 'row 1 item 3'],
['row 2 item 1', 'row 2 item 2', 'row 2 item 3'],
],
}));
如何使用 dialogflow-fulfillment 創建表格?
實際上,就我而言,我使用的是 dialogflow-fulfillment。 而且我想使用像:
agent.add(new Table({
dividers: true,
columns: ['header 1', 'header 2', 'header 3'],
rows: [
['row 1 item 1', 'row 1 item 2', 'row 1 item 3'],
['row 2 item 1', 'row 2 item 2', 'row 2 item 3'],
],
}));
我可以使用 dialogflow-fulfillment 這樣做嗎?
也許是吧。 這取決於您希望該表在何處工作。
Dialogflow 集成一般沒有表定義。 因此,您無法創建可用於 Facebook 集成的表。
但是,如果您想為 Actions on Google 創建一個表,您可以這樣做。 而不是試圖將其添加到您的agent
對象,你可以得到一個conv
使用對象agent.getConv()
並以此來增加一個表conv.add()
我沒有測試過這個,但它可能是這樣的:
const { WebhookClient } = require('dialogflow-fulfillment');
const { Table } = require('actions-on-google');
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
function assistantTableHandler(agent) {
let conv = agent.conv(); // Get Actions on Google library conversation object
conv.ask('Please choose an item:'); // Use Actions on Google library to add responses
conv.ask(new Table({
dividers: true,
columns: ['header 1', 'header 2', 'header 3'],
rows: [
['row 1 item 1', 'row 1 item 2', 'row 1 item 3'],
['row 2 item 1', 'row 2 item 2', 'row 2 item 3'],
],
}));
};
// Add handler registration, etc
}
您可以查看更完整的示例,說明如何使用 dialogflow-fulfillment 庫在 Google 對象上使用 Actions。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.