コード例 #1
0
        protected override void ExecuteCmdlet()
        {
            var groupId = Team.GetGroupId(HttpClient, AccessToken);

            if (groupId != null)
            {
                var channel = Channel.GetChannel(HttpClient, AccessToken, groupId);
                if (channel != null)
                {
                    var channelMessage = new TeamChannelMessage();
                    channelMessage.Importance       = Important ? "high" : "normal";
                    channelMessage.Body.Content     = Message;
                    channelMessage.Body.ContentType = ContentType == TeamChannelMessageContentType.Html ? "html" : "text";

                    TeamsUtility.PostMessageAsync(HttpClient, AccessToken, groupId, channel.Id, channelMessage).GetAwaiter().GetResult();
                }
                else
                {
                    throw new PSArgumentException("Channel not found");
                }
            }
            else
            {
                throw new PSArgumentException("Team not found");
            }
        }
コード例 #2
0
 public static void PostMessage(HttpClient httpClient, string accessToken, string groupId, string channelId, TeamChannelMessage message)
 {
     GraphHelper.PostAsync(httpClient, $"v1.0/teams/{groupId}/channels/{channelId}/messages", message, accessToken).GetAwaiter().GetResult();
 }
コード例 #3
0
 public static async Task PostMessageAsync(HttpClient httpClient, string accessToken, string groupId, string channelId, TeamChannelMessage message)
 {
     await GraphHelper.PostAsync(httpClient, $"v1.0/teams/{groupId}/channels/{channelId}/messages", message, accessToken);
 }
コード例 #4
0
        public void Initialize()
        {
            if (!TestCommon.AppOnlyTesting())
            {
                const string teamTemplateName = "Sample Engineering Team";
                _teamNames.Add(teamTemplateName);
                _jsonTemplate = "{ \"[email protected]\": \"https://graph.microsoft.com/beta/teamsTemplates(\'standard\')\", \"visibility\": \"Private\", \"displayName\": \"" + teamTemplateName + "\", \"description\": \"This is a sample engineering team, used to showcase the range of properties supported by this API\", \"channels\": [ { \"displayName\": \"Announcements 📢\", \"isFavoriteByDefault\": true, \"description\": \"This is a sample announcements channel that is favorited by default. Use this channel to make important team, product, and service announcements.\" }, { \"displayName\": \"Training 🏋️\", \"isFavoriteByDefault\": true, \"description\": \"This is a sample training channel, that is favorited by default, and contains an example of pinned website and YouTube tabs.\", \"tabs\": [ { \"[email protected]\": \"https://graph.microsoft.com/v1.0/appCatalogs/teamsApps(\'com.microsoft.teamspace.tab.web\')\", \"name\": \"A Pinned Website\", \"configuration\": { \"contentUrl\": \"https://docs.microsoft.com/en-us/microsoftteams/microsoft-teams\" } }, { \"[email protected]\": \"https://graph.microsoft.com/v1.0/appCatalogs/teamsApps(\'com.microsoft.teamspace.tab.youtube\')\", \"name\": \"A Pinned YouTube Video\", \"configuration\": { \"contentUrl\": \"https://tabs.teams.microsoft.com/Youtube/Home/YoutubeTab?videoId=X8krAMdGvCQ\", \"websiteUrl\": \"https://www.youtube.com/watch?v=X8krAMdGvCQ\" } } ] }, { \"displayName\": \"Planning 📅 \", \"description\": \"This is a sample of a channel that is not favorited by default, these channels will appear in the more channels overflow menu.\", \"isFavoriteByDefault\": false }, { \"displayName\": \"Issues and Feedback 🐞\", \"description\": \"This is a sample of a channel that is not favorited by default, these channels will appear in the more channels overflow menu.\" } ], \"memberSettings\": { \"allowCreateUpdateChannels\": true, \"allowDeleteChannels\": true, \"allowAddRemoveApps\": true, \"allowCreateUpdateRemoveTabs\": true, \"allowCreateUpdateRemoveConnectors\": true }, \"guestSettings\": { \"allowCreateUpdateChannels\": false, \"allowDeleteChannels\": false }, \"funSettings\": { \"allowGiphy\": true, \"giphyContentRating\": \"Moderate\", \"allowStickersAndMemes\": true, \"allowCustomMemes\": true }, \"messagingSettings\": { \"allowUserEditMessages\": true, \"allowUserDeleteMessages\": true, \"allowOwnerDeleteMessages\": true, \"allowTeamMentions\": true, \"allowChannelMentions\": true }, \"installedApps\": [ { \"[email protected]\": \"https://graph.microsoft.com/v1.0/appCatalogs/teamsApps(\'com.microsoft.teamspace.tab.vsts\')\" }, { \"[email protected]\": \"https://graph.microsoft.com/v1.0/appCatalogs/teamsApps(\'1542629c-01b3-4a6d-8f76-1938b779e48d\')\" } ] }";

                const string teamName = @"Unallowed &_,.;:/\""!@$%^*[]+=&'|<>{}-()?#¤`´~¨ Ääkköset";
                _teamNames.Add(teamName);
                var security = new TeamSecurity
                {
                    AllowToAddGuests = false,
                    Owners           = { new TeamSecurityUser {
                                             UserPrincipalName = ConfigurationManager.AppSettings["SPOUserName"]
                                         } }
                };
                var funSettings = new TeamFunSettings
                {
                    AllowCustomMemes      = true,
                    AllowGiphy            = true,
                    AllowStickersAndMemes = true,
                    GiphyContentRating    = TeamGiphyContentRating.Moderate
                };
                var guestSettings = new TeamGuestSettings
                {
                    AllowCreateUpdateChannels = false,
                    AllowDeleteChannels       = false
                };
                var memberSettings = new TeamMemberSettings
                {
                    AllowDeleteChannels               = false,
                    AllowAddRemoveApps                = true,
                    AllowCreateUpdateChannels         = true,
                    AllowCreateUpdateRemoveConnectors = false,
                    AllowCreateUpdateRemoveTabs       = true
                };
                var messagingSettings = new TeamMessagingSettings
                {
                    AllowChannelMentions     = true,
                    AllowOwnerDeleteMessages = true,
                    AllowTeamMentions        = false,
                    AllowUserDeleteMessages  = true,
                    AllowUserEditMessages    = true
                };
                var channel = new TeamChannel
                {
                    DisplayName         = "Another channel",
                    Description         = "Another channel description!",
                    IsFavoriteByDefault = true
                };
                var tab = new TeamTab
                {
                    DisplayName = "OneNote Tab",
                    TeamsAppId  = "0d820ecd-def2-4297-adad-78056cde7c78"/*,
                                                                         * Configuration = new TeamTabConfiguration
                                                                         * {
                                                                         * ContentUrl = "https://todo-improve-this-test-when-tab-resource-provisioning-has-been-implemented"
                                                                         * }*/
                };
                channel.Tabs.Add(tab);
                var message = new TeamChannelMessage
                {
                    Message = "Welcome to this awesome new channel!"
                };
                channel.Messages.Add(message);

                _team = new Team {
                    DisplayName = teamName, Description = "Testing creating mailNickname from a display name that has unallowed and accented characters", Visibility = TeamVisibility.Public, Security = security, FunSettings = funSettings, GuestSettings = guestSettings, MemberSettings = memberSettings, MessagingSettings = messagingSettings, Channels = { channel }
                };
            }
        }
コード例 #5
0
        private static string CreateTeamChannelMessage(PnPMonitoredScope scope, TokenParser parser, TeamChannelMessage message, string teamId, string channelId, string accessToken)
        {
            var messageString = parser.ParseString(message.Message);
            var messageJson   = JToken.Parse($"{{ \"body\": {{ \"content\": \"{messageString}\" }} }}");

            var messageId = GraphHelper.CreateOrUpdateGraphObject(scope,
                                                                  HttpMethodVerb.POST,
                                                                  $"{GraphHelper.MicrosoftGraphBaseURI}beta/teams/{teamId}/channels/{channelId}/messages",
                                                                  messageJson,
                                                                  HttpHelper.JsonContentType,
                                                                  accessToken,
                                                                  null,
                                                                  null,
                                                                  null,
                                                                  null,
                                                                  CoreResources.Provisioning_ObjectHandlers_Teams_Team_CannotSendMessage,
                                                                  false);

            return(messageId);
        }