diff --git a/src/cdk/v2/destinations/clicksend/procWorkflow.yaml b/src/cdk/v2/destinations/clicksend/procWorkflow.yaml index 0c368e749f..6a8646d812 100644 --- a/src/cdk/v2/destinations/clicksend/procWorkflow.yaml +++ b/src/cdk/v2/destinations/clicksend/procWorkflow.yaml @@ -60,7 +60,7 @@ steps: name : String(.properties.name), body : String(.properties.body), from : $.getDestinationExternalID(^.message,'CLICKSEND_SENDER_EMAIL') || ^.destination.Config.defaultSenderEmail, - schedule : .properties.schedule, + schedule : $.deduceSchedule(.properties.schedule,{{{{$.getGenericPaths("timestamp")}}}}, ^.destination.Config) }); console.log(JSON.stringify(.destination.Config)); console.log(.destination.Config.defaultSenderEmail); @@ -78,7 +78,7 @@ steps: to: {{{{$.getGenericPaths("phone")}}}}, body: .properties.body, source: .properties.source || ^.destination.Config.defaultSource, - schedule: .properties.schedule, + schedule: $.deduceSchedule(.properties.schedule, ^.destination.Config), custom_string: .properties.custom_string, country: {{{{$.getGenericPaths("country")}}}}, from_email: .properties.from_email diff --git a/src/cdk/v2/destinations/clicksend/utils.js b/src/cdk/v2/destinations/clicksend/utils.js index 0cf9a25e6e..efd75988fd 100644 --- a/src/cdk/v2/destinations/clicksend/utils.js +++ b/src/cdk/v2/destinations/clicksend/utils.js @@ -40,6 +40,27 @@ const validateTrackSMSCampaignPayload = (payload) => { } }; +const deduceSchedule = (eventLevelSchedule, timestamp, destConfig) => { + if (isDefinedAndNotNullAndNotEmpty(eventLevelSchedule) && !Number.isNaN(destConfig)) { + return eventLevelSchedule; + } + const { defaultCampaignScheduleUnit, defaultCampaignSchedule } = destConfig; + // Parse the input timestamp into a Date object + const date = new Date(timestamp); + + // Check the delta unit and add the appropriate amount of time + if (defaultCampaignScheduleUnit === 'day') { + date.setDate(date.getDate() + defaultCampaignSchedule); + } else if (defaultCampaignScheduleUnit === 'minute') { + date.setMinutes(date.getMinutes() + defaultCampaignSchedule); + } else { + throw new Error("Invalid delta unit. Use 'day' or 'minute'."); + } + + // Return the future date as a UNIX timestamp in seconds + return Math.floor(date.getTime() / 1000); +}; + const mergeMetadata = (batch) => { const metadata = []; batch.forEach((event) => { @@ -144,4 +165,5 @@ module.exports = { getEndIdentifyPoint, validateIdentifyPayload, validateTrackSMSCampaignPayload, + deduceSchedule, };