コード例 #1
0
        /// <summary>
        /// Handle adaptive card submit in 1:1 chat.
        /// Submits the question or feedback to the SME team.
        /// </summary>
        /// <param name="message">A message in a conversation.</param>
        /// <param name="turnContext">Context object containing information cached for a single turn of conversation with a user.</param>
        /// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
        /// <returns>A task that represents the work queued to execute.</returns>
        public async Task SendAdaptiveCardInPersonalChatAsync(
            IMessageActivity message,
            ITurnContext <IMessageActivity> turnContext,
            CancellationToken cancellationToken)
        {
            Attachment   smeTeamCard = null;    // Notification to SME team
            Attachment   userCard    = null;    // Acknowledgement to the user
            TicketEntity newTicket   = null;    // New ticket

            string text = (message.Text ?? string.Empty).Trim();

            switch (text)
            {
            // Sends user ask an expert card from the answer card.
            case Constants.AskAnExpert:
                this.logger.LogInformation("Sending user ask an expert card (from answer)");
                var askAnExpertPayload = ((JObject)message.Value).ToObject <ResponseCardPayload>();
                await this.SendActivityInChatAsync(turnContext, MessageFactory.Attachment(AskAnExpertCard.GetCard(askAnExpertPayload)), cancellationToken);

                break;

            // Sends user the feedback card from the answer card.
            case Constants.ShareFeedback:
                this.logger.LogInformation("Sending user share feedback card (from answer)");
                var shareFeedbackPayload = ((JObject)message.Value).ToObject <ResponseCardPayload>();
                await this.SendActivityInChatAsync(turnContext, MessageFactory.Attachment(ShareFeedbackCard.GetCard(shareFeedbackPayload)), cancellationToken);

                break;

            // User submits the ask an expert card.
            case Constants.AskAnExpertSubmitText:
                this.logger.LogInformation("Received question for expert");
                newTicket = await AdaptiveCardHelper.AskAnExpertSubmitText(message, turnContext, cancellationToken, this.ticketsProvider).ConfigureAwait(false);

                if (newTicket != null)
                {
                    smeTeamCard = new SmeTicketCard(newTicket).ToAttachment();
                    userCard    = new UserNotificationCard(newTicket).ToAttachment(Strings.NotificationCardContent);
                }

                break;

            // User submits the share feedback card.
            case Constants.ShareFeedbackSubmitText:
                this.logger.LogInformation("Received app feedback");
                smeTeamCard = await AdaptiveCardHelper.ShareFeedbackSubmitText(message, turnContext, cancellationToken).ConfigureAwait(false);

                if (smeTeamCard != null)
                {
                    await this.SendActivityInChatAsync(turnContext, MessageFactory.Text(Strings.ThankYouTextContent), cancellationToken);
                }

                break;

            default:
                var payload = ((JObject)message.Value).ToObject <ResponseCardPayload>();

                if (payload.IsPrompt)
                {
                    this.logger.LogInformation("Sending input to QnAMaker for prompt");
                    await this.qnaPairServiceFacade.GetReplyToQnAAsync(turnContext, message).ConfigureAwait(false);
                }
                else
                {
                    this.logger.LogWarning($"Unexpected text in submit payload: {message.Text}");
                }

                break;
            }

            string expertTeamId = await this.configurationProvider.GetSavedEntityDetailAsync(ConfigurationEntityTypes.TeamId).ConfigureAwait(false);

            // Send message to SME team.
            if (smeTeamCard != null)
            {
                await this.SendTicketCardToSMETeamAsync(turnContext, smeTeamCard, expertTeamId, cancellationToken, newTicket);
            }

            // Send acknowledgment to the user
            if (userCard != null)
            {
                await this.SendActivityInChatAsync(turnContext, MessageFactory.Attachment(userCard), cancellationToken);
            }
        }
コード例 #2
0
        /// <summary>
        /// Handle adaptive card submit in 1:1 chat.
        /// Submits the question or feedback to the SME team.
        /// </summary>
        /// <param name="message">A message in a conversation.</param>
        /// <param name="turnContext">Context object containing information cached for a single turn of conversation with a user.</param>
        /// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
        /// <returns>A task that represents the work queued to execute.</returns>
        private async Task OnAdaptiveCardSubmitInPersonalChatAsync(
            IMessageActivity message,
            ITurnContext <IMessageActivity> turnContext,
            CancellationToken cancellationToken)
        {
            Attachment   smeTeamCard = null;    // Notification to SME team
            Attachment   userCard    = null;    // Acknowledgement to the user
            TicketEntity newTicket   = null;    // New ticket

            switch (message?.Text)
            {
            case Constants.AskAnExpert:
                this.logger.LogInformation("Sending user ask an expert card (from answer)");
                var askAnExpertPayload = ((JObject)message.Value).ToObject <ResponseCardPayload>();
                await turnContext.SendActivityAsync(MessageFactory.Attachment(AskAnExpertCard.GetCard(askAnExpertPayload))).ConfigureAwait(false);

                break;

            case Constants.ShareFeedback:
                this.logger.LogInformation("Sending user share feedback card (from answer)");
                var shareFeedbackPayload = ((JObject)message.Value).ToObject <ResponseCardPayload>();
                await turnContext.SendActivityAsync(MessageFactory.Attachment(ShareFeedbackCard.GetCard(shareFeedbackPayload))).ConfigureAwait(false);

                break;

            case AskAnExpertCard.AskAnExpertSubmitText:
                this.logger.LogInformation("Received question for expert");
                newTicket = await AdaptiveCardHelper.AskAnExpertSubmitText(message, turnContext, cancellationToken, this.ticketsProvider).ConfigureAwait(false);

                if (newTicket != null)
                {
                    smeTeamCard = new SmeTicketCard(newTicket).ToAttachment(message?.LocalTimestamp);
                    userCard    = new UserNotificationCard(newTicket).ToAttachment(Strings.NotificationCardContent, message?.LocalTimestamp);
                }

                break;

            case ShareFeedbackCard.ShareFeedbackSubmitText:
                this.logger.LogInformation("Received app feedback");
                smeTeamCard = await AdaptiveCardHelper.ShareFeedbackSubmitText(message, turnContext, cancellationToken).ConfigureAwait(false);

                if (smeTeamCard != null)
                {
                    await turnContext.SendActivityAsync(MessageFactory.Text(Strings.ThankYouTextContent)).ConfigureAwait(false);
                }

                break;

            default:
                var payload = ((JObject)message.Value).ToObject <ResponseCardPayload>();

                if (payload.IsPrompt)
                {
                    this.logger.LogInformation("Sending input to QnAMaker for prompt");
                    await this.GetQuestionAnswerReplyAsync(turnContext, message).ConfigureAwait(false);
                }
                else
                {
                    this.logger.LogWarning($"Unexpected text in submit payload: {message.Text}");
                }

                break;
            }

            string expertTeamId = await this.configurationProvider.GetSavedEntityDetailAsync(ConfigurationEntityTypes.TeamId).ConfigureAwait(false);

            // Send message to SME team.
            if (smeTeamCard != null)
            {
                var resourceResponse = await this.SendCardToTeamAsync(turnContext, smeTeamCard, expertTeamId, cancellationToken).ConfigureAwait(false);

                // If a ticket was created, update the ticket with the conversation info.
                if (newTicket != null)
                {
                    newTicket.SmeCardActivityId       = resourceResponse.ActivityId;
                    newTicket.SmeThreadConversationId = resourceResponse.Id;
                    await this.ticketsProvider.UpsertTicketAsync(newTicket).ConfigureAwait(false);
                }
            }

            // Send acknowledgment to the user
            if (userCard != null)
            {
                await turnContext.SendActivityAsync(MessageFactory.Attachment(userCard), cancellationToken).ConfigureAwait(false);
            }
        }