/// <summary> /// Handle message activity 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="onCallSupportDetailSearchService">Provider to search on call support details in Azure Table Storage.</param> /// <param name="ticketDetailStorageProvider">Provider to store ticket details to Azure Table Storage.</param> /// <param name="cardConfigurationStorageProvider">Provider to search card configuration details in Azure Table Storage.</param> /// <param name="logger">Sends logs to the Application Insights service.</param> /// <param name="appBaseUrl">Represents the Application base Uri.</param> /// <param name="localizer">The current cultures' string localizer.</param> /// <param name="cancellationToken">Propagates notification that operations should be canceled.</param> /// <returns>A task that represents the work queued to execute.</returns> internal static async Task OnMessageActivityInChannelAsync( IMessageActivity message, ITurnContext <IMessageActivity> turnContext, IOnCallSupportDetailSearchService onCallSupportDetailSearchService, ITicketDetailStorageProvider ticketDetailStorageProvider, ICardConfigurationStorageProvider cardConfigurationStorageProvider, ILogger logger, string appBaseUrl, IStringLocalizer <Strings> localizer, CancellationToken cancellationToken) { turnContext = turnContext ?? throw new ArgumentNullException(nameof(turnContext)); if (!string.IsNullOrEmpty(message.ReplyToId) && message.Value != null && ((JObject)message.Value).HasValues) { logger.LogInformation($"Card submit in channel {message.Value?.ToString()}"); await OnAdaptiveCardSubmitInChannelAsync(message : message, turnContext : turnContext, ticketDetailStorageProvider : ticketDetailStorageProvider, cardConfigurationStorageProvider : cardConfigurationStorageProvider, logger : logger, appBaseUrl : appBaseUrl, localizer : localizer, cancellationToken : cancellationToken); return; } turnContext.Activity.RemoveRecipientMention(); string text = turnContext.Activity.Text.Trim(); switch (text.ToUpperInvariant()) { case Constants.ManageExpertsAction: // Get on call support data from storage var onCallSupportDetails = await onCallSupportDetailSearchService.SearchOnCallSupportTeamAsync(searchQuery : string.Empty, count : 10); var onCallSMEDetailActivity = MessageFactory.Attachment(OnCallSMEDetailCard.GetOnCallSMEDetailCard(onCallSupportDetails, localizer)); var result = await turnContext.SendActivityAsync(onCallSMEDetailActivity); // Add activityId in the data which will be posted to task module in future after clicking on Manage button. AdaptiveCard adaptiveCard = (AdaptiveCard)onCallSMEDetailActivity.Attachments?[0].Content; AdaptiveCardAction cardAction = (AdaptiveCardAction)((AdaptiveSubmitAction)adaptiveCard?.Actions?[0]).Data; cardAction.ActivityId = result.Id; // Refresh manage experts card with activity Id bound to manage button. onCallSMEDetailActivity.Id = result.Id; onCallSMEDetailActivity.ReplyToId = result.Id; await turnContext.UpdateActivityAsync(onCallSMEDetailActivity); break; default: logger.LogInformation("Unrecognized input in channel."); await turnContext.SendActivityAsync(MessageFactory.Attachment(WelcomeTeamCard.GetCard(appBaseUrl, localizer))); break; } }
// Handle members added conversationUpdate event in team private async Task OnMembersAddedToTeamAsync(IList <ChannelAccount> membersAdded, ITurnContext <IConversationUpdateActivity> turnContext, CancellationToken cancellationToken) { var activity = turnContext.Activity; if (membersAdded.Any(m => m.Id == activity.Recipient.Id)) { // Bot was added to a team this.telemetryClient.TrackTrace($"Bot added to team {activity.Conversation.Id}"); var teamDetails = ((JObject)turnContext.Activity.ChannelData).ToObject <TeamsChannelData>(); var botDisplayName = turnContext.Activity.Recipient.Name; var teamWelcomeCardAttachment = WelcomeTeamCard.GetCard(); await this.SendCardToTeamAsync(turnContext, teamWelcomeCardAttachment, teamDetails.Team.Id, cancellationToken); } }
/// <summary> /// Sends welcome card in teams chat. /// </summary> /// <param name="membersAdded">Channel account information needed to route a message.</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 SendWelcomeCardInTeamChatAsync( IList <ChannelAccount> membersAdded, ITurnContext <IConversationUpdateActivity> turnContext, CancellationToken cancellationToken) { var activity = turnContext.Activity; if (membersAdded.Any(channelAccount => channelAccount.Id == activity.Recipient.Id)) { // Bot was added to a team this.logger.LogInformation($"Bot added to team {activity.Conversation.Id}"); var teamDetails = ((JObject)turnContext.Activity.ChannelData).ToObject <TeamsChannelData>(); var botDisplayName = turnContext.Activity.Recipient.Name; var teamWelcomeCardAttachment = WelcomeTeamCard.GetCard(); await this.notificationService.NotifyInTeamChatAsync(turnContext, teamWelcomeCardAttachment, teamDetails.Team.Id, cancellationToken).ConfigureAwait(false); } }
/// <summary> /// Handle members added conversationUpdate event in team. /// </summary> /// <param name="membersAdded">Channel account information needed to route a message.</param> /// <param name="turnContext">Context object containing information cached for a single turn of conversation with a user.</param> /// <param name="microsoftAppCredentials">Microsoft Application credentials for Bot/ME.</param> /// <param name="logger">Sends logs to the Application Insights service.</param> /// <param name="appBaseUrl">Represents the Application base Uri.</param> /// <param name="localizer">The current cultures' string localizer.</param> /// <param name="cancellationToken">Propagates notification that operations should be canceled.</param> /// <returns>A task that represents the work queued to execute.</returns> internal static async Task OnMembersAddedToTeamAsync( IList <ChannelAccount> membersAdded, ITurnContext <IConversationUpdateActivity> turnContext, MicrosoftAppCredentials microsoftAppCredentials, ILogger logger, string appBaseUrl, IStringLocalizer <Strings> localizer, CancellationToken cancellationToken) { turnContext = turnContext ?? throw new ArgumentNullException(nameof(turnContext)); var activity = turnContext.Activity; if (membersAdded.Any(channelAccount => channelAccount.Id == activity.Recipient.Id)) { // Bot was added to a team logger.LogInformation($"Bot added to team {activity.Conversation.Id}"); var teamDetails = ((JObject)turnContext.Activity.ChannelData).ToObject <TeamsChannelData>(); var teamWelcomeCardAttachment = WelcomeTeamCard.GetCard(appBaseUrl, localizer); await CardHelper.SendCardToTeamAsync(turnContext, teamWelcomeCardAttachment, teamDetails.Team.Id, microsoftAppCredentials, cancellationToken); } }