如何通过 Fulfillment 为 Dialogflow Messenger 集成添加建议芯片? [英] How to add Suggestion Chips through Fulfillment for the Dialogflow Messenger integration?

查看:35
本文介绍了如何通过 Fulfillment 为 Dialogflow Messenger 集成添加建议芯片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在网站中嵌入了 Dialogflow Messenger,并想添加一些建议芯片.通过 Custom Payload 响应类型很容易,而且它们显示得很好.但我如何通过履行添加它们?

So I have the Dialogflow Messenger embedded in a website and want to add some Suggestion chips. It's easy through the Custom Payload Response type and they show up just fine. But how do I add them through fulfillment?

我目前有一个自定义的 webhook 设置,我的想法是有这样的东西:

I currently have a custom webhook setup and the idea is to have something like this:

if (x) {
  agent.add('blablabla');
  agent.add(new Suggestion('One');
} else {
  agent.add('blablabla');
  agent.add(new Suggestion('Two');
}

new Suggestion 不起作用,那么还有其他方法吗?我在想这样的事情:

new Suggestion doesn't work though, so is there another way of doing this? I was thinking about something like this:

agent.add(new Payload(
  "richContent": [
    [
      {
        "options": [
          {
            "text": "One"
          },
          {
            "text": "Two"
          }
        ],
        "type": "chips"
      }
    ]
  ]));

本质上是尝试将自定义负载直接插入到响应 JSON 中,如果这有意义的话.但是是的,不知道如何实际做到这一点.有人知道怎么做吗?

Essentially trying to insert the Custom Payload directly into the response JSON, if that makes any sense. But yeah no idea how to actually do it. Anyone know how?

推荐答案

我不清楚您所说的 new Suggestion() 不起作用究竟是什么意思.您是说 Dialogflow Messenger 中不显示建议芯片?它们是否显示在 Dialogflow 本身中?

It is unclear to me what you exactly mean by new Suggestion() doesn't work. You mean the suggestion chips do not show in Dialogflow Messenger? Do they show in Dialogflow itself?

让我分享几点:

  • 据我所知结构 agent.add(new Suggestion(One")); 应该可以工作.我尝试了一个简单的例子,它在 Dialogflow UI 中运行良好,代码如下:
  • As far as I know the structure agent.add(new Suggestion("One")); should work. I tried a simple example and it is working fine in Dialogflow UI, with the code:
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
 
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
 
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response });
  console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
  console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
  
  let intentMap = new Map();
  intentMap.set('Default Welcome Intent', welcome);
  intentMap.set('Default Fallback Intent', fallback);
  function welcome(agent){ 
    agent.add("What is your favorite animal?");
    agent.add(new Suggestion("Dog"));
    agent.add(new Suggestion("Cat"));
  }

  function fallback(agent) {
    agent.add(`I didn't understand`);
    agent.add(`I'm sorry, can you try again?`);
  }

  agent.handleRequest(intentMap);
});

  • 如果即使在 Dialogflow UI 中也没有呈现建议芯片,我建议您尝试使用之前的代码来消除 Dialogflow 设置的任何潜在问题.您可能需要升级一些依赖项,例如dialogflow-fulfillment":^0.6.1".

    某些集成(例如 Google 助理)使用来自 actions-on-googleSuggestions 库.例如,请参阅官方 Google 助理代码示例.如果它适合您的用例,您可以尝试遵循类似的行为,尽管我认为情况并非如此.作为参考,您可以查看 this github 问题.

    Some integrations, like Google Assistant use the Suggestions library from actions-on-google. See for example official Google Assistant code example. You may try to follow a similar behavior if it fits your use case although I do not think it is the case. As a reference you can check this github issue.

    这篇关于如何通过 Fulfillment 为 Dialogflow Messenger 集成添加建议芯片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆