Beispiel #1
0
        public async Task <object> PrepareAsync(IActivity item, CancellationToken token)
        {
            this.botData.PrivateConversationData.TryGetValue <bool>(Constants.IsAnsweringKey, out bool isAnswering);

            var messageActivity = item.AsMessageActivity();

            var botAccount = messageActivity?.Recipient;

            if (ConversationHelper.IsUserGoingToAnswerQuestion(messageActivity) || isAnswering)
            {
                return(null);
            }

            if (!ConversationHelper.CanHandleActivity(messageActivity, isAnswering, botAccount))
            {
                return("reset");
            }

            if (messageActivity != null && ConversationHelper.IsBotMentioned(messageActivity, botAccount))
            {
                // removes any mention from the text
                messageActivity.Text = messageActivity.Text.Replace("@" + messageActivity.Recipient.Name, string.Empty).Trim();
            }

            return(await this.inner.PrepareAsync(item, token));
        }
Beispiel #2
0
        public async Task <object> PrepareAsync(IActivity item, CancellationToken token)
        {
            this.botData.PrivateConversationData.TryGetValue <bool>(Constants.IsAnsweringKey, out bool isAnswering);

            var messageActivity = item.AsMessageActivity();

            var botAccount = messageActivity?.Recipient;

            if (ConversationHelper.IsUserGoingToAnswerQuestion(messageActivity) || isAnswering)
            {
                return(null);
            }

            if (!ConversationHelper.CanHandleActivity(messageActivity, isAnswering, botAccount))
            {
                return("reset");
            }

            if (messageActivity != null && (ConversationHelper.IsBotMentioned(messageActivity, botAccount)))
            {
                // removes any mention from the text
                messageActivity.Text = messageActivity.Text.Replace("@" + messageActivity.Recipient.Name, string.Empty).Trim();
            }

            var result = await this.inner.PrepareAsync(item, token) as QnAMakerResult;

            if (result != null && result.Answer.ToLower().StartsWith("dynamic/"))
            {
                switch (result.Answer.Substring(result.Answer.LastIndexOf("/")))
                {
                case "/list":
                    var kb = await this.wikiService.DownloadKb();

                    string questions = kb.QuestionsAndAnswers.OrderBy(x => x.Questions.First()).Aggregate(
                        "I know the answers for the following:\n\r",
                        (current, next) =>
                    {
                        return(current += $"\n\r• {next.Questions.First()}");
                    });

                    result.Answer = questions;
                    break;
                }
            }

            return(result);
        }