Class

MatrixClient

MatrixClient(homeserverUrl, accessToken, storage, cryptoStore)

A client that is capable of interacting with a matrix homeserver.
Constructor

# new MatrixClient(homeserverUrl, accessToken, storage, cryptoStore)

Creates a new matrix client
Parameters:
Name Type Default Description
homeserverUrl string The homeserver's client-server API URL
accessToken string The access token for the homeserver
storage IStorageProvider null The storage provider to use. Defaults to MemoryStorageProvider.
cryptoStore ICryptoStorageProvider null Optional crypto storage provider to use. If not supplied, end-to-end encryption will not be functional in this client.

View Source MatrixClient.ts, line 39

Classes

MatrixClient
MatrixClient

Members

# adminApis

Gets the admin API access class.

View Source MatrixClient.ts, line 163

# crypto

The crypto manager instance for this client. Generally speaking, this shouldn't need to be accessed but is made available. Will be null/undefined if crypto is not possible.

View Source MatrixClient.ts, line 64

CryptoClient

# crypto

The crypto manager instance for this client. Generally speaking, this shouldn't need to be accessed but is made available. Will be null/undefined if crypto is not possible.

View Source MatrixClient.ts, line 2112

# dms

The DM manager instance for this client.

View Source MatrixClient.ts, line 68

DMs

# dms

The DM manager instance for this client.

View Source MatrixClient.ts, line 2118

# metrics

The metrics instance for this client

View Source MatrixClient.ts, line 139

# metrics

Assigns a new metrics instance, overwriting the old one.

View Source MatrixClient.ts, line 146

# persistTokenAfterSync

Set this to true to have the client only persist the sync token after the sync has been processed successfully. Note that if this is true then when the sync loop throws an error the client will not persist a token.

View Source MatrixClient.ts, line 87

# protected persistTokenAfterSync

Set this to true to have the client only persist the sync token after the sync has been processed successfully. Note that if this is true then when the sync loop throws an error the client will not persist a token.

View Source MatrixClient.ts, line 2125

# storageProvider

The storage provider for this client. Direct access is usually not required.

View Source MatrixClient.ts, line 133

# syncingPresence

The presence status to use while syncing. The valid values are "online" to set the account as online, "offline" to set the user as offline, "unavailable" for marking the user away, and null for not setting an explicit presence (the default). Has no effect if the client is not syncing. Does not apply until the next sync request.

View Source MatrixClient.ts, line 51

PresenceState | null

# syncingPresence

The presence status to use while syncing. The valid values are "online" to set the account as online, "offline" to set the user as offline, "unavailable" for marking the user away, and null for not setting an explicit presence (the default). Has no effect if the client is not syncing. Does not apply until the next sync request.

View Source MatrixClient.ts, line 2096

# syncingTimeout

The number of milliseconds to wait for new events for on the next sync. Has no effect if the client is not syncing. Does not apply until the next sync request.

View Source MatrixClient.ts, line 57

# syncingTimeout

The number of milliseconds to wait for new events for on the next sync. Has no effect if the client is not syncing. Does not apply until the next sync request.

View Source MatrixClient.ts, line 2103

# unstableApis

Gets the unstable API access class. This is generally not recommended to be used by clients.

View Source MatrixClient.ts, line 156

Methods

# addPreprocessor(preprocessor) → {void}

Adds a preprocessor to the event pipeline. When this client encounters an event, it will try to run it through the preprocessors it can in the order they were added.
Parameters:
Name Type Description
preprocessor IPreprocessor the preprocessor to add

View Source MatrixClient.ts, line 2216

void

# adminApis() → {AdminApis}

Gets the admin API access class.

View Source MatrixClient.ts, line 2172

The admin API access class.
AdminApis

# banUser(userId, roomId, reasonnullable) → {Promise.<any>}

Bans a user from a room.
Parameters:
Name Type Attributes Description
userId string the user ID to ban
roomId string the room ID to set the ban in
reason string <nullable>
optional reason for the ban

View Source MatrixClient.ts, line 2444

resolves when completed
Promise.<any>

# async calculatePowerLevelChangeBoundsOn(targetUserId, roomId) → {Promise.<PowerLevelBounds>}

Determines the boundary conditions for this client's ability to change another user's power level in a given room. This will identify the maximum possible level this client can change the user to, and if that change could even be possible. If the returned object indicates that the client can change the power level of the user, the client is able to set the power level to any value equal to or less than the maximum value.
Parameters:
Name Type Description
targetUserId string The user ID to compare against.
roomId string The room ID to compare within.

View Source MatrixClient.ts, line 2876

The bounds of the client's ability to change the user's power level.
Promise.<PowerLevelBounds>

# async checkOneTimeKeyCounts() → {Promise.<OTKCounts>}

Gets the current One Time Key counts.

View Source MatrixClient.ts, line 2995

Resolves to the One Time Key counts.
Promise.<OTKCounts>

# async claimOneTimeKeys(userDeviceMap, federationTimeoutMs) → {Promise.<OTKClaimResponse>}

Claims One Time Keys for a set of user devices, returning those keys. The caller is expected to verify and validate the returned keys. Failures with federation are reported in the returned object.
Parameters:
Name Type Description
userDeviceMap Record.<string, Record.<string, OTKAlgorithm>> The map of user IDs to device IDs to OTKAlgorithm to request a claim for.
federationTimeoutMs number The default timeout for claiming keys over federation. Defaults to 10 seconds.

View Source MatrixClient.ts, line 3047

Promise.<OTKClaimResponse>

# createRoom(properties) → {Promise.<string>}

Creates a room. See the RoomCreateOptions interface for more information on what to provide for `properties`. Note that creating a room may cause the bot/appservice to raise a join event.
Parameters:
Name Type Description
properties RoomCreateOptions the properties of the room.

View Source MatrixClient.ts, line 2839

resolves to the room ID that represents the room
Promise.<string>

# createRoomAlias(alias, roomId) → {Promise}

Adds a new room alias to the room directory
Parameters:
Name Type Description
alias string The alias to add (eg: "#my-room:matrix.org")
roomId string The room ID to add the alias to

View Source MatrixClient.ts, line 2370

resolves when the alias has been added
Promise

# async createSpace(opts) → {Promise.<Space>}

Creates a Space room.
Parameters:
Name Type Description
opts SpaceCreateOptions The creation options.

View Source MatrixClient.ts, line 2966

Resolves to the created space.
Promise.<Space>

# deleteRoomAlias(alias) → {Promise}

Removes a room alias from the room directory
Parameters:
Name Type Description
alias string The alias to remove

View Source MatrixClient.ts, line 2378

resolves when the alias has been deleted
Promise

# doRequest(method, endpoint, qs, body, timeout, raw, contentType, noEncoding) → {Promise.<any>}

Performs a web request to the homeserver, applying appropriate authorization headers for this client.
Parameters:
Name Type Description
method "GET" | "POST" | "PUT" | "DELETE" The HTTP method to use in the request
endpoint string The endpoint to call. For example: "/_matrix/client/v3/account/whoami"
qs any The query string to send. Optional.
body any The request body to send. Optional. Will be converted to JSON unless the type is a Buffer.
timeout number The number of milliseconds to wait before timing out.
raw boolean If true, the raw response will be returned instead of the response body.
contentType string The content type to send. Only used if the `body` is a Buffer.
noEncoding string Set to true to disable encoding, and return a Buffer. Defaults to false

View Source MatrixClient.ts, line 3086

Resolves to the response (body), rejected if a non-2xx status code was returned.
Promise.<any>

# async doesServerSupportAnyOneVersion(versions) → {Promise.<boolean>}

Determines if the server supports at least one of the given specification versions or not.
Parameters:
Name Type Description
versions Array.<string> The versions to look for. Eg: ["v1.1"]

View Source MatrixClient.ts, line 2252

Resolves to true if the server supports any of the versions, false otherwise.
Promise.<boolean>

# async doesServerSupportUnstableFeature(feature) → {Promise.<boolean>}

Determines if the server supports a given unstable feature flag. Useful for determining if the server can support an unstable MSC.
Parameters:
Name Type Description
feature string The feature name to look for.

View Source MatrixClient.ts, line 2234

Resolves to true if the server supports the flag, false otherwise.
Promise.<boolean>

# async doesServerSupportVersion(version) → {Promise.<boolean>}

Determines if the server supports a given version of the specification or not.
Parameters:
Name Type Description
version string The version to look for. Eg: "v1.1"

View Source MatrixClient.ts, line 2243

Resolves to true if the server supports the version, false otherwise.
Promise.<boolean>

# async downloadContent(mxcUrl, allowRemote) → {Promise.<{data: Buffer, contentType: string}>}

Download content from the homeserver's media repository. Note that this will not automatically decrypt media as it cannot determine if the media is encrypted.
Parameters:
Name Type Description
mxcUrl string The MXC URI for the content.
allowRemote string Indicates to the server that it should not attempt to fetch the media if it is deemed remote. This is to prevent routing loops where the server contacts itself. Defaults to true if not provided.

View Source MatrixClient.ts, line 2933

Resolves to the downloaded content.
Promise.<{data: Buffer, contentType: string}>

# forgetRoom(roomId) → {Promise.<{}>}

Forgets the given room
Parameters:
Name Type Description
roomId string the room ID to forget

View Source MatrixClient.ts, line 2669

Resolves when forgotten
Promise.<{}>

# async getAccountData(eventType) → {Promise.<any>}

Retrieves content from account data.
Parameters:
Name Type Description
eventType string The type of account data to retrieve.

View Source MatrixClient.ts, line 2269

Resolves to the content of that account data.
Promise.<any>

# getAllRoomMembers(roomId, atToken) → {Promise.<Array.<MembershipEvent>>}

Gets all room members in the room, optionally at a given point in time.
Parameters:
Name Type Description
roomId string The room ID to get members of.
atToken string Optional batch token to get members at. Leave falsy for "now".

View Source MatrixClient.ts, line 2629

Resolves to the member events in the room.
Promise.<Array.<MembershipEvent>>

# getDirectoryVisibility(roomId) → {Promise.<("public"|"private")>}

Gets the visibility of a room in the directory.
Parameters:
Name Type Description
roomId string The room ID to query the visibility of

View Source MatrixClient.ts, line 2395

The visibility of the room
Promise.<("public"|"private")>

# async getEvent(roomId, eventId) → {Promise.<any>}

Gets an event for a room. If the event is encrypted, and the client supports encryption, and the room is encrypted, then this will return a decrypted event.
Parameters:
Name Type Description
roomId string the room ID to get the event in
eventId string the event ID to look up

View Source MatrixClient.ts, line 2495

resolves to the found event
Promise.<any>

# async getEventContext(roomId, eventId, limit) → {Promise.<EventContext>}

Gets the context surrounding an event.
Parameters:
Name Type Description
roomId string The room ID to get the context in.
eventId string The event ID to get the context of.
limit number The maximum number of events to return on either side of the event.

View Source MatrixClient.ts, line 2544

The context of the event
Promise.<EventContext>

# async getIdentityServerClient(identityServerName) → {Promise.<IdentityClient>}

Acquires an identity server client for communicating with an identity server. Note that this will automatically do the login portion to establish a usable token with the identity server provided, but it will not automatically accept any terms of service. The identity server name provided will in future be resolved to a server address - for now that resolution is assumed to be prefixing the name with `https://`.
Parameters:
Name Type Description
identityServerName string The domain of the identity server to connect to.

View Source MatrixClient.ts, line 2199

Resolves to a prepared identity client.
Promise.<IdentityClient>

# getJoinedRoomMembers(roomId) → {Promise.<string>}

Gets the joined members in a room. The client must be in the room to make this request.
Parameters:
Name Type Description
roomId string The room ID to get the joined members of.

View Source MatrixClient.ts, line 2595

The joined user IDs in the room
Promise.<string>

# async getJoinedRoomMembersWithProfiles(roomId) → {Object}

Gets the joined members in a room, as an object mapping userIds to profiles. The client must be in the room to make this request.
Parameters:
Name Type Description
roomId string The room ID to get the joined members of.

View Source MatrixClient.ts, line 2604

The joined user IDs in the room as an object mapped to a set of profiles.
Object

# getJoinedRooms() → {Promise.<Array.<string>>}

Gets a list of joined room IDs

View Source MatrixClient.ts, line 2587

resolves to a list of room IDs the client participates in
Promise.<Array.<string>>

# async getOpenIDConnectToken() → {Promise.<OpenIDConnectToken>}

Retrieves an OpenID Connect token from the homeserver for the current user.

View Source MatrixClient.ts, line 2260

Resolves to the token.
Promise.<OpenIDConnectToken>

# async getOwnDevices() → {Promise.<Array.<OwnUserDevice>>}

Gets a device list for the client's own account, with metadata. The devices are not verified in this response, but should be active on the account.

View Source MatrixClient.ts, line 3032

Resolves to the active devices on the account.
Promise.<Array.<OwnUserDevice>>

# async getPresenceStatus() → {Promise.<Presence>}

Gets the presence information for the current user.

View Source MatrixClient.ts, line 2331

Resolves to the presence status of the user.
Promise.<Presence>

# async getPresenceStatusFor(userId) → {Promise.<Presence>}

Gets the presence information for a given user.
Parameters:
Name Type Description
userId string The user ID to look up the presence of.

View Source MatrixClient.ts, line 2340

Resolves to the presence status of the user.
Promise.<Presence>

# async getPublishedAlias(roomIdOrAlias) → {Promise.<string>}

Gets a published alias for the given room. These are supplied by the room admins and should point to the room, but may not. This is primarily intended to be used in the context of rendering a mention (pill) for a room.
Parameters:
Name Type Description
roomIdOrAlias string The room ID or alias to get an alias for.

View Source MatrixClient.ts, line 2361

Resolves to a published room alias, or falsey if none found.
Promise.<string>

# getRawEvent(roomId, eventId) → {Promise.<any>}

Gets an event for a room. Returned as a raw event.
Parameters:
Name Type Description
roomId string the room ID to get the event in
eventId string the event ID to look up

View Source MatrixClient.ts, line 2504

resolves to the found event
Promise.<any>

# async getRelationsForEvent(roomId, eventId, relationTypenullable, eventTypenullable) → {Promise.<{chunk: Array.<any>}>}

Get relations for a given event.
Parameters:
Name Type Attributes Description
roomId string The room ID to for the given event.
eventId string The event ID to list relations for.
relationType string <nullable>
The type of relations (e.g. `m.room.member`) to filter for. Optional.
eventType string <nullable>
The type of event to look for (e.g. `m.room.member`). Optional.

View Source MatrixClient.ts, line 3070

Resolves to an object containing the chunk of relations
Promise.<{chunk: Array.<any>}>

# async getRoomAccountData(eventType, roomId) → {Promise.<any>}

Retrieves content from room account data.
Parameters:
Name Type Description
eventType string The type of room account data to retrieve.
roomId string The room to read the account data from.

View Source MatrixClient.ts, line 2279

Resolves to the content of that account data.
Promise.<any>

# getRoomMembers(roomId, batchToken, membership, notMembership) → {Promise.<Array.<MembershipEvent>>}

Gets the membership events of users in the room. Defaults to all membership types, though this can be controlled with the membership and notMembership arguments. To change the point in time, use the batchToken.
Parameters:
Name Type Description
roomId string The room ID to get members in.
batchToken string The point in time to get members at (or null for 'now')
membership Array.<string> The membership kinds to search for.
notMembership Array.<string> The membership kinds to not search for.
See:
  • getRoomMembersByMembership
  • getRoomMembersWithoutMembership
  • getAllRoomMembers

View Source MatrixClient.ts, line 2620

Resolves to the membership events of the users in the room.
Promise.<Array.<MembershipEvent>>

# getRoomMembersByMembership(roomId, membership, atTokennullable) → {Promise.<Array.<MembershipEvent>>}

Gets the membership events of users in the room which have a particular membership type. To change the point in time the server should return membership events at, use `atToken`.
Parameters:
Name Type Attributes Description
roomId string The room ID to get members in.
membership Membership The membership to search for.
atToken string <nullable>
Optional batch token to use, or null for "now".

View Source MatrixClient.ts, line 2640

Resolves to the membership events of the users in the room.
Promise.<Array.<MembershipEvent>>

# async getRoomMembersWithoutMembership(roomId, notMembership, atTokennullable) → {Promise.<Array.<MembershipEvent>>}

Gets the membership events of users in the room which lack a particular membership type. To change the point in time the server should return membership events at, use `atToken`.
Parameters:
Name Type Attributes Description
roomId string The room ID to get members in.
notMembership Membership The membership to NOT search for.
atToken string <nullable>
Optional batch token to use, or null for "now".

View Source MatrixClient.ts, line 2652

Resolves to the membership events of the users in the room.
Promise.<Array.<MembershipEvent>>

# getRoomState(roomId) → {Promise.<Array.<any>>}

Gets the room state for the given room. Returned as raw events.
Parameters:
Name Type Description
roomId string the room ID to get state for

View Source MatrixClient.ts, line 2512

resolves to the room's state
Promise.<Array.<any>>

# getRoomStateEvent(roomId, type, stateKey) → {Promise.<any>}

Gets a state event for a given room of a given type under the given state key.
Parameters:
Name Type Description
roomId string the room ID
type string the event type
stateKey String the state key

View Source MatrixClient.ts, line 2533

resolves to the state event
Promise.<any>

# getRoomStateEvents(roomId, type, stateKey) → {Promise.<(any|Array.<any>)>}

Gets the state events for a given room of a given type under the given state key.
Parameters:
Name Type Description
roomId string the room ID
type string the event type
stateKey String the state key, falsey if not needed
Deprecated:
  • It is not possible to get an array of events - use getRoomStateEvent instead

View Source MatrixClient.ts, line 2523

resolves to the state event(s)
Promise.<(any|Array.<any>)>

# async getRoomUpgradeHistory(roomId) → {Promise.<{previous: Array.<RoomReference>, newer: Array.<RoomReference>}>}

Determines the upgrade history for a given room as a doubly-linked list styled structure. Given a room ID in the history of upgrades, the resulting `previous` array will hold any rooms which are older than the given room. The resulting `newer` array will hold any rooms which are newer versions of the room. Both arrays will be defined, but may be empty individually. Element zero of each will always be the nearest to the given room ID and the last element will be the furthest from the room. The given room will never be in either array.
Parameters:
Name Type Description
roomId string the room ID to get the history of

View Source MatrixClient.ts, line 2957

Resolves to the room's upgrade history
Promise.<{previous: Array.<RoomReference>, newer: Array.<RoomReference>}>

# async getSafeAccountData(eventType, defaultContent) → {Promise.<any>}

Retrieves content from account data. If the account data request throws an error, this simply returns the default provided.
Parameters:
Name Type Description
eventType string The type of account data to retrieve.
defaultContent any The default value. Defaults to null.

View Source MatrixClient.ts, line 2290

Resolves to the content of that account data, or the default.
Promise.<any>

# async getSafeRoomAccountData(eventType, roomId, defaultContent) → {Promise.<any>}

Retrieves content from room account data. If the account data request throws an error, this simply returns the default provided.
Parameters:
Name Type Description
eventType string The type of room account data to retrieve.
roomId string The room to read the account data from.
defaultContent any The default value. Defaults to null.

View Source MatrixClient.ts, line 2302

Resolves to the content of that room account data, or the default.
Promise.<any>

# async getServerVersions() → {Promise.<ServerVersions>}

Retrieves the server's supported specification versions and unstable features.

View Source MatrixClient.ts, line 2224

Resolves to the server's supported versions.
Promise.<ServerVersions>

# async getSpace(roomIdOrAlias) → {Promise.<Space>}

Gets a Space. This API does not work with unstable spaces (e.g. org.matrix.msc.1772.space)
Parameters:
Name Type Description
roomIdOrAlias string

View Source MatrixClient.ts, line 2978

If the room is not a space or there was an error
Resolves to the space.
Promise.<Space>

# async getUserDevices(userIds, federationTimeoutMs) → {Promise.<MultiUserDeviceListResponse>}

Gets unverified device lists for the given users. The caller is expected to validate and verify the device lists, including that the returned devices belong to the claimed users. Failures with federation are reported in the returned object. Users which did not fail a federation lookup but have no devices will not appear in either the failures or in the returned devices. See https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-keys-query for more information.
Parameters:
Name Type Description
userIds Array.<string> The user IDs to query.
federationTimeoutMs number The default timeout for requesting devices over federation. Defaults to 10 seconds.

View Source MatrixClient.ts, line 3023

Resolves to the device list/errors for the requested user IDs.
Promise.<MultiUserDeviceListResponse>

# async getUserId() → {Promise.<string>}

Gets the current user ID for this client

View Source MatrixClient.ts, line 2461

The user ID of this client
Promise.<string>

# getUserProfile(userId) → {Promise.<any>}

Gets the profile for a given user
Parameters:
Name Type Description
userId string the user ID to lookup

View Source MatrixClient.ts, line 2552

the profile of the user
Promise.<any>

# async getWhoAmI() → {Promise.<IWhoAmI>}

Gets the user's information from the server directly.

View Source MatrixClient.ts, line 2469

The "who am I" response.
Promise.<IWhoAmI>

# impersonateUserId(userId, deviceId) → {void}

Sets a user ID to impersonate as. This will assume that the access token for this client is for an application service, and that the userId given is within the reach of the application service. Setting this to null will stop future impersonation. The user ID is assumed to already be valid
Parameters:
Name Type Description
userId string The user ID to masquerade as, or `null` to clear masquerading.
deviceId string Optional device ID to impersonate under the given user, if supported by the server. Check the whoami response after setting.

View Source MatrixClient.ts, line 2185

void

# inviteUser(userId, roomId) → {Promise.<any>}

Invites a user to a room.
Parameters:
Name Type Description
userId string the user ID to invite
roomId string the room ID to invite the user to

View Source MatrixClient.ts, line 2424

resolves when completed
Promise.<any>

# async joinRoom(roomIdOrAlias, viaServers) → {Promise.<string>}

Joins the given room
Parameters:
Name Type Description
roomIdOrAlias string the room ID or alias to join
viaServers Array.<string> the server names to try and join through

View Source MatrixClient.ts, line 2580

resolves to the joined room ID
Promise.<string>

# kickUser(userId, roomId, reasonnullable) → {Promise.<any>}

Kicks a user from a room.
Parameters:
Name Type Attributes Description
userId string the user ID to kick
roomId string the room ID to kick the user in
reason string <nullable>
optional reason for the kick

View Source MatrixClient.ts, line 2434

resolves when completed
Promise.<any>

# leaveRoom(roomId, reasonopt) → {Promise.<any>}

Leaves the given room
Parameters:
Name Type Attributes Description
roomId string the room ID to leave
reason string <optional>
Optional reason to be included as the reason for leaving the room.

View Source MatrixClient.ts, line 2661

resolves when left
Promise.<any>

# lookupRoomAlias(roomAlias) → {Promise.<RoomDirectoryLookupResponse>}

Does a room directory lookup for a given room alias
Parameters:
Name Type Description
roomAlias string the room alias to look up in the room directory

View Source MatrixClient.ts, line 2415

resolves to the room's information
Promise.<RoomDirectoryLookupResponse>

# metrics(metrics)

Assigns a new metrics instance, overwriting the old one.
Parameters:
Name Type Description
metrics Metrics The new metrics instance.

View Source MatrixClient.ts, line 2157

# mxcToHttp(mxc) → {string}

Converts a MXC URI to an HTTP URL.
Parameters:
Name Type Description
mxc string The MXC URI to convert

View Source MatrixClient.ts, line 2898

The HTTP URL for the content.
string

# mxcToHttpThumbnail(mxc, width, height, method) → {string}

Converts a MXC URI to an HTTP URL for downsizing the content.
Parameters:
Name Type Description
mxc string The MXC URI to convert and downsize.
width number The width, as an integer, for the thumbnail.
height number The height, as an intenger, for the thumbnail.
method "crop" | "scale" Whether to crop or scale (preserve aspect ratio) the content.

View Source MatrixClient.ts, line 2909

The HTTP URL for the downsized content.
string

# redactEvent(roomId, eventId, reason) → {Promise.<string>}

Redact an event in a given room
Parameters:
Name Type Description
roomId string the room ID to send the redaction to
eventId string the event ID to redact
reason String an optional reason for redacting the event

View Source MatrixClient.ts, line 2829

resolves to the event ID that represents the redaction
Promise.<string>

# replyHtmlNotice(roomId, event, html) → {Promise.<string>}

Replies to a given event with the given HTML. The event is sent with a msgtype of m.notice. The message will be encrypted if the client supports encryption and the room is encrypted.
Parameters:
Name Type Description
roomId string the room ID to reply in
event any the event to reply to
html string the HTML to reply with.

View Source MatrixClient.ts, line 2735

resolves to the event ID which was sent
Promise.<string>

# replyHtmlText(roomId, event, html) → {Promise.<string>}

Replies to a given event with the given HTML. The event is sent with a msgtype of m.text. The message will be encrypted if the client supports encryption and the room is encrypted.
Parameters:
Name Type Description
roomId string the room ID to reply in
event any the event to reply to
html string the HTML to reply with.

View Source MatrixClient.ts, line 2712

resolves to the event ID which was sent
Promise.<string>

# replyNotice(roomId, event, text, html) → {Promise.<string>}

Replies to a given event with the given text. The event is sent with a msgtype of m.notice. The message will be encrypted if the client supports encryption and the room is encrypted.
Parameters:
Name Type Description
roomId string the room ID to reply in
event any the event to reply to
text string the text to reply with
html string the HTML to reply with, or falsey to use the `text`

View Source MatrixClient.ts, line 2724

resolves to the event ID which was sent
Promise.<string>

# replyText(roomId, event, text, html) → {Promise.<string>}

Replies to a given event with the given text. The event is sent with a msgtype of m.text. The message will be encrypted if the client supports encryption and the room is encrypted.
Parameters:
Name Type Description
roomId string the room ID to reply in
event any the event to reply to
text string the text to reply with
html string the HTML to reply with, or falsey to use the `text`

View Source MatrixClient.ts, line 2701

resolves to the event ID which was sent
Promise.<string>

# async resolveRoom(roomIdOrAlias) → {Promise.<string>}

Resolves a room ID or alias to a room ID. If the given ID or alias looks like a room ID already, it will be returned as-is. If the room ID or alias looks like a room alias, it will be resolved to a room ID if possible. If the room ID or alias is neither, an error will be raised.
Parameters:
Name Type Description
roomIdOrAlias string the room ID or alias to resolve to a room ID

View Source MatrixClient.ts, line 2407

resolves to the room ID
Promise.<string>

# async sendEvent(roomId, eventType, content) → {Promise.<string>}

Sends an event to the given room. This will encrypt the event before sending if the room is encrypted and the client supports encryption. Use sendRawEvent() to avoid this behaviour.
Parameters:
Name Type Description
roomId string the room ID to send the event to
eventType string the type of event to send
content string the event body to send

View Source MatrixClient.ts, line 2797

resolves to the event ID that represents the event
Promise.<string>

# sendHtmlNotice(roomId, html) → {Promise.<string>}

Sends a notice to the given room with HTML content. The message will be encrypted if the client supports encryption and the room is encrypted.
Parameters:
Name Type Description
roomId string the room ID to send the notice to
html string the HTML to send

View Source MatrixClient.ts, line 2755

resolves to the event ID that represents the message
Promise.<string>

# sendHtmlText(roomId, html) → {Promise.<string>}

Sends a text message to the given room with HTML content. The message will be encrypted if the client supports encryption and the room is encrypted.
Parameters:
Name Type Description
roomId string the room ID to send the text to
html string the HTML to send

View Source MatrixClient.ts, line 2775

resolves to the event ID that represents the message
Promise.<string>

# sendMessage(roomId, content) → {Promise.<string>}

Sends a message to the given room. The message will be encrypted if the client supports encryption and the room is encrypted.
Parameters:
Name Type Description
roomId string the room ID to send the message to
content object the event content to send

View Source MatrixClient.ts, line 2785

resolves to the event ID that represents the message
Promise.<string>

# sendNotice(roomId, text) → {Promise.<string>}

Sends a notice to the given room. The message will be encrypted if the client supports encryption and the room is encrypted.
Parameters:
Name Type Description
roomId string the room ID to send the notice to
text string the text to send

View Source MatrixClient.ts, line 2745

resolves to the event ID that represents the message
Promise.<string>

# async sendRawEvent(roomId, eventType, content) → {Promise.<string>}

Sends an event to the given room.
Parameters:
Name Type Description
roomId string the room ID to send the event to
eventType string the type of event to send
content string the event body to send

View Source MatrixClient.ts, line 2808

resolves to the event ID that represents the event
Promise.<string>

# sendReadReceipt(roomId, eventId) → {Promise.<any>}

Sends a read receipt for an event in a room
Parameters:
Name Type Description
roomId string the room ID to send the receipt to
eventId string the event ID to set the receipt at

View Source MatrixClient.ts, line 2678

resolves when the receipt has been sent
Promise.<any>

# sendStateEvent(roomId, type, stateKey, content) → {Promise.<string>}

Sends a state event to the given room
Parameters:
Name Type Description
roomId string the room ID to send the event to
type string the event type to send
stateKey string the state key to send, should not be null
content string the event body to send

View Source MatrixClient.ts, line 2819

resolves to the event ID that represents the message
Promise.<string>

# sendText(roomId, text) → {Promise.<string>}

Sends a text message to the given room. The message will be encrypted if the client supports encryption and the room is encrypted.
Parameters:
Name Type Description
roomId string the room ID to send the text to
text string the text to send

View Source MatrixClient.ts, line 2765

resolves to the event ID that represents the message
Promise.<string>

# async sendToDevices(type, messages) → {Promise.<void>}

Sends to-device messages to the respective users/devices.
Parameters:
Name Type Description
type string The message type being sent.
messages Record.<string, Record.<string, any>> The messages to send, mapped as user ID to device ID (or "*" to denote all of the user's devices) to message payload (content).

View Source MatrixClient.ts, line 3058

Resolves when complete.
Promise.<void>

# async setAccountData(eventType, content) → {Promise.<any>}

Sets account data.
Parameters:
Name Type Description
eventType string The type of account data to set
content any The content to set

View Source MatrixClient.ts, line 2312

Resolves when updated
Promise.<any>

# async setAvatarUrl(avatarUrl) → {Promise.<any>}

Sets a new avatar url for the user.
Parameters:
Name Type Description
avatarUrl string the new avatar URL for the user, in the form of a Matrix Content URI

View Source MatrixClient.ts, line 2570

resolves when complete
Promise.<any>

# setDirectoryVisibility(roomId, visibility) → {Promise}

Sets the visibility of a room in the directory.
Parameters:
Name Type Description
roomId string The room ID to manipulate the visibility of
visibility "public" | "private" The visibility to set for the room

View Source MatrixClient.ts, line 2387

resolves when the visibility has been updated
Promise

# async setDisplayName(displayName) → {Promise.<any>}

Sets a new display name for the user.
Parameters:
Name Type Description
displayName string the new display name for the user, or null to clear

View Source MatrixClient.ts, line 2561

resolves when complete
Promise.<any>

# setJoinStrategy(strategy) → {void}

Sets the strategy to use for when joinRoom is called on this client
Parameters:
Name Type Description
strategy IJoinRoomStrategy The strategy to use, or null to use none

View Source MatrixClient.ts, line 2207

void

# async setPresenceStatus(presence, statusMessagenullable) → {Promise.<any>}

Sets the presence status for the current user.
Parameters:
Name Type Attributes Description
presence PresenceState The new presence state for the user.
statusMessage string <nullable>
Optional status message to include with the presence.

View Source MatrixClient.ts, line 2350

Resolves when complete.
Promise.<any>

# async setRoomAccountData(eventType, roomId, content) → {Promise.<any>}

Sets room account data.
Parameters:
Name Type Description
eventType string The type of room account data to set
roomId string The room to set account data in
content any The content to set

View Source MatrixClient.ts, line 2323

Resolves when updated
Promise.<any>

# async setTyping(roomId, typing, timeout) → {Promise.<any>}

Sets the typing status of the current user in a room
Parameters:
Name Type Description
roomId string the room ID the user is typing in
typing boolean is the user currently typing
timeout number how long should the server preserve the typing state, in milliseconds

View Source MatrixClient.ts, line 2689

resolves when the typing state has been set
Promise.<any>

# async setUserPowerLevel(userId, roomId, newLevel) → {Promise.<any>}

Sets the power level for a given user ID in the given room. Note that this is not safe to call multiple times concurrently as changes are not atomic. This will throw an error if the user lacks enough permission to change the power level, or if a power level event is missing from the room.
Parameters:
Name Type Description
userId string The user ID to change
roomId string The room ID to change the power level in
newLevel number The integer power level to set the user to.

View Source MatrixClient.ts, line 2890

Resolves when complete.
Promise.<any>

# async start(filter) → {Promise.<any>}

Starts syncing the client with an optional filter
Parameters:
Name Type Description
filter any The filter to use, or null for none

View Source MatrixClient.ts, line 2484

Resolves when the client has started syncing
Promise.<any>

# stop()

Stops the client from syncing.

View Source MatrixClient.ts, line 2475

# storageProvider() → {IStorageProvider}

The storage provider for this client. Direct access is usually not required.

View Source MatrixClient.ts, line 2143

# unbanUser(userId, roomId) → {Promise.<any>}

Unbans a user in a room.
Parameters:
Name Type Description
userId string the user ID to unban
roomId string the room ID to lift the ban in

View Source MatrixClient.ts, line 2453

resolves when completed
Promise.<any>

# unstableApis() → {UnstableApis}

Gets the unstable API access class. This is generally not recommended to be used by clients.

View Source MatrixClient.ts, line 2165

The unstable API access class.
UnstableApis

# uploadContent(data, contentType, filename) → {Promise.<string>}

Uploads data to the homeserver's media repository. Note that this will not automatically encrypt media as it cannot determine if the media should be encrypted.
Parameters:
Name Type Description
data Buffer the content to upload.
contentType string the content type of the file. Defaults to application/octet-stream
filename string the name of the file. Optional.

View Source MatrixClient.ts, line 2920

resolves to the MXC URI of the content
Promise.<string>

# uploadContentFromUrl(url) → {Promise.<string>}

Uploads data to the homeserver's media repository after downloading it from the provided URL.
Parameters:
Name Type Description
url string The URL to download content from.

View Source MatrixClient.ts, line 2942

Resolves to the MXC URI of the content
Promise.<string>

# async uploadDeviceOneTimeKeys(keys) → {Promise.<OTKCounts>}

Uploads One Time Keys for the current device.
Parameters:
Name Type Description
keys OTKs The keys to upload.

View Source MatrixClient.ts, line 2987

Resolves to the current One Time Key counts when complete.
Promise.<OTKCounts>

# async uploadFallbackKey(fallbackKey) → {Promise.<OTKCounts>}

Uploads a fallback One Time Key to the server for usage. This will replace the existing fallback key.
Parameters:
Name Type Description
fallbackKey FallbackKey The fallback key.

View Source MatrixClient.ts, line 3005

Resolves to the One Time Key counts.
Promise.<OTKCounts>

# async userHasPowerLevelFor(userId, roomId, eventType, isState) → {Promise.<boolean>}

Checks if a given user has a required power level required to send the given event.
Parameters:
Name Type Description
userId string the user ID to check the power level of
roomId string the room ID to check the power level in
eventType string the event type to look for in the `events` property of the power levels
isState boolean true to indicate the event is intended to be a state event

View Source MatrixClient.ts, line 2851

resolves to true if the user has the required power level, resolves to false otherwise
Promise.<boolean>

# async userHasPowerLevelForAction(userId, roomId, action) → {Promise.<boolean>}

Checks if a given user has a required power level to perform the given action
Parameters:
Name Type Description
userId string the user ID to check the power level of
roomId string the room ID to check the power level in
action PowerLevelAction the action to check power level for

View Source MatrixClient.ts, line 2862

resolves to true if the user has the required power level, resolves to false otherwise
Promise.<boolean>