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

时间:2019-03-03 16:32:35

标签: google-assistant-sdk

我是来自印度的ÀnalhqShaikh。  我最近成为Google Assistant开发者社区的成员。现在,我目前正在为链接到网站的当天的图像和事实工作应用程序。我用Dialogflow构建它。我想知道如何基于链接到NASA Apod网站的基本卡片响应构建“助手”应用程序。它应该类似于当天的事实图片应用程序。 请给我解决方法。

1 个答案:

答案 0 :(得分: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