public void TestCommentBodyParse() { InitMPData(); for (int i = 0; i < testCriteria_keyword.GetLength(0); i++) { string commentBody = testCriteria_keyword[i, 0]; string expectedUrl = testCriteria_keyword[i, 1]; string resultReply = BotReply.GetReplyForRequest(commentBody); Assert.IsTrue(resultReply.Contains(Utilities.GetSimpleURL(Utilities.MPBASEURL + expectedUrl)), "Failed for " + testCriteria_keyword[i, 0]); } }
public void TestCommentBodyParse() { MountainProjectDataSearch.InitMountainProjectData(@"..\..\MountainProjectDBBuilder\bin\MountainProjectAreas.xml"); for (int i = 0; i < testCriteria_keyword.GetLength(0); i++) { string commentBody = testCriteria_keyword[i, 0]; string expectedUrl = testCriteria_keyword[i, 1]; string resultReply = BotReply.GetReplyForCommentBody(commentBody); Assert.IsTrue(resultReply.Contains(expectedUrl)); } }
public void TestLocationString() { MountainProjectDataSearch.InitMountainProjectData(@"..\..\MountainProjectDBBuilder\bin\MountainProjectAreas.xml"); for (int i = 0; i < testCriteria_location.GetLength(0); i++) { string query = testCriteria_location[i, 0]; string expectedLocation = testCriteria_location[i, 1]; string resultLocation = BotReply.GetLocationString(MountainProjectDataSearch.SearchMountainProject(query)); resultLocation = resultLocation.Replace("\n\n", ""); //Remove markdown newline resultLocation = resultLocation.Replace("Located in ", ""); //Simplify results for unit test Assert.AreEqual(expectedLocation, resultLocation); } }
// POST: api/Answer public void PostAnswerOne(string botAnswer, string intentName) { int sessionId = int.Parse(db.Session.OrderByDescending(x => x.SessionId).Select(x => x.SessionId).First().ToString()); int intentId = db.Intent.Where(x => x.Name == intentName).Select(x => x.IntentId).FirstOrDefault(); int questionId = int.Parse(db.Question.OrderByDescending(x => x.QuestionId).Select(x => x.QuestionId).First().ToString()); BotReply br = new BotReply(); br.QuestionId = questionId; br.SessionId = sessionId; br.AnswerId = Convert.ToInt32(db.sp_AnswerInsert(intentId, botAnswer, false).FirstOrDefault()); db.BotReply.Add(br); db.SaveChanges(); }
public void SetUp() { correctMovieInfo = new MovieInfo { Country = "Russia", Director = "Mr. mediocrity", OriginalTitle = "Very expensive bad film", Rating = new Dictionary <string, string> { { "imdb", "1" } }, Title = "THE BEST FILM EVER", Year = DateTime.Now.Year }; phraseDicts = new IPhraseDict[] { new RuPhraseDict(), new EnPhraseDict() }; testReply = new BotReply(phraseDicts); }
public void TestLocationString() { InitMPData(); for (int i = 0; i < testCriteria_location.GetLength(0); i++) { string query = testCriteria_location[i, 0]; string expectedLocation = testCriteria_location[i, 1]; SearchResult searchResult = MountainProjectDataSearch.Search(query); string resultLocation = BotReply.GetLocationString(searchResult.FilteredResult); resultLocation = resultLocation.Replace(Markdown.NewLine, ""); //Remove markdown newline resultLocation = resultLocation.Replace("Located in ", ""); //Simplify results for unit test resultLocation = Regex.Replace(resultLocation, @"\[|\]\(.*?\)", ""); //Remove markdown link formatting Assert.AreEqual(expectedLocation, resultLocation, "Failed for " + testCriteria_location[i, 0]); Assert.IsTrue(searchResult.TimeSpanTaken().TotalSeconds < 5, $"{query} took too long ({searchResult.TimeTakenMS} ms)"); } }
// POST: api/Answer public void PostAnswer(string userInput, string botAnswer, string intentName, string intentScore, string entityScore) { int sessionId = int.Parse(db.Session.OrderByDescending(x => x.SessionId).Select(x => x.SessionId).First().ToString()); int intentId = db.Intent.Where(x => x.Name == intentName).Select(x => x.IntentId).FirstOrDefault(); int scoreId = Convert.ToInt32(db.sp_ScoreInsert(Convert.ToDecimal(intentScore), Convert.ToDecimal(intentScore)).FirstOrDefault()); int questionId = Convert.ToInt32(db.sp_QuestionInsert(userInput, intentId, scoreId, DateTime.Now, sessionId).FirstOrDefault()); BotReply br = new BotReply(); br.QuestionId = questionId; br.SessionId = sessionId; br.AnswerId = Convert.ToInt32(db.sp_AnswerInsert(intentId, botAnswer, false).FirstOrDefault()); db.BotReply.Add(br); db.SaveChanges(); }
public void SendReply(BotReply botReply, string text) { if (botReply.ReplyType == BotReplyType.RequestForChoseParser || botReply.ReplyType == BotReplyType.UnknownParser) { var rkm = new ReplyKeyboardMarkup { Keyboard = new[] { new KeyboardButton[] { "IEXCloud", "Finhub" } } }; SendTelegramReplyWithMarkup(botReply.User.Id, rkm, text); } else if (!ReferenceEquals(botReply.SymbolParameters, null) && botReply.SymbolParameters.ContainsKey("text")) { text = outputRender.CreateSymbolsInfo(botReply.SymbolParameters["text"]); SendTelegramReplyWithoutMarkup(botReply.User.Id, text); } else { SendTelegramReplyWithoutMarkup(botReply.User.Id, text); } }
public static List <string> Write(BotReply reply) { List <string> commands = new List <string>(); int buttoncount = 1; foreach (var part in reply.Parts) { if (part.TypeDelay > 0) { Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("[...]"); System.Threading.Thread.Sleep(part.TypeDelay); Console.ForegroundColor = ConsoleColor.Green; Console.CursorLeft = 0; } switch (part.Type) { case StandardPartTypeEnum.Question: case StandardPartTypeEnum.Text: Console.WriteLine("\t" + part.Text); break; case StandardPartTypeEnum.Button: Console.Write("\t[" + buttoncount.ToString() + "]:" + part.Text); buttoncount++; commands.Add(part.Command); break; } } if (reply.Parts.Any(_ => _.Type == StandardPartTypeEnum.Button)) { Console.WriteLine( ); } Console.WriteLine( ); return(commands); }
public static string Write(BotReply reply) { StringBuilder bld = new StringBuilder(); bld.Append("\t" + DateTime.Now.ToString( ) + "\r\n"); foreach (var part in reply.Parts) { switch (part.Type) { case StandardPartTypeEnum.Question: case StandardPartTypeEnum.Text: bld.Append("\t" + part.Text.Replace("\n", "\r\n\t") + "\r\n"); break; case StandardPartTypeEnum.Button: bld.Append("\t[" + part.Text + "]\r\n"); break; } } bld.Append("\r\n"); return(bld.ToString( )); }
public ActionResult Bot(UserMessage um) { //System.Diagnostics.Debug.WriteLine(um.msg); List <BotReply> br = new List <BotReply>(); BotReply b = new BotReply(); switch (um.msg.ToLower()) { case "hi": case "sup": case "hey": case "hello": b.message = "Hey! How can i help you today? \\"; b.message += "If you need any help in the inputs available, type \"help\" or \"--h\""; break; case "bye": case "good bye": case "goodbye": case "bye bye": case "byebye": case "gotta go": case "gotta go!": case "see you again!": case "see you again": case "ttyl": case "talk to you later": b.message = "Ok bye! See you again!"; break; case "what is this?": case "what is this": b.message = "This is a simple chat bot like application that takes your input and gives you a reply \\"; b.message += "This was inspired by the Microsoft Bot Framework \\"; b.message += "Do check out the Bot Framework and see how you can host your very own bot in Azure!"; break; case "copyright": b.message = "Coded by Kok Wah in 2018"; break; case "how to use?": b.message = "To configure it you just need to add on to the switch statement \\"; b.message += "case \"What the user will enter\": \\"; b.message += "b.message = \"What your bot will reply\"; \\"; b.message += "break; \\"; b.message += "To set up a default reply, when non of the user input matches \\"; b.message += "Add this to the end of the switch statement \\"; b.message += "default: \\"; b.message += "b.message = \"What your bot will reply\"; \\"; b.message += "break;"; break; case "help": case "\\h": case "\\help": case "--h": case "/help": case "/h": b.message = "Here are some valid inputs: \\"; b.message += "Greetings - Hey, Hi, Sup, Hello \\"; b.message += "Bye - Bye, Good Bye, Bye Bye, Gotta Go, See You Again, TTYL \\"; b.message += "Find out about the app - What is this? \\"; b.message += "Copyright - Copyright \\"; b.message += "How to configure this to suit your needs - How To Use?"; break; default: b.message = "That input is not available type \"help\" or \"--h\" to see what is valid!"; break; } //userinput message b.usertyped = um.msg; DateTime today = DateTime.Now; //user timestamp b.usertime = today.ToString("d") + " " + today.ToString("T"); //delay for bot timestamp DateTime bottime = today.AddSeconds(3); b.timestamp = bottime.ToString("d") + " " + bottime.ToString("T"); //keep track of everything if (noofentries >= 1) { //System.Diagnostics.Debug.WriteLine("old user reply: " + userreplies + " old bot reply: " + botreplies + " old timestamp: " + timestampsss + " old user time: " + usertimess); userreplies = userreplies + "\'" + b.usertyped; botreplies = botreplies + "\'" + b.message; timestampsss = timestampsss + "\'" + b.timestamp; usertimess = usertimess + "\'" + b.usertime; //System.Diagnostics.Debug.WriteLine("new user reply: " + userreplies + " new bot reply: " + botreplies + " new timestamp: " + timestampsss + " new user time: " + usertimess); String[] temp1 = userreplies.Split('\''); //System.Diagnostics.Debug.WriteLine("First " + temp1[0] + " next " + temp1[1]); String[] temp2 = botreplies.Split('\''); //System.Diagnostics.Debug.WriteLine("First " + temp2[0] + " next " + temp2[1]); String[] temp3 = timestampsss.Split('\''); //System.Diagnostics.Debug.WriteLine("First " + temp3[0] + " next " + temp3[1]); String[] temp4 = usertimess.Split('\''); //System.Diagnostics.Debug.WriteLine("First " + temp4[0] + " next " + temp4[1]); for (int i = 0; i < temp1.Length; i++) { BotReply save = new BotReply(); save.usertyped = temp1[i]; //System.Diagnostics.Debug.WriteLine("Went in "+temp1[i]); save.message = temp2[i]; //System.Diagnostics.Debug.WriteLine("Went in " + temp2[i]); save.timestamp = temp3[i]; //System.Diagnostics.Debug.WriteLine("Went in " + temp3[i]); save.usertime = temp4[i]; //System.Diagnostics.Debug.WriteLine("Went in " + temp4[i]); //System.Diagnostics.Debug.WriteLine(); br.Add(save); } } else { userreplies = b.usertyped; botreplies = b.message; timestampsss = b.timestamp; usertimess = b.usertime; br.Add(b); } noofentries++; /* * for(int i=0; i<br.Count; i++) * { * System.Diagnostics.Debug.WriteLine(br.Count); * System.Diagnostics.Debug.WriteLine(i); * System.Diagnostics.Debug.WriteLine("What is in br " + br[i].message); * System.Diagnostics.Debug.WriteLine("What is in br " + br[i].timestamp); * System.Diagnostics.Debug.WriteLine("What is in br " + br[i].usertyped); * System.Diagnostics.Debug.WriteLine("What is in br " + br[i].usertime); * }*/ return(View(br)); }
public void BotOnReply(BotReply botReply) { SendReply(botReply, outputRender.RenderReply(botReply.ReplyType)); }
private void Nothing(BotReply obj) { return; }