public async Task ListJobsIntent(IDialogContext context, IAwaitable <IMessageActivity> message, LuisResult result)
        {
            {
                var messageToForward = await message;

                EntityRecommendation jobSearch;
                if (result.TryFindEntity(ServiceEntities.ServiceStatus, out jobSearch))
                {
                    var model = JobModelExtension.GetContextData(context);
                    // Title case the search entity for consistency
                    model.SearchTerm = new CultureInfo("en").TextInfo.ToTitleCase(jobSearch.Entity.ToLower());
                    var res  = jobSearch.Resolution.Values;
                    var resV = res.ToList()[0] as List <object>;
                    model.ResolutionTerm = resV[0].ToString();

                    JobModelExtension.SetContextData(context, model);
                    await context.PostAsync($"OK, let me look for information on ({model.SearchTerm}) jobs.");

                    await context.Forward(new SearchServiceDialog(), AfterDialog, messageToForward, CancellationToken.None);
                }

                // If we cant identify a product entity, start an explore dialog
                else
                {
                    await context.PostAsync($"I couldn't find any jobs with the required status! Waiting, In Progress and Completed are the accepted status");
                }
            }
        }
Esempio n. 2
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);
                }
            }
        }