actions-on-google - 为什么@assistant/conversation 中没有轮播
问题描述
如果没有,我想使用两张以上的卡。如果没有,我想知道如何使用 List(列表代码示例)。
绝对不是 Dialogflow 代码!我需要 ActionsOnGoogle 代码。
const functions = require('firebase-functions');
const syncRequest = require('sync-request');
const express = require('express');
const {
conversation,
Simple,
Card,
Image,
Button,
List,
Table,
Carousel <-------------------------------(Carousel is not constructor ERROR)
} = require('@assistant/conversation');
const app = conversation({debug:true});
app.handle('callApi', (conv) => {
conv.add(new Card({
title: "hello1",
subtitle: "hi",
text: "blablablablablablablablablablablablablablablablablabla",
image: new Image({
url: "some url",
alt: "Some alternative text",
})
}), new Card({
title: "hello2",
subtitle: "ddddddddd",
text: "testtesttesttesttesttesttesttesttesttesttesttesttesttest",
image: new Image({
url: "some url",
alt: "Some alternative text",
})
}));----------------------------------------------------two Card doesn't it work
});
exports.ActionsOnGoogleFulfillment = functions.https.onRequest(app);
寻找 ActionsOnGoogleFulfillment 文档和示例/示例代码链接。
解决方案
Carousel 类型已被Collection类型取代,它在大多数平台上做同样的事情。但是,该名称反映了它可能不会在任何地方都显示为轮播,但仍会代表类似卡片的布局。
对于列表和集合等视觉选择响应,定义响应分为两部分:
- 为类型创建运行时类型覆盖,并包括有关每个条目的可视信息
- 创建列表或集合并引用该类型中的项目以显示
您将通过向会话添加一些内容来创建类型覆盖。所以它可能看起来像这样:
conv.session.typeOverrides = [{
name: 'prompt_option',
mode: 'TYPE_REPLACE',
synonym: {
entries: [
{
name: 'ITEM_1',
synonyms: ['Item 1', 'First item'],
display: {
title: 'Item #1',
description: 'Description of Item #1',
image: ASSISTANT_LOGO_IMAGE,
}
},
{
name: 'ITEM_2',
synonyms: ['Item 2', 'Second item'],
display: {
title: 'Item #2',
description: 'Description of Item #2',
image: ASSISTANT_LOGO_IMAGE,
}
},
{
name: 'ITEM_3',
synonyms: ['Item 3', 'Third item'],
display: {
title: 'Item #3',
description: 'Description of Item #3',
image: ASSISTANT_LOGO_IMAGE,
}
},
{
name: 'ITEM_4',
synonyms: ['Item 4', 'Fourth item'],
display: {
title: 'Item #4',
description: 'Description of Item #4',
image: ASSISTANT_LOGO_IMAGE,
}
},
]
}
}];
然后,您将创建并添加 Collection 对象,从您声明的类型中引用键:
conv.add(new Collection({
title: 'Collection Title',
subtitle: 'Collection subtitle',
items: [
{
key: 'ITEM_1'
},
{
key: 'ITEM_2'
},
{
key: 'ITEM_3'
},
{
key: 'ITEM_4'
}
],
}));
});
对 List 执行此操作将是类似的。实体类型和可视组件将是相同的,但您会稍微不同地定义列表:
conv.add(new List({
title: 'List title',
subtitle: 'List subtitle',
items: [
{
key: 'ITEM_1'
},
{
key: 'ITEM_2'
},
{
key: 'ITEM_3'
},
{
key: 'ITEM_4'
}
],
}));
});
推荐阅读
- prefetch - Google Lighthouse 无法识别预连接和 dns-prefetch
- javascript - Vuex - 突变后获取状态
- html - 如何使用脚本中的帖子?
- android - 禁用设置按钮后,Android我的应用程序崩溃
- html - 如何将 const 传递给多个组件/拆分 React-Redux-Router 文件
- c# - Unity - 从编辑器通过引用传递脚本,在运行时在对象上实例化它
- node.js - 使用自定义标题 WSO2
- javascript - 嵌套列表权重总和算法问题
- python - 使用 PrintfTickFormatter 将 Bokeh x 轴从小数格式化为百分比
- c++ - C++:一个对象可以同时存储和不存储吗?