简体   繁体   English

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

[英]keeping-data-between-intents-from-webhook-in-dialogflow II

My question is very similar to this one Keeping data between intents from WebHook in Dialogflow answer by @prisioner But unlike the original one, I am already using context in my c# web API v2 implementation, in my context I set an attribute that store the current episode my action is playing (it is kind of media player), so the first time my action gets invoked, we randomly pick an episode to play, I added a next and previous followup intents that are using the previously set context with lifespan of 5 (just to be on the safe side) 我的问题是非常相似,这一个从网络挂接在Dialogflow保持意图之间的数据通过回答@prisioner但不同的是原来的,我已经在我的C#使用上下文web API v2实现,在我的方面,我设置存储当前的属性我的动作正在播放情节(这是一种媒体播放器),因此,当我的动作第一次被调用时,我们随机选择一个情节来播放,我添加了下一个和上一个后续意图,它们使用的是先前设置的上下文,寿命为5 (只是为了安全起见)

I try to include #context.episdeId as part of my intent request parameters, but that returns a 500 error , but as soon as I remove that request parameter the request is executed, however, my context is empty in my followup intents. 我尝试将#context.episdeId包含在我的意向请求参数中,但这会返回500 error ,但是一旦删除该请求参数,请求便会执行,但是,我的后续意向中的上下文为空。

this is how my response to the first intent looks like. 这就是我对第一个意图的回应。

{
  "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
      }
    }
  ]
}

But, in my followup (next) intent, this is what my endpoint gets, check how the same sessionId it is been used. 但是,按照我的后续(下一个)意图,这就是我的端点得到的结果,请检查如何使用相同的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
}

Thanks for the quick reply @prisoner here you can find the screenshot https://i.imgur.com/JwWFNma.png 感谢@prisoner的快速回复,您可以在此处找到屏幕截图https://i.imgur.com/JwWFNma.png

Using https://www.mockable.io as my new end point and returning a predefined response that will set the output context, I was able to see that the error was on my web API class mapping, to verify that, I read the raw request on my end point using something like this. 使用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();

Then I just de-serialize the rawRequest object. 然后,我只反序列化rawRequest对象。

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

I am posting this just in case somebody else runs into the same situation. 我发布此消息是为了防止其他人遇到相同的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM