/// <summary> /// Invoked when a message activity is received from the bot. /// </summary> /// <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> protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) { try { turnContext = turnContext ?? throw new ArgumentNullException(nameof(turnContext)); var activity = turnContext.Activity; if (!string.IsNullOrEmpty(activity.Text)) { var command = activity.RemoveRecipientMention().Trim(); switch (command.ToUpperInvariant()) { case Constants.HelpCommand: // Help command to get the information about the bot. this.logger.LogInformation("Sending user help card."); var userHelpCards = CarouselCard.GetUserHelpCards(this.options.Value.AppBaseUri); await turnContext.SendActivityAsync(MessageFactory.Carousel(userHelpCards)).ConfigureAwait(false); break; case Constants.PreferenceSettings: // Preference command to get the card to setup the tags preference of a team. await turnContext.SendActivityAsync(MessageFactory.Attachment(WelcomeCard.GetPreferenceCard(localizer: this.localizer)), cancellationToken).ConfigureAwait(false); break; default: this.logger.LogInformation($"Received a command {command.ToUpperInvariant()} which is not supported."); break; } } } catch (Exception ex) { this.logger.LogError(ex, "Error while message activity is received from the bot."); throw; } }
/// <summary> /// Invoked when a message activity is received from the bot. /// </summary> /// <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> protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) { try { turnContext = turnContext ?? throw new ArgumentNullException(nameof(turnContext)); var message = turnContext.Activity; message = message ?? throw new NullReferenceException(nameof(message)); if (message.Conversation.ConversationType == Constants.ChannelConversationType) { var command = message.RemoveRecipientMention().Trim(); switch (command.ToUpperInvariant()) { case Constants.PreferenceSettings: // Preference command to get the card to setup the category preference of a team. await turnContext.SendActivityAsync(MessageFactory.Attachment(WelcomeCard.GetPreferenceCard(localizer: this.localizer)), cancellationToken); break; default: this.logger.LogInformation($"Received a command {command.ToUpperInvariant()} which is not supported."); await turnContext.SendActivityAsync(MessageFactory.Text(this.localizer.GetString("UnsupportedBotCommandText"))); break; } } else { this.logger.LogInformation($"Received a command which is not supported."); await turnContext.SendActivityAsync(MessageFactory.Text(this.localizer.GetString("UnsupportedBotPersonalCommandText"))); } } catch (Exception ex) { this.logger.LogError(ex, "Error while message activity is received from the bot."); throw; } }