示例#1
0
        public IDictionary <string, IEnumerable <TeamsApp> > GetChannelAppsDictionary()
        {
            Dictionary <string, IEnumerable <TeamsApp> > result = new Dictionary <string, IEnumerable <TeamsApp> >();
            IEnumerable <JObject> channels = GetChannelListItems(Settings.SharePointGroupId, Settings.ChannelListName);
            IEnumerable <JObject> teamsChannelApplistItems = sharePointController.GetListItems(graphClientManager.GetGraphHttpClient(),
                                                                                               Settings.SharePointGroupId, Settings.ChannelAppListName);

            foreach (JObject item in teamsChannelApplistItems)
            {
                string channelid = item["fields"]?[Settings.ChannelAppChannelNameField]?.ToString();
                if (channelid != null)
                {
                    string channelName =
                        channels.FirstOrDefault(x => x["fields"]?["id"]?.ToString() == channelid)["fields"]?
                        [Settings.ChannelNameField]?.ToString();
                    if (!string.IsNullOrWhiteSpace(channelName))
                    {
                        TeamsApp app = new TeamsApp
                        {
                            DisplayName = item["fields"]?[Settings.ChannelAppTabNameField]?.ToString(),
                            Id          = item["fields"]?[Settings.ChannelAppAppIdField]?.ToString()
                        };

                        TeamsAppConfiguration appConfig = new TeamsAppConfiguration
                        {
                            EntityId   = item["fields"]?[Settings.ChannelAppAppEntityIdField]?.ToString(),
                            ContentUrl = item["fields"]?[Settings.ChannelAppContentUrlField]?.ToString(),
                            WebsiteUrl = item["fields"]?[Settings.ChannelAppWebUrlField]?.ToString(),
                            RemoveUrl  = item["fields"]?[Settings.ChannelAppRemoveUrlField]?.ToString()
                        };

                        app.Configuration = appConfig;

                        if (result.ContainsKey(channelName))
                        {
                            ((List <TeamsApp>)result[channelName]).Add(app);
                        }
                        else
                        {
                            List <TeamsApp> appList = new List <TeamsApp>
                            {
                                app
                            };
                            result.Add(channelName, appList);
                        }
                    }
                    else
                    {
                        throw new AutoTeamsStructureException($"Channel name cannot be found in app list for item {item["id"]}");
                    }
                }
            }

            return(result);
        }
        private static async Task <Channel> InitializeTeamInGroupAsync(GraphService graphClient, string groupId, string welcomeMessage)
        {
            // Create the team
            var team = new Team
            {
                GuestSettings = new TeamGuestSettings
                {
                    AllowCreateUpdateChannels = false,
                    AllowDeleteChannels       = false
                }
            };

            await graphClient.CreateTeamAsync(groupId, team);

            logger.Info("Created team");

            // Get channels
            var channels = await graphClient.GetTeamChannelsAsync(groupId);

            // Get "General" channel. Since it is created by default and is the only
            // channel after creation, just get the first result.
            var generalChannel = channels.Value.First();

            // Create welcome message (new thread)
            var welcomeThread = new ChatThread
            {
                RootMessage = new ChatMessage
                {
                    Body = new ItemBody {
                        Content = welcomeMessage
                    }
                }
            };

            await graphClient.CreateChatThreadAsync(groupId, generalChannel.Id, welcomeThread);

            logger.Info("Posted welcome message");

            // Provision pilot channel
            var pilotChannel = new Channel
            {
                DisplayName = "Pilots",
                Description = "Discussion about flightpath, weather, etc."
            };

            await graphClient.CreateTeamChannelAsync(groupId, pilotChannel);

            logger.Info("Created Pilots channel");

            // Provision flight attendants channel
            var flightAttendantsChannel = new Channel
            {
                DisplayName = "Flight Attendants",
                Description = "Discussion about duty assignments, etc."
            };

            await graphClient.CreateTeamChannelAsync(groupId, flightAttendantsChannel);

            logger.Info("Created FA channel");

            // Add the requested team app
            if (!string.IsNullOrEmpty(teamAppId))
            {
                var teamsApp = new TeamsApp
                {
                    Id = teamAppId
                };

                await graphClient.AddAppToTeam(groupId, teamsApp);
            }
            logger.Info("Added app to team");

            // Return the general channel
            return(generalChannel);
        }