From 409b1708916c9da5ce21a715c9b58c8b5e20e397 Mon Sep 17 00:00:00 2001 From: Matt Lott Date: Tue, 14 Jun 2016 16:44:51 -0700 Subject: [PATCH] Update inbound lead assignment splits --- scripts/updateCloseIoLeads.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/scripts/updateCloseIoLeads.js b/scripts/updateCloseIoLeads.js index 8d1edce15..7753fa320 100644 --- a/scripts/updateCloseIoLeads.js +++ b/scripts/updateCloseIoLeads.js @@ -57,7 +57,20 @@ const emailDelayMinutes = 27; const scriptStartTime = new Date(); const closeIoApiKey = process.argv[2]; // Automatic mails sent as API owners, first key assumed to be primary and gets 50% of the leads -const closeIoMailApiKeys = [process.argv[3], process.argv[3], process.argv[4], process.argv[5]]; +const closeIoMailApiKeys = [ + { + apiKey: process.argv[3], + weight: .7 + }, + { + apiKey: process.argv[4], + weight: .25 + }, + { + apiKey: process.argv[5], + weight: .05 + }, +]; const closeIoEuMailApiKey = process.argv[6]; const intercomAppIdApiKey = process.argv[7]; const intercomAppId = intercomAppIdApiKey.split(':')[0]; @@ -238,7 +251,14 @@ function isUSSchoolStatus(status) { function getEmailApiKey(leadStatus) { if (leadStatus === defaultEuLeadStatus) return closeIoEuMailApiKey; if (closeIoMailApiKeys.length < 0) return; - return closeIoMailApiKeys[Math.floor(Math.random() * closeIoMailApiKeys.length)]; + const weightedList = []; + for (let closeIoMailApiKey of closeIoMailApiKeys) { + const multiples = closeIoMailApiKey.weight * 100; + for (let i = 0; i < multiples; i++) { + weightedList.push(closeIoMailApiKey.apiKey); + } + } + return weightedList[Math.floor(Math.random() * weightedList.length)]; } function getRandomEmailTemplate(templates) {