Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Bridge

Hierarchy

  • Bridge

Index

Constructors

constructor

  • new Bridge(opts: BridgeOpts): Bridge

Properties

Readonly opts

opts: VettedBridgeOpts

Accessors

appService

  • get appService(): undefined | AppService

botUserId

  • get botUserId(): string

Methods

addAppServicePath

  • addAppServicePath(opts: { checkToken?: undefined | false | true; handler: (req: ExRequest, respose: ExResponse, next: NextFunction) => void; method: "GET" | "PUT" | "POST" | "DELETE"; path: string }): void
  • Install a custom handler for an incoming HTTP API request. This allows callers to add extra functionality, implement new APIs, etc...

    Parameters

    • opts: { checkToken?: undefined | false | true; handler: (req: ExRequest, respose: ExResponse, next: NextFunction) => void; method: "GET" | "PUT" | "POST" | "DELETE"; path: string }

      Named options

      • Optional checkToken?: undefined | false | true

        Should the token be automatically checked. Defaults to true.

      • handler: (req: ExRequest, respose: ExResponse, next: NextFunction) => void

        Function to handle requests to this endpoint.

          • (req: ExRequest, respose: ExResponse, next: NextFunction): void
          • Parameters

            • req: ExRequest
            • respose: ExResponse
            • next: NextFunction

            Returns void

      • method: "GET" | "PUT" | "POST" | "DELETE"

        The HTTP method name.

      • path: string

        Path to the endpoint.

    Returns void

canProvisionRoom

  • Determines whether a room should be provisoned based on user provided rules and the room state. Will default to true if no rules have been provided.

    Parameters

    • roomId: string

      The room to check.

    • Default value cache: boolean = true

      Should the validator check it's cache.

    Returns Promise<RoomLinkValidatorStatus>

    resolves if can and rejects if it cannot. A status code is returned on both.

checkHomeserverSupport

  • checkHomeserverSupport(): Promise<void>

close

  • close(): Promise<void>
  • Close the appservice HTTP listener, and clear all timeouts.

    Returns Promise<void>

    Resolves when the appservice HTTP listener has stopped

getBot

getClientFactory

getEventStore

getIntent

  • getIntent(userId?: undefined | string, request?: Request<unknown>): Intent
  • Retrieve an Intent instance for the specified user ID. If no ID is given, an instance for the bot itself is returned.

    Parameters

    • Optional userId: undefined | string

      Optional. The user ID to get an Intent for.

    • Optional request: Request<unknown>

      Optional. The request instance to tie the MatrixClient instance to. Useful for logging contextual request IDs.

    Returns Intent

    The intent instance

getIntentFromLocalpart

  • getIntentFromLocalpart(localpart: string, request?: Request<unknown>): Intent
  • Retrieve an Intent instance for the specified user ID localpart. This must be the complete user localpart.

    Parameters

    • localpart: string

      The user ID localpart to get an Intent for.

    • Optional request: Request<unknown>

      Optional. The request instance to tie the MatrixClient instance to. Useful for logging contextual request IDs.

    Returns Intent

    The intent instance

getPrometheusMetrics

  • getPrometheusMetrics(registerEndpoint?: boolean, registry?: Registry): PrometheusMetrics
  • Returns a PrometheusMetrics instance stored on the bridge, creating it first if required. The instance will be registered with the HTTP server so it can serve the "/metrics" page in the usual way. The instance will automatically register the Matrix SDK metrics by calling {PrometheusMetrics~registerMatrixSdkMetrics}.

    Parameters

    • Default value registerEndpoint: boolean = true

      Register the /metrics endpoint on the appservice HTTP server. Defaults to true.

    • Optional registry: Registry

      Optionally provide an alternative registry for metrics.

    Returns PrometheusMetrics

getRequestFactory

getRoomLinkValidator

getRoomStore

getUserStore

loadDatabases

  • loadDatabases(): Promise<void>
  • Load the user and room databases. Access them via getUserStore() and getRoomStore().

    Returns Promise<void>

provisionUser

  • provisionUser(matrixUser: MatrixUser, provisionedUser?: undefined | { name?: undefined | string; remote?: RemoteUser; url?: undefined | string }): Promise<void>
  • Provision a user on the homeserver.

    Parameters

    • matrixUser: MatrixUser

      The virtual user to be provisioned.

    • Optional provisionedUser: undefined | { name?: undefined | string; remote?: RemoteUser; url?: undefined | string }

      Provisioning information.

    Returns Promise<void>

    Resolved when provisioned.

registerBridgeGauges

  • A convenient shortcut to calling registerBridgeGauges() on the PrometheusMetrics instance directly. This version will supply the value of the matrixGhosts field if the counter function did not return it, for convenience.

    example

    bridge.registerBridgeGauges(() => { return { matrixRoomConfigs: Object.keys(this.matrixRooms).length, remoteRoomConfigs: Object.keys(this.remoteRooms).length,

        remoteGhosts: Object.keys(this.remoteGhosts).length,
    
        ...
    }

    })

    Parameters

    Returns void

requestCheckToken

  • requestCheckToken(req: ExRequest): boolean
  • Check a express Request to see if it's correctly authenticated (includes the hsToken). The query parameter access_token and the Authorization header are checked.

    Parameters

    • req: ExRequest

    Returns boolean

    True if authenticated, False if not.

run

  • run<T>(port: number, config: T, appServiceInstance?: AppService, hostname?: undefined | string, backlog?: number): Promise<void>
  • Run the bridge (start listening)

    Type parameters

    • T

    Parameters

    • port: number

      The port to listen on.

    • config: T

      Configuration options

    • Optional appServiceInstance: AppService

      The AppService instance to attach to. If not provided, one will be created.

    • Optional hostname: undefined | string

      Optional hostname to bind to. (e.g. 0.0.0.0)

    • Default value backlog: number = 10

    Returns Promise<void>

    A promise resolving when the bridge is ready

Generated using TypeDoc