@devops-optimove/optigration-sdk-js

1.0.17 • Public • Published

Optimove Engagement sdk

How to use:

  1. Get a webhook from optimove
  2. Use the webhook values you got and create an instance of the engagement SDK
  3. You can use one of the public methods the SDK has
    • getMetaData() - Returns a json of the campaign's metadata
    • getCustomersByBatchID(batchID) - Returns a stream of customers for the batchID file number you passed
Error Message Explanation
metadata is empty or does not exist. Metadata issues. Please, check your settings object and "metadataFilePath" field, especially.
Couldn't receive a metadata. Something wrong with creating metadata object.
batchID: ${batchID} is not valid. Wrong BatchIDNumber was provided for getCustomersByBatchID function.
sdk settings are manadatory. No SDK settings object or it has no keys.
tenantID is manadatory. No tenantID field in the setting object
bucketName is mandatory. No bucketName field in the setting object
customersFolderPath is mandatory. No customersFolderPath field in the setting object
metadataFilePath is mandatory. No metadataFilePath field in the setting object
decryptionKey is mandatory. No decryptionKey field in the setting object
_getStorage error - error details. Google Cloud issue. Contact Optimove if the issue repeats.
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();

Readme

Keywords

none

Package Sidebar

Install

npm i @devops-optimove/optigration-sdk-js

Weekly Downloads

0

Version

1.0.17

License

MIT

Unpacked Size

14 kB

Total Files

7

Last publish

Collaborators

  • it_support
  • optimove-devops