@cognigy/rest-api-client
Version:
Cognigy REST-Client
221 lines • 8.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EMAIL_NOTIFICATION = exports.EMAIL_NOTIFICATION_ERROR = void 0;
/* Custom modules */
const createNodeDescriptor_1 = require("../../../createNodeDescriptor");
const errors_1 = require("../../../../errors");
exports.EMAIL_NOTIFICATION_ERROR = "Email Notifcations have not yet been configured for this environment. Please contact your system administrator to enable this feature";
exports.EMAIL_NOTIFICATION = (0, createNodeDescriptor_1.createNodeDescriptor)({
type: "emailNotification",
defaultLabel: "Email Notification",
summary: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__SUMMARY",
fields: [
{
key: "recipient",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__RECIPIENT__LABEL",
description: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__RECIPIENT__DESCRIPTION",
params: {
required: true
}
},
{
key: "subject",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__SUBJECT__LABEL",
params: {
required: true
}
},
{
key: "message",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__MESSAGE__LABEL",
defaultValue: "\n",
params: {
multiline: true,
richText: true
}
},
{
key: "cc",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__CC__LABEL",
description: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__CC__DESCRIPTION",
},
{
key: "bcc",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__BCC__LABEL",
description: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__BCC__DESCRIPTION",
},
{
key: "async",
type: "toggle",
label: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__ASYNC__LABEL",
description: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__ASYNC__DESCRIPTION",
defaultValue: false
},
{
key: "priority",
type: "select",
label: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__PRIORITY__LABEL",
defaultValue: "normal",
params: {
options: [
{ label: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__PRIORITY__HIGH__LABEL", value: "high" },
{ label: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__PRIORITY__NORMAL__LABEL", value: "normal" },
{ label: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__PRIORITY__LOW__LABEL", value: "low" }
]
}
},
{
key: "storeLocation",
type: "select",
label: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__STORE_LOCATION__LABEL",
description: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__STORE_LOCATION__DESCRIPTION",
params: {
options: [
{
label: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__STORE_LOCATION__NONE__LABEL",
value: "none"
},
{
label: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__STORE_LOCATION__INPUT__LABEL",
value: "input"
},
{
label: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__STORE_LOCATION__CONTEXT__LABEL",
value: "context"
}
],
},
defaultValue: "none"
},
{
key: "inputKey",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__INPUT_KEY__LABEL",
defaultValue: "email",
condition: {
key: "storeLocation",
value: "input",
}
},
{
key: "contextKey",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__CONTEXT_KEY__LABEL",
defaultValue: "email",
condition: {
key: "storeLocation",
value: "context",
}
},
{
key: "stopOnError",
type: "toggle",
label: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__STOP_ON_ERROR__LABEL",
defaultValue: false
}
],
sections: [
{
"key": "advanced",
"label": "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__ADVANCED__LABEL",
"defaultCollapsed": true,
"fields": [
"from",
"cc",
"bcc",
"replyTo",
"defineText",
"text",
"priority",
"async"
]
},
{
"key": "attachments",
"label": "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__ATTACHMENTS__LABEL",
"defaultCollapsed": true,
"fields": [
"attachmentType",
"attachmentFilename",
"attachmentContentType",
"attachmentEncodingType",
"attachmentContent",
"attachmentURL",
"attachmentRaw"
]
},
{
key: "resultStorage",
label: "UI__NODE_EDITOR__SMTP__EMAIL_NOTIFICATION__RESULT_STORAGE__LABEL",
defaultCollapsed: true,
fields: [
"storeLocation",
"inputKey",
"contextKey",
"stopOnError"
]
},
],
form: [
{ key: "recipient", type: "field" },
{ key: "subject", type: "field" },
{ key: "message", type: "field" },
{ key: "resultStorage", type: "section" },
{ key: "advanced", type: "section" }
],
preview: {
key: "recipient",
type: "text"
},
tags: ["data", "service", "mail", "email"],
function: async ({ cognigy, config, nodeId, nodeType, organisationId, projectId, childConfigs }) => {
const { api } = cognigy;
const { recipient, message, storeLocation, inputKey, contextKey, stopOnError } = config;
if (!recipient) {
throw new errors_1.InvalidArgumentError("A Recipient has to be specified");
}
if (!message) {
throw new errors_1.InvalidArgumentError("A Message has to be specified");
}
if (storeLocation === "context" && !contextKey) {
throw new errors_1.InvalidArgumentError("A context key has to be specified");
}
if (storeLocation === "input" && !inputKey) {
throw new errors_1.InvalidArgumentError("An input key has to be specified");
}
try {
const result = await api.emailNotification({ cognigy, config, nodeId, nodeType, organisationId, projectId, childConfigs });
switch (storeLocation) {
case "context":
api.deleteContext(contextKey);
api.addToContext(contextKey, { result }, "simple");
break;
case "input":
api.addToInput(inputKey, { result });
break;
}
}
catch (err) {
if (stopOnError || err.message.includes(exports.EMAIL_NOTIFICATION_ERROR)) {
throw err;
}
const resultObject = {
error: err.message
};
switch (storeLocation) {
case "context":
api.addToContext(contextKey, resultObject, "simple");
break;
case "input":
api.addToInput(inputKey, resultObject);
break;
}
}
}
});
//# sourceMappingURL=emailNotification.js.map