[英]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.