Example #1
0
        /// <summary>
        /// Processes an incoming message, raising events accordingly. This is the most important method of all bot functionality.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="isReprocessing">if set to <c>true</c> [is reprocessing].</param>
        private void ProcessMessage(Message message, bool isReprocessing)
        {
            if (!isReprocessing)
            {
                Debug.WriteLine("Bot received: " + message.Content);
                if (this.MessageReceived != null)
                {
                    // raising message received event
                    this.MessageReceived(this, new MessageEventArgs(message));
                }
            }

            message.Content = this.PreProcessMessageContent(message.Content);

            if (this.isCollectingFeedback)
            {
                this.isCollectingFeedback = false;

                FeedbackType feedbackType;
                Reply        feedbackReply = FeedbackEngine.ProcessFeedback(message, this.originalMessage, out feedbackType);
                this.RaiseReplied(feedbackReply, message, ReplyContext.FeedbackResponse, null);

                // If the user didn't provide feedback, we try handling the message again, which will
                // re-start the handling process as the bot is not in feedback collection mode anymore.
                if (feedbackType == FeedbackType.NotProvided)
                {
                    this.ProcessMessage(message, true);
                }

                else if (feedbackType == FeedbackType.Negative)
                {
                    if (!this.GiveUpOnNegativeFeedback)
                    {
                        // The current handler is no good anymore (negative feedback received).
                        this.messageHandlerCandidates.Remove(MessageHandler);

                        // Let's try the other ones!
                        this.ProcessNewMessage(this.originalMessage, this.messageHandlerCandidates);
                    }
                }
            }

            // is this message the start of a new conversation?
            else if (this.isNewConversation)
            {
                this.ConversationReplyCount   = 0;
                this.originalMessage          = message;
                this.messageHandlerCandidates = GetMessageHandlerCandidates(message);
                this.ProcessNewMessage(message, this.messageHandlerCandidates);
            }

            // else, this message is part of an already existent conversation.
            else
            {
                this.InvokeMessageHandler(MessageHandler, message);
            }
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Bot"/> class.
 /// </summary>
 public Bot()
 {
     FeedbackEngine = new FeedbackEngine();
 }