to install run: npm i @devops-optimove/optigration-sdk-js
const EngagerSDK = require('https://www.npmjs.com/package/@devops-optimove/optigration-sdk-js')
// Example of a webhook payload:
{
EventTypeID: 14,
TimeStamp: "2022-07-19 08:54",
CampaignID: 38085,
EngagementID: 144523,
TenantID: 28209,
BucketName: "optigration-external-eu",
CustomersFolderPath: "2022-07-19 09 00 webhhook-name channel-id engagement-id/customers",
MetadataFilePath: "2022-07-19 09 00 webhhook-name channel-id engagement-id/metadata_engagement-id",
DecryptionKey: "your-decryption-key",
ChannelID: 1
}
// Example of getMetaData response
{
actionID: 1712,
actionName: 'demo-1',
campaignID: 38456,
campaignPlanID: 10828,
channelID: 1,
channelName: 'the-campaign-channel',
engagementID: 144950,
numberOfCustomers: 2403,
numberOfFiles: 5,
planDetailChannelID: 86923,
promotions: 'promo1,promo2',
scheduledTime: '2023-10-15T09:00:00Z',
targetGroupName: 'the-tg-name',
templateID: 4,
templateName: 'the-template-name',
tenantID: 1099,
bucketName: 'optigration-external-eu',
customersFolderPath: '2022-07-19 09 00 webhhook-name channel-id engagement-id/customers',
metadataFilePath: '2022-07-19 09 00 webhhook-name channel-id engagement-id/metadata_engagement-id',
duration: 1,
internalAccountID: 'brand-id',
accountName: 'my-account',
identifier: 'webhook-identifier',
tags: 'tag1,tag2'
}
// Use the values you got from the webhook in your settings object
const settings = {
campaignID: webhook.CampaignID,
engagementID: webhook.EngagementID,
tenantID: webhook.TenantID,
bucketName: webhook.BucketName,
customersFolderPath: webhook.CustomersFolderPath,
metadataFilePath: webhook.MetadataFilePath,
decryptionKey: webhook.DecryptionKey
}
const engagerSDK = new EngagerSDK(settings);
const getMetaData = async () => {
try {
const metaData = await engagerSDK.getMetaData();
return metaData;
}
catch (err) {
console.log(err);
}
}
const getCustomersByBatchID = (batchID) => {
try {
const customersStream = engagerSDK.getCustomersByBatchID(batchID);
return customersStream;
}
catch (err) {
console.log(err);
}
}
async function run() {
const campaignMetadata = await getMetaData();
console.log(`Campaign metadata ${JSON.stringify(campaignMetadata)}`)
for (let index = 1; index < campaignMetadata.numberOfFiles; index++) {
const customersStream = getCustomersByBatchID(index);
readFile(customersStream, index);
}
}
const readFile = (customersStream, index) => {
console.log(`Reading file #${index}`);
customersStream.on('data', (customerObject) => {
console.log(`Record for file #${index}`)
console.log(customerObject);
})
customersStream.on('end', () => {
console.log(`Finished reading customers file stream #${index}`);
})
customersStream.on('error', (err) => {
console.error(err);
})
}
run();