公式の.NET APIクライアント用Stream Chatのクライアント、チャットアプリケーションを構築するサービス。
ドキュメントを探索»
コードサンプル・報告バグ・リクエスト機能
Get Startページでストリームアカウントにサインアップできます。
このライブラリを使用して、Chat API Endpointsサーバー側にアクセスできます。
クライアント側の統合(Webおよびモバイル)については、JavaScript、iOSおよびAndroid SDKライブラリ(Docs)をご覧ください。
v1.0 <の変化の変化
図書館は、v1.0の多くの変更を受けて、将来的に使用しやすく、より維持可能になりました。主な変更は、
ChannelとClientクラスの両方がクライアントと呼ばれる小さなモジュールに分離されていることです。 (これにより、Javaライブラリの構造も再編成されます。)主な変更:
ChannelとClientクラスはなくなり、StreamChat.Clients名前空間の小規模なクライアントに編成されています。- これらのクライアントは、
ChannelがメモリにchannelTypeとchannelId保持していた場所で以前に行ったため、状態を維持していません。したがって、これは、channelTypeとchannelIdでIChannelClient多くのメソッド呼び出しに渡す必要があることを意味します。- Asyncメソッド名には、
Asyncサフィックスがあります。- すべてのパブリックメソッドとクラスにはドキュメントがあります。
- 識別子は、Microsoftの命名ガイドに従うために
IDからIdに名前が変更されました。userIDなどなど。>userId。- より理にかなっているために、多くのデータクラスが名前が変更されています。
ChannelObject>Channelなど。- データクラスは、
StreamChat.Modelsの名前空間に移動されました。- 完全な機能パリティ:すべてのバックエンドAPIが利用可能です。
- 返された値は、
ApiResponseのタイプであり、GetRateLimit()メソッドを使用してinformaitonを制限します。- プロジェクトのフォルダー構造は、Microsoftの推奨に従うように再編成されています。
- ユニットテストが改善されました。それらは小さく、より集中しており、クリーンアップ方法を持っています。
- .NET 6.0サポートを追加しました。
ライブラリの適切な使用法:
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 ) ;
$ dotnet add package stream-chat-netヒント:サンプルフォルダーにコードサンプルを見つけることができます。
using StreamChat . Clients ; // 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 ( ) ; 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 ) ) ; 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 } ) ; var userClient = clientFactory . GetUserClient ( ) ;
await userClient . ExportAsync ( "bob-1" ) ;
await userClient . DeactivateAsync ( "bob-1" ) ;
await userClient . ReactivateAsync ( "bob-1" ) ;
await userClient . DeleteAsync ( "bob-1" ) ; 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 ( ) ; 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 ) ; 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 ) var reactionClient = clientFactory . GetReactionClient ( ) ;
await reactionClient . SendReactionAsync ( message . Id , "like" , bob . Id ) ;
var allReactions = await reactionClient . GetReactionsAsync ( message . Id ) ; 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 ) ; 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 }
} ) ; 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 ) ; 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" ] ) ;
} このライブラリを改善するか、問題を修正するコードの変更を歓迎します。すべてのベストプラクティスに従って、GitHubにプルリクエストを送信する前に該当する場合はテストを追加してください。公式リポジトリにコードをマージできることを非常に嬉しく思います。最初に貢献者ライセンス契約(CLA)に署名してください。詳細については、ライセンスファイルを参照してください。
いくつかの開発のヒントについては、Convinting.mdにアクセスしてください。
最近、3800万ドルのシリーズBの資金調達ラウンドを閉鎖し、積極的に成長し続けています。私たちのAPIは10億人以上のエンドユーザーによって使用されており、世界中の最も強力なエンジニアのチーム内で製品に大きな影響を与える機会があります。
現在のオープニングをチェックして、StreamのWebサイトで申請してください。