google-assistant-sdk - 如何使用基于 Basic 卡并链接到网站的 Dialogflow 在 Google 上构建 Action?
问题描述
我想知道如何基于链接到 NASA 的 Apod 网站的基本卡片响应构建助手应用程序。它应该像当天的事实图像应用程序。
解决方案
早上好,Annalhq!您可以使用此示例代码开始使用基本卡:
if (!conv.surface.capabilities.has('actions.capability.SCREEN_OUTPUT')) {
conv.ask('Sorry, try this on a screen device or select the ' +
'phone surface in the simulator.');
return;
}
conv.ask('This is a basic card example.');
// Create a basic card
conv.ask(new BasicCard({
text: `This is a basic card. Text in a basic card can include "quotes" and
most other unicode characters including emoji . Basic cards also support
some markdown formatting like *emphasis* or _italics_, **strong** or
__bold__, and ***bold itallic*** or ___strong emphasis___ as well as other
things like line \nbreaks`, // Note the two spaces before '\n' required for
// a line break to be rendered in the card.
subtitle: 'This is a subtitle',
title: 'Title: this is a title',
buttons: new Button({
title: 'This is a button',
url: 'https://assistant.google.com/',
}),
image: new Image({
url: 'https://example.com/image.png',
alt: 'Image alternate text',
}),
display: 'CROPPED',
}));
在您的卡片按预期显示后,您可以添加链接建议芯片,如下所示:
if (!conv.surface.capabilities.has('actions.capability.SCREEN_OUTPUT')) {
conv.ask('Sorry, try this on a screen device or select the ' +
'phone surface in the simulator.');
return;
}
conv.ask('These are suggestion chips.');
conv.ask(new Suggestions('Suggestion Chips'));
conv.ask(new Suggestions(['suggestion 1', 'suggestion 2']));
conv.ask(new LinkOutSuggestion({
name: 'Suggestion Link',
url: 'https://assistant.google.com/',
}));
有关更多信息,请参阅文档:
https://developers.google.com/actions/assistant/responses#basic_card
https://developers.google.com/actions/assistant/responses#suggestion_chips
推荐阅读
- java - 无法在 netbeans 中启用 JavaFX
- ansible - Ansible 连接到 Windows Server 2016
- json - 如何在 Postgres 中构建 JSON 对象而不显式引用每一列
- flutter - 在 FutureBuilder 中设置类型的最佳方法?
- git - 如何安全地 git clone 到共享机器上
- typescript - 如何让 splitChunks 生成 commonjs requires() 语句?
- java - java Gson json格式化程序,是否可以输出Z而不是+ 0000?
- apache - 将所有子目录和查询字符串重写到父文件夹
- java - 从 xsd 生成类并重命名包括 getter/setter
- sql - ALTER CREATE 语法,用于在所有版本的 SQL Server 中创建更改对象