Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AppService

Hierarchy

  • EventEmitter
    • AppService

Index

Constructors

constructor

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

    throws

    If a homeserver token is not supplied.

    Parameters

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

      Configuration for this service.

      • homeserverToken: string

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

      • Optional httpMaxSizeBytes?: undefined | 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): this
  • on(event: "ephemeral", cb: (event: Record<string, unknown>) => void): this
  • on(event: "http-log", cb: (line: string) => void): this
  • on(event: string, cb: (event: Record<string, unknown>) => void): this
  • 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 this

  • 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 this

  • 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 this

  • 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 this

Properties

Readonly app

app: Application
deprecated

Use AppService.expressApp

Static defaultMaxListeners

defaultMaxListeners: number

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): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

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(): Array<string | symbol>
  • Returns Array<string | symbol>

getMaxListeners

  • getMaxListeners(): number
  • Returns number

listen

  • listen(port: number, hostname: string, backlog: number, callback?: undefined | (() => 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: undefined | (() => void)

      The callback for the "listening" event. Optional.

    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): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

onAliasQuery

  • onAliasQuery(alias: string, callback: () => void): PromiseLike<void> | null
  • 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 PromiseLike<void> | null

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

onUserQuery

  • onUserQuery(userId: string, callback: () => void): PromiseLike<void> | null
  • 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 PromiseLike<void> | null

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

once

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

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

          • Rest ...args: any[]

          Returns void

    Returns this

prependListener

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

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

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

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

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

          • Rest ...args: any[]

          Returns void

    Returns this

rawListeners

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

    • event: string | symbol

    Returns Function[]

removeAllListeners

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

    • Optional event: string | symbol

    Returns this

removeListener

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

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

          • Rest ...args: any[]

          Returns void

    Returns this

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

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

Static listenerCount

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

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Generated using TypeDoc