stream-chat-net 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package stream-chat-net --version 2.0.0                
NuGet\Install-Package stream-chat-net -Version 2.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="stream-chat-net" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add stream-chat-net --version 2.0.0                
#r "nuget: stream-chat-net, 2.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install stream-chat-net as a Cake Addin
#addin nuget:?package=stream-chat-net&version=2.0.0

// Install stream-chat-net as a Cake Tool
#tool nuget:?package=stream-chat-net&version=2.0.0                

Official .NET SDK for Stream Chat

.github/workflows/ci.yaml NuGet Badge

<p align="center"> <img src="./assets/logo.svg" width="50%" height="50%"> </p> <p align="center"> Official .NET API client for Stream Chat, a service for building chat applications. <br /> <a href="https://getstream.io/chat/docs/"><strong>Explore the docs ยป</strong></a> <br /> <br /> <a href="https://github.com/GetStream/stream-chat-net/tree/master/samples">Code Samples</a> ยท <a href="https://github.com/GetStream/stream-chat-net/issues">Report Bug</a> ยท <a href="https://github.com/GetStream/stream-chat-net/issues">Request Feature</a> </p>

๐Ÿ“ About Stream

You can sign up for a Stream account at our Get Started page.

You can use this library to access chat API endpoints server-side.

For the client-side integrations (web and mobile) have a look at the JavaScript, iOS and Android SDK libraries (docs).


๐Ÿšจ Breaking changes in v1.0 <

The library received many changes in v1.0 to make it easier to use and more maintanable in the future. The main change is that both Channel and Client classes have been separated into small modules that we call clients. (This resambles the structure of our Java library as well.) Main changes:

  • Channel and Client classes are gone, and have been organized into smaller clients in StreamChat.Clients namespace.
  • These clients do not maintain state as Channel used to did earlier where it kept the channelType and channelId in the memory. So this means that you'll need to pass in channelType and channelId to a lot of method calls in IChannelClient.
  • Async method names have Async suffix now.
  • All public methods and classes have documentation.
  • Identifiers has been renamed from ID to Id to follow Microsoft's naming guide. Such as userID โ†’ userId.
  • A lot of data classes have been renamed to make more sense. Such as ChannelObject โ†’ Channel.
  • Data classes have been moved to StreamChat.Models namespace.
  • Full feature parity: all backend APIs are available.
  • Returned values are type of ApiResponse and expose rate limit informaiton with GetRateLimit() method.
  • The folder structure of the project has been reorganized to follow Microsoft's recommendation.
  • Unit tests have been improved. They are smaller, more focused and have cleanup methods.
  • Added .NET 6.0 support.

The proper usage of the library:

var clientFactory = new StreamClientFactory("YourApiKey", "YourApiSecret");
// Note: all client instances can be used as a singleton for the lifetime
// of your application as they don't maintain state.
var userClient = clientFactory.GetUserClient();
var channelClient = clientFactory.GetChannelClient();
var messageClient = clientFactory.GetMessageClient();
var reactionClient = clientFactory.GetReactionClient();

var jamesBond = await userClient.UpsertAsync(new UserRequest { Id = "james_bond" });
var agentM = await userClient.UpsertAsync(new UserRequest { Id = "agent_m" });

var channel = await channelClient.GetOrCreateAsync("messaging", "superHeroChannel", createdBy: jamesBond.Id);
await channelClient.AddMembersAsync(channel.Type, channel.Id, jamesBond.Id, agentM.Id);

var message = await messageClient.SendMessageAsync(channel.Type, channel.Id, jamesBond.Id, "I need a new quest Agent M.");
await reactionClient.SendReactionAsync(message.Id, "like", agentM.Id);

โš™๏ธ Installation

$ dotnet add package stream-chat-net

๐Ÿ’ก Tip: you can find code samples in the samples folder.

โœจ Getting started

Import

using StreamChat.Clients;

Initialize client

// Client factory instantiation.
var clientFactory = new StreamClientFactory("YourApiKey", "YourApiSecret");

// Or you can configure some options such as custom HttpClient, HTTP timeouts etc.
var clientFactory = new StreamClientFactory("YourApiKey", "YourApiSecret", opts => opts.Timeout = TimeSpan.FromSeconds(5));

// Get clients from client factory. Note: all clients can be used as a singleton in your application.
var channelClient = clientFactory.GetChannelClient();
var messageClient = clientFactory.GetMessageClient();

Generate a token for client-side usage

var userClient = clientFactory.GetUserClient();

// Without expiration
var token = userClient.CreateToken("bob-1");

// With expiration
var token = userClient.CreateToken("bob-1", expiration: DateTimeOffset.UtcNow.AddHours(1));

Create/Update users

var userClient = clientFactory.GetUserClient();

var bob = new UserRequest
{
    Id = "bob-1",
    Role = Role.Admin,
    Teams = new[] { "red", "blue" } // if multi-tenant enabled
};
bob.SetData("age", 27);

await userClient.UpsertAsync(bob);

// Batch update is also supported
var jane = new UserRequest { Id = "jane"};
var june = new UserRequest { Id = "june"};
var users = await userClient.UpsertManyAsync(new[] { bob, jane, june });

GDPR-like User endpoints

var userClient = clientFactory.GetUserClient();

await userClient.ExportAsync("bob-1");
await userClient.DeactivateAsync("bob-1");
await userClient.ReactivateAsync("bob-1");
await userClient.DeleteAsync("bob-1");

Channel types

var channelTypeClient = clientFactory.GetChannelTypeClient();

var chanTypeConf = new ChannelTypeWithStringCommands
{
    Name = "livechat",
    Automod = Automod.Disabled,
    Commands = new List<string> { Commands.Ban },
    Mutes = true
};
var chanType = await channelTypeClient.CreateChannelTypeAsync(chanTypeConf);

var allChanTypes = await channelTypeClient.ListChannelTypesAsync();

Channels

var channelClient = clientFactory.GetChannelClient();

// Create a channel with members from the start, Bob is the creator
var channel = channelClient.GetOrCreateAsync("messaging", "bob-and-jane", bob.Id, bob.Id, jane.Id);

// Create channel and then add members, Mike is the creator
var channel = channelClient.GetOrCreateAsync("messaging", "bob-and-jane", mike.Id);
channelClient.AddMembersAsync(channel.Type, channel.Id, bob.Id, jane.Id, joe.Id);

Messaging

var messageClient = clientFactory.GetMessageClient();

// Only text
messageClient.SendMessageAsync(channel.Type, channel.Id, bob.Id, "Hey, I'm Bob!");

// With custom data
var msgReq = new MessageRequest { Text = "Hi june!" };
msgReq.SetData("location", "amsterdam");

var bobMessageResp = await messageClient.SendMessageAsync(channelType, channel.Id, msgReq, bob.Id);

// Threads
var juneReply = new MessageRequest { Text = "Long time no see!" };
var juneReplyMessage = await messageClient.SendMessageToThreadAsync(channel.Type, channel.Id, juneReply, june.Id, bobMessageResp.Message.Id)

Reactions

var reactionClient = clientFactory.GetReactionClient();

await reactionClient.SendReactionAsync(message.Id, "like", bob.Id);

var allReactions = await reactionClient.GetReactionsAsync(message.Id);

Moderation

var channelClient = clientFactory.GetChannelClient();
var userClient = clientFactory.GetUserClient();
var flagClient = clientFactory.GetFlagClient();

await channelClient.AddModeratorsAsync(channel.Type, channel.Id, new[] { jane.Id });

await userClient.BanAsync(new BanRequest
{
    Type = channel.Type,
    Id = channel.Id,
    Reason = "reason",
    TargetUserId = bob.Id,
    UserId = jane.Id
});

await flagClient.FlagUserAsync(bob.Id, jane.Id);

Permissions

var permissionClient = clientFactory.GetPermissionClient();

await permissionClient.CreateRoleAsync("channel-boss");

// Assign users to roles (optional message)
await channelClient.AssignRolesAsync(new AssignRoleRequest
{
    AssignRoles = new List<RoleAssignment>
    {
        new RoleAssignment { UserId = bob.ID, ChannelRole = Role.ChannelModerator },
        new RoleAssignment { UserId = june.ID, ChannelRole = "channel-boss" }
    },
    Message = new MessageRequest { Text = "Bob and June just became mods", User = bob }
});

Devices

var deviceClient = clientFactory.GetDeviceClient();

var junePhone = new Device
{
    ID = "iOS Device Token",
    PushProvider = PushProvider.APN,
    UserId = june.ID
};

await deviceClient.AddDeviceAsync(junePhone);

var devices = await deviceClient.GetDevicesAsync(june.Id);

Export Channels

var channelClient = clientFactory.GetChannelClient();
var taskClient = clientFactory.GetTaskClient();

var taskResponse = channelClient.ExportChannelAsync(new ExportChannelRequest { Id = channel.Id, Type = channel.Type });

// Wait for the completion
var complete = false;
var iterations = 0;
AsyncTaskStatusResponse resp = null;
while (!complete && iterations < 1000)
{
    resp = await taskClient.GetTaskStatusAsync(taskResponse.TaskId);
    if (resp.Status == AsyncTaskStatus.Completed)
    {
        complete = true;
        break;
    }
    iterations++;
    await Task.Delay(100);
}

if (complete)
{
    Console.WriteLine(resp.Result["url"]);
}

โœ๏ธ Contributing

We welcome code changes that improve this library or fix a problem, please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on Github. We are very happy to merge your code in the official repository. Make sure to sign our Contributor License Agreement (CLA) first. See our license file for more details.

Head over to CONTRIBUTING.md for some development tips.

๐Ÿง‘โ€๐Ÿ’ป We are hiring!

We've recently closed a $38 million Series B funding round and we keep actively growing. Our APIs are used by more than a billion end-users, and you'll have a chance to make a huge impact on the product within a team of the strongest engineers all over the world.

Check out our current openings and apply via Stream's website.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.6 is compatible.  netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 is compatible.  net461 was computed.  net462 was computed.  net463 was computed.  net47 is compatible.  net471 was computed.  net472 was computed.  net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.6.0 55,833 5/8/2024
2.5.0 31,916 11/8/2023
2.4.0 2,047 10/30/2023
2.3.0 21,283 7/26/2023
2.2.0 1,929 7/11/2023
2.1.2 4,735 5/9/2023
2.1.1 55,709 7/12/2022
2.1.0 3,714 5/30/2022
2.0.0 17,110 4/7/2022
1.1.1 2,441 2/14/2022
1.1.0 756 2/8/2022
1.0.0 1,543 2/1/2022
0.26.0 6,965 12/22/2021
0.25.0 350 12/15/2021
0.24.0 1,357 12/6/2021
0.23.0 1,011 12/3/2021
0.22.0 4,821 11/16/2021
0.21.0 2,736 11/11/2021
0.20.1 2,455 11/1/2021
0.19.0 8,572 8/19/2021
0.18.0 596 8/19/2021
0.17.0 5,291 7/19/2021
0.16.0 3,008 6/25/2021
0.15.0 506 6/17/2021
0.14.0 10,311 6/1/2021
0.13.0 478 5/31/2021
0.12.0 3,535 5/7/2021
0.11.0 12,226 3/10/2021
0.10.0 498 3/3/2021
0.9.0 398 3/3/2021
0.8.1 2,067 2/2/2021
0.8.0 402 2/2/2021
0.7.1 666 1/25/2021
0.7.0 387 1/25/2021
0.6.1 4,462 11/20/2020
0.6.0 500 11/13/2020
0.5.0 3,088 10/2/2020
0.4.7 495 10/2/2020
0.4.3 7,749 6/2/2020
0.4.2 748 3/17/2020
0.4.1 8,116 12/6/2019
0.3.0 3,065 6/26/2019
0.2.0 625 5/22/2019
0.1.0 642 5/15/2019
0.0.2 610 5/10/2019
0.0.1 699 5/7/2019

## [2.0.0](https://github.com/GetStream/stream-chat-net/compare/1.1.1...2.0.0) (2022-04-06)


### โš  BREAKING CHANGES

* remove json property attributes (#100)

### Features

* add command override ([#103](https://github.com/GetStream/stream-chat-net/issues/103)) ([23669b8](https://github.com/GetStream/stream-chat-net/commit/23669b8dfca864a6faa41bc89f97f078ef1f1f7e))
* add device and push fields ([#104](https://github.com/GetStream/stream-chat-net/issues/104)) ([bc2a164](https://github.com/GetStream/stream-chat-net/commit/bc2a164bb99a28b80350b0b9ef455ceaec95d873))
* add new moderation apis ([#101](https://github.com/GetStream/stream-chat-net/issues/101)) ([f11a65f](https://github.com/GetStream/stream-chat-net/commit/f11a65f2f576a483cfbf3bf39fbb550b4952b3f5))
* add push provider api ([#102](https://github.com/GetStream/stream-chat-net/issues/102)) ([9ee847c](https://github.com/GetStream/stream-chat-net/commit/9ee847c7e3a6bf382948e072a92c9ffd03fc4c0e))
* add reminders ([#105](https://github.com/GetStream/stream-chat-net/issues/105)) ([2f551f1](https://github.com/GetStream/stream-chat-net/commit/2f551f1bb35e818c199899fc428587accaf130e4))
* add user custom events ([#96](https://github.com/GetStream/stream-chat-net/issues/96)) ([e94416a](https://github.com/GetStream/stream-chat-net/commit/e94416ac6b957c52006620f23ab5e9002236b348))
* **truncate:** add user id for truncation ([#107](https://github.com/GetStream/stream-chat-net/issues/107)) ([406c994](https://github.com/GetStream/stream-chat-net/commit/406c99409b081c857e11cc867126b61fa34a018b))


* remove json property attributes ([#100](https://github.com/GetStream/stream-chat-net/issues/100)) ([acf4b43](https://github.com/GetStream/stream-chat-net/commit/acf4b43021899bf28d3ba17f84c98563074142d0))

#