将数据从Webhook的意图之间保持在对话流II中

时间:2019-07-04 17:48:17

标签: android-intent dialogflow webhooks

我的问题与Keeping data between intents from WebHook in Dialogflow的这个@prisioner答案非常相似 但是,与原始版本不同,我已经在c#web API v2实现中使用了上下文,在上下文中,我设置了一个属性,该属性存储了动作正在播放的当前情节(它是一种媒体播放器),因此是第一次我的动作被调用,我们随机选择要播放的情节,我添加了下一个和上一个后续意图,这些意图使用的是先前设置的上下文,寿命为5(出于安全考虑)

我尝试将#context.episdeId包含在我的意图请求参数中,但这会返回500 error,但是一旦删除该请求参数,该请求就会被执行,但是,我的上下文在我的追踪意图。

这是我对第一个意图的回应。

{
  "Payload": {
    "google": {
      "richResponse": {
        "Items": [
          {
            "simpleResponse": {
              "TextToSpeech": "Playing episode",
              "DisplayText": "Playing episode 123"
            }
          },
          {
            "mediaResponse": {
              "mediaType": "AUDIO",
              "mediaObjects": [
                {
                  "Name": "Playing episode 123",
                  "Description": "Image from Episode 123",
                  "LargeImage": {
                    "url": "https://mydomain/640x480.jpg",
                    "accessibilityText": "Image from episode 123"
                  },
                  "ContentUrl": "https://mydomain/epidode123.mp3"
                }
              ]
            }
          }
        ]
      }
    }
  },
  "OutputContexts": [
    {
      "Name": "projects/{projectId}/agent/sessions/2d2851bc-fc56-d7dc-c18a-588d42a77360/contexts/playerstarter-followup",
      "LifespanCount": 5,
      "Parameters": {
        "playerTypeOriginal": null,
        "playerType": null,
        "playerType1Original": null,
        "playerType1": null,
        "episodeIdOriginal": 761198,
        "episodeId": 761198,
        "showIdOriginal": 0,
        "showId": 378
      }
    }
  ]
}

但是,按照我的后续(下一个)意图,这就是我的端点得到的结果,请检查如何使用相同的sessionId。

{
  "QueryResult": {
    "QueryText": "next",
    "Parameters": {
      "PlayerType": null,
      "PlayerType1": null,
      "ShowId": 378,
      "EpisodeId": 0
    },
    "AllRequiredParamsPresent": true,
    "Intent": {
      "Name": "projects/{projectId}/agent/intents/66f12b74-93cc-450e-9ca2-0b119c5674ea",
      "DisplayName": "player.starter - next"
    },
    "IntentDetectionConfidence": 1,
    "LanguageCode": "en",
    "OutputContexts": [
      {
        "Name": "projects/{projectId}/agent/sessions/2d2851bc-fc56-d7dc-c18a-588d42a77360/contexts/playerstarter-followup",
        "LifespanCount": 5,
        "Parameters": {
          "playerTypeOriginal": "",
          "playerType": "previous",
          "playerType1Original": "",
          "playerType1": "",
          "episodeIdOriginal": 0,
          "episodeId": 0,
          "showIdOriginal": 0,
          "showId": 378
        }
      }
    ]
  },
  "ResponseId": "8088377a-c297-49a2-bb7e-c3a60a4c2e07-68e175c7",
  "Session": "projects/testing-c58c3/agent/sessions/2d2851bc-fc56-d7dc-c18a-588d42a77360",
  "IsMinistryAction": false,
  "EpisodeId": 0
}

感谢@prisoner的快速回复,您可以在https://i.imgur.com/JwWFNma.png屏幕截图中找到

1 个答案:

答案 0 :(得分:0)

使用https://www.mockable.io作为我的新终点,并返回将设置输出上下文的预定义响应,我能够看到错误出在我的Web API类映射上,以验证是否已阅读原始内容像这样在我的终点请求。

    //Getting the raw request
    var bodyStream = new StreamReader(HttpContext.Current.Request.InputStream);
    bodyStream.BaseStream.Seek(0, SeekOrigin.Begin);
    var rawRequest = bodyStream.ReadToEnd();

然后我只是反序列化rawRequest对象。

    var requestJobj = JsonConvert.DeserializeObject<GoogleHomeRequest>(rawRequest);

我发布此消息是为了防止其他人遇到相同的情况。