cancel
Showing results for 
Search instead for 
Did you mean: 

Automatic sending of DOI mails (reminder mails) after x days from the Backend. Maximum 3 times.

santhireswaran
Newcomer
0 Kudos
294

Is there a standard function in CDC for the mentioned use case or even a simple work around.

Regards
SuN

View Entire Topic
christoph_probst
Active Participant

To do the resent of the DOI mail we created our own dataflow in CDC (beware that you have a limit on how many flows you can create)

The dataflow was at the end very easy:

read account data -> evaluate data with a script -> trigger resend api endpoint

Here are the steps, be aware the the script is base64 encoded and does not cover the 3 times logic but you can adapt it easily.

Flow steps:

{
"steps": [
{
"id": "gigya.account",
"type": "datasource.read.gigya.account",
"params": {
"select": "email,subscriptions",
"from": "emailAccounts",
"deltaField": "lastUpdatedTimestamp",
"batchSize": 300,
"maxConcurrency": 1,
"keepFieldNamesWithDotAsIs": false
},
"next": [
"record.evaluate"
]
},
{
"id": "gigya.generic",
"type": "datasource.write.gigya.generic",
"params": {
"apiMethod": "accounts.resendDOIConfirmationEmail",
"maxConnections": 10,
"apiParams": [
{
"sourceField": "email",
"paramName": "email",
"value": ""
},
{
"sourceField": "subscriptionId",
"paramName": "subscriptionId",
"value": ""
}
],
"addResponse": false,
"apiKey": "...",
"userKey": "...",
"secret": "..."
},
"next": []
},
{
"id": "record.evaluate",
"type": "record.evaluate",
"params": {
"script": "ZnVuY3Rpb24gcmVzZW5kRG91YmVsT3B0aW5NYWlsKHN1YnNjcmlwdGlvbikgew0KICAgIHZhciBlbWFpbCA9IHN1YnNjcmlwdGlvbi5lbWFpbDsNCiAgICB2YXIgZG9pID0gZW1haWwuZG91YmxlT3B0SW47DQogICAgaWYgKGVtYWlsICYmIGVtYWlsLmlzU3Vic2NyaWJlZCkgew0KICAgICAgICBpZiAoZG9pICYmIGRvaS5lbWFpbFNlbnRUaW1lICYmICJQZW5kaW5nIiA9PSBkb2kuc3RhdHVzKSB7DQogICAgICAgICAgICB2YXIgbGFzdFVwZGF0ZWQgPSBEYXRlLnBhcnNlKGVtYWlsLmxhc3RVcGRhdGVkU3Vic2NyaXB0aW9uU3RhdGUpOw0KICAgICAgICAgICAgdmFyIGVtYWlsU2VudCA9IERhdGUucGFyc2UoZG9pLmVtYWlsU2VudFRpbWUpOw0KICAgICAgICAgICAgcmV0dXJuIGVtYWlsU2VudCA8IGxhc3RVcGRhdGVkOw0KICAgICAgICB9DQogICAgfQ0KICAgIHJldHVybiBmYWxzZTsNCn0NCg0KZnVuY3Rpb24gcHJvY2VzcyhyZWNvcmQsIGN0eCwgbG9nZ2VyLCBuZXh0KSB7DQogICAgdmFyIGVtYWlsID0gcmVjb3JkLmVtYWlsOw0KICAgIHZhciBzdWJzY3JpcHRpb25zID0gcmVjb3JkLnN1YnNjcmlwdGlvbnM7DQogICAgZm9yICh2YXIgc3Vic2NyaXB0aW9uS2V5IGluIHN1YnNjcmlwdGlvbnMpIHsNCiAgICAgICAgdmFyIHN1YnNjcmlwdGlvbiA9IHN1YnNjcmlwdGlvbnNbc3Vic2NyaXB0aW9uS2V5XTsNCiAgICAgICAgaWYgKHJlc2VuZERvdWJlbE9wdGluTWFpbChzdWJzY3JpcHRpb24pKSB7DQogICAgICAgICAgICBsb2dnZXIuaW5mbygicmVjb3JkLmV2YWx1YXRlIiwgIlRyaWdnZXIgcmVzZW5kaW5nIGRvdWJsZSBvcHRpbiBtYWlsIGZvciAiICsgc3Vic2NyaXB0aW9uS2V5ICsgIiB0byAiICsgZW1haWwpDQogICAgICAgICAgICB2YXIgbmV3RGF0YSA9IHsNCiAgICAgICAgICAgICAgICAic3Vic2NyaXB0aW9uSWQiOiBzdWJzY3JpcHRpb25LZXksDQogICAgICAgICAgICAgICAgImVtYWlsIjogZW1haWwNCiAgICAgICAgICAgIH07DQogICAgICAgICAgICBuZXh0LmFjY2VwdChuZXdEYXRhLCByZWNvcmQpOw0KICAgICAgICB9ICAgDQogICAgfQ0KfQ==",
"notifyLastRecord": false
},
"next": [
"gigya.generic"
]
}
]
}

Encoded script

function resendDoubelOptinMail(subscription) {
var email = subscription.email;
var doi = email.doubleOptIn;
if (email && email.isSubscribed) {
if (doi && doi.emailSentTime && "Pending" == doi.status) {
var lastUpdated = Date.parse(email.lastUpdatedSubscriptionState);
var emailSent = Date.parse(doi.emailSentTime);
return emailSent < lastUpdated;
}
}
return false;
}

function process(record, ctx, logger, next) {
var email = record.email;
var subscriptions = record.subscriptions;
for (var subscriptionKey in subscriptions) {
var subscription = subscriptions[subscriptionKey];
if (resendDoubelOptinMail(subscription)) {
logger.info("record.evaluate", "Trigger resending double optin mail for " + subscriptionKey + " to " + email)
var newData = {
"subscriptionId": subscriptionKey,
"email": email
};
next.accept(newData, record);
}
}
}