Exemplo n.º 1
0
        /// <summary>
        /// Handles a user statement.
        /// </summary>
        /// <param name="userInput">The user input.</param>
        /// <returns>The response to the user statement</returns>
        public UserStatementResponse HandleUserStatement(string userInput)
        {
            var response = new UserStatementResponse();

            LastInput = userInput;
            LastResponse = response;

            return response;
        }
Exemplo n.º 2
0
        private UserStatementResponse HandleUserStatementInternal(
            [NotNull] string userInput,
            bool saveToLog = true)
        {
            //- Log the input to the diagnostic log.
            Console?.Log(Resources.ChatInputHeader, userInput, LogLevel.UserInput);

            // Store the input in chat history (only if we're logging it)
            if (saveToLog) { AddHistoryEntry(_user, userInput); }

            // Give our input to the chat ChatEngine
            var result = GetChatResult(userInput);

            //- If it's a catastrophic failure, return a nearly empty object without storing the null response
            if (result == null)
            {
                return new UserStatementResponse(userInput,
                                                 Resources.DefaultFailureResponseText,
                                                 string.Empty,
                                                 ChatCommand.Empty,
                                                 null);
            }

            // Get the template out of the response so we can see if there are any OOB instructions
            var template = GetResponseTemplate(result);

            // Log and store the response
            var output = result.Output;
            if (!string.IsNullOrWhiteSpace(output))
            {
                Console?.Log(Resources.ChatOutputHeader, output, LogLevel.ChatResponse);

                AddHistoryEntry(ChatEngine.SystemUser, output, result);
            }

            //- Log the output to the diagnostic log. Sometimes - for redirect commands / etc. there's no response
            if (!string.IsNullOrWhiteSpace(template))
            {
                Console?.Log(Resources.ChatOutputHeader,
                             string.Format(CultureInfo.CurrentCulture,
                                           Resources.AimlStatementHandlerUsingTemplate.NonNull(),
                                           template),
                             LogLevel.Verbose);
            }

            //- Update query properties and return the result
            var response = new UserStatementResponse(userInput, output, template, ChatCommand.Empty, result);
            LastResponse = response;

            return response;
        }