public override async Task <ParseResult> ParseAsync(ChatState chatState, Chat_ParseField chatParseField, ChatMessage message) { var preFlowName = chatParseField.GetProperty("preFlowName"); var preStepId = chatParseField.GetProperty("preStepId"); var postFlowName = chatParseField.GetProperty("postFlowName"); var postStepId = chatParseField.GetProperty("postStepId"); if (String.IsNullOrEmpty(preFlowName) || String.IsNullOrEmpty(preStepId) || String.IsNullOrEmpty(postFlowName) || String.IsNullOrEmpty(postStepId)) { throw new ApplicationException("Parse: Missing rule data for IntentGateway Parser."); } message.Classifications = await ClassifyText(message.CorrectedUserInput, preFlowName, preStepId, postFlowName, postStepId, chatState.SessionData.IsSmsChannel); chatState.UpdateLastClassification(message.Classifications); if (!message.Classifications.IsSuccessful) { return(ParseResult.Failed); } // We don't want common chat intent's here. var intent = chatState.LastClassification.GetBestResult().Intent; if (intent != null && intent.StartsWith("commonchat-")) { return(ParseResult.Failed); } return(ParseResult.CreateSuccess(message.Classifications.GetBestResult().Result)); }
public override Task <ParseResult> ParseAsync(ChatState state, Chat_ParseField chatParseField, ChatMessage message) { string text = GetTextSource(chatParseField, message); // Shortcut for common case where flow tries to take all user input. // .* regex means all characters EXCEPT newlines. But the flow wants all including newlines // so running regex to collect all data doesn't make sense. So we just set the variable to everything. if (chatParseField.RuleData == ".*") { return(Task.FromResult(ParseResult.CreateSuccess(text))); } string regex = chatParseField?.GetProperty("Regex") ?? chatParseField.RuleData; try { var match = Regex.Match(text, regex, RegexOptions.IgnoreCase, ChatConfiguration.RegexTimeout); if (match.Success) { if (String.IsNullOrEmpty(chatParseField.Answer)) { return(Task.FromResult(ParseResult.CreateSuccess(match.Value))); } return(Task.FromResult(ParseResult.CreateSuccess(chatParseField.Answer))); } } catch (RegexMatchTimeoutException) { logger.ErrorFormat("Regex timed out. {0}", regex); } return(Task.FromResult(ParseResult.Failed)); }
public override Task <ParseResult> ParseAsync(ChatState state, Chat_ParseField chatParseField, ChatMessage message) { var matches = Regex.Matches(message.UserInput, @"\d+") .Cast <Match>() .Select(m => m.Value) .ToArray(); if (matches.Length == 0) { return(Task.FromResult(ParseResult.Failed)); } var setting = chatParseField?.GetProperty("AllowedValues"); if (String.IsNullOrEmpty(setting)) { return(Task.FromResult(ParseResult.CreateSuccess(int.Parse(matches[0])))); } var allowedValues = setting.Split(',', ' '); var foundValue = allowedValues.Where(b => matches.Any(a => b.Contains(a))).FirstOrDefault(); if (foundValue == null) { return(Task.FromResult(ParseResult.Failed)); } return(Task.FromResult(ParseResult.CreateSuccess(int.Parse(foundValue)))); }
public override async Task <ParseResult> ParseAsync(ChatState chatState, Chat_ParseField chatParseField, ChatMessage message) { int timezoneOffset = chatState.GetUserTimeZoneOffset(); if (message.LuisDateOutput == null) { message.LuisDateOutput = await luisService.Parse(message.UserInput, timezoneOffset); } var assumeFuture = false; if (bool.TryParse(chatParseField?.GetProperty("AssumeFuture"), out bool test)) { assumeFuture = test; } var results = ExtractDateResults(chatState, message.LuisDateOutput, assumeFuture); if ((results == null) || (results.Length == 0)) { logger.InfoFormat("Parse: luis date parser got nothing. - {0}", (message.LuisDateOutput != null) ? JsonConvert.SerializeObject(message.LuisDateOutput) : "null"); return(ParseResult.Failed); } if (version == 1) { return(ProcessAsV1Date(message, timezoneOffset, results)); } return(ParseResult.CreateSuccess(results)); }
public override async Task <ParseResult> ParseAsync(ChatState chatState, Chat_ParseField chatParseField, ChatMessage message) { // Strip PII data string text = filterService.FilterUserData(chatState, message.CorrectedUserInput, false); string classifiers = chatParseField?.GetProperty("Classifiers") ?? defaultClassifier; message.Classifications = await classificationService.ClassifyAsync(classifiers, threshold, text, false, chatState.SessionData.IsSmsChannel); chatState.UpdateLastClassification(message.Classifications); if (message.Classifications.IsSuccessful) { // We don't want common chat intent's here. if (message.Classifications.GetBestResult().Intent.StartsWith("commonchat-")) { return(ParseResult.Failed); } return(ParseResult.CreateSuccess(message.Classifications.GetBestResult().Intent)); } return(ParseResult.Failed); }