Moogsoft Docs

Constants

Each Moobot runs in its own thread and instances of Moobots are independent of each other. The Constants module enables you to share logic, states or flags between Moobots. You can build a key value dictionary mapping that is shared across Moobot instances.

There are many system wide defined Constants that are used in the Events module to define which event to listen for. See the event types table below for more information.

The Constants module is available to load into any standard Moobot.

To use, define a new global object constants at the top of a Moobot JavaScript file:

var constants = MooBot.loadModule('Constants');
Reference Guide

You can use the following methods in the RabbitMQ Moobot module.

put

Associated the specified value with the specified key. Replaces the mapping for an existing key.

Request Argument

Name

Type

Description

key

String

The key to associate with the value.

value

Object

The value to associate with the key.

Return Parameter

None.

get

Returns the value mapped to a specified key.

Request Argument

Name

Type

Description

key

String

The key for which to retrieve the value.

Return Parameter

Type

Description

Object

The value to which the key is mapped, or null if no mapping exists.

contains

Returns a positive response if the module contains an object with the specified name.

Request Argument

Name

Type

Description

name

String

The Object name.

Return Parameter

Type

Description

Boolean

True if the module contains the named object, otherwise false.

remove

Removes the value mapped to the specified key.

Request Argument

Name

Type

Description

key

String

The key for which the value is to be removed.

Return Parameter

None.

eventType

Returns the value of a specified event type.

Request Argument

Name

Type

Description

name

String

The name of the event type. See the list below.

Event Types

Name

Passed Value

Description

E_LamEvent

"Event"/"Events"

Raw event from a LAM

E_NewAlert

"Alert"/"Alerts"

New alert

E_AlertUpdate

"AlertUpdate"

Alert update

E_CloseAlert

"AlertClose"

Close alert

E_NewComment

"Comment"

New comment

E_NewFeedback

"Feedback"

New feedback

E_NewSig

"Sig"

New Situation

E_SigClose

"SigClose"

Close Situation

E_SigUpdate

"SigUpdate"

Updated Situation

E_SigStatus

"SigStatus"

Situation status

E_SigAction

"SigAction"

Situation action

E_ThreadEntry

"ThreadEntry"

A thread entry

E_NewThreadEntry

"NewThreadEntry"

A new thread entry

E_Summary

"Summary"

System summary

E_Invite

"Invitation"

Situation Room invitation

E_User

"User"

Username

E_Unknown

"Unknown"

An uncategorised event (error condition)

Return Parameter

Type

Description

CEvent

An object containing the value of the specified event type.

Examples

The following example in AlertBuilder.js shows the Constants module with two methods that allow you to post and retrieve values from a shared scratchpad.

var count=0 
constants.put("counter",count);

The variable count is set to 0 and stored using the label counter.

  • put () takes the name of the variable you want to store counter, and the variable count.

You can later retrieve a value by calling the method get () and passing the name of the shared attribute you want, which is returned as a JavaScript local variable.

var count_val=constants.get("counter");
count_val++; 
constants.put("counter",count_val);
  • get takes the name of the shared attribute counter.

  • count_val is incremented.

  • put takes the name of the variable to store, counter, and the incremented value count_val.

If nothing is stored in counter, the Moobot returns null.

The following example passes the name of an event and returns a system wide constant that identifies that type of event when using the Events module.

constants.eventType("Event")