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 path | Exported member |
|---|---|
CQ.Communications.HttpRequest | HttpRequest |
CQ.Communications.sendMessage | sendMessage |
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
| Method | Parameters | Returns |
|---|---|---|
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 (
emailby default, can be sent toslackorteamsas well) - additionalParamateres (
url,subjectData, andtoare 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"
})
| Parameter | Type | Default | Description |
|---|---|---|---|
text | string | Required | Notification message. |
type | string | "email" | One of "email", "slack", or "teams". |
additionalParamateres | object | Object with url, subjectData, and to set to null | Delivery-specific options. |
additionalParamateres.url | string or null | null | Destination hook URL. |
additionalParamateres.subjectData | any | null | Optional subject data. |
additionalParamateres.to | string or null | null | Email 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.