Exemple #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            CEKResponse response = null;;

            if (req.Headers.TryGetValue("SignatureCEK", out var signature))
            {
                var client  = new ClovaClient();
                var request = await client.GetRequest(signature, req.Body);

                // IntentRequestのみここにくる
                if (request.Request.Type == RequestType.IntentRequest)
                {
                    // メイン処理
                    var result = IntentHandler.Handle(request.Request.Intent.Name);
                    response = result.GetClovaResponse();
                }
                else
                {
                    // エラー
                    response = new CEKResponse();
                    response.AddText("よくわかりませんでしたが、たぶんラッキーな1日になると思いますよ。");
                    response.ShouldEndSession = true;
                }
            }
            else
            {
                // エラー
                response = new CEKResponse();
                response.AddText("よくわかりませんでしたが、きっと大丈夫ですよ。");
                response.ShouldEndSession = true;
            }
            return(new OkObjectResult(response));
        }
Exemple #2
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            var json = await req.ReadAsStringAsync();

            var           skillRequest = JsonConvert.DeserializeObject <SkillRequest>(json);
            SkillResponse response     = null;

            if (await ValidateRequest(req, log, skillRequest))
            {
                // IntentRequestのみここにくる
                if (skillRequest.Request is IntentRequest intentRequest)
                {
                    // メイン処理
                    var result = IntentHandler.Handle(intentRequest.Intent.Name);
                    response = result.GetAlexaResponse();
                }
                else
                {
                    // エラー
                    response = new SkillResponse()
                    {
                        Version  = "1.0",
                        Response = new ResponseBody()
                        {
                            OutputSpeech = new PlainTextOutputSpeech {
                                Text = "よくわかりませんでしたが、たぶんラッキーな1日になると思いますよ。"
                            },
                            ShouldEndSession = true
                        }
                    };
                }
            }
            else
            {
                // エラー
                response = new SkillResponse()
                {
                    Version  = "1.0",
                    Response = new ResponseBody()
                    {
                        OutputSpeech = new PlainTextOutputSpeech {
                            Text = "よくわかりませんでしたが、きっと大丈夫ですよ。"
                        },
                        ShouldEndSession = true
                    }
                };
            }
            return(new OkObjectResult(response));
        }
Exemple #3
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            var             parser         = new JsonParser(JsonParser.Settings.Default.WithIgnoreUnknownFields(true));
            var             webhookRequest = parser.Parse <WebhookRequest>(await req.ReadAsStringAsync());
            WebhookResponse response       = null;

            if (webhookRequest.QueryResult.Intent.DisplayName != "input.welcome")
            {
                // メイン処理
                var result = IntentHandler.Handle(webhookRequest.QueryResult.Intent.DisplayName);
                response = result.GetGoogleResponse();
            }
            else
            {
                // エラー
                response = new WebhookResponse();
                response.FulfillmentText = "よくわかりませんでしたが、きっと大丈夫ですよ。";
            }

            return(new ProtcolBufJsonResult(response, JsonFormatter.Default));
        }