Exemplo n.º 1
0
        //uses LUIS to understand user query inteligently, and respond appropriately
        private async Task <Activity> NaturalInteractionHandler(Activity message)
        {
            if ((message.Text.Trim().ToLower() ?? "") == "")
            {
                return(message.CreateReply("Error: Message type unsupported"));
            }
            LUISHandler.LUISQueryResult LUISResult = await LUISHandler.HandleQuery(message.Text);

            switch (LUISResult.responseType)
            {
            case LUISHandler.ResponseType.ExchangeRate:
                return(await ExchangeRateHandler.HandleExchangeRateMessage(message, LUISResult));

            case LUISHandler.ResponseType.Logout:
                return(await FacebookHandler.LogoutHandler(message));

            case LUISHandler.ResponseType.None:
                return(await UnknownHandler(message));

            case LUISHandler.ResponseType.AccountBalance:
                return(await BankHandler.HandleBalance(message));

            case LUISHandler.ResponseType.MakePayment:
                return(await BankHandler.HandleTransaction(message, LUISResult));

            case LUISHandler.ResponseType.TransactionHistory:
                return(await BankHandler.HandleHistory(message));

            default:
                return(message.CreateReply("Error: Unimplemented"));
            }
        }
Exemplo n.º 2
0
        private static List <string> RatesFromLUIS(LUISHandler.LUISQueryResult LUISResult)
        {
            List <string> Rates = new List <string>();

            if (LUISResult.parameters.ContainsKey("SourceRate"))
            {
                Rates.Add(LUISResult.parameters["SourceRate"]);
            }
            if (LUISResult.parameters.ContainsKey("DestinationRate"))
            {
                Rates.Add(LUISResult.parameters["DestinationRate"]);
            }
            return(Rates);
        }
Exemplo n.º 3
0
        public static async Task <Activity> HandleExchangeRateMessage(Activity message, LUISHandler.LUISQueryResult LUISResult)
        {
            try
            {
                //figure out conversions, if one rate given, try the other one as first nzd, then usd.
                //ignoring destination/source for simplicity, will report rate both ways
                List <string> givenCodes = RatesFromLUIS(LUISResult).Union(new List <string> {
                    "NZD", "USD"
                }, StringComparer.OrdinalIgnoreCase).Take(2).ToList();
                //exact rates arent neccesarily inverses...
                double FirstToSecond = await ExchangeRateFromTo(givenCodes[0], givenCodes[1]);

                double SecondToFirst = await ExchangeRateFromTo(givenCodes[1], givenCodes[0]);

                string reply = string.Format("Exchange rate from {0} to {1} is {2:F4} (Rate from {1} to {0} is {3:F4})",
                                             givenCodes[0].ToUpper(), givenCodes[1].ToUpper(), FirstToSecond, SecondToFirst);
                return(message.CreateReply(reply));
            }
            catch (KeyNotFoundException)
            {
                return(message.CreateReply("Could not find exchange rate"));
            }
        }