/// <summary> /// Called when a message is received by the dialog /// </summary> private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result) { var activity = await result as Activity; string message = string.Empty; if (activity.Text != null) { message = Microsoft.Bot.Connector.Teams.ActivityExtensions.GetTextWithoutMentions(activity).ToLowerInvariant(); } // Check if User or Team is registered in the database, and store the information in ConversationData for quick retrieval later. string profileKey = GetKey(activity, Constants.ProfileKey); User userDetails = null; var channelData = context.Activity.GetChannelData <TeamsChannelData>(); var emailId = await GetUserEmailId(activity); Tenant tenantData = await Common.CheckAndAddTenantDetails(channelData.Tenant.Id); Role role = Common.GetUserRole(emailId, tenantData); if (context.ConversationData.ContainsKey(profileKey)) { userDetails = context.ConversationData.GetValue <User>(profileKey); } else { userDetails = await CheckAndAddUserDetails(activity, channelData); context.ConversationData.SetValue(profileKey, userDetails); } if (!tenantData.IsAdminConsented) { if (channelData.Team == null) { await SendOAuthCardAsync(context, activity); } else { var reply = activity.CreateReply(); reply.Attachments.Add(CardHelper.GetCardForNonConsentedTenant()); await context.PostAsync(reply); } return; } if (activity.Attachments != null && activity.Attachments.Any(a => a.ContentType == FileDownloadInfo.ContentType)) { // Excel file with tenant-level group information was uploaded: update the tenant info in the database var attachment = activity.Attachments.First(); await HandleExcelAttachement(context, attachment, channelData); } else if (activity.Value != null) { // Handle clicks on adaptive card buttons, whether from a card in the conversation, or in a task module await HandleActions(context, activity, tenantData, userDetails); } else { if (message.ToLowerInvariant().Contains("refresh photos") && role == Role.Admin) { await RefreshProfilePhotos(context, activity, tenantData, userDetails); } else if (message.ToLowerInvariant().Contains("clear cache")) { await ClearCache(context); } else { var reply = activity.CreateReply(); if (channelData.Team != null) { if (message != Constants.ShowWelcomeScreen.ToLower()) { reply.Text = "Announcements app is notification only in teams and channels. Please use the app in 1:1 chat to interact meaningfully."; await context.PostAsync(reply); return; } } if (tenantData.Admin == userDetails.Id || tenantData.Moderators.Contains(userDetails.Id)) { reply.Attachments.Add(CardHelper.GetWelcomeScreen(channelData.Team != null, role)); } else { reply.Attachments.Add(CardHelper.GetWelcomeScreen(channelData.Team != null, role)); } await context.PostAsync(reply); } } }