问题与Dialogflow API WebhookResponse V2 for Actions for Google

时间:2017-12-13 16:25:56

标签: sinatra dialogflow google-assistant-sdk google-assist-api

我正在测试Actions for Google,所以我创建了一个简单的Sinatra应用程序,它看起来像:

    require 'sinatra'
    require 'json'

    post '/google_assistant_api' do
      content_type :json

      case intent_name
      when "input_welcome"
        decorated_response
      when "Recipe name"
        basic_card
      end
    end

    private

      def decorated_response
        {
          source: "test source",
          speech: "speech",
          display_text: "something"
        }.to_json
      end

      def intent_name
        parsed_request["queryResult"]["intent"]["displayName"]
      end

      def parsed_request
        @parsed_request ||= JSON.parse(request.body.read)
      end

      def basic_card
       {
         "fulfillmentText": "ACTIONS_ON_GOOGLE",
         "fulfillmentMessages": [
           {
             "platform": "PLATFORM_UNSPECIFIED",
             "text": {
               "text": [
                 "string text"
               ]
             },
             "image": {
               "imageUri": "https://avatars3.githubusercontent.com/u/119195?
s=400&v=4"
             },
             "basicCard": {
               "title": "title string",
               "subtitle": "subtitle",
               "formattedText": "formatted text",
               "image": {
                 "imageUri": "https://avatars3.githubusercontent.com/u/119195"
               },
               "buttons": []
             }
           }
         ],
         "source": "source string"
       }.to_json
      end

请注意,我使用API​​的V2并使用google助手进行测试:

enter image description here

我尝试了很多基于https://gist.github.com/manniru/f52af230669bd3ed2e69ffe4a76ab309的其他响应格式而没有运气。我一直在说:

Sorry! there was no response from the Agent. Please try later.

enter image description here

有没有人试过非nodejs运气回应?我很感激任何样本回复,因为简单的回答似乎有效,但至于basic card我没有运气。

1 个答案:

答案 0 :(得分:1)

Dialogflow的v2 API对webhook请求和响应使用不同的格式,此处记录:

  1. Dialogflow v2 Webhook Request
  2. Dialogflow v2 Webhook Response
  3. 您的代码似乎正在使用old format