首页 文章

实现对话Webhook作为Azure功能应用程序

提问于
浏览
1

我有一个天蓝色的功能应用程序,我用作谷歌助手操作的webhook . 我试图按照文档进行正确的响应,但在测试我的webhook时,我不断在模拟器中收到以下错误 . 我的回复消息中有什么东西看起来不对吗?

无法从http_response解析SDKResponse:

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 451
Content-Type: application/json; charset=utf-8
Content-Encoding: gzip
Expires: -1
Vary: Accept-Encoding
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Sun, 28 May 2017 19:00:13 GMT

{"conversationToken":"cee44ab4-97dd-4e18-99c7-2b8613eb7584","expectUserResponse":true,"expectedInputs":[{"inputPrompt":{"richInitialPrompt":{"items":[{"simpleResponse":{"textToSpeech":"So, you want to become a great swordsman? First, you must learn the proper technique of insult sword fighting. The current difficulty level is Easy. Say 'Tutorial' for some quick instructions. Say 'Start Game' to start the game. Say 'Options' for more options. "}}]}}}]}

这是为了可读性而格式化的json:

{
  "conversationToken": "cee44ab4-97dd-4e18-99c7-2b8613eb7584",
  "expectUserResponse": true,
  "expectedInputs": [
    {
      "inputPrompt": {
        "richInitialPrompt": {
          "items": [
            {
              "simpleResponse": {
                "textToSpeech": "So, you want to become a great swordsman? ... "
              }
            }
          ]
        }
      }
    }
  ]
}

通过我的最新测试,我尝试发送在Fulfillment页面说明中给出的确切示例响应,但它仍然失败:https://developers.google.com/actions/components/fulfillment

{
  "conversationToken": "{\"state\":null,\"data\":{}}",
  "expectUserResponse": true,
  "expectedInputs": [
    {
      "inputPrompt": {
        "richInitialPrompt": {
          "items": [
            {
              "simpleResponse": {
                "textToSpeech": "Howdy! I can tell you fun facts about almost any number, like 42. What do you have in mind?",
                "displayText": "Howdy! I can tell you fun facts about almost any number. What do you have in mind?"
              }
            }
          ],
          "suggestions": []
        }
      },
      "possibleIntents": [ { "intent": "actions.intent.TEXT" } ]
    }
  ]
}

1 回答

  • 1

    看起来您的 items 条目稍有无效 . Item对象被定义为union字段,表示必须设置三个属性之一( simpleResponsebasicCardstructuredResponse )及其各自的值 .

    所以 textToSpeech 属性不应该直接位于 richInitialPrompt.item 之下,而是应该有一个 simpleResponse 属性,在此之下, textToSpeech 属性(或者对于SimpleResponse对象有意义的其他属性之一 . 你必须至少有一个SimpleResponse(它必须是第一个),你可能不会超过两个 .

    但是在这种情况下,你的第二个回复附带的文字没有意义 . 两个响应都将被显示/显示 - 如果用户操作有延迟,则不会显示 .

    v1协议有一种方法可以支持重新提示的细节,但我在v2中看不到相同的东西 .

    所以JSON应该看起来更像:

    {
        "conversationToken": "fa3bfc17-de0a-4df8-900d-44dbb17b86c6",
        "expectUserResponse": true,
        "expectedInputs": [
            {
                "inputPrompt": {
                    "richInitialPrompt": {
                        "items": [
                            "simpleResponse": {
                                "textToSpeech": "Text for my response"  
                            } 
                        ]
                    }
                }
            }
        ]
    }
    

相关问题