如何使用基于Basic卡的Dialogflow并链接到网站,在Google上构建Action?

问题描述 投票:0回答:1

我是来自印度的Shannhq Shaikh。我最近成为了Google智能助理开发者社区的成员。现在我正在使用应用程序来处理与网站链接的图像和事实。我正在用Dialogflow构建它。我想知道如何基于连接到NASA的Apod网站的基本卡片响应来构建助手应用程序。它应该像当时的事实形象的应用程序。请给我解决方案。

google-assistant-sdk
1个回答
0
投票

早上好,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

© www.soinside.com 2019 - 2024. All rights reserved.