Events (MoogDb Only)
Compatibility with MoogDb and MoogDb.V2
Methods and auxiliary objects listed here are compatible with the MoogDb module, which was removed in v4.1.14.
Information here is provided for reference only.
For methods and auxiliary objects compatible with its replacement, see the MoogDb V2 module.
Description
The events Moobot module allows you to make a Moobot driven by the occurrence of events by defining the type of event that interests the Moobot.
The events module is available to load into any standard Moobot.
To use, at the top of a Moobot js file, define a new global variable events
to load the events module:
var events = MooBot.loadModule('Events');
Method
events.onEvent
The events module has only one method, onEvent
. This method points the Moobot to a supplied JavaScript function, which is called when a specified event type occurs.
The parameters to the called function depend on the type of event that you are listening for. In a Moobot, this method is typically the last line in a script.
The type of event adaptor chosen is specific to the type of Moobot you are building.
events.onEvent
Takes the name of a valid JavaScript function in a Moobot and also event code (from the constants module eventType
), and returns an event adaptor object.
Request Arguments
Name | Type | Description |
---|---|---|
functionName | String | The name of a valid JavaScript function in the Moobot that is called when the event arrives. |
type | CEvent |
|
Return Parameter
Name | Type | Description |
---|---|---|
CEventAdaptor | Object | An event adaptor object. Made active with the listen function in-line to listen for the event type. |
Example
For the AlertBuilder MooBot:
events.onEvent("newEvent",constants.eventType("Event")).listen();
When the Moolet starts and loads this events Moobot, its JavaScript file executes, initialising the Moobot to respond in an event-driven way to events arriving.
newEvent Javascript function
The format of the function newEvent
(which is called when you get an event), is as follows:
function newEvent
Request Arguments
Name | Type | Description |
---|---|---|
event | CEvent object | An object that encapsulates all the data for the event from the Message Bus. |
response | CResponse object | An object to communicate back to the Moolet. The Moolet uses this response to broadcast any updates, or any changes to the data structures on the Message Bus. |
CEventAdaptor auxiliary object
This object is a utility class used by the events module to allow for the programmatic activation of event listening. It has one method:
listen
Starts the event adaptor listening, which then calls the specified function when an event occurs.
Request Argument
None.
Return Parameter
Void - no value returned.
CEvent auxiliary object
This object encapsulates a generic Message Bus event object, and the contents of it are specific to the event type it represents. You can however access the key-value pairs contained in the object, and also set the values. Its methods include:
contains
Returns true if the event contains a value stored at the key name.
Request Argument
Name | Type | Description |
---|---|---|
name | String | The name of the key being queried. |
Return Parameter
Type | Description |
---|---|
Boolean | True if the Event has a field called |
set
Associates the specified value
with the specified name
in the event. Previous key mapping has the old value
replaced.
Request Argument
Name | Type | Description |
---|---|---|
name | String | The key with which the specified value is to be associated. |
value | Object | The value associated with the key. |
Return Parameter
Type | Description |
---|---|
Boolean | Indicates if the operation was successful: true = success, false = fail. |
value
Returns the object stored at the key name
.
Request Argument
Name | Type | Description |
---|---|---|
name | String | The name of the key to return the object from. |
Return Parameter
Type | Description |
---|---|
Object | A Javascript object containing what is at the key name. |
CEvent auxiliary object
Note
The following methods only apply to the MoogDb module, which is being deprecated.
getCorrelationInfo
Returns the external service correlation_info
(where this has been set) for a Situation.
Request Argument
Name | Type | Description |
---|---|---|
scope | Javascript object | The Moobot context, provided by using |
Return Parameter
Type | Description |
---|---|
Object | Javascript object containing the |
getCustomInfo
Returns the custom information (if any) for an alert or Situation.
Request Argument
Name | Type | Description |
---|---|---|
scope | Javascript object | The Moobot context, provided by using this as a parameter. |
Return Parameter
Type | Description |
---|---|
Object | Javascript object containing the custom information. |
getJournalDetails
Returns the details (if any) of the journaled operation for a Situation.
Request Argument
Name | Type | Description |
---|---|---|
scope | Javascript object | The Moobot context, provided by using |
Return Parameter
Type | Description |
---|---|
Object | Javascript object containing the details of the journaled operation for a Situation. |
getSummaryData
Returns the summary information from a statistics summary event.
Request Argument
Name | Type | Description |
---|---|---|
scope | Javascript object | The Moobot context, provided by using |
Return Parameter
Type | Description |
---|---|
Object | Javascript object containing the summary information. |
setCustomInfo
Sets the custom information for an Alert or Situation
Request Arguments
Name | Type | Description |
---|---|---|
scope | Javascript object | The Moobot context, provided by using |
customInfoJS | Native object | A Javascript object containing the custom information. |
Return Parameter
Void - no value returned.
CResponse auxiliary object
Note
The following methods only apply to the MoogDb module, which has been deprecated.
doNotPropagate
Indicates that no propagation is needed.
Request Argument
None.
Return Parameter
Void - no value returned.
message
Object to broadcast on.
Request Argument
Name | Type | Description |
---|---|---|
msg | CEvent | Object to broadcast on. |
Return Parameter
Void - no value returned.
output
Freeform message to attach.
Request Argument
Name | Type | Description |
---|---|---|
txt | String | The message as a text string. |
Return Parameter
Void - no value returned.
retcode
The retcode
value must be >= 0 for a message to be sent.
Request Argument
Name | Type | Description |
---|---|---|
code | Number | Must be >= 0 for a message to be sent. |
Return Parameter
Void - no value returned.
topic
Topic to broadcast message on.
Request Argument
Name | Type | Description |
---|---|---|
topic | String | The topic name. |
Return Parameter
Void - no value returned.