The Utilities module contains useful utility functions commonly used in other modules and project code.
Table of Contents |
---|
Dependencies
The Utilities module is dependent on the following modules:
math
utilities.math contains mathematical utility functions
getRandomInt
Returns a random integer between a minimum and maximum value (inclusive).
...
Returns: A random integer between the minimum and maximum value (inclusive).
multiagent
utilities.multiagent contains utility functions for working with Orbita multiagent objects
randomize
Randomizes the content of a multiagent object by looking for double horizontal rule tags as a separator in the raw multiagent entries, choosing a random response from the available options for each entry, and updating the multiagent with the randomized content.
...
Returns: The Orbita multiagent object with the response randomized.
getEmpty
Returns an empty Orbita multiagent object.
...
Returns: An empty Orbita multiagent object.
string
utilities.string contains utility functions for working with strings
normalize
Formats a string to normalize it for comparison purposes.
...
Returns: The string in lowercase with leading and trailing whitespace trimmed.
removeExcessWhitespace
Collapses any group of multiple whitespace characters in the string down to a single space.
...
Returns: The string with excess whitespace collapsed.
removeLinkTags
Strips any link tags from the string.
...
Returns: The string with link tags removed.
stripNewLines
Strips new line characters from the provided string.
...
Returns: The string stripped of new line characters.
hyphenate
Hyphenates the provided string by replacing spaces with hyphens.
...
Returns: The hyphenated string.
capitalize
Will uppercase the first character of the provided string.
...
Returns: The capitalized string.
camelize
Will take a series of words and reduce it to a single camelcase word.
...
Returns: The camelized string.
isString
Indicates if the provided value is a string or not.
...
Returns: True if the value is a string, false otherwise.
input
utilities.input contains utility functions for cleaning and validating input
phone.clean
Strips a phone number down to just its digits.
...
Returns: A string containing only the digits from the phone number.
phone.isValid
Determines the validity of the provided phone number (after cleaning it first).
...
Returns: True if the phone number is valid, false otherwise.
email.isValid
Determines the validity of the provided email address.
...
Returns: True if the email address is valid, false otherwise.
session
utilities.session contains utility functions for working with Orbita session
getSessionId
Gets the Orbita session ID from a message object.
...
Returns: The Orbita session ID for the request.
Anchor | ||||
---|---|---|---|---|
|
Indicates if the provided message object originated from a chat session.
...
Info |
---|
The determination is made based on the presence of the isChatRequest flag set by the Chatbot module. |
object
utilities.object contains utility functions for working with objects
deepFreeze
Freezes an object entirely by recursively freezing all properties.
...
Returns: The frozen object.
clone
An alias for Lodash's clone method.
get
An alias for Lodash's get method.
set
An alias for Lodash’s set method.
unset
An alias for Lodash’s unset method.
isPureObject
Indicates if the specified object is a pure object (and not an array, function, or null).
...
Returns: True if the object is a pure object, false otherwise.
merge
An alias for Lodash’s merge method.
replaceTokens
Replaces tokens from the provided mapping in any string properties at any level in the object.
...
Returns: Nothing, the replacements are performed in-place.
mongo
utilities.mongo contains utility functions related to MongoDB
isValidObjectId
Checks whether or not a provided string is a valid Mongo Object ID.
...
Returns: True if the string is a valid Mongo Object ID, false otherwise.
orbita
utilities.orbita contains utility functions that are very specific to Orbita
parseVersion
Parses an Orbita version string
...
major (int): The parsed major version.
minor (int): The parsed minor version.
patch (int): The parsed patch version.
build (int): The parsed build number (if any).
isAtLeast (function): This function takes in a version to compare the parsed version to. Returns true if the parsed version is at least the same as or a later version than the specified target version, or false otherwise.
redis
utilities.redis contains functions for writing to and reading from the Redis cache
Note |
---|
For each of these functions, if Redis caching is not enabled for the environment, the standard in-memory store will be used. A warning will appear in the debug console if this is happening, but the promise returned from the function will not reject. |
get
Gets an entry from the Redis cache by key.
...
Returns: A promise that will resolve with the requested entry (or undefined if it does not exist in the cache)
set
Sets an entry in the Redis cache with the specified key and value.
...
Returns: A promise that will resolve when the value has been written to the cache
clear
Gets an entry from the Redis with the specified key by setting it to undefined.
...
Returns: A promise that will resolve when the value has been cleared from the cache
data
utilities.data contains utility functions for data transformations and manipulations
map
Maps data from a source object to a new format using the provided mapping.
...
Returns: The mapped data.
backendRequest
A helper function for making requests to the Orbita backend.
...
Returns: A promise that will resolve with the status code and body of the response when the request has been fulfilled.
httpRequest
A helper function for making generic HTTP requests.
...
Returns: A promise that will resolve with the status code and body of the response when the request has been fulfilled.
orbitaAPI
utilities.orbitaAPI contains wrappers for Orbita API endpoints
Anchor | ||||
---|---|---|---|---|
|
Retrieves an Orbita authentication token for the current environment using the provided credentials
...
Returns: A promise that will resolve with an authentication token for the provided service account.
verify
Verifies the validity of a provided authentication token.
...
Returns: A promise that will resolve with the verification response from Orbita.
user
utilities.orbitaAPI.user contains wrappers for Orbita user API endpoints.
getById
Retrieves an Orbita user by their ID.
...
Returns: A promise that will resolve with the Orbita user record.
schema
utilities.orbitaAPI.schema contains wrappers for Orbita schema API endpoints.
getByKey
Retrieves an Orbita schema by type and key.
...
Returns: A promise that will resolve with the Orbita schema.
getSchemaFields
Returns a simplified list of the fields of the specified Orbita schema.
...
Returns: A promise that will resolve with a simplified list of the schema fields (key and type only).
content
utilities.orbitaAPI.content contains wrappers for Orbita content API endpoints.
getAll
Retrieves all Orbita content records by type and schema key.
...
Returns: A promise that will resolve with all the content records for the specified schema.
getById
Retrieves an Orbita content record by type, schema key and id.
...
Returns: A promise that will resolve with the content record.
getOneByProperty
Retrieves an Orbita content record by type, schema key, property and value.
...
Returns: A promise that will resolve with the first content record with the specified property set to the specified value, or null if no results were found.
create
Creates an Orbita content record with the specified type, schema key, and data.
...
Returns: A promise that will resolve with the created content record.
update
Updates an Orbita content record with the specified type, schema key, and id with the provided data.
...
Returns: A promise that will resolve with the updated content record.
slotType
utilities.orbitaAPI.slotType contains wrappers for Orbita slot type API endpoints.
get
Retrieves an Orbita slot type by name.
...
Returns: A promise that will resolve with the slot type.
create
Creates an Orbita slot type.
...
Returns: A promise that will resolve with the newly created slot type record.
create
Updates an Orbita slot type.
...
Returns: A promise that will resolve with the updated slot type record.
flowStudio
utilities.orbitaAPI.flowStudio contains wrappers for Orbita Flow studio API endpoints.
getOneByProperty
Retrieves an Orbita Flow Studio flow by property and value.
...
Returns: A promise that will resolve with the first Flow Studio flow with the specified property set to the specified value, or null if no results were found.
orbitaUtilities
utilities.orbitaUtilities contains wrappers for Orbita Utilities endpoints
orbita
utilities.orbitaUtilities.orbita contains wrappers for the Orbita Utilities wrapper for Orbita API endpoints
getProject
Retrieves an Orbita project from a specified environment by ID.
...
Returns: A promise that will resolve with the Orbita project.
getAllSchemas
Retrieves all available schemas for an Orbita project from a specified environment by ID.
...
Returns: A promise that will resolve with the available schemas for the Orbita project.
environment
utilities.orbitaUtilities.environment contains wrappers for the Orbita Utilities environment endpoint
getById
Retrieves an environment from Orbita Utilities by ID.
...
Returns: A promise that will resolve with the environment.
clientProject
utilities.orbitaUtilities.clientProject contains wrappers for the Orbita Utilities client project endpoint
getById
Retrieves a client project from Orbita Utilities by ID.
...
Returns: A promise that will resolve with the client project.
versionControl
utilities.orbitaUtilities.versionControl contains wrappers for the Orbita Utilities version control endpoint
requestDifferenceForConfiguration
Requests a difference for a particular version control configuration.
...
Returns: A promise that will resolve with the Git diff when the request has been fulfilled by Orbita Utilities.
requestSnapshotForConfiguration
Requests a snapshot for a particular version control configuration.
...
Returns: A promise that will resolve when the request has been fulfilled by Orbita Utilities.
configuration
utilities.orbitaUtilities.versionControl.configuration contains wrappers for the Orbita Utilities version control configuration endpoint
getById
Retrieves a version control configuration from Orbita Utilities by ID.
...
Returns: A promise that will resolve with the version control configuration.
sync
utilities.orbitaUtilities.sync contains wrappers for the Orbita Utilities sync endpoint
status
utilities.orbitaUtilities.sync.status contains wrappers for the Orbita Utilities sync status endpoint
getCurrent
Retrieves the current sync status information from Orbita Utilities.
...
Returns: A promise that will resolve with the current sync status information.
content
utilities.orbitaUtilities.sync.content contains wrappers for the Orbita Utilities content sync endpoint
requestSynchronization
Requests a synchronization of content from one project to another in Orbita Utilities.
...
Returns: A promise that will resolve with the response to the content synchronization request from Orbita Utilities.
flowStudio
utilities.orbitaUtilities.sync.flowStudio contains wrappers for the Orbita Utilities flow studio sync endpoint
requestSynchronization
Requests a synchronization of flow studio flows from one project to another in Orbita Utilities.
...