Exemple #1
0
        public void ParseEventRequest()
        {
            var json    = @"{
  ""version"": ""1.0"",
  ""session"": {
    ""new"": false,
    ""sessionAttributes"": {},
    ""sessionId"": ""a29cfead-c5ba-474d-8745-6c1a6625f0c5"",
    ""user"": {
      ""userId"": ""U399a1e08a8d474521fc4bbd8c7b4148f"",
      ""accessToken"": ""XHapQasdfsdfFsdfasdflQQ7""
    }
  },
  ""context"": {
    ""System"": {
      ""application"": {
        ""applicationId"": ""com.yourdomain.extension.pizzabot""
      },
      ""user"": {
        ""userId"": ""U399a1e08a8d474521fc4bbd8c7b4148f"",
        ""accessToken"": ""XHapQasdfsdfFsdfasdflQQ7""
      },
      ""device"": {
        ""deviceId"": ""096e6b27-1717-33e9-b0a7-510a48658a9b"",
        ""display"": {
          ""size"": ""l100"",
          ""orientation"": ""landscape"",
          ""dpi"": 96,
          ""contentLayer"": {
            ""width"": 640,
            ""height"": 360
          }
        }
      }
    }
  },
  ""request"": {
    ""type"": ""EventRequest"",
    ""requestId"": ""f09874hiudf-sdf-4wku-flksdjfo4hjsdf"",
    ""timestamp"": ""2018-06-11T09:19:23Z"",
    ""event"" : {
      ""namespace"":""ClovaSkill"",
      ""name"":""SkillEnabled"",
      ""payload"": null
    }
  }
}";
            var request = ClovaRequest.FromJson(json);

            Assert.Equal(RequestType.EventRequest, request.RequestType);
            var eventRequest = request.Request.ToObject <EventRequest>();

            Assert.Equal("f09874hiudf-sdf-4wku-flksdjfo4hjsdf", eventRequest.RequestId);
            Assert.Equal("2018-06-11T09:19:23Z", eventRequest.Timestamp);

            Assert.Equal("ClovaSkill", eventRequest.Event.Namespace);
            Assert.Equal("SkillEnabled", eventRequest.Event.Name);
            Assert.Null(eventRequest.Event.Payload);
        }
Exemple #2
0
        public void ParseIntentRequest()
        {
            var json    = @"{
  ""version"": ""1.0"",
  ""session"": {
    ""new"": false,
    ""sessionAttributes"": {},
    ""sessionId"": ""a29cfead-c5ba-474d-8745-6c1a6625f0c5"",
    ""user"": {
      ""userId"": ""U399a1e08a8d474521fc4bbd8c7b4148f"",
      ""accessToken"": ""XHapQasdfsdfFsdfasdflQQ7""
    }
  },
  ""context"": {
    ""System"": {
      ""application"": {
        ""applicationId"": ""com.yourdomain.extension.pizzabot""
      },
      ""user"": {
        ""userId"": ""U399a1e08a8d474521fc4bbd8c7b4148f"",
        ""accessToken"": ""XHapQasdfsdfFsdfasdflQQ7""
      },
      ""device"": {
        ""deviceId"": ""096e6b27-1717-33e9-b0a7-510a48658a9b"",
        ""display"": {
          ""size"": ""l100"",
          ""orientation"": ""landscape"",
          ""dpi"": 96,
          ""contentLayer"": {
            ""width"": 640,
            ""height"": 360
          }
        }
      }
    }
  },
  ""request"": {
    ""type"": ""IntentRequest"",
    ""intent"": {
      ""name"": ""OrderPizza"",
      ""slots"": {
        ""pizzaType"": {
          ""name"": ""pizzaType"",
          ""value"": ""ペパロニ""
        }
      }
    }
  }
}";
            var request = ClovaRequest.FromJson(json);

            Assert.Equal(RequestType.IntentRequest, request.RequestType);
            var intentRequest = request.Request.ToObject <IntentRequest>();

            Assert.Equal("OrderPizza", intentRequest.Intent.Name);
            Assert.Equal("pizzaType", intentRequest.Intent.Slots["pizzaType"].Name);
            Assert.Equal("ペパロニ", intentRequest.Intent.Slots["pizzaType"].Value);
        }
Exemple #3
0
        public void ParseLaunchRequest()
        {
            var json    = @"{
  ""version"": ""1.0"",
  ""session"": {
    ""new"": true,
    ""sessionAttributes"": {},
    ""sessionId"": ""a29cfead-c5ba-474d-8745-6c1a6625f0c5"",
    ""user"": {
      ""userId"": ""U399a1e08a8d474521fc4bbd8c7b4148f"",
      ""accessToken"": ""XHapQasdfsdfFsdfasdflQQ7""
    }
  },
  ""context"": {
    ""System"": {
      ""application"": {
        ""applicationId"": ""com.yourdomain.extension.pizzabot""
      },
      ""user"": {
        ""userId"": ""U399a1e08a8d474521fc4bbd8c7b4148f"",
        ""accessToken"": ""XHapQasdfsdfFsdfasdflQQ7""
      },
      ""device"": {
        ""deviceId"": ""096e6b27-1717-33e9-b0a7-510a48658a9b"",
        ""display"": {
          ""size"": ""l100"",
          ""orientation"": ""landscape"",
          ""dpi"": 96,
          ""contentLayer"": {
            ""width"": 640,
            ""height"": 360
          }
        }
      }
    }
  },
  ""request"": {
    ""type"": ""LaunchRequest""
  }
}";
            var request = ClovaRequest.FromJson(json);

            Assert.Equal(RequestType.LaunchRequest, request.RequestType);
        }
Exemple #4
0
        public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest httpRequest, ILogger log)
        {
            var s    = new StreamReader(httpRequest.Body);
            var json = s.ReadToEnd();

            log.LogInformation(json);
            var req = ClovaRequest.FromJson(json);

            if (req.RequestType == RequestType.IntentRequest)
            {
                var intentRequest = req.Request.ToObject <IntentRequest>();
                switch (intentRequest.Intent.Name)
                {
                case "ThrowDiceIntent":
                    return(CreateSimpleTextResponse($"サイコロを1個投げます。結果は{Random.Next(1, 7)}です。", true));

                default:
                    return(CreateSimpleTextResponse("すいません。よくわかりません。サイコロを振ってと話しかけてください。"));
                }
            }

            if (req.RequestType == RequestType.LaunchRequest)
            {
                return(CreateSimpleTextResponse("こんにちは。サイコロを振ってと話しかけてください。"));
            }

            if (req.RequestType == RequestType.SessionEndedRequest)
            {
                return(CreateSimpleTextResponse("さようなら。"));
            }

            if (req.RequestType == RequestType.EventRequest)
            {
                return(CreateSimpleTextResponse("すいません。イベントには対応していません。"));
            }

            throw new InvalidOperationException();
        }