问题
In actions-on-google we can add table like :
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'],
],
}));
How to create the table using dialogflow-fulfillment ??
Actually in my case, I am using dialogflow-fulfillment. ANd I want to use like :
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'],
],
}));
Can I do it like this using dialogflow-fulfillment?
回答1:
From the source code of library, it doesn't seem that Table
is still provided in that.
By looking at the source I can say it is providing
- Text
- Cards
- Images
- Suggestion Chips (Quick Replies)
Even if we look at src folder it is not having anything related to Table
回答2:
Maybe, yes. It depends on exactly where you expect the table to work.
There is no table definition for Dialogflow integrations in general. So you can't create a table that will work on the Facebook integration.
However, if you want to create a table for Actions on Google, you can do this. Instead of trying to add it to your agent
object, you can get a conv
object using agent.getConv()
and use this to add a table with conv.add()
.
I haven't tested this, but it might be something like this:
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
}
You can see a more complete example of how to use Actions on Google object using the dialogflow-fulfillment library.
来源:https://stackoverflow.com/questions/56964982/how-to-create-table-in-dialogflow-fulfillment