Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Intent

Index

Constructors

constructor

  • new Intent(botSdkIntent: Intent, botClient: MatrixClient, opts?: IntentOpts): Intent
  • Create an entity which can fulfil the intent of a given user.

    Parameters

    • botSdkIntent: Intent

      The bot sdk intent which this intent wraps 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: IntentOpts = {}

      Options for this Intent instance.

    Returns Intent

Properties

Readonly botSdkIntent

botSdkIntent: Intent

Accessors

client

  • get client(): any
  • Legacy property to access the matrix-js-sdk.

    deprecated

    Support for the matrix-js-sdk client will be going away in a future release. Where possible, the intent object functions should be used. The botSdkIntent also provides access to the new client.

    see

    getClient

    Returns any

matrixClient

  • get matrixClient(): MatrixClient

userId

  • get userId(): string

Methods

ban

  • ban(roomId: string, target: string, reason?: string): Promise<any>
  • 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

    • roomId: string

      The room to ban the user from.

    • target: string

      The target of the ban operation.

    • Optional reason: string

      Optional. The reason for the ban.

    Returns Promise<any>

    Resolved when banned, else rejected with an error.

createAlias

  • createAlias(alias: string, roomId: string): Promise<any>
  • Create a new alias mapping.

    Parameters

    • alias: string

      The room alias to create

    • roomId: string

      The room ID the alias should point at.

    Returns Promise<any>

createRoom

ensureProfile

  • ensureProfile(displayname?: string, avatarUrl?: string): Promise<void>
  • Ensure that the user has the given profile information set. If it does not, set it.

    Parameters

    • Optional displayname: string

      The displayname to set. Leave undefined to ignore.

    • Optional avatarUrl: string

      The avatar to set. Leave undefined to ignore.

    Returns Promise<void>

ensureRegistered

  • ensureRegistered(forceRegister?: boolean): Promise<any>

getClient

  • getClient(): any
  • Return a matrix-js-sdk client, which is created on demand.

    deprecated

    Support for the matrix-js-sdk client will be going away in a future release. Where possible, the intent object functions should be used. The botSdkIntent also provides access to the new client.

    Returns any

    The client

getEvent

  • getEvent(roomId: string, eventId: string, useCache?: boolean): Promise<any>
  • Get an event in a room. This will automatically make the client join the room so they can get the event if they are not already joined.

    Parameters

    • roomId: string

      The room to fetch the event from.

    • eventId: string

      The eventId of the event to fetch.

    • useCache: boolean = true

      Should the request attempt to lookup from the cache.

    Returns Promise<any>

    Resolves with the content of the event, or rejects if not found.

getProfileInfo

  • getProfileInfo(userId: string, info?: UserProfileKeys, useCache?: boolean): Promise<MatrixProfileInfo>
  • Get a user's profile information

    Parameters

    • userId: string

      The ID of the user whose profile to return

    • info: UserProfileKeys = null

      The profile field name to retrieve (e.g. 'displayname' or 'avatar_url'), or null to fetch the entire profile information.

    • useCache: boolean = true

      Should the request attempt to lookup state from the cache.

    Returns Promise<MatrixProfileInfo>

    A Promise that resolves with the requested user's profile information

getStateEvent

  • getStateEvent(roomId: string, eventType: string, stateKey?: string, returnNull?: boolean): Promise<any>
  • Get a state event in a room. This will automatically make the client join the room so they can get the state if they are not already joined.

    Parameters

    • roomId: string

      The room to get the state from.

    • eventType: string

      The event type to fetch.

    • stateKey: string = ""

      The state key of the event to fetch.

    • returnNull: boolean = false

      Return null on not found, rather than throwing

    Returns Promise<any>

invite

  • invite(roomId: string, target: string): Promise<any>
  • 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

    • roomId: string

      The room to invite the user to.

    • target: string

      The user ID to invite.

    Returns Promise<any>

    Resolved when invited, else rejected with an error.

isRoomEncrypted

  • isRoomEncrypted(roomId: string): Promise<string | false>
  • Check if a room is encrypted. If it is, return the algorithm.

    Parameters

    • roomId: string

      The room ID to be checked

    Returns Promise<string | false>

    The encryption algorithm or false

join

  • join(roomIdOrAlias: string, viaServers?: string[]): Promise<string>
  • 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

    • roomIdOrAlias: string

      The room ID or room alias to join.

    • Optional viaServers: string[]

      The server names to try and join through in addition to those that are automatically chosen.

    Returns Promise<string>

kick

  • kick(roomId: string, target: string, reason?: string): Promise<any>
  • 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

    • roomId: string

      The room to kick the user from.

    • target: string

      The target of the kick operation.

    • Optional reason: string

      Optional. The reason for the kick.

    Returns Promise<any>

    Resolved when kickked, else rejected with an error.

leave

  • leave(roomId: string, reason?: string): Promise<any>
  • Leave a room

    This will no-op if the user isn't in the room.

    Parameters

    • roomId: string

      The room to leave.

    • Optional reason: string

      An optional string to explain why the user left the room.

    Returns Promise<any>

onEvent

  • onEvent(event: { content: { algorithm?: string; avatar_url?: string; displayname?: string; membership: UserMembership }; room_id: string; state_key: unknown; type: string }): void
  • 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. This function does nothing if a backing store was provided to the Intent.

    Parameters

    • event: { content: { algorithm?: string; avatar_url?: string; displayname?: string; membership: UserMembership }; room_id: string; state_key: unknown; type: string }

      The incoming event JSON

      • content: { algorithm?: string; avatar_url?: string; displayname?: string; membership: UserMembership }
        • Optional algorithm?: string
        • Optional avatar_url?: string
        • Optional displayname?: string
        • membership: UserMembership
      • room_id: string
      • state_key: unknown
      • type: string

    Returns void

resolveRoom

  • resolveRoom(roomAliasOrId: string): Promise<string>
  • Resolve a roomId or alias into a roomId. If a roomId is given, it is immediately returned.

    throws

    If the provided string was incorrectly formatted or alias does not exist.

    Parameters

    • roomAliasOrId: string

      A roomId or alias to resolve.

    Returns Promise<string>

roomState

  • roomState(roomId: string, useCache?: boolean): Promise<unknown>
  • 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

    • roomId: string

      The room to get the state from.

    • useCache: boolean = false

      Should the request attempt to lookup state from the cache.

    Returns Promise<unknown>

sendEvent

  • sendEvent(roomId: string, type: string, content: Record<string, unknown>): Promise<{ event_id: string }>
  • 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

    • roomId: string

      The room to send to.

    • type: string

      The event type

    • content: Record<string, unknown>

      The event content

    Returns Promise<{ event_id: string }>

sendMessage

  • sendMessage(roomId: string, content: Record<string, unknown>): Promise<{ event_id: string }>
  • 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

    • roomId: string

      The room to send to.

    • content: Record<string, unknown>

      The event content

    Returns Promise<{ event_id: string }>

sendReadReceipt

  • sendReadReceipt(roomId: string, eventId: string): Promise<any>
  • 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.

    Parameters

    • roomId: string

      The room to send to.

    • eventId: string

      The event ID to set the receipt mark to.

    Returns Promise<any>

sendStateEvent

  • sendStateEvent(roomId: string, type: string, skey: string, content: Record<string, unknown>): Promise<{ event_id: string }>
  • 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

    • roomId: string

      The room to send to.

    • type: string

      The event type

    • skey: string

      The state key

    • content: Record<string, unknown>

      The event content

    Returns Promise<{ event_id: string }>

sendText

  • sendText(roomId: string, text: string): Promise<{ event_id: string }>
  • 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

    • roomId: string

      The room to send to.

    • text: string

      The text string to send.

    Returns Promise<{ event_id: string }>

    The Matrix event ID.

sendTyping

  • sendTyping(roomId: string, isTyping: boolean): Promise<any>
  • 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

    • roomId: string

      The room to send to.

    • isTyping: boolean

      True if typing

    Returns Promise<any>

setAvatarUrl

  • setAvatarUrl(url: string): Promise<any>

setDisplayName

  • setDisplayName(name: string): Promise<any>

setPowerLevel

  • setPowerLevel(roomId: string, target: string, level: undefined | number): Promise<void>
  • Set the power level of the given target.

    Parameters

    • roomId: string

      The room to set the power level in.

    • target: string

      The target user ID

    • level: undefined | number

      The desired level. Undefined will remove the users custom power level.

    Returns Promise<void>

setPresence

  • setPresence(presence: PresenceState, statusMsg?: string): Promise<any>
  • Set the presence of this user.

    Parameters

    • presence: PresenceState

      One of "online", "offline" or "unavailable".

    • Optional statusMsg: string

    Returns Promise<any>

    Resolves if the presence was set or no-oped, rejects otherwise.

setRoomAvatar

  • setRoomAvatar(roomId: string, avatar: string, info?: string): Promise<{ event_id: string }>
  • 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

    • roomId: string

      The room to send to.

    • avatar: string

      The url of the avatar.

    • Optional info: string

      Extra information about the image. See m.room.avatar for details.

    Returns Promise<{ event_id: string }>

setRoomDirectoryVisibility

  • setRoomDirectoryVisibility(roomId: string, visibility: "public" | "private"): Promise<any>
  • Set the visibility of a room in the homeserver's room directory.

    Parameters

    • roomId: string

      The room

    • visibility: "public" | "private"

      Should the room be visible

    Returns Promise<any>

setRoomDirectoryVisibilityAppService

  • setRoomDirectoryVisibilityAppService(roomId: string, networkId: string, visibility: "public" | "private"): Promise<any>
  • Set the visibility of a room in the appservice's room directory. This only works if you have defined the protocol in the registration file.

    Parameters

    • roomId: string

      The room

    • networkId: string

      The network (not protocol) that owns this room. E.g. "freenode" (for an IRC bridge)

    • visibility: "public" | "private"

      Should the room be visible

    Returns Promise<any>

setRoomName

  • setRoomName(roomId: string, name: string): Promise<{ event_id: string }>
  • 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

    • roomId: string

      The room to send to.

    • name: string

      The room name.

    Returns Promise<{ event_id: string }>

    The Matrix event ID.

setRoomTopic

  • setRoomTopic(roomId: string, topic: string): Promise<{ event_id: string }>
  • 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

    • roomId: string

      The room to send to.

    • topic: string

      The room topic.

    Returns Promise<{ event_id: string }>

setRoomUserProfile

  • setRoomUserProfile(roomId: string, profile: MatrixProfileInfo): Promise<void>

unban

  • unban(roomId: string, target: string): Promise<any>
  • 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

    • roomId: string

      The room to unban the user from.

    • target: string

      The target of the unban operation.

    Returns Promise<any>

    Resolved when unbanned, else rejected with an error.

unstableSignalBridgeError

  • unstableSignalBridgeError(roomID: string, eventID: string, networkName: undefined | string, reason: BridgeErrorReason, affectedUsers: string[]): Promise<{ event_id: string }>
  • Signals that an error occured while handling an event by the bridge.

    Warning: This function is unstable and is likely to change pending the outcome of https://github.com/matrix-org/matrix-doc/pull/2162.

    Parameters

    • roomID: string

      ID of the room in which the error occured.

    • eventID: string

      ID of the event for which the error occured.

    • networkName: undefined | string

      Name of the bridged network.

    • reason: BridgeErrorReason

      The reason why the bridge error occured.

    • affectedUsers: string[]

      Array of regex matching all affected users.

    Returns Promise<{ event_id: string }>

uploadContent

  • uploadContent(content: string | Buffer | ReadStream, opts?: FileUploadOpts): Promise<string>
  • Upload a file to the homeserver.

    Parameters

    • content: string | Buffer | ReadStream

      The file contents

    • opts: FileUploadOpts = {}

      Additional options for the upload.

    Returns Promise<string>

    A MXC URL pointing to the uploaded data.

Generated using TypeDoc