Class MatrixClient
Namespace: Uniform.Matrix.Protocol.Client
Assembly: Uniform.Matrix.Protocol.Client.dll
public sealed class MatrixClient
MatrixClient client = new(http, new Uri("https://matrix.org"));
await client.LoginWithPasswordAsync("@alice:matrix.org", password);
await foreach (SyncResponse sync in client.SyncLoopAsync(cancellationToken: cancellationToken))
foreach ((string roomId, JoinedRoom room) in sync.Rooms.Join)
foreach (ClientEvent ev in room.Timeline.Events)
if (ev.TryGetContent(out MessageContent? message)) Console.WriteLine($"{ev.Sender}: {message.Body}");
Constructors
|
Edit this page
View Source
Create a logged-out client for homeserver.
Declaration
public MatrixClient(HttpClient http, Uri homeserver)
Parameters
|
Edit this page
View Source
Create a client that resumes a stored session.
Declaration
public MatrixClient(HttpClient http, MatrixSession session)
Parameters
Fields
|
Edit this page
View Source
The query parameter that delays a send, MSC4140.
Declaration
public const string DelayParameter = "org.matrix.msc4140.delay"
Field Value
Properties
|
Edit this page
View Source
Declaration
public string? AccessToken { get; }
Property Value
|
Edit this page
View Source
Declaration
public string? DeviceId { get; }
Property Value
|
Edit this page
View Source
Base URL with a trailing slash, so relative endpoint paths append instead of replacing.
Declaration
public Uri Homeserver { get; }
Property Value
|
Edit this page
View Source
Declaration
public bool IsLoggedIn { get; }
Property Value
|
Edit this page
View Source
Longest server-requested wait that is retried; longer waits throw MatrixException at once so callers are not blocked for minutes.
Declaration
public TimeSpan MaxRateLimitDelay { get; set; }
Property Value
|
Edit this page
View Source
Declaration
public int MaxRateLimitRetries { get; set; }
Property Value
|
Edit this page
View Source
Current session; null when logged out.
Declaration
public MatrixSession? Session { get; }
Property Value
|
Edit this page
View Source
Declaration
public TimeSpan SyncRetryDelay { get; set; }
Property Value
|
Edit this page
View Source
Declaration
public TimeSpan SyncRetryMaxDelay { get; set; }
Property Value
|
Edit this page
View Source
Declaration
public string? UserId { get; }
Property Value
Methods
|
Edit this page
View Source
Declaration
public Task BanAsync(string roomId, string userId, string? reason = null, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Changes the password, confirming with the current one; other devices are logged out unless logoutDevices is false.
Declaration
public Task ChangePasswordAsync(string currentPassword, string newPassword, bool logoutDevices = true, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<KeysClaimResponse> ClaimKeysAsync(IReadOnlyDictionary<string, IReadOnlyList<string>> devices, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Create an account that logs in with password; for admins.
Declaration
public Task<AdminAccount> CreateAdminAccountAsync(string userId, string password, string? displayName = null, bool admin = false, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Create a direct-message room with userId, invites them and record it in Direct; return the room ID.
Declaration
public Task<string> CreateDirectRoomAsync(string userId, bool encrypted = false, CancellationToken cancellationToken = default)
Parameters
| Type |
Name |
Description |
| string |
userId |
User to chat with.
|
| bool |
encrypted |
Whether to turn on end-to-end encryption from the start.
|
| CancellationToken |
cancellationToken |
Cancellation token.
|
Returns
|
Edit this page
View Source
CreateEditContent(string, string, string?)
Build edit content replacing the text of eventId, optionally with a formatted html body.
Declaration
public static MessageContent CreateEditContent(string eventId, string newText, string? html = null)
Parameters
Returns
|
Edit this page
View Source
CreateFileContent(EncryptedFile, string, string, long?)
Build file message content for an encrypted upload, for encrypted rooms.
Declaration
public static MessageContent CreateFileContent(EncryptedFile file, string fileName, string contentType, long? size)
Parameters
Returns
|
Edit this page
View Source
CreateFileContent(MxcUri, string, string, long?)
Build file message content for uploaded media, picking the message type from contentType.
Declaration
public static MessageContent CreateFileContent(MxcUri uri, string fileName, string contentType, long? size)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<string> CreateFilterAsync(Filter filter, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
CreateKeyBackupVersionAsync(string, JsonObject, CancellationToken)
Creates a key backup version, which becomes current; returns its version ID.
Declaration
public Task<string> CreateKeyBackupVersionAsync(string algorithm, JsonObject authData, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<(MxcUri ContentUri, DateTimeOffset ExpiresAt)> CreateMediaAsync(CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
CreateReactionContent(string, string)
Declaration
public static ReactionContent CreateReactionContent(string eventId, string key)
Parameters
Returns
|
Edit this page
View Source
Create a registration token: token, or a random one; usable usesAllowed times, or any number, until expiry, or forever. For admins.
Declaration
public Task<AdminRegistrationToken> CreateRegistrationTokenAsync(string? token = null, int? usesAllowed = null, DateTimeOffset? expiry = null, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
CreateReplyContent(ClientEvent, string, string?, IEnumerable<string>?, string?)
Build reply content that mentions the replied sender unless it is ownUserId.
Declaration
public static MessageContent CreateReplyContent(ClientEvent replyTo, string text, string? ownUserId, IEnumerable<string>? alsoMentioned = null, string? html = null)
Parameters
Returns
|
Edit this page
View Source
Creates an alias like #room:server for a room.
Declaration
public Task CreateRoomAliasAsync(string roomAlias, string roomId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<string> CreateRoomAsync(CreateRoomRequest request, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Deactivates the account for good, confirming with password, and clears Session; the user ID cannot be registered again.
Declaration
public Task DeactivateAccountAsync(string password, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Deactivate an account: it leaves its rooms and cannot log in again; for admins.
Declaration
public Task DeactivateUserAsync(string userId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task DeleteDevicesAsync(IReadOnlyList<string> deviceIds, string? password, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Delete media of the server; for admins.
Declaration
public Task DeleteMediaAsync(string serverName, string mediaId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Delete one of the user's own push rules.
Declaration
public Task DeletePushRuleAsync(string kind, string ruleId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Delete a registration token; for admins.
Declaration
public Task DeleteRegistrationTokenAsync(string token, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Delete a report; for admins.
Declaration
public Task DeleteReportAsync(long reportId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task DeleteRoomAliasAsync(string roomAlias, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task DeleteTagAsync(string roomId, string tag, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<MediaDownload> DownloadMediaAsync(MxcUri uri, CancellationToken cancellationToken = default)
Parameters
Returns
using MediaDownload media = await client.DownloadMediaAsync(MxcUri.Parse(message.Url!));
await using FileStream file = File.Create(media.FileName ?? "download");
await media.Content.CopyToAsync(file);
|
Edit this page
View Source
Download a server-made thumbnail of about width×height pixels; servers may return the original for small images.
Declaration
public Task<MediaDownload> DownloadThumbnailAsync(MxcUri uri, int width, int height, bool crop = false, CancellationToken cancellationToken = default)
Parameters
| Type |
Name |
Description |
| MxcUri |
uri |
Content URI of an image or video.
|
| int |
width |
Desired width in pixels.
|
| int |
height |
Desired height in pixels.
|
| bool |
crop |
Whether to crop to the exact size instead of scaling to fit.
|
| CancellationToken |
cancellationToken |
Cancellation token.
|
Returns
|
Edit this page
View Source
Forgets a left room so it no longer appears in sync.
Declaration
public Task ForgetRoomAsync(string roomId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<T> GetAccountDataAsync<T>(string type, CancellationToken cancellationToken = default)
Parameters
Returns
Type Parameters
|
Edit this page
View Source
Return a local account; for admins.
Declaration
public Task<AdminAccount> GetAdminAccountAsync(string userId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Return a page of local accounts, optionally matching name and including deactivated ones; for admins.
Declaration
public Task<AdminAccountsResponse> GetAdminAccountsAsync(string? name = null, bool includeDeactivated = false, int from = 0, int limit = 100, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Return the joined members of a room; for admins.
Declaration
public Task<IReadOnlyList<string>> GetAdminRoomMembersAsync(string roomId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Return a page of rooms, most members first, optionally matching searchTerm; for admins.
Declaration
public Task<AdminRoomsResponse> GetAdminRoomsAsync(string? searchTerm = null, int from = 0, int limit = 100, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
GetContextAsync(string, string, int?, string?, CancellationToken)
Return an event with the events around it and the state at it.
Declaration
public Task<ContextResponse> GetContextAsync(string roomId, string eventId, int? limit = null, string? filter = null, CancellationToken cancellationToken = default)
Parameters
| Type |
Name |
Description |
| string |
roomId |
Room ID.
|
| string |
eventId |
Event to center on.
|
| int? |
limit |
Maximum number of events before and after together; server default when null.
|
| string |
filter |
Inline RoomEventFilter JSON.
|
| CancellationToken |
cancellationToken |
Cancellation token.
|
Returns
|
Edit this page
View Source
Declaration
public Task<IReadOnlyList<Device>> GetDevicesAsync(CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<DirectContent> GetDirectRoomsAsync(CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<ClientEvent> GetEventAsync(string roomId, string eventId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<IReadOnlyCollection<string>> GetIgnoredUsersAsync(CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<IReadOnlyDictionary<string, RoomMember>> GetJoinedMembersAsync(string roomId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<IReadOnlyList<string>> GetJoinedRoomsAsync(CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<KeyBackupVersion?> GetKeyBackupVersionAsync(CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<LoginFlowsResponse> GetLoginFlowsAsync(CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<IReadOnlyList<ClientEvent>> GetMembersAsync(string roomId, string? membership = null, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<MessagesResponse> GetMessagesAsync(string roomId, string? from = null, Direction direction = Direction.Backward, int? limit = null, string? filter = null, string? to = null, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Return the room's power levels from the server; null when the room has none.
Declaration
public Task<PowerLevelsContent?> GetPowerLevelsAsync(string roomId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<PresenceContent> GetPresenceAsync(string userId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<ProfileResponse> GetProfileAsync(string userId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<PublicRoomsResponse> GetPublicRoomsAsync(string? server = null, int? limit = null, string? since = null, string? searchTerm = null, CancellationToken cancellationToken = default)
Parameters
| Type |
Name |
Description |
| string |
server |
Server whose directory to list; this homeserver when null.
|
| int? |
limit |
Maximum number of rooms; server default when null.
|
| string |
since |
NextBatch of the previous page.
|
| string |
searchTerm |
Text to match in name, topic and alias; uses the filtered form when set.
|
| CancellationToken |
cancellationToken |
Cancellation token.
|
Returns
|
Edit this page
View Source
Return the user's push rules as JSON by kind: override, content, room, sender and underride.
Declaration
public Task<JsonElement> GetPushRulesAsync(CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Return the user's pushers as JSON: an array of pushers with their app, key and data.
Declaration
public Task<JsonElement> GetPushersAsync(CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Return what registering on the server needs: whether it is open at all, a registration token, and policies to accept; throw MatrixException when registration is disabled.
Declaration
public Task<RegistrationRequirements> GetRegistrationRequirementsAsync(CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Return the registration tokens; with valid, only those that may or may not register now. For admins.
Declaration
public Task<IReadOnlyList<AdminRegistrationToken>> GetRegistrationTokensAsync(bool? valid = null, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Return a page of reports, newest first; for admins.
Declaration
public Task<AdminReportsResponse> GetReportsAsync(int from = 0, int limit = 100, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<T> GetRoomAccountDataAsync<T>(string roomId, string type, CancellationToken cancellationToken = default)
Parameters
Returns
Type Parameters
|
Edit this page
View Source
Declaration
public Task<IReadOnlyList<string>> GetRoomAliasesAsync(string roomId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Downloads all session keys of backup version.
Declaration
public Task<KeysBackup> GetRoomKeysAsync(string version, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Return the homeserver's MatrixRTC transports, preferred first; none when the server has none or does not know the endpoint.
Declaration
public Task<IReadOnlyList<RtcTransport>> GetRtcTransportsAsync(CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<IReadOnlyList<ClientEvent>> GetStateAsync(string roomId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<T> GetStateEventAsync<T>(string roomId, string eventType, string stateKey = "", CancellationToken cancellationToken = default)
Parameters
Returns
Type Parameters
TopicContent topic = await client.GetStateEventAsync<TopicContent>(roomId, EventTypes.RoomTopic);
|
Edit this page
View Source
Return the tags of a room.
Declaration
public Task<TagContent> GetTagsAsync(string roomId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<TurnServerResponse> GetTurnServerAsync(CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Return the server's preview of a web page as JSON: og:title, og:description, and og:image as an mxc:// URI with matrix:image:size; throws MatrixException when the server has previews off.
Declaration
public Task<JsonElement> GetUrlPreviewAsync(Uri url, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<VersionsResponse> GetVersionsAsync(CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Ignore userId; the server then hides their events and invite.
Declaration
public Task IgnoreUserAsync(string userId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public void InterruptSync()
|
Edit this page
View Source
Declaration
public Task InviteAsync(string roomId, string userId, string? reason = null, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Return whether an account is locked; for admins.
Declaration
public Task<bool> IsLockedAsync(string userId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Return whether the signed-in user is a server admin, by asking for an admin-only list; false on servers without Synapse's admin API.
Declaration
public Task<bool> IsServerAdminAsync(CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Return whether an account is suspended; for admins.
Declaration
public Task<bool> IsSuspendedAsync(string userId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<bool> IsUsernameAvailableAsync(string username, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Joins a room by ID or alias, accepting an invite if there is one; returns the room ID.
Declaration
public Task<string> JoinRoomAsync(string roomIdOrAlias, IEnumerable<string>? via = null, string? reason = null, CancellationToken cancellationToken = default)
Parameters
| Type |
Name |
Description |
| string |
roomIdOrAlias |
Room ID like !abc:server or alias like #room:server.
|
| IEnumerable<string> |
via |
Servers to join through when this server is not in the room.
|
| string |
reason |
Reason shown in the membership event.
|
| CancellationToken |
cancellationToken |
Cancellation token.
|
Returns
|
Edit this page
View Source
Kicks userId from a room.
Declaration
public Task KickAsync(string roomId, string userId, string? reason = null, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Leaves a room or rejects an invite.
Declaration
public Task LeaveRoomAsync(string roomId, string? reason = null, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<LoginResponse> LoginWithPasswordAsync(string user, string password, string? deviceDisplayName = null, CancellationToken cancellationToken = default)
Parameters
| Type |
Name |
Description |
| string |
user |
Localpart or full user ID.
|
| string |
password |
Password of the user.
|
| string |
deviceDisplayName |
Display name for the new device; server default when null.
|
| CancellationToken |
cancellationToken |
Cancellation token.
|
Returns
|
Edit this page
View Source
Declaration
public Task LogoutAllAsync(CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task LogoutAsync(CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Record roomId as a direct chat with userId in Direct, e.g. after joining an invite marked is_direct; nothing changes when it is recorded already.
Declaration
public Task MarkDirectRoomAsync(string userId, string roomId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Queries all device keys of userIds.
Declaration
public Task<KeysQueryResponse> QueryKeysAsync(IEnumerable<string> userIds, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Reactivate a deactivated account, so it can log in again; for admins.
Declaration
public Task ReactivateUserAsync(string userId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Redacts an event and returns the redaction's event ID.
Declaration
public Task<string> RedactAsync(string roomId, string eventId, string? reason = null, string? transactionId = null, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Registers an account and stores the Session; answers the stages of the first flow it can: the dummy stage of open registration, the token stage with registrationToken, and the terms stage when acceptTerms.
Declaration
public Task<RegisterResponse> RegisterAsync(string username, string password, string? registrationToken = null, string? deviceDisplayName = null, bool acceptTerms = false, bool inhibitLogin = false, CancellationToken cancellationToken = default)
Parameters
| Type |
Name |
Description |
| string |
username |
Wanted localpart, e.g. alice.
|
| string |
password |
Password of the new account.
|
| string |
registrationToken |
Token from the server's admin, when registration needs one.
|
| string |
deviceDisplayName |
Display name of the new device.
|
| bool |
acceptTerms |
Whether the user accepted the policies of GetRegistrationRequirementsAsync(CancellationToken).
|
| bool |
inhibitLogin |
Whether to only create the account, without a device or Session, e.g. to log in afterwards the usual way.
|
| CancellationToken |
cancellationToken |
Cancellation token.
|
Returns
|
Edit this page
View Source
Declaration
public Task RenameDeviceAsync(string deviceId, string displayName, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Reports an event as objectionable to the admins of this user's server.
Declaration
public Task ReportEventAsync(string roomId, string eventId, string? reason = null, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Reports a room as objectionable to the admins of this user's server.
Declaration
public Task ReportRoomAsync(string roomId, string? reason = null, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Reports a user as objectionable to the admins of this user's server.
Declaration
public Task ReportUserAsync(string userId, string? reason = null, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Return an OpenID token of the logged-in user, which another service, e.g. a LiveKit authorization service, verifies with the homeserver.
Declaration
public Task<OpenIdTokenResponse> RequestOpenIdTokenAsync(CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Set a new password for an account, logging out its devices unless logoutDevices is false; for admins.
Declaration
public Task ResetPasswordAsync(string userId, string newPassword, bool logoutDevices = true, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Resolves an alias like #room:server to a room ID.
Declaration
public Task<RoomAliasResponse> ResolveRoomAliasAsync(string roomAlias, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<T> RetryTransientAsync<T>(Func<CancellationToken, Task<T>> action, Action<Exception, TimeSpan>? onRetry, CancellationToken cancellationToken)
Parameters
Returns
Type Parameters
|
Edit this page
View Source
Searches users by user ID or display name, e.g. for /whois or completion.
Declaration
public Task<UserDirectoryResponse> SearchUsersAsync(string searchTerm, int? limit = null, CancellationToken cancellationToken = default)
Parameters
| Type |
Name |
Description |
| string |
searchTerm |
Text to match.
|
| int? |
limit |
Maximum number of results; server default when null.
|
| CancellationToken |
cancellationToken |
Cancellation token.
|
Returns
|
Edit this page
View Source
Send a state event after delay, unless restarted, cancelled or sent first; return its delay ID. MatrixRTC sends an empty membership so, to leave a call when the device disappears.
Declaration
public Task<string> SendDelayedStateEventAsync(string roomId, string eventType, object content, string stateKey, TimeSpan delay, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Send an edit replacing the text of eventId.
Declaration
public Task<string> SendEditAsync(string roomId, string eventId, string newText, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Send a Emote message, like IRC /me.
Declaration
public Task<string> SendEmoteAsync(string roomId, string text, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Sends a room event and returns its event ID.
Declaration
public Task<string> SendEventAsync(string roomId, string eventType, object content, string? transactionId = null, CancellationToken cancellationToken = default)
Parameters
| Type |
Name |
Description |
| string |
roomId |
Room ID.
|
| string |
eventType |
Event type, see EventTypes.
|
| object |
content |
Event content; serialized with its runtime type.
|
| string |
transactionId |
Reuse when retrying the same send so the server deduplicates it; generated when null.
|
| CancellationToken |
cancellationToken |
Cancellation token.
|
Returns
|
Edit this page
View Source
Upload content and send it to roomId as an image, video, audio or file message by contentType; return the event ID.
Declaration
public Task<string> SendFileAsync(string roomId, Stream content, string fileName, string contentType, string? transactionId = null, CancellationToken cancellationToken = default)
Parameters
| Type |
Name |
Description |
| string |
roomId |
Room ID.
|
| Stream |
content |
File bytes.
|
| string |
fileName |
File name shown to others.
|
| string |
contentType |
MIME type, e.g. image/png.
|
| string |
transactionId |
Reuse when retrying the same send; generated when null.
|
| CancellationToken |
cancellationToken |
Cancellation token.
|
Returns
|
Edit this page
View Source
Send an HTML message with a plain-text fallback.
Declaration
public Task<string> SendHtmlAsync(string roomId, string text, string html, Mentions? mentions = null, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
SendMessageAsync(string, MessageContent, string?, CancellationToken)
Declaration
public Task<string> SendMessageAsync(string roomId, MessageContent content, string? transactionId = null, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<string> SendNoticeAsync(string roomId, string text, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Send a reaction key, usually an emoji, to eventId.
Declaration
public Task<string> SendReactionAsync(string roomId, string eventId, string key, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task SendReceiptAsync(string roomId, string eventId, string receiptType = "m.read", CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Send a reply to replyTo, mentioning its sender.
Declaration
public Task<string> SendReplyAsync(string roomId, ClientEvent replyTo, string text, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Send a server notice to a local user; return the event ID. For admins.
Declaration
public Task<string> SendServerNoticeAsync(string userId, string text, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Sets a state event and returns its event ID.
Declaration
public Task<string> SendStateEventAsync(string roomId, string eventType, object content, string stateKey = "", CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
SendTextAsync(string, string, CancellationToken)
Declaration
public Task<string> SendTextAsync(string roomId, string text, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Sends to-device messages, content by user ID then device ID.
Declaration
public Task SendToDeviceAsync(string eventType, IReadOnlyDictionary<string, Dictionary<string, object>> messages, string? transactionId = null, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Sets global account data of type.
Declaration
public Task SetAccountDataAsync(string type, object content, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task SetAvatarUrlAsync(string avatarUrl, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task SetDisplayNameAsync(string displayName, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Lock an account, so its sessions are refused until it is unlocked; or unlock it. For admins.
Declaration
public Task SetLockedAsync(string userId, bool locked, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task SetPresenceAsync(string presence, string? statusMessage = null, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Replace the actions of a push rule, e.g. ["notify"].
Declaration
public Task SetPushRuleActionsAsync(string kind, string ruleId, IReadOnlyList<object> actions, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task SetPushRuleAsync(string kind, string ruleId, object rule, string? before = null, string? after = null, CancellationToken cancellationToken = default)
Parameters
| Type |
Name |
Description |
| string |
kind |
Rule kind, e.g. room to change a room's notifications, with the room ID as ruleId.
|
| string |
ruleId |
Rule ID; a room ID for room rules, a user ID for sender rules.
|
| object |
rule |
The rule's actions, with conditions or pattern as its kind needs, e.g. new { actions = Array.Empty<object>() } to mute.
|
| string |
before |
Rule ID to place it before, or null.
|
| string |
after |
Rule ID to place it after, or null.
|
| CancellationToken |
cancellationToken |
Cancellation token.
|
Returns
|
Edit this page
View Source
Enable or disable a push rule, including the server's default rules.
Declaration
public Task SetPushRuleEnabledAsync(string kind, string ruleId, bool enabled, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Add, replace or delete a pusher: an object with pushkey, app_id and kind (null deletes), and when adding app_display_name, device_display_name, lang and data with the gateway url.
Declaration
public Task SetPusherAsync(object pusher, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task SetReadMarkersAsync(string roomId, string fullyRead, string? read = null, CancellationToken cancellationToken = default)
Parameters
| Type |
Name |
Description |
| string |
roomId |
Room ID.
|
| string |
fullyRead |
Event up to which the user has read everything.
|
| string |
read |
Event for a public read receipt; none when null.
|
| CancellationToken |
cancellationToken |
Cancellation token.
|
Returns
|
Edit this page
View Source
Mark a report resolved, or open it again; for admins of Uniform servers, as Synapse has no such call.
Declaration
public Task SetReportResolvedAsync(long reportId, bool resolved, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Sets room account data of type.
Declaration
public Task SetRoomAccountDataAsync(string roomId, string type, object content, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<string> SetRoomAvatarAsync(string roomId, MxcUri? avatarUrl, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task SetRoomDirectoryVisibilityAsync(string roomId, bool listed, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<string> SetRoomNameAsync(string roomId, string name, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<string> SetRoomTopicAsync(string roomId, string topic, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Give or take server admin rights; for admins.
Declaration
public Task SetServerAdminAsync(string userId, bool admin, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Suspend an account, so it can read but not send, join or invite; or end the suspension. For admins.
Declaration
public Task SetSuspendedAsync(string userId, bool suspended, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task SetTagAsync(string roomId, string tag, double? order = null, CancellationToken cancellationToken = default)
Parameters
| Type |
Name |
Description |
| string |
roomId |
Room ID.
|
| string |
tag |
Tag name; custom tags use reverse-DNS names like u.work.
|
| double? |
order |
Position among rooms with the same tag, from 0 to 1.
|
| CancellationToken |
cancellationToken |
Cancellation token.
|
Returns
|
Edit this page
View Source
Set whether the user is typing in a room.
Declaration
public Task SetTypingAsync(string roomId, bool typing, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
| Type |
Name |
Description |
| string |
roomId |
Room ID.
|
| bool |
typing |
Whether the user is typing.
|
| TimeSpan? |
timeout |
How long typing lasts unless renewed; used only when typing is true.
|
| CancellationToken |
cancellationToken |
Cancellation token.
|
Returns
|
Edit this page
View Source
Give userId level in the room, e.g. Moderator, keeping every other power level as it is.
Declaration
public Task<string> SetUserPowerLevelAsync(string roomId, string userId, long level, CancellationToken cancellationToken = default)
Parameters
| Type |
Name |
Description |
| string |
roomId |
Room ID.
|
| string |
userId |
User to change.
|
| long |
level |
New level; 0 is an ordinary member.
|
| CancellationToken |
cancellationToken |
Cancellation token.
|
Returns
|
Edit this page
View Source
Shut a room down on the server: its local members leave, its aliases go, and with block no local user can join it again. For admins.
Declaration
public Task<AdminRoomShutdown> ShutdownRoomAsync(string roomId, bool block, string? message = null, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Syncs once; waits up to timeout for new events.
Declaration
public Task<SyncResponse> SyncAsync(string? since = null, TimeSpan? timeout = null, string? filter = null, bool fullState = false, string? setPresence = null, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Sync repeatedly, yielding each response; retry transient failures and a locked account (UserLocked) with backoff, and throw on others such as UnknownToken.
Declaration
public IAsyncEnumerable<SyncResponse> SyncLoopAsync(string? since = null, string? filter = null, TimeSpan? timeout = null, Action<Exception, TimeSpan>? onRetry = null, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Return global account data of type, or null when unset.
Declaration
public Task<T?> TryGetAccountDataAsync<T>(string type, CancellationToken cancellationToken = default) where T : class
Parameters
Returns
Type Parameters
|
Edit this page
View Source
Return raw content of one state event, or null when unset.
Declaration
public Task<JsonElement?> TryGetStateEventAsync(string roomId, string eventType, string stateKey = "", CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task UnbanAsync(string roomId, string userId, string? reason = null, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task UnignoreUserAsync(string userId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Restart, cancel or send a delayed event: action is restart, cancel or send.
Declaration
public Task UpdateDelayedEventAsync(string delayId, string action, CancellationToken cancellationToken = default)
Parameters
Returns
Exceptions
|
Edit this page
View Source
Change how many times a token may be used, null for any number, and when it expires, null for never; for admins.
Declaration
public Task<AdminRegistrationToken> UpdateRegistrationTokenAsync(string token, int? usesAllowed, DateTimeOffset? expiry, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
UploadCrossSigningKeysAsync(JsonObject, JsonObject, JsonObject, string?, CancellationToken)
Uploads cross-signing public keys; the server may ask for the password, and refuses to replace keys without it.
Declaration
public Task UploadCrossSigningKeysAsync(JsonObject masterKey, JsonObject selfSigningKey, JsonObject userSigningKey, string? password, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
UploadKeysAsync(JsonObject?, JsonObject?, JsonObject?, CancellationToken)
Uploads signed device keys, one-time keys and fallback keys; any may be null.
Declaration
public Task<KeysUploadResponse> UploadKeysAsync(JsonObject? deviceKeys, JsonObject? oneTimeKeys, JsonObject? fallbackKeys, CancellationToken cancellationToken = default)
Parameters
| Type |
Name |
Description |
| JsonObject |
deviceKeys |
Signed device keys, uploaded once per device.
|
| JsonObject |
oneTimeKeys |
Signed one-time keys by signed_curve25519:id.
|
| JsonObject |
fallbackKeys |
Signed fallback keys by signed_curve25519:id.
|
| CancellationToken |
cancellationToken |
Cancellation token.
|
Returns
|
Edit this page
View Source
Uploads media and returns its content URI for e.g. Url.
Declaration
public Task<MxcUri> UploadMediaAsync(Stream content, string contentType, string? fileName = null, CancellationToken cancellationToken = default)
Parameters
| Type |
Name |
Description |
| Stream |
content |
Media bytes; buffered in memory when not seekable, as rate-limit retries resend it.
|
| string |
contentType |
MIME type, e.g. image/png.
|
| string |
fileName |
File name to store with the media.
|
| CancellationToken |
cancellationToken |
Cancellation token.
|
Returns
|
Edit this page
View Source
Declaration
public Task UploadMediaToAsync(MxcUri contentUri, Stream content, string contentType, string? fileName = null, CancellationToken cancellationToken = default)
Parameters
| Type |
Name |
Description |
| MxcUri |
contentUri |
The reserved URI.
|
| Stream |
content |
Media bytes; buffered in memory when not seekable, as rate-limit retries resend it.
|
| string |
contentType |
MIME type, e.g. image/png.
|
| string |
fileName |
File name to store with the media.
|
| CancellationToken |
cancellationToken |
Cancellation token.
|
Returns
|
Edit this page
View Source
Uploads session keys to backup version; the server keeps the better of old and new.
Declaration
public Task UploadRoomKeysAsync(string version, KeysBackup keys, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
UploadSignaturesAsync(IReadOnlyDictionary<string, Dictionary<string, JsonObject>>, CancellationToken)
Uploads signatures of devices or master keys: user ID, then device ID or public key, then the signed object.
Declaration
public Task<JsonElement> UploadSignaturesAsync(IReadOnlyDictionary<string, Dictionary<string, JsonObject>> signatures, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<WhoAmIResponse> WhoAmIAsync(CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Return a user's devices and connections with whois; servers allow it for admins, and for oneself.
Declaration
public Task<WhoisResponse> WhoisAsync(string userId, CancellationToken cancellationToken = default)
Parameters
Returns