Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • EventEmitter
    • AppService

Index

Constructors

constructor

  • new AppService(config: { homeserverToken: string; httpMaxSizeBytes?: number }): AppService
  • Construct a new application service.

    throws

    If a homeserver token is not supplied.

    Parameters

    • config: { homeserverToken: string; httpMaxSizeBytes?: number }

      Configuration for this service.

      • homeserverToken: string

        The incoming HS token to expect. Must be set prior to calling listen(port).

      • Optional httpMaxSizeBytes?: number

        The max number of bytes allowed on an incoming HTTP request. Default: 5000000.

    Returns AppService

Events

on

  • on(event: "event", cb: (event: Record<string, unknown>) => void): AppService
  • on(event: "ephemeral", cb: (event: Record<string, unknown>) => void): AppService
  • on(event: "http-log", cb: (line: string) => void): AppService
  • on(event: string, cb: (event: Record<string, unknown>) => void): AppService
  • Emitted when an event is pushed to the appservice. The format of the event object is documented at https://matrix.org/docs/spec/application_service/r0.1.2#put-matrix-app-v1-transactions-txnid

    example

    appService.on("event", function(ev) { console.log("ID: %s", ev.event_id); });

    Parameters

    • event: "event"
    • cb: (event: Record<string, unknown>) => void
        • (event: Record<string, unknown>): void
        • Parameters

          • event: Record<string, unknown>

          Returns void

    Returns AppService

  • Emitted when an ephemeral event is pushed to the appservice. The format of the event object is documented at https://github.com/matrix-org/matrix-doc/pull/2409

    example

    appService.on("ephemeral", function(ev) { console.log("ID: %s", ev.type); });

    Parameters

    • event: "ephemeral"
    • cb: (event: Record<string, unknown>) => void
        • (event: Record<string, unknown>): void
        • Parameters

          • event: Record<string, unknown>

          Returns void

    Returns AppService

  • Emitted when the HTTP listener logs some information. access_tokens are stripped from requests

    example

    appService.on("http-log", function(line) { console.log(line); });

    Parameters

    • event: "http-log"
    • cb: (line: string) => void
        • (line: string): void
        • Parameters

          • line: string

          Returns void

    Returns AppService

  • Emitted when an event of a particular type is pushed to the appservice. This will be emitted in addition to "event", so ensure your bridge deduplicates events.

    example

    appService.on("type:m.room.message", function(event) { console.log("ID: %s", ev.content.body); });

    Parameters

    • event: string

      Should start with "type:"

    • cb: (event: Record<string, unknown>) => void
        • (event: Record<string, unknown>): void
        • Parameters

          • event: Record<string, unknown>

          Returns void

    Returns AppService

Properties

Readonly app

app: Application
deprecated

Use AppService.expressApp

Static Readonly captureRejectionSymbol

captureRejectionSymbol: typeof captureRejectionSymbol

Static captureRejections

captureRejections: boolean

Sets or gets the default captureRejection value for all emitters.

Static defaultMaxListeners

defaultMaxListeners: number

Static Readonly errorMonitor

errorMonitor: typeof errorMonitor

This symbol shall be used to install a listener for only monitoring 'error' events. Listeners installed using this symbol are called before the regular 'error' listeners are called.

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted, therefore the process will still crash if no regular 'error' listener is installed.

Accessors

expressApp

  • get expressApp(): Application
  • The Express App instance for the appservice, which can be extended with paths.

    Returns Application

Methods

addListener

  • addListener(event: string | symbol, listener: (...args: any[]) => void): AppService
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns AppService

close

  • close(): Promise<void>
  • Closes the HTTP server.

    throws

    If the server has not been started.

    Returns Promise<void>

    When the operation has completed

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

eventNames

  • eventNames(): (string | symbol)[]
  • Returns (string | symbol)[]

getMaxListeners

  • getMaxListeners(): number
  • Returns number

listen

  • listen(port: number, hostname: string, backlog: number, callback?: () => void): undefined | Promise<unknown>
  • Begin listening on the specified port.

    Parameters

    • port: number

      The port to listen on.

    • hostname: string

      Optional hostname to listen on

    • backlog: number

      Maximum length of the queue of pending connections

    • Optional callback: () => void

      The callback for the "listening" event. Optional.

        • (): void
        • Returns void

    Returns undefined | Promise<unknown>

    When the server is listening, if a callback is not provided.

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

off

  • off(event: string | symbol, listener: (...args: any[]) => void): AppService
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns AppService

onAliasQuery

  • onAliasQuery(alias: string, callback: () => void): null | PromiseLike<void>
  • Override this method to handle alias queries.

    Parameters

    • alias: string

      The queried room alias

    • callback: () => void

      The callback to invoke when complete.

        • (): void
        • Returns void

    Returns null | PromiseLike<void>

    A promise to resolve when complete (if callback isn't supplied)

onUserQuery

  • onUserQuery(userId: string, callback: () => void): null | PromiseLike<void>
  • Override this method to handle user queries.

    Parameters

    • userId: string

      The queried user ID.

    • callback: () => void

      The callback to invoke when complete.

        • (): void
        • Returns void

    Returns null | PromiseLike<void>

    A promise to resolve when complete (if callback isn't supplied)

once

  • once(event: string | symbol, listener: (...args: any[]) => void): AppService
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns AppService

prependListener

  • prependListener(event: string | symbol, listener: (...args: any[]) => void): AppService
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns AppService

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): AppService
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns AppService

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

removeAllListeners

  • removeAllListeners(event?: string | symbol): AppService
  • Parameters

    • Optional event: string | symbol

    Returns AppService

removeListener

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): AppService
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns AppService

setHomeserverToken

  • setHomeserverToken(hsToken: string): void
  • Set the token that should be used to verify incoming events.

    Parameters

    • hsToken: string

      The home server token

    Returns void

setMaxListeners

  • Parameters

    • n: number

    Returns AppService

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Static on

  • on(emitter: EventEmitter, event: string): AsyncIterableIterator<any>
  • Parameters

    • emitter: EventEmitter
    • event: string

    Returns AsyncIterableIterator<any>

Static once

  • once(emitter: NodeEventTarget, event: string | symbol): Promise<any[]>
  • once(emitter: DOMEventTarget, event: string): Promise<any[]>
  • Parameters

    • emitter: NodeEventTarget
    • event: string | symbol

    Returns Promise<any[]>

  • Parameters

    • emitter: DOMEventTarget
    • event: string

    Returns Promise<any[]>

Generated using TypeDoc