/// <summary> /// Entry point. /// </summary> /// <param name="args">args of this app.</param> /// <returns>Task for async.</returns> static async Task MainAsync(string[] args) { /* ******************************************************** * NOTE: THIS IS ONLY A SAMPLE. * I will put most codes in this Main() on purpose. * So, you will be able to understand the sample * after you read it from top to bottom. * You do not need to care about 'SampleUtil' in this code. * The 'SampleUtil' does something tedious. * Only you need to do to understand the sample * is reading this code in Main() from top to bottom. * *********************************************************/ SampleUtil.ShowTitle("[S1040] ListResult Enumerator(Pagination)", "Get first list result, and then get next list result..."); // Load encrypted token that is encrypted by 'S0010SetupSamples'. ProtectedString token = SampleUtil.LoadEncryptedToken(); if (token != null) { //////////////////////////////////////////////////////////////////////////// // Create an instance for Webex Teams API. // As best practice, the instance should be re-used as long as possible. // For bots, the lifetime of the instance typically is almost the same as the lifetime of the app process. var teams = TeamsAPI.CreateVersion1Client(token); ///////////////////////////////////////////////////// // Create 4 temporary spaces for the sample. for (int i = 0; i < 4; i++) { string title = String.Format("Sample Temporary Space-{0} #WebexTeamsAPIClientV1SamplesTemporary", i); SampleUtil.ShowMessage("Create a Space: {0}", title); var r = await teams.CreateSpaceAsync(title); if (r.IsSuccessStatus) { SampleUtil.ShowMessage("Succeeded to create space."); } else { SampleUtil.ShowMessage("Failed to create space, StatusCode = {0}", r.HttpStatusCode); } } ///////////////////////////////////////////////////// // List spaces for each 2 spaces. // In this case, 'max: 2' parameter is set. var e = (await teams.ListSpacesAsync( max: 2, type: SpaceType.Group, sortBy: SpaceSortBy.Created) ).GetListResultEnumerator(); // In this sample, give up iteration after getting 4 spaces. int count = 4; // Iterate list result. while (await e.MoveNextAsync()) { // Get current result. var r = e.CurrentResult; if (r.IsSuccessStatus && r.Data.HasItems) { SampleUtil.ShowMessage("Succeeded to get {0} spaces.", r.Data.ItemCount); foreach (var space in r.Data.Items) { SampleUtil.ShowMessage(" Title: {0}", space.Title); count--; } } if (count <= 0) { break; } } ///////////////////////////////////////////////////// // Clean up the temporary created spaces. SampleUtil.ShowMessage("Cleaning up the temporary created spaces."); var temporarySpaces = new List <Space>(); ///////////////////////////////////////////////////// // Try to find all the temporary created spaces. e = (await teams.ListSpacesAsync(type: SpaceType.Group)).GetListResultEnumerator(); while (await e.MoveNextAsync()) { var r = e.CurrentResult; if (r.IsSuccessStatus && r.Data.HasItems) { foreach (var space in r.Data.Items) { if (space.Title.Contains("#WebexTeamsAPIClientV1SamplesTemporary")) { temporarySpaces.Add(space); } } } } ///////////////////////////////////////////////////// // Delete the temporary created spaces found. foreach (var space in temporarySpaces) { SampleUtil.ShowMessage("Deleting {0}", space.Title); var r = await teams.DeleteSpaceAsync(space); if (r.IsSuccessStatus) { SampleUtil.ShowMessage("Succeeded to delete space."); } else { SampleUtil.ShowMessage("Failed to delete space, StatusCode = {0}", r.HttpStatusCode); } } } }
/// <summary> /// Entry point. /// </summary> /// <param name="args">args of this app.</param> /// <returns>Task for async.</returns> static async Task MainAsync(string[] args) { /* ******************************************************** * NOTE: THIS IS ONLY A SAMPLE. * I will put most codes in this Main() on purpose. * So, you will be able to understand the sample * after you read it from top to bottom. * You do not need to care about 'SampleUtil' in this code. * The 'SampleUtil' does something tedious. * Only you need to do to understand the sample * is reading this code in Main() from top to bottom. * *********************************************************/ SampleUtil.ShowTitle("[S1010] Post a message", "Post a message to Sample space."); // Load encrypted token that is encrypted by 'S0010SetupSamples'. ProtectedString token = SampleUtil.LoadEncryptedToken(); if (token != null) { //////////////////////////////////////////////////////////////////////////// // Create an instance for Webex Teams API. // As best practice, the instance should be re-used as long as possible. // For bots, the lifetime of the instance typically is almost the same as the lifetime of the app process. var teams = TeamsAPI.CreateVersion1Client(token); // Try to find Sample space. var space = await SampleUtil.FindSampleSpaceAsync(teams); if (space != null) { ///////////////////////////////////////////////////////////////// // By default, the API Client posts a message as markdown. var r = await teams.CreateMessageAsync(space, "Hello, **Webex Teams**!!"); if (r.IsSuccessStatus) { SampleUtil.ShowMessage("Succeeded to post a message: Id = {0}", r.Data.Id); } else { SampleUtil.ShowMessage("Failed to post a message: StatusCode = {0}", r.HttpStatusCode); } ///////////////////////////////////////////////////////////////// // To post a message as normal text, use 'textType: MessageTextType.Text' parameter. r = await teams.CreateMessageAsync(space, "Hello, **Webex Teams**!!", textType : MessageTextType.Text); if (r.IsSuccessStatus) { SampleUtil.ShowMessage("Succeeded to post a message: Id = {0}", r.Data.Id); } else { SampleUtil.ShowMessage("Failed to post a message: StatusCode = {0}", r.HttpStatusCode); } } } }