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);
        }
Esempio n. 2
0
        private static async Task <Channel> InitializeTeamInGroupAsync(string groupId, string welcomeMessage)
        {
            // Create the team
            var team = new Team
            {
                GuestSettings = new TeamGuestSettings
                {
                    AllowCreateUpdateChannels = false,
                    AllowDeleteChannels       = false
                }
            };

            await graphClient.CreateTeamAsync(groupId, team);

            logger.LogInformation("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.CurrentPage.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.LogInformation("Posted welcome message");

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

            await graphClient.CreateTeamChannelAsync(groupId, pilotChannel);

            logger.LogInformation("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.LogInformation("Created FA channel");

            // Add the requested team app
            if (!string.IsNullOrEmpty(teamAppId))
            {
                var teamsApp = new TeamsAppInstallation
                {
                    AdditionalData = new Dictionary <string, object>()
                };

                teamsApp.AdditionalData.Add("*****@*****.**",
                                            $"https://graph.microsoft.com/beta/appCatalogs/teamsApps/{teamAppId}");

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

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