Note:
getstream-netis the new full-product SDK for Stream, covering Chat, Video, Moderation, and Feeds with long-term support.
stream-chat-netis now in maintenance mode. It will continue to receive critical fixes and requested features, so it is safe to keep using. However, we encourage existing users to migrate when convenient and strongly recommend that new projects start withgetstream-net.Check out the Migration Guide for side-by-side examples covering common use cases.
Official .NET SDK for Stream Chat
Official .NET API client for Stream Chat, a service for building chat applications.
Explore the docs »
Code Samples
·
Report Bug
·
Request Feature
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).
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
ChannelandClientclasses have been separated into small modules that we call clients. (This resambles the structure of our Java library as well.) Main changes:
ChannelandClientclasses are gone, and have been organized into smaller clients inStreamChat.Clientsnamespace.- These clients do not maintain state as
Channelused to did earlier where it kept thechannelTypeandchannelIdin the memory. So this means that you'll need to pass inchannelTypeandchannelIdto a lot of method calls inIChannelClient.- Async method names have
Asyncsuffix now.- All public methods and classes have documentation.
- Identifiers has been renamed from
IDtoIdto follow Microsoft's naming guide. Such asuserID->userId.- A lot of data classes have been renamed to make more sense. Such as
ChannelObject->Channel.- Data classes have been moved to
StreamChat.Modelsnamespace.- Full feature parity: all backend APIs are available.
- Returned values are type of
ApiResponseand expose rate limit informaiton withGetRateLimit()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:
varclientFactory=newStreamClientFactory("YourApiKey","YourApiSecret");// Note: all client instances can be used as a singleton for the lifetime// of your application as they don't maintain state.varuserClient=clientFactory.GetUserClient();varchannelClient=clientFactory.GetChannelClient();varmessageClient=clientFactory.GetMessageClient();varreactionClient=clientFactory.GetReactionClient();varjamesBond=awaituserClient.UpsertAsync(newUserRequest{Id="james_bond"});varagentM=awaituserClient.UpsertAsync(newUserRequest{Id="agent_m"});varchannel=awaitchannelClient.GetOrCreateAsync("messaging","superHeroChannel",createdBy:jamesBond.Id);awaitchannelClient.AddMembersAsync(channel.Type,channel.Id,jamesBond.Id,agentM.Id);varmessage=awaitmessageClient.SendMessageAsync(channel.Type,channel.Id,jamesBond.Id,"I need a new quest Agent M.");awaitreactionClient.SendReactionAsync(message.Id,"like",agentM.Id);
$ dotnet add package stream-chat-net💡 Tip: you can find code samples in the samples folder.
usingStreamChat.Clients;// Client factory instantiation.varclientFactory=newStreamClientFactory("YourApiKey","YourApiSecret");// Or you can configure some options such as custom HttpClient, HTTP timeouts etc.varclientFactory=newStreamClientFactory("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.varchannelClient=clientFactory.GetChannelClient();varmessageClient=clientFactory.GetMessageClient();varuserClient=clientFactory.GetUserClient();// Without expirationvartoken=userClient.CreateToken("bob-1");// With expirationvartoken=userClient.CreateToken("bob-1",expiration:DateTimeOffset.UtcNow.AddHours(1));varuserClient=clientFactory.GetUserClient();varbob=newUserRequest{Id="bob-1",Role=Role.Admin,Teams=new[]{"red","blue"}// if multi-tenant enabled};bob.SetData("age",27);awaituserClient.UpsertAsync(bob);// Batch update is also supportedvarjane=newUserRequest{Id="jane"};varjune=newUserRequest{Id="june"};varusers=awaituserClient.UpsertManyAsync(new[]{bob,jane,june});varuserClient=clientFactory.GetUserClient();awaituserClient.ExportAsync("bob-1");awaituserClient.DeactivateAsync("bob-1");awaituserClient.ReactivateAsync("bob-1");awaituserClient.DeleteAsync("bob-1");varchannelTypeClient=clientFactory.GetChannelTypeClient();varchanTypeConf=newChannelTypeWithStringCommands{Name="livechat",Automod=Automod.Disabled,Commands=newList<string>{Commands.Ban},Mutes=true};varchanType=awaitchannelTypeClient.CreateChannelTypeAsync(chanTypeConf);varallChanTypes=awaitchannelTypeClient.ListChannelTypesAsync();varchannelClient=clientFactory.GetChannelClient();// Create a channel with members from the start, Bob is the creatorvarchannel=channelClient.GetOrCreateAsync("messaging","bob-and-jane",bob.Id,bob.Id,jane.Id);// Create channel and then add members, Mike is the creatorvarchannel=channelClient.GetOrCreateAsync("messaging","bob-and-jane",mike.Id);channelClient.AddMembersAsync(channel.Type,channel.Id,bob.Id,jane.Id,joe.Id);varmessageClient=clientFactory.GetMessageClient();// Only textmessageClient.SendMessageAsync(channel.Type,channel.Id,bob.Id,"Hey, I'm Bob!");// With custom datavarmsgReq=newMessageRequest{Text="Hi june!"};msgReq.SetData("location","amsterdam");varbobMessageResp=awaitmessageClient.SendMessageAsync(channelType,channel.Id,msgReq,bob.Id);// ThreadsvarjuneReply=newMessageRequest{Text="Long time no see!"};varjuneReplyMessage=awaitmessageClient.SendMessageToThreadAsync(channel.Type,channel.Id,juneReply,june.Id,bobMessageResp.Message.Id)varreactionClient=clientFactory.GetReactionClient();awaitreactionClient.SendReactionAsync(message.Id,"like",bob.Id);varallReactions=awaitreactionClient.GetReactionsAsync(message.Id);varchannelClient=clientFactory.GetChannelClient();varuserClient=clientFactory.GetUserClient();varflagClient=clientFactory.GetFlagClient();awaitchannelClient.AddModeratorsAsync(channel.Type,channel.Id,new[]{jane.Id});awaituserClient.BanAsync(newBanRequest{Type=channel.Type,Id=channel.Id,Reason="reason",TargetUserId=bob.Id,UserId=jane.Id});awaitflagClient.FlagUserAsync(bob.Id,jane.Id);varpermissionClient=clientFactory.GetPermissionClient();awaitpermissionClient.CreateRoleAsync("channel-boss");// Assign users to roles (optional message)awaitchannelClient.AssignRolesAsync(newAssignRoleRequest{AssignRoles=newList<RoleAssignment>{newRoleAssignment{UserId=bob.ID,ChannelRole=Role.ChannelModerator},newRoleAssignment{UserId=june.ID,ChannelRole="channel-boss"}},Message=newMessageRequest{Text="Bob and June just became mods",User=bob}});vardeviceClient=clientFactory.GetDeviceClient();varjunePhone=newDevice{ID="iOS Device Token",PushProvider=PushProvider.APN,UserId=june.ID};awaitdeviceClient.AddDeviceAsync(junePhone);vardevices=awaitdeviceClient.GetDevicesAsync(june.Id);varchannelClient=clientFactory.GetChannelClient();vartaskClient=clientFactory.GetTaskClient();vartaskResponse=channelClient.ExportChannelAsync(newExportChannelRequest{Id=channel.Id,Type=channel.Type});// Wait for the completionvarcomplete=false;variterations=0;AsyncTaskStatusResponseresp=null;while(!complete&&iterations<1000){resp=awaittaskClient.GetTaskStatusAsync(taskResponse.TaskId);if(resp.Status==AsyncTaskStatus.Completed){complete=true;break;}iterations++;awaitTask.Delay(100);}if(complete){Console.WriteLine(resp.Result["url"]);}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'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.