Work in progress on tag language
Fix - message sent to a list not associated with a campaign couldn't be shown in archive - to know which message to show even if the list is not at the campaign, we store test messages in table test_messages
This commit is contained in:
parent
00e328a914
commit
4113cb8476
17 changed files with 312 additions and 172 deletions
|
@ -888,7 +888,7 @@ async function _changeStatus(context, campaignId, permittedCurrentStates, newSta
|
|||
|
||||
|
||||
async function start(context, campaignId, startAt) {
|
||||
await _changeStatus(context, campaignId, [CampaignStatus.IDLE, CampaignStatus.PAUSED, CampaignStatus.FINISHED], CampaignStatus.SCHEDULED, 'Cannot start campaign until it is in IDLE, PAUSED, or FINISHED state', startAt);
|
||||
await _changeStatus(context, campaignId, [CampaignStatus.IDLE, CampaignStatus.SCHEDULED, CampaignStatus.PAUSED, CampaignStatus.FINISHED], CampaignStatus.SCHEDULED, 'Cannot start campaign until it is in IDLE, PAUSED, or FINISHED state', startAt);
|
||||
}
|
||||
|
||||
async function stop(context, campaignId) {
|
||||
|
@ -990,8 +990,9 @@ async function testSend(context, data) {
|
|||
const messageData = {
|
||||
campaignId: campaignId,
|
||||
subject: data.subjectPrepend + campaign.subject + data.subjectAppend,
|
||||
html: data.html, // The html and text may be undefined
|
||||
html: data.html, // The html, text and tagLanguage may be undefined
|
||||
text: data.text,
|
||||
tagLanguage: data.tagLanguage,
|
||||
attachments: []
|
||||
};
|
||||
|
||||
|
@ -1048,7 +1049,8 @@ async function testSend(context, data) {
|
|||
const messageData = {
|
||||
subject: 'Test',
|
||||
html: data.html,
|
||||
text: data.text
|
||||
text: data.text,
|
||||
tagLanguage: data.tagLanguage
|
||||
};
|
||||
|
||||
const list = await lists.getByCidTx(tx, context, data.listCid);
|
||||
|
|
|
@ -140,10 +140,10 @@ async function addOrGet(campaignId, url) {
|
|||
}
|
||||
}
|
||||
|
||||
async function updateLinks(campaign, list, subscription, mergeTags, message) {
|
||||
if ((campaign.open_tracking_disabled && campaign.click_tracking_disabled) || !message || !message.trim()) {
|
||||
async function updateLinks(source, tagLanguage, mergeTags, campaign, list, subscription) {
|
||||
if ((campaign.open_tracking_disabled && campaign.click_tracking_disabled) || !source || !source.trim()) {
|
||||
// tracking is disabled, do not modify the message
|
||||
return message;
|
||||
return source;
|
||||
}
|
||||
|
||||
// insert tracking image
|
||||
|
@ -151,12 +151,12 @@ async function updateLinks(campaign, list, subscription, mergeTags, message) {
|
|||
let inserted = false;
|
||||
const imgUrl = getPublicUrl(`/links/${campaign.cid}/${list.cid}/${subscription.cid}`);
|
||||
const img = '<img src="' + imgUrl + '" width="1" height="1" alt="mt">';
|
||||
message = message.replace(/<\/body\b/i, match => {
|
||||
source = source.replace(/<\/body\b/i, match => {
|
||||
inserted = true;
|
||||
return img + match;
|
||||
});
|
||||
if (!inserted) {
|
||||
message = message + img;
|
||||
source = source + img;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ async function updateLinks(campaign, list, subscription, mergeTags, message) {
|
|||
|
||||
const urlsToBeReplaced = new Set();
|
||||
|
||||
message.replace(re, (match, prefix, encodedUrl) => {
|
||||
source.replace(re, (match, prefix, encodedUrl) => {
|
||||
const url = he.decode(encodedUrl, {isAttributeValue: true});
|
||||
urlsToBeReplaced.add(url);
|
||||
});
|
||||
|
@ -173,19 +173,19 @@ async function updateLinks(campaign, list, subscription, mergeTags, message) {
|
|||
const urls = new Map(); // url -> {id, cid} (as returned by add)
|
||||
for (const url of urlsToBeReplaced) {
|
||||
// url might include variables, need to rewrite those just as we do with message content
|
||||
const expanedUrl = tools.formatMessage(campaign, list, subscription, mergeTags, url);
|
||||
const expanedUrl = tools.formatCampaignTemplate(url, tagLanguage, mergeTags, false, campaign, list, subscription);
|
||||
const link = await addOrGet(campaign.id, expanedUrl);
|
||||
urls.set(url, link);
|
||||
}
|
||||
|
||||
message = message.replace(re, (match, prefix, encodedUrl) => {
|
||||
source = source.replace(re, (match, prefix, encodedUrl) => {
|
||||
const url = he.decode(encodedUrl, {isAttributeValue: true});
|
||||
const link = urls.get(url);
|
||||
return prefix + (link ? getPublicUrl(`/links/${campaign.cid}/${list.cid}/${subscription.cid}/${link.cid}`) : url);
|
||||
});
|
||||
}
|
||||
|
||||
return message;
|
||||
return source;
|
||||
}
|
||||
|
||||
module.exports.LinkId = LinkId;
|
||||
|
|
|
@ -158,6 +158,7 @@ const MAX_EMAIL_COUNT = 100;
|
|||
async function sendAsTransactionalEmail(context, templateId, sendConfigurationId, emails, subject, mergeTags) {
|
||||
// TODO - Update this to use MessageSender.queueMessageTx (with renderedHtml and renderedText)
|
||||
|
||||
/*
|
||||
if (emails.length > MAX_EMAIL_COUNT) {
|
||||
throw new Error(`Cannot send more than ${MAX_EMAIL_COUNT} emails at once`);
|
||||
}
|
||||
|
@ -182,6 +183,7 @@ async function sendAsTransactionalEmail(context, templateId, sendConfigurationId
|
|||
};
|
||||
|
||||
const html = tools.formatTemplate(
|
||||
TODO - tag langauge
|
||||
template.html,
|
||||
null,
|
||||
variables,
|
||||
|
@ -190,6 +192,7 @@ async function sendAsTransactionalEmail(context, templateId, sendConfigurationId
|
|||
|
||||
const text = (template.text || '').trim()
|
||||
? tools.formatTemplate(
|
||||
TODO - tag langauge
|
||||
template.text,
|
||||
null,
|
||||
variables,
|
||||
|
@ -210,6 +213,7 @@ async function sendAsTransactionalEmail(context, templateId, sendConfigurationId
|
|||
);
|
||||
}
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue