【问题标题】:Having an issue with Dialogflow API WebhookResponse V2 for Actions for GoogleDialogflow API WebhookResponse V2 for Actions for Google 出现问题
【发布时间】:2018-05-27 15:06:31
【问题描述】:

我正在测试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 并使用谷歌助手进行测试:

我尝试了许多其他基于https://gist.github.com/manniru/f52af230669bd3ed2e69ffe4a76ab309 的响应格式,但没有成功。我不断得到:

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

有没有人幸运地尝试过非 nodejs 响应?我将不胜感激任何示例响应,因为简单的响应似乎有效,但是至于 basic card 我没有运气。

【问题讨论】:

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


    【解决方案1】:

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

    1. Dialogflow v2 Webhook Request
    2. Dialogflow v2 Webhook Response

    您的代码似乎正在使用old format

    【讨论】:

    • 谢谢,回复部分的问题。我使用了官方文档中描述的响应,但仍然遇到同样的问题。我用gist.github.com/eqbal/311e775946543ad25319ce9a64578da6。您尝试过任何有效的示例响应吗?
    • 请使用您在要点中引用的 v2 回复更新您的问题。您需要将 platformPLATFORM_UNSPECIFIED 更改为 ACTIONS_ON_GOOGLE ,如此处所述 [0] 才能使用 Google 助理。您还需要使用此处描述的 Google 响应 [1] 上的操作,其中包括 simpleResponsesbasicCardsuggestionslinkOutSuggestionlistSelectcarouselSelect。 [0]dialogflow.com/docs/reference/api-v2/rest/v2beta1/…[1]dialogflow.com/docs/reference/api-v2/rest/v2beta1/…
    • 感谢您在这里的详细回复。我更新了platform,但我仍然得到相同的回复。该操作触发了 webhook api,但看起来它永远不会到达 dialogflow。您是否有示例工作示例,以便我可以用作起点?
    • 我遇到了类似的问题(请参阅 stackoverflow.com/questions/48211405/…),根据我的错误消息“不能查找字段:消息 google.cloud.dialogflow.v2beta1.WebhookResponse 中的语音”。你 (@matthewayne) 能对此有所了解吗?
    猜你喜欢
    • 1970-01-01
    • 2011-03-14
    • 2017-06-20
    • 1970-01-01
    • 1970-01-01
    • 2019-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多