Class

Intent

Intent(options, impersonateUserId, appservice)

An Intent is an intelligent client that tracks things like the user's membership in rooms to ensure the action being performed is possible. This is very similar to how Intents work in the matrix-js-sdk in that the Intent will ensure that the user is joined to the room before posting a message, for example.
Constructor

# new Intent(options, impersonateUserId, appservice)

Creates a new intent. Intended to be created by application services.
Parameters:
Name Type Description
options IAppserviceOptions The options for the application service.
impersonateUserId string The user ID to impersonate.
appservice Appservice The application service itself.

View Source appservice/Intent.ts, line 21

Classes

Intent
Intent

Members

# metrics

The metrics instance for this intent. Note that this will not raise metrics for the underlying client - those will be available through this instance's parent (the appservice).

View Source appservice/Intent.ts, line 30

Metrics

# metrics

The metrics instance for this intent. Note that this will not raise metrics for the underlying client - those will be available through this instance's parent (the appservice).

View Source appservice/Intent.ts, line 422

# underlyingClient

Gets the underlying MatrixClient that powers this Intent.

View Source appservice/Intent.ts, line 84

# unstableApis

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

View Source appservice/Intent.ts, line 92

# userId

Gets the user ID this intent is for.

View Source appservice/Intent.ts, line 78

Methods

# async enableEncryption(providedDeviceId) → {Promise.<void>}

Sets up crypto on the client if it hasn't already been set up.
Parameters:
Name Type Description
providedDeviceId Optional device ID. If given, this will used instead of trying to masquerade as the first non-key enabled device.

View Source appservice/Intent.ts, line 463

Resolves when complete.
Promise.<void>

# async ensureJoined(roomId) → {Promise.<any>}

Ensures the user is joined to the given room
Parameters:
Name Type Description
roomId string The room ID to join
Deprecated:
  • Use `joinRoom()` instead

View Source appservice/Intent.ts, line 554

Resolves when complete
Promise.<any>

# async ensureRegistered(deviceId) → {Promise.<any>}

Ensures the user is registered
Parameters:
Name Type Description
deviceId An optional device ID to register with.

View Source appservice/Intent.ts, line 573

Resolves when complete
Promise.<any>

# async ensureRegisteredAndJoined(roomId) → {Promise.<any>}

Ensures the user is registered and joined to the given room.
Parameters:
Name Type Description
roomId string The room ID to join

View Source appservice/Intent.ts, line 544

Resolves when complete
Promise.<any>

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

Ensures this intent has a registered device for receiving appservice to-device messages. Uses the keyed device path when automatic encryption is enabled or `enableEncryption()` has already been called; otherwise it creates or reuses a stable unkeyed device. The path is chosen when this method is called. The unkeyed client is captured at that point, so later encryption setup does not change an in-flight unkeyed readiness operation. On the unkeyed path, the device ID is `BOTSDK_TODEVICE_V1_` followed by the first 32 lowercase hex digits of SHA-256 over the UTF-8 string `registration.sender_localpart + ":" + homeserverName`. Device IDs are scoped to each Matrix user. The ID survives restarts and appservice token rotation; changing either identity input selects a new device. This method does not delete the old device. On the keyed path, the existing crypto device identity is reused. Device registration alone does not guarantee delivery: the homeserver and appservice registration must support to-device transactions.

View Source appservice/Intent.ts, line 486

Resolves to the ready device ID.
Promise.<string>

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

Gets the joined rooms for the intent.

View Source appservice/Intent.ts, line 495

Resolves to an array of room IDs where the intent is joined.
Promise.<Array.<string>>

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

Joins the given room
Parameters:
Name Type Description
roomIdOrAlias string the room ID or alias to join

View Source appservice/Intent.ts, line 514

resolves to the joined room ID
Promise.<string>

# async 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 appservice/Intent.ts, line 505

Resolves when the room has been left.
Promise.<any>

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

Refreshes which rooms the user is joined to, potentially saving time on calls like ensureJoined()
Deprecated:
  • There is no longer a joined rooms cache, use `getJoinedRooms()` instead

View Source appservice/Intent.ts, line 564

Resolves to the joined room IDs for the user.
Promise.<Array.<string>>

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

Sends an event to a room.
Parameters:
Name Type Description
roomId string The room ID to send the event to.
content any The content of the event.

View Source appservice/Intent.ts, line 535

Resolves to the event ID of the sent event.
Promise.<string>

# async sendText(roomId, body, msgtype) → {Promise.<string>}

Sends a text message to a room.
Parameters:
Name Type Description
roomId string The room ID to send text to.
body string The message body to send.
msgtype "m.text" | "m.emote" | "m.notice" The message type to send.

View Source appservice/Intent.ts, line 525

Resolves to the event ID of the sent message.
Promise.<string>

# underlyingClient() → {MatrixClient}

Gets the underlying MatrixClient that powers this Intent.

View Source appservice/Intent.ts, line 445

MatrixClient

# unstableApis() → {UnstableAppserviceApis}

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

View Source appservice/Intent.ts, line 453

The unstable API access class.

# userId() → {string}

Gets the user ID this intent is for.

View Source appservice/Intent.ts, line 438

string