コード例 #1
0
        private SkillResponse ParseIntents(SkillRequest skillRequest)
        {
            SkillResponse skillResponse  = null;
            var           intentRequest  = skillRequest.Request as IntentRequest;
            var           intentName     = intentRequest.Intent.Name;
            IAppRequest   iRequest       = null;
            string        controllerName = "";

            _commonMethods.ProcessIntends(skillRequest, ref skillResponse, intentName, ref iRequest, ref controllerName);
            if (skillResponse != null)
            {
                skillResponse.SessionAttributes = skillRequest.Session.Attributes;
                return(skillResponse);
            }
            _commonMethods.SetupAPICall(iRequest, controllerName, out RestClient clinet, out RestRequest request, Request);
            var response = clinet.Execute <AppResponse>(request).Data;

            if (response != null && response.IsResponseSuccess)
            {
                var returnMsg = response.ResponseData.ConvertAllToASCII();
                returnMsg = CheckAndAddEndOfMessage(returnMsg);
                returnMsg = returnMsg.ConvertToSSML();
                var speech = new SsmlOutputSpeech
                {
                    Ssml = returnMsg
                };
                skillResponse = ResponseBuilder.Tell(speech, skillRequest.Session);
                skillResponse.Response.ShouldEndSession = response.ShouldEndSession;
            }
            else
            {
                _logger.LogError("Error while parsing  request:");
                _logger.LogError(skillRequest.ToString());
                skillResponse = ErrorRequestHandler(intentName);
                skillResponse.SessionAttributes = skillRequest.Session.Attributes;
            }
            return(skillResponse);
        }