@cognigy/rest-api-client
Version:
Cognigy REST-Client
528 lines (527 loc) • 19.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SEND_EMAIL = void 0;
/* Custom modules */
const createNodeDescriptor_1 = require("../../../createNodeDescriptor");
const errors_1 = require("../../../../errors");
const smtpConnection_1 = require("./smtpConnection");
const serviceConnection_1 = require("./serviceConnection");
const oAuth2Connection_1 = require("./oAuth2Connection");
exports.SEND_EMAIL = (0, createNodeDescriptor_1.createNodeDescriptor)({
type: "sendEmail",
defaultLabel: "Send SMTP Email",
summary: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__SUMMARY",
fields: [
{
key: "smtpType",
type: "select",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__SMTP_TYPE__LABEL",
description: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__SMTP_TYPE__DESCRIPTION",
params: {
options: [
{ label: "126", value: "126" },
{ label: "163", value: "163" },
{ label: "1und1", value: "1und1" },
{ label: "AOL", value: "AOL" },
{ label: "DebugMail", value: "DebugMail" },
{ label: "DynectEmail", value: "DynectEmail" },
{ label: "FastMail", value: "FastMail" },
{ label: "GandiMail", value: "GandiMail" },
{ label: "Gmail", value: "Gmail" },
{ label: "Godaddy", value: "Godaddy" },
{ label: "GodaddyAsia", value: "GodaddyAsia" },
{ label: "GodaddyEurope", value: "GodaddyEurope" },
{ label: "hot.ee", value: "hot.ee" },
{ label: "Hotmail", value: "Hotmail" },
{ label: "iCloud", value: "iCloud" },
{ label: "mail.ee", value: "mail.ee" },
{ label: "Mail.ru", value: "Mail.ru" },
{ label: "Maildev", value: "Maildev" },
{ label: "Mailgun", value: "Mailgun" },
{ label: "Mailjet", value: "Mailjet" },
{ label: "Mailosaur", value: "Mailosaur" },
{ label: "Mandrill", value: "Mandrill" },
{ label: "Naver", value: "Naver" },
{ label: "OpenMailBox", value: "OpenMailBox" },
{ label: "Office365", value: "Outlook365" },
{ label: "Postmark", value: "Postmark" },
{ label: "QQ", value: "QQ" },
{ label: "QQex", value: "QQex" },
{ label: "SendCloud", value: "SendCloud" },
{ label: "SendGrid", value: "SendGrid" },
{ label: "SendinBlue", value: "SendinBlue" },
{ label: "SendPulse", value: "SendPulse" },
{ label: "SES", value: "SES" },
{ label: "SES-US-EAST-1", value: "SES-US-EAST-1" },
{ label: "SES-US-WEST-2", value: "SES-US-WEST-2" },
{ label: "SES-EU-WEST-1", value: "SES-EU-WEST-1" },
{ label: "Sparkpost", value: "Sparkpost" },
{ label: "Yahoo", value: "Yahoo" },
{ label: "Yandex", value: "Yandex" },
{ label: "Zoho", value: "Zoho" },
{ label: "qiye.aliyun", value: "qiye.aliyun" },
{ label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__SMTP_TYPE__OTHER_SMTP__LABEL", value: "otherSmtp" },
]
}
},
{
key: "connection",
type: "connection",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__CONNECTION__LABEL",
params: {
required: false,
connectionType: smtpConnection_1.SMTP_CONNECTION.type
},
condition: {
or: [
{
"key": "smtpType",
"value": "otherSmtp"
},
{
"key": "smtpType",
"value": ""
},
{
"key": "smtpType",
"value": null
}
]
}
},
{
key: "authType",
type: "select",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__AUTH_TYPE__LABEL",
description: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__AUTH_TYPE__DESCRIPTION",
defaultValue: "basic",
params: {
required: true,
options: [
{
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__AUTH_TYPE__BASIC__LABEL",
value: "basic"
},
{
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__AUTH_TYPE__OAUTH2__LABEL",
value: "oauth2"
},
]
}
},
{
key: "serviceConnection",
type: "connection",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__SERVICE_CONNECTION__LABEL",
params: {
connectionType: serviceConnection_1.EMAIL_SERVICE_CONNECTION.type
},
condition: {
key: "authType",
value: "basic"
}
},
{
key: "oAuth2Connection",
type: "connection",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__OAUTH2_CONNECTION__LABEL",
params: {
connectionType: oAuth2Connection_1.EMAIL_SERVICE_OAUTH2_CONNECTION.type
},
condition: {
key: "authType",
value: "oauth2"
}
},
{
key: "serviceWarning",
type: "description",
label: " ",
params: {
text: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__SERVICE_WARNING__TEXT"
},
condition: {
"key": "smtpType",
"value": "otherSmtp",
"negate": true
}
},
{
key: "googleWarning",
type: "description",
label: " ",
params: {
text: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__GOOGLE_WARNING__TEXT"
},
condition: {
"key": "smtpType",
"value": "Gmail"
}
},
{
key: "recipient",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__RECIPIENT__LABEL",
description: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__RECIPIENT__DESCRIPTION",
params: {
required: true
}
},
{
key: "from",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__FROM__LABEL",
description: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__FROM__DESCRIPTION"
},
{
key: "subject",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__SUBJECT__LABEL",
params: {
required: true
}
},
{
key: "message",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__MESSAGE__LABEL",
defaultValue: "\n",
params: {
multiline: true,
richText: true
}
},
{
key: "cc",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__CC__LABEL"
},
{
key: "bcc",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__BCC__LABEL"
},
{
key: "replyTo",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__REPLY_TO__LABEL"
},
{
key: "defineText",
type: "toggle",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__DEFINE_TEXT__LABEL",
description: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__DEFINE_TEXT__DESCRIPTION",
defaultValue: false
},
{
key: "text",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__TEXT__LABEL",
condition: {
key: "defineText",
value: true
},
params: {
multiline: true
}
},
{
key: "async",
type: "toggle",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__ASYNC__LABEL",
description: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__ASYNC__DESCRIPTION",
defaultValue: false
},
{
key: "attachmentType",
type: "select",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__ATTACHMENT_TYPE__LABEL",
defaultValue: "none",
params: {
options: [
{ label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__ATTACHMENT_TYPE__NONE__LABEL", value: "none" },
{ label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__ATTACHMENT_TYPE__TEXT__LABEL", value: "text" },
{ label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__ATTACHMENT_TYPE__URL__LABEL", value: "url" },
{ label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__ATTACHMENT_TYPE__BASE64__LABEL", value: "base64" },
{ label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__ATTACHMENT_TYPE__CUSTOM__LABEL", value: "custom" },
{ label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__ATTACHMENT_TYPE__ROW__LABEL", value: "raw" },
]
}
},
{
key: "priority",
type: "select",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__PRIORITY__LABEL",
defaultValue: "normal",
params: {
options: [
{ label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__PRIORITY__HIGH__LABEL", value: "high" },
{ label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__PRIORITY__NORMAL__LABEL", value: "normal" },
{ label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__PRIORITY__LOW__LABEL", value: "low" }
]
}
},
{
key: "attachmentFilename",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__ATTACHMENT_FILENAME__LABEL",
defaultValue: "file.txt",
description: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__ATTACHMENT_FILENAME__DESCRIPTION",
condition: {
and: [
{
key: "attachmentType",
value: "none",
negate: true
},
{
key: "attachmentType",
value: "raw",
negate: true
},
{
key: "attachmentType",
value: null,
negate: true
}
]
}
},
{
key: "attachmentContentType",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__ATTACHMENT_CONTENT_TYPE__LABEL",
defaultValue: "text/plain",
condition: {
key: "attachmentType",
value: "custom"
}
},
{
key: "attachmentEncodingType",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__ATTACHMENT_ECONDING_TYPE__LABEL",
defaultValue: "base64",
condition: {
key: "attachmentType",
value: "base64"
}
},
{
key: "attachmentContent",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__ATTACHMENT_CONTENT__LABEL",
params: {
multiline: true
},
condition: {
or: [
{
"key": "attachmentType",
"value": "text"
},
{
"key": "attachmentType",
"value": "base64"
},
{
"key": "attachmentType",
"value": "custom"
},
]
}
},
{
key: "attachmentURL",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__ATTACHMENT_URL__LABEL",
description: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__ATTACHMENT_URL__DESCRIPTION",
condition: {
key: "attachmentType",
value: "url"
}
},
{
key: "attachmentRaw",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__ATTACHMENT_ROW__LABEL",
defaultValue: `Content-Type: text/plain
Content-Disposition: attachment;
Hello world!`,
params: {
multiline: true
},
condition: {
key: "attachmentType",
value: "raw"
}
},
{
key: "storeLocation",
type: "select",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__STORE_LOCATION__LABEL",
description: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__STORE_LOCATION__DESCRIPTION",
params: {
options: [
{
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__STORE_LOCATION__NONE__LABEL",
value: "none"
},
{
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__STORE_LOCATION__INPUT__LABEL",
value: "input"
},
{
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__STORE_LOCATION__CONTEXT__LABEL",
value: "context"
}
],
},
defaultValue: "none"
},
{
key: "inputKey",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__INPUT_KEY__LABEL",
defaultValue: "email",
condition: {
key: "storeLocation",
value: "input",
}
},
{
key: "contextKey",
type: "cognigyText",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__CONTEXT_KEY__LABEL",
defaultValue: "email",
condition: {
key: "storeLocation",
value: "context",
}
},
{
key: "stopOnError",
type: "toggle",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__STOP_ON_ERROR__LABEL",
defaultValue: false
}
],
sections: [
{
"key": "advanced",
"label": "UI__NODE_EDITOR__SMTP__SEND_EMAIL__ADVANCED__LABEL",
"defaultCollapsed": true,
"fields": [
"from",
"cc",
"bcc",
"replyTo",
"defineText",
"text",
"priority",
"async"
]
},
{
key: "auth",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__AUTH__LABEL",
defaultCollapsed: false,
fields: [
"authType",
"serviceConnection",
"oAuth2Connection",
]
},
{
"key": "attachments",
"label": "UI__NODE_EDITOR__SMTP__SEND_EMAIL__ATTACHMENT__LABEL",
"defaultCollapsed": true,
"fields": [
"attachmentType",
"attachmentFilename",
"attachmentContentType",
"attachmentEncodingType",
"attachmentContent",
"attachmentURL",
"attachmentRaw"
]
},
{
key: "resultStorage",
label: "UI__NODE_EDITOR__SMTP__SEND_EMAIL__RESULT_STORAGE__LABEL",
defaultCollapsed: true,
fields: [
"storeLocation",
"inputKey",
"contextKey",
"stopOnError"
]
},
],
form: [
{ key: "smtpType", type: "field" },
{ key: "serviceWarning", type: "field" },
{ key: "googleWarning", type: "field" },
{ key: "connection", type: "field" },
{ key: "recipient", type: "field" },
{ key: "subject", type: "field" },
{ key: "message", type: "field" },
{ key: "auth", type: "section" },
{ key: "attachments", type: "section" },
{ 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 { connection, serviceConnection, oAuth2Connection, recipient, message, storeLocation, inputKey, contextKey, stopOnError } = config;
if (!connection && !serviceConnection && !oAuth2Connection) {
throw new errors_1.InvalidArgumentError("A Connection has to be selected");
}
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.sendEmail({ 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) {
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=sendEmail.js.map