public void ProcessIntends(WebhookRequest value, string intentName, ref IAppRequest iRequest, ref string controllerName)
        {
            string entityOrSlot;

            switch (intentName)
            {
            case "companyNews":
                var company = value.QueryResult.Parameters.Fields["companyName"].ToString();
                entityOrSlot = company;
                break;

            case "newsFetch":
                var newsSource = value.QueryResult.Parameters.Fields["newsSource"].ToString();
                entityOrSlot = newsSource;
                break;

            case "stockQuote":
            case "fundamentals":
                var companyName = value.QueryResult.Parameters.Fields["CompanyName"].ToString();
                entityOrSlot = companyName;
                break;

            case "marketSummary":
                entityOrSlot = "";
                break;

            case "recommend":
                entityOrSlot = "";
                break;

            default:
                return;
            }
            ProcessIntends(entityOrSlot, intentName, ref iRequest, ref controllerName);
        }
        public void SetupAPICall(IAppRequest iRequest, string controllerName, out RestClient clinet, out RestRequest request, HttpRequest webRequest)
        {
            controllerName = "/api/" + controllerName;
            var baseURL         = webRequest.Host.ToString();
            var keyUsedToAccess = webRequest.Headers["key"].ToString();

            clinet  = new RestClient("https://" + baseURL);
            request = new RestRequest(controllerName, Method.POST);
            request.AddHeader("key", keyUsedToAccess.IsNullOrWhiteSpace() ? "" : keyUsedToAccess);
            request.AddJsonBody(iRequest);
            return;
        }
        private void ProcessIntends(string entityOrSlot, string intentName, ref IAppRequest iRequest, ref string controllerName)
        {
            switch (intentName)
            {
            case "companyNews":
                controllerName = "companyNews";
                var company = entityOrSlot;
                company  = company.StripSpecialChar();
                iRequest = new CompanyData {
                    CompanyName = company
                };
                break;

            case "newsFetch":
                controllerName = "NewsFetch";
                var newsSource = entityOrSlot;
                newsSource = newsSource.StripSpecialChar();
                iRequest   = new StandardNews {
                    NewsSource = newsSource
                };
                break;

            case "stockQuote":
                controllerName = "StockQuote";
                company        = entityOrSlot.StripSpecialChar();
                iRequest       = new CompanyData {
                    CompanyName = company
                };
                break;

            case "fundamentals":
                controllerName = "Fundamentals";
                company        = entityOrSlot.StripSpecialChar();
                iRequest       = new CompanyData {
                    CompanyName = company
                };
                break;

            case "marketSummary":
                controllerName = "MarketData";
                iRequest       = new MarketData();
                break;

            case "recommend":
                controllerName = "Recommendations";
                iRequest       = new Recommendations();
                break;

            default:
                break;
            }
        }
        private WebhookResponse ProcessWebhookRequests(WebhookRequest value)
        {
            var         intentName     = value.QueryResult.Intent.DisplayName;
            IAppRequest iRequest       = null;
            string      controllerName = "";

            _commonMethods.ProcessIntends(value, intentName, ref iRequest, ref controllerName);
            _commonMethods.SetupAPICall(iRequest, controllerName, out RestClient clinet, out RestRequest request, Request);
            var responseResult = clinet.Execute <AppResponse>(request);

            _logger.LogInformation("Completed service request");
            var response = responseResult.Data;

            if (response != null && response.IsResponseSuccess)
            {
                var returnMsg = response.ResponseData.ConvertAllToASCII();
                returnMsg = CheckAndAddEndOfMessage(returnMsg);
                returnMsg = returnMsg.ConvertAllToASCII();
                var simpleResponses = new Message
                {
                    SimpleResponses = new SimpleResponses(),
                    Platform        = Platform.ActionsOnGoogle
                };
                simpleResponses.SimpleResponses.SimpleResponses_.Add(
                    new SimpleResponse
                {
                    Ssml = returnMsg.ConvertToSSML()
                });
                var returnValue = new WebhookResponse();
                returnValue.FulfillmentMessages.Add(simpleResponses);
                return(returnValue);
            }
            _logger.LogError($"{controllerName} could not process request.\n\tDetails:");
            _logger.LogError($"Input value{value.ToString()}");
            _logger.LogError($"Value sent as parameter to {controllerName}:\n{iRequest}");
            _logger.LogError($"Return value if any:{response}");
            return(new WebhookResponse
            {
                FulfillmentText = Utility.ErrorReturnMsg() + Utility.EndOfCurrentRequest()
            });
        }
        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);
        }
        public void ProcessIntends(SkillRequest skillRequest, ref SkillResponse response, string intentName, ref IAppRequest iRequest, ref string controllerName)
        {
            string entityOrSlot;
            var    intentRequest = skillRequest.Request as IntentRequest;

            switch (intentName)
            {
            case "companyNews":
                var company = intentRequest.Intent.Slots["companyName"].Value;
                entityOrSlot = company;
                break;

            case "newsFetch":
                var newsSource = "google-news";
                var authories  = intentRequest.Intent.Slots["newsSource"].Resolution.Authorities.FirstOrDefault();
                if (authories != null)
                {
                    if (authories.Values.Any())
                    {
                        var source = authories.Values[0].Value.Name;
                        newsSource = source;
                    }
                }
                entityOrSlot = newsSource;
                break;

            case "stockQuote":
            case "fundamentals":
                company      = intentRequest.Intent.Slots["CompanyName"].Value;
                entityOrSlot = company.StripSpecialChar();
                break;

            case "marketSummary":
                entityOrSlot = "";
                break;

            case "recommend":
                entityOrSlot = "";
                break;

            //Unique to Alexa
            case "AMAZON.FallbackIntent":
            case "FallbackIntent":
                var seeker = rnd.Next(fallbackMsgs.Length);
                response = ResponseBuilder.Tell(fallbackMsgs[seeker]);
                response.Response.ShouldEndSession = false;
                return;

            case "AMAZON.CancelIntent":
            case "CancelIntent":
                response = ResponseBuilder.Tell("Okay we'll terminate now!");
                response.Response.ShouldEndSession = true;
                return;

            case "AMAZON.HelpIntent":
            case "HelpIntent":
                var speech = new SsmlOutputSpeech
                {
                    Ssml = helpMsgInSsml
                };
                response = ResponseBuilder.Tell(speech);
                response.Response.ShouldEndSession = false;
                return;

            case "AMAZON.StopIntent":
            case "StopIntent":
            case "AMAZON.NavigateHomeIntent":
            case "NavigateHomeIntent":
            default:
                seeker   = rnd.Next(stopMsgs.Length);
                response = ResponseBuilder.Tell(stopMsgs[seeker]);
                response.Response.ShouldEndSession = true;
                _logger.LogDebug("Ending user session");
                return;
            }
            ProcessIntends(entityOrSlot, intentName, ref iRequest, ref controllerName);
        }