// Handle message activity in channel
        private async Task OnMessageActivityInChannelAsync(IMessageActivity message, ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            if (!string.IsNullOrEmpty(message.ReplyToId) && (message.Value != null) && ((JObject)message.Value).HasValues)
            {
                this.telemetryClient.TrackTrace("Card submit in channel");
                await this.OnAdaptiveCardSubmitInChannelAsync(message, turnContext, cancellationToken);

                return;
            }

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

            switch (text)
            {
            case TeamTour:
                this.telemetryClient.TrackTrace("Sending team tour card");
                var teamTourCards = TourCarousel.GetTeamTourCards(this.appBaseUri);
                await turnContext.SendActivityAsync(MessageFactory.Carousel(teamTourCards));

                break;

            default:
                this.telemetryClient.TrackTrace("Unrecognized input in channel");
                var unrecognizedInputCard = UnrecognizedTeamInputCard.GetCard();
                await turnContext.SendActivityAsync(MessageFactory.Attachment(unrecognizedInputCard));

                break;
            }
        }
Esempio n. 2
0
        // Handle message activity in channel
        private async Task OnMessageActivityInChannelAsync(IMessageActivity message, ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            if (!string.IsNullOrEmpty(message.ReplyToId) && (message.Value != null) && ((JObject)message.Value).HasValues)
            {
                this.telemetryClient.TrackTrace("Card submit in channel");
                await this.OnAdaptiveCardSubmitInChannelAsync(message, turnContext, cancellationToken);

                return;
            }

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

            if (text.Equals(Resource.ResourceManager.GetString("TakeATeamTourButtonText", CultureInfo.CurrentCulture), StringComparison.InvariantCultureIgnoreCase))
            {
                this.telemetryClient.TrackTrace("Sending team tour card");
                var teamTourCards = TourCarousel.GetTeamTourCards(this.appBaseUri);
                await turnContext.SendActivityAsync(MessageFactory.Carousel(teamTourCards));
            }
            else
            {
                this.telemetryClient.TrackTrace("Unrecognized input in channel");
                var unrecognizedInputCard = UnrecognizedTeamInputCard.GetCard();
                await turnContext.SendActivityAsync(MessageFactory.Attachment(unrecognizedInputCard));
            }
        }
        /// <summary>
        /// Resolves bot commands in channel.
        /// </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 ResolveBotCommandInTeamChatAsync(
            IMessageActivity message,
            ITurnContext <IMessageActivity> turnContext,
            CancellationToken cancellationToken)
        {
            string text;

            // Check if the incoming request is from SME for updating the ticket status.
            if (!string.IsNullOrEmpty(message.ReplyToId) && (message.Value != null) && ((JObject)message.Value).HasValues && !string.IsNullOrEmpty(((JObject)message.Value)["ticketId"]?.ToString()))
            {
                text = ChangeStatus ?? throw new ArgumentNullException(nameof(ChangeStatus));
            }
            else
            {
                text = message.Text?.ToLower()?.Trim() ?? string.Empty;
            }

            try
            {
                switch (text)
                {
                case Constants.TeamTour:
                    this.logger.LogInformation("Sending team tour card");
                    var teamTourCards = TourCarousel.GetTeamTourCards(this.appBaseUri);
                    await turnContext.SendActivityAsync(MessageFactory.Carousel(teamTourCards)).ConfigureAwait(false);

                    break;

                case ChangeStatus:
                    this.logger.LogInformation($"Card submit in channel {message.Value?.ToString()}");
                    await this.conversationService.SendAdaptiveCardInTeamChatAsync(message, turnContext, cancellationToken).ConfigureAwait(false);

                    return;

                case Constants.DeleteCommand:
                    this.logger.LogInformation($"Delete card submit in channel {message.Value?.ToString()}");
                    await QnaHelper.DeleteQnaPair(turnContext, this.qnaServiceProvider, this.activityStorageProvider, this.logger, cancellationToken).ConfigureAwait(false);

                    break;

                case Constants.NoCommand:
                    return;

                default:
                    this.logger.LogInformation("Unrecognized input in channel");
                    await turnContext.SendActivityAsync(MessageFactory.Attachment(UnrecognizedTeamInputCard.GetCard())).ConfigureAwait(false);

                    break;
                }
            }
            catch (Exception ex)
            {
                // Check if expert user is trying to delete the question and knowledge base has not published yet.
                if (((ErrorResponseException)ex).Response.StatusCode == HttpStatusCode.BadRequest)
                {
                    var knowledgeBaseId = await this.configurationProvider.GetSavedEntityDetailAsync(Constants.KnowledgeBaseEntityId).ConfigureAwait(false);

                    var hasPublished = await this.qnaServiceProvider.GetInitialPublishedStatusAsync(knowledgeBaseId).ConfigureAwait(false);

                    // Check if knowledge base has not published yet.
                    if (!hasPublished)
                    {
                        var activity      = (Activity)turnContext.Activity;
                        var activityValue = ((JObject)activity.Value).ToObject <AdaptiveSubmitActionData>();
                        await turnContext.SendActivityAsync(MessageFactory.Text(string.Format(CultureInfo.InvariantCulture, Strings.WaitMessage, activityValue?.OriginalQuestion))).ConfigureAwait(false);

                        this.logger.LogError(ex, $"Error processing message: {ex.Message}", SeverityLevel.Error);
                        return;
                    }
                }

                // Throw the error at calling place, if there is any generic exception which is not caught by above conditon.
                throw;
            }
        }