Options
All
  • Public
  • Public/Protected
  • All
Menu

Collects messages on a chat. Will automatically stop if the chat ('chatDelete') is deleted.

Hierarchy

Index

Constructors

constructor

  • new MessageCollector(sessionId: string, instanceId: string, chat: ChatId, filter: (...args: any[]) => boolean | Promise<boolean>, options?: CollectorOptions, openWaEventEmitter: EventEmitter2): MessageCollector
  • emits

    MessageCollector#Message

    Parameters

    • sessionId: string

      The id of the session

    • instanceId: string

      The id of the current instance of the session (see: client.getInstanceId)

    • chat: ChatId
    • filter: (...args: any[]) => boolean | Promise<boolean>

      The filter to be applied to this collector

        • (...args: any[]): boolean | Promise<boolean>
        • Parameters

          • Rest ...args: any[]

          Returns boolean | Promise<boolean>

    • options: CollectorOptions = {}

      The options to be applied to this collector

    • openWaEventEmitter: EventEmitter2

      The EventEmitter2 that fires all open-wa events. In local instances of the library, this is the global ev object.

    Returns MessageCollector

Properties

Protected _idletimeout

_idletimeout: Timeout

Protected _timeout

_timeout: Timeout

chat

chat: ChatId

collected

collected: Collection<string, any>

ended

ended: boolean

ev

ev: EventEmitter2

filter

filter: (...args: any[]) => boolean | Promise<boolean>

Type declaration

    • (...args: any[]): boolean | Promise<boolean>
    • Parameters

      • Rest ...args: any[]

      Returns boolean | Promise<boolean>

instanceId

instanceId: string

options

received

received: number

sessionId

sessionId: string

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

next

  • get next(): Promise<any>
  • Returns a promise that resolves with the next collected element; rejects with collected elements if the collector finishes without receiving a next element

    readonly

    Returns Promise<any>

Methods

[Symbol.asyncIterator]

  • [Symbol.asyncIterator](): any

addListener

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

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

          • Rest ...args: any[]

          Returns void

    Returns MessageCollector

checkEnd

  • checkEnd(): void
  • Checks whether the collector should end, and if so, ends it.

    Returns void

clearImmediate

  • clearImmediate(immediate: Immediate): void
  • Clears an immediate.

    Parameters

    • immediate: Immediate

      Immediate to cancel

    Returns void

clearInterval

  • clearInterval(interval: Timeout): void
  • Clears an interval.

    Parameters

    • interval: Timeout

      Interval to cancel

    Returns void

clearTimeout

  • clearTimeout(timeout: Timeout): void
  • Clears a timeout.

    Parameters

    • timeout: Timeout

      Timeout to cancel

    Returns void

destroy

  • destroy(): void
  • Destroys all assets used by the base client.

    Returns void

dispose

  • dispose(message: Message): `false_${number}-${number}@g.us_${string}` | `false_${number}@c.us_${string}` | `true_${number}-${number}@g.us_${string}` | `true_${number}@c.us_${string}`
  • Handles a message for possible disposal.

    Parameters

    • message: Message

      The message that could be disposed of

    Returns `false_${number}-${number}@g.us_${string}` | `false_${number}@c.us_${string}` | `true_${number}-${number}@g.us_${string}` | `true_${number}@c.us_${string}`

emit

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

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

    Returns boolean

eventNames

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

eventSignature

getMaxListeners

  • getMaxListeners(): number

handleCollect

  • handleCollect(...args: any[]): Promise<void>
  • Call this to handle an event as a collectable element. Accepts any event data as parameters.

    emits

    Collector#collect

    Parameters

    • Rest ...args: any[]

      The arguments emitted by the listener

    Returns Promise<void>

handleDispose

  • handleDispose(...args: any[]): Promise<void>
  • Call this to remove an element from the collection. Accepts any event data as parameters.

    emits

    Collector#dispose

    Parameters

    • Rest ...args: any[]

      The arguments emitted by the listener

    Returns Promise<void>

listenerCount

  • listenerCount(event: string | symbol): number

listeners

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

off

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

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

          • Rest ...args: any[]

          Returns void

    Returns MessageCollector

on

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

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

          • Rest ...args: any[]

          Returns void

    Returns MessageCollector

once

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

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

          • Rest ...args: any[]

          Returns void

    Returns MessageCollector

prependListener

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

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

          • Rest ...args: any[]

          Returns void

    Returns MessageCollector

prependOnceListener

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

rawListeners

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

removeAllListeners

removeListener

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

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

          • Rest ...args: any[]

          Returns void

    Returns MessageCollector

resetTimer

  • resetTimer(__namedParameters?: { idle: any; time: any }): void
  • Resets the collectors timeout and idle timer.

    Parameters

    • __namedParameters: { idle: any; time: any } = ...
      • idle: any
      • time: any

    Returns void

setImmediate

  • setImmediate(fn: (...args: any[]) => any, ...args: any[]): Immediate
  • Sets an immediate that will be automatically cancelled if the client is destroyed.

    Parameters

    • fn: (...args: any[]) => any

      Function to execute

        • (...args: any[]): any
        • Parameters

          • Rest ...args: any[]

          Returns any

    • Rest ...args: any[]

      Arguments for the function

    Returns Immediate

setInterval

  • setInterval(fn: (...args: any[]) => any, delay: number, ...args: any[]): Timeout
  • Sets an interval that will be automatically cancelled if the client is destroyed.

    Parameters

    • fn: (...args: any[]) => any

      Function to execute

        • (...args: any[]): any
        • Parameters

          • Rest ...args: any[]

          Returns any

    • delay: number

      Time to wait between executions (in milliseconds)

    • Rest ...args: any[]

      Arguments for the function

    Returns Timeout

setMaxListeners

setTimeout

  • setTimeout(fn: (...args: any[]) => any, delay: number, ...args: any[]): Timeout
  • Sets a timeout that will be automatically cancelled if the client is destroyed.

    Parameters

    • fn: (...args: any[]) => any

      Function to execute

        • (...args: any[]): any
        • Parameters

          • Rest ...args: any[]

          Returns any

    • delay: number

      Time to wait before executing (in milliseconds)

    • Rest ...args: any[]

      Arguments for the function

    Returns Timeout

stop

  • stop(reason?: string): void
  • Stops this collector and emits the end event.

    emits

    Collector#end

    Parameters

    • reason: string = 'user'

    Returns void

wrapHandler

  • wrapHandler(handler: (data: any) => any): (__namedParameters: { data: any }) => any
  • Parameters

    • handler: (data: any) => any
        • (data: any): any
        • Parameters

          • data: any

          Returns any

    Returns (__namedParameters: { data: any }) => any

      • (__namedParameters: { data: any }): any
      • Parameters

        • __namedParameters: { data: any }
          • data: any

        Returns any

Static getEventListener

  • getEventListener(emitter: DOMEventTarget | EventEmitter, name: string | symbol): Function[]
  • Returns a list listener for a specific emitter event name.

    Parameters

    • emitter: DOMEventTarget | EventEmitter
    • name: string | symbol

    Returns Function[]

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, options?: StaticEventEmitterOptions): AsyncIterableIterator<any>
  • Parameters

    • emitter: EventEmitter
    • event: string
    • Optional options: StaticEventEmitterOptions

    Returns AsyncIterableIterator<any>

Static once

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

    • emitter: NodeEventTarget
    • event: string | symbol
    • Optional options: StaticEventEmitterOptions

    Returns Promise<any[]>

  • Parameters

    • emitter: DOMEventTarget
    • event: string
    • Optional options: StaticEventEmitterOptions

    Returns Promise<any[]>