自定义有效负载中的媒体响应(Dialogflow)

时间:2018-03-10 15:28:33

标签: actions-on-google

我试图在自定义有效负载中编写媒体响应代码而没有运气。我肯定做错了但我不知道:)测试时媒体响应没有出现。 (请注意我在英语行动中尝试这一点)。这是JSON代码:

{
  "platform": "google",
  "type": "custom_payload",
  "payload": {
    "google": {
      "richResponse": {
        "items": [
          {
            "mediaResponse": {
              "mediaType": "AUDIO",
              "mediaObjects": [
                {
                  "name": "Exercises",
                  "description": "ex",
                  "largeImage": {
                    "url": "https://firebasestorage.googleapis.com/...",
                    "accessibilityText": "image..."
                  },
                  "contentUrl": "https://firebasestorage.googleapis.com/..."
                }
              ]
            }
          }
        ]
      }
    }
  }
}

更新:

我已将JSON更新为类似的内容。但是我收到一个错误:" API版本2:无法使用' INVALID_ARGUMENT'解析JSON响应字符串。错误:":找不到字段。"

{
"platform":"google",
"type":"custom_payload",
"payload":{
  "google":{
     "richResponse":{
        "items":[
           {
              "simpleResponse":{
                 "textToSpeech":"Hey! Good to see you."
              }
           },
           {
              "mediaResponse":{
                 "mediaType":"AUDIO",
                 "mediaObjects":[
                    {
                       "name":"Exercises",
                       "description":"ex",
                       "largeImage":{
                          "url":"https://firebasestorage...",
                          "accessibilityText":"..."
                       },
                       "contentUrl":"https://firebasestorage.googleapis.com/..."
                    }
                 ]
              }
           }
        ],
        "suggestions":[
           {
              "title":"chips"
           }
        ]
     }
  }

以下是调试信息:

{
 "audioResponse": "//NExAARWG...",
 "conversationToken": "GidzaW11bG...",
 "debugInfo": {
  "agentToAssistantDebug": {
  "agentToAssistantJson": "{\"message\":\"Failed to parse Dialogflow response into AppResponse, exception thrown with message: Empty speech response\",\"apiResponse\":{\"id\":\"cd7204ac-ab80-42aa-9755-6123cbb938a6\",\"timestamp\":\"2018-03-11T09:02:35.827Z\",\"lang\":\"en-us\",\"result\":{},\"status\":{\"code\":200,\"errorType\":\"success\"},\"sessionId\":\"1520758955600\"}}"
},
"assistantToAgentDebug": {
  "assistantToAgentJson": "{\"user\":{\"userId\":\"AA9douaa4XGkqtmcU_EDjPy7PQ_9\",\"locale\":\"en-US\",\"lastSeen\":\"2018-03-11T09:02:09Z\"},\"conversation\":{\"conversationId\":\"1520758955600\",\"type\":\"NEW\"},\"inputs\":[{\"intent\":\"actions.intent.MAIN\",\"rawInputs\":[{\"inputType\":\"VOICE\",\"query\":\"Talk to Zen Coach\"}]}],\"surface\":{\"capabilities\":[{\"name\":\"actions.capability.SCREEN_OUTPUT\"},{\"name\":\"actions.capability.MEDIA_RESPONSE_AUDIO\"},{\"name\":\"actions.capability.WEB_BROWSER\"},{\"name\":\"actions.capability.AUDIO_OUTPUT\"}]},\"isInSandbox\":true,\"availableSurfaces\":[{\"capabilities\":[{\"name\":\"actions.capability.SCREEN_OUTPUT\"},{\"name\":\"actions.capability.AUDIO_OUTPUT\"}]}]}",
  "curlCommand": "curl -v 'https://api.api.ai/api/integrations/google?token=0def1bb6be4b4bf2810ec68bf6f37a6a' -H 'Content-Type: application/json;charset=UTF-8' -H 'Google-Actions-API-Version: 2' -H 'Authorization: eyJhbGciOiJSUzI1NiIsImtpZCI6ImFjMmI2M2ZhZWZjZjgzNjJmNGM1MjhlN2M3ODQzMzg3OTM4NzAxNmIifQ.eyJhdWQiOiJ6ZW4tY29hY2giLCJhenAiOiI0OTYwOTIwOTE1NzEtMGNhY3VtczVkZ3F1OWpkM2k0dHZpOGFiOTVydXQ2NnQuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJleHAiOjE1MjA3NTkwNzUsImlzcyI6Imh0dHBzOi8vYWNjb3VudHMuZ29vZ2xlLmNvbSIsImp0aSI6IjY4NDc0NThhNTNhZGExODAxZjMwMjAyYjkxZGIyODZhMjk1NzA2YmIiLCJpYXQiOjE1MjA3NTg5NTUsIm5iZiI6MTUyMDc1ODY1NX0.e1cqg96F5L-BvD0yJz3UFgsnX_0TRox0Lu8R9K5NhhXcQVfC7mq1QwCqs2DGrUJGquGdW2GhzBU2lzf4ro2TUeieg4ozak1OmiYAMqtiCH0EodeHy59AXXqzb3a35YuD7CmSDu6qVQRfEp8uaaH2t-Sq9lUchudNOgjucip3ex9Rr2XacHm0qWtV69H1o-Yq5INl5HHR0kNqtEIsxUox961imKvDLN5s--F35yTbAhIWibr6OmaACyzSQW5X7OjrJ2781DSmEdYn73poDbuwMS9E2l9B-QTUHAIpUM5b4WqrFkD6XKALdf2pQFwZlRRhDzRiDKWLA-i1w-mcak0LWw'  -A 'Mozilla/5.0 (compatible; Google-Cloud-Functions/2.1; +http://www.google.com/bot.html)' -X POST -d '{\"user\":{\"userId\":\"AA9douaa4XGkqtmcU_EDjPy7PQ_9\",\"locale\":\"en-US\",\"lastSeen\":\"2018-03-11T09:02:09Z\"},\"conversation\":{\"conversationId\":\"1520758955600\",\"type\":\"NEW\"},\"inputs\":[{\"intent\":\"actions.intent.MAIN\",\"rawInputs\":[{\"inputType\":\"VOICE\",\"query\":\"Talk to Zen Coach\"}]}],\"surface\":{\"capabilities\":[{\"name\":\"actions.capability.SCREEN_OUTPUT\"},{\"name\":\"actions.capability.MEDIA_RESPONSE_AUDIO\"},{\"name\":\"actions.capability.WEB_BROWSER\"},{\"name\":\"actions.capability.AUDIO_OUTPUT\"}]},\"isInSandbox\":true,\"availableSurfaces\":[{\"capabilities\":[{\"name\":\"actions.capability.SCREEN_OUTPUT\"},{\"name\":\"actions.capability.AUDIO_OUTPUT\"}]}]}'"
},
"sharedDebugInfo": [
  {
    "name": "ResponseValidation",
    "subDebugEntry": [
      {
        "debugInfo": "API Version 2: Failed to parse JSON response string with 'INVALID_ARGUMENT' error: \": Cannot find field.\".",
        "name": "UnparseableJsonResponse"
      }
    ]
  }
]
},
"response": "Zen coach isn't responding right now. Try again soon.",
"visualResponse": {
"visualElements": []
}
}

2 个答案:

答案 0 :(得分:4)

您是否正在添加"平台":" google"和"键入":" custom_payload"在自定义有效负载?如果是这样,请尝试删除它。

我使用Voice Metronome应用程序完成了以下工作:

{
  "google":{
     "richResponse":{
        "items":[
           {
              "simpleResponse":{
                 "textToSpeech":"Hey! Good to see you."
              }
           },
           {
              "mediaResponse":{
                 "mediaType":"AUDIO",
                 "mediaObjects":[
                    {
                       "name":"Exercises",
                       "description":"ex",
                       "largeImage":{
                          "url":"http://res.freestockphotos.biz/pictures/17/17903-balloons-pv.jpg",
                          "accessibilityText":"..."
                       },
                       "contentUrl":"https://freepd.com/Chill/Chill Air.mp3"
                    }
                 ]
              }
           }
        ],
        "suggestions":[
           {
              "title":"chips"
           }
        ]
     }
  }
}

enter image description here

答案 1 :(得分:1)

问题是firstName属性仍然需要遵循RichResponse对象的规则。其中的第一项必须是SimpleResponse对象。 (我没有测试过,但你可能没有说什么,但是对你的音频进行介绍是一个好地方。)

错误消息richResponse表明它可能还在响应中的顶级对象上查找Failed to parse Dialogflow response into AppResponse, exception thrown with message: Empty speech response参数,这是Dialogflow v1期望复制{{1}的内容} speechsimpleResponse个参数。如果你设置为v2,我不确定为什么会出现这种情况,但听起来有些东西可能会混淆。我会确保你使用的是v1并且你有一个ssml参数。

另请注意,reviewers will look for suggestion chips有关如何在音频期间或之后向前移动对话,如果这不是最终回复的话。