Built motion from commit 52c8a02d.|2.6.29
[motion2.git] / server / components / import / cm / csv2.js
index cfed003..7dd1090 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x85f6=['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','DROP\x20TABLE\x20','each','contactId','contactTypeId','orderBy','voice_queues_has_cm_lists','VoiceQueueId','voice_queues','campaigns','campaigns_has_cm_blacklists','CampaignId','finish','affectedRows','unlink','exit','complete','argv','arguments\x20<filename>\x20<parameters>\x20<agents>','root','existsSync','binding','binding\x20doesn\x27t\x20exists','phone\x20is\x20mandatory','firstName\x20is\x20mandatory','ListId\x20is\x20mandatory','body\x20id\x20mandatory','map','No\x20agent\x20available','uncaughtException','path','lodash','papaparse','util','bluebird','moment','squel','ioredis','../../../config/environment/shared','import','redis','defaults','localhost','socket.io-emitter','format','YYYY-MM-DD\x20HH:mm:ss','test','select','field','from','join','\x20=\x20','.dialCheckDuplicateType\x20IN\x20(','CmContact','then','split','length','all','isNil','push','findOne','update','CmContactHasItem','create','PHONE','inserted','cm_contacts.phone','cm_contacts.id','cm_contacts.updatedAt','cm_contacts.UserId','insert','into','cm_hopper','fromQuery','ContactId','ListId','updatedAt','fields','cm_contacts','cm_contacts.ListId\x20=\x20','.CmListId','.id\x20=\x20','where','.CmListId\x20=\x20?','cm_contacts.createdAt\x20=\x20?','cm_contacts.phone\x20NOT\x20IN\x20(?)','\x22always\x22','\x22onlyIfOpen\x22','cm_contacts.ListId','cm_contacts.createdAt','phone','cm_hopper_black','ListId\x20=\x20?','date_add(cm_contacts.scheduledat,interval\x20','.offset-cm_contacts.utcOffset\x20minute)','cm_contacts.priority','createdAt','priority','UserId','toString','cm_hopper.id','cm_contact_has_items.item','cm_contact_has_items.OrderBy','cm_contact_has_items.createdAt','cm_contact_has_items.updatedAt','cm_hopper_additional_phones','CmHopperId','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','CompanyId',')\x20NOT\x20IN\x20?','deletedAt\x20IS\x20NULL','id\x20IN\x20?','MIN(id)','min_id','group','info','error','message','errors','sequelize','spread','catch','campaigns.id','campaigns.dialTimezone','campaigns_has_cm_lists','campaigns.id\x20=\x20campaigns_has_cm_lists.CampaignId','query','voice_queues.id','voice_queues.dialTimezone','voice_queues_has_cm_lists.CmListId=','timezones','dialTimezone','set','main','stringify','send','start','clone','socket_timestamp','server/files/tmp','findAll','name','_description','AdditionalPhones','header','parse','createReadStream','data','rows','find','hasOwnProperty','trim','replace','scheduledat','isValid','scheduledat\x20wrong\x20format\x20(YYYY-MM-DD\x20HH:mm:ss)','isNaN','isNumber','includes','email','email\x20wrong\x20format','dateOfBirth','YYYY-MM-DD','dateOfBirth\x20wrong\x20format\x20(YYYY-MM-DD)','utcOffset','firstName','\x20not\x20specified','itemTypeId','description','SystemRow','emit','contact:import:','Abort\x20parser','abort','SystemError','step','duplicates'];(function(_0x40a045,_0x516f0e){var _0x1a687c=function(_0x48c9fe){while(--_0x48c9fe){_0x40a045['push'](_0x40a045['shift']());}};_0x1a687c(++_0x516f0e);}(_0x85f6,0xdf));var _0x685f=function(_0x519d6c,_0x9092c4){_0x519d6c=_0x519d6c-0x0;var _0x40ec69=_0x85f6[_0x519d6c];return _0x40ec69;};'use strict';var fs=require('fs');var path=require(_0x685f('0x0'));var _=require(_0x685f('0x1'));var Papa=require(_0x685f('0x2'));var util=require(_0x685f('0x3'));var BPromise=require(_0x685f('0x4'));var moment=require(_0x685f('0x5'));var squel=require(_0x685f('0x6'));var Redis=require(_0x685f('0x7'));var db=require('../../../mysqldb')['db'];var config=require('../../../config/environment');var shared=require(_0x685f('0x8'));var logger=require('../../../config/logger')(_0x685f('0x9'));config[_0x685f('0xa')]=_[_0x685f('0xb')](config[_0x685f('0xa')],{'host':_0x685f('0xc'),'port':0x18eb});var socket=require(_0x685f('0xd'))(new Redis(config['redis']));var stats={'finish':![],'errors':[],'rows':0x0,'affectedRows':0x0};var results=[];var promisesAdditionalPhones=[];var orderBy=0x0;var stopped=![];var NOW=moment()[_0x685f('0xe')](_0x685f('0xf'));var contactItemTypes=[];var phoneDescriptions=[];var hasAdditionalPhones=![];var tmp_voice_queues;var tmp_campaigns;var tzOffset=0x0;var hasTZ;var NOW=moment()[_0x685f('0xe')]('YYYY-MM-DD\x20HH:mm:ss');function isEmail(_0x553134){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))*$/[_0x685f('0x10')](_0x553134);}function selectNotIn(_0x3660f6,_0x213aed,_0x732254,_0x8e6ba3,_0x54f1c6){return squel[_0x685f('0x11')]()[_0x685f('0x12')]('phone')[_0x685f('0x13')](_0x8e6ba3)[_0x685f('0x14')](_0x213aed,null,_0x213aed+'.id\x20=\x20'+_0x8e6ba3+'.'+_0x732254)['where'](_0x8e6ba3+'.'+_0x732254+_0x685f('0x15')+_0x3660f6+'.'+_0x732254)['where'](_0x213aed+_0x685f('0x16')+_0x54f1c6[_0x685f('0x14')]()+')');}function handleAdditionalPhones(){return new Promise(function(_0x2510d9,_0x46446f){promisesAdditionalPhones=[];return db[_0x685f('0x17')]['findAll']({'raw':!![],'attributes':['id','AdditionalPhones'],'where':{'createdAt':NOW,'AdditionalPhones':{'$ne':null}}})[_0x685f('0x18')](function(_0x72f849){if(_0x72f849!==null){var _0x1b0b35=[];for(var _0x35c4c8=0x0;_0x35c4c8<_0x72f849['length'];_0x35c4c8++){var _0x284f33=_0x72f849[_0x35c4c8];_0x1b0b35['push'](insertAdditionalPhones(_0x284f33));}}Promise['all'](_0x1b0b35)[_0x685f('0x18')](function(){_0x2510d9({'val':0x1});});});});}function insertAdditionalPhones(_0x31d01e){return new Promise(function(_0x5d5046,_0x3d5904){var _0x550744=_0x31d01e['AdditionalPhones'];var _0x4140f9=_0x550744[_0x685f('0x19')](';');var _0x3efcff=[];orderBy=0x0;for(var _0x34bd0b=0x0;_0x34bd0b<_0x4140f9[_0x685f('0x1a')];_0x34bd0b++){_0x3efcff['push'](splitAdditionalPhone(_0x31d01e['id'],_0x4140f9[_0x34bd0b]));}Promise[_0x685f('0x1b')](_0x3efcff)[_0x685f('0x18')](function(){_0x5d5046({'val':_0x4140f9[_0x685f('0x1a')]});});});}function splitAdditionalPhone(_0x47cbd4,_0x222045){return new Promise(function(_0x2df8b1,_0x3ea42e){var _0x43395d=_0x222045[_0x685f('0x19')](':');var _0x264a11=_0x43395d[0x0];var _0x5f2c5a=_0x43395d[0x1];if(!_[_0x685f('0x1c')](_0x5f2c5a)){var _0x4ebc28=_0x5f2c5a['split']('|');var _0x7d6680=[];for(var _0x2415eb=0x0;_0x2415eb<_0x4ebc28[_0x685f('0x1a')];_0x2415eb++){if(_0x4ebc28[_0x2415eb]!==''){var _0x56f5b5=_['filter'](promisesAdditionalPhones,{'contactId':_0x47cbd4,'phone':_0x4ebc28[_0x2415eb]});if(_0x56f5b5[_0x685f('0x1a')]==0x0){orderBy++;promisesAdditionalPhones[_0x685f('0x1d')]({'contactId':_0x47cbd4,'contactTypeId':_0x264a11,'phone':_0x4ebc28[_0x2415eb],'orderBy':orderBy});}}}_0x2df8b1({'ok':0x1});}else _0x2df8b1({'res':0x0});});}function createAdditionalPhone(_0x337b06,_0x5707fd,_0x5ffa0e,_0x9e9f16){var _0x2f1a09='';var _0x2ee580='';var _0x19af62=_0x5ffa0e['split']('§');_0x2f1a09=_0x19af62[0x0];if(_0x19af62[_0x685f('0x1a')]==0x2)_0x2ee580=_0x19af62[0x1];return new Promise(function(_0x19c0ff,_0x32b800){return db['CmContactHasItem'][_0x685f('0x1e')]({'where':{'CmContactId':_0x337b06,'item':_0x2f1a09}})[_0x685f('0x18')](function(_0x34ac21){if(_0x34ac21){return db['CmContactHasItem'][_0x685f('0x1f')]({'ItemTypeId':_0x5707fd,'description':_0x2ee580,'OrderBy':_0x9e9f16},{'where':{'CmContactId':_0x337b06,'item':_0x2f1a09}})['then'](function(_0x113653){_0x19c0ff({'res':'updated'});});}else{return db[_0x685f('0x20')][_0x685f('0x21')]({'CmContactId':_0x337b06,'item':_0x2f1a09,'description':_0x2ee580,'ItemTypeId':_0x5707fd,'OrderBy':_0x9e9f16,'ItemClass':_0x685f('0x22')})['then'](function(_0x2af19e){_0x19c0ff({'res':_0x685f('0x23')});});}});});}function insertCmHopper(_0x12cda5,_0x47dadd,_0x262539,_0x40f646,_0x4ed673){var _0x2fd824=[_0x685f('0x24'),'cm_contacts.scheduledat',_0x685f('0x25'),'cm_contacts.ListId',_0x47dadd+'.'+_0x40f646,'cm_contacts.createdAt',_0x685f('0x26'),'cm_contacts.priority',_0x685f('0x27'),'\x22'+_0x4ed673+'\x22'];return squel[_0x685f('0x28')]()[_0x685f('0x29')](_0x685f('0x2a'))[_0x685f('0x2b')](['phone','scheduledat',_0x685f('0x2c'),_0x685f('0x2d'),_0x40f646,'createdAt',_0x685f('0x2e'),'priority','UserId','recallme'],squel[_0x685f('0x11')]()[_0x685f('0x2f')](_0x2fd824)[_0x685f('0x13')](_0x47dadd)[_0x685f('0x14')](_0x685f('0x30'),null,_0x685f('0x31')+_0x47dadd+_0x685f('0x32'))[_0x685f('0x14')](_0x262539,null,_0x262539+_0x685f('0x33')+_0x47dadd+'.'+_0x40f646)[_0x685f('0x34')](_0x47dadd+_0x685f('0x35'),_0x12cda5)[_0x685f('0x34')](_0x685f('0x36'),NOW)[_0x685f('0x34')](_0x685f('0x37'),selectNotIn(_0x47dadd,_0x262539,_0x40f646,_0x685f('0x2a'),[_0x685f('0x38'),_0x685f('0x39')]))['where'](_0x685f('0x37'),selectNotIn(_0x47dadd,_0x262539,_0x40f646,_0x685f('0x2a'),['\x22always\x22'])))['toString']();}function insertCmHopperBlack(_0x1b2030,_0x3ee29d,_0x1db800,_0x440859){var _0x354636=[_0x685f('0x24'),_0x685f('0x25'),_0x685f('0x3a'),_0x3ee29d+'.'+_0x440859,_0x685f('0x3b'),_0x685f('0x26')];return squel[_0x685f('0x28')]()[_0x685f('0x29')]('cm_hopper_black')[_0x685f('0x2b')]([_0x685f('0x3c'),_0x685f('0x2c'),_0x685f('0x2d'),_0x440859,'createdAt','updatedAt'],squel['select']()['fields'](_0x354636)[_0x685f('0x13')](_0x3ee29d)['join'](_0x685f('0x30'),null,_0x685f('0x31')+_0x3ee29d+_0x685f('0x32'))['join'](_0x1db800,null,_0x1db800+_0x685f('0x33')+_0x3ee29d+'.'+_0x440859)['where'](_0x3ee29d+_0x685f('0x35'),_0x1b2030)[_0x685f('0x34')](_0x685f('0x36'),NOW)['where']('cm_contacts.phone\x20NOT\x20IN\x20(?)',squel['select']()['field'](_0x685f('0x3c'))['from'](_0x685f('0x3d'))[_0x685f('0x34')](_0x685f('0x3e'),_0x1b2030)[_0x685f('0x34')](_0x440859+_0x685f('0x15')+_0x3ee29d+'.'+_0x440859)))['toString']();}function insertTzCmHopper(_0x11e6c2,_0x26304b,_0x34db4e,_0x1ad71f,_0x5351f0,_0x48c0ca){var _0xa5b1a0=[_0x685f('0x24'),_0x685f('0x3f')+_0x48c0ca+_0x685f('0x40'),_0x685f('0x25'),_0x685f('0x3a'),_0x26304b+'.'+_0x1ad71f,'cm_contacts.createdAt',_0x685f('0x26'),_0x685f('0x41'),'cm_contacts.UserId','\x22'+_0x5351f0+'\x22'];var _0xf850bc=squel[_0x685f('0x28')]()[_0x685f('0x29')](_0x685f('0x2a'))['fromQuery'](['phone','scheduledat','ContactId',_0x685f('0x2d'),_0x1ad71f,_0x685f('0x42'),'updatedAt',_0x685f('0x43'),_0x685f('0x44'),'recallme'],squel[_0x685f('0x11')]()[_0x685f('0x2f')](_0xa5b1a0)[_0x685f('0x13')](_0x26304b)[_0x685f('0x14')](_0x685f('0x30'),null,_0x685f('0x31')+_0x26304b+_0x685f('0x32'))['join'](_0x34db4e,null,_0x34db4e+'.id\x20=\x20'+_0x26304b+'.'+_0x1ad71f)['join'](_0x48c0ca,null,_0x48c0ca+_0x685f('0x33')+_0x26304b+'.'+_0x1ad71f)[_0x685f('0x34')](_0x26304b+'.CmListId\x20=\x20?',_0x11e6c2)['where']('cm_contacts.createdAt\x20=\x20?',NOW)[_0x685f('0x34')](_0x685f('0x37'),selectNotIn(_0x26304b,_0x34db4e,_0x1ad71f,_0x685f('0x2a'),[_0x685f('0x38'),_0x685f('0x39')]))[_0x685f('0x34')](_0x685f('0x37'),selectNotIn(_0x26304b,_0x34db4e,_0x1ad71f,_0x685f('0x2a'),['\x22always\x22'])))[_0x685f('0x45')]();return _0xf850bc;}function insertTzCmHopperBlack(_0x29eda6,_0x169526,_0x5576f8,_0x20c1b9){var _0x2393e3=['cm_contacts.phone',_0x685f('0x25'),_0x685f('0x3a'),_0x169526+'.'+_0x20c1b9,_0x685f('0x3b'),_0x685f('0x26')];return squel[_0x685f('0x28')]()[_0x685f('0x29')](_0x685f('0x3d'))[_0x685f('0x2b')]([_0x685f('0x3c'),_0x685f('0x2c'),_0x685f('0x2d'),_0x20c1b9,_0x685f('0x42'),_0x685f('0x2e')],squel[_0x685f('0x11')]()[_0x685f('0x2f')](_0x2393e3)[_0x685f('0x13')](_0x169526)['join']('cm_contacts',null,'cm_contacts.ListId\x20=\x20'+_0x169526+_0x685f('0x32'))[_0x685f('0x14')](_0x5576f8,null,_0x5576f8+_0x685f('0x33')+_0x169526+'.'+_0x20c1b9)[_0x685f('0x34')](_0x169526+_0x685f('0x35'),_0x29eda6)[_0x685f('0x34')](_0x685f('0x36'),NOW)[_0x685f('0x34')](_0x685f('0x37'),squel[_0x685f('0x11')]()[_0x685f('0x12')]('phone')['from'](_0x685f('0x3d'))[_0x685f('0x34')]('ListId\x20=\x20?',_0x29eda6)['where'](_0x20c1b9+_0x685f('0x15')+_0x169526+'.'+_0x20c1b9)))[_0x685f('0x45')]();}function insertCmHopperAdditionalPhones(_0x5060ed){var _0x4b1c75=[_0x685f('0x46'),_0x685f('0x47'),_0x685f('0x48'),_0x685f('0x49'),_0x685f('0x4a')];return squel[_0x685f('0x28')]()['into'](_0x685f('0x4b'))['fromQuery']([_0x685f('0x4c'),_0x685f('0x3c'),_0x685f('0x4d'),_0x685f('0x42'),_0x685f('0x2e')],squel['select']()[_0x685f('0x2f')](_0x4b1c75)[_0x685f('0x13')]('cm_hopper')[_0x685f('0x14')](_0x685f('0x30'),null,_0x685f('0x4e'))[_0x685f('0x14')](_0x685f('0x4f'),null,_0x685f('0x50'))['where'](_0x685f('0x51'),_0x5060ed)[_0x685f('0x34')]('cm_contacts.createdAt\x20=\x20?',NOW))[_0x685f('0x45')]();}function insertCmContact(_0x57d437,_0x2b7e62,_0x239038,_0x47e5c2){var _0x51deaa=_[_0x685f('0x52')](_[_0x685f('0x53')](_0x47e5c2),[_0x685f('0x2d'),_0x685f('0x54'),_0x685f('0x42'),_0x685f('0x2e')]);return squel[_0x685f('0x28')]()[_0x685f('0x29')](_0x685f('0x30'))[_0x685f('0x2b')](_0x51deaa,squel[_0x685f('0x11')]()['fields'](_0x51deaa)[_0x685f('0x13')](_0x2b7e62)[_0x685f('0x34')]('('+_0x239038[_0x685f('0x14')](',')+_0x685f('0x55'),squel['select']()[_0x685f('0x2f')](_0x239038)[_0x685f('0x13')](_0x685f('0x30'))['where'](_0x685f('0x3e'),_0x57d437)[_0x685f('0x34')](_0x685f('0x56')))['where'](_0x685f('0x57'),squel['select']()[_0x685f('0x12')](_0x685f('0x58'),_0x685f('0x59'))['from'](_0x2b7e62)[_0x685f('0x5a')](_0x239038['join'](','))))[_0x685f('0x45')]();}function handleStop(){logger[_0x685f('0x5b')]('Received\x20SIGINT');stopped=!![];}function handleUncaughtException(_0xb7bd13){logger[_0x685f('0x5c')](_0xb7bd13[_0x685f('0x5d')]);process['exit'](0x1);}function handleError(_0x189914,_0x42837e){stats[_0x685f('0x5e')]['push']({'name':_0x42837e['code'],'message':_0x42837e[_0x685f('0x5d')],'row':_0x189914});}function handleQuery(_0x1ba1cd){logger[_0x685f('0x5b')](_0x1ba1cd);return db[_0x685f('0x5f')]['query'](_0x1ba1cd)[_0x685f('0x60')](function(_0x54f79e){results[_0x685f('0x1d')](_0x54f79e);})[_0x685f('0x61')](function(_0x45d143){logger[_0x685f('0x5c')](_0x45d143[_0x685f('0x5d')]);});}function updateTzCampaigns(_0x77a61f){return new Promise(function(_0x354b36,_0x5e02e2){var _0x350452=squel[_0x685f('0x11')]()['fields']([_0x685f('0x62'),_0x685f('0x63')])[_0x685f('0x13')]('campaigns')[_0x685f('0x14')](_0x685f('0x64'),null,_0x685f('0x65'))[_0x685f('0x34')]('campaigns_has_cm_lists.CmListId='+_0x77a61f);db['sequelize'][_0x685f('0x66')](_0x350452[_0x685f('0x45')]())[_0x685f('0x60')](function(_0x41b04a){var _0x3dfe01=[];for(var _0x40d215=0x0;_0x40d215<_0x41b04a['length'];_0x40d215++){_0x3dfe01[_0x685f('0x1d')](getTimezoneData(_0x41b04a[_0x40d215],tmp_campaigns));}BPromise[_0x685f('0x1b')](_0x3dfe01)[_0x685f('0x18')](function(){_0x354b36({'val':0x1});});})[_0x685f('0x61')](function(_0xb5eb1d){logger[_0x685f('0x5c')](_0xb5eb1d[_0x685f('0x5d')]);_0x354b36({'val':0x0});});});}function updateTzVoiceQueues(_0x5992eb){return new Promise(function(_0x2f9e96,_0x2ac062){var _0x37a16b=squel[_0x685f('0x11')]()[_0x685f('0x2f')]([_0x685f('0x67'),_0x685f('0x68')])[_0x685f('0x13')]('voice_queues')[_0x685f('0x14')]('voice_queues_has_cm_lists',null,'voice_queues.id\x20=\x20voice_queues_has_cm_lists.VoiceQueueId')[_0x685f('0x34')](_0x685f('0x69')+_0x5992eb);db[_0x685f('0x5f')][_0x685f('0x66')](_0x37a16b['toString']())['spread'](function(_0x1ad013){var _0x32de99=[];for(var _0x2318c4=0x0;_0x2318c4<_0x1ad013[_0x685f('0x1a')];_0x2318c4++){_0x32de99['push'](getTimezoneData(_0x1ad013[_0x2318c4],tmp_voice_queues));}BPromise[_0x685f('0x1b')](_0x32de99)[_0x685f('0x18')](function(){_0x2f9e96({'val':0x1});});})['catch'](function(_0xb3be3c){logger['error'](_0xb3be3c['message']);_0x2f9e96({'val':0x0});});});}function getTimezoneData(_0xbe119c,_0x493a3e){return new Promise(function(_0x5e785c,_0xd8a295){var _0x526bf5=shared[_0x685f('0x6a')];var _0x1e6b62=_0x526bf5[_0xbe119c[_0x685f('0x6b')]];if(_[_0x685f('0x1c')](_0x1e6b62)){_0x5e785c({'ret':0x1});}else{var _0x52ac0f=_0x1e6b62['utcOffset'];var _0x48f85e=squel[_0x685f('0x28')]()[_0x685f('0x29')](_0x493a3e)[_0x685f('0x6c')]('id',_0xbe119c['id'])[_0x685f('0x6c')]('offset',_0x52ac0f)[_0x685f('0x6c')](_0x685f('0x6b'),_0xbe119c['dialTimezone'])[_0x685f('0x45')]();return db['sequelize'][_0x685f('0x66')](_0x48f85e)[_0x685f('0x60')](function(_0x203f7a){_0x5e785c({'ret':0x1});})[_0x685f('0x61')](function(_0x40479b){logger['error'](_0x40479b[_0x685f('0x5d')]);_0xd8a295({'ret':0x1});});}});}function handleTZQuery(_0x3db970){logger[_0x685f('0x5b')](_0x3db970);return db['sequelize'][_0x685f('0x66')](_0x3db970)[_0x685f('0x60')](function(_0x4931d2){})[_0x685f('0x61')](function(_0x5e2662){logger[_0x685f('0x5c')](_0x5e2662[_0x685f('0x5d')]);});}function main(_0x3ae9c3,_0xf4958c,_0xa79254,_0x4bf260){logger[_0x685f('0x5b')](_0x685f('0x6d'),_0x3ae9c3,JSON[_0x685f('0x6e')](_0xf4958c));process[_0x685f('0x6f')](_0x685f('0x70'));var _0x445b05=_0xf4958c['binding'];var _0x3fe932=_[_0x685f('0x71')](_0x445b05);var _0x831c1a=_0xf4958c[_0x685f('0x72')];var _0x7de203=path['join'](config['root'],_0x685f('0x73'),_0x831c1a+'.csv');hasTZ=_[_0x685f('0x53')](_0x445b05)['includes'](_0x685f('0x6b'));var _0x4f6ff5=_[_0x685f('0x53')](_0x445b05)[_0x685f('0x14')]();logger['info']('header',_0x4f6ff5);db['ContactItemType'][_0x685f('0x74')]({'raw':!![],'attributes':['id',_0x685f('0x75')]})[_0x685f('0x18')](function(_0x3ad2b7){for(var _0x427cef=0x0;_0x427cef<_0x3ad2b7['length'];_0x427cef++){if(_0x3ad2b7[_0x427cef][_0x685f('0x75')]in _0x445b05){contactItemTypes[_0x685f('0x1d')](_0x3ad2b7[_0x427cef]);delete _0x3fe932[_0x3ad2b7[_0x427cef]['name']];hasAdditionalPhones=!![];}for(var _0x24d4c0 in _0x445b05){if(_0x3ad2b7[_0x427cef]['name']+_0x685f('0x76')===_0x24d4c0){phoneDescriptions[_0x685f('0x1d')]({'itemTypeId':_0x3ad2b7[_0x427cef]['id'],'description':_0x24d4c0});delete _0x3fe932[_0x24d4c0];}}}if(hasAdditionalPhones)_0x3fe932[_0x685f('0x77')]='';var _0xe606eb=_['keys'](_0x3fe932)[_0x685f('0x14')]();logger[_0x685f('0x5b')](_0x685f('0x78'),_0xe606eb);fs['writeFileSync'](_0x7de203,_0xe606eb+'\x0a');Papa[_0x685f('0x79')](fs[_0x685f('0x7a')](_0x3ae9c3),{'header':!![],'skipEmptyLines':!![],'step':function(_0x536610,_0x491097){try{for(var _0x5d8b14=0x0,_0xee5b40=[];_0x5d8b14<_0x536610[_0x685f('0x7b')][_0x685f('0x1a')];_0x5d8b14++){stats[_0x685f('0x7c')]+=0x1;if(_0x536610[_0x685f('0x5e')][_0x5d8b14]){handleError(_0x536610[_0x685f('0x7b')][_0x5d8b14],_0x536610[_0x685f('0x5e')][_0x5d8b14]);}else{var _0x296799=[];var _0x364877=[];var _0x504ab2={};for(var _0x56767a in _0x445b05){let _0x64633e=contactItemTypes[_0x685f('0x7d')](_0x2969c6=>_0x2969c6[_0x685f('0x75')]===_0x56767a);let _0x24a8f3=contactItemTypes[_0x685f('0x7d')](_0x34f373=>_0x34f373[_0x685f('0x75')]+'_description'===_0x56767a);if(_[_0x685f('0x1c')](_0x64633e)&&_['isNil'](_0x24a8f3)){if(_0x445b05[_0x685f('0x7e')](_0x56767a)){if(_0x536610[_0x685f('0x7b')][_0x5d8b14][_0x445b05[_0x56767a]]){var _0x23a3b9=_[_0x685f('0x7f')](_0x536610['data'][_0x5d8b14][_0x445b05[_0x56767a]][_0x685f('0x80')](/"/g,'\x27'));switch(_0x56767a){case _0x685f('0x81'):var _0x31c44b=moment(_0x23a3b9,_0x685f('0xf'),!![]);if(_0x31c44b[_0x685f('0x82')]()){_0xee5b40[_0x685f('0x1d')]('\x22'+_0x23a3b9+'\x22');}else{_0x296799[_0x685f('0x1d')](_0x685f('0x83'));}break;case _0x685f('0x43'):var _0x2343c2=parseInt(_0x23a3b9);_0x23a3b9=_[_0x685f('0x84')](_0x2343c2)||_0x2343c2<0x0||_0x2343c2>0x4?_0x4bf260?0x3:0x2:_0x2343c2;_0xee5b40[_0x685f('0x1d')]('\x22'+_0x23a3b9+'\x22');break;case _0x685f('0x44'):var _0x30cf94=parseInt(_0x23a3b9);if(_[_0x685f('0x85')](_0x30cf94)&&_[_0x685f('0x86')](_0xa79254,_0x30cf94)){_0xee5b40[_0x685f('0x1d')]('\x22'+_0x30cf94+'\x22');}else{_0x296799[_0x685f('0x1d')]('agent\x20not\x20exists');}break;case _0x685f('0x87'):if(isEmail(_0x23a3b9)){_0xee5b40[_0x685f('0x1d')]('\x22'+_0x23a3b9+'\x22');}else{_0x296799['push'](_0x685f('0x88'));}break;case _0x685f('0x89'):var _0x376d27=moment(_0x23a3b9,_0x685f('0x8a'),!![]);if(_0x376d27[_0x685f('0x82')]()){_0xee5b40[_0x685f('0x1d')]('\x22'+_0x23a3b9+'\x22');}else{_0x296799['push'](_0x685f('0x8b'));}break;case _0x685f('0x6b'):var _0x5d79a6=shared[_0x685f('0x6a')];var _0x638f8c=_0x5d79a6[_0x23a3b9];if(!_[_0x685f('0x1c')](_0x638f8c)){var _0x21a72e=_0x638f8c[_0x685f('0x8c')];_0xee5b40['push']('\x22'+_0x23a3b9+'\x22');_0xee5b40[_0x685f('0x1d')]('\x22'+_0x21a72e+'\x22');}break;default:_0xee5b40[_0x685f('0x1d')]('\x22'+_0x23a3b9+'\x22');}}else{switch(_0x56767a){case _0x685f('0x8d'):case'phone':_0x296799[_0x685f('0x1d')](_0x56767a+_0x685f('0x8e'));break;default:_0xee5b40[_0x685f('0x1d')]('\x22\x22');}}}}else{var _0x1e18f1='';if(!_[_0x685f('0x1c')](_0x64633e)){if(!_0x504ab2['hasOwnProperty'](_0x64633e['id'])){if(!_[_0x685f('0x1c')](_0x536610['data'][_0x5d8b14][_0x445b05[_0x56767a]])){var _0x23a3b9=_[_0x685f('0x7f')](_0x536610[_0x685f('0x7b')][_0x5d8b14][_0x445b05[_0x56767a]][_0x685f('0x80')](/"/g,'\x27'));var _0x24287c=phoneDescriptions[_0x685f('0x7d')](_0x3ab8f4=>_0x3ab8f4[_0x685f('0x8f')]===_0x64633e['id']);if(!_[_0x685f('0x1c')](_0x24287c)){var _0x211541=_['trim'](_0x536610[_0x685f('0x7b')][_0x5d8b14][_0x445b05[_0x24287c[_0x685f('0x90')]]][_0x685f('0x80')](/"/g,'\x27'));if(!_['isNil'](_0x211541))_0x23a3b9=_0x23a3b9+'§'+_0x211541;}if(_0x1e18f1=='')_0x1e18f1=_0x23a3b9;else _0x1e18f1+='|'+_0x23a3b9;}_0x364877[_0x685f('0x1d')](_0x64633e['id']+':'+_0x1e18f1);_0x504ab2[_0x64633e['id']]=0x1;}}}}if(hasAdditionalPhones){_0xee5b40[_0x685f('0x1d')]('\x22'+_0x364877[_0x685f('0x14')](';')+'\x22');}if(_0x296799['length']){handleError(_0x536610[_0x685f('0x7b')][_0x5d8b14],{'code':_0x685f('0x91'),'message':_0x296799['join']()});}else{fs['appendFileSync'](_0x7de203,_0xee5b40[_0x685f('0x14')]()+'\x0a');}_0xee5b40=[];}if(!(stats[_0x685f('0x7c')]%0xc8)){socket[_0x685f('0x92')](_0x685f('0x93')+_0x831c1a,stats);stats[_0x685f('0x5e')]=[];}}if(stopped){logger[_0x685f('0x5b')](_0x685f('0x94'));_0x491097[_0x685f('0x95')]();}}catch(_0x493fde){handleError(_0x536610[_0x685f('0x7b')][_0x5d8b14],{'code':_0x685f('0x96'),'message':_0x493fde['message']});logger[_0x685f('0x5c')](_0x685f('0x97'),_0x493fde['message']);}},'complete':function(){try{var _0x5f2286=[];var _0x1ee614=[];var _0x264cf2='cm_contacts';if(_0xf4958c[_0x685f('0x98')]&&_0xf4958c['duplicates'][_0x685f('0x1a')]){_0x264cf2='cm_contacts_'+_0x831c1a;_0x5f2286[_0x685f('0x1d')](_0x685f('0x99')+_0x264cf2+_0x685f('0x9a'));}tmp_campaigns=_0x685f('0x9b')+_0x831c1a;tmp_voice_queues='voice_queues_'+_0x831c1a;_0x1ee614[_0x685f('0x1d')]('CREATE\x20TABLE\x20'+tmp_campaigns+_0x685f('0x9c'));_0x1ee614['push'](_0x685f('0x99')+tmp_voice_queues+'(id\x20int,dialTimezone\x20varchar(255),offset\x20int);');BPromise['each'](_0x1ee614,handleTZQuery)[_0x685f('0x18')](function(_0x1f2aba){updateTzCampaigns(_0xf4958c[_0x685f('0x2d')])[_0x685f('0x18')](function(_0x34872e){updateTzVoiceQueues(_0xf4958c[_0x685f('0x2d')])[_0x685f('0x18')](function(_0x44383e){if(hasTZ)_0xe606eb=_0xe606eb['replace']('dialTimezone',_0x685f('0x9d'));var _0x4f5d0f=util[_0x685f('0xe')](_0x685f('0x9e'),_0x7de203,_0x264cf2,_0xe606eb,_0xf4958c[_0x685f('0x2d')],_0xf4958c['CompanyId']||null,NOW,NOW);if(_[_0x685f('0x1c')](_0x445b05[_0x685f('0x81')])){_0x4f5d0f+=',\x20scheduledAt\x20=\x20NOW()';}_0x5f2286[_0x685f('0x1d')](_0x4f5d0f);if(_0xf4958c[_0x685f('0x98')]&&_0xf4958c[_0x685f('0x98')][_0x685f('0x1a')]){_0x5f2286['push'](insertCmContact(_0xf4958c['ListId'],_0x264cf2,_0xf4958c['duplicates'],_0x445b05));_0x5f2286[_0x685f('0x1d')](_0x685f('0x9f')+_0x264cf2+';');}BPromise[_0x685f('0xa0')](_0x5f2286,handleQuery)[_0x685f('0x18')](function(_0x49ccba){BPromise[_0x685f('0x1b')]([handleAdditionalPhones()])[_0x685f('0x18')](function(){_0x5f2286=[];for(var _0x4af3e6=0x0;_0x4af3e6<promisesAdditionalPhones[_0x685f('0x1a')];_0x4af3e6++){if(promisesAdditionalPhones[_0x4af3e6][_0x685f('0x3c')]!='§'){_0x5f2286[_0x685f('0x1d')](createAdditionalPhone(promisesAdditionalPhones[_0x4af3e6][_0x685f('0xa1')],promisesAdditionalPhones[_0x4af3e6][_0x685f('0xa2')],promisesAdditionalPhones[_0x4af3e6][_0x685f('0x3c')],promisesAdditionalPhones[_0x4af3e6][_0x685f('0xa3')]));}}BPromise['all'](_0x5f2286)[_0x685f('0x18')](function(){_0x5f2286=[];if(hasTZ){_0x5f2286[_0x685f('0x1d')](insertTzCmHopper(_0xf4958c[_0x685f('0x2d')],_0x685f('0xa4'),'voice_queues',_0x685f('0xa5'),_0x4bf260,tmp_voice_queues));_0x5f2286['push'](insertTzCmHopperBlack(_0xf4958c[_0x685f('0x2d')],'voice_queues_has_cm_blacklists',_0x685f('0xa6'),_0x685f('0xa5')));_0x5f2286[_0x685f('0x1d')](insertTzCmHopper(_0xf4958c['ListId'],'campaigns_has_cm_lists',_0x685f('0xa7'),'CampaignId',_0x4bf260,tmp_campaigns));_0x5f2286[_0x685f('0x1d')](insertTzCmHopperBlack(_0xf4958c[_0x685f('0x2d')],_0x685f('0xa8'),'campaigns',_0x685f('0xa9')));_0x5f2286['push'](insertCmHopperAdditionalPhones(_0xf4958c['ListId']));}else{_0x5f2286[_0x685f('0x1d')](insertCmHopper(_0xf4958c[_0x685f('0x2d')],_0x685f('0xa4'),_0x685f('0xa6'),_0x685f('0xa5'),_0x4bf260));_0x5f2286[_0x685f('0x1d')](insertCmHopperBlack(_0xf4958c[_0x685f('0x2d')],'voice_queues_has_cm_blacklists',_0x685f('0xa6'),_0x685f('0xa5')));_0x5f2286[_0x685f('0x1d')](insertCmHopper(_0xf4958c[_0x685f('0x2d')],_0x685f('0x64'),_0x685f('0xa7'),_0x685f('0xa9'),_0x4bf260));_0x5f2286[_0x685f('0x1d')](insertCmHopperBlack(_0xf4958c['ListId'],_0x685f('0xa8'),_0x685f('0xa7'),_0x685f('0xa9')));_0x5f2286[_0x685f('0x1d')](insertCmHopperAdditionalPhones(_0xf4958c[_0x685f('0x2d')]));}_0x5f2286[_0x685f('0x1d')](_0x685f('0x9f')+tmp_campaigns+';');_0x5f2286[_0x685f('0x1d')](_0x685f('0x9f')+tmp_voice_queues+';');BPromise[_0x685f('0xa0')](_0x5f2286,handleQuery)[_0x685f('0x18')](function(_0x1dcb2b){stats[_0x685f('0xaa')]=!![];stats[_0x685f('0xab')]=_0xf4958c[_0x685f('0x98')]&&_0xf4958c[_0x685f('0x98')][_0x685f('0x1a')]?results[0x2][_0x685f('0xab')]:results[0x0]['affectedRows'];socket[_0x685f('0x92')](_0x685f('0x93')+_0x831c1a,stats);fs[_0x685f('0xac')](_0x3ae9c3);fs[_0x685f('0xac')](_0x7de203);process[_0x685f('0xad')](0x0);})[_0x685f('0x61')](function(_0x2d43ed){logger[_0x685f('0x5c')](_0x2d43ed[_0x685f('0x5d')]);process['exit'](0x1);});});});})[_0x685f('0x61')](function(_0x385022){logger[_0x685f('0x5c')](_0x385022[_0x685f('0x5d')]);process[_0x685f('0xad')](0x1);});});});});}catch(_0x20a7c2){logger[_0x685f('0x5c')](_0x685f('0xae'),_0x20a7c2[_0x685f('0x5d')]);process[_0x685f('0xad')](0x1);}},'error':function(_0x38ab6a,_0x535f2c,_0x45dbe0,_0x1c7d27){throw new Error(_0x1c7d27);}});});}function validate(){if(process['argv']&&process[_0x685f('0xaf')][_0x685f('0x1a')]<0x4){throw new Error(_0x685f('0xb0'));}var _0x175d97=path['join'](config[_0x685f('0xb1')],_0x685f('0x73'),process['argv'][0x2]);if(!fs[_0x685f('0xb2')](_0x175d97)){throw new Error('file\x20doesn\x27t\x20exists');}var _0x2759d3={};try{_0x2759d3=JSON[_0x685f('0x79')](process[_0x685f('0xaf')][0x3]);if(!_0x2759d3[_0x685f('0xb3')]){throw new Error(_0x685f('0xb4'));}if(!_0x2759d3[_0x685f('0xb3')]['phone']){throw new Error(_0x685f('0xb5'));}if(!_0x2759d3['binding']['firstName']){throw new Error(_0x685f('0xb6'));}var _0x577c54=0x0;if(_0x2759d3[_0x685f('0xb3')]['UserId']){_0x577c54=0x1;}if(!_0x2759d3['ListId']){throw new Error(_0x685f('0xb7'));}}catch(_0x520d20){throw new Error(_0x685f('0xb8'));}var _0x4520d4=[];try{_0x4520d4=_[_0x685f('0xb9')](JSON['parse'](process[_0x685f('0xaf')][0x4]),'id');}catch(_0x5e41e1){logger[_0x685f('0x5b')](_0x685f('0xba'));}main(_0x175d97,_0x2759d3,_0x4520d4,_0x577c54);}validate();process['on']('SIGINT',handleStop);process['on'](_0x685f('0xbb'),handleUncaughtException);
\ No newline at end of file
+var _0x42d4=['scheduledat','ContactId','ListId','createdAt','updatedAt','priority','UserId','recallme','fields','cm_contacts','cm_contacts.ListId\x20=\x20','.CmListId','.CmListId\x20=\x20?','cm_contacts.createdAt\x20=\x20?','cm_contacts.phone\x20NOT\x20IN\x20(?)','\x22always\x22','cm_hopper','toString','cm_hopper_black','ListId\x20=\x20?','date_add(cm_contacts.scheduledat,interval\x20','.offset-cm_contacts.utcOffset\x20minute)','cm_contacts.createdAt','cm_contacts.priority','\x22onlyIfOpen\x22','cm_contact_has_items.createdAt','cm_contact_has_items.updatedAt','CmHopperId','OrderBy','cm_contacts.id\x20=\x20cm_contact_has_items.CmContactId','cm_hopper.ListId\x20=\x20?','concat','CompanyId','scheduledAt','id\x20IN\x20?','MIN(id)','group','Received\x20SIGINT','error','message','exit','errors','info','query','spread','catch','campaigns.dialTimezone','campaigns_has_cm_lists','campaigns.id\x20=\x20campaigns_has_cm_lists.CampaignId','sequelize','voice_queues.id','voice_queues.dialTimezone','voice_queues_has_cm_lists','voice_queues.id\x20=\x20voice_queues_has_cm_lists.VoiceQueueId','voice_queues_has_cm_lists.CmListId=','timezones','utcOffset','set','offset','dialTimezone','main','start','binding','clone','socket_timestamp','root','server/files/tmp','.csv','keys','includes','header','findAll','name','_description','writeFileSync','parse','createReadStream','data','rows','find','hasOwnProperty','replace','isValid','isNaN','agent\x20not\x20exists','email\x20wrong\x20format','dateOfBirth','YYYY-MM-DD','firstName','trim','itemTypeId','SystemRow','appendFileSync','Abort\x20parser','abort','SystemError','step','duplicates','CREATE\x20TABLE\x20','campaigns_','voice_queues_','(id\x20int,dialTimezone\x20varchar(255),offset\x20int);','each','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',',\x20scheduledAt\x20=\x20NOW()','DROP\x20TABLE\x20','contactId','contactTypeId','orderBy','voice_queues','VoiceQueueId','voice_queues_has_cm_blacklists','CampaignId','campaigns_has_cm_blacklists','campaigns','affectedRows','emit','contact:import:','unlink','complete','argv','arguments\x20<filename>\x20<parameters>\x20<agents>','existsSync','binding\x20doesn\x27t\x20exists','phone\x20is\x20mandatory','firstName\x20is\x20mandatory','ListId\x20is\x20mandatory','body\x20id\x20mandatory','map','No\x20agent\x20available','uncaughtException','path','papaparse','util','bluebird','moment','ioredis','../../../mysqldb','../../../config/logger','import','redis','defaults','localhost','socket.io-emitter','format','YYYY-MM-DD\x20HH:mm:ss','select','field','phone','from','join','.id\x20=\x20','where','\x20=\x20','AdditionalPhones','then','push','all','split','length','isNil','filter','CmContactHasItem','findOne','update','updated','create','PHONE','inserted','cm_contacts.phone','cm_contacts.id','cm_contacts.ListId','cm_contacts.updatedAt','cm_contacts.UserId','insert','into','fromQuery'];(function(_0x352fbf,_0x17cd4f){var _0x3d4c9b=function(_0x424bf5){while(--_0x424bf5){_0x352fbf['push'](_0x352fbf['shift']());}};_0x3d4c9b(++_0x17cd4f);}(_0x42d4,0x1e5));var _0x442d=function(_0x32e419,_0xff0455){_0x32e419=_0x32e419-0x0;var _0x1f0315=_0x42d4[_0x32e419];return _0x1f0315;};'use strict';var fs=require('fs');var path=require(_0x442d('0x0'));var _=require('lodash');var Papa=require(_0x442d('0x1'));var util=require(_0x442d('0x2'));var BPromise=require(_0x442d('0x3'));var moment=require(_0x442d('0x4'));var squel=require('squel');var Redis=require(_0x442d('0x5'));var db=require(_0x442d('0x6'))['db'];var config=require('../../../config/environment');var shared=require('../../../config/environment/shared');var logger=require(_0x442d('0x7'))(_0x442d('0x8'));config[_0x442d('0x9')]=_[_0x442d('0xa')](config[_0x442d('0x9')],{'host':_0x442d('0xb'),'port':0x18eb});var socket=require(_0x442d('0xc'))(new Redis(config['redis']));var stats={'finish':![],'errors':[],'rows':0x0,'affectedRows':0x0};var results=[];var promisesAdditionalPhones=[];var orderBy=0x0;var stopped=![];var NOW=moment()[_0x442d('0xd')]('YYYY-MM-DD\x20HH:mm:ss');var contactItemTypes=[];var phoneDescriptions=[];var hasAdditionalPhones=![];var tmp_voice_queues;var tmp_campaigns;var tzOffset=0x0;var hasTZ;var NOW=moment()['format'](_0x442d('0xe'));function isEmail(_0x161564){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))*$/['test'](_0x161564);}function selectNotIn(_0x5e740b,_0x29cd67,_0xf6c7e4,_0x1e3c9e,_0x492467){return squel[_0x442d('0xf')]()[_0x442d('0x10')](_0x442d('0x11'))[_0x442d('0x12')](_0x1e3c9e)[_0x442d('0x13')](_0x29cd67,null,_0x29cd67+_0x442d('0x14')+_0x1e3c9e+'.'+_0xf6c7e4)[_0x442d('0x15')](_0x1e3c9e+'.'+_0xf6c7e4+_0x442d('0x16')+_0x5e740b+'.'+_0xf6c7e4)[_0x442d('0x15')](_0x29cd67+'.dialCheckDuplicateType\x20IN\x20('+_0x492467[_0x442d('0x13')]()+')');}function handleAdditionalPhones(){return new Promise(function(_0xcc4fc2,_0x6afab3){promisesAdditionalPhones=[];return db['CmContact']['findAll']({'raw':!![],'attributes':['id',_0x442d('0x17')],'where':{'createdAt':NOW,'AdditionalPhones':{'$ne':null}}})[_0x442d('0x18')](function(_0x303209){if(_0x303209!==null){var _0x1f4e4d=[];for(var _0x1e8ad1=0x0;_0x1e8ad1<_0x303209['length'];_0x1e8ad1++){var _0x10d7d6=_0x303209[_0x1e8ad1];_0x1f4e4d[_0x442d('0x19')](insertAdditionalPhones(_0x10d7d6));}}Promise[_0x442d('0x1a')](_0x1f4e4d)[_0x442d('0x18')](function(){_0xcc4fc2({'val':0x1});});});});}function insertAdditionalPhones(_0x5e3c44){return new Promise(function(_0x586aca,_0x2e6321){var _0x29fe52=_0x5e3c44[_0x442d('0x17')];var _0x494d95=_0x29fe52[_0x442d('0x1b')](';');var _0xa9e4f0=[];orderBy=0x0;for(var _0x189e6f=0x0;_0x189e6f<_0x494d95[_0x442d('0x1c')];_0x189e6f++){_0xa9e4f0['push'](splitAdditionalPhone(_0x5e3c44['id'],_0x494d95[_0x189e6f]));}Promise['all'](_0xa9e4f0)[_0x442d('0x18')](function(){_0x586aca({'val':_0x494d95[_0x442d('0x1c')]});});});}function splitAdditionalPhone(_0x12d4ce,_0x2519af){return new Promise(function(_0x6a2964,_0x2d2300){var _0x3190ad=_0x2519af[_0x442d('0x1b')](':');var _0x2d139c=_0x3190ad[0x0];var _0x3d637c=_0x3190ad[0x1];if(!_[_0x442d('0x1d')](_0x3d637c)){var _0xf9d1ec=_0x3d637c[_0x442d('0x1b')]('|');var _0x29d35a=[];for(var _0x385c24=0x0;_0x385c24<_0xf9d1ec[_0x442d('0x1c')];_0x385c24++){if(_0xf9d1ec[_0x385c24]!==''){var _0x270769=_[_0x442d('0x1e')](promisesAdditionalPhones,{'contactId':_0x12d4ce,'phone':_0xf9d1ec[_0x385c24]});if(_0x270769[_0x442d('0x1c')]==0x0){orderBy++;promisesAdditionalPhones['push']({'contactId':_0x12d4ce,'contactTypeId':_0x2d139c,'phone':_0xf9d1ec[_0x385c24],'orderBy':orderBy});}}}_0x6a2964({'ok':0x1});}else _0x6a2964({'res':0x0});});}function createAdditionalPhone(_0x5c8a9a,_0x1a029c,_0x460586,_0x3a4579){var _0x521085='';var _0x2653bf='';var _0x413e2f=_0x460586[_0x442d('0x1b')]('§');_0x521085=_0x413e2f[0x0];if(_0x413e2f[_0x442d('0x1c')]==0x2)_0x2653bf=_0x413e2f[0x1];return new Promise(function(_0x5b1019,_0x195491){return db[_0x442d('0x1f')][_0x442d('0x20')]({'where':{'CmContactId':_0x5c8a9a,'item':_0x521085}})[_0x442d('0x18')](function(_0x52faf){if(_0x52faf){return db[_0x442d('0x1f')][_0x442d('0x21')]({'ItemTypeId':_0x1a029c,'description':_0x2653bf,'OrderBy':_0x3a4579},{'where':{'CmContactId':_0x5c8a9a,'item':_0x521085}})[_0x442d('0x18')](function(_0x3a638e){_0x5b1019({'res':_0x442d('0x22')});});}else{return db[_0x442d('0x1f')][_0x442d('0x23')]({'CmContactId':_0x5c8a9a,'item':_0x521085,'description':_0x2653bf,'ItemTypeId':_0x1a029c,'OrderBy':_0x3a4579,'ItemClass':_0x442d('0x24')})[_0x442d('0x18')](function(_0x5c9521){_0x5b1019({'res':_0x442d('0x25')});});}});});}function insertCmHopper(_0x2d162c,_0x262d91,_0x2ea550,_0x1ed887,_0x17c154){var _0x49514d=[_0x442d('0x26'),'cm_contacts.scheduledat',_0x442d('0x27'),_0x442d('0x28'),_0x262d91+'.'+_0x1ed887,'cm_contacts.createdAt',_0x442d('0x29'),'cm_contacts.priority',_0x442d('0x2a'),'\x22'+_0x17c154+'\x22'];return squel[_0x442d('0x2b')]()[_0x442d('0x2c')]('cm_hopper')[_0x442d('0x2d')]([_0x442d('0x11'),_0x442d('0x2e'),_0x442d('0x2f'),_0x442d('0x30'),_0x1ed887,_0x442d('0x31'),_0x442d('0x32'),_0x442d('0x33'),_0x442d('0x34'),_0x442d('0x35')],squel['select']()[_0x442d('0x36')](_0x49514d)[_0x442d('0x12')](_0x262d91)[_0x442d('0x13')](_0x442d('0x37'),null,_0x442d('0x38')+_0x262d91+_0x442d('0x39'))['join'](_0x2ea550,null,_0x2ea550+'.id\x20=\x20'+_0x262d91+'.'+_0x1ed887)[_0x442d('0x15')](_0x262d91+_0x442d('0x3a'),_0x2d162c)[_0x442d('0x15')](_0x442d('0x3b'),NOW)[_0x442d('0x15')](_0x442d('0x3c'),selectNotIn(_0x262d91,_0x2ea550,_0x1ed887,'cm_hopper',[_0x442d('0x3d'),'\x22onlyIfOpen\x22']))[_0x442d('0x15')]('cm_contacts.phone\x20NOT\x20IN\x20(?)',selectNotIn(_0x262d91,_0x2ea550,_0x1ed887,_0x442d('0x3e'),[_0x442d('0x3d')])))[_0x442d('0x3f')]();}function insertCmHopperBlack(_0x39d99a,_0x3b22c5,_0x2efc42,_0x34ff2f){var _0x4e2613=[_0x442d('0x26'),_0x442d('0x27'),'cm_contacts.ListId',_0x3b22c5+'.'+_0x34ff2f,'cm_contacts.createdAt',_0x442d('0x29')];return squel[_0x442d('0x2b')]()[_0x442d('0x2c')](_0x442d('0x40'))[_0x442d('0x2d')]([_0x442d('0x11'),'ContactId','ListId',_0x34ff2f,_0x442d('0x31'),_0x442d('0x32')],squel[_0x442d('0xf')]()[_0x442d('0x36')](_0x4e2613)['from'](_0x3b22c5)['join'](_0x442d('0x37'),null,_0x442d('0x38')+_0x3b22c5+_0x442d('0x39'))[_0x442d('0x13')](_0x2efc42,null,_0x2efc42+_0x442d('0x14')+_0x3b22c5+'.'+_0x34ff2f)[_0x442d('0x15')](_0x3b22c5+_0x442d('0x3a'),_0x39d99a)[_0x442d('0x15')](_0x442d('0x3b'),NOW)['where'](_0x442d('0x3c'),squel['select']()[_0x442d('0x10')](_0x442d('0x11'))[_0x442d('0x12')](_0x442d('0x40'))['where'](_0x442d('0x41'),_0x39d99a)[_0x442d('0x15')](_0x34ff2f+'\x20=\x20'+_0x3b22c5+'.'+_0x34ff2f)))[_0x442d('0x3f')]();}function insertTzCmHopper(_0x25c31f,_0x529bc0,_0x152862,_0x5fb3b0,_0x18bbc1,_0x15a871){var _0x552eb5=[_0x442d('0x26'),_0x442d('0x42')+_0x15a871+_0x442d('0x43'),'cm_contacts.id',_0x442d('0x28'),_0x529bc0+'.'+_0x5fb3b0,_0x442d('0x44'),_0x442d('0x29'),_0x442d('0x45'),_0x442d('0x2a'),'\x22'+_0x18bbc1+'\x22'];var _0x4a65bf=squel[_0x442d('0x2b')]()[_0x442d('0x2c')](_0x442d('0x3e'))[_0x442d('0x2d')]([_0x442d('0x11'),_0x442d('0x2e'),'ContactId',_0x442d('0x30'),_0x5fb3b0,_0x442d('0x31'),_0x442d('0x32'),'priority','UserId',_0x442d('0x35')],squel[_0x442d('0xf')]()['fields'](_0x552eb5)[_0x442d('0x12')](_0x529bc0)[_0x442d('0x13')]('cm_contacts',null,'cm_contacts.ListId\x20=\x20'+_0x529bc0+'.CmListId')[_0x442d('0x13')](_0x152862,null,_0x152862+'.id\x20=\x20'+_0x529bc0+'.'+_0x5fb3b0)[_0x442d('0x13')](_0x15a871,null,_0x15a871+'.id\x20=\x20'+_0x529bc0+'.'+_0x5fb3b0)[_0x442d('0x15')](_0x529bc0+'.CmListId\x20=\x20?',_0x25c31f)[_0x442d('0x15')](_0x442d('0x3b'),NOW)['where'](_0x442d('0x3c'),selectNotIn(_0x529bc0,_0x152862,_0x5fb3b0,_0x442d('0x3e'),['\x22always\x22',_0x442d('0x46')]))[_0x442d('0x15')](_0x442d('0x3c'),selectNotIn(_0x529bc0,_0x152862,_0x5fb3b0,_0x442d('0x3e'),['\x22always\x22'])))['toString']();return _0x4a65bf;}function insertTzCmHopperBlack(_0xc78b57,_0x10b38d,_0x6ecefa,_0x2a6ad2){var _0x457def=[_0x442d('0x26'),_0x442d('0x27'),'cm_contacts.ListId',_0x10b38d+'.'+_0x2a6ad2,'cm_contacts.createdAt',_0x442d('0x29')];return squel[_0x442d('0x2b')]()[_0x442d('0x2c')]('cm_hopper_black')[_0x442d('0x2d')]([_0x442d('0x11'),_0x442d('0x2f'),'ListId',_0x2a6ad2,_0x442d('0x31'),'updatedAt'],squel[_0x442d('0xf')]()[_0x442d('0x36')](_0x457def)['from'](_0x10b38d)['join']('cm_contacts',null,'cm_contacts.ListId\x20=\x20'+_0x10b38d+_0x442d('0x39'))[_0x442d('0x13')](_0x6ecefa,null,_0x6ecefa+_0x442d('0x14')+_0x10b38d+'.'+_0x2a6ad2)[_0x442d('0x15')](_0x10b38d+'.CmListId\x20=\x20?',_0xc78b57)['where']('cm_contacts.createdAt\x20=\x20?',NOW)[_0x442d('0x15')]('cm_contacts.phone\x20NOT\x20IN\x20(?)',squel['select']()[_0x442d('0x10')]('phone')['from'](_0x442d('0x40'))['where'](_0x442d('0x41'),_0xc78b57)[_0x442d('0x15')](_0x2a6ad2+'\x20=\x20'+_0x10b38d+'.'+_0x2a6ad2)))[_0x442d('0x3f')]();}function insertCmHopperAdditionalPhones(_0x1abaab){var _0x5d109b=['cm_hopper.id','cm_contact_has_items.item','cm_contact_has_items.OrderBy',_0x442d('0x47'),_0x442d('0x48')];return squel[_0x442d('0x2b')]()[_0x442d('0x2c')]('cm_hopper_additional_phones')[_0x442d('0x2d')]([_0x442d('0x49'),_0x442d('0x11'),_0x442d('0x4a'),_0x442d('0x31'),_0x442d('0x32')],squel[_0x442d('0xf')]()[_0x442d('0x36')](_0x5d109b)['from']('cm_hopper')['join'](_0x442d('0x37'),null,'cm_contacts.id\x20=\x20cm_hopper.ContactId')[_0x442d('0x13')]('cm_contact_has_items',null,_0x442d('0x4b'))['where'](_0x442d('0x4c'),_0x1abaab)['where'](_0x442d('0x3b'),NOW))[_0x442d('0x3f')]();}function insertCmContact(_0x551de7,_0xe62f18,_0x5253f3,_0x5ab148){var _0x160dfe=_[_0x442d('0x4d')](_['keys'](_0x5ab148),['ListId',_0x442d('0x4e'),_0x442d('0x31'),'updatedAt',_0x442d('0x4f')]);return squel[_0x442d('0x2b')]()[_0x442d('0x2c')](_0x442d('0x37'))[_0x442d('0x2d')](_0x160dfe,squel[_0x442d('0xf')]()[_0x442d('0x36')](_0x160dfe)[_0x442d('0x12')](_0xe62f18)[_0x442d('0x15')]('('+_0x5253f3['join'](',')+')\x20NOT\x20IN\x20?',squel[_0x442d('0xf')]()[_0x442d('0x36')](_0x5253f3)['from']('cm_contacts')['where'](_0x442d('0x41'),_0x551de7)[_0x442d('0x15')]('deletedAt\x20IS\x20NULL'))['where'](_0x442d('0x50'),squel[_0x442d('0xf')]()[_0x442d('0x10')](_0x442d('0x51'),'min_id')[_0x442d('0x12')](_0xe62f18)[_0x442d('0x52')](_0x5253f3['join'](','))))[_0x442d('0x3f')]();}function handleStop(){logger['info'](_0x442d('0x53'));stopped=!![];}function handleUncaughtException(_0x280a70){logger[_0x442d('0x54')](_0x280a70[_0x442d('0x55')]);process[_0x442d('0x56')](0x1);}function handleError(_0x9137b1,_0x2939c4){stats[_0x442d('0x57')]['push']({'name':_0x2939c4['code'],'message':_0x2939c4['message'],'row':_0x9137b1});}function handleQuery(_0x5d00fb){logger[_0x442d('0x58')](_0x5d00fb);return db['sequelize'][_0x442d('0x59')](_0x5d00fb)[_0x442d('0x5a')](function(_0x40b016){results[_0x442d('0x19')](_0x40b016);})[_0x442d('0x5b')](function(_0x5828a4){logger[_0x442d('0x54')](_0x5828a4[_0x442d('0x55')]);});}function updateTzCampaigns(_0x485fcd){return new Promise(function(_0x46839f,_0x4feef0){var _0x1b5e6f=squel['select']()[_0x442d('0x36')](['campaigns.id',_0x442d('0x5c')])[_0x442d('0x12')]('campaigns')[_0x442d('0x13')](_0x442d('0x5d'),null,_0x442d('0x5e'))[_0x442d('0x15')]('campaigns_has_cm_lists.CmListId='+_0x485fcd);db[_0x442d('0x5f')][_0x442d('0x59')](_0x1b5e6f['toString']())[_0x442d('0x5a')](function(_0x2d52cb){var _0x17772a=[];for(var _0x2f7d60=0x0;_0x2f7d60<_0x2d52cb['length'];_0x2f7d60++){_0x17772a[_0x442d('0x19')](getTimezoneData(_0x2d52cb[_0x2f7d60],tmp_campaigns));}BPromise['all'](_0x17772a)[_0x442d('0x18')](function(){_0x46839f({'val':0x1});});})[_0x442d('0x5b')](function(_0x297583){logger[_0x442d('0x54')](_0x297583[_0x442d('0x55')]);_0x46839f({'val':0x0});});});}function updateTzVoiceQueues(_0x2252af){return new Promise(function(_0x2bcd7c,_0x45001a){var _0x896268=squel['select']()[_0x442d('0x36')]([_0x442d('0x60'),_0x442d('0x61')])['from']('voice_queues')[_0x442d('0x13')](_0x442d('0x62'),null,_0x442d('0x63'))['where'](_0x442d('0x64')+_0x2252af);db[_0x442d('0x5f')][_0x442d('0x59')](_0x896268[_0x442d('0x3f')]())['spread'](function(_0x299fc6){var _0x1fb315=[];for(var _0x4d9d81=0x0;_0x4d9d81<_0x299fc6['length'];_0x4d9d81++){_0x1fb315[_0x442d('0x19')](getTimezoneData(_0x299fc6[_0x4d9d81],tmp_voice_queues));}BPromise['all'](_0x1fb315)[_0x442d('0x18')](function(){_0x2bcd7c({'val':0x1});});})[_0x442d('0x5b')](function(_0x1e8937){logger[_0x442d('0x54')](_0x1e8937['message']);_0x2bcd7c({'val':0x0});});});}function getTimezoneData(_0x1b12bf,_0x496510){return new Promise(function(_0x19dfcc,_0xfc6290){var _0x13a0e0=shared[_0x442d('0x65')];var _0x43e4a1=_0x13a0e0[_0x1b12bf['dialTimezone']];if(_['isNil'](_0x43e4a1)){_0x19dfcc({'ret':0x1});}else{var _0x458d74=_0x43e4a1[_0x442d('0x66')];var _0x4c76c9=squel[_0x442d('0x2b')]()[_0x442d('0x2c')](_0x496510)[_0x442d('0x67')]('id',_0x1b12bf['id'])[_0x442d('0x67')](_0x442d('0x68'),_0x458d74)[_0x442d('0x67')](_0x442d('0x69'),_0x1b12bf[_0x442d('0x69')])[_0x442d('0x3f')]();return db[_0x442d('0x5f')][_0x442d('0x59')](_0x4c76c9)[_0x442d('0x5a')](function(_0x534ad5){_0x19dfcc({'ret':0x1});})['catch'](function(_0x1c0d22){logger[_0x442d('0x54')](_0x1c0d22[_0x442d('0x55')]);_0xfc6290({'ret':0x1});});}});}function handleTZQuery(_0x312eb6){logger[_0x442d('0x58')](_0x312eb6);return db[_0x442d('0x5f')]['query'](_0x312eb6)[_0x442d('0x5a')](function(_0x50523e){})[_0x442d('0x5b')](function(_0x431fe3){logger[_0x442d('0x54')](_0x431fe3[_0x442d('0x55')]);});}function main(_0x32fa00,_0x4d13f6,_0x225aa3,_0x1da14c){logger[_0x442d('0x58')](_0x442d('0x6a'),_0x32fa00,JSON['stringify'](_0x4d13f6));process['send'](_0x442d('0x6b'));var _0x310a15=_0x4d13f6[_0x442d('0x6c')];var _0xc96524=_[_0x442d('0x6d')](_0x310a15);var _0xf39590=_0x4d13f6[_0x442d('0x6e')];var _0x496ea4=path[_0x442d('0x13')](config[_0x442d('0x6f')],_0x442d('0x70'),_0xf39590+_0x442d('0x71'));hasTZ=_[_0x442d('0x72')](_0x310a15)[_0x442d('0x73')]('dialTimezone');var _0x403053=_['keys'](_0x310a15)[_0x442d('0x13')]();logger[_0x442d('0x58')](_0x442d('0x74'),_0x403053);db['ContactItemType'][_0x442d('0x75')]({'raw':!![],'attributes':['id',_0x442d('0x76')]})[_0x442d('0x18')](function(_0x54cef0){for(var _0x524510=0x0;_0x524510<_0x54cef0['length'];_0x524510++){if(_0x54cef0[_0x524510][_0x442d('0x76')]in _0x310a15){contactItemTypes[_0x442d('0x19')](_0x54cef0[_0x524510]);delete _0xc96524[_0x54cef0[_0x524510]['name']];hasAdditionalPhones=!![];}for(var _0x1352d7 in _0x310a15){if(_0x54cef0[_0x524510][_0x442d('0x76')]+_0x442d('0x77')===_0x1352d7){phoneDescriptions[_0x442d('0x19')]({'itemTypeId':_0x54cef0[_0x524510]['id'],'description':_0x1352d7});delete _0xc96524[_0x1352d7];}}}if(hasAdditionalPhones)_0xc96524[_0x442d('0x17')]='';var _0x3fefa2=_['keys'](_0xc96524)[_0x442d('0x13')]();logger[_0x442d('0x58')](_0x442d('0x74'),_0x3fefa2);fs[_0x442d('0x78')](_0x496ea4,_0x3fefa2+'\x0a');Papa[_0x442d('0x79')](fs[_0x442d('0x7a')](_0x32fa00),{'header':!![],'skipEmptyLines':!![],'step':function(_0xa4be42,_0x1aabb1){try{for(var _0x5557fc=0x0,_0x6060f4=[];_0x5557fc<_0xa4be42[_0x442d('0x7b')][_0x442d('0x1c')];_0x5557fc++){stats[_0x442d('0x7c')]+=0x1;if(_0xa4be42[_0x442d('0x57')][_0x5557fc]){handleError(_0xa4be42['data'][_0x5557fc],_0xa4be42[_0x442d('0x57')][_0x5557fc]);}else{var _0x1ac88d=[];var _0xe62ec3=[];var _0x5f52db={};for(var _0x374ea0 in _0x310a15){let _0x495f3f=contactItemTypes[_0x442d('0x7d')](_0x3c09d5=>_0x3c09d5[_0x442d('0x76')]===_0x374ea0);let _0x410ce3=contactItemTypes[_0x442d('0x7d')](_0x84c7e8=>_0x84c7e8[_0x442d('0x76')]+_0x442d('0x77')===_0x374ea0);if(_[_0x442d('0x1d')](_0x495f3f)&&_['isNil'](_0x410ce3)){if(_0x310a15[_0x442d('0x7e')](_0x374ea0)){if(_0xa4be42[_0x442d('0x7b')][_0x5557fc][_0x310a15[_0x374ea0]]){var _0x55e326=_['trim'](_0xa4be42['data'][_0x5557fc][_0x310a15[_0x374ea0]][_0x442d('0x7f')](/"/g,'\x27'));switch(_0x374ea0){case _0x442d('0x2e'):var _0x460231=moment(_0x55e326,_0x442d('0xe'),!![]);if(_0x460231[_0x442d('0x80')]()){_0x6060f4['push']('\x22'+_0x55e326+'\x22');}else{_0x1ac88d[_0x442d('0x19')]('scheduledat\x20wrong\x20format\x20(YYYY-MM-DD\x20HH:mm:ss)');}break;case _0x442d('0x33'):var _0x38b225=parseInt(_0x55e326);_0x55e326=_[_0x442d('0x81')](_0x38b225)||_0x38b225<0x0||_0x38b225>0x4?_0x1da14c?0x3:0x2:_0x38b225;_0x6060f4[_0x442d('0x19')]('\x22'+_0x55e326+'\x22');break;case _0x442d('0x34'):var _0x50cb4e=parseInt(_0x55e326);if(_['isNumber'](_0x50cb4e)&&_[_0x442d('0x73')](_0x225aa3,_0x50cb4e)){_0x6060f4[_0x442d('0x19')]('\x22'+_0x50cb4e+'\x22');}else{_0x1ac88d['push'](_0x442d('0x82'));}break;case'email':if(isEmail(_0x55e326)){_0x6060f4['push']('\x22'+_0x55e326+'\x22');}else{_0x1ac88d[_0x442d('0x19')](_0x442d('0x83'));}break;case _0x442d('0x84'):var _0x4d2167=moment(_0x55e326,_0x442d('0x85'),!![]);if(_0x4d2167[_0x442d('0x80')]()){_0x6060f4[_0x442d('0x19')]('\x22'+_0x55e326+'\x22');}else{_0x1ac88d[_0x442d('0x19')]('dateOfBirth\x20wrong\x20format\x20(YYYY-MM-DD)');}break;case _0x442d('0x69'):var _0x206f50=shared[_0x442d('0x65')];var _0x1c2134=_0x206f50[_0x55e326];if(!_[_0x442d('0x1d')](_0x1c2134)){var _0x4dc087=_0x1c2134['utcOffset'];_0x6060f4['push']('\x22'+_0x55e326+'\x22');_0x6060f4[_0x442d('0x19')]('\x22'+_0x4dc087+'\x22');}break;default:_0x6060f4[_0x442d('0x19')]('\x22'+_0x55e326+'\x22');}}else{switch(_0x374ea0){case _0x442d('0x86'):case _0x442d('0x11'):_0x1ac88d[_0x442d('0x19')](_0x374ea0+'\x20not\x20specified');break;default:_0x6060f4[_0x442d('0x19')]('\x22\x22');}}}}else{var _0x2f3a02='';if(!_[_0x442d('0x1d')](_0x495f3f)){if(!_0x5f52db[_0x442d('0x7e')](_0x495f3f['id'])){if(!_[_0x442d('0x1d')](_0xa4be42['data'][_0x5557fc][_0x310a15[_0x374ea0]])){var _0x55e326=_[_0x442d('0x87')](_0xa4be42[_0x442d('0x7b')][_0x5557fc][_0x310a15[_0x374ea0]][_0x442d('0x7f')](/"/g,'\x27'));var _0x2cc864=phoneDescriptions['find'](_0x561002=>_0x561002[_0x442d('0x88')]===_0x495f3f['id']);if(!_[_0x442d('0x1d')](_0x2cc864)){var _0x5627a7=_[_0x442d('0x87')](_0xa4be42['data'][_0x5557fc][_0x310a15[_0x2cc864['description']]]['replace'](/"/g,'\x27'));if(!_['isNil'](_0x5627a7))_0x55e326=_0x55e326+'§'+_0x5627a7;}if(_0x2f3a02=='')_0x2f3a02=_0x55e326;else _0x2f3a02+='|'+_0x55e326;}_0xe62ec3['push'](_0x495f3f['id']+':'+_0x2f3a02);_0x5f52db[_0x495f3f['id']]=0x1;}}}}if(hasAdditionalPhones){_0x6060f4[_0x442d('0x19')]('\x22'+_0xe62ec3['join'](';')+'\x22');}if(_0x1ac88d[_0x442d('0x1c')]){handleError(_0xa4be42[_0x442d('0x7b')][_0x5557fc],{'code':_0x442d('0x89'),'message':_0x1ac88d['join']()});}else{fs[_0x442d('0x8a')](_0x496ea4,_0x6060f4[_0x442d('0x13')]()+'\x0a');}_0x6060f4=[];}if(!(stats[_0x442d('0x7c')]%0xc8)){socket['emit']('contact:import:'+_0xf39590,stats);stats[_0x442d('0x57')]=[];}}if(stopped){logger[_0x442d('0x58')](_0x442d('0x8b'));_0x1aabb1[_0x442d('0x8c')]();}}catch(_0x9cb596){handleError(_0xa4be42[_0x442d('0x7b')][_0x5557fc],{'code':_0x442d('0x8d'),'message':_0x9cb596['message']});logger[_0x442d('0x54')](_0x442d('0x8e'),_0x9cb596['message']);}},'complete':function(){try{var _0x223859=[];var _0x34a782=[];var _0xcaabd7=_0x442d('0x37');if(_0x4d13f6[_0x442d('0x8f')]&&_0x4d13f6['duplicates'][_0x442d('0x1c')]){_0xcaabd7='cm_contacts_'+_0xf39590;_0x223859[_0x442d('0x19')](_0x442d('0x90')+_0xcaabd7+'\x20LIKE\x20cm_contacts;');}tmp_campaigns=_0x442d('0x91')+_0xf39590;tmp_voice_queues=_0x442d('0x92')+_0xf39590;_0x34a782[_0x442d('0x19')](_0x442d('0x90')+tmp_campaigns+_0x442d('0x93'));_0x34a782['push']('CREATE\x20TABLE\x20'+tmp_voice_queues+_0x442d('0x93'));BPromise[_0x442d('0x94')](_0x34a782,handleTZQuery)[_0x442d('0x18')](function(_0x185060){updateTzCampaigns(_0x4d13f6[_0x442d('0x30')])['then'](function(_0x1e392c){updateTzVoiceQueues(_0x4d13f6[_0x442d('0x30')])['then'](function(_0x2579c0){if(hasTZ)_0x3fefa2=_0x3fefa2[_0x442d('0x7f')](_0x442d('0x69'),'dialTimezone,utcOffset');var _0x494d0d=util['format'](_0x442d('0x95'),_0x496ea4,_0xcaabd7,_0x3fefa2,_0x4d13f6[_0x442d('0x30')],_0x4d13f6[_0x442d('0x4e')]||null,NOW,NOW);if(_['isNil'](_0x310a15[_0x442d('0x2e')])){_0x494d0d+=_0x442d('0x96');}_0x223859['push'](_0x494d0d);if(_0x4d13f6[_0x442d('0x8f')]&&_0x4d13f6[_0x442d('0x8f')][_0x442d('0x1c')]){_0x223859[_0x442d('0x19')](insertCmContact(_0x4d13f6[_0x442d('0x30')],_0xcaabd7,_0x4d13f6[_0x442d('0x8f')],_0x310a15));_0x223859[_0x442d('0x19')](_0x442d('0x97')+_0xcaabd7+';');}BPromise[_0x442d('0x94')](_0x223859,handleQuery)[_0x442d('0x18')](function(_0x503e85){BPromise[_0x442d('0x1a')]([handleAdditionalPhones()])[_0x442d('0x18')](function(){_0x223859=[];for(var _0x5a4de8=0x0;_0x5a4de8<promisesAdditionalPhones[_0x442d('0x1c')];_0x5a4de8++){if(promisesAdditionalPhones[_0x5a4de8]['phone']!='§'){_0x223859[_0x442d('0x19')](createAdditionalPhone(promisesAdditionalPhones[_0x5a4de8][_0x442d('0x98')],promisesAdditionalPhones[_0x5a4de8][_0x442d('0x99')],promisesAdditionalPhones[_0x5a4de8][_0x442d('0x11')],promisesAdditionalPhones[_0x5a4de8][_0x442d('0x9a')]));}}BPromise['all'](_0x223859)['then'](function(){_0x223859=[];if(hasTZ){_0x223859[_0x442d('0x19')](insertTzCmHopper(_0x4d13f6[_0x442d('0x30')],'voice_queues_has_cm_lists',_0x442d('0x9b'),_0x442d('0x9c'),_0x1da14c,tmp_voice_queues));_0x223859['push'](insertTzCmHopperBlack(_0x4d13f6[_0x442d('0x30')],_0x442d('0x9d'),'voice_queues',_0x442d('0x9c')));_0x223859[_0x442d('0x19')](insertTzCmHopper(_0x4d13f6['ListId'],'campaigns_has_cm_lists','campaigns',_0x442d('0x9e'),_0x1da14c,tmp_campaigns));_0x223859[_0x442d('0x19')](insertTzCmHopperBlack(_0x4d13f6[_0x442d('0x30')],_0x442d('0x9f'),'campaigns','CampaignId'));_0x223859[_0x442d('0x19')](insertCmHopperAdditionalPhones(_0x4d13f6[_0x442d('0x30')]));}else{_0x223859[_0x442d('0x19')](insertCmHopper(_0x4d13f6[_0x442d('0x30')],_0x442d('0x62'),_0x442d('0x9b'),_0x442d('0x9c'),_0x1da14c));_0x223859[_0x442d('0x19')](insertCmHopperBlack(_0x4d13f6[_0x442d('0x30')],_0x442d('0x9d'),_0x442d('0x9b'),_0x442d('0x9c')));_0x223859[_0x442d('0x19')](insertCmHopper(_0x4d13f6[_0x442d('0x30')],_0x442d('0x5d'),_0x442d('0xa0'),_0x442d('0x9e'),_0x1da14c));_0x223859[_0x442d('0x19')](insertCmHopperBlack(_0x4d13f6['ListId'],_0x442d('0x9f'),_0x442d('0xa0'),_0x442d('0x9e')));_0x223859[_0x442d('0x19')](insertCmHopperAdditionalPhones(_0x4d13f6['ListId']));}_0x223859[_0x442d('0x19')]('DROP\x20TABLE\x20'+tmp_campaigns+';');_0x223859['push'](_0x442d('0x97')+tmp_voice_queues+';');BPromise[_0x442d('0x94')](_0x223859,handleQuery)[_0x442d('0x18')](function(_0x24f6be){stats['finish']=!![];stats[_0x442d('0xa1')]=_0x4d13f6[_0x442d('0x8f')]&&_0x4d13f6[_0x442d('0x8f')][_0x442d('0x1c')]?results[0x2]['affectedRows']:results[0x0][_0x442d('0xa1')];socket[_0x442d('0xa2')](_0x442d('0xa3')+_0xf39590,stats);fs['unlink'](_0x32fa00);fs[_0x442d('0xa4')](_0x496ea4);process[_0x442d('0x56')](0x0);})[_0x442d('0x5b')](function(_0x262c6b){logger[_0x442d('0x54')](_0x262c6b['message']);process['exit'](0x1);});});});})['catch'](function(_0xf5f450){logger[_0x442d('0x54')](_0xf5f450[_0x442d('0x55')]);process[_0x442d('0x56')](0x1);});});});});}catch(_0x56e758){logger[_0x442d('0x54')](_0x442d('0xa5'),_0x56e758[_0x442d('0x55')]);process['exit'](0x1);}},'error':function(_0x4f1a0a,_0x2c4fea,_0x31853c,_0x3faa55){throw new Error(_0x3faa55);}});});}function validate(){if(process[_0x442d('0xa6')]&&process[_0x442d('0xa6')][_0x442d('0x1c')]<0x4){throw new Error(_0x442d('0xa7'));}var _0x459ed2=path[_0x442d('0x13')](config[_0x442d('0x6f')],_0x442d('0x70'),process[_0x442d('0xa6')][0x2]);if(!fs[_0x442d('0xa8')](_0x459ed2)){throw new Error('file\x20doesn\x27t\x20exists');}var _0x321221={};try{_0x321221=JSON[_0x442d('0x79')](process['argv'][0x3]);if(!_0x321221[_0x442d('0x6c')]){throw new Error(_0x442d('0xa9'));}if(!_0x321221[_0x442d('0x6c')][_0x442d('0x11')]){throw new Error(_0x442d('0xaa'));}if(!_0x321221['binding'][_0x442d('0x86')]){throw new Error(_0x442d('0xab'));}var _0x110ba2=0x0;if(_0x321221[_0x442d('0x6c')][_0x442d('0x34')]){_0x110ba2=0x1;}if(!_0x321221[_0x442d('0x30')]){throw new Error(_0x442d('0xac'));}}catch(_0x66615b){throw new Error(_0x442d('0xad'));}var _0x13840a=[];try{_0x13840a=_[_0x442d('0xae')](JSON['parse'](process[_0x442d('0xa6')][0x4]),'id');}catch(_0x2ab9f6){logger[_0x442d('0x58')](_0x442d('0xaf'));}main(_0x459ed2,_0x321221,_0x13840a,_0x110ba2);}validate();process['on']('SIGINT',handleStop);process['on'](_0x442d('0xb0'),handleUncaughtException);
\ No newline at end of file