EventEmitter
ClientInterface
new Client(params
):Client
string
• params.businessAccountId: string
• params.phoneNumberId: string
• params.port: number
• params.webhookEndpoint: string
• params.webhookSecret: string
Client
EventEmitter.constructor
media: MediaManager
Media manager to upload, get and media via whatsapp cloud api
ClientInterface.media
message: MessageManager
Message manager to manage the outgoing messaging operations.
ClientInterface.message
Unix Timestamp at which client gets into ClientStatusEnum.Ready statereadonly
readyAtTimeStamp:null
|number
=null
ClientInterface.readyAtTimeStamp
requester: RequestClient
Requester is an internal utility to communicate with Whatsapp cloud api
ClientInterface.requester
status:Status of the clientnull
|ClientStatusEnum
=null
ClientInterface.status
webhook: Webhook
Webhook manager to handle the incoming message and event listening
ClientInterface.webhook
Value:static
readonly
captureRejectionSymbol: typeofcaptureRejectionSymbol
Symbol.for('nodejs.rejection')
See how to write a custom rejection handler
.
EventEmitter.captureRejectionSymbol
Value: boolean Change the defaultstatic
captureRejections:boolean
captureRejections
option on all new EventEmitter
objects.
EventEmitter.captureRejections
By default, a maximum ofstatic
defaultMaxListeners:number
10
listeners can be registered for any single
event. This limit can be changed for individual EventEmitter
instances
using the emitter.setMaxListeners(n)
method. To change the default
for allEventEmitter
instances, the events.defaultMaxListeners
property
can be used. If this value is not a positive number, a RangeError
is thrown.
Take caution when setting the events.defaultMaxListeners
because the
change affects all EventEmitter
instances, including those created before
the change is made. However, calling emitter.setMaxListeners(n)
still has
precedence over events.defaultMaxListeners
.
This is not a hard limit. The EventEmitter
instance will allow
more listeners to be added but will output a trace warning to stderr indicating
that a “possible EventEmitter memory leak” has been detected. For any single
EventEmitter
, the emitter.getMaxListeners()
and emitter.setMaxListeners()
methods can be used to
temporarily avoid this warning:
--trace-warnings
command-line flag can be used to display the
stack trace for such warnings.
The emitted warning can be inspected with process.on('warning')
and will
have the additional emitter
, type
, and count
properties, referring to
the event emitter instance, the event’s name and the number of attached
listeners, respectively.
Its name
property is set to 'MaxListenersExceededWarning'
.
EventEmitter.defaultMaxListeners
This symbol shall be used to install a listener for only monitoringstatic
readonly
errorMonitor: typeoferrorMonitor
'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.
EventEmitter.errorMonitor
Timestamp at which the client switched to ClientStatusEnum.Ready stateget
getReadyAtTimestamp():null
|0
|Date
null
| 0
| Date
Getter for phone numberget
phoneNumberId():string
string
Function to update the initial access token given at the point of client creationsset
updateAccessToken(accessToken
):void
string
Function to set the phone number id used to send messagesset
updateSenderPhoneNumberId(phoneNumber
):void
string
Uptime in milliseconds since the client first got into ClientStatusEnum.Ready stateget
uptime():null
|number
null
| number
[captureRejectionSymbol]
()?optional
[captureRejectionSymbol]<K
>(error
,event
, …args
):void
Error
• event: string
| symbol
• …args: AnyRest
void
EventEmitter.[captureRejectionSymbol]
addListener<Alias forK
>(eventName
,listener
):this
emitter.on(eventName, listener)
.
string
| symbol
• listener
this
EventEmitter.addListener
emit<Function to emit a new event on incoming webhook or wapi eventsT
>(eventName
,data
):boolean
WapiEventDataMap
T
• data: WapiEventDataMap
[T
]
boolean
ClientInterface.emit
EventEmitter.emit
eventNames(): (Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings orstring
|symbol
)[]
Symbol
s.
string
| symbol
)[]
EventEmitter.eventNames
getMaxListeners(): number
Returns the current max listener value for the EventEmitter
which is either
set by emitter.setMaxListeners(n)
or defaults to defaultMaxListeners.
number
EventEmitter.getMaxListeners
initiate(): void
Function to initiate the wapi client and start listening to the incoming webhook events
void
ClientInterface.initiate
listenerCount<Returns the number of listeners listening for the event namedK
>(eventName
,listener
?):number
eventName
.
If listener
is provided, it will return how many times the listener is found
in the list of the listeners of the event.
string
| symbol
The name of the event being listened for
• listener?: Function
The event handler function
number
EventEmitter.listenerCount
listeners<Returns a copy of the array of listeners for the event namedK
>(eventName
):Function
[]
eventName
.
string
| symbol
Function
[]
EventEmitter.listeners
off<Alias forK
>(eventName
,listener
):this
emitter.removeListener()
.
string
| symbol
• listener
this
EventEmitter.off
on<Function to attach event listener to wapi clientT
>(eventName
,listener
):this
WapiEventDataMap
T
• listener
this
ClientInterface.on
EventEmitter.on
once<Adds a one-timeK
>(eventName
,listener
):this
listener
function for the event named eventName
. The
next time eventName
is triggered, this listener is removed and then invoked.
EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener()
method can be used as an alternative to add the
event listener to the beginning of the listeners array.
string
| symbol
The name of the event.
• listener
The callback function
this
EventEmitter.once
prependListener<Adds theK
>(eventName
,listener
):this
listener
function to the beginning of the listeners array for the
event named eventName
. No checks are made to see if the listener
has
already been added. Multiple calls passing the same combination of eventName
and listener
will result in the listener
being added, and called, multiple times.
EventEmitter
, so that calls can be chained.
string
| symbol
The name of the event.
• listener
The callback function
this
EventEmitter.prependListener
prependOnceListener<Adds a one-timeK
>(eventName
,listener
):this
listener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
listener is removed, and then invoked.
EventEmitter
, so that calls can be chained.
string
| symbol
The name of the event.
• listener
The callback function
this
EventEmitter.prependOnceListener
rawListeners<Returns a copy of the array of listeners for the event namedK
>(eventName
):Function
[]
eventName
,
including any wrappers (such as those created by .once()
).
string
| symbol
Function
[]
EventEmitter.rawListeners
removeAllListeners(Removes all listeners, or those of the specifiedeventName
?):this
eventName
.
It is bad practice to remove listeners added elsewhere in the code,
particularly when the EventEmitter
instance was created by some other
component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
string
| symbol
this
EventEmitter.removeAllListeners
removeListener<Removes the specifiedK
>(eventName
,listener
):this
listener
from the listener array for the event named eventName
.
removeListener()
will remove, at most, one instance of a listener from the
listener array. If any single listener has been added multiple times to the
listener array for the specified eventName
, then removeListener()
must be
called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
time of emitting are called in order. This implies that any removeListener()
or removeAllListeners()
calls after emitting and before the last listener finishes execution
will not remove them fromemit()
in progress. Subsequent events behave as expected.
emitter.listeners()
method will need to be recreated.
When a single function has been added as a handler multiple times for a single
event (as in the example below), removeListener()
will remove the most
recently added instance. In the example the once('ping')
listener is removed:
EventEmitter
, so that calls can be chained.
string
| symbol
• listener
this
EventEmitter.removeListener
setMaxListeners(By defaultn
):this
EventEmitter
s will print a warning if more than 10
listeners are
added for a particular event. This is a useful default that helps finding
memory leaks. The emitter.setMaxListeners()
method allows the limit to be
modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
number
this
EventEmitter.setMaxListeners
Experimental
Listens once to thestatic
addAbortListener(signal
,resource
):Disposable
abort
event on the provided signal
.
Listening to the abort
event on abort signals is unsafe and may
lead to resource leaks since another third party with the signal can
call e.stopImmediatePropagation()
. Unfortunately Node.js cannot change
this since it would violate the web standard. Additionally, the original
API makes it easy to forget to remove listeners.
This API allows safely using AbortSignal
s in Node.js APIs by solving these
two issues by listening to the event such that stopImmediatePropagation
does
not prevent the listener from running.
Returns a disposable so that it may be unsubscribed from more easily.
AbortSignal
• resource
Disposable
Disposable that removes the abort
listener.
EventEmitter.addAbortListener
getter for clientstatic
getClient(): typeofClient
Client
Returns a copy of the array of listeners for the event namedstatic
getEventListeners(emitter
,name
):Function
[]
eventName
.
For EventEmitter
s this behaves exactly the same as calling .listeners
on
the emitter.
For EventTarget
s this is the only way to get the event listeners for the
event target. This is useful for debugging and diagnostic purposes.
EventTarget
| EventEmitter
<DefaultEventMap
>
• name: string
| symbol
Function
[]
EventEmitter.getEventListeners
Returns the currently set max amount of listeners. Forstatic
getMaxListeners(emitter
):number
EventEmitter
s this behaves exactly the same as calling .getMaxListeners
on
the emitter.
For EventTarget
s this is the only way to get the max event listeners for the
event target. If the number of event handlers on a single EventTarget exceeds
the max set, the EventTarget will print a warning.
EventTarget
| EventEmitter
<DefaultEventMap
>
number
EventEmitter.getMaxListeners
A class method that returns the number of listeners for the givenstatic
listenerCount(emitter
,eventName
):number
eventName
registered on the given emitter
.
EventEmitter
<DefaultEventMap
>
The emitter to query
• eventName: string
| symbol
The event name
number
EventEmitter.listenerCount
listenerCount
instead.
static
on(emitter
,eventName
,options
?):AsyncIterableIterator
<any
>
AsyncIterator
that iterates eventName
events. It will throw
if the EventEmitter
emits 'error'
. It removes all listeners when
exiting the loop. The value
returned by each iteration is an array
composed of the emitted event arguments.
An AbortSignal
can be used to cancel waiting on events:
EventEmitter
<DefaultEventMap
>
• eventName: string
The name of the event being listened for
• options?: StaticEventEmitterOptions
AsyncIterableIterator
<any
>
An AsyncIterator
that iterates eventName
events emitted by the emitter
EventEmitter.on
Creates astatic
once(emitter
,eventName
,options
?):Promise
<any
[]>
Promise
that is fulfilled when the EventEmitter
emits the given
event or that is rejected if the EventEmitter
emits 'error'
while waiting.
The Promise
will resolve with an array of all the arguments emitted to the
given event.
This method is intentionally generic and works with the web platform EventTarget interface, which has no special'error'
event
semantics and does not listen to the 'error'
event.
'error'
event is only used when events.once()
is used to wait for another event. If events.once()
is used to wait for the
‘error'
event itself, then it is treated as any other kind of event without
special handling:
AbortSignal
can be used to cancel waiting for the event:
EventEmitter
<DefaultEventMap
>
• eventName: string
| symbol
• options?: StaticEventEmitterOptions
Promise
<any
[]>
EventEmitter.once
static
once(emitter
,eventName
,options
?):Promise
<any
[]>
EventTarget
• eventName: string
• options?: StaticEventEmitterOptions
Promise
<any
[]>
EventEmitter.once
static
setMaxListeners(n
?, …eventTargets
?):void
number
A non-negative number. The maximum number of listeners per EventTarget
event.
• …eventTargets?: (EventTarget
| EventEmitter
<DefaultEventMap
>)[]
void
EventEmitter.setMaxListeners