在 Dialogflow webhook 中使用 SSML 时询问

Asking while using SSML in Dialogflow webhook

我正在尝试通过 DialogFlow 在 Google Agent 上构建一个 Actions,但在包含 ssml 的情况下尝试向用户提问时总是出现错误。

我已经在 DialogFlow 上构建了代理,使用 fulfillment webhook 实现了逻辑(通过节点模块 dialogflow-fulfillment 实现)并且已经能够使用右侧 DialogFlow 的测试控制台在 DialogFlow 上成功测试.

因此,我将 DialogFlow Integrations 连接到 Google Assistant。

我第一次尝试失败:

const client = new WebhookClient({ req, res });
let qToSnd = 'Hi <break time=\"500ms\"/> Can I help you?';
let conv = client.conv();
conv.ask(qToSnd);
client.add(conv);

上面的方法可行(不会出错)但会导致在说出 <break> 标签时提出问题。

我也试过:

conv.ask(
  new Text({
    text: _stripTags(qToSnd),
    ssml: qToSnd
}));

但是,当我在 Google 模拟器上使用 Actions 对此进行测试时,我收到错误消息:

[Agent] isn't responding right now. Try again soon.

深入查看日志查看器显示以下错误消息:

MalformedResponse: ErrorId: ... Failed to parse Dialogflow response into AppResponse because of invalid platform response. : Could not find a RichResponse or SystemIntent in the platform response for agentId: ... and intentId: ...

我的成就 API 回来了:

{
  "payload": {
    "google": {
      "expectUserResponse": true,
      "richResponse": {
        "items": [
          {
            "text": "Hi - Can I help you?",
            "ssml": "Hi <break time=\"500ms\"/> Can I help you?"
          }
        ]
      }
    }
  }
}

我将不胜感激任何正确方向的指示。

查看 JSON 片段以获取 the documentation 中的简单响应,您应该将您的项目包装在 simpleResponse 元素中。此外,您用于文本和音频响应的键不正确,应该是 textToSpeechdisplayText.

{
  "payload": {
    "google": {
      "expectUserResponse": true,
      "richResponse": {
        "items": [
          {
            "simpleResponse": {
              "textToSpeech": "Howdy, this is GeekNum. I can tell you fun facts about almost any number, my favorite is 42. What number do you have in mind?",
              "displayText": "Howdy! I can tell you fun facts about almost any number. What do you have in mind?"
            }
          }
        ]
      }
    }
  }
}

受下面@NickFelker 的回答的启发并对该主题进行了更多研究,我能够通过确保添加 <speak> 标签来使 SSML 正常工作。所以这有效:

const client = new WebhookClient({ req, res });
let qToSnd = 'Hi <break time=\"500ms\"/> Can I help you?';
let conv = client.conv();
conv.ask('<speak>' + qToSnd + '</speak>');
client.add(conv);

实现APIreturns:

{
  "payload": {
    "google": {
      "expectUserResponse": true,
      "richResponse": {
        "items": [
          {
              "simpleResponse": {
                  "textToSpeech": "<speak>Hi <break time=\"500ms\"/> Can I help you</speak>"
              }
          }
        ]
      }
    }
  }
}