Esempio n. 1
0
        public async Task getStockChart(IDialogContext context, LuisResult result)
        {
            string tickerSymbol = "";

            // Ensures a ticker symbol has been specified
            if (result.Entities.Count > 0 || context.UserData.TryGetValue("tickerSymbol", out tickerSymbol))
            {
                // First checks whether ticker symbol has been specified otherwise takes most recently specified ticker symbol
                tickerSymbol = (result.Entities.Count > 0) ? result.Entities[0].Entity : tickerSymbol;

                Microsoft.Bot.Connector.Activity reply = (Microsoft.Bot.Connector.Activity)context.MakeMessage();

                reply.Type        = "message";
                reply.Attachments = new List <Attachment>();

                List <CardImage> cardImages = new List <CardImage>();
                cardImages.Add(new CardImage(url: $"http://ichart.finance.yahoo.com/b?s={tickerSymbol}"));

                List <CardAction> cardButtons = new List <CardAction>();
                CardAction        plButton    = new CardAction()
                {
                    Value = $"http://money.cnn.com/quote/quote.html?symb={tickerSymbol}",
                    Type  = "openUrl",
                    Title = "More Info"
                };
                cardButtons.Add(plButton);
                string stockInfo = await Sotck.getStockAsync(tickerSymbol);

                HeroCard plCard = new HeroCard()
                {
                    Title   = stockInfo,
                    Images  = cardImages,
                    Buttons = cardButtons
                };

                Attachment plAttachment = plCard.ToAttachment();
                reply.Attachments.Add(plAttachment);
                await context.PostAsync(reply);

                context.Wait(MessageReceived);
            }
            else
            {
                await context.PostAsync("We were unable to identify the ticker symbol");

                context.Wait(MessageReceived);
            }
        }
Esempio n. 2
0
        public async Task getStockPrice(IDialogContext context, LuisResult result)
        {
            string endOutput = string.Empty;

            if (result.Entities.Count > 0)
            {
                string tickerSymbol = result.Entities[0].Entity;
                string stockInfo    = await Sotck.getStockAsync(tickerSymbol);

                endOutput = stockInfo;

                context.UserData.SetValue <string>("tickerSymbol", tickerSymbol);
            }
            else
            {
                endOutput = "We were unable to identify the ticker symbol";
            }
            await context.PostAsync(endOutput);

            context.Wait(MessageReceived);
        }