没有建议筹码

No suggestions chips

我在 dialogflow 上使用 webhook 时遇到此错误。我也没有看到筹码。但是正常的文本来了。所有其他的东西和匹配的意图和参数都很好用。

关于如何解决这个问题有什么建议吗?

MalformedResponse expected_inputs[0].input_prompt.rich_initial_prompt: 'item[2]' must not be empty.
MalformedResponse expected_inputs[0].input_prompt.rich_initial_prompt: 'item[3]' must not be empty.
MalformedResponse expected_inputs[0].input_prompt.rich_initial_prompt: 'item[4]' must not be empty.
MalformedResponse expected_inputs[0].input_prompt.rich_initial_prompt: 'item[5]' must not be empty.

这是我的代码。

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));

function convert(agent) {
let conv = agent.conv();

let toConvert = conv.parameters["convert"]


if (toConvert.length > 60) {
    conv.ask(`To long`)
} else {
    conv.ask(`"${toConvert}" secret ${textConvert(toConvert)} secret`)
    conv.ask(`Secret`)
}


conv.ask(new Suggestion(`text`))
conv.ask(new Suggestion(`text`))
conv.ask(new Suggestion(`1`))
conv.ask(new Suggestion(`Secret`))

agent.add(conv); 


}



let intentMap = new Map();
intentMap.set('Convert', convert)

agent.handleRequest(intentMap);

Suggestions 对象应该是要询问的文本建议数组。您不应该(也不能)发送多个 Suggestions 对象。

因此您的代码应该更像这样:

conv.ask( new Suggestions([
  `text`,
  `text`,
  `1`,
  `secret`
]);

碰巧您使用的是以前的 SDK,文档中已经提到它已被弃用,您应该做的第一件事是将代码迁移到新的 AoG SDK。您可以在此处找到迁移指南:

Migration Guide

然后,您可以使用新库来处理建议纸片,这应该可以解决您的问题:

conv.ask(new Suggestions(['suggestion 1', 'suggestion 2']));

别忘了看看图书馆:

Suggestion Chip v2