예제 #1
0
        public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            var message = await result;

            //You can indicate to the user you are running the query :)
            //await context.PostAsync("Hold on one second!");
            var model = JobModelExtension.GetContextData(context);


            if (false)
            {
                //Here you can check if the intention is not found so you can list all the available options
            }
            else
            {
                var results = await searchService.FilterByStatus(model.ResolutionTerm);

                var channelID = message.ChannelId;

                //Check weather we have values in the search result
                if (results.Values.Length > 0)
                {
                    List <Attachment> foundItems = new List <Attachment>();

                    //To display the result in a nice card like boxes, we use custom CardUtil which provide a nice channel specific render of a card using Microsoft.Bot.Connector.Attachment
                    for (int i = 0; i < results.Values.Length; i++)
                    {
                        var searchItem = results.Values[i];

                        //We are not interested in deleted items
                        if (searchItem.IsDeleted == true)
                        {
                            continue;
                        }

                        var attachment = CardUtil.CreateCardAttachment(channelID, results.Values[i]);
                        foundItems.Add(attachment);
                    }

                    var reply = context.MakeMessage();
                    reply.AttachmentLayout = AttachmentLayoutTypes.List;
                    reply.Attachments      = foundItems;

                    await context.PostAsync(reply);

                    context.Done <object>(null);
                }
                else
                {
                    await context.PostAsync($"Sorry! I couldn't find anything that matched the search '{model.SearchTerm}'");

                    context.Done <object>(null);
                }
            }
        }
예제 #2
0
        public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            var message = await result;

            //await context.PostAsync("Hold on one second!");

            var model = ProductModel.GetContextData(context);

            if (!string.IsNullOrEmpty(model.API) || !string.IsNullOrEmpty(model.Category))
            {
                await context.PostAsync($"I've found some information on '{model.SearchTerm}'");

                ProductModel.SetContextData(context, model);
                await context.Forward(new ServiceExploreDialog(), AfterDialog, message, CancellationToken.None);
            }

            else
            {
                var results = await searchService.Search(model.SearchTerm);

                var channelID = message.ChannelId;

                if (results.value.Length > 0)
                {
                    List <Attachment> attachments = new List <Attachment>();
                    for (int i = 0; i < results.value.Length; i++)
                    {
                        var attachment = CardUtil.CreateCardAttachment(channelID, results.value[i]);
                        attachments.Add(attachment);
                    }

                    var reply = context.MakeMessage();
                    reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                    reply.Attachments      = attachments;

                    await context.PostAsync(reply);

                    context.Done <object>(null);
                }
                else
                {
                    await context.PostAsync($"Sorry! I couldnt find anything that matched the search '{model.SearchTerm}'");

                    context.Done <object>(null);
                }
            }
        }
예제 #3
0
        public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            var message = await result;
            var model   = ProductModel.GetContextData(context);
            var value   = await searchService.GetFeature(model.Feature);

            var channelID  = message.ChannelId;
            var attachment = CardUtil.CreateCardAttachment(channelID, value);

            var reply = context.MakeMessage();

            reply.Attachments.Add(attachment);

            await context.PostAsync(reply, CancellationToken.None);

            context.Done(string.Empty);
        }