Class: Intent

Intent

new Intent(client, botClient, opts)

Create an entity which can fulfil the intent of a given user.
Parameters:
Name Type Description
client MatrixClient The matrix client instance whose intent is being fulfilled e.g. the entity joining the room when you call intent.join(roomId).
botClient MatrixClient The client instance for the AS bot itself. This will be used to perform more priveleged actions such as creating new rooms, sending invites, etc.
opts Object Options for this Intent instance.
Properties
Name Type Description
registered boolean True to inform this instance that the client is already registered. No registration requests will be made from this Intent. Default: false.
dontCheckPowerLevel boolean True to not check for the right power level before sending events. Default: false.
Source:

Methods

ban(roomId, target, reason) → {Promise}

Ban a user from a room.

This will automatically make the client join the room so they can send the ban if they are not already joined.
Parameters:
Name Type Description
roomId string The room to ban the user from.
target string The target of the ban operation.
reason string Optional. The reason for the ban.
Source:
Returns:
Resolved when banned, else rejected with an error.
Type
Promise

createAlias(alias, roomId) → {Promise}

Create a new alias mapping.
Parameters:
Name Type Description
alias string The room alias to create
roomId string The room ID the alias should point at.
Source:
Returns:
Type
Promise

createRoom(opts) → {Promise}

Create a room with a set of options.
Parameters:
Name Type Description
opts Object Options.
Properties
Name Type Description
createAsClient boolean True to create this room as a client and not the bot: the bot will not join. False to create this room as the bot and auto-join the client. Default: false.
options Object Options to pass to the client SDK /createRoom API.
Source:
Returns:
Type
Promise

getClient() → {MatrixClient}

Return the client this Intent is acting on behalf of.
Source:
Returns:
The client
Type
MatrixClient

getProfileInfo(userId, info) → {Promise}

Get a user's profile information

Parameters:
Name Type Description
userId string The ID of the user whose profile to return
info string The profile field name to retrieve (e.g. 'displayname' or 'avatar_url'), or null to fetch the entire profile information.
Source:
Returns:
A Promise that resolves with the requested user's profile information
Type
Promise

invite(roomId, target) → {Promise}

Invite a user to a room.

This will automatically make the client join the room so they can send the invite if they are not already joined.
Parameters:
Name Type Description
roomId string The room to invite the user to.
target string The user ID to invite.
Source:
Returns:
Resolved when invited, else rejected with an error.
Type
Promise

join(roomId) → {Promise}

Join a room

This will automatically send an invite from the bot if it is an invite-only room, which may make the bot attempt to join the room if it isn't already.
Parameters:
Name Type Description
roomId string The room to join.
Source:
Returns:
Type
Promise

kick(roomId, target, reason) → {Promise}

Kick a user from a room.

This will automatically make the client join the room so they can send the kick if they are not already joined.
Parameters:
Name Type Description
roomId string The room to kick the user from.
target string The target of the kick operation.
reason string Optional. The reason for the kick.
Source:
Returns:
Resolved when kickked, else rejected with an error.
Type
Promise

leave(roomId) → {Promise}

Leave a room

This will no-op if the user isn't in the room.
Parameters:
Name Type Description
roomId string The room to leave.
Source:
Returns:
Type
Promise

onEvent(event)

Inform this Intent class of an incoming event. Various optimisations will be done if this is provided. For example, a /join request won't be sent out if it knows you've already been joined to the room.
Parameters:
Name Type Description
event Object The incoming event JSON
Source:

roomState(roomId) → {Promise}

Get the current room state for a room.

This will automatically make the client join the room so they can get the state if they are not already joined.
Parameters:
Name Type Description
roomId string The room to get the state from.
Source:
Returns:
Type
Promise

sendEvent(roomId, type, content) → {Promise}

Send a message event to a room.

This will automatically make the client join the room so they can send the message if they are not already joined. It will also make sure that the client has sufficient power level to do this.
Parameters:
Name Type Description
roomId string The room to send to.
type string The event type
content Object The event content
Source:
Returns:
Type
Promise

sendMessage(roomId, content) → {Promise}

Send an m.room.message event to a room.

This will automatically make the client join the room so they can send the message if they are not already joined. It will also make sure that the client has sufficient power level to do this.
Parameters:
Name Type Description
roomId string The room to send to.
content Object The event content
Source:
Returns:
Type
Promise

sendReadReceipt() → {Promise}

Send a read receipt to a room.

This will automatically make the client join the room so they can send the receipt event if they are not already joined.
Source:
Returns:
Type
Promise

sendStateEvent(roomId, type, skey, content) → {Promise}

Send a state event to a room.

This will automatically make the client join the room so they can send the state if they are not already joined. It will also make sure that the client has sufficient power level to do this.
Parameters:
Name Type Description
roomId string The room to send to.
type string The event type
skey string The state key
content Object The event content
Source:
Returns:
Type
Promise

sendText(roomId, text) → {Promise}

Send a plaintext message to a room.

This will automatically make the client join the room so they can send the message if they are not already joined. It will also make sure that the client has sufficient power level to do this.
Parameters:
Name Type Description
roomId string The room to send to.
text string The text string to send.
Source:
Returns:
Type
Promise

sendTyping(roomId, isTyping) → {Promise}

Send a typing event to a room.

This will automatically make the client join the room so they can send the typing event if they are not already joined.
Parameters:
Name Type Description
roomId string The room to send to.
isTyping boolean True if typing
Source:
Returns:
Type
Promise

setAvatarUrl(url) → {Promise}

Set the user's avatar URL

Parameters:
Name Type Description
url string The new avatar URL
Source:
Returns:
Type
Promise

setDisplayName(name) → {Promise}

Set the user's display name

Parameters:
Name Type Description
name string The new display name
Source:
Returns:
Type
Promise

setPowerLevel(roomId, target, level) → {Promise}

Set the power level of the given target.
Parameters:
Name Type Description
roomId string The room to set the power level in.
target string The target user ID
level number The desired level
Source:
Returns:
Type
Promise

setRoomAvatar(roomId, avatar, info) → {Promise}

Set the avatar of a room.

This will automatically make the client join the room so they can set the topic if they are not already joined. It will also make sure that the client has sufficient power level to do this.
Parameters:
Name Type Description
roomId string The room to send to.
avatar string The url of the avatar.
info string Extra information about the image. See m.room.avatar for details.
Source:
Returns:
Type
Promise

setRoomName(roomId, name) → {Promise}

Set the name of a room.

This will automatically make the client join the room so they can set the name if they are not already joined. It will also make sure that the client has sufficient power level to do this.
Parameters:
Name Type Description
roomId string The room to send to.
name string The room name.
Source:
Returns:
Type
Promise

setRoomTopic(roomId, topic) → {Promise}

Set the topic of a room.

This will automatically make the client join the room so they can set the topic if they are not already joined. It will also make sure that the client has sufficient power level to do this.
Parameters:
Name Type Description
roomId string The room to send to.
topic string The room topic.
Source:
Returns:
Type
Promise

unban(roomId, target) → {Promise}

Unban a user from a room.

This will automatically make the client join the room so they can send the unban if they are not already joined.
Parameters:
Name Type Description
roomId string The room to unban the user from.
target string The target of the unban operation.
Source:
Returns:
Resolved when unbanned, else rejected with an error.
Type
Promise