2017-08-09 88 views
1

我的機器人想通過API.AI向Google智能助理髮送輪播。我的理解是,我需要把它們放在裏面data - >google,如:如何通過API.AI發送傳送帶?

{ 
    "data": { 
     "google": { 
      "expectUserResponse": true, 
      "isSsml": false, 
      "expectedInputs": [ 
       { 
        "inputPrompt": { 
         "richInitialPrompt": { 
          "items": [ 
           { 
            "simpleResponse": { 
             "textToSpeech": "Hello World" 
            } 
           } 
          ] 
         } 
        }, 
        "possibleIntents": [ 
         { 
          "intent": "actions.intent.OPTION", 
          "inputValueData": { 
           "@type": "type.googleapis.com/google.actions.v2.OptionValueSpec", 
           "carouselSelect": { 
            "items": [ 
             { 
              "optionInfo": {"key": "FOO", "synonyms": ["foo"]}, 
              "title": "Foo", 
              "image": {"url": "http://example.com/", "accessibilityText": "Foo"} 
             }, 
             { 
              "optionInfo": {"key": "BAR", "synonyms": ["bar"]}, 
              "title": "Bar", 
              "image": {"url": "http://example.com/", "accessibilityText": "Bar"} 
             } 
            ] 
           } 
          } 
         } 
        ] 
       } 
      ] 
     } 
    } 
} 

但它不工作。什麼是正確的格式?

+0

你是什麼意思「不起作用」?你是否收到任何錯誤或其他? – Prisoner

回答

2

如果您正在通過模擬器進行測試,應該出現一個驗證錯誤,該錯誤至少會爲您提供一些關於缺失的指導。如果你甚至沒有得到,那麼除了data.google對象之外的其他部件可能會有問題,這樣api.ai就會出現問題。

有一些事情,一眼就可能是問題。你不能在api.ai響應中粘貼對話webhook響應。見https://developers.google.com/actions/apiai/webhook#response的文檔,但這裏有幾件事情,我看這可能是問題

  • expectedInputs屬性不應該存在。
  • data.google.expectedInputs.possibleIntents屬性應該是在data.google.systemIntent
  • 您仍然需要提供api.ai領域,如基本speech財產
  • data.google.expectedInputs.inputPrompt.richInitialPrompt將在

下面是一些的JSON適用於我:


{ 
    "speech": "Hello", 
    "contextOut": [ 
     { 
      "name": "_actions_on_google_", 
      "lifespan": 100, 
      "parameters": {} 
     } 
    ], 
    "data": { 
     "google": { 
      "expectUserResponse": true, 
      "richResponse": { 
       "items": [ 
        { 
         "simpleResponse": { 
          "textToSpeech": "Hello" 
         } 
        } 
       ], 
       "suggestions": [] 
      }, 
      "systemIntent": { 
       "intent": "actions.intent.OPTION", 
       "data": { 
        "@type": "type.googleapis.com/google.actions.v2.OptionValueSpec", 
        "carouselSelect": { 
         "items": [ 
          { 
           "title": "Foo", 
           "image": { 
            "url": "http://example.com/foo.jpg", 
            "accessibilityText": "Foo title" 
           }, 
           "optionInfo": { 
            "key": "foo-key", 
            "synonyms": [ 
             "foo-alt-1", 
             "foo-alt-2" 
            ] 
           } 
          }, 
          { 
           "title": "Bar", 
           "image": { 
            "url": "http://example.com/bar.jpg", 
            "accessibilityText": "Bar title" 
           }, 
           "optionInfo": { 
            "key": "bar-key", 
            "synonyms": [ 
             "bar-alt-1", 
             "bar-alt-2" 
            ] 
           } 
          } 
         ] 
        } 
       } 
      } 
     } 
    } 
}