Esempio n. 1
0
        public async Task DescribeDatasetIntent(IDialogContext context, LuisResult result)
        {
            EntityRecommendation dataSetEntity;
            string dstype;

            if (result.TryFindEntity("supporteddatasettype", out dataSetEntity))
            {
                System.Diagnostics.Debug.WriteLine($"entity {dataSetEntity}");
                dstype = dataSetEntity.Entity;
            }
            else
            {
                dstype = result.Query;
            }

            if (!_SupportedDatasets.Any(m => m.Key == dstype))
            {
                dstype = "ato";
                await context.PostAsync($"Which dataset?? anyways, here is the {dstype} one!");
            }



            var dtTypes = await EdaClient.GetAtoDataTypesAsync(dstype);

            await context.PostAsync($"You sent {result.Query}.");

            //await context.PostAsync($"response ----- {str}");

            var responseMessage = context.MakeMessage();
            int i = 1;

            foreach (var item in dtTypes)
            {
                HeroCard hCard = new HeroCard()
                {
                    Title    = $"Column {i++}: {item.ColName}",
                    Subtitle = $"Type: {item.ColType}"
                };
                responseMessage.Attachments.Add(hCard.ToAttachment());
            }


            responseMessage.AttachmentLayout = AttachmentLayoutTypes.List;

            await context.PostAsync(responseMessage);


            context.Wait(this.MessageReceived);
        }
Esempio n. 2
0
        public async Task PlotDatasetIntent(IDialogContext context, LuisResult result)
        {
            EntityRecommendation dataSetEntity;
            string dstype;

            if (result.TryFindEntity("supporteddatasettype", out dataSetEntity))
            {
                System.Diagnostics.Debug.WriteLine($"entity {dataSetEntity}");
                dstype = dataSetEntity.Entity;
            }
            else
            {
                dstype = result.Query;
            }

            if (!_SupportedDatasets.Any(m => m.Key == dstype))
            {
                dstype = "ato";
                await context.PostAsync($"Which dataset?? anyways, here is the {dstype} one!");
            }

            var resp = await EdaClient.GetPlotAsync(dstype);

            int i = 1;

            foreach (var item in resp)
            {
                var responseMessage = context.MakeMessage();
                responseMessage.Attachments.Add(new Attachment()
                {
                    ContentUrl   = item,
                    ContentType  = "image/png",
                    ThumbnailUrl = item,
                    Name         = $"{dstype}-plot{i++}.png"
                });
                responseMessage.AttachmentLayout = AttachmentLayoutTypes.List;
                await context.PostAsync(responseMessage);
            }



            context.Wait(this.MessageReceived);
        }
Esempio n. 3
0
        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result)
        {
            var activity = await result as Activity;

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

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

            if (activity.Text == "ato")
            {
                var str = await EdaClient.GetAtoDataTypesAsync("ato");

                await context.PostAsync($"You sent {activity.Text}.");

                await context.PostAsync($"response ----- {str}");
            }
            else if (activity.Text == "search")
            {
                var srchClient = new SearchDatasets();

                var searchResults = await srchClient.GetAzSearchResultsAsync("Energy");



                // use attachment list
                var responseMessage = context.MakeMessage(); // show have preperties set properly for conversation and recepient
                responseMessage.AttachmentLayout = AttachmentLayoutTypes.List;
                responseMessage.Attachments      = new List <Attachment>();

                var i    = 1;
                var item = searchResults.Results[0];
                {
                    var    files = item.Document["files"] as string[];
                    string url   = (string)files[0];

                    CardAction cardButton = new CardAction()
                    {
                        Title = $"{new UriBuilder(url).Uri.AbsoluteUri}",
                        Type  = "openUrl",
                        Value = new UriBuilder(url).Uri.AbsoluteUri
                    };


                    List <CardAction> cardActions = new List <CardAction>();
                    cardActions.Add(cardButton);
                    HeroCard hCard = new HeroCard()
                    {
                        Title = $"{i++}: {item.Document["title"]}",

                        Text = $"{item.Document["description"]}",
                        //Text = $"Text: {v.name}",
                        Images  = null,
                        Buttons = cardActions
                    };

                    Attachment cardAttachment = hCard.ToAttachment();
                    responseMessage.Attachments.Add(cardAttachment);
                }

                await context.PostAsync(responseMessage);
            }
            else if (activity.Text == "graph")
            {
                var resp = await EdaClient.GetPlotAsync("ato");


                var responseMessage = context.MakeMessage();
                responseMessage.Attachments.Add(new Attachment()
                {
                    ContentUrl  = resp[0],
                    ContentType = "image/png",
                    Name        = "ato.png"
                });


                await context.PostAsync(responseMessage);
            }
            else
            {
            }

            context.Wait(MessageReceivedAsync);
        }