Skip to content

Documentation

Communications

Communication helpers exposed to CYBERQUEST scripts through CQ.Communications.

Overview

The CQ.Communications namespace provides HTTP and notification helpers for use in customizable CYBERQUEST scripts, including Data Transformation Service (DTS) and alert scripts.

Available members

Access pathExported member
CQ.Communications.HttpRequestHttpRequest
CQ.Communications.sendMessagesendMessage

HttpRequest

This class is a wrapper that encapsulates the http client on specific targets (windowsagent, etc.).

All methods that send requests will return a uniform formatted response, along with the status code or potential errors.

Access this class through the global CQ object as CQ.Communications.HttpRequest.

Configuration

const config = {
  method: "GET",
  data: null,
  withCredentials: false,
  CredentialsType: "plain", // "plain", "encrypted", or "managed"
  timeout: 60000, // milliseconds
  rejectUnauthorized: false,
  auth: {
    username: "user",
    password: "pass"
  },
  headers: {},
  cookies: [],
  responseSizeLimit: -1 // unlimited
};

These are the defaults applied by HttpRequest. The auth value may also be a managed-credential GUID. Request-specific configuration is merged with these defaults. The convenience methods override method and, where applicable, data before sending the request.

Request methods

MethodParametersReturns
get(url, config = null)Request URL and optional configuration object.HttpResponse
post(url, data, config = null)Request URL, request body, and optional configuration.HttpResponse
put(url, data, config = null)Request URL, request body, and optional configuration.HttpResponse
delete(url, config = null)Request URL and optional configuration.HttpResponse
head(url, config = null)Request URL and optional configuration.HttpResponse
putV2(url, data, config = null)Request URL, request body, and optional configuration.HttpResponse
deleteV2(url, data, config = null)Request URL, request body, and optional configuration.HttpResponse
headV2(url, data, config = null)Request URL, request body, and optional configuration.HttpResponse
patchV2(url, data, config = null)Request URL, request body, and optional configuration.HttpResponse

The V2 variants pass data through to the runtime transport for HTTP methods whose original wrapper does not accept a request body.

HttpRequest.get

CQ.Communications.HttpRequest.get(url, config=null)
  • HttpResponse

HttpRequest.post

CQ.Communications.HttpRequest.post(url, data, config=null)
  • HttpResponse

HttpRequest.put

CQ.Communications.HttpRequest.put(url, data, config=null)
  • HttpResponse

HttpRequest.delete

CQ.Communications.HttpRequest.delete(url, config=null)
  • HttpResponse

HttpRequest.head

CQ.Communications.HttpRequest.head(url, config=null)
  • HttpResponse

HttpRequest.putV2

CQ.Communications.HttpRequest.putV2(url, data, config=null)

HttpRequest.deleteV2

CQ.Communications.HttpRequest.deleteV2(url, data, config=null)

HttpRequest.headV2

CQ.Communications.HttpRequest.headV2(url, data, config=null)

HttpRequest.patchV2

CQ.Communications.HttpRequest.patchV2(url, data, config=null)

HttpResponse

Properties:

  • int statusCode
  • string data - The raw response body
  • string header - The raw response header
  • Array headers - The response headers
  • string errorMsg - Error message, if any
  • string contentType - Response content type
  • boolean isError - Whether the request failed
  • int messageLength - Response-body length

HttpResponse.getData()

Returns the response body stored in data without parsing it.

HttpResponse.asJson()

Returns the parsed response body when it contains valid JSON; otherwise, returns null.

HttpResponse.asXml()

Parses the response body with JSON.parse().

sendMessage

Parameters:

  • text - this is the message of the notification
  • type - what platform the notification is sent to (email by default, can be sent to slack or teams as well)
  • additionalParamateres (url, subjectData, and to are optional at this layer)

Taking into account the type parameter of the sendMessage method, the module will select the appropriate particular class, instantiate it under its own rules and dispatch the notification.

Usage

CQ.Communications.sendMessage(message, platform, {
  url: "",
  to: "optional",
  subjectData: "optional"
})
ParameterTypeDefaultDescription
textstringRequiredNotification message.
typestring"email"One of "email", "slack", or "teams".
additionalParamateresobjectObject with url, subjectData, and to set to nullDelivery-specific options.
additionalParamateres.urlstring or nullnullDestination hook URL.
additionalParamateres.subjectDataanynullOptional subject data.
additionalParamateres.tostring or nullnullEmail recipient.

subjectData is accepted for compatibility but is not currently used by the runtime notification dispatcher. url is passed to the selected notification hook; whether it is required depends on that hook. For email, the dispatcher constructs this payload before calling the email hook:

{
  payload: {
    data: {
      to: additionalParamateres.to,
      Severity: 4,
      Message: text
    }
  },
  localTime: moment().unix()
}

Slack and Teams receive a message object containing { text } instead; the hook determines how url is used. The function returns the selected hook’s sendMessage result, or undefined when type is unsupported.