private async Task ResumeAfterPrompt(IDialogContext context, IAwaitable <string> result) { try { var mess = await result; int choice; bool isNumberic = int.TryParse(mess, out choice); if (isNumberic) { // Connect to the database Models.BotDataEntities1 DB = new Models.BotDataEntities1(); int id = ansid[choice - 1]; var Answer = (from FAQ in DB.helps where FAQ.id == id select FAQ) .ToList(); System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(Answer[0].answer); await context.PostAsync(sb.ToString()); var reply = context.MakeMessage(); reply.Attachments = new List <Attachment>(); List <CardAction> cardButtons = new List <CardAction>(); CardAction person = new CardAction() { Value = "https://support.microsoft.com/en-us/answerdesk/accessibility", Type = "openUrl", Title = "Talk to a person" }; cardButtons.Add(person); CardAction web = new CardAction() { Value = Answer[0].link, Type = "openUrl", Title = "View on Web" }; cardButtons.Add(web); HeroCard plCard = new HeroCard() { Title = "Hope that help!", Text = "You can choose 'Talk to a person' or 'View the answer on Web' by click buttons below", Buttons = cardButtons }; Attachment plAttachment = plCard.ToAttachment(); reply.Attachments.Add(plAttachment); await context.PostAsync(reply); } else { await context.PostAsync($"Sorry! You can go [here](https://support.microsoft.com/en-us/answerdesk/accessibility) to talk to a person."); } } catch (TooManyAttemptsException) { } context.Wait(this.MessageReceivedAsync); }
private async Task ResumeAfterPrompt(IDialogContext context, IAwaitable <string> result) { try { var mess = await result; int choice; bool isNumberic = int.TryParse(mess, out choice); if (isNumberic) { if (choice > ansid.Count) { PromptDialog.Text(context, this.ResumeAfterPrompt, "Sorry, I can't understand your response. If you would like help with one of these topics, please type the number, otherwise answer no.\n\n"); return; } else { // Connect to the database Models.BotDataEntities1 DB = new Models.BotDataEntities1(); int id = ansid[choice - 1]; var Answer = (from FAQ in DB.windows where FAQ.id == id && FAQ.winver.Equals(WinVer) select FAQ) .ToList(); System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(String.Format("**{0}**\n\n{1}\n\n", Answer[0].question2, Answer[0].answer)); await context.PostAsync(sb.ToString()); } } else { if (mess.ToLower().Equals("no")) { await context.PostAsync($"Sorry! You can go [here](https://support.microsoft.com/en-us/answerdesk/accessibility) to talk to a person."); } else { PromptDialog.Text(context, this.ResumeAfterPrompt, "Sorry, I can't understand your response. If you would like help with one of these topics, please type the number, otherwise answer no.\n\n"); return; } } } catch (TooManyAttemptsException) { } context.Wait(this.MessageReceivedAsync); }
private async Task AfterChoseCategory(IDialogContext context, IAwaitable <string> result) { var option = await result; bool b = category_names.Any(option.Contains); if (b) { Category_Name = option; //await context.PostAsync($"From now on, all my searches will be in {category_name}"); var mess = context.MakeMessage(); mess.AttachmentLayout = AttachmentLayoutTypes.Carousel; mess.Attachments = new List <Attachment>(); Models.BotDataEntities1 DB = new Models.BotDataEntities1(); var Questions = (from h in DB.helps join c in DB.categories on h.category_id equals c.category_id where c.category_name.Equals(Category_Name) //orderby h.id ascending select h.question).Distinct() .ToList(); foreach (var q in Questions) { var Qcard = new HeroCard { Title = q, Buttons = new List <CardAction> { new CardAction(ActionTypes.ImBack, title: "Show me", value: q) } }; mess.Attachments.Add(Qcard.ToAttachment()); } await context.PostAsync(mess); context.Wait(this.MessageReceivedAsync); } else { PromptDialog.Text(context, this.AfterChoseCategory, "Please choose a category from the list above!"); } }
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> result) { var message = await result; if (faq.Any(message.Text.ToLower().Equals)) { await context.PostAsync($"Is there anything else I can help you with?"); Models.BotDataEntities1 DB = new Models.BotDataEntities1(); var categories = (from data in DB.categories select data).ToList(); var length = categories.Count(); var limit = Math.Ceiling((double)categories.Count() / 8); for (var k = 0; k < limit; k++) { var chosen = context.MakeMessage(); chosen.AttachmentLayout = AttachmentLayoutTypes.Carousel; chosen.Attachments = new List <Attachment>(); var max = length > 8 ? 8 : length; for (var m = 0; m < max; m++) { var index = 8 * k + m; var card = new HeroCard { Title = categories[index].category_name, Images = new List <CardImage>() { new CardImage(url: categories[index].category_image) }, Buttons = new List <CardAction>() { new CardAction(ActionTypes.ImBack, "Choose this category", value: categories[index].category_name) } }; chosen.Attachments.Add(card.ToAttachment()); } await context.PostAsync(chosen); length -= 8; } PromptDialog.Text(context, this.AfterChoseCategory, "Please choose a category from the list above!"); return; } else if (hello.Any(message.Text.ToLower().Contains)) { // } else if (message.Text.ToLower().Equals("talk to a person")) { await context.PostAsync($"Go [here](https://support.microsoft.com/en-us/answerdesk/accessibility) to talk to a person"); } else if (thanks.Any(message.Text.ToLower().Contains)) { await context.PostAsync($"Glad to talk to you!"); } else if (message.Text.ToLower().Contains("help")) { await context.PostAsync(HelpMesage); } else { //Connect to the database Models.BotDataEntities1 DB = new Models.BotDataEntities1(); //Get answers var Answers = (from FAQ in DB.helps where FAQ.question.Equals(message.Text) select FAQ) .ToList(); if (Answers.Count > 0) { // found 1 answer relative if (Answers.Count == 1) { // Create a response System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(Answers[0].answer); // Send the reply await context.PostAsync(sb.ToString()); var reply = context.MakeMessage(); reply.Attachments = new List <Attachment>(); List <CardAction> cardButtons = new List <CardAction>(); CardAction person = new CardAction() { Value = "https://support.microsoft.com/en-us/answerdesk/accessibility", Type = "openUrl", Title = "Talk to a person" }; cardButtons.Add(person); CardAction web = new CardAction() { Value = Answers[0].link, Type = "openUrl", Title = "View on Web" }; cardButtons.Add(web); HeroCard plCard = new HeroCard() { Title = "Hope that help!", Text = "You can choose 'Talk to a person' or 'View the answer on Web' by click buttons below", Buttons = cardButtons }; Attachment plAttachment = plCard.ToAttachment(); reply.Attachments.Add(plAttachment); await context.PostAsync(reply); } else if (Answers.Count > 1) { // Create a response System.Text.StringBuilder sb = new System.Text.StringBuilder(); var i = 1; List <string> num = new List <string>(); ansid.Clear(); sb.Append(message.Text + "\r\n"); // Loop through each answers foreach (var ans in Answers) { ansid.Add(ans.id); num.Add(i.ToString()); // Add the answer to the response sb.Append(String.Format("{0}. {1}\r\n", i, ans.sub_question)); i++; } //PromptDialog.Text(context, this.ResumeAfterPrompt, sb.ToString()); await context.PostAsync(sb.ToString()); num.Add("No"); PromptDialog.Choice(context, this.ResumeAfterPrompt, num.ToArray(), "If you would like help with one of these questions, please choose the number, otherwise choose No.\r\n" , "Sorry, I can't understand your response. If you would like help with one of these topics, please choose the number, otherwise choose No.\n\n"); return; } } else { await context.PostAsync($"Let me have a quick look..."); //Search on Web CustomsearchService customSearchService = new CustomsearchService(new Google.Apis.Services.BaseClientService.Initializer() { ApiKey = apiKey }); CseResource.ListRequest listRequest = customSearchService.Cse.List(message.Text); listRequest.Cx = searchEngineId; Search search = listRequest.Execute(); var ret = context.MakeMessage(); ret.AttachmentLayout = AttachmentLayoutTypes.Carousel; ret.Attachments = new List <Attachment>(); foreach (var item in search.Items) { var card = new HeroCard { Title = item.Title, Subtitle = item.DisplayLink, Text = item.Snippet, Buttons = new List <CardAction>() { new CardAction(ActionTypes.OpenUrl, "View on Web", value: item.Link) } }; ret.Attachments.Add(card.ToAttachment()); } await context.PostAsync(ret); } } context.Wait(this.MessageReceivedAsync); }
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> result) { var message = await result; if (faq.Any(message.Text.ToLower().Contains)) { await context.PostAsync($"Is there anything else I can help you with?"); Models.BotDataEntities1 DB = new Models.BotDataEntities1(); var categories = (from data in DB.categories select data); var chosen = context.MakeMessage(); chosen.AttachmentLayout = AttachmentLayoutTypes.Carousel; chosen.Attachments = new List <Attachment>(); foreach (var cate in categories) { var card = new HeroCard { Title = cate.category_name, //Images = new List<CardImage>() { new CardImage(url: cate.category_image) }, Buttons = new List <CardAction>() { new CardAction(ActionTypes.ImBack, "Choose this category", value: cate.category_name) } }; chosen.Attachments.Add(card.ToAttachment()); } await context.PostAsync(chosen); PromptDialog.Text(context, this.AfterChoseCategory, "Please choose a category from the list above!"); return; } else if (hello.Any(message.Text.ToLower().Contains)) { // } else if (message.Text.ToLower().Equals("talk to a person")) { await context.PostAsync($"Go [here](https://support.microsoft.com/en-us/answerdesk/accessibility) to talk to a person"); } else if (thanks.Any(message.Text.ToLower().Contains)) { await context.PostAsync($"Glad to talk to you!"); } else if (message.Text.ToLower().Contains("help")) { await context.PostAsync(HelpMesage); } else { //Connect to the database Models.BotDataEntities1 DB = new Models.BotDataEntities1(); //Get answers var Answers = (from FAQ in DB.helps where FAQ.question.Equals(message.Text) select FAQ) .ToList(); if (Answers.Count > 0) { // found 1 answer relative if (Answers.Count == 1) { // Create a response System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(Answers[0].answer); // Send the reply await context.PostAsync(sb.ToString()); var reply = context.MakeMessage(); reply.Attachments = new List <Attachment>(); List <CardAction> cardButtons = new List <CardAction>(); CardAction person = new CardAction() { Value = "https://support.microsoft.com/en-us/answerdesk/accessibility", Type = "openUrl", Title = "Talk to a person" }; cardButtons.Add(person); CardAction web = new CardAction() { Value = Answers[0].link, Type = "openUrl", Title = "View on Web" }; cardButtons.Add(web); HeroCard plCard = new HeroCard() { Title = "Hope that help!", Text = "You can choose 'Talk to a person' or 'View the answer on Web' by click buttons below", Buttons = cardButtons }; Attachment plAttachment = plCard.ToAttachment(); reply.Attachments.Add(plAttachment); await context.PostAsync(reply); } else if (Answers.Count > 1) { // Create a response System.Text.StringBuilder sb = new System.Text.StringBuilder(); var i = 0; ansid.Clear(); sb.Append("If you would like help with one of these questions, please type the number, otherwise answer no.\n\n"); // Loop through each answers foreach (var ans in Answers) { ansid.Add(ans.id); // Add the answer to the response sb.Append(String.Format("{0}. {1}\n\n", ++i, ans.sub_question)); } PromptDialog.Text(context, this.ResumeAfterPrompt, sb.ToString()); return; } } else { await context.PostAsync($"Let me have a quick look...(Search question on google/bing-not yet finished!)"); //Search on Web } } context.Wait(this.MessageReceivedAsync); }
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> result) { var message = await result; if (message.Text.ToLower().Equals("faq")) { await context.PostAsync($"Is there anything else I can help you with?"); //Connect to the database Models.BotDataEntities1 DB = new Models.BotDataEntities1(); var categories = (from data in DB.categories select data).ToList(); // sql query (linq) var length = categories.Count(); var limit = Math.Ceiling((double)categories.Count() / 8); for (var k = 0; k < limit; k++) { var chosen = context.MakeMessage(); chosen.AttachmentLayout = AttachmentLayoutTypes.Carousel; chosen.Attachments = new List <Attachment>(); var max = length > 8 ? 8 : length; for (var m = 0; m < max; m++) { var index = 8 * k + m; var card = new HeroCard { Title = categories[index].category_name, Images = new List <CardImage>() { new CardImage(url: categories[index].category_image) }, Buttons = new List <CardAction>() { new CardAction(ActionTypes.ImBack, "Choose this category", value: categories[index].category_name) } }; chosen.Attachments.Add(card.ToAttachment()); } await context.PostAsync(chosen); length -= 8; } } else if (category_names.Any(message.Text.Equals)) { var mess = context.MakeMessage(); mess.AttachmentLayout = AttachmentLayoutTypes.Carousel; mess.Attachments = new List <Attachment>(); //Connect to the database Models.BotDataEntities1 DB = new Models.BotDataEntities1(); var Questions = (from h in DB.helps join c in DB.categories on h.category_id equals c.category_id where c.category_name.Equals(message.Text) select h.question).Distinct() .ToList(); // Loop through each questions foreach (var q in Questions) { var Qcard = new HeroCard { Title = q, Buttons = new List <CardAction> { new CardAction(ActionTypes.ImBack, title: "Show me", value: q) } }; mess.Attachments.Add(Qcard.ToAttachment()); } await context.PostAsync(mess); } else if (hello.Any(message.Text.ToLower().Equals)) { await context.PostAsync($"Describe your problem and I'll look for the best solution."); } else if (message.Text.ToLower().Equals("talk to a person")) { await context.PostAsync($"Go [here](https://support.microsoft.com/en-us/answerdesk/accessibility) to talk to a person"); } else if (thanks.Any(message.Text.ToLower().Contains)) { await context.PostAsync($"Glad to talk to you!"); } else if (message.Text.ToLower().Contains("help")) { await context.PostAsync(HelpMesage); } else { //Connect to the database Models.BotDataEntities1 DB = new Models.BotDataEntities1(); //Get answers var Answers = (from FAQ in DB.helps where FAQ.question.Equals(message.Text) || FAQ.sub_question.Equals(message.Text) select FAQ) .ToList(); if (Answers.Count > 0) { // found 1 answer relative = sub_question is null if (Answers.Count == 1) { await context.PostAsync(Answers[0].answer); var reply = context.MakeMessage(); reply.Attachments = new List <Attachment>(); List <CardAction> cardButtons = new List <CardAction>(); CardAction person = new CardAction() { Value = "https://support.microsoft.com/en-us/answerdesk/accessibility", Type = "openUrl", Title = "Talk to a person" }; cardButtons.Add(person); CardAction web = new CardAction() { Value = Answers[0].link, Type = "openUrl", Title = "View on Web" }; cardButtons.Add(web); CardAction thanks = new CardAction() { Value = "Got it, thanks!", Type = "imBack", Title = "Got it, thanks!" }; cardButtons.Add(thanks); HeroCard plCard = new HeroCard() { Title = "Hope that help!", Text = "You can choose 'Talk to a person' or 'View the answer on Web' by click buttons below", Buttons = cardButtons }; Attachment plAttachment = plCard.ToAttachment(); reply.Attachments.Add(plAttachment); await context.PostAsync(reply); } else if (Answers.Count > 1) // sub_question is not null { var rep = context.MakeMessage(); rep.AttachmentLayout = AttachmentLayoutTypes.Carousel; rep.Attachments = new List <Attachment>(); // show sub_question list foreach (var ans in Answers) { var card = new HeroCard { Title = ans.sub_question, Buttons = new List <CardAction> { new CardAction(ActionTypes.ImBack, "Show me", value: ans.sub_question) } }; rep.Attachments.Add(card.ToAttachment()); } await context.PostAsync(rep); } } else { await context.PostAsync($"Let me have a quick look..."); //Search on Web using google cse api CustomsearchService customSearchService = new CustomsearchService(new Google.Apis.Services.BaseClientService.Initializer() { ApiKey = apiKey }); CseResource.ListRequest listRequest = customSearchService.Cse.List(message.Text); listRequest.Cx = searchEngineId; Search search = listRequest.Execute(); var ret = context.MakeMessage(); ret.AttachmentLayout = AttachmentLayoutTypes.Carousel; ret.Attachments = new List <Attachment>(); // loop through each google results foreach (var item in search.Items) { var card = new HeroCard { Title = item.Title, Subtitle = item.DisplayLink, Text = item.Snippet, Buttons = new List <CardAction>() { new CardAction(ActionTypes.OpenUrl, "View on Web", value: item.Link) } }; ret.Attachments.Add(card.ToAttachment()); } await context.PostAsync(ret); } } context.Wait(this.MessageReceivedAsync); }
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> result) { var message = await result; if (message.Text.ToLower().StartsWith("hi") || message.Text.ToLower().StartsWith("hello")) { await context.PostAsync($"Describe your problem and I'll look for the best solution. You can also ask to talk to a person at any time."); PromptDialog.Choice(context, this.ChoseWinver, WinVerOptions.ToArray(), "Before get started, please tell me your windows version?", "I didn't understand. Please try again."); return; } else if (message.Text.ToLower().StartsWith("change")) { PromptDialog.Choice(context, this.ChoseWinver, WinVerOptions.ToArray(), "Please tell me your windows version?", "I didn't understand. Please try again."); return; } else if (message.Text.ToLower().Contains("person")) { await context.PostAsync($"Go [here](https://support.microsoft.com/en-us/answerdesk/accessibility) to talk to a person"); } else if (message.Text.ToLower().Contains("thanks") || message.Text.ToLower().Contains("fixed")) { await context.PostAsync($"Glad to talk to you!"); } else if (message.Text.ToLower().Contains("start over")) { PromptDialog.Confirm(context, this.StartOver, "Start over? This will clear the history and restart the chat.", "Didn't get that!"); return; } else if (message.Text.ToLower().Contains("help")) { await context.PostAsync($"Help"); } else { // Connect to the database Models.BotDataEntities1 DB = new Models.BotDataEntities1(); // Get answers var Answers = (from FAQ in DB.windows where FAQ.question1.ToLower().Contains(message.Text) && FAQ.winver.Equals(WinVer) select FAQ) .ToList(); if (Answers.Count > 0) { // found 1 answer relative if (Answers.Count == 1) { // Create a response System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(Answers[0].answer); //sb.Append(String.Format("**{0}**\n\n{1}\n\n", Answers[0].question1, Answers[0].answer)); // Send the reply await context.PostAsync(sb.ToString()); } else if (Answers.Count > 1) { // Create a response System.Text.StringBuilder sb = new System.Text.StringBuilder(); var i = 0; ansid.Clear(); sb.Append("If you would like help with one of these topics, please type the number, otherwise answer no.\n\n"); // Loop through each answers foreach (var ans in Answers) { ansid.Add(ans.id); // Add the answer to the response sb.Append(String.Format("{0}. {1}\n\n", ++i, ans.question2)); } PromptDialog.Text(context, this.ResumeAfterPrompt, sb.ToString()); return; } // Add Talk to a person button var reply = context.MakeMessage(); reply.Attachments = new List <Attachment>(); List <CardImage> cardImages = new List <CardImage>(); cardImages.Add(new CardImage(url: "http://www.elemica.com/wp-content/uploads/2015/02/support-smiley.png")); List <CardAction> cardButtons = new List <CardAction>(); CardAction plButton = new CardAction() { Value = "https://support.microsoft.com/en-us/answerdesk/accessibility", Type = "openUrl", Title = "Talk to a person" }; cardButtons.Add(plButton); HeroCard plCard = new HeroCard() { Title = "Hope that help!", Text = "If not, please feel free to rephrase your question or click below to talk to a person.", //Images = cardImages, Buttons = cardButtons }; Attachment plAttachment = plCard.ToAttachment(); reply.Attachments.Add(plAttachment); await context.PostAsync(reply); } else { await context.PostAsync($"Sorry I did not understand: " + message.Text); } } context.Wait(this.MessageReceivedAsync); }