Dialogflow 中的自定义负载

Custom payload in Dialogflow

我尝试通过 fulfillment(nodejs) 在 Dialogflow 中发送自定义负载

我的动机是发送 link 及其文本作为对网页的响应。

我的示例代码供参考:

  const response = {
      messages: [
        {
          payload: {
            messages: [
              {
                speech: 'here are some quick links for your convenience.',
                linkmessage: [{
                  message: 'google',
                  link: 'www.google.com'
                }, {
                  message: 'yahoo',
                  link: 'www.yahoo.co.in'
                }],
                button: [{
                  buttonname: 'more page'
                }]
              }
            ]
          }
        }
      ]
    };
    agent.add(new Payload(agent.UNSPECIFIED, response, { rawPayload: true, sendAsMessage: true}));

这里我得到的响应是:

{
    "fulfillment": {
      "speech": "",
      "messages": [
        {
          "lang": "en",
          "type": 0,
          "speech": ""
        }
      ],
      "data": {
        "null": {
          "messages": [
            {
              "payload": {
                "messages": [
                  {
                    "speech": "here are some quick links for your convenience.",
                    "linkmessage": [{
                      "message": "google",
                      "link": "www.google.com"
                    }, {
                      "message": "yahoo",
                      "link": "www.yahoo.co.in"
                    }],
                    "button": [{
                      "buttonname": "more page"
                    }]
                  }
                ]
              }
            }
          ]
        }
      }
    }

在这里您可以看到响应中我得到“null”对象附加在响应中的数据对象中。

谁能帮我从 dialogflow 响应中删除 null 对象,以及从 fulfillment nodejs 发送自定义负载的任何其他选项。

function update() {
const response = {
      messages: [
        {
          payload: {
            messages: [
              {
                speech: 'here are some quick links for your convenience.',
                linkmessage: [{
                  message: 'google',
                  link: 'www.google.com'
                }, {
                  message: 'yahoo',
                  link: 'www.yahoo.co.in'
                }],
                button: [{
                  buttonname: 'more page'
                }]
              }
            ]
          }
        }
      ]
    };
    agent.add(new Payload(agent.UNSPECIFIED, response, { rawPayload: true, sendAsMessage: true}));
}

在这个函数中需要添加参数作为代理,这样你就可以得到非'null'对象

需要更新参考代码。

function update(agent) {
const response = {
      messages: [
        {
          payload: {
            messages: [
              {
                speech: 'here are some quick links for your convenience.',
                linkmessage: [{
                  message: 'google',
                  link: 'www.google.com'
                }, {
                  message: 'yahoo',
                  link: 'www.yahoo.co.in'
                }],
                button: [{
                  buttonname: 'more page'
                }]
              }
            ]
          }
        }
      ]
    };
    agent.add(new Payload(agent.UNSPECIFIED, response, { rawPayload: true, sendAsMessage: true}));
}