在Dialogflow Webhook中使用SSML时询问

时间:2019-06-09 04:30:37

标签: actions-on-google

我正在尝试通过DialogFlow在Google Agent上构建操作,并在尝试向用户询问包含ssml的问题时不断出错。

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

因此,我将DialogFlow集成连接到了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模拟器上的操作进行测试时,收到错误消息:

  

[Agent]目前没有回应。请稍后重试。

浏览日志查看器将显示以下错误消息:

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?"
          }
        ]
      }
    }
  }
}

我会感激任何正确方向的指点。

2 个答案:

答案 0 :(得分:0)

the documentation中查看JSON代码片段中的简单响应,您应该将项目包装在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?"
            }
          }
        ]
      }
    }
  }
}

答案 1 :(得分:0)

受到@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);

履行API返回:

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