Exemple #1
0
        public async Task <CommonTextResult> Handle(CommonTextRequest request, CancellationToken cancellationToken)
        {
            // Unknown input
            _telemetryClient.TrackTrace($"Handling common message from user: {request.Activity.Text}");

            var activity  = request.Activity;
            var botMsg    = request.BotLastMessage.Message;
            var lastMatch = request.UserMatch;

            var    replyActivity = request.Activity.CreateReply();
            string newbotMessage;

            if (botMsg.Is(BotMessageTypes.FbYesSuperResponse))
            {
                await _repository.FeedbackCommentCreate(
                    lastMatch.SenderEmail,
                    lastMatch.SenderAadId,
                    lastMatch.RecipientEmail,
                    lastMatch.RecipientAadId,
                    FbDetailTypes.Super,
                    FbRootTypes.Yes,
                    activity.Text);

                ReplyAfterComment(replyActivity);
                newbotMessage = BotMessageTypes.FbSuperCommentsAccepted;
            }
            else if (botMsg.Is(BotMessageTypes.FbYesGoodResponse))
            {
                await _repository.FeedbackCommentCreate(
                    lastMatch.SenderEmail,
                    lastMatch.SenderAadId,
                    lastMatch.RecipientEmail,
                    lastMatch.RecipientAadId,
                    FbDetailTypes.Good,
                    FbRootTypes.Yes,
                    activity.Text);

                ReplyAfterComment(replyActivity);
                newbotMessage = BotMessageTypes.FbGoodCommentsAccepted;
            }
            else if (botMsg.Is(BotMessageTypes.FbYesBadResponse))
            {
                await _repository.FeedbackCommentCreate(
                    lastMatch.SenderEmail,
                    lastMatch.SenderAadId,
                    lastMatch.RecipientEmail,
                    lastMatch.RecipientAadId,
                    FbDetailTypes.Bad,
                    FbRootTypes.Yes,
                    activity.Text);

                ReplyAfterComment(replyActivity);
                newbotMessage = BotMessageTypes.FbBadCommentsAccepted;
            }
            else if (botMsg.Is(BotMessageTypes.FbNoCanceledResponse))
            {
                await _repository.FeedbackCommentCreate(
                    lastMatch.SenderEmail,
                    lastMatch.SenderAadId,
                    lastMatch.RecipientEmail,
                    lastMatch.RecipientAadId,
                    FbDetailTypes.Canceled,
                    FbRootTypes.No,
                    activity.Text);

                ReplyAfterComment(replyActivity);
                newbotMessage = BotMessageTypes.FbCanceledCommentsAccepted;
            }
            else if (botMsg.Is(BotMessageTypes.FbNoGoodTimeResponse))
            {
                await _repository.FeedbackCommentCreate(
                    lastMatch.SenderEmail,
                    lastMatch.SenderAadId,
                    lastMatch.RecipientEmail,
                    lastMatch.RecipientAadId,
                    FbDetailTypes.NoGoodTime,
                    FbRootTypes.No,
                    activity.Text);

                ReplyAfterComment(replyActivity);
                newbotMessage = BotMessageTypes.FbNoGoodTimeCommentsAccepted;
            }
            else if (botMsg.Is(BotMessageTypes.FbNoAnotherReasonResponse))
            {
                await _repository.FeedbackCommentCreate(
                    lastMatch.SenderEmail,
                    lastMatch.SenderAadId,
                    lastMatch.RecipientEmail,
                    lastMatch.RecipientAadId,
                    FbDetailTypes.NoAnother,
                    FbRootTypes.No,
                    activity.Text);

                ReplyAfterComment(replyActivity);
                newbotMessage = BotMessageTypes.FbAnotherReasonCommentsAccepted;
            }
            else
            {
                if (botMsg.Is(BotMessageTypes.Fb) ||
                    botMsg.Is(BotMessageTypes.FbRootYesDetails) ||
                    botMsg.Is(BotMessageTypes.FbRootNoDetails) ||
                    botMsg.Is(BotMessageTypes.FbRootUnknownAnswer) ||
                    botMsg.Is(BotMessageTypes.FbYesUnknownAnswer) ||
                    botMsg.Is(BotMessageTypes.FbNoUnknownAnswerResponse))
                {
                    ReplyUnknownChooseAnswer(replyActivity);
                    if (botMsg.Is(BotMessageTypes.Fb))
                    {
                        newbotMessage = BotMessageTypes.FbRootUnknownAnswer;
                    }
                    else if (botMsg.Is(BotMessageTypes.FbRootYesDetails))
                    {
                        newbotMessage = BotMessageTypes.FbYesUnknownAnswer;
                    }
                    else if (botMsg.Is(BotMessageTypes.FbRootNoDetails))
                    {
                        newbotMessage = BotMessageTypes.FbNoUnknownAnswerResponse;
                    }
                    else
                    {
                        newbotMessage = botMsg;
                    }
                }
                else
                {
                    await _repository.UnknownMessageCreate(lastMatch.SenderEmail, lastMatch.SenderAadId, activity.Text);

                    ReplyBye(replyActivity);
                    newbotMessage = BotMessageTypes.ByeForNextPeriod;
                }
            }

            return(new CommonTextResult
            {
                Reply = replyActivity,
                NewBotMessage = newbotMessage
            });

            //var unrecognizedInputAdaptiveCard = UnrecognizedInputAdaptiveCard.GetCard();
            //replyActivity.Attachments = new List<Attachment>()
            //{
            //    new Attachment()
            //    {
            //        ContentType = "application/vnd.microsoft.card.adaptive",
            //        Content = JsonConvert.DeserializeObject(unrecognizedInputAdaptiveCard)
            //    }
            //};
        }