/// <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("[S1030] Markdown Builder", "How to use markdown builder."); // 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) { //////////////////////////////////////////////////////////////// // You can build markdown that can be used in Webex Teams API. var md = new MarkdownBuilder(); // Bold md.Append("Hello, Bold ").AppendBold("WebexTeams").Append("!!").AppendLine(); // Italic md.Append("Hello, Italic ").AppendItalic("WebexTeams").Append("!!").AppendLine(); // Link md.AppendParagraphSeparater(); md.AppendBlockQuote("Hi!").AppendLink("This is Link", new Uri("https://www.google.com/")).Append("."); // Block Quote md.AppendParagraphSeparater(); md.AppendBlockQuote("Hi! This is Block Quote."); // Ordered List md.AppendParagraphSeparater(); md.AppendBold("This is Ordered list:").AppendLine(); md.AppendOrderedList("list item 01"); md.AppendOrderedList("list item 02"); md.AppendOrderedList("list item 03"); // Unordered List md.AppendParagraphSeparater(); md.AppendBold("This is Unordered list:").AppendLine(); md.AppendUnorderedList("list item 01"); md.AppendUnorderedList("list item 02"); md.AppendUnorderedList("list item 03"); // Inline Code. md.AppendParagraphSeparater(); md.Append("The ").AppendInLineCode("print(\"Hello, World!!\")").Append(" is inline code."); // Code Block. md.AppendParagraphSeparater(); md.Append("This is Code Block:").AppendLine(); md.BeginCodeBlock() .Append("#include <stdio.h>\n") .Append("\n") .Append("int main(void)\n") .Append("{\n") .Append(" printf(\"Hello, World!!\\n\");\n") .Append("\n") .Append(" return 0;\n") .Append("}\n") .EndCodeBlock(); var r = await teams.CreateMessageAsync(space, md.ToString()); 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); } // Mentioned to All. md.Clear(); md.Append("Hi ").AppendMentionToAll().Append(", this message is mentioned to all in the space."); r = await teams.CreateMessageAsync(space, md.ToString()); 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); } } } }
/// <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("[S1020] Check if a request suceeded or not", "Sample to check if a request suceeded or not, or handle TeamsResultException."); // 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) { ///////////////////////////////////////////////////////////////////// // result.IsSuccessStatus indicates the request succeeded or not. var r = await teams.CreateMessageAsync(space, "This message will be posted."); 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}, TrackingId = {1}", r.HttpStatusCode, r.TrackingId); } ///////////////////////////////////////////////////////////////////// // This request will not succeed because the space id is invalid. r = await teams.CreateMessageAsync("invalid_space_id", "Bacause of invalid space id, this message will not be posted."); 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}, TrackingId = {1}", r.HttpStatusCode, r.TrackingId); } //////////////////////////////////////////////////////////////////////// // result.GetData() throws TeamsResultException on error response. // On the other hands, result.Data does not throw TeamsResultException. try { r = await teams.CreateMessageAsync("invalid_space_id", "Bacause of invalid space id, this message will not be posted."); ///////////////////////////////////////////////////// // This does not throw TeamsResultException. // And empty id will be shown. var message = r.Data; SampleUtil.ShowMessage("Message id by r.Data.Id = {0}", message.Id); ///////////////////////////////////////////////////// // This throws TeamsResultException. // So, the id will not be shown. message = r.GetData(); SampleUtil.ShowMessage("Message id by r.GetData().Id = {0}", message.Id); } catch (TeamsResultException tre) { SampleUtil.ShowMessage("{0}: StatusCode = {1}, TrackingId = {2}", tre.Message, tre.HttpStatusCode, tre.TrackingId); } } } }
/// <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); } } } }