我正在嘗試使用 Java DialogFlow API 為 Google Assistant 構建 webhook 響應。我的響應在 DialogFlow 的“立即嘗試”功能中運行良好,但 Google 智能助理一直說“現在沒有響應。稍后再試”。作為一項實驗,我設法通過使用非 webhook 響應(即通過正常的 DialogFlow Intent UI)讓 Google Assistant 工作。當我查看我的歷史記錄時,我看到工作響應如下所示:"queryText": "GOOGLE_ASSISTANT_WELCOME", "action": "input.welcome", "fulfillmentMessages": [ { "text": { "text": [ "[{\"type\":\"simple_response\",\"platform\":\"google\",\"textToSpeech\":\"Hello\"}]" ] } }這對我來說似乎很奇怪,因為文本正文實際上是一個進一步的 JSON 編碼對象(在其他字段中包含 textToSpeech)。當我像這樣使用 Java DialogFlow API 時:List<String> texts = new ArrayList<>();texts.add( "Foo" );message.setText( new GoogleCloudDialogflowV2IntentMessageText().setText( texts ));我得到一種不同的格式: "fulfillmentMessages": [ { "text": { "text": [ "Foo" ] } }谷歌助理說:MalformedResponse: Failed to parse Dialogflow response into AppResponse because of empty speech response"即使我嘗試強制將編碼的 JSON 字符串作為我的文本正文,它似乎仍然不起作用。返回默認消息格式以便 Google 智能助理可以閱讀的正確方法是什么?我試過simpleResponse了,但也沒用
1 回答

holdtom
TA貢獻1805條經驗 獲得超10個贊
以下是聽到響應所需的最低響應
{
"payload": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Welcome! Do you want me to change color or pause spinning? You can also tell me to ask you later."
}
}
]
}
}
}
}
當然,對于 java,您可以使用 API 來生成所需的輸出響應。另外,如果您將 basicCards 或圖像用于智能顯示,那么使用 API 肯定會有更多幫助。您還可以檢查模擬器的響應。
添加回答
舉報
0/150
提交
取消