Skip to content

Commit

Permalink
Merge branch 'release/0.86.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jericho committed Dec 19, 2024
2 parents 57f9d98 + fa260ab commit 59f0341
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 116 deletions.
84 changes: 34 additions & 50 deletions Source/ZoomNet.IntegrationTests/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using Logzio.DotNet.NLog;
using Formitable.BetterStack.Logger.Microsoft;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NLog;
using NLog.Config;
using NLog.Extensions.Logging;
using NLog.Targets;
using System;
using System.Linq;
using System.Threading;
Expand All @@ -15,13 +11,10 @@ namespace ZoomNet.IntegrationTests
{
public class Program
{
public static async Task Main(string[] args)
public static async Task Main()
{
//var serializerContext = GenerateAttributesForSerializerContext();

var builder = Host.CreateApplicationBuilder();
builder.Services.AddHostedService<TestsRunner>();

// Configure cancellation (this allows you to press CTRL+C or CTRL+Break to stop the integration tests)
var cts = new CancellationTokenSource();
Console.CancelKeyPress += (s, e) =>
Expand All @@ -30,16 +23,40 @@ public static async Task Main(string[] args)
cts.Cancel();
};

// Configure logging
builder.Logging.ClearProviders(); // Remove the built-in providers (which include the Console)
builder.Logging.AddNLog(GetNLogConfiguration()); // Add our desired custom providers (which include the Colored Console)
var services = new ServiceCollection();
ConfigureServices(services);
using var serviceProvider = services.BuildServiceProvider();
var app = serviceProvider.GetService<IHostedService>();
await app.StartAsync(cts.Token).ConfigureAwait(false);
}

private static void ConfigureServices(ServiceCollection services)
{
services.AddHostedService<TestsRunner>();

// Run the tests
var host = builder.Build();
await host.StartAsync(cts.Token).ConfigureAwait(false);

// Stop NLog (which has the desirable side-effect of flushing any pending logs)
LogManager.Shutdown();
services
.AddLogging(logging =>
{
var betterStackToken = Environment.GetEnvironmentVariable("BETTERSTACK_TOKEN");
if (!string.IsNullOrEmpty(betterStackToken))
{
logging.AddBetterStackLogger(options =>
{
options.SourceToken = betterStackToken;
options.Context["source"] = "ZoomNet_integration_tests";
options.Context["ZoomNet-Version"] = ZoomClient.Version;
});
}

logging.AddSimpleConsole(options =>
{
options.SingleLine = true;
options.TimestampFormat = "yyyy-MM-dd HH:mm:ss ";
});

logging.AddFilter("*", LogLevel.Debug);
});
}

private static string GenerateAttributesForSerializerContext()
Expand Down Expand Up @@ -82,38 +99,5 @@ private static string GenerateAttributesForSerializerContext()
var result = string.Join("\r\n\r\n", [simpleAttributes, arrayAttributes, nullableAttributes]);
return result;
}

private static LoggingConfiguration GetNLogConfiguration()
{
// Configure logging
var nLogConfig = new LoggingConfiguration();

// Send logs to logz.io
var logzioToken = Environment.GetEnvironmentVariable("LOGZIO_TOKEN");
if (!string.IsNullOrEmpty(logzioToken))
{
var logzioTarget = new LogzioTarget
{
Name = "Logzio",
Token = logzioToken,
LogzioType = "nlog",
JsonKeysCamelCase = true,
// ProxyAddress = "http://localhost:8888",
};
logzioTarget.ContextProperties.Add(new TargetPropertyWithContext("Source", "ZoomNet_integration_tests"));
logzioTarget.ContextProperties.Add(new TargetPropertyWithContext("ZoomNet-Version", ZoomNet.ZoomClient.Version));

nLogConfig.AddTarget("Logzio", logzioTarget);
nLogConfig.AddRule(NLog.LogLevel.Trace, NLog.LogLevel.Fatal, logzioTarget, "*"); // Send all logs to logz.io, no matther the 'level'
}

// Send logs to console
var consoleTarget = new ColoredConsoleTarget();
nLogConfig.AddTarget("ColoredConsole", consoleTarget);
nLogConfig.AddRule(NLog.LogLevel.Debug, NLog.LogLevel.Fatal, consoleTarget, "*"); // Only display logs with 'Debug' level or higher in the console
nLogConfig.AddRule(NLog.LogLevel.Trace, NLog.LogLevel.Fatal, consoleTarget, "ZoomNet.ZoomWebSocketClient"); // Display all logs to console when testing the WebSocket client, no matther the 'level'

return nLogConfig;
}
}
}
26 changes: 18 additions & 8 deletions Source/ZoomNet.IntegrationTests/TestsRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ public async Task StartAsync(CancellationToken cancellationToken)
var connectionType = ConnectionType.OAuthServerToServer;
// -----------------------------------------------------------------------------

// As far as I know, Zoom only supports ClientCredentials when invoking the methods on the ChatBot endpoint
if (testType == TestType.Chatbot && connectionType != ConnectionType.OAuthClientCredentials)
{
throw new Exception("Zoom only support client credentials when invoking the ChatBot endpoint.");
}

// Configure the proxy if desired
var proxy = useProxy ? new WebProxy($"http://localhost:{proxyPort}") : null;

// Get the connection info and test suite
var connectionInfo = GetConnectionInfo(connectionType);
var connectionInfo = GetConnectionInfo(connectionType, testType);
var testSuite = GetTestSuite(connectionInfo, testType, proxy, _loggerFactory);

// Run the tests
Expand All @@ -65,7 +71,7 @@ public Task StopAsync(CancellationToken cancellationToken)
return Task.CompletedTask;
}

private static IConnectionInfo GetConnectionInfo(ConnectionType connectionType)
private static IConnectionInfo GetConnectionInfo(ConnectionType connectionType, TestType testType)
{
// Jwt
if (connectionType == ConnectionType.Jwt)
Expand All @@ -76,11 +82,14 @@ private static IConnectionInfo GetConnectionInfo(ConnectionType connectionType)
}

// OAuth
var clientId = Environment.GetEnvironmentVariable("ZOOM_OAUTH_CLIENTID", EnvironmentVariableTarget.User);
var clientSecret = Environment.GetEnvironmentVariable("ZOOM_OAUTH_CLIENTSECRET", EnvironmentVariableTarget.User);
var clientIdVariableName = testType == TestType.Chatbot ? "ZOOM_CHATBOT_CLIENTID" : "ZOOM_OAUTH_CLIENTID";
var clientSecretVariableName = testType == TestType.Chatbot ? "ZOOM_CHATBOT_CLIENTSECRET" : "ZOOM_OAUTH_CLIENTSECRET";

var clientId = Environment.GetEnvironmentVariable(clientIdVariableName, EnvironmentVariableTarget.User);
var clientSecret = Environment.GetEnvironmentVariable(clientSecretVariableName, EnvironmentVariableTarget.User);

if (string.IsNullOrEmpty(clientId)) throw new Exception("You must set the ZOOM_OAUTH_CLIENTID environment variable before you can run integration tests.");
if (string.IsNullOrEmpty(clientSecret)) throw new Exception("You must set the ZOOM_OAUTH_CLIENTSECRET environment variable before you can run integration tests.");
if (string.IsNullOrEmpty(clientId)) throw new Exception($"You must set the {clientIdVariableName} environment variable before you can run integration tests.");
if (string.IsNullOrEmpty(clientSecret)) throw new Exception($"You must set the {clientSecretVariableName} environment variable before you can run integration tests.");

switch (connectionType)
{
Expand Down Expand Up @@ -111,12 +120,13 @@ private static IConnectionInfo GetConnectionInfo(ConnectionType connectionType)
}
case ConnectionType.OAuthClientCredentials:
{
var accessToken = Environment.GetEnvironmentVariable("ZOOM_OAUTH_CLIENTCREDENTIALS_ACCESSTOKEN", EnvironmentVariableTarget.User);
var accessTokenVariableName = testType == TestType.Chatbot ? "ZOOM_OAUTH_CHATBOT_ACCESSTOKEN" : "ZOOM_OAUTH_CLIENTCREDENTIALS_ACCESSTOKEN";
var accessToken = Environment.GetEnvironmentVariable(accessTokenVariableName, EnvironmentVariableTarget.User);

return OAuthConnectionInfo.WithClientCredentials(clientId, clientSecret, accessToken,
(newRefreshToken, newAccessToken) =>
{
Environment.SetEnvironmentVariable("ZOOM_OAUTH_CLIENTCREDENTIALS_ACCESSTOKEN", newAccessToken, EnvironmentVariableTarget.User);
Environment.SetEnvironmentVariable(accessTokenVariableName, newAccessToken, EnvironmentVariableTarget.User);
});
}
case ConnectionType.OAuthServerToServer:
Expand Down
10 changes: 4 additions & 6 deletions Source/ZoomNet.IntegrationTests/ZoomNet.IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Logzio.DotNet.NLog" Version="1.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.14" />
<PackageReference Include="Formitable.BetterStack.Logger.Microsoft" Version="0.1.2" />
<PackageReference Include="Microsoft.Extensions.Diagnostics" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
38 changes: 38 additions & 0 deletions Source/ZoomNet/Extensions/Public.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading;
using System.Threading.Tasks;
using ZoomNet.Models;
using ZoomNet.Models.ChatbotMessage;
using ZoomNet.Models.Webhooks;
using ZoomNet.Resources;

Expand Down Expand Up @@ -385,5 +386,42 @@ public static bool HasPermission(this IZoomClient client, string scope)
{
return client.HasPermissions(new[] { scope });
}

/// <summary>
/// Send a Chatbot message.
/// </summary>
/// <param name="chatbotResource">The chatbot resource.</param>
/// <param name="accountId">The account ID to which the message was sent.</param>
/// <param name="toJId">The JID of group channel or user to whom the message should be sent.</param>
/// <param name="robotJId">The robot JID.</param>
/// <param name="message">The simple text message to send.</param>
/// <param name="enableMarkdownSupport">True if the message contains markdown syntax.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// The async task.
/// </returns>
public static Task<ChatbotMessageInformation> SendMessageAsync(this IChatbot chatbotResource, string accountId, string toJId, string robotJId, string message, bool enableMarkdownSupport = false, CancellationToken cancellationToken = default)
{
return chatbotResource.SendMessageAsync(accountId, toJId, robotJId, new ChatbotContent() { Head = new ChatbotHeader(message) }, enableMarkdownSupport, cancellationToken);
}

/// <summary>
/// Edit a Chatbot message.
/// </summary>
/// <param name="chatbotResource">The chatbot resource.</param>
/// <param name="messageId">The message ID of the message to edit.</param>
/// <param name="accountId">The account ID to which the message was sent.</param>
/// <param name="toJId">The JID of group channel or user to whom the message should be sent.</param>
/// <param name="robotJId">The robot JID.</param>
/// <param name="message">The simple text message to send.</param>
/// <param name="enableMarkdownSupport">True if the message contains markdown syntax.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// The async task.
/// </returns>
public static Task<ChatbotMessageInformation> EditMessageAsync(this IChatbot chatbotResource, string messageId, string accountId, string toJId, string robotJId, string message, bool enableMarkdownSupport = false, CancellationToken cancellationToken = default)
{
return chatbotResource.EditMessageAsync(messageId, accountId, toJId, robotJId, new ChatbotContent() { Head = new ChatbotHeader(message) }, enableMarkdownSupport, cancellationToken);
}
}
}
6 changes: 3 additions & 3 deletions Source/ZoomNet/Models/PresenceStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public enum PresenceStatus
/// <summary>
/// In calendar event.
/// </summary>
[EnumMember(Value = "In_Calendar_Event")]
[EnumMember(Value = "In_A_Calendar_Event")]
InEvent,

/// <summary>
Expand All @@ -52,13 +52,13 @@ public enum PresenceStatus
/// <summary>
/// In a Zoom meeting.
/// </summary>
[EnumMember(Value = "In_A_Zoom_Meeting")]
[EnumMember(Value = "In_A_Meeting")]
InMeeting,

/// <summary>
/// On a call.
/// </summary>
[EnumMember(Value = "On_A_Call")]
[EnumMember(Value = "In_A_Call")]
OnCall,

/// <summary>
Expand Down
12 changes: 0 additions & 12 deletions Source/ZoomNet/Resources/Chatbot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ public Task<ChatbotMessageInformation> DeleteMessageAsync(string messageId, stri
.AsObject<ChatbotMessageInformation>();
}

/// <inheritdoc/>
public Task<ChatbotMessageInformation> SendMessageAsync(string accountId, string toJId, string robotJId, string message, bool enableMarkdownSupport = false, CancellationToken cancellationToken = default)
{
return SendMessageAsync(accountId, toJId, robotJId, new ChatbotContent() { Head = new ChatbotHeader(message) }, enableMarkdownSupport, cancellationToken);
}

/// <inheritdoc/>
public Task<ChatbotMessageInformation> SendMessageAsync(string accountId, string toJId, string robotJId, ChatbotContent content, bool enableMarkdownSupport = false, CancellationToken cancellationToken = default)
{
Expand All @@ -60,12 +54,6 @@ public Task<ChatbotMessageInformation> SendMessageAsync(string accountId, string
.AsObject<ChatbotMessageInformation>();
}

/// <inheritdoc/>
public Task<ChatbotMessageInformation> EditMessageAsync(string messageId, string accountId, string toJId, string robotJId, string message, bool enableMarkdownSupport = false, CancellationToken cancellationToken = default)
{
return EditMessageAsync(messageId, accountId, toJId, robotJId, new ChatbotContent() { Head = new ChatbotHeader(message) }, enableMarkdownSupport, cancellationToken);
}

/// <inheritdoc/>
public Task<ChatbotMessageInformation> EditMessageAsync(string messageId, string accountId, string toJId, string robotJId, ChatbotContent content, bool enableMarkdownSupport = false, CancellationToken cancellationToken = default)
{
Expand Down
29 changes: 0 additions & 29 deletions Source/ZoomNet/Resources/IChatbot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,6 @@ public interface IChatbot
/// </returns>
public Task<ChatbotMessageInformation> DeleteMessageAsync(string messageId, string accountId, string userJId, string robotJId, CancellationToken cancellationToken = default);

/// <summary>
/// Send a Chatbot message.
/// </summary>
/// <param name="accountId">The account ID to which the message was sent.</param>
/// <param name="toJId">The JID of group channel or user to whom the message should be sent.</param>
/// <param name="robotJId">The robot JID.</param>
/// <param name="message">The simple text message to send.</param>
/// <param name="enableMarkdownSupport">True if the message contains markdown syntax.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// The async task.
/// </returns>
public Task<ChatbotMessageInformation> SendMessageAsync(string accountId, string toJId, string robotJId, string message, bool enableMarkdownSupport = false, CancellationToken cancellationToken = default);

/// <summary>
/// Send a Chatbot message.
/// </summary>
Expand All @@ -54,21 +40,6 @@ public interface IChatbot
/// </returns>
public Task<ChatbotMessageInformation> SendMessageAsync(string accountId, string toJId, string robotJId, ChatbotContent content, bool enableMarkdownSupport = false, CancellationToken cancellationToken = default);

/// <summary>
/// Edit a Chatbot message.
/// </summary>
/// <param name="messageId">The message ID of the message to edit.</param>
/// <param name="accountId">The account ID to which the message was sent.</param>
/// <param name="toJId">The JID of group channel or user to whom the message should be sent.</param>
/// <param name="robotJId">The robot JID.</param>
/// <param name="message">The simple text message to send.</param>
/// <param name="enableMarkdownSupport">True if the message contains markdown syntax.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// The async task.
/// </returns>
public Task<ChatbotMessageInformation> EditMessageAsync(string messageId, string accountId, string toJId, string robotJId, string message, bool enableMarkdownSupport = false, CancellationToken cancellationToken = default);

/// <summary>
/// Edit a Chatbot message.
/// </summary>
Expand Down
Loading

0 comments on commit 59f0341

Please sign in to comment.