18 var _0xc04a=['contactId','contactTypeId','orderBy','voice_queues_has_cm_blacklists','VoiceQueueId','campaigns_has_cm_blacklists','CampaignId','finish','affectedRows','contact:import:','unlink','exit','complete','argv','existsSync','file\x20doesn\x27t\x20exists','binding\x20doesn\x27t\x20exists','firstName\x20is\x20mandatory','ListId\x20is\x20mandatory','body\x20id\x20mandatory','SIGINT','uncaughtException','path','util','moment','squel','ioredis','../../../mysqldb','../../../config/environment/shared','../../../config/logger','import','redis','localhost','socket.io-emitter','YYYY-MM-DD\x20HH:mm:ss','format','test','select','field','phone','from','join','.id\x20=\x20','where','CmContact','findAll','length','all','AdditionalPhones','split','push','then','isNil','filter','findOne','CmContactHasItem','update','updated','PHONE','inserted','cm_contacts.scheduledat','cm_contacts.id','cm_contacts.ListId','cm_contacts.createdAt','cm_contacts.updatedAt','cm_contacts.priority','cm_contacts.UserId','into','cm_hopper','fromQuery','scheduledat','ListId','createdAt','updatedAt','priority','UserId','recallme','fields','cm_contacts.ListId\x20=\x20','.CmListId','.CmListId\x20=\x20?','cm_contacts.createdAt\x20=\x20?','\x22onlyIfOpen\x22','cm_contacts.phone\x20NOT\x20IN\x20(?)','\x22always\x22','cm_contacts.phone','ContactId','cm_hopper_black','\x20=\x20','date_add(cm_contacts.scheduledat,interval\x20','.offset-cm_contacts.utcOffset\x20minute)','insert','cm_contacts','toString','ListId\x20=\x20?','cm_hopper.id','cm_contact_has_items.item','cm_contact_has_items.OrderBy','cm_contact_has_items.updatedAt','cm_hopper_additional_phones','OrderBy','cm_contacts.id\x20=\x20cm_hopper.ContactId','cm_contact_has_items','cm_contacts.id\x20=\x20cm_contact_has_items.CmContactId','cm_hopper.ListId\x20=\x20?','concat','keys',')\x20NOT\x20IN\x20?','deletedAt\x20IS\x20NULL','min_id','group','info','errors','message','query','catch','campaigns.id','campaigns.dialTimezone','campaigns','campaigns_has_cm_lists','campaigns.id\x20=\x20campaigns_has_cm_lists.CampaignId','campaigns_has_cm_lists.CmListId=','spread','error','voice_queues.id','voice_queues.dialTimezone','voice_queues','voice_queues_has_cm_lists','voice_queues.id\x20=\x20voice_queues_has_cm_lists.VoiceQueueId','voice_queues_has_cm_lists.CmListId=','dialTimezone','set','offset','sequelize','stringify','start','binding','clone','socket_timestamp','root','server/files/tmp','.csv','header','name','writeFileSync','parse','data','find','hasOwnProperty','trim','replace','isValid','scheduledat\x20wrong\x20format\x20(YYYY-MM-DD\x20HH:mm:ss)','isNaN','isNumber','includes','agent\x20not\x20exists','email\x20wrong\x20format','dateOfBirth','dateOfBirth\x20wrong\x20format\x20(YYYY-MM-DD)','timezones','utcOffset','firstName','itemTypeId','description','SystemRow','appendFileSync','rows','abort','SystemError','step','duplicates','cm_contacts_','CREATE\x20TABLE\x20','\x20LIKE\x20cm_contacts;','campaigns_','(id\x20int,dialTimezone\x20varchar(255),offset\x20int);','dialTimezone,utcOffset','LOAD\x20DATA\x20LOCAL\x20INFILE\x20\x27%s\x27\x20INTO\x20TABLE\x20%s\x20CHARACTER\x20SET\x20UTF8\x20FIELDS\x20TERMINATED\x20BY\x20\x27,\x27\x20ENCLOSED\x20BY\x20\x27\x22\x27\x20LINES\x20TERMINATED\x20BY\x20\x27\x0a\x27\x20IGNORE\x201\x20ROWS\x20(%s)\x20SET\x20id\x20=\x20NULL,\x20ListId\x20=\x20%s,\x20CompanyId\x20=\x20%s,\x20createdAt\x20=\x20\x27%s\x27,\x20updatedAt\x20=\x20\x27%s\x27','CompanyId',',\x20scheduledAt\x20=\x20NOW()','DROP\x20TABLE\x20','each'];(function(_0x4a52f9,_0x1515d4){var _0x2005ff=function(_0x38e8f2){while(--_0x38e8f2){_0x4a52f9['push'](_0x4a52f9['shift']());}};_0x2005ff(++_0x1515d4);}(_0xc04a,0x184));var _0xac04=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xc04a[_0x3dd15e];return _0x231fd0;};'use strict';var fs=require('fs');var path=require(_0xac04('0x0'));var _=require('lodash');var Papa=require('papaparse');var util=require(_0xac04('0x1'));var BPromise=require('bluebird');var moment=require(_0xac04('0x2'));var squel=require(_0xac04('0x3'));var Redis=require(_0xac04('0x4'));var db=require(_0xac04('0x5'))['db'];var config=require('../../../config/environment');var shared=require(_0xac04('0x6'));var logger=require(_0xac04('0x7'))(_0xac04('0x8'));config[_0xac04('0x9')]=_['defaults'](config[_0xac04('0x9')],{'host':_0xac04('0xa'),'port':0x18eb});var socket=require(_0xac04('0xb'))(new Redis(config[_0xac04('0x9')]));var stats={'finish':![],'errors':[],'rows':0x0,'affectedRows':0x0};var results=[];var promisesAdditionalPhones=[];var orderBy=0x0;var stopped=![];var NOW=moment()['format'](_0xac04('0xc'));var contactItemTypes=[];var phoneDescriptions=[];var hasAdditionalPhones=![];var tmp_voice_queues;var tmp_campaigns;var tzOffset=0x0;var hasTZ;var NOW=moment()[_0xac04('0xd')]('YYYY-MM-DD\x20HH:mm:ss');function isEmail(_0x568619){return/^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/[_0xac04('0xe')](_0x568619);}function selectNotIn(_0xa336de,_0x4da3b6,_0x3422ae,_0x2992f8,_0xfd10b0){return squel[_0xac04('0xf')]()[_0xac04('0x10')](_0xac04('0x11'))[_0xac04('0x12')](_0x2992f8)[_0xac04('0x13')](_0x4da3b6,null,_0x4da3b6+_0xac04('0x14')+_0x2992f8+'.'+_0x3422ae)[_0xac04('0x15')](_0x2992f8+'.'+_0x3422ae+'\x20=\x20'+_0xa336de+'.'+_0x3422ae)[_0xac04('0x15')](_0x4da3b6+'.dialCheckDuplicateType\x20IN\x20('+_0xfd10b0[_0xac04('0x13')]()+')');}function handleAdditionalPhones(){return new Promise(function(_0x1d1299,_0x510e4c){promisesAdditionalPhones=[];return db[_0xac04('0x16')][_0xac04('0x17')]({'raw':!![],'attributes':['id','AdditionalPhones'],'where':{'createdAt':NOW,'AdditionalPhones':{'$ne':null}}})['then'](function(_0x195542){if(_0x195542!==null){var _0x3a6b6c=[];for(var _0x2ae27f=0x0;_0x2ae27f<_0x195542[_0xac04('0x18')];_0x2ae27f++){var _0x344319=_0x195542[_0x2ae27f];_0x3a6b6c['push'](insertAdditionalPhones(_0x344319));}}Promise[_0xac04('0x19')](_0x3a6b6c)['then'](function(){_0x1d1299({'val':0x1});});});});}function insertAdditionalPhones(_0x3741a6){return new Promise(function(_0x39bd69,_0x501f22){var _0x365518=_0x3741a6[_0xac04('0x1a')];var _0x47498f=_0x365518[_0xac04('0x1b')](';');var _0x112d13=[];orderBy=0x0;for(var _0x38ac39=0x0;_0x38ac39<_0x47498f[_0xac04('0x18')];_0x38ac39++){_0x112d13[_0xac04('0x1c')](splitAdditionalPhone(_0x3741a6['id'],_0x47498f[_0x38ac39]));}Promise['all'](_0x112d13)[_0xac04('0x1d')](function(){_0x39bd69({'val':_0x47498f[_0xac04('0x18')]});});});}function splitAdditionalPhone(_0x4d42c1,_0x363aa6){return new Promise(function(_0x58dd80,_0x50d830){var _0x5ae7b0=_0x363aa6[_0xac04('0x1b')](':');var _0x40e9c7=_0x5ae7b0[0x0];var _0x2dc036=_0x5ae7b0[0x1];if(!_[_0xac04('0x1e')](_0x2dc036)){var _0x44b4ab=_0x2dc036[_0xac04('0x1b')]('|');var _0x14a011=[];for(var _0x22a845=0x0;_0x22a845<_0x44b4ab['length'];_0x22a845++){if(_0x44b4ab[_0x22a845]!==''){var _0x55dff5=_[_0xac04('0x1f')](promisesAdditionalPhones,{'contactId':_0x4d42c1,'phone':_0x44b4ab[_0x22a845]});if(_0x55dff5[_0xac04('0x18')]==0x0){orderBy++;promisesAdditionalPhones['push']({'contactId':_0x4d42c1,'contactTypeId':_0x40e9c7,'phone':_0x44b4ab[_0x22a845],'orderBy':orderBy});}}}_0x58dd80({'ok':0x1});}else _0x58dd80({'res':0x0});});}function createAdditionalPhone(_0x519d6c,_0x5aea37,_0x3c363c,_0x2b5a83){var _0x322020='';var _0x50f792='';var _0x38abf5=_0x3c363c[_0xac04('0x1b')]('§');_0x322020=_0x38abf5[0x0];if(_0x38abf5['length']==0x2)_0x50f792=_0x38abf5[0x1];return new Promise(function(_0x21c3f8,_0xfc34a7){return db['CmContactHasItem'][_0xac04('0x20')]({'where':{'CmContactId':_0x519d6c,'item':_0x322020}})['then'](function(_0x27f5a2){if(_0x27f5a2){return db[_0xac04('0x21')][_0xac04('0x22')]({'ItemTypeId':_0x5aea37,'description':_0x50f792,'OrderBy':_0x2b5a83},{'where':{'CmContactId':_0x519d6c,'item':_0x322020}})[_0xac04('0x1d')](function(_0x1bafa8){_0x21c3f8({'res':_0xac04('0x23')});});}else{return db[_0xac04('0x21')]['create']({'CmContactId':_0x519d6c,'item':_0x322020,'description':_0x50f792,'ItemTypeId':_0x5aea37,'OrderBy':_0x2b5a83,'ItemClass':_0xac04('0x24')})['then'](function(_0x3e1bab){_0x21c3f8({'res':_0xac04('0x25')});});}});});}function insertCmHopper(_0x5d37e1,_0x1bf928,_0x368ced,_0x2a1596,_0x5247bf){var _0x10e70a=['cm_contacts.phone',_0xac04('0x26'),_0xac04('0x27'),_0xac04('0x28'),_0x1bf928+'.'+_0x2a1596,_0xac04('0x29'),_0xac04('0x2a'),_0xac04('0x2b'),_0xac04('0x2c'),'\x22'+_0x5247bf+'\x22'];return squel['insert']()[_0xac04('0x2d')](_0xac04('0x2e'))[_0xac04('0x2f')]([_0xac04('0x11'),_0xac04('0x30'),'ContactId',_0xac04('0x31'),_0x2a1596,_0xac04('0x32'),_0xac04('0x33'),_0xac04('0x34'),_0xac04('0x35'),_0xac04('0x36')],squel[_0xac04('0xf')]()[_0xac04('0x37')](_0x10e70a)['from'](_0x1bf928)[_0xac04('0x13')]('cm_contacts',null,_0xac04('0x38')+_0x1bf928+_0xac04('0x39'))['join'](_0x368ced,null,_0x368ced+_0xac04('0x14')+_0x1bf928+'.'+_0x2a1596)[_0xac04('0x15')](_0x1bf928+_0xac04('0x3a'),_0x5d37e1)['where'](_0xac04('0x3b'),NOW)[_0xac04('0x15')]('cm_contacts.phone\x20NOT\x20IN\x20(?)',selectNotIn(_0x1bf928,_0x368ced,_0x2a1596,_0xac04('0x2e'),['\x22always\x22',_0xac04('0x3c')]))[_0xac04('0x15')](_0xac04('0x3d'),selectNotIn(_0x1bf928,_0x368ced,_0x2a1596,_0xac04('0x2e'),[_0xac04('0x3e')])))['toString']();}function insertCmHopperBlack(_0x255fd1,_0x24d78c,_0x5d06c2,_0x5dea2f){var _0x1a8f51=[_0xac04('0x3f'),_0xac04('0x27'),_0xac04('0x28'),_0x24d78c+'.'+_0x5dea2f,_0xac04('0x29'),_0xac04('0x2a')];return squel['insert']()[_0xac04('0x2d')]('cm_hopper_black')[_0xac04('0x2f')](['phone',_0xac04('0x40'),_0xac04('0x31'),_0x5dea2f,_0xac04('0x32'),_0xac04('0x33')],squel[_0xac04('0xf')]()[_0xac04('0x37')](_0x1a8f51)[_0xac04('0x12')](_0x24d78c)[_0xac04('0x13')]('cm_contacts',null,_0xac04('0x38')+_0x24d78c+'.CmListId')[_0xac04('0x13')](_0x5d06c2,null,_0x5d06c2+_0xac04('0x14')+_0x24d78c+'.'+_0x5dea2f)[_0xac04('0x15')](_0x24d78c+_0xac04('0x3a'),_0x255fd1)[_0xac04('0x15')](_0xac04('0x3b'),NOW)['where'](_0xac04('0x3d'),squel[_0xac04('0xf')]()[_0xac04('0x10')]('phone')[_0xac04('0x12')](_0xac04('0x41'))[_0xac04('0x15')]('ListId\x20=\x20?',_0x255fd1)[_0xac04('0x15')](_0x5dea2f+_0xac04('0x42')+_0x24d78c+'.'+_0x5dea2f)))['toString']();}function insertTzCmHopper(_0x34ca22,_0x34fc13,_0x34d121,_0xe0bb1c,_0x17edc3,_0x173343){var _0x301f5c=[_0xac04('0x3f'),_0xac04('0x43')+_0x173343+_0xac04('0x44'),'cm_contacts.id',_0xac04('0x28'),_0x34fc13+'.'+_0xe0bb1c,_0xac04('0x29'),_0xac04('0x2a'),_0xac04('0x2b'),_0xac04('0x2c'),'\x22'+_0x17edc3+'\x22'];var _0x3fc402=squel[_0xac04('0x45')]()[_0xac04('0x2d')](_0xac04('0x2e'))[_0xac04('0x2f')]([_0xac04('0x11'),_0xac04('0x30'),_0xac04('0x40'),_0xac04('0x31'),_0xe0bb1c,_0xac04('0x32'),_0xac04('0x33'),'priority','UserId',_0xac04('0x36')],squel[_0xac04('0xf')]()['fields'](_0x301f5c)['from'](_0x34fc13)['join'](_0xac04('0x46'),null,_0xac04('0x38')+_0x34fc13+_0xac04('0x39'))[_0xac04('0x13')](_0x34d121,null,_0x34d121+_0xac04('0x14')+_0x34fc13+'.'+_0xe0bb1c)[_0xac04('0x13')](_0x173343,null,_0x173343+'.id\x20=\x20'+_0x34fc13+'.'+_0xe0bb1c)[_0xac04('0x15')](_0x34fc13+_0xac04('0x3a'),_0x34ca22)[_0xac04('0x15')](_0xac04('0x3b'),NOW)[_0xac04('0x15')](_0xac04('0x3d'),selectNotIn(_0x34fc13,_0x34d121,_0xe0bb1c,'cm_hopper',['\x22always\x22',_0xac04('0x3c')]))[_0xac04('0x15')](_0xac04('0x3d'),selectNotIn(_0x34fc13,_0x34d121,_0xe0bb1c,'cm_hopper',[_0xac04('0x3e')])))[_0xac04('0x47')]();return _0x3fc402;}function insertTzCmHopperBlack(_0x22b68,_0x231a17,_0xbe3740,_0x2c4cdd){var _0x25765b=[_0xac04('0x3f'),_0xac04('0x27'),_0xac04('0x28'),_0x231a17+'.'+_0x2c4cdd,_0xac04('0x29'),_0xac04('0x2a')];return squel[_0xac04('0x45')]()[_0xac04('0x2d')](_0xac04('0x41'))['fromQuery']([_0xac04('0x11'),_0xac04('0x40'),_0xac04('0x31'),_0x2c4cdd,_0xac04('0x32'),_0xac04('0x33')],squel[_0xac04('0xf')]()[_0xac04('0x37')](_0x25765b)[_0xac04('0x12')](_0x231a17)[_0xac04('0x13')]('cm_contacts',null,_0xac04('0x38')+_0x231a17+_0xac04('0x39'))['join'](_0xbe3740,null,_0xbe3740+_0xac04('0x14')+_0x231a17+'.'+_0x2c4cdd)[_0xac04('0x15')](_0x231a17+_0xac04('0x3a'),_0x22b68)[_0xac04('0x15')]('cm_contacts.createdAt\x20=\x20?',NOW)[_0xac04('0x15')]('cm_contacts.phone\x20NOT\x20IN\x20(?)',squel[_0xac04('0xf')]()['field'](_0xac04('0x11'))[_0xac04('0x12')](_0xac04('0x41'))[_0xac04('0x15')](_0xac04('0x48'),_0x22b68)[_0xac04('0x15')](_0x2c4cdd+'\x20=\x20'+_0x231a17+'.'+_0x2c4cdd)))['toString']();}function insertCmHopperAdditionalPhones(_0x431085){var _0x10ab6d=[_0xac04('0x49'),_0xac04('0x4a'),_0xac04('0x4b'),'cm_contact_has_items.createdAt',_0xac04('0x4c')];return squel[_0xac04('0x45')]()[_0xac04('0x2d')](_0xac04('0x4d'))['fromQuery'](['CmHopperId',_0xac04('0x11'),_0xac04('0x4e'),_0xac04('0x32'),_0xac04('0x33')],squel['select']()[_0xac04('0x37')](_0x10ab6d)[_0xac04('0x12')]('cm_hopper')[_0xac04('0x13')](_0xac04('0x46'),null,_0xac04('0x4f'))[_0xac04('0x13')](_0xac04('0x50'),null,_0xac04('0x51'))[_0xac04('0x15')](_0xac04('0x52'),_0x431085)[_0xac04('0x15')]('cm_contacts.createdAt\x20=\x20?',NOW))[_0xac04('0x47')]();}function insertCmContact(_0x24266c,_0x955214,_0x18fae9,_0x160c1c){var _0x488ae7=_[_0xac04('0x53')](_[_0xac04('0x54')](_0x160c1c),[_0xac04('0x31'),'CompanyId',_0xac04('0x32'),_0xac04('0x33')]);return squel[_0xac04('0x45')]()[_0xac04('0x2d')](_0xac04('0x46'))[_0xac04('0x2f')](_0x488ae7,squel[_0xac04('0xf')]()[_0xac04('0x37')](_0x488ae7)[_0xac04('0x12')](_0x955214)[_0xac04('0x15')]('('+_0x18fae9[_0xac04('0x13')](',')+_0xac04('0x55'),squel[_0xac04('0xf')]()[_0xac04('0x37')](_0x18fae9)[_0xac04('0x12')](_0xac04('0x46'))['where'](_0xac04('0x48'),_0x24266c)[_0xac04('0x15')](_0xac04('0x56')))['where']('id\x20IN\x20?',squel[_0xac04('0xf')]()[_0xac04('0x10')]('MIN(id)',_0xac04('0x57'))[_0xac04('0x12')](_0x955214)[_0xac04('0x58')](_0x18fae9[_0xac04('0x13')](','))))[_0xac04('0x47')]();}function handleStop(){logger[_0xac04('0x59')]('Received\x20SIGINT');stopped=!![];}function handleUncaughtException(_0x379d46){logger['error'](_0x379d46['message']);process['exit'](0x1);}function handleError(_0x5effd0,_0x364c4d){stats[_0xac04('0x5a')]['push']({'name':_0x364c4d['code'],'message':_0x364c4d[_0xac04('0x5b')],'row':_0x5effd0});}function handleQuery(_0x5d062b){logger[_0xac04('0x59')](_0x5d062b);return db['sequelize'][_0xac04('0x5c')](_0x5d062b)['spread'](function(_0x1187e6){results['push'](_0x1187e6);})[_0xac04('0x5d')](function(_0x48fd2f){logger['error'](_0x48fd2f['message']);});}function updateTzCampaigns(_0x201c47){return new Promise(function(_0x2f037c,_0x1f727b){var _0x35f4bf=squel[_0xac04('0xf')]()[_0xac04('0x37')]([_0xac04('0x5e'),_0xac04('0x5f')])[_0xac04('0x12')](_0xac04('0x60'))[_0xac04('0x13')](_0xac04('0x61'),null,_0xac04('0x62'))[_0xac04('0x15')](_0xac04('0x63')+_0x201c47);db['sequelize']['query'](_0x35f4bf['toString']())[_0xac04('0x64')](function(_0x7b5f12){var _0xafda2c=[];for(var _0x543207=0x0;_0x543207<_0x7b5f12['length'];_0x543207++){_0xafda2c['push'](getTimezoneData(_0x7b5f12[_0x543207],tmp_campaigns));}BPromise[_0xac04('0x19')](_0xafda2c)['then'](function(){_0x2f037c({'val':0x1});});})[_0xac04('0x5d')](function(_0x58d1df){logger[_0xac04('0x65')](_0x58d1df['message']);_0x2f037c({'val':0x0});});});}function updateTzVoiceQueues(_0x46f113){return new Promise(function(_0x197e61,_0x1afeec){var _0x3edc95=squel['select']()[_0xac04('0x37')]([_0xac04('0x66'),_0xac04('0x67')])[_0xac04('0x12')](_0xac04('0x68'))['join'](_0xac04('0x69'),null,_0xac04('0x6a'))['where'](_0xac04('0x6b')+_0x46f113);db['sequelize'][_0xac04('0x5c')](_0x3edc95['toString']())[_0xac04('0x64')](function(_0xfa3541){var _0xe00d1a=[];for(var _0x2b784c=0x0;_0x2b784c<_0xfa3541['length'];_0x2b784c++){_0xe00d1a[_0xac04('0x1c')](getTimezoneData(_0xfa3541[_0x2b784c],tmp_voice_queues));}BPromise[_0xac04('0x19')](_0xe00d1a)[_0xac04('0x1d')](function(){_0x197e61({'val':0x1});});})[_0xac04('0x5d')](function(_0x4f4b93){logger[_0xac04('0x65')](_0x4f4b93[_0xac04('0x5b')]);_0x197e61({'val':0x0});});});}function getTimezoneData(_0xa1a806,_0x306a58){return new Promise(function(_0x2bc067,_0x18dd6d){var _0x21f120=shared['timezones'];var _0xc4fe15=_0x21f120[_0xa1a806[_0xac04('0x6c')]];if(_['isNil'](_0xc4fe15)){_0x2bc067({'ret':0x1});}else{var _0x32e994=_0xc4fe15['utcOffset'];var _0x169478=squel[_0xac04('0x45')]()[_0xac04('0x2d')](_0x306a58)[_0xac04('0x6d')]('id',_0xa1a806['id'])[_0xac04('0x6d')](_0xac04('0x6e'),_0x32e994)[_0xac04('0x6d')](_0xac04('0x6c'),_0xa1a806[_0xac04('0x6c')])[_0xac04('0x47')]();return db[_0xac04('0x6f')]['query'](_0x169478)['spread'](function(_0x25805f){_0x2bc067({'ret':0x1});})[_0xac04('0x5d')](function(_0x3c9647){logger[_0xac04('0x65')](_0x3c9647['message']);_0x18dd6d({'ret':0x1});});}});}function handleTZQuery(_0x1a8dfe){logger[_0xac04('0x59')](_0x1a8dfe);return db[_0xac04('0x6f')]['query'](_0x1a8dfe)[_0xac04('0x64')](function(_0x22a6d0){})[_0xac04('0x5d')](function(_0x204ba3){logger[_0xac04('0x65')](_0x204ba3[_0xac04('0x5b')]);});}function main(_0x329c99,_0x4399b6,_0x2897da,_0x1bcb4e){logger[_0xac04('0x59')]('main',_0x329c99,JSON[_0xac04('0x70')](_0x4399b6));process['send'](_0xac04('0x71'));var _0x2fb397=_0x4399b6[_0xac04('0x72')];var _0x3fa5bd=_[_0xac04('0x73')](_0x2fb397);var _0x142ba5=_0x4399b6[_0xac04('0x74')];var _0x1f9449=path[_0xac04('0x13')](config[_0xac04('0x75')],_0xac04('0x76'),_0x142ba5+_0xac04('0x77'));hasTZ=_[_0xac04('0x54')](_0x2fb397)['includes'](_0xac04('0x6c'));var _0x2a5841=_[_0xac04('0x54')](_0x2fb397)[_0xac04('0x13')]();logger[_0xac04('0x59')](_0xac04('0x78'),_0x2a5841);db['ContactItemType'][_0xac04('0x17')]({'raw':!![],'attributes':['id',_0xac04('0x79')]})[_0xac04('0x1d')](function(_0x2c2c6a){for(var _0x1f1a2a=0x0;_0x1f1a2a<_0x2c2c6a['length'];_0x1f1a2a++){if(_0x2c2c6a[_0x1f1a2a][_0xac04('0x79')]in _0x2fb397){contactItemTypes[_0xac04('0x1c')](_0x2c2c6a[_0x1f1a2a]);delete _0x3fa5bd[_0x2c2c6a[_0x1f1a2a][_0xac04('0x79')]];hasAdditionalPhones=!![];}for(var _0x908a7f in _0x2fb397){if(_0x2c2c6a[_0x1f1a2a]['name']+'_description'===_0x908a7f){phoneDescriptions[_0xac04('0x1c')]({'itemTypeId':_0x2c2c6a[_0x1f1a2a]['id'],'description':_0x908a7f});delete _0x3fa5bd[_0x908a7f];}}}if(hasAdditionalPhones)_0x3fa5bd[_0xac04('0x1a')]='';var _0xcd37d=_['keys'](_0x3fa5bd)[_0xac04('0x13')]();logger[_0xac04('0x59')](_0xac04('0x78'),_0xcd37d);fs[_0xac04('0x7a')](_0x1f9449,_0xcd37d+'\x0a');Papa[_0xac04('0x7b')](fs['createReadStream'](_0x329c99),{'header':!![],'skipEmptyLines':!![],'step':function(_0x208780,_0x49e499){try{for(var _0x3dd16b=0x0,_0x2e748d=[];_0x3dd16b<_0x208780[_0xac04('0x7c')][_0xac04('0x18')];_0x3dd16b++){stats['rows']+=0x1;if(_0x208780[_0xac04('0x5a')][_0x3dd16b]){handleError(_0x208780[_0xac04('0x7c')][_0x3dd16b],_0x208780[_0xac04('0x5a')][_0x3dd16b]);}else{var _0x252fd5=[];var _0x19e738=[];var _0x2230c8={};for(var _0x36fac4 in _0x2fb397){let _0x43a241=contactItemTypes[_0xac04('0x7d')](_0x520311=>_0x520311[_0xac04('0x79')]===_0x36fac4);let _0x477019=contactItemTypes[_0xac04('0x7d')](_0x405141=>_0x405141[_0xac04('0x79')]+'_description'===_0x36fac4);if(_[_0xac04('0x1e')](_0x43a241)&&_['isNil'](_0x477019)){if(_0x2fb397[_0xac04('0x7e')](_0x36fac4)){if(_0x208780['data'][_0x3dd16b][_0x2fb397[_0x36fac4]]){var _0xf9f3ff=_[_0xac04('0x7f')](_0x208780[_0xac04('0x7c')][_0x3dd16b][_0x2fb397[_0x36fac4]][_0xac04('0x80')](/"/g,'\x27'));switch(_0x36fac4){case _0xac04('0x30'):var _0x4749a0=moment(_0xf9f3ff,_0xac04('0xc'),!![]);if(_0x4749a0[_0xac04('0x81')]()){_0x2e748d[_0xac04('0x1c')]('\x22'+_0xf9f3ff+'\x22');}else{_0x252fd5[_0xac04('0x1c')](_0xac04('0x82'));}break;case _0xac04('0x34'):var _0x3bfec1=parseInt(_0xf9f3ff);_0xf9f3ff=_[_0xac04('0x83')](_0x3bfec1)||_0x3bfec1<0x0||_0x3bfec1>0x4?_0x1bcb4e?0x3:0x2:_0x3bfec1;_0x2e748d[_0xac04('0x1c')]('\x22'+_0xf9f3ff+'\x22');break;case _0xac04('0x35'):var _0x45a14c=parseInt(_0xf9f3ff);if(_[_0xac04('0x84')](_0x45a14c)&&_[_0xac04('0x85')](_0x2897da,_0x45a14c)){_0x2e748d['push']('\x22'+_0x45a14c+'\x22');}else{_0x252fd5['push'](_0xac04('0x86'));}break;case'email':if(isEmail(_0xf9f3ff)){_0x2e748d[_0xac04('0x1c')]('\x22'+_0xf9f3ff+'\x22');}else{_0x252fd5['push'](_0xac04('0x87'));}break;case _0xac04('0x88'):var _0x3cedd4=moment(_0xf9f3ff,'YYYY-MM-DD',!![]);if(_0x3cedd4[_0xac04('0x81')]()){_0x2e748d[_0xac04('0x1c')]('\x22'+_0xf9f3ff+'\x22');}else{_0x252fd5['push'](_0xac04('0x89'));}break;case _0xac04('0x6c'):var _0x1621f5=shared[_0xac04('0x8a')];var _0x2ad7bc=_0x1621f5[_0xf9f3ff];if(!_[_0xac04('0x1e')](_0x2ad7bc)){var _0x2a31fa=_0x2ad7bc[_0xac04('0x8b')];_0x2e748d[_0xac04('0x1c')]('\x22'+_0xf9f3ff+'\x22');_0x2e748d[_0xac04('0x1c')]('\x22'+_0x2a31fa+'\x22');}break;default:_0x2e748d['push']('\x22'+_0xf9f3ff+'\x22');}}else{switch(_0x36fac4){case _0xac04('0x8c'):case _0xac04('0x11'):_0x252fd5['push'](_0x36fac4+'\x20not\x20specified');break;default:_0x2e748d['push']('\x22\x22');}}}}else{var _0x57ca89='';if(!_[_0xac04('0x1e')](_0x43a241)){if(!_0x2230c8['hasOwnProperty'](_0x43a241['id'])){if(!_[_0xac04('0x1e')](_0x208780[_0xac04('0x7c')][_0x3dd16b][_0x2fb397[_0x36fac4]])){var _0xf9f3ff=_[_0xac04('0x7f')](_0x208780['data'][_0x3dd16b][_0x2fb397[_0x36fac4]]['replace'](/"/g,'\x27'));var _0x18434f=phoneDescriptions[_0xac04('0x7d')](_0x46dbb4=>_0x46dbb4[_0xac04('0x8d')]===_0x43a241['id']);if(!_['isNil'](_0x18434f)){var _0x483a3a=_[_0xac04('0x7f')](_0x208780[_0xac04('0x7c')][_0x3dd16b][_0x2fb397[_0x18434f[_0xac04('0x8e')]]][_0xac04('0x80')](/"/g,'\x27'));if(!_['isNil'](_0x483a3a))_0xf9f3ff=_0xf9f3ff+'§'+_0x483a3a;}if(_0x57ca89=='')_0x57ca89=_0xf9f3ff;else _0x57ca89+='|'+_0xf9f3ff;}_0x19e738[_0xac04('0x1c')](_0x43a241['id']+':'+_0x57ca89);_0x2230c8[_0x43a241['id']]=0x1;}}}}if(hasAdditionalPhones){_0x2e748d['push']('\x22'+_0x19e738['join'](';')+'\x22');}if(_0x252fd5['length']){handleError(_0x208780[_0xac04('0x7c')][_0x3dd16b],{'code':_0xac04('0x8f'),'message':_0x252fd5['join']()});}else{fs[_0xac04('0x90')](_0x1f9449,_0x2e748d['join']()+'\x0a');}_0x2e748d=[];}if(!(stats[_0xac04('0x91')]%0xc8)){socket['emit']('contact:import:'+_0x142ba5,stats);stats[_0xac04('0x5a')]=[];}}if(stopped){logger[_0xac04('0x59')]('Abort\x20parser');_0x49e499[_0xac04('0x92')]();}}catch(_0x191797){handleError(_0x208780['data'][_0x3dd16b],{'code':_0xac04('0x93'),'message':_0x191797[_0xac04('0x5b')]});logger[_0xac04('0x65')](_0xac04('0x94'),_0x191797[_0xac04('0x5b')]);}},'complete':function(){try{var _0x5e6d88=[];var _0xd76c1=[];var _0x4bdc37=_0xac04('0x46');if(_0x4399b6[_0xac04('0x95')]&&_0x4399b6[_0xac04('0x95')][_0xac04('0x18')]){_0x4bdc37=_0xac04('0x96')+_0x142ba5;_0x5e6d88[_0xac04('0x1c')](_0xac04('0x97')+_0x4bdc37+_0xac04('0x98'));}tmp_campaigns=_0xac04('0x99')+_0x142ba5;tmp_voice_queues='voice_queues_'+_0x142ba5;_0xd76c1[_0xac04('0x1c')](_0xac04('0x97')+tmp_campaigns+'(id\x20int,dialTimezone\x20varchar(255),offset\x20int);');_0xd76c1[_0xac04('0x1c')]('CREATE\x20TABLE\x20'+tmp_voice_queues+_0xac04('0x9a'));BPromise['each'](_0xd76c1,handleTZQuery)[_0xac04('0x1d')](function(_0x29f1e1){updateTzCampaigns(_0x4399b6[_0xac04('0x31')])[_0xac04('0x1d')](function(_0x35b0dc){updateTzVoiceQueues(_0x4399b6[_0xac04('0x31')])[_0xac04('0x1d')](function(_0xe6b4fc){if(hasTZ)_0xcd37d=_0xcd37d[_0xac04('0x80')]('dialTimezone',_0xac04('0x9b'));var _0x2269bf=util[_0xac04('0xd')](_0xac04('0x9c'),_0x1f9449,_0x4bdc37,_0xcd37d,_0x4399b6[_0xac04('0x31')],_0x4399b6[_0xac04('0x9d')]||null,NOW,NOW);if(_[_0xac04('0x1e')](_0x2fb397[_0xac04('0x30')])){_0x2269bf+=_0xac04('0x9e');}_0x5e6d88[_0xac04('0x1c')](_0x2269bf);if(_0x4399b6[_0xac04('0x95')]&&_0x4399b6[_0xac04('0x95')][_0xac04('0x18')]){_0x5e6d88[_0xac04('0x1c')](insertCmContact(_0x4399b6[_0xac04('0x31')],_0x4bdc37,_0x4399b6[_0xac04('0x95')],_0x2fb397));_0x5e6d88[_0xac04('0x1c')](_0xac04('0x9f')+_0x4bdc37+';');}BPromise[_0xac04('0xa0')](_0x5e6d88,handleQuery)['then'](function(_0x1faf1d){BPromise[_0xac04('0x19')]([handleAdditionalPhones()])[_0xac04('0x1d')](function(){_0x5e6d88=[];for(var _0x48ff26=0x0;_0x48ff26<promisesAdditionalPhones[_0xac04('0x18')];_0x48ff26++){if(promisesAdditionalPhones[_0x48ff26]['phone']!='§'){_0x5e6d88['push'](createAdditionalPhone(promisesAdditionalPhones[_0x48ff26][_0xac04('0xa1')],promisesAdditionalPhones[_0x48ff26][_0xac04('0xa2')],promisesAdditionalPhones[_0x48ff26][_0xac04('0x11')],promisesAdditionalPhones[_0x48ff26][_0xac04('0xa3')]));}}BPromise['all'](_0x5e6d88)['then'](function(){_0x5e6d88=[];if(hasTZ){_0x5e6d88[_0xac04('0x1c')](insertTzCmHopper(_0x4399b6[_0xac04('0x31')],'voice_queues_has_cm_lists',_0xac04('0x68'),'VoiceQueueId',_0x1bcb4e,tmp_voice_queues));_0x5e6d88[_0xac04('0x1c')](insertTzCmHopperBlack(_0x4399b6[_0xac04('0x31')],_0xac04('0xa4'),'voice_queues',_0xac04('0xa5')));_0x5e6d88[_0xac04('0x1c')](insertTzCmHopper(_0x4399b6['ListId'],'campaigns_has_cm_lists',_0xac04('0x60'),'CampaignId',_0x1bcb4e,tmp_campaigns));_0x5e6d88[_0xac04('0x1c')](insertTzCmHopperBlack(_0x4399b6[_0xac04('0x31')],_0xac04('0xa6'),_0xac04('0x60'),'CampaignId'));_0x5e6d88[_0xac04('0x1c')](insertCmHopperAdditionalPhones(_0x4399b6[_0xac04('0x31')]));}else{_0x5e6d88[_0xac04('0x1c')](insertCmHopper(_0x4399b6[_0xac04('0x31')],'voice_queues_has_cm_lists',_0xac04('0x68'),_0xac04('0xa5'),_0x1bcb4e));_0x5e6d88['push'](insertCmHopperBlack(_0x4399b6['ListId'],_0xac04('0xa4'),'voice_queues',_0xac04('0xa5')));_0x5e6d88['push'](insertCmHopper(_0x4399b6['ListId'],_0xac04('0x61'),_0xac04('0x60'),'CampaignId',_0x1bcb4e));_0x5e6d88[_0xac04('0x1c')](insertCmHopperBlack(_0x4399b6['ListId'],_0xac04('0xa6'),_0xac04('0x60'),_0xac04('0xa7')));_0x5e6d88[_0xac04('0x1c')](insertCmHopperAdditionalPhones(_0x4399b6[_0xac04('0x31')]));}_0x5e6d88['push'](_0xac04('0x9f')+tmp_campaigns+';');_0x5e6d88[_0xac04('0x1c')]('DROP\x20TABLE\x20'+tmp_voice_queues+';');BPromise['each'](_0x5e6d88,handleQuery)['then'](function(_0x56a8af){stats[_0xac04('0xa8')]=!![];stats[_0xac04('0xa9')]=_0x4399b6['duplicates']&&_0x4399b6[_0xac04('0x95')][_0xac04('0x18')]?results[0x2]['affectedRows']:results[0x0][_0xac04('0xa9')];socket['emit'](_0xac04('0xaa')+_0x142ba5,stats);fs[_0xac04('0xab')](_0x329c99);fs[_0xac04('0xab')](_0x1f9449);process[_0xac04('0xac')](0x0);})[_0xac04('0x5d')](function(_0x22993a){logger['error'](_0x22993a[_0xac04('0x5b')]);process[_0xac04('0xac')](0x1);});});});})[_0xac04('0x5d')](function(_0x585f90){logger[_0xac04('0x65')](_0x585f90[_0xac04('0x5b')]);process[_0xac04('0xac')](0x1);});});});});}catch(_0x4cd162){logger[_0xac04('0x65')](_0xac04('0xad'),_0x4cd162[_0xac04('0x5b')]);process['exit'](0x1);}},'error':function(_0x2a1cb7,_0xe7b84a,_0x4af85f,_0x115552){throw new Error(_0x115552);}});});}function validate(){if(process[_0xac04('0xae')]&&process['argv']['length']<0x4){throw new Error('arguments\x20<filename>\x20<parameters>\x20<agents>');}var _0x173586=path[_0xac04('0x13')](config[_0xac04('0x75')],_0xac04('0x76'),process[_0xac04('0xae')][0x2]);if(!fs[_0xac04('0xaf')](_0x173586)){throw new Error(_0xac04('0xb0'));}var _0x4fe14d={};try{_0x4fe14d=JSON[_0xac04('0x7b')](process[_0xac04('0xae')][0x3]);if(!_0x4fe14d[_0xac04('0x72')]){throw new Error(_0xac04('0xb1'));}if(!_0x4fe14d[_0xac04('0x72')][_0xac04('0x11')]){throw new Error('phone\x20is\x20mandatory');}if(!_0x4fe14d[_0xac04('0x72')][_0xac04('0x8c')]){throw new Error(_0xac04('0xb2'));}var _0x83994e=0x0;if(_0x4fe14d[_0xac04('0x72')][_0xac04('0x35')]){_0x83994e=0x1;}if(!_0x4fe14d[_0xac04('0x31')]){throw new Error(_0xac04('0xb3'));}}catch(_0x1cda21){throw new Error(_0xac04('0xb4'));}var _0x2c3e07=[];try{_0x2c3e07=_['map'](JSON['parse'](process['argv'][0x4]),'id');}catch(_0x2b9421){logger['info']('No\x20agent\x20available');}main(_0x173586,_0x4fe14d,_0x2c3e07,_0x83994e);}validate();process['on'](_0xac04('0xb5'),handleStop);process['on'](_0xac04('0xb6'),handleUncaughtException);