Skip to content

PureCloud.Client is a modern, lightweight C# SDK designed for integrating with the Genesys Cloud API. Originally forked from [platform-client-sdk-dotnet](https://github.com/MyPureCloud/platform-client-sdk-dotnet), this library has been significantly improved and refactored for better maintainability, performance, and developer experience.

Notifications You must be signed in to change notification settings

MikeAlhayek/PureCloud.Client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PureCloud.Client

PureCloud.Client is a modern, lightweight C# SDK designed for integrating with the Genesys Cloud API. Originally forked from platform-client-sdk-dotnet, this library has been significantly improved and refactored for better maintainability, performance, and developer experience.

Key Improvements

  • Fully asynchronous API to avoid thread blocking
  • First-class support for Dependency Injection
  • Uses System.Text.Json for efficient JSON (de)serialization
  • Targets modern .NET platforms, including .NET 8 and above
  • Clean, maintainable codebase with minimal dependencies
  • Lightweight and optimized for modern server applications

Setup

Install the PureCloud.Client NuGet package.

Then, register the required services in your DI container:

services
    .AddPureCloudCore()
    .AddPureCloudApis();

ASP.NET Core Integration

If you're working with ASP.NET Core, you can integrate an identity token store or a simple in-memory token store by installing the PureCloud.Client.AspNetCore.Http package.

Option 1: Identity Token Store (Recommended for Production)

Use the identity-based token store when you want to persist tokens securely using your existing identity system:

services
    .AddPureCloudCore()
    .AddPureCloudApis()
    .AddIdentityTokenStore<IUser>();

Option 2: In-Memory Token Store (For Development Only)

For development or debugging purposes, you can use an in-memory token store:

services
    .AddPureCloudCore()
    .AddPureCloudApis()
    .AddInMemoryTokenStore();

Note: AddInMemoryTokenStore is not suitable for production environments. For production use, it is strongly recommended to implement a custom token store tailored to your application's needs.


Example Usage

public sealed class Example
{
    private readonly INotificationClientFactory _notificationClientFactory;
    private readonly IUserApis _userApis;

    public Example(INotificationClientFactory notificationClientFactory, IUserApis userApis)
    {
        _notificationClientFactory = notificationClientFactory;
        _userApis = userApis;
    }

    public async Task HandleNotificationsAsync(CancellationToken cancellationToken)
    {
        // Get a new instance ot the notification client from the 'INotificationClientFactory'
        await using var notificationClient = _notificationClientFactory.Create();

        // Get the current user
        var user = await _userApis.GetCurrentUserAsync(null, null, cancellationToken);

        // You can use the builder or use other AddSubscription methods to add subscriptions.
        await notificationClient.AddSubscriptionsAsync(builder => builder
            .Add("v2.users.{0}.presence", user.Id)
            .Add("v2.users.{0}.conversations", user.Id)
            .Add("v2.users.{0}.conversations.calls", user.Id)
        );

        // Register a functions to call when a notification is received from the server.
        _notificationClient.NotificationHandlers.Add(EventsHandlerAsync);

        // Process notifications for 60 seconds
        await Task.Delay(TimeSpan.FromSeconds(60), cancellationToken);
    }

    private Task EventsHandlerAsync(INotificationData data)
    {
        switch (data)
        {
            case NotificationData<PresenceEventUserPresence> presence:
                // Handle presence event
                break;

            case NotificationData<ConversationEventTopicConversation> conversation:
                // Handle conversation event
                break;

            case NotificationData<ConversationCallEventTopicCallConversation> callConversation:
                // Handle call conversation event
                break;
        }

        return Task.CompletedTask;
    }
}

About

PureCloud.Client is a modern, lightweight C# SDK designed for integrating with the Genesys Cloud API. Originally forked from [platform-client-sdk-dotnet](https://github.com/MyPureCloud/platform-client-sdk-dotnet), this library has been significantly improved and refactored for better maintainability, performance, and developer experience.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages