Пример #1
0
        public async Task CurrencyConversion(IDialogContext context, LuisResult result)
        {
            var    message = context.MakeMessage();
            string fromCur = "";          // store the currency the user wants to convert from
            string toCur   = "";          // store the currency the user wants to convert to
            EntityRecommendation fromEnt; // Entity LUIS determines
            EntityRecommendation toEnt;

            // Find out the Entity is there
            if (result.TryFindEntity("FromCurrency", out fromEnt))
            {
                fromCur = fromEnt.Entity;
            }
            else
            {
                await context.PostAsync($"The query is not correct. Please try again.");

                return;
            }

            // Find out the Entity is there
            if (result.TryFindEntity("ToCurrency", out toEnt))
            {
                toCur = toEnt.Entity;
            }
            else
            {
                await context.PostAsync($"The query is not correct. Please try again.");

                return;
            }

            // Calculate using Yahoo API and give the result back to the user
            exchangerate ex = new exchangerate();
            await context.PostAsync($"Your Conversion base on a $1 value is: {ex.conversionRate(fromCur, toCur)}");

            PromptDialog.Confirm(context, Continuation, $"Is there anything else I can help you with?");
        }
Пример #2
0
        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result)
        {
            var activity = await result as Activity;

            // Split the currency the user wants to convert by comma
            string[] splitValue = activity.Text.Split(',');
            for (int i = 0; i < splitValue.Length; i++)
            {
                splitValue[i] = splitValue[i].Trim();
            }
            exchangerate ex = new exchangerate();

            // Called the Yahoo API to do the conversion
            string exchange = ex.conversionRate(splitValue[0], splitValue[1]);

            // calculate something for us to return
            int length = (activity.Text ?? string.Empty).Length;

            // return our reply to the user
            // await context.PostAsync($"You have sent {activity.Text} which was {length} characters");
            await context.PostAsync($"Your Conversion {exchange}");

            context.Wait(MessageReceivedAsync);
        }