public async void GetApplicationAnswerSaludarTest()
        {
            luisClient.GetUserIntent(Arg.Any <string>())
            .Returns(x => Task.FromResult(new IntentionResult {
                Intention = Intention.Saludar, Telefono = null
            }));

            var result = await conversationService.GetApplicationAnswer("hola");

            Assert.AreEqual(Message.HelloMessage, result);
        }
Esempio n. 2
0
        public async Task <string> GetApplicationAnswer(string message)
        {
            try
            {
                var intentionResult = await luisClient.GetUserIntent(message);

                if (intentionResult.Telefono != null)
                {
                    var telefono = intentionResult.Telefono.Replace("-", "").Replace(" ", "");
                    var success  = long.TryParse(telefono, out long numeroTelefono);
                    if (!success)
                    {
                        return(Message.InvalidPhoneNumberMessage);
                    }
                    else
                    {
                        phoneCallClient.MakePhoneCall(numeroTelefono);
                        return(Message.CallingMessage);
                    }
                }

                switch (intentionResult.Intention)
                {
                case Intention.Saludar:
                    return(Message.HelloMessage);

                case Intention.Terminar:
                    return(Message.GoodByMessage);

                case Intention.BuscarTelefono:
                    return(Message.AskPhoneMessage);

                case Intention.None:
                default:
                    return(Message.CantHelpMessage);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return(Message.ErrorMessage);
            }
        }