Example #1
0
        private static APIAIRequestResult FulfillAction(APIAIRequestResult requestResult, AIResponse responce)
        {
            requestResult.ActionIncomplete = responce.Result.ActionIncomplete;

            switch (responce.Result.Action)
            {
            case "save.address":
                requestResult.Action = Actions.AddressSave;
                return(requestResult);

            case "save.city":
                requestResult.Action = Actions.CitySave;
                return(requestResult);

            default:
                requestResult.Action = Actions.None;
                return(requestResult);
            }
        }
Example #2
0
        public APIAIRequestResult TryRecogniseAddress(string message)
        {
            AIResponse         responce      = _provider.GetConfiguredProvider().TextRequest(message);
            APIAIRequestResult requestResult = new APIAIRequestResult();

            requestResult = FulfillAction(requestResult, responce);

            if (!requestResult.ActionIncomplete)
            {
                requestResult.RecognitionStatus = RecognitionStatus.Valid;

                if (requestResult.Action == Actions.AddressSave)
                {
                    requestResult.Address       = responce.Result.Parameters.FirstOrDefault(p => p.Key == ADDRESS_PARAMETER_KEY).Value.ToString();
                    requestResult.TravelingType = responce.Result.Parameters.FirstOrDefault(p => p.Key == TRAVELING_TYPE).Value.ToString();
                }

                else if (requestResult.Action == Actions.CitySave)
                {
                    requestResult.City          = responce.Result.Parameters.FirstOrDefault(p => p.Key == GEOCITY_PARAMETER_KEY).Value.ToString();
                    requestResult.TravelingType = responce.Result.Parameters.FirstOrDefault(p => p.Key == TRAVELING_TYPE).Value.ToString();
                }
                else
                {
                    requestResult.QuestionToAsk     = responce.Result.Fulfillment.Speech;
                    requestResult.RecognitionStatus = RecognitionStatus.Invalid;
                }
            }
            else
            {
                requestResult.RecognitionStatus = RecognitionStatus.AddressMissing;
                requestResult.QuestionToAsk     = responce.Result.Fulfillment.Speech;
            }

            return(requestResult);
        }