74 linhas
2,9 KiB
JavaScript
74 linhas
2,9 KiB
JavaScript
'use strict';
|
|
|
|
const { api, compact, toList } = require('../lib/http');
|
|
|
|
const perform = (z, bundle) => {
|
|
const i = bundle.inputData;
|
|
if (!i.html && !i.text && !i.template_id) {
|
|
throw new z.errors.Error('Give the email content in HTML, in plain text or as a template.', 'missing_content', 400);
|
|
}
|
|
return api(z, {
|
|
method: 'POST',
|
|
path: '/v1/email/messages',
|
|
idempotent: true,
|
|
idempotencyKey: i.idempotency_key,
|
|
body: compact({
|
|
from: i.from,
|
|
from_name: i.from_name,
|
|
to: toList(i.to),
|
|
cc: toList(i.cc),
|
|
bcc: toList(i.bcc),
|
|
reply_to: toList(i.reply_to),
|
|
subject: i.subject,
|
|
html: i.html,
|
|
text: i.text,
|
|
template_id: i.template_id ? parseInt(i.template_id, 10) : undefined,
|
|
variables: i.variables,
|
|
send_at: i.send_at,
|
|
}),
|
|
});
|
|
};
|
|
|
|
module.exports = {
|
|
key: 'send_email',
|
|
noun: 'Email',
|
|
display: {
|
|
label: 'Send Email',
|
|
description: 'Sends a transactional email through E-mail Center from a verified domain.',
|
|
},
|
|
operation: {
|
|
inputFields: [
|
|
{ key: 'from', label: 'From', required: true, helpText: 'An address at a verified domain, such as notifications@example.co.ao.' },
|
|
{ key: 'from_name', label: 'From Name', required: false },
|
|
{ key: 'to', label: 'To', required: true, list: true, helpText: 'Up to 50 recipients in To, Cc and Bcc together. Each one uses one credit.' },
|
|
{ key: 'cc', label: 'Cc', required: false, list: true },
|
|
{ key: 'bcc', label: 'Bcc', required: false, list: true },
|
|
{ key: 'reply_to', label: 'Reply To', required: false, list: true },
|
|
{ key: 'subject', label: 'Subject', required: false, helpText: 'Can use {{name}} variables.' },
|
|
{ key: 'html', label: 'HTML Body', required: false, type: 'text' },
|
|
{ key: 'text', label: 'Plain Text Body', required: false, type: 'text' },
|
|
{ key: 'template_id', label: 'Template ID', required: false, type: 'integer', helpText: 'A template of your account. Empty subject and body come from it.' },
|
|
{ key: 'variables', label: 'Variables', required: false, dict: true, helpText: 'Values for {{name}} placeholders.' },
|
|
{ key: 'send_at', label: 'Send At', required: false, type: 'datetime', helpText: 'Optional, up to 30 days ahead.' },
|
|
{ key: 'idempotency_key', label: 'Idempotency Key', required: false, helpText: 'Optional. A unique value so the same email is never sent twice within 24 hours.' },
|
|
],
|
|
perform,
|
|
sample: {
|
|
id: '9003',
|
|
status: 'sent',
|
|
simulated: false,
|
|
from: 'notifications@example.co.ao',
|
|
to: ['joao.fernandes@example.co.ao'],
|
|
subject: 'Your order is ready',
|
|
recipients: 1,
|
|
credits: 1,
|
|
created_at: '2026-11-27T15:17:29+02:00',
|
|
},
|
|
outputFields: [
|
|
{ key: 'id', label: 'Email ID' },
|
|
{ key: 'status', label: 'Status' },
|
|
{ key: 'recipients', label: 'Recipients', type: 'number' },
|
|
{ key: 'credits', label: 'Credits', type: 'number' },
|
|
],
|
|
},
|
|
};
|