Built motion from commit 00bf23f6.|2.6.16
[motion2.git] / server / api / openchannelAccount / openchannelAccount.controller.js
index 7b894b9..c4fead4 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x8f05=['Tags','color','tag','addAgents','emit','userOpenchannelAccount:save','removeAgents','isArray','userOpenchannelAccount:remove','getAgents','CmList','DESC','out','dataValues','Messages','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','defaults','redis','localhost','socket.io-emitter','register','jayson/promise','client','http','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','debug','stringify','error','message','info','result','catch','sendStatus','status','end','json','undefined','offset','count','set','Content-Range','apply','reject','save','update','then','destroy','get','OpenchannelAccounts','UserProfileResource','name','send','index','Pause','mandatoryDispositionPause','rawAttributes','type','model','map','query','keys','intersection','attributes','fields','nolimit','limit','order','sort','where','filters','filter','merge','options','OpenchannelAccount','include','findAll','rows','show','params','includeAll','find','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','autoAssociation','body','describe','OpenchannelAccountId','getDispositions','length','hasOwnProperty','Disposition','removeDispositions','ids','addAnswer','CannedAnswer','findOne','pick','removeAnswers','openchannel','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','isNil','from','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','List','Contacts','OpenchannelApplication','Applications','account','applications','list','orderBy','ListId','contact','lastName','threadId','OpenchannelInteraction','externalUrl','spread','firstName','messageId','interaction','created','autoclose','close','unmanaged','*,*,*,*','OpenchannelMessage','AttachmentId','UserId','unshift','waitForTheAssignedAgent','forcedOwnership','Start','startRouting','EventManager','notify','addApplications','sequelize','Transaction','READ_COMMITTED','priority','finally','getInteractions','Contact','User','fullname','internal'];(function(_0xfb7ee3,_0x6f1f19){var _0x5c061d=function(_0x404867){while(--_0x404867){_0xfb7ee3['push'](_0xfb7ee3['shift']());}};_0x5c061d(++_0x6f1f19);}(_0x8f05,0x17f));var _0x58f0=function(_0x3498e5,_0x1f78fd){_0x3498e5=_0x3498e5-0x0;var _0x3fe3fd=_0x8f05[_0x3498e5];return _0x3fe3fd;};'use strict';var emlformat=require(_0x58f0('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x58f0('0x1'));var jsonpatch=require(_0x58f0('0x2'));var rp=require(_0x58f0('0x3'));var moment=require(_0x58f0('0x4'));var BPromise=require(_0x58f0('0x5'));var Mustache=require('mustache');var util=require(_0x58f0('0x6'));var path=require(_0x58f0('0x7'));var sox=require(_0x58f0('0x8'));var csv=require(_0x58f0('0x9'));var ejs=require(_0x58f0('0xa'));var fs=require('fs');var fs_extra=require(_0x58f0('0xb'));var _=require(_0x58f0('0xc'));var squel=require('squel');var crypto=require(_0x58f0('0xd'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x58f0('0x9'));var querystring=require(_0x58f0('0xe'));var Papa=require(_0x58f0('0xf'));var Redis=require(_0x58f0('0x10'));var authService=require(_0x58f0('0x11'));var qs=require(_0x58f0('0x12'));var as=require(_0x58f0('0x13'));var hardwareService=require(_0x58f0('0x14'));var logger=require(_0x58f0('0x15'))(_0x58f0('0x16'));var utils=require(_0x58f0('0x17'));var config=require(_0x58f0('0x18'));var licenseUtil=require('../../config/license/util');var db=require(_0x58f0('0x19'))['db'];config['redis']=_[_0x58f0('0x1a')](config[_0x58f0('0x1b')],{'host':_0x58f0('0x1c'),'port':0x18eb});var socket=require(_0x58f0('0x1d'))(new Redis(config[_0x58f0('0x1b')]));require('./openchannelAccount.socket')[_0x58f0('0x1e')](socket);var jayson=require(_0x58f0('0x1f'));var client=jayson[_0x58f0('0x20')][_0x58f0('0x21')]({'port':0x232c});var client9002=jayson[_0x58f0('0x20')][_0x58f0('0x21')]({'port':0x232a});function respondWithRpcPromise(_0x12e0e4,_0x489422,_0x443eee,_0x53dc8a){return new BPromise(function(_0x4c6156,_0x199ad3){var _0x8a19e0=_0x53dc8a||client;return _0x8a19e0['request'](_0x12e0e4,_0x443eee)['then'](function(_0x3f9df9){logger['info'](_0x58f0('0x22'),_0x489422,_0x58f0('0x23'));logger[_0x58f0('0x24')]('OpenchannelAccount,\x20%s,\x20%s,\x20%s',_0x489422,'request\x20sent',JSON[_0x58f0('0x25')](_0x3f9df9));if(_0x3f9df9[_0x58f0('0x26')]){if(_0x3f9df9['error']['code']===0x1f4){logger[_0x58f0('0x26')](_0x58f0('0x22'),_0x489422,_0x3f9df9[_0x58f0('0x26')][_0x58f0('0x27')]);return _0x199ad3(_0x3f9df9[_0x58f0('0x26')]['message']);}logger[_0x58f0('0x26')]('OpenchannelAccount,\x20%s,\x20%s',_0x489422,_0x3f9df9['error'][_0x58f0('0x27')]);return _0x4c6156(_0x3f9df9[_0x58f0('0x26')][_0x58f0('0x27')]);}else{logger[_0x58f0('0x28')](_0x58f0('0x22'),_0x489422,_0x58f0('0x23'));_0x4c6156(_0x3f9df9[_0x58f0('0x29')][_0x58f0('0x27')]);}})[_0x58f0('0x2a')](function(_0x2bf9cd){logger['error'](_0x58f0('0x22'),_0x489422,_0x2bf9cd);_0x199ad3(_0x2bf9cd);});});}function respondWithStatusCode(_0x50b83e,_0x3ceb4a){_0x3ceb4a=_0x3ceb4a||0xcc;return function(_0x17cff0){if(_0x17cff0){return _0x50b83e[_0x58f0('0x2b')](_0x3ceb4a);}return _0x50b83e[_0x58f0('0x2c')](_0x3ceb4a)[_0x58f0('0x2d')]();};}function respondWithResult(_0x4268e0,_0x4d36c7){_0x4d36c7=_0x4d36c7||0xc8;return function(_0x39efbc){if(_0x39efbc){return _0x4268e0[_0x58f0('0x2c')](_0x4d36c7)[_0x58f0('0x2e')](_0x39efbc);}};}function respondWithFilteredResult(_0x1daaee,_0x2b97fa){return function(_0x4cda3c){if(_0x4cda3c){var _0x5dbfe6=typeof _0x2b97fa['offset']===_0x58f0('0x2f')&&typeof _0x2b97fa['limit']===_0x58f0('0x2f');var _0x429eb8=_0x4cda3c['count'];var _0xf3a9c8=_0x5dbfe6?0x0:_0x2b97fa[_0x58f0('0x30')];var _0x39f473=_0x5dbfe6?_0x4cda3c[_0x58f0('0x31')]:_0x2b97fa[_0x58f0('0x30')]+_0x2b97fa['limit'];var _0x58ea59;if(_0x39f473>=_0x429eb8){_0x39f473=_0x429eb8;_0x58ea59=0xc8;}else{_0x58ea59=0xce;}_0x1daaee[_0x58f0('0x2c')](_0x58ea59);return _0x1daaee[_0x58f0('0x32')](_0x58f0('0x33'),_0xf3a9c8+'-'+_0x39f473+'/'+_0x429eb8)[_0x58f0('0x2e')](_0x4cda3c);}return null;};}function patchUpdates(_0x74562){return function(_0x5da849){try{jsonpatch[_0x58f0('0x34')](_0x5da849,_0x74562,!![]);}catch(_0x10ddde){return BPromise[_0x58f0('0x35')](_0x10ddde);}return _0x5da849[_0x58f0('0x36')]();};}function saveUpdates(_0x2b97de,_0x306f90){return function(_0x471713){if(_0x471713){return _0x471713[_0x58f0('0x37')](_0x2b97de)[_0x58f0('0x38')](function(_0x244f23){return _0x244f23;});}return null;};}function removeEntity(_0x74a521,_0x4f460e){return function(_0x3758a7){if(_0x3758a7){return _0x3758a7[_0x58f0('0x39')]()[_0x58f0('0x38')](function(){var _0x190976=_0x3758a7[_0x58f0('0x3a')]({'plain':!![]});var _0x419392=_0x58f0('0x3b');return db[_0x58f0('0x3c')][_0x58f0('0x39')]({'where':{'type':_0x419392,'resourceId':_0x190976['id']}})['then'](function(){return _0x3758a7;});})[_0x58f0('0x38')](function(){_0x74a521[_0x58f0('0x2c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x4a8ccc,_0x449c8c){return function(_0x13ad17){if(!_0x13ad17){_0x4a8ccc[_0x58f0('0x2b')](0x194);}return _0x13ad17;};}function handleError(_0x40be99,_0x48fcb2){_0x48fcb2=_0x48fcb2||0x1f4;return function(_0x50461b){logger[_0x58f0('0x26')](_0x50461b['stack']);if(_0x50461b[_0x58f0('0x3d')]){delete _0x50461b[_0x58f0('0x3d')];}_0x40be99[_0x58f0('0x2c')](_0x48fcb2)[_0x58f0('0x3e')](_0x50461b);};}exports[_0x58f0('0x3f')]=function(_0x5cc2bb,_0x347209){var _0x22aab2={'include':[{'model':db[_0x58f0('0x40')],'as':_0x58f0('0x41')}]},_0x63c233={},_0x3a50e0={'count':0x0,'rows':[]};var _0x5b3fc9=_['map'](db['OpenchannelAccount'][_0x58f0('0x42')],function(_0x4a7c79){return{'name':_0x4a7c79['fieldName'],'type':_0x4a7c79[_0x58f0('0x43')]['key']};});_0x63c233[_0x58f0('0x44')]=_[_0x58f0('0x45')](_0x5b3fc9,'name');_0x63c233[_0x58f0('0x46')]=_[_0x58f0('0x47')](_0x5cc2bb[_0x58f0('0x46')]);_0x63c233['filters']=_[_0x58f0('0x48')](_0x63c233[_0x58f0('0x44')],_0x63c233[_0x58f0('0x46')]);_0x22aab2[_0x58f0('0x49')]=_[_0x58f0('0x48')](_0x63c233[_0x58f0('0x44')],qs[_0x58f0('0x4a')](_0x5cc2bb[_0x58f0('0x46')]['fields']));_0x22aab2[_0x58f0('0x49')]=_0x22aab2[_0x58f0('0x49')]['length']?_0x22aab2[_0x58f0('0x49')]:_0x63c233[_0x58f0('0x44')];if(!_0x5cc2bb[_0x58f0('0x46')]['hasOwnProperty'](_0x58f0('0x4b'))){_0x22aab2[_0x58f0('0x4c')]=qs[_0x58f0('0x4c')](_0x5cc2bb[_0x58f0('0x46')][_0x58f0('0x4c')]);_0x22aab2[_0x58f0('0x30')]=qs[_0x58f0('0x30')](_0x5cc2bb[_0x58f0('0x46')]['offset']);}_0x22aab2[_0x58f0('0x4d')]=qs[_0x58f0('0x4e')](_0x5cc2bb[_0x58f0('0x46')][_0x58f0('0x4e')]);_0x22aab2[_0x58f0('0x4f')]=qs[_0x58f0('0x50')](_['pick'](_0x5cc2bb['query'],_0x63c233[_0x58f0('0x50')]),_0x5b3fc9);if(_0x5cc2bb[_0x58f0('0x46')][_0x58f0('0x51')]){_0x22aab2[_0x58f0('0x4f')]=_[_0x58f0('0x52')](_0x22aab2[_0x58f0('0x4f')],{'$or':_[_0x58f0('0x45')](_0x5b3fc9,function(_0x18c063){if(_0x18c063[_0x58f0('0x43')]!=='VIRTUAL'){var _0x4acba2={};_0x4acba2[_0x18c063[_0x58f0('0x3d')]]={'$like':'%'+_0x5cc2bb['query'][_0x58f0('0x51')]+'%'};return _0x4acba2;}})});}_0x22aab2=_['merge']({},_0x22aab2,_0x5cc2bb[_0x58f0('0x53')]);var _0x17de75={'where':_0x22aab2[_0x58f0('0x4f')]};return db[_0x58f0('0x54')][_0x58f0('0x31')](_0x17de75)['then'](function(_0x229d8e){_0x3a50e0['count']=_0x229d8e;if(_0x5cc2bb[_0x58f0('0x46')]['includeAll']){_0x22aab2[_0x58f0('0x55')]=[{'all':!![]}];}return db[_0x58f0('0x54')][_0x58f0('0x56')](_0x22aab2);})[_0x58f0('0x38')](function(_0x539f18){_0x3a50e0[_0x58f0('0x57')]=_0x539f18;return _0x3a50e0;})[_0x58f0('0x38')](respondWithFilteredResult(_0x347209,_0x22aab2))[_0x58f0('0x2a')](handleError(_0x347209,null));};exports[_0x58f0('0x58')]=function(_0x361507,_0x57b2b1){var _0x18eca3={'raw':![],'where':{'id':_0x361507[_0x58f0('0x59')]['id']},'include':[{'model':db[_0x58f0('0x40')],'as':_0x58f0('0x41')}]},_0x1dbdbf={};_0x1dbdbf['model']=_[_0x58f0('0x47')](db[_0x58f0('0x54')][_0x58f0('0x42')]);_0x1dbdbf[_0x58f0('0x46')]=_[_0x58f0('0x47')](_0x361507[_0x58f0('0x46')]);_0x1dbdbf[_0x58f0('0x50')]=_[_0x58f0('0x48')](_0x1dbdbf[_0x58f0('0x44')],_0x1dbdbf[_0x58f0('0x46')]);_0x18eca3[_0x58f0('0x49')]=_['intersection'](_0x1dbdbf[_0x58f0('0x44')],qs['fields'](_0x361507['query'][_0x58f0('0x4a')]));_0x18eca3[_0x58f0('0x49')]=_0x18eca3[_0x58f0('0x49')]['length']?_0x18eca3[_0x58f0('0x49')]:_0x1dbdbf[_0x58f0('0x44')];if(_0x361507[_0x58f0('0x46')][_0x58f0('0x5a')]){_0x18eca3['include']=[{'all':!![]}];}_0x18eca3=_[_0x58f0('0x52')]({},_0x18eca3,_0x361507[_0x58f0('0x53')]);return db[_0x58f0('0x54')][_0x58f0('0x5b')](_0x18eca3)['then'](handleEntityNotFound(_0x57b2b1,null))['then'](respondWithResult(_0x57b2b1,null))[_0x58f0('0x2a')](handleError(_0x57b2b1,null));};exports['create']=function(_0x1e2082,_0x3e02ad){return db[_0x58f0('0x54')][_0x58f0('0x5c')](_0x1e2082['body'],{})[_0x58f0('0x38')](function(_0x272f38){var _0x2dbf6d=_0x1e2082[_0x58f0('0x5d')][_0x58f0('0x3a')]({'plain':!![]});if(!_0x2dbf6d)throw new Error(_0x58f0('0x5e'));if(_0x2dbf6d[_0x58f0('0x5f')]===_0x58f0('0x5d')){var _0x30e8dc=_0x272f38[_0x58f0('0x3a')]({'plain':!![]});var _0x6381f3=_0x58f0('0x3b');return db['UserProfileSection'][_0x58f0('0x5b')]({'where':{'name':_0x6381f3,'userProfileId':_0x2dbf6d['userProfileId']},'raw':!![]})['then'](function(_0x5c6a6b){if(_0x5c6a6b&&_0x5c6a6b[_0x58f0('0x60')]===0x0){return db[_0x58f0('0x3c')]['create']({'name':_0x30e8dc[_0x58f0('0x3d')],'resourceId':_0x30e8dc['id'],'type':_0x5c6a6b[_0x58f0('0x3d')],'sectionId':_0x5c6a6b['id']},{})[_0x58f0('0x38')](function(){return _0x272f38;});}else{return _0x272f38;}})[_0x58f0('0x2a')](function(_0x4b5e56){logger[_0x58f0('0x26')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x4b5e56);throw _0x4b5e56;});}return _0x272f38;})[_0x58f0('0x38')](respondWithResult(_0x3e02ad,0xc9))[_0x58f0('0x2a')](handleError(_0x3e02ad,null));};exports[_0x58f0('0x37')]=function(_0x35a148,_0x114329){if(_0x35a148[_0x58f0('0x61')]['id']){delete _0x35a148[_0x58f0('0x61')]['id'];}return db[_0x58f0('0x54')][_0x58f0('0x5b')]({'where':{'id':_0x35a148[_0x58f0('0x59')]['id']},'include':[{'model':db[_0x58f0('0x40')],'as':_0x58f0('0x41')}]})['then'](handleEntityNotFound(_0x114329,null))[_0x58f0('0x38')](saveUpdates(_0x35a148[_0x58f0('0x61')],null))[_0x58f0('0x38')](respondWithResult(_0x114329,null))['catch'](handleError(_0x114329,null));};exports[_0x58f0('0x39')]=function(_0x360aeb,_0x8af34c){return db[_0x58f0('0x54')][_0x58f0('0x5b')]({'where':{'id':_0x360aeb[_0x58f0('0x59')]['id']}})['then'](handleEntityNotFound(_0x8af34c,null))[_0x58f0('0x38')](removeEntity(_0x8af34c,null))[_0x58f0('0x2a')](handleError(_0x8af34c,null));};exports[_0x58f0('0x62')]=function(_0x154e33,_0x49daa1){return db[_0x58f0('0x54')][_0x58f0('0x62')]()[_0x58f0('0x38')](respondWithResult(_0x49daa1,null))[_0x58f0('0x2a')](handleError(_0x49daa1,null));};exports['addDisposition']=function(_0x47b142,_0x20cbdb,_0x163b13){if(_0x47b142[_0x58f0('0x61')]['id']){delete _0x47b142['body']['id'];}return db['OpenchannelAccount'][_0x58f0('0x5b')]({'where':{'id':_0x47b142['params']['id']}})['then'](handleEntityNotFound(_0x20cbdb,null))['then'](function(_0xee0d0a){if(_0xee0d0a){_0x47b142[_0x58f0('0x61')][_0x58f0('0x63')]=_0xee0d0a['id'];return db['Disposition'][_0x58f0('0x5c')](_0x47b142[_0x58f0('0x61')]);}})['then'](respondWithResult(_0x20cbdb,null))['catch'](handleError(_0x20cbdb,null));};exports[_0x58f0('0x64')]=function(_0x1fd60c,_0x5e4212,_0x13399e){var _0x58f606={'raw':![],'where':{}};var _0x5a7e84={};var _0x2da62a={'count':0x0,'rows':[]};return db[_0x58f0('0x54')]['findOne']({'where':{'id':_0x1fd60c['params']['id']}})[_0x58f0('0x38')](handleEntityNotFound(_0x5e4212,null))[_0x58f0('0x38')](function(_0x44339f){if(_0x44339f){_0x5a7e84[_0x58f0('0x44')]=_[_0x58f0('0x47')](db['Disposition']['rawAttributes']);_0x5a7e84['query']=_[_0x58f0('0x47')](_0x1fd60c[_0x58f0('0x46')]);_0x5a7e84[_0x58f0('0x50')]=_[_0x58f0('0x48')](_0x5a7e84[_0x58f0('0x44')],_0x5a7e84[_0x58f0('0x46')]);_0x58f606['attributes']=_[_0x58f0('0x48')](_0x5a7e84['model'],qs['fields'](_0x1fd60c[_0x58f0('0x46')][_0x58f0('0x4a')]));_0x58f606[_0x58f0('0x49')]=_0x58f606['attributes'][_0x58f0('0x65')]?_0x58f606['attributes']:_0x5a7e84['model'];if(!_0x1fd60c[_0x58f0('0x46')][_0x58f0('0x66')](_0x58f0('0x4b'))){_0x58f606[_0x58f0('0x4c')]=qs[_0x58f0('0x4c')](_0x1fd60c[_0x58f0('0x46')][_0x58f0('0x4c')]);_0x58f606[_0x58f0('0x30')]=qs['offset'](_0x1fd60c[_0x58f0('0x46')][_0x58f0('0x30')]);}_0x58f606['order']=qs[_0x58f0('0x4e')](_0x1fd60c[_0x58f0('0x46')]['sort']);_0x58f606[_0x58f0('0x4f')]=qs[_0x58f0('0x50')](_['pick'](_0x1fd60c[_0x58f0('0x46')],_0x5a7e84[_0x58f0('0x50')]));_0x58f606['where']['OpenchannelAccountId']=_0x44339f['id'];if(_0x1fd60c[_0x58f0('0x46')][_0x58f0('0x51')]){_0x58f606[_0x58f0('0x4f')]=_[_0x58f0('0x52')](_0x58f606[_0x58f0('0x4f')],{'$or':_[_0x58f0('0x45')](_0x58f606[_0x58f0('0x49')],function(_0x219fe6){var _0x1d6f2e={};_0x1d6f2e[_0x219fe6]={'$like':'%'+_0x1fd60c[_0x58f0('0x46')][_0x58f0('0x51')]+'%'};return _0x1d6f2e;})});}_0x58f606=_[_0x58f0('0x52')]({},_0x58f606,_0x1fd60c[_0x58f0('0x53')]);return db[_0x58f0('0x67')]['count']({'where':_0x58f606[_0x58f0('0x4f')]})[_0x58f0('0x38')](function(_0x5162f8){_0x2da62a[_0x58f0('0x31')]=_0x5162f8;if(_0x1fd60c[_0x58f0('0x46')][_0x58f0('0x5a')]){_0x58f606[_0x58f0('0x55')]=[{'all':!![]}];}return db[_0x58f0('0x67')][_0x58f0('0x56')](_0x58f606);})[_0x58f0('0x38')](function(_0x23a3cb){_0x2da62a[_0x58f0('0x57')]=_0x23a3cb;return _0x2da62a;});}})['then'](respondWithFilteredResult(_0x5e4212,_0x58f606))[_0x58f0('0x2a')](handleError(_0x5e4212,null));};exports[_0x58f0('0x68')]=function(_0x3febeb,_0x15c963,_0x50d54f){return db[_0x58f0('0x54')]['find']({'where':{'id':_0x3febeb[_0x58f0('0x59')]['id']}})[_0x58f0('0x38')](handleEntityNotFound(_0x15c963,null))[_0x58f0('0x38')](function(_0x1b81f3){if(_0x1b81f3){return _0x1b81f3['removeDispositions'](_0x3febeb['query'][_0x58f0('0x69')]);}})[_0x58f0('0x38')](respondWithStatusCode(_0x15c963,null))[_0x58f0('0x2a')](handleError(_0x15c963,null));};exports[_0x58f0('0x6a')]=function(_0x3cd443,_0xbb1b9a,_0x5a4952){if(_0x3cd443[_0x58f0('0x61')]['id']){delete _0x3cd443[_0x58f0('0x61')]['id'];}return db[_0x58f0('0x54')]['find']({'where':{'id':_0x3cd443[_0x58f0('0x59')]['id']}})['then'](handleEntityNotFound(_0xbb1b9a,null))[_0x58f0('0x38')](function(_0x6d67cf){if(_0x6d67cf){_0x3cd443[_0x58f0('0x61')][_0x58f0('0x63')]=_0x6d67cf['id'];return db[_0x58f0('0x6b')][_0x58f0('0x5c')](_0x3cd443['body']);}})[_0x58f0('0x38')](respondWithResult(_0xbb1b9a,null))[_0x58f0('0x2a')](handleError(_0xbb1b9a,null));};exports['getAnswers']=function(_0x2b5833,_0x10b301,_0x3f7b03){var _0x56980b={'raw':![],'where':{}};var _0x3cb448={};var _0x1057f0={'count':0x0,'rows':[]};return db['OpenchannelAccount'][_0x58f0('0x6c')]({'where':{'id':_0x2b5833[_0x58f0('0x59')]['id']}})[_0x58f0('0x38')](handleEntityNotFound(_0x10b301,null))['then'](function(_0xca4ca8){if(_0xca4ca8){_0x3cb448[_0x58f0('0x44')]=_[_0x58f0('0x47')](db[_0x58f0('0x6b')][_0x58f0('0x42')]);_0x3cb448[_0x58f0('0x46')]=_[_0x58f0('0x47')](_0x2b5833[_0x58f0('0x46')]);_0x3cb448[_0x58f0('0x50')]=_['intersection'](_0x3cb448['model'],_0x3cb448[_0x58f0('0x46')]);_0x56980b[_0x58f0('0x49')]=_[_0x58f0('0x48')](_0x3cb448[_0x58f0('0x44')],qs[_0x58f0('0x4a')](_0x2b5833[_0x58f0('0x46')]['fields']));_0x56980b[_0x58f0('0x49')]=_0x56980b[_0x58f0('0x49')][_0x58f0('0x65')]?_0x56980b[_0x58f0('0x49')]:_0x3cb448[_0x58f0('0x44')];if(!_0x2b5833[_0x58f0('0x46')][_0x58f0('0x66')]('nolimit')){_0x56980b[_0x58f0('0x4c')]=qs[_0x58f0('0x4c')](_0x2b5833[_0x58f0('0x46')][_0x58f0('0x4c')]);_0x56980b[_0x58f0('0x30')]=qs[_0x58f0('0x30')](_0x2b5833[_0x58f0('0x46')][_0x58f0('0x30')]);}_0x56980b[_0x58f0('0x4d')]=qs[_0x58f0('0x4e')](_0x2b5833[_0x58f0('0x46')][_0x58f0('0x4e')]);_0x56980b[_0x58f0('0x4f')]=qs[_0x58f0('0x50')](_[_0x58f0('0x6d')](_0x2b5833[_0x58f0('0x46')],_0x3cb448['filters']));_0x56980b[_0x58f0('0x4f')][_0x58f0('0x63')]=_0xca4ca8['id'];if(_0x2b5833[_0x58f0('0x46')][_0x58f0('0x51')]){_0x56980b[_0x58f0('0x4f')]=_[_0x58f0('0x52')](_0x56980b[_0x58f0('0x4f')],{'$or':_[_0x58f0('0x45')](_0x56980b[_0x58f0('0x49')],function(_0x576c73){var _0x19f538={};_0x19f538[_0x576c73]={'$like':'%'+_0x2b5833[_0x58f0('0x46')]['filter']+'%'};return _0x19f538;})});}_0x56980b=_[_0x58f0('0x52')]({},_0x56980b,_0x2b5833[_0x58f0('0x53')]);return db[_0x58f0('0x6b')][_0x58f0('0x31')]({'where':_0x56980b[_0x58f0('0x4f')]})[_0x58f0('0x38')](function(_0x4dd35f){_0x1057f0['count']=_0x4dd35f;if(_0x2b5833[_0x58f0('0x46')][_0x58f0('0x5a')]){_0x56980b[_0x58f0('0x55')]=[{'all':!![]}];}return db[_0x58f0('0x6b')]['findAll'](_0x56980b);})[_0x58f0('0x38')](function(_0x53c34c){_0x1057f0['rows']=_0x53c34c;return _0x1057f0;});}})['then'](respondWithFilteredResult(_0x10b301,_0x56980b))['catch'](handleError(_0x10b301,null));};exports[_0x58f0('0x6e')]=function(_0x1ba9fd,_0x40e186,_0x1a963b){return db[_0x58f0('0x54')][_0x58f0('0x5b')]({'where':{'id':_0x1ba9fd['params']['id']}})[_0x58f0('0x38')](handleEntityNotFound(_0x40e186,null))['then'](function(_0x45eb6b){if(_0x45eb6b){return _0x45eb6b['removeAnswers'](_0x1ba9fd[_0x58f0('0x46')][_0x58f0('0x69')]);}})['then'](respondWithStatusCode(_0x40e186,null))[_0x58f0('0x2a')](handleError(_0x40e186,null));};exports['notify']=function(_0x5c9e6a,_0x4fb206,_0x3edcff){var _0x5f0af5={'body':_0x5c9e6a[_0x58f0('0x61')],'channel':_0x58f0('0x6f')};var _0x4b0de9=[];var _0x351787=[];var _0x70b4ab={};var _0x30c024=![];return db[_0x58f0('0x70')]['describe']()[_0x58f0('0x38')](function(_0x3992f0){if(!_0x3992f0){throw new db[(_0x58f0('0x71'))][(_0x58f0('0x72'))](_0x58f0('0x73'));}_0x4b0de9=_[_0x58f0('0x74')](_[_0x58f0('0x47')](_0x3992f0),[_0x58f0('0x75'),'updatedAt']);_0x351787=_['difference'](_[_0x58f0('0x47')](_0x3992f0),[_0x58f0('0x75'),_0x58f0('0x76'),'CompanyId','ListId']);if(_0x5c9e6a[_0x58f0('0x61')]['id']){delete _0x5c9e6a[_0x58f0('0x61')]['id'];}if(_[_0x58f0('0x77')](_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x78')])){throw new db['Sequelize'][(_0x58f0('0x72'))]('from\x20is\x20mandatory');}if(_[_0x58f0('0x77')](_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x61')])||_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x61')]===''){throw new db[(_0x58f0('0x71'))][(_0x58f0('0x72'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x58f0('0x77')](_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x79')])){throw new db[(_0x58f0('0x71'))]['ValidationError'](_0x58f0('0x7a')+_0x351787);}if(!_[_0x58f0('0x7b')](_0x351787,_0x5c9e6a['body'][_0x58f0('0x79')])){throw new db[(_0x58f0('0x71'))][(_0x58f0('0x72'))](_0x58f0('0x7c')+_0x351787);}_0x70b4ab[_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x79')]]=_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x78')];})[_0x58f0('0x38')](function(){return db['OpenchannelAccount'][_0x58f0('0x5b')]({'where':{'id':_0x5c9e6a[_0x58f0('0x59')]['id']},'include':[{'model':db['CmList'],'as':_0x58f0('0x7d'),'include':[{'model':db[_0x58f0('0x70')],'as':_0x58f0('0x7e'),'where':_0x70b4ab,'limit':0x1,'order':[[_0x58f0('0x76'),'DESC']]}]},{'model':db[_0x58f0('0x7f')],'as':_0x58f0('0x80')}]});})[_0x58f0('0x38')](handleEntityNotFound(_0x4fb206,null))['then'](function(_0x46bbf1){if(_0x46bbf1&&_0x46bbf1[_0x58f0('0x7d')]){_0x5f0af5[_0x58f0('0x81')]=_0x46bbf1;_0x5f0af5[_0x58f0('0x82')]=_0x46bbf1['Applications'];_0x5f0af5[_0x58f0('0x83')]=_0x46bbf1['List'];_0x5f0af5['applications']=_[_0x58f0('0x84')](_0x5f0af5[_0x58f0('0x82')],['priority'],['asc']);if(_0x5f0af5[_0x58f0('0x81')][_0x58f0('0x80')]){delete _0x5f0af5[_0x58f0('0x81')][_0x58f0('0x80')];}if(_0x5f0af5[_0x58f0('0x81')]['List']&&_0x5f0af5[_0x58f0('0x81')][_0x58f0('0x7d')][_0x58f0('0x7e')][_0x58f0('0x65')]){return _0x5f0af5[_0x58f0('0x81')][_0x58f0('0x7d')]['Contacts'][0x0];}var _0x19d5ba=_[_0x58f0('0x1a')](_0x5c9e6a[_0x58f0('0x61')],{'firstName':_0x5c9e6a[_0x58f0('0x61')]['from'],'ListId':_0x46bbf1[_0x58f0('0x85')]});_0x19d5ba[_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x79')]]=_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x78')];return db[_0x58f0('0x70')][_0x58f0('0x5c')](_0x19d5ba,{'fields':_0x4b0de9,'raw':!![]});}})[_0x58f0('0x38')](handleEntityNotFound(_0x4fb206,null))[_0x58f0('0x38')](function(_0x2cac81){_0x5f0af5[_0x58f0('0x86')]=_0x2cac81;if(_0x2cac81){var _0x4de82b={'ContactId':_0x2cac81['id'],'OpenchannelAccountId':_0x5c9e6a[_0x58f0('0x59')]['id'],'from':(_0x2cac81['firstName']||'')+'\x20'+(_0x2cac81[_0x58f0('0x87')]||'')};var _0x5ae696={'OpenchannelAccountId':_0x5c9e6a[_0x58f0('0x59')]['id'],'closed':![]};if(_0x5c9e6a['body'][_0x58f0('0x88')]){_0x5ae696[_0x58f0('0x88')]=_0x5c9e6a[_0x58f0('0x61')]['threadId'];return db[_0x58f0('0x89')][_0x58f0('0x5b')]({'where':_0x5ae696})['then'](function(_0xb8b7b7){if(_0xb8b7b7){return[_0xb8b7b7,![]];}_0x4de82b[_0x58f0('0x88')]=_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x88')];_0x4de82b[_0x58f0('0x8a')]=_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x8a')];return db[_0x58f0('0x89')][_0x58f0('0x5c')](_0x4de82b)['then'](function(_0x16ad6a){return[_0x16ad6a,!![]];});});}else{_0x5ae696[_0x58f0('0x88')]=null;}_0x5ae696['ContactId']=_0x2cac81['id'];return db[_0x58f0('0x89')][_0x58f0('0x5b')]({'where':_0x5ae696})[_0x58f0('0x38')](function(_0x40a707){if(_0x40a707){return[_0x40a707,![]];}return db['OpenchannelInteraction']['create'](_0x4de82b)[_0x58f0('0x38')](function(_0x5869d2){return[_0x5869d2,!![]];});});}})[_0x58f0('0x8b')](function(_0x2fc394,_0x2c602d){if(_0x2fc394){_0x30c024=_0x2c602d;if(!_0x2c602d){var _0x3a2d08={'from':(_0x5f0af5[_0x58f0('0x86')][_0x58f0('0x8c')]||'')+'\x20'+(_0x5f0af5[_0x58f0('0x86')][_0x58f0('0x87')]||'')};if(_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x88')]&&_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x8d')]&&_0x5c9e6a['body'][_0x58f0('0x88')]!=_0x5c9e6a[_0x58f0('0x61')]['messageId']){_0x3a2d08[_0x58f0('0x88')]=_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x8d')];}return _0x2fc394['update'](_0x3a2d08);}else{return _0x2fc394;}}})[_0x58f0('0x38')](function(_0x1177d7){_0x5f0af5[_0x58f0('0x8e')]=_0x1177d7[_0x58f0('0x3a')]({'plain':!![]});_0x5f0af5['interaction'][_0x58f0('0x8f')]=_0x30c024;if(_0x5f0af5[_0x58f0('0x8e')][_0x58f0('0x8f')]){if(_0x5f0af5['account'][_0x58f0('0x90')]){_0x5f0af5['applications']['push']({'id':0x0,'priority':_0x5f0af5[_0x58f0('0x82')][_0x58f0('0x65')]+0x1,'app':_0x58f0('0x91'),'appdata':_0x58f0('0x92'),'interval':_0x58f0('0x93')});}}return db[_0x58f0('0x94')][_0x58f0('0x5c')]({'body':_0x5c9e6a['body'][_0x58f0('0x61')],'OpenchannelAccountId':_0x5c9e6a[_0x58f0('0x59')]['id'],'OpenchannelInteractionId':_0x1177d7['id'],'direction':'in','ContactId':_0x5f0af5[_0x58f0('0x86')]['id'],'AttachmentId':_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x95')]});})[_0x58f0('0x38')](function(_0x3ded16){_0x5f0af5[_0x58f0('0x27')]=_0x3ded16;if(_0x5f0af5[_0x58f0('0x8e')]['UserId']){return db['User'][_0x58f0('0x5b')]({'attributes':['id',_0x58f0('0x3d')],'where':{'id':_0x5f0af5['interaction'][_0x58f0('0x96')]}})[_0x58f0('0x38')](function(_0x1adf3b){if(_0x1adf3b){_0x5f0af5['applications'][_0x58f0('0x97')]({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x1adf3b[_0x58f0('0x3d')]+','+(_0x5f0af5[_0x58f0('0x81')][_0x58f0('0x98')]||0xa),'interval':_0x58f0('0x93')});_0x5f0af5[_0x58f0('0x99')]=![];}return respondWithRpcPromise(_0x58f0('0x9a'),_0x58f0('0x9b'),_0x5f0af5);});}return respondWithRpcPromise(_0x58f0('0x9a'),_0x58f0('0x9b'),_0x5f0af5);})[_0x58f0('0x38')](function(_0x5102c1){respondWithRpcPromise(_0x58f0('0x9c'),_0x58f0('0x9c'),{'event':_0x58f0('0x9d'),'message':_0x5102c1},client9002);return _0x5102c1;})[_0x58f0('0x38')](respondWithResult(_0x4fb206,null))[_0x58f0('0x2a')](handleError(_0x4fb206,null));};exports[_0x58f0('0x9e')]=function(_0x466a5c,_0x2abe6f){var _0x329c33=_0x466a5c[_0x58f0('0x59')]['id'];var _0x262631=_0x466a5c[_0x58f0('0x61')];var _0x1c080b=0xc8;var _0x551f65=null;return db[_0x58f0('0x9f')]['transaction']({'isolationLevel':db['sequelize'][_0x58f0('0xa0')]['ISOLATION_LEVELS'][_0x58f0('0xa1')]},function(_0x367901){return db[_0x58f0('0x54')][_0x58f0('0x6c')]({'where':{'id':_0x329c33},'transaction':_0x367901})[_0x58f0('0x38')](function(_0x392e6b){if(_0x392e6b){return db[_0x58f0('0x7f')]['destroy']({'where':{'OpenchannelAccountId':_0x329c33},'transaction':_0x367901})[_0x58f0('0x38')](function(){var _0xc85dd5=_['map'](_0x262631,function(_0x1e68ab){_0x1e68ab[_0x58f0('0x63')]=_0x329c33;return _0x1e68ab;});return db[_0x58f0('0x7f')]['bulkCreate'](_0xc85dd5,{'transaction':_0x367901});});}else{_0x1c080b=0x194;_0x551f65=[];}});})[_0x58f0('0x38')](function(){if(_0x1c080b!==0x194){return db[_0x58f0('0x7f')]['findAndCountAll']({'where':{'OpenchannelAccountId':_0x329c33},'order':_0x58f0('0xa2')})['then'](function(_0x5d2e84){_0x551f65=_0x5d2e84;});}})[_0x58f0('0x2a')](function(_0x4f06dd){_0x1c080b=0x1f4;logger['error'](_0x4f06dd['stack']);if(_0x4f06dd[_0x58f0('0x3d')]){delete _0x4f06dd[_0x58f0('0x3d')];}_0x551f65=_0x4f06dd;})[_0x58f0('0xa3')](function(){if(_0x551f65===null){_0x2abe6f[_0x58f0('0x2b')](_0x1c080b);}else{if(_0x1c080b===0x1f4){_0x2abe6f[_0x58f0('0x2c')](_0x1c080b)[_0x58f0('0x3e')](_0x551f65);}else{_0x2abe6f[_0x58f0('0x2c')](_0x1c080b)['json'](_0x551f65);}}});};exports['getApplications']=function(_0x13180a,_0x30c12b,_0x30d644){var _0x3ccf7a={};var _0x18a63e={};var _0x379fb9;var _0x5882ed;return db[_0x58f0('0x54')]['findOne']({'where':{'id':_0x13180a['params']['id']}})[_0x58f0('0x38')](handleEntityNotFound(_0x30c12b,null))['then'](function(_0x5e370a){if(_0x5e370a){_0x379fb9=_0x5e370a;_0x18a63e[_0x58f0('0x44')]=_['keys'](db[_0x58f0('0x7f')][_0x58f0('0x42')]);_0x18a63e[_0x58f0('0x46')]=_[_0x58f0('0x47')](_0x13180a['query']);_0x18a63e['filters']=_[_0x58f0('0x48')](_0x18a63e[_0x58f0('0x44')],_0x18a63e[_0x58f0('0x46')]);_0x3ccf7a['attributes']=_[_0x58f0('0x48')](_0x18a63e['model'],qs[_0x58f0('0x4a')](_0x13180a[_0x58f0('0x46')][_0x58f0('0x4a')]));_0x3ccf7a['attributes']=_0x3ccf7a[_0x58f0('0x49')][_0x58f0('0x65')]?_0x3ccf7a[_0x58f0('0x49')]:_0x18a63e[_0x58f0('0x44')];_0x3ccf7a[_0x58f0('0x4d')]=qs[_0x58f0('0x4e')](_0x13180a[_0x58f0('0x46')][_0x58f0('0x4e')]);_0x3ccf7a[_0x58f0('0x4f')]=qs['filters'](_[_0x58f0('0x6d')](_0x13180a['query'],_0x18a63e[_0x58f0('0x50')]));if(_0x13180a[_0x58f0('0x46')]['filter']){_0x3ccf7a[_0x58f0('0x4f')]=_[_0x58f0('0x52')](_0x3ccf7a[_0x58f0('0x4f')],{'$or':_[_0x58f0('0x45')](_0x3ccf7a[_0x58f0('0x49')],function(_0x14a5fc){var _0x3a1e5d={};_0x3a1e5d[_0x14a5fc]={'$like':'%'+_0x13180a[_0x58f0('0x46')][_0x58f0('0x51')]+'%'};return _0x3a1e5d;})});}_0x3ccf7a=_[_0x58f0('0x52')]({},_0x3ccf7a,_0x13180a[_0x58f0('0x53')]);return _0x379fb9['getApplications'](_0x3ccf7a);}})[_0x58f0('0x38')](function(_0x6fd16e){if(_0x6fd16e){_0x5882ed=_0x6fd16e[_0x58f0('0x65')];if(!_0x13180a['query']['hasOwnProperty'](_0x58f0('0x4b'))){_0x3ccf7a[_0x58f0('0x4c')]=qs[_0x58f0('0x4c')](_0x13180a[_0x58f0('0x46')][_0x58f0('0x4c')]);_0x3ccf7a[_0x58f0('0x30')]=qs[_0x58f0('0x30')](_0x13180a[_0x58f0('0x46')][_0x58f0('0x30')]);}return _0x379fb9['getApplications'](_0x3ccf7a);}})[_0x58f0('0x38')](function(_0x53b0ed){if(_0x53b0ed){return _0x53b0ed?{'count':_0x5882ed,'rows':_0x53b0ed}:null;}})[_0x58f0('0x38')](respondWithResult(_0x30c12b,null))[_0x58f0('0x2a')](handleError(_0x30c12b,null));};exports[_0x58f0('0xa4')]=function(_0x1931f5,_0x1028fc,_0x5ad008){var _0x203052={'raw':![],'where':{}};var _0x3d91b5={};var _0x37a801={'count':0x0,'rows':[]};return db[_0x58f0('0x54')][_0x58f0('0x6c')]({'where':{'id':_0x1931f5[_0x58f0('0x59')]['id']}})[_0x58f0('0x38')](handleEntityNotFound(_0x1028fc,null))[_0x58f0('0x38')](function(_0x3df0bf){if(_0x3df0bf){_0x3d91b5[_0x58f0('0x44')]=_['keys'](db[_0x58f0('0x89')][_0x58f0('0x42')]);_0x3d91b5[_0x58f0('0x46')]=_[_0x58f0('0x47')](_0x1931f5[_0x58f0('0x46')]);_0x3d91b5['filters']=_['intersection'](_0x3d91b5[_0x58f0('0x44')],_0x3d91b5[_0x58f0('0x46')]);_0x203052['attributes']=_[_0x58f0('0x48')](_0x3d91b5[_0x58f0('0x44')],qs[_0x58f0('0x4a')](_0x1931f5[_0x58f0('0x46')][_0x58f0('0x4a')]));_0x203052[_0x58f0('0x49')]=_0x203052[_0x58f0('0x49')][_0x58f0('0x65')]?_0x203052[_0x58f0('0x49')]:_0x3d91b5[_0x58f0('0x44')];if(!_0x1931f5['query'][_0x58f0('0x66')](_0x58f0('0x4b'))){_0x203052['limit']=qs[_0x58f0('0x4c')](_0x1931f5[_0x58f0('0x46')][_0x58f0('0x4c')]);_0x203052[_0x58f0('0x30')]=qs[_0x58f0('0x30')](_0x1931f5[_0x58f0('0x46')][_0x58f0('0x30')]);}_0x203052[_0x58f0('0x4d')]=qs[_0x58f0('0x4e')](_0x1931f5[_0x58f0('0x46')]['sort']);_0x203052['where']=qs['filters'](_[_0x58f0('0x6d')](_0x1931f5[_0x58f0('0x46')],_0x3d91b5[_0x58f0('0x50')]));_0x203052[_0x58f0('0x4f')][_0x58f0('0x63')]=_0x3df0bf['id'];if(_0x1931f5[_0x58f0('0x46')][_0x58f0('0x51')]){_0x203052[_0x58f0('0x4f')]=_['merge'](_0x203052[_0x58f0('0x4f')],{'$or':_[_0x58f0('0x45')](_0x203052[_0x58f0('0x49')],function(_0x203d6d){var _0xda5328={};_0xda5328[_0x203d6d]={'$like':'%'+_0x1931f5['query'][_0x58f0('0x51')]+'%'};return _0xda5328;})});}_0x203052=_[_0x58f0('0x52')]({},_0x203052,_0x1931f5[_0x58f0('0x53')]);return db[_0x58f0('0x89')][_0x58f0('0x31')]({'where':_0x203052[_0x58f0('0x4f')]})[_0x58f0('0x38')](function(_0x6c96cc){_0x37a801['count']=_0x6c96cc;if(_0x1931f5[_0x58f0('0x46')]['includeAll']){_0x203052[_0x58f0('0x55')]=[{'model':db[_0x58f0('0x70')],'as':_0x58f0('0xa5'),'required':![]},{'model':db[_0x58f0('0xa6')],'as':'Owner','attributes':[_0x58f0('0x3d'),_0x58f0('0xa7'),_0x58f0('0xa8')],'required':![]},{'model':db['Tag'],'as':_0x58f0('0xa9'),'attributes':['id',_0x58f0('0x3d'),_0x58f0('0xaa')],'where':_0x1931f5[_0x58f0('0x46')][_0x58f0('0xab')]?{'id':_0x1931f5[_0x58f0('0x46')]['tag']}:undefined,'required':_0x1931f5[_0x58f0('0x46')][_0x58f0('0xab')]?!![]:![]}];}return db[_0x58f0('0x89')][_0x58f0('0x56')](_0x203052);})['then'](function(_0x3653b1){_0x37a801[_0x58f0('0x57')]=_0x3653b1;return _0x37a801;});}})[_0x58f0('0x38')](respondWithFilteredResult(_0x1028fc,_0x203052))[_0x58f0('0x2a')](handleError(_0x1028fc,null));};exports[_0x58f0('0xac')]=function(_0x91c507,_0x2cdd80,_0xad6b3d){return db[_0x58f0('0x54')][_0x58f0('0x5b')]({'where':{'id':_0x91c507['params']['id']}})[_0x58f0('0x38')](handleEntityNotFound(_0x2cdd80,null))['then'](function(_0x1dc19f){if(_0x1dc19f){return _0x1dc19f['addAgents'](_0x91c507[_0x58f0('0x61')][_0x58f0('0x69')],_['omit'](_0x91c507[_0x58f0('0x61')],['ids','id'])||{})[_0x58f0('0x8b')](function(_0x4951cf){for(var _0x1385e3=0x0;_0x1385e3<_0x91c507[_0x58f0('0x61')][_0x58f0('0x69')]['length'];_0x1385e3+=0x1){socket[_0x58f0('0xad')](_0x58f0('0xae'),{'UserId':Number(_0x91c507['body']['ids'][_0x1385e3]),'OpenchannelAccountId':Number(_0x91c507[_0x58f0('0x59')]['id'])});}return _0x4951cf;});}})['then'](respondWithResult(_0x2cdd80,null))['catch'](handleError(_0x2cdd80,null));};exports[_0x58f0('0xaf')]=function(_0x1db992,_0x567f43,_0x1ef876){return db[_0x58f0('0x54')]['find']({'where':{'id':_0x1db992[_0x58f0('0x59')]['id']}})[_0x58f0('0x38')](handleEntityNotFound(_0x567f43,null))[_0x58f0('0x38')](function(_0x52dba2){if(_0x52dba2){return _0x52dba2['removeAgents'](_0x1db992[_0x58f0('0x46')]['ids'])[_0x58f0('0x38')](function(){if(_[_0x58f0('0xb0')](_0x1db992['query'][_0x58f0('0x69')])){for(var _0x36cf2b=0x0;_0x36cf2b<_0x1db992['query'][_0x58f0('0x69')]['length'];_0x36cf2b+=0x1){socket[_0x58f0('0xad')](_0x58f0('0xb1'),{'UserId':Number(_0x1db992['query'][_0x58f0('0x69')][_0x36cf2b]),'OpenchannelAccountId':Number(_0x1db992[_0x58f0('0x59')]['id'])});}}else{socket[_0x58f0('0xad')]('userOpenchannelAccount:remove',{'UserId':Number(_0x1db992['query'][_0x58f0('0x69')]),'OpenchannelAccountId':Number(_0x1db992[_0x58f0('0x59')]['id'])});}});}})[_0x58f0('0x38')](respondWithStatusCode(_0x567f43,null))[_0x58f0('0x2a')](handleError(_0x567f43,null));};exports[_0x58f0('0xb2')]=function(_0x100526,_0x34d7df,_0x297ce3){var _0x2b7f7a={};var _0x5bc936={};var _0x42a593;var _0x2de332;return db[_0x58f0('0x54')][_0x58f0('0x6c')]({'where':{'id':_0x100526[_0x58f0('0x59')]['id']}})[_0x58f0('0x38')](handleEntityNotFound(_0x34d7df,null))[_0x58f0('0x38')](function(_0x21f134){if(_0x21f134){_0x42a593=_0x21f134;_0x5bc936[_0x58f0('0x44')]=_['keys'](db['User']['rawAttributes']);_0x5bc936[_0x58f0('0x46')]=_[_0x58f0('0x47')](_0x100526[_0x58f0('0x46')]);_0x5bc936[_0x58f0('0x50')]=_['intersection'](_0x5bc936[_0x58f0('0x44')],_0x5bc936[_0x58f0('0x46')]);_0x2b7f7a[_0x58f0('0x49')]=_[_0x58f0('0x48')](_0x5bc936[_0x58f0('0x44')],qs['fields'](_0x100526[_0x58f0('0x46')][_0x58f0('0x4a')]));_0x2b7f7a['attributes']=_0x2b7f7a[_0x58f0('0x49')][_0x58f0('0x65')]?_0x2b7f7a['attributes']:_0x5bc936[_0x58f0('0x44')];_0x2b7f7a[_0x58f0('0x4d')]=qs['sort'](_0x100526[_0x58f0('0x46')][_0x58f0('0x4e')]);_0x2b7f7a[_0x58f0('0x4f')]=qs[_0x58f0('0x50')](_[_0x58f0('0x6d')](_0x100526[_0x58f0('0x46')],_0x5bc936[_0x58f0('0x50')]));if(_0x100526['query'][_0x58f0('0x51')]){_0x2b7f7a[_0x58f0('0x4f')]=_['merge'](_0x2b7f7a[_0x58f0('0x4f')],{'$or':_['map'](_0x2b7f7a['attributes'],function(_0x54b024){var _0x4caa27={};_0x4caa27[_0x54b024]={'$like':'%'+_0x100526[_0x58f0('0x46')][_0x58f0('0x51')]+'%'};return _0x4caa27;})});}_0x2b7f7a=_[_0x58f0('0x52')]({},_0x2b7f7a,_0x100526['options']);return _0x42a593['getAgents'](_0x2b7f7a);}})[_0x58f0('0x38')](function(_0x3f0bf8){if(_0x3f0bf8){_0x2de332=_0x3f0bf8[_0x58f0('0x65')];if(!_0x100526['query']['hasOwnProperty'](_0x58f0('0x4b'))){_0x2b7f7a['limit']=qs[_0x58f0('0x4c')](_0x100526[_0x58f0('0x46')][_0x58f0('0x4c')]);_0x2b7f7a[_0x58f0('0x30')]=qs[_0x58f0('0x30')](_0x100526['query'][_0x58f0('0x30')]);}return _0x42a593[_0x58f0('0xb2')](_0x2b7f7a);}})['then'](function(_0xac19a3){if(_0xac19a3){return _0xac19a3?{'count':_0x2de332,'rows':_0xac19a3}:null;}})[_0x58f0('0x38')](respondWithResult(_0x34d7df,null))[_0x58f0('0x2a')](handleError(_0x34d7df,null));};exports[_0x58f0('0x3e')]=function(_0x400513,_0x4d83f7,_0x19dd80){var _0x371057,_0xc72729,_0xdbf418;if(_[_0x58f0('0x77')](_0x400513[_0x58f0('0x61')][_0x58f0('0x61')])||_0x400513[_0x58f0('0x61')][_0x58f0('0x61')]===''){throw new db[(_0x58f0('0x71'))][(_0x58f0('0x72'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x58f0('0x77')](_0x400513[_0x58f0('0x61')]['to'])){}_0x371057=_0x400513[_0x58f0('0x61')]['to'];return db['OpenchannelAccount']['findOne']({'where':{'id':_0x400513[_0x58f0('0x59')]['id']}})[_0x58f0('0x38')](handleEntityNotFound(_0x4d83f7,null))[_0x58f0('0x38')](function(_0x2d999b){if(_0x2d999b){return db[_0x58f0('0x54')][_0x58f0('0x5b')]({'where':{'id':_0x2d999b['id']},'include':[{'model':db[_0x58f0('0xb3')],'as':'List','include':[{'model':db[_0x58f0('0x70')],'as':'Contacts','where':{[_0x2d999b[_0x58f0('0x79')]]:_0x371057},'limit':0x1,'order':[['updatedAt',_0x58f0('0xb4')]]}]}]})[_0x58f0('0x38')](handleEntityNotFound(_0x4d83f7,null))[_0x58f0('0x38')](function(_0x2f7e06){if(_0x2f7e06&&_0x2f7e06[_0x58f0('0x7d')]){_0xc72729=_0x2f7e06[_0x58f0('0x3a')]({'plain':!![]});if(_0xc72729['List']&&_0xc72729[_0x58f0('0x7d')][_0x58f0('0x7e')][_0x58f0('0x65')]){return _0xc72729[_0x58f0('0x7d')][_0x58f0('0x7e')][0x0];}return db[_0x58f0('0x70')]['create'](_[_0x58f0('0x1a')](_0x400513['body'],{'firstName':_0x371057,[_0x2f7e06[_0x58f0('0x79')]]:_0x371057,'phone':_0x371057,'ListId':_0xc72729[_0x58f0('0x85')]}));}})[_0x58f0('0x38')](handleEntityNotFound(_0x4d83f7,null))[_0x58f0('0x38')](function(_0x8c2f40){if(_0x8c2f40){_0xdbf418=_0x8c2f40;return db[_0x58f0('0x89')][_0x58f0('0x5b')]({'where':{'ContactId':_0xdbf418['id'],'closed':![],'OpenchannelAccountId':_0xc72729['id']}})['then'](function(_0x59db58){if(_0x59db58){return[_0x59db58,![]];}return db[_0x58f0('0x89')]['create']({'UserId':_0x400513[_0x58f0('0x5d')]['id'],'ContactId':_0xdbf418['id'],'OpenchannelAccountId':_0xc72729['id'],'lastMsgDirection':_0x58f0('0xb5'),'Messages':[_[_0x58f0('0x52')](_0x400513[_0x58f0('0x61')],{'read':![],'body':_0x400513['body']['body'],'OpenchannelAccountId':_0xc72729['id'],'UserId':_0x400513[_0x58f0('0x5d')]['id'],'ContactId':_0xdbf418['id']})]},{'include':[{'model':db[_0x58f0('0x94')],'as':'Messages'}]})['then'](function(_0x158408){return[_0x158408,!![]];});});}})['spread'](function(_0x238b94,_0x526dbd){if(_0x526dbd){return _0x238b94;}return db['OpenchannelMessage'][_0x58f0('0x5c')](_['merge'](_0x400513[_0x58f0('0x61')],{'read':![],'body':_0x400513[_0x58f0('0x61')]['body'],'OpenchannelAccountId':_0xc72729['id'],'OpenchannelInteractionId':_0x238b94['id'],'UserId':_0x400513[_0x58f0('0x5d')]['id'],'ContactId':_0xdbf418['id']}))['then'](function(_0x3ef376){_0x238b94[_0x58f0('0xb6')][_0x58f0('0xb7')]=[];_0x238b94['dataValues'][_0x58f0('0xb7')]['push'](_0x3ef376[_0x58f0('0xb6')]);return _0x238b94;});});}})[_0x58f0('0x38')](respondWithResult(_0x4d83f7,null))[_0x58f0('0x2a')](handleError(_0x4d83f7,null));};
\ No newline at end of file
+var _0x8248=['params','length','include','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','OpenchannelAccounts','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','OpenchannelAccountId','getDispositions','findOne','Disposition','removeDispositions','ids','addAnswer','CannedAnswer','removeAnswers','notify','openchannel','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','ListId','isNil','from','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','List','Contacts','DESC','Applications','account','applications','list','orderBy','priority','asc','defaults','contact','firstName','threadId','OpenchannelInteraction','externalUrl','ContactId','lastName','messageId','interaction','created','autoclose','push','close','unmanaged','*,*,*,*','OpenchannelMessage','UserId','User','unshift','agent','waitForTheAssignedAgent','forcedOwnership','Start','startRouting','EventManager','addApplications','sequelize','transaction','Transaction','ISOLATION_LEVELS','OpenchannelApplication','bulkCreate','findAndCountAll','finally','getApplications','getInteractions','Owner','internal','Tag','Tags','tag','addAgents','omit','spread','emit','removeAgents','isArray','userOpenchannelAccount:remove','getAgents','CmList','out','Messages','eml-format','rimraf','fast-json-patch','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','../../components/parsers/advancedSearch','../../config/utils','../../config/environment','../../config/license/util','redis','socket.io-emitter','./openchannelAccount.socket','register','jayson/promise','client','http','info','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','sendStatus','status','end','json','limit','undefined','count','set','Content-Range','apply','reject','update','then','destroy','get','UserProfileResource','stack','name','send','index','Pause','mandatoryDispositionPause','map','OpenchannelAccount','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','offset','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','findAll','rows','catch'];(function(_0x51b0dc,_0x5307b7){var _0x13fa89=function(_0x2c880f){while(--_0x2c880f){_0x51b0dc['push'](_0x51b0dc['shift']());}};_0x13fa89(++_0x5307b7);}(_0x8248,0x67));var _0x8824=function(_0x4c7225,_0x4dc28d){_0x4c7225=_0x4c7225-0x0;var _0x19f1ed=_0x8248[_0x4c7225];return _0x19f1ed;};'use strict';var emlformat=require(_0x8824('0x0'));var rimraf=require(_0x8824('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x8824('0x2'));var rp=require('request-promise');var moment=require(_0x8824('0x3'));var BPromise=require(_0x8824('0x4'));var Mustache=require('mustache');var util=require(_0x8824('0x5'));var path=require(_0x8824('0x6'));var sox=require(_0x8824('0x7'));var csv=require(_0x8824('0x8'));var ejs=require(_0x8824('0x9'));var fs=require('fs');var fs_extra=require(_0x8824('0xa'));var _=require(_0x8824('0xb'));var squel=require(_0x8824('0xc'));var crypto=require(_0x8824('0xd'));var jsforce=require(_0x8824('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x8824('0x8'));var querystring=require(_0x8824('0xf'));var Papa=require(_0x8824('0x10'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x8824('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0x8824('0x12'));var config=require(_0x8824('0x13'));var licenseUtil=require(_0x8824('0x14'));var db=require('../../mysqldb')['db'];config[_0x8824('0x15')]=_['defaults'](config[_0x8824('0x15')],{'host':'localhost','port':0x18eb});var socket=require(_0x8824('0x16'))(new Redis(config[_0x8824('0x15')]));require(_0x8824('0x17'))[_0x8824('0x18')](socket);var jayson=require(_0x8824('0x19'));var client=jayson[_0x8824('0x1a')][_0x8824('0x1b')]({'port':0x232c});var client9002=jayson[_0x8824('0x1a')][_0x8824('0x1b')]({'port':0x232a});function respondWithRpcPromise(_0x447946,_0x367ffe,_0x34afb5,_0x37bb4c){return new BPromise(function(_0x21ebd4,_0x5ce033){var _0x1635e4=_0x37bb4c||client;return _0x1635e4['request'](_0x447946,_0x34afb5)['then'](function(_0x32cd83){logger[_0x8824('0x1c')](_0x8824('0x1d'),_0x367ffe,_0x8824('0x1e'));logger['debug'](_0x8824('0x1f'),_0x367ffe,'request\x20sent',JSON[_0x8824('0x20')](_0x32cd83));if(_0x32cd83['error']){if(_0x32cd83[_0x8824('0x21')][_0x8824('0x22')]===0x1f4){logger[_0x8824('0x21')](_0x8824('0x1d'),_0x367ffe,_0x32cd83[_0x8824('0x21')][_0x8824('0x23')]);return _0x5ce033(_0x32cd83[_0x8824('0x21')]['message']);}logger[_0x8824('0x21')](_0x8824('0x1d'),_0x367ffe,_0x32cd83[_0x8824('0x21')][_0x8824('0x23')]);return _0x21ebd4(_0x32cd83['error'][_0x8824('0x23')]);}else{logger['info']('OpenchannelAccount,\x20%s,\x20%s',_0x367ffe,_0x8824('0x1e'));_0x21ebd4(_0x32cd83[_0x8824('0x24')][_0x8824('0x23')]);}})['catch'](function(_0xd89d43){logger[_0x8824('0x21')](_0x8824('0x1d'),_0x367ffe,_0xd89d43);_0x5ce033(_0xd89d43);});});}function respondWithStatusCode(_0x44d4d6,_0x4a967d){_0x4a967d=_0x4a967d||0xcc;return function(_0x321695){if(_0x321695){return _0x44d4d6[_0x8824('0x25')](_0x4a967d);}return _0x44d4d6[_0x8824('0x26')](_0x4a967d)[_0x8824('0x27')]();};}function respondWithResult(_0x181562,_0xc22bd4){_0xc22bd4=_0xc22bd4||0xc8;return function(_0x253a41){if(_0x253a41){return _0x181562[_0x8824('0x26')](_0xc22bd4)[_0x8824('0x28')](_0x253a41);}};}function respondWithFilteredResult(_0xfe4d0b,_0x4bb39a){return function(_0x137523){if(_0x137523){var _0x5bac2d=typeof _0x4bb39a['offset']==='undefined'&&typeof _0x4bb39a[_0x8824('0x29')]===_0x8824('0x2a');var _0x2d946c=_0x137523[_0x8824('0x2b')];var _0x34260c=_0x5bac2d?0x0:_0x4bb39a['offset'];var _0x532b25=_0x5bac2d?_0x137523['count']:_0x4bb39a['offset']+_0x4bb39a['limit'];var _0x17a995;if(_0x532b25>=_0x2d946c){_0x532b25=_0x2d946c;_0x17a995=0xc8;}else{_0x17a995=0xce;}_0xfe4d0b['status'](_0x17a995);return _0xfe4d0b[_0x8824('0x2c')](_0x8824('0x2d'),_0x34260c+'-'+_0x532b25+'/'+_0x2d946c)[_0x8824('0x28')](_0x137523);}return null;};}function patchUpdates(_0x49dac8){return function(_0x51cf4e){try{jsonpatch[_0x8824('0x2e')](_0x51cf4e,_0x49dac8,!![]);}catch(_0xc91479){return BPromise[_0x8824('0x2f')](_0xc91479);}return _0x51cf4e['save']();};}function saveUpdates(_0x6fd49f,_0x329072){return function(_0x524976){if(_0x524976){return _0x524976[_0x8824('0x30')](_0x6fd49f)[_0x8824('0x31')](function(_0x1ce485){return _0x1ce485;});}return null;};}function removeEntity(_0x200adb,_0xc6cb29){return function(_0x4a4ca7){if(_0x4a4ca7){return _0x4a4ca7[_0x8824('0x32')]()[_0x8824('0x31')](function(){var _0x122b76=_0x4a4ca7[_0x8824('0x33')]({'plain':!![]});var _0x1714c6='OpenchannelAccounts';return db[_0x8824('0x34')][_0x8824('0x32')]({'where':{'type':_0x1714c6,'resourceId':_0x122b76['id']}})[_0x8824('0x31')](function(){return _0x4a4ca7;});})[_0x8824('0x31')](function(){_0x200adb[_0x8824('0x26')](0xcc)[_0x8824('0x27')]();});}};}function handleEntityNotFound(_0x19b775,_0x18f4ff){return function(_0xa86d7){if(!_0xa86d7){_0x19b775[_0x8824('0x25')](0x194);}return _0xa86d7;};}function handleError(_0x29be04,_0x572a7d){_0x572a7d=_0x572a7d||0x1f4;return function(_0x27af2c){logger[_0x8824('0x21')](_0x27af2c[_0x8824('0x35')]);if(_0x27af2c[_0x8824('0x36')]){delete _0x27af2c[_0x8824('0x36')];}_0x29be04['status'](_0x572a7d)[_0x8824('0x37')](_0x27af2c);};}exports[_0x8824('0x38')]=function(_0x5cff82,_0x2c95d2){var _0x452bc4={'include':[{'model':db[_0x8824('0x39')],'as':_0x8824('0x3a')}]},_0x1e7cae={},_0x312020={'count':0x0,'rows':[]};var _0xac8792=_[_0x8824('0x3b')](db[_0x8824('0x3c')][_0x8824('0x3d')],function(_0x3a1fd5){return{'name':_0x3a1fd5[_0x8824('0x3e')],'type':_0x3a1fd5[_0x8824('0x3f')]['key']};});_0x1e7cae[_0x8824('0x40')]=_[_0x8824('0x3b')](_0xac8792,_0x8824('0x36'));_0x1e7cae[_0x8824('0x41')]=_[_0x8824('0x42')](_0x5cff82[_0x8824('0x41')]);_0x1e7cae[_0x8824('0x43')]=_[_0x8824('0x44')](_0x1e7cae[_0x8824('0x40')],_0x1e7cae[_0x8824('0x41')]);_0x452bc4[_0x8824('0x45')]=_[_0x8824('0x44')](_0x1e7cae['model'],qs[_0x8824('0x46')](_0x5cff82[_0x8824('0x41')]['fields']));_0x452bc4[_0x8824('0x45')]=_0x452bc4[_0x8824('0x45')]['length']?_0x452bc4[_0x8824('0x45')]:_0x1e7cae[_0x8824('0x40')];if(!_0x5cff82['query'][_0x8824('0x47')](_0x8824('0x48'))){_0x452bc4[_0x8824('0x29')]=qs[_0x8824('0x29')](_0x5cff82['query'][_0x8824('0x29')]);_0x452bc4['offset']=qs[_0x8824('0x49')](_0x5cff82[_0x8824('0x41')]['offset']);}_0x452bc4[_0x8824('0x4a')]=qs['sort'](_0x5cff82[_0x8824('0x41')][_0x8824('0x4b')]);_0x452bc4[_0x8824('0x4c')]=qs[_0x8824('0x43')](_[_0x8824('0x4d')](_0x5cff82['query'],_0x1e7cae[_0x8824('0x43')]),_0xac8792);if(_0x5cff82['query'][_0x8824('0x4e')]){_0x452bc4['where']=_[_0x8824('0x4f')](_0x452bc4[_0x8824('0x4c')],{'$or':_[_0x8824('0x3b')](_0xac8792,function(_0x35502e){if(_0x35502e[_0x8824('0x3f')]!==_0x8824('0x50')){var _0x1c88ea={};_0x1c88ea[_0x35502e[_0x8824('0x36')]]={'$like':'%'+_0x5cff82['query'][_0x8824('0x4e')]+'%'};return _0x1c88ea;}})});}_0x452bc4=_[_0x8824('0x4f')]({},_0x452bc4,_0x5cff82[_0x8824('0x51')]);var _0x84fb40={'where':_0x452bc4['where']};return db[_0x8824('0x3c')]['count'](_0x84fb40)[_0x8824('0x31')](function(_0xfb9dc5){_0x312020[_0x8824('0x2b')]=_0xfb9dc5;if(_0x5cff82[_0x8824('0x41')][_0x8824('0x52')]){_0x452bc4['include']=[{'all':!![]}];}return db[_0x8824('0x3c')][_0x8824('0x53')](_0x452bc4);})[_0x8824('0x31')](function(_0x161bd6){_0x312020[_0x8824('0x54')]=_0x161bd6;return _0x312020;})['then'](respondWithFilteredResult(_0x2c95d2,_0x452bc4))[_0x8824('0x55')](handleError(_0x2c95d2,null));};exports['show']=function(_0x28a274,_0x3ac5f7){var _0x60dd4f={'raw':![],'where':{'id':_0x28a274[_0x8824('0x56')]['id']},'include':[{'model':db['Pause'],'as':_0x8824('0x3a')}]},_0x39853f={};_0x39853f[_0x8824('0x40')]=_['keys'](db['OpenchannelAccount'][_0x8824('0x3d')]);_0x39853f[_0x8824('0x41')]=_[_0x8824('0x42')](_0x28a274[_0x8824('0x41')]);_0x39853f['filters']=_[_0x8824('0x44')](_0x39853f[_0x8824('0x40')],_0x39853f[_0x8824('0x41')]);_0x60dd4f[_0x8824('0x45')]=_['intersection'](_0x39853f['model'],qs[_0x8824('0x46')](_0x28a274[_0x8824('0x41')][_0x8824('0x46')]));_0x60dd4f['attributes']=_0x60dd4f[_0x8824('0x45')][_0x8824('0x57')]?_0x60dd4f['attributes']:_0x39853f['model'];if(_0x28a274[_0x8824('0x41')][_0x8824('0x52')]){_0x60dd4f[_0x8824('0x58')]=[{'all':!![]}];}_0x60dd4f=_['merge']({},_0x60dd4f,_0x28a274[_0x8824('0x51')]);return db[_0x8824('0x3c')][_0x8824('0x59')](_0x60dd4f)[_0x8824('0x31')](handleEntityNotFound(_0x3ac5f7,null))[_0x8824('0x31')](respondWithResult(_0x3ac5f7,null))[_0x8824('0x55')](handleError(_0x3ac5f7,null));};exports['create']=function(_0x46b57b,_0xbe90c1){return db[_0x8824('0x3c')][_0x8824('0x5a')](_0x46b57b[_0x8824('0x5b')],{})[_0x8824('0x31')](function(_0x3e9cb5){var _0x1cb16f=_0x46b57b[_0x8824('0x5c')][_0x8824('0x33')]({'plain':!![]});if(!_0x1cb16f)throw new Error(_0x8824('0x5d'));if(_0x1cb16f['role']===_0x8824('0x5c')){var _0x46b8ac=_0x3e9cb5[_0x8824('0x33')]({'plain':!![]});var _0x27e5e9=_0x8824('0x5e');return db['UserProfileSection']['find']({'where':{'name':_0x27e5e9,'userProfileId':_0x1cb16f[_0x8824('0x5f')]},'raw':!![]})[_0x8824('0x31')](function(_0x404251){if(_0x404251&&_0x404251['autoAssociation']===0x0){return db[_0x8824('0x34')]['create']({'name':_0x46b8ac[_0x8824('0x36')],'resourceId':_0x46b8ac['id'],'type':_0x404251[_0x8824('0x36')],'sectionId':_0x404251['id']},{})[_0x8824('0x31')](function(){return _0x3e9cb5;});}else{return _0x3e9cb5;}})[_0x8824('0x55')](function(_0x1abc59){logger[_0x8824('0x21')](_0x8824('0x60'),_0x1abc59);throw _0x1abc59;});}return _0x3e9cb5;})[_0x8824('0x31')](respondWithResult(_0xbe90c1,0xc9))['catch'](handleError(_0xbe90c1,null));};exports[_0x8824('0x30')]=function(_0x244dd4,_0x3f62d6){if(_0x244dd4[_0x8824('0x5b')]['id']){delete _0x244dd4['body']['id'];}return db[_0x8824('0x3c')][_0x8824('0x59')]({'where':{'id':_0x244dd4['params']['id']},'include':[{'model':db[_0x8824('0x39')],'as':'mandatoryDispositionPause'}]})[_0x8824('0x31')](handleEntityNotFound(_0x3f62d6,null))['then'](saveUpdates(_0x244dd4[_0x8824('0x5b')],null))[_0x8824('0x31')](respondWithResult(_0x3f62d6,null))[_0x8824('0x55')](handleError(_0x3f62d6,null));};exports[_0x8824('0x32')]=function(_0x215358,_0x484025){return db[_0x8824('0x3c')]['find']({'where':{'id':_0x215358[_0x8824('0x56')]['id']}})['then'](handleEntityNotFound(_0x484025,null))['then'](removeEntity(_0x484025,null))[_0x8824('0x55')](handleError(_0x484025,null));};exports[_0x8824('0x61')]=function(_0x11f001,_0x112682){return db['OpenchannelAccount'][_0x8824('0x61')]()['then'](respondWithResult(_0x112682,null))['catch'](handleError(_0x112682,null));};exports[_0x8824('0x62')]=function(_0x442588,_0x18cc36,_0x24d8a7){if(_0x442588[_0x8824('0x5b')]['id']){delete _0x442588[_0x8824('0x5b')]['id'];}return db[_0x8824('0x3c')]['find']({'where':{'id':_0x442588[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x18cc36,null))['then'](function(_0x4d680e){if(_0x4d680e){_0x442588[_0x8824('0x5b')][_0x8824('0x63')]=_0x4d680e['id'];return db['Disposition']['create'](_0x442588[_0x8824('0x5b')]);}})[_0x8824('0x31')](respondWithResult(_0x18cc36,null))[_0x8824('0x55')](handleError(_0x18cc36,null));};exports[_0x8824('0x64')]=function(_0x10f942,_0x24a9b0,_0x17b563){var _0x3c3e3b={'raw':![],'where':{}};var _0xae8665={};var _0x42d7bb={'count':0x0,'rows':[]};return db[_0x8824('0x3c')][_0x8824('0x65')]({'where':{'id':_0x10f942[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x24a9b0,null))[_0x8824('0x31')](function(_0x1476d8){if(_0x1476d8){_0xae8665[_0x8824('0x40')]=_[_0x8824('0x42')](db[_0x8824('0x66')][_0x8824('0x3d')]);_0xae8665['query']=_['keys'](_0x10f942['query']);_0xae8665[_0x8824('0x43')]=_['intersection'](_0xae8665[_0x8824('0x40')],_0xae8665[_0x8824('0x41')]);_0x3c3e3b[_0x8824('0x45')]=_['intersection'](_0xae8665[_0x8824('0x40')],qs[_0x8824('0x46')](_0x10f942[_0x8824('0x41')][_0x8824('0x46')]));_0x3c3e3b[_0x8824('0x45')]=_0x3c3e3b[_0x8824('0x45')][_0x8824('0x57')]?_0x3c3e3b[_0x8824('0x45')]:_0xae8665[_0x8824('0x40')];if(!_0x10f942['query'][_0x8824('0x47')](_0x8824('0x48'))){_0x3c3e3b['limit']=qs[_0x8824('0x29')](_0x10f942[_0x8824('0x41')][_0x8824('0x29')]);_0x3c3e3b[_0x8824('0x49')]=qs[_0x8824('0x49')](_0x10f942['query'][_0x8824('0x49')]);}_0x3c3e3b[_0x8824('0x4a')]=qs[_0x8824('0x4b')](_0x10f942[_0x8824('0x41')][_0x8824('0x4b')]);_0x3c3e3b[_0x8824('0x4c')]=qs[_0x8824('0x43')](_['pick'](_0x10f942[_0x8824('0x41')],_0xae8665[_0x8824('0x43')]));_0x3c3e3b['where'][_0x8824('0x63')]=_0x1476d8['id'];if(_0x10f942[_0x8824('0x41')][_0x8824('0x4e')]){_0x3c3e3b[_0x8824('0x4c')]=_[_0x8824('0x4f')](_0x3c3e3b['where'],{'$or':_[_0x8824('0x3b')](_0x3c3e3b[_0x8824('0x45')],function(_0x33d0e6){var _0x22ddd5={};_0x22ddd5[_0x33d0e6]={'$like':'%'+_0x10f942[_0x8824('0x41')][_0x8824('0x4e')]+'%'};return _0x22ddd5;})});}_0x3c3e3b=_[_0x8824('0x4f')]({},_0x3c3e3b,_0x10f942['options']);return db[_0x8824('0x66')][_0x8824('0x2b')]({'where':_0x3c3e3b[_0x8824('0x4c')]})[_0x8824('0x31')](function(_0x187112){_0x42d7bb['count']=_0x187112;if(_0x10f942[_0x8824('0x41')][_0x8824('0x52')]){_0x3c3e3b['include']=[{'all':!![]}];}return db[_0x8824('0x66')][_0x8824('0x53')](_0x3c3e3b);})[_0x8824('0x31')](function(_0x497911){_0x42d7bb[_0x8824('0x54')]=_0x497911;return _0x42d7bb;});}})['then'](respondWithFilteredResult(_0x24a9b0,_0x3c3e3b))[_0x8824('0x55')](handleError(_0x24a9b0,null));};exports[_0x8824('0x67')]=function(_0x4125e3,_0x5ba86c,_0x3be598){return db[_0x8824('0x3c')][_0x8824('0x59')]({'where':{'id':_0x4125e3[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x5ba86c,null))['then'](function(_0x5515a4){if(_0x5515a4){return _0x5515a4[_0x8824('0x67')](_0x4125e3[_0x8824('0x41')][_0x8824('0x68')]);}})['then'](respondWithStatusCode(_0x5ba86c,null))[_0x8824('0x55')](handleError(_0x5ba86c,null));};exports[_0x8824('0x69')]=function(_0x21c1e2,_0x46956e,_0x43775c){if(_0x21c1e2['body']['id']){delete _0x21c1e2[_0x8824('0x5b')]['id'];}return db[_0x8824('0x3c')][_0x8824('0x59')]({'where':{'id':_0x21c1e2[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x46956e,null))[_0x8824('0x31')](function(_0x10747b){if(_0x10747b){_0x21c1e2['body'][_0x8824('0x63')]=_0x10747b['id'];return db['CannedAnswer'][_0x8824('0x5a')](_0x21c1e2['body']);}})[_0x8824('0x31')](respondWithResult(_0x46956e,null))[_0x8824('0x55')](handleError(_0x46956e,null));};exports['getAnswers']=function(_0x30868b,_0x3bc341,_0x48465a){var _0x2eb894={'raw':![],'where':{}};var _0x541754={};var _0x320f16={'count':0x0,'rows':[]};return db[_0x8824('0x3c')]['findOne']({'where':{'id':_0x30868b['params']['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x3bc341,null))[_0x8824('0x31')](function(_0x1a91c7){if(_0x1a91c7){_0x541754[_0x8824('0x40')]=_[_0x8824('0x42')](db['CannedAnswer']['rawAttributes']);_0x541754[_0x8824('0x41')]=_['keys'](_0x30868b['query']);_0x541754['filters']=_[_0x8824('0x44')](_0x541754[_0x8824('0x40')],_0x541754[_0x8824('0x41')]);_0x2eb894[_0x8824('0x45')]=_[_0x8824('0x44')](_0x541754[_0x8824('0x40')],qs[_0x8824('0x46')](_0x30868b[_0x8824('0x41')][_0x8824('0x46')]));_0x2eb894[_0x8824('0x45')]=_0x2eb894[_0x8824('0x45')]['length']?_0x2eb894[_0x8824('0x45')]:_0x541754[_0x8824('0x40')];if(!_0x30868b[_0x8824('0x41')][_0x8824('0x47')](_0x8824('0x48'))){_0x2eb894[_0x8824('0x29')]=qs[_0x8824('0x29')](_0x30868b[_0x8824('0x41')]['limit']);_0x2eb894[_0x8824('0x49')]=qs[_0x8824('0x49')](_0x30868b[_0x8824('0x41')]['offset']);}_0x2eb894[_0x8824('0x4a')]=qs[_0x8824('0x4b')](_0x30868b[_0x8824('0x41')][_0x8824('0x4b')]);_0x2eb894['where']=qs[_0x8824('0x43')](_[_0x8824('0x4d')](_0x30868b['query'],_0x541754[_0x8824('0x43')]));_0x2eb894['where'][_0x8824('0x63')]=_0x1a91c7['id'];if(_0x30868b['query'][_0x8824('0x4e')]){_0x2eb894[_0x8824('0x4c')]=_[_0x8824('0x4f')](_0x2eb894[_0x8824('0x4c')],{'$or':_[_0x8824('0x3b')](_0x2eb894['attributes'],function(_0x50bc87){var _0x58cd08={};_0x58cd08[_0x50bc87]={'$like':'%'+_0x30868b[_0x8824('0x41')][_0x8824('0x4e')]+'%'};return _0x58cd08;})});}_0x2eb894=_[_0x8824('0x4f')]({},_0x2eb894,_0x30868b[_0x8824('0x51')]);return db['CannedAnswer'][_0x8824('0x2b')]({'where':_0x2eb894[_0x8824('0x4c')]})[_0x8824('0x31')](function(_0x375ab7){_0x320f16['count']=_0x375ab7;if(_0x30868b[_0x8824('0x41')]['includeAll']){_0x2eb894[_0x8824('0x58')]=[{'all':!![]}];}return db[_0x8824('0x6a')][_0x8824('0x53')](_0x2eb894);})['then'](function(_0xca0f36){_0x320f16['rows']=_0xca0f36;return _0x320f16;});}})[_0x8824('0x31')](respondWithFilteredResult(_0x3bc341,_0x2eb894))['catch'](handleError(_0x3bc341,null));};exports[_0x8824('0x6b')]=function(_0x3e6feb,_0x1ad890,_0x484e25){return db[_0x8824('0x3c')][_0x8824('0x59')]({'where':{'id':_0x3e6feb[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x1ad890,null))[_0x8824('0x31')](function(_0x135008){if(_0x135008){return _0x135008['removeAnswers'](_0x3e6feb[_0x8824('0x41')][_0x8824('0x68')]);}})[_0x8824('0x31')](respondWithStatusCode(_0x1ad890,null))['catch'](handleError(_0x1ad890,null));};exports[_0x8824('0x6c')]=function(_0x2beffc,_0x25d193,_0x3cce8f){var _0x9c20a0={'body':_0x2beffc[_0x8824('0x5b')],'channel':_0x8824('0x6d')};var _0x160884=[];var _0x3e2425=[];var _0x10f73d={};var _0x2a7115=![];return db[_0x8824('0x6e')][_0x8824('0x61')]()[_0x8824('0x31')](function(_0x112cee){if(!_0x112cee){throw new db[(_0x8824('0x6f'))][(_0x8824('0x70'))](_0x8824('0x71'));}_0x160884=_[_0x8824('0x72')](_[_0x8824('0x42')](_0x112cee),[_0x8824('0x73'),_0x8824('0x74')]);_0x3e2425=_[_0x8824('0x72')](_['keys'](_0x112cee),['createdAt',_0x8824('0x74'),_0x8824('0x75'),_0x8824('0x76')]);if(_0x2beffc[_0x8824('0x5b')]['id']){delete _0x2beffc[_0x8824('0x5b')]['id'];}if(_[_0x8824('0x77')](_0x2beffc[_0x8824('0x5b')][_0x8824('0x78')])){throw new db[(_0x8824('0x6f'))][(_0x8824('0x70'))](_0x8824('0x79'));}if(_[_0x8824('0x77')](_0x2beffc[_0x8824('0x5b')][_0x8824('0x5b')])||_0x2beffc['body'][_0x8824('0x5b')]===''){throw new db[(_0x8824('0x6f'))][(_0x8824('0x70'))](_0x8824('0x7a'));}if(_[_0x8824('0x77')](_0x2beffc[_0x8824('0x5b')][_0x8824('0x7b')])){throw new db[(_0x8824('0x6f'))][(_0x8824('0x70'))]('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x3e2425);}if(!_[_0x8824('0x7c')](_0x3e2425,_0x2beffc['body']['mapKey'])){throw new db[(_0x8824('0x6f'))][(_0x8824('0x70'))](_0x8824('0x7d')+_0x3e2425);}_0x10f73d[_0x2beffc[_0x8824('0x5b')][_0x8824('0x7b')]]=_0x2beffc[_0x8824('0x5b')][_0x8824('0x78')];})[_0x8824('0x31')](function(){return db[_0x8824('0x3c')][_0x8824('0x59')]({'where':{'id':_0x2beffc['params']['id']},'include':[{'model':db['CmList'],'as':_0x8824('0x7e'),'include':[{'model':db[_0x8824('0x6e')],'as':_0x8824('0x7f'),'where':_0x10f73d,'limit':0x1,'order':[[_0x8824('0x74'),_0x8824('0x80')]]}]},{'model':db['OpenchannelApplication'],'as':_0x8824('0x81')}]});})[_0x8824('0x31')](handleEntityNotFound(_0x25d193,null))[_0x8824('0x31')](function(_0x1473d5){if(_0x1473d5&&_0x1473d5[_0x8824('0x7e')]){_0x9c20a0[_0x8824('0x82')]=_0x1473d5;_0x9c20a0[_0x8824('0x83')]=_0x1473d5[_0x8824('0x81')];_0x9c20a0[_0x8824('0x84')]=_0x1473d5['List'];_0x9c20a0[_0x8824('0x83')]=_[_0x8824('0x85')](_0x9c20a0['applications'],[_0x8824('0x86')],[_0x8824('0x87')]);if(_0x9c20a0[_0x8824('0x82')][_0x8824('0x81')]){delete _0x9c20a0[_0x8824('0x82')][_0x8824('0x81')];}if(_0x9c20a0[_0x8824('0x82')][_0x8824('0x7e')]&&_0x9c20a0['account'][_0x8824('0x7e')][_0x8824('0x7f')][_0x8824('0x57')]){return _0x9c20a0['account'][_0x8824('0x7e')][_0x8824('0x7f')][0x0];}var _0x25d1fa=_[_0x8824('0x88')](_0x2beffc[_0x8824('0x5b')],{'firstName':_0x2beffc[_0x8824('0x5b')][_0x8824('0x78')],'ListId':_0x1473d5[_0x8824('0x76')]});_0x25d1fa[_0x2beffc['body'][_0x8824('0x7b')]]=_0x2beffc[_0x8824('0x5b')]['from'];return db[_0x8824('0x6e')][_0x8824('0x5a')](_0x25d1fa,{'fields':_0x160884,'raw':!![]});}})['then'](handleEntityNotFound(_0x25d193,null))[_0x8824('0x31')](function(_0x20fd8a){_0x9c20a0[_0x8824('0x89')]=_0x20fd8a;if(_0x20fd8a){var _0x3f707c={'ContactId':_0x20fd8a['id'],'OpenchannelAccountId':_0x2beffc[_0x8824('0x56')]['id'],'from':(_0x20fd8a[_0x8824('0x8a')]||'')+'\x20'+(_0x20fd8a['lastName']||'')};var _0x226978={'OpenchannelAccountId':_0x2beffc[_0x8824('0x56')]['id'],'closed':![]};if(_0x2beffc[_0x8824('0x5b')][_0x8824('0x8b')]){_0x226978['threadId']=_0x2beffc[_0x8824('0x5b')]['threadId'];return db[_0x8824('0x8c')][_0x8824('0x59')]({'where':_0x226978})[_0x8824('0x31')](function(_0x50d81a){if(_0x50d81a){return[_0x50d81a,![]];}_0x3f707c[_0x8824('0x8b')]=_0x2beffc['body']['threadId'];_0x3f707c[_0x8824('0x8d')]=_0x2beffc[_0x8824('0x5b')][_0x8824('0x8d')];return db[_0x8824('0x8c')][_0x8824('0x5a')](_0x3f707c)[_0x8824('0x31')](function(_0x3f94e9){return[_0x3f94e9,!![]];});});}else{_0x226978[_0x8824('0x8b')]=null;}_0x226978[_0x8824('0x8e')]=_0x20fd8a['id'];return db[_0x8824('0x8c')][_0x8824('0x59')]({'where':_0x226978})[_0x8824('0x31')](function(_0x4d0f41){if(_0x4d0f41){return[_0x4d0f41,![]];}return db['OpenchannelInteraction'][_0x8824('0x5a')](_0x3f707c)[_0x8824('0x31')](function(_0x5328fd){return[_0x5328fd,!![]];});});}})['spread'](function(_0x220ad5,_0x2de9c8){if(_0x220ad5){_0x2a7115=_0x2de9c8;if(!_0x2de9c8){var _0x30d533={'from':(_0x9c20a0['contact'][_0x8824('0x8a')]||'')+'\x20'+(_0x9c20a0[_0x8824('0x89')][_0x8824('0x8f')]||'')};if(_0x2beffc['body'][_0x8824('0x8b')]&&_0x2beffc[_0x8824('0x5b')][_0x8824('0x90')]&&_0x2beffc[_0x8824('0x5b')][_0x8824('0x8b')]!=_0x2beffc['body'][_0x8824('0x90')]){_0x30d533[_0x8824('0x8b')]=_0x2beffc['body'][_0x8824('0x90')];}return _0x220ad5[_0x8824('0x30')](_0x30d533);}else{return _0x220ad5;}}})[_0x8824('0x31')](function(_0x25f6f4){_0x9c20a0[_0x8824('0x91')]=_0x25f6f4[_0x8824('0x33')]({'plain':!![]});_0x9c20a0['interaction'][_0x8824('0x92')]=_0x2a7115;if(_0x9c20a0[_0x8824('0x91')][_0x8824('0x92')]){if(_0x9c20a0[_0x8824('0x82')][_0x8824('0x93')]){_0x9c20a0[_0x8824('0x83')][_0x8824('0x94')]({'id':0x0,'priority':_0x9c20a0[_0x8824('0x83')][_0x8824('0x57')]+0x1,'app':_0x8824('0x95'),'appdata':_0x8824('0x96'),'interval':_0x8824('0x97')});}}return db[_0x8824('0x98')][_0x8824('0x5a')]({'body':_0x2beffc['body'][_0x8824('0x5b')],'OpenchannelAccountId':_0x2beffc[_0x8824('0x56')]['id'],'OpenchannelInteractionId':_0x25f6f4['id'],'direction':'in','ContactId':_0x9c20a0[_0x8824('0x89')]['id'],'AttachmentId':_0x2beffc[_0x8824('0x5b')]['AttachmentId']});})[_0x8824('0x31')](function(_0xaa912c){_0x9c20a0[_0x8824('0x23')]=_0xaa912c;if(_0x9c20a0[_0x8824('0x91')][_0x8824('0x99')]){return db[_0x8824('0x9a')][_0x8824('0x59')]({'attributes':['id',_0x8824('0x36')],'where':{'id':_0x9c20a0[_0x8824('0x91')][_0x8824('0x99')]}})[_0x8824('0x31')](function(_0x1420e2){if(_0x1420e2){_0x9c20a0[_0x8824('0x83')][_0x8824('0x9b')]({'id':0x0,'priority':0x0,'app':_0x8824('0x9c'),'appdata':_0x1420e2[_0x8824('0x36')]+','+(_0x9c20a0[_0x8824('0x82')][_0x8824('0x9d')]||0xa),'interval':_0x8824('0x97')});_0x9c20a0[_0x8824('0x9e')]=![];}return respondWithRpcPromise(_0x8824('0x9f'),_0x8824('0xa0'),_0x9c20a0);});}return respondWithRpcPromise(_0x8824('0x9f'),'startRouting',_0x9c20a0);})[_0x8824('0x31')](function(_0x27aab8){respondWithRpcPromise(_0x8824('0xa1'),_0x8824('0xa1'),{'event':_0x8824('0x6c'),'message':_0x27aab8},client9002);return _0x27aab8;})[_0x8824('0x31')](respondWithResult(_0x25d193,null))[_0x8824('0x55')](handleError(_0x25d193,null));};exports[_0x8824('0xa2')]=function(_0xe3229b,_0xb46043){var _0x3e6ddc=_0xe3229b['params']['id'];var _0xe10c06=_0xe3229b['body'];var _0x46aeeb=0xc8;var _0x1ae778=null;return db[_0x8824('0xa3')][_0x8824('0xa4')]({'isolationLevel':db[_0x8824('0xa3')][_0x8824('0xa5')][_0x8824('0xa6')]['READ_COMMITTED']},function(_0x4566a4){return db[_0x8824('0x3c')]['findOne']({'where':{'id':_0x3e6ddc},'transaction':_0x4566a4})[_0x8824('0x31')](function(_0x273225){if(_0x273225){return db[_0x8824('0xa7')][_0x8824('0x32')]({'where':{'OpenchannelAccountId':_0x3e6ddc},'transaction':_0x4566a4})[_0x8824('0x31')](function(){var _0x26ca8d=_[_0x8824('0x3b')](_0xe10c06,function(_0x294098){_0x294098[_0x8824('0x63')]=_0x3e6ddc;return _0x294098;});return db[_0x8824('0xa7')][_0x8824('0xa8')](_0x26ca8d,{'transaction':_0x4566a4});});}else{_0x46aeeb=0x194;_0x1ae778=[];}});})[_0x8824('0x31')](function(){if(_0x46aeeb!==0x194){return db[_0x8824('0xa7')][_0x8824('0xa9')]({'where':{'OpenchannelAccountId':_0x3e6ddc},'order':_0x8824('0x86')})[_0x8824('0x31')](function(_0x25f1f7){_0x1ae778=_0x25f1f7;});}})[_0x8824('0x55')](function(_0x316e4f){_0x46aeeb=0x1f4;logger[_0x8824('0x21')](_0x316e4f[_0x8824('0x35')]);if(_0x316e4f['name']){delete _0x316e4f[_0x8824('0x36')];}_0x1ae778=_0x316e4f;})[_0x8824('0xaa')](function(){if(_0x1ae778===null){_0xb46043[_0x8824('0x25')](_0x46aeeb);}else{if(_0x46aeeb===0x1f4){_0xb46043[_0x8824('0x26')](_0x46aeeb)['send'](_0x1ae778);}else{_0xb46043[_0x8824('0x26')](_0x46aeeb)[_0x8824('0x28')](_0x1ae778);}}});};exports[_0x8824('0xab')]=function(_0x505525,_0x5040f6,_0x25d0eb){var _0x13b679={};var _0x5e146e={};var _0x407727;var _0x136e1c;return db[_0x8824('0x3c')][_0x8824('0x65')]({'where':{'id':_0x505525[_0x8824('0x56')]['id']}})['then'](handleEntityNotFound(_0x5040f6,null))[_0x8824('0x31')](function(_0x1487ec){if(_0x1487ec){_0x407727=_0x1487ec;_0x5e146e[_0x8824('0x40')]=_[_0x8824('0x42')](db[_0x8824('0xa7')]['rawAttributes']);_0x5e146e[_0x8824('0x41')]=_[_0x8824('0x42')](_0x505525['query']);_0x5e146e[_0x8824('0x43')]=_['intersection'](_0x5e146e[_0x8824('0x40')],_0x5e146e[_0x8824('0x41')]);_0x13b679[_0x8824('0x45')]=_['intersection'](_0x5e146e[_0x8824('0x40')],qs[_0x8824('0x46')](_0x505525[_0x8824('0x41')][_0x8824('0x46')]));_0x13b679[_0x8824('0x45')]=_0x13b679[_0x8824('0x45')][_0x8824('0x57')]?_0x13b679[_0x8824('0x45')]:_0x5e146e[_0x8824('0x40')];_0x13b679[_0x8824('0x4a')]=qs['sort'](_0x505525[_0x8824('0x41')]['sort']);_0x13b679[_0x8824('0x4c')]=qs[_0x8824('0x43')](_['pick'](_0x505525[_0x8824('0x41')],_0x5e146e[_0x8824('0x43')]));if(_0x505525[_0x8824('0x41')][_0x8824('0x4e')]){_0x13b679[_0x8824('0x4c')]=_[_0x8824('0x4f')](_0x13b679[_0x8824('0x4c')],{'$or':_[_0x8824('0x3b')](_0x13b679[_0x8824('0x45')],function(_0x5baf15){var _0x5b7299={};_0x5b7299[_0x5baf15]={'$like':'%'+_0x505525['query']['filter']+'%'};return _0x5b7299;})});}_0x13b679=_[_0x8824('0x4f')]({},_0x13b679,_0x505525['options']);return _0x407727[_0x8824('0xab')](_0x13b679);}})[_0x8824('0x31')](function(_0x31a7c3){if(_0x31a7c3){_0x136e1c=_0x31a7c3['length'];if(!_0x505525['query'][_0x8824('0x47')](_0x8824('0x48'))){_0x13b679['limit']=qs[_0x8824('0x29')](_0x505525[_0x8824('0x41')][_0x8824('0x29')]);_0x13b679['offset']=qs[_0x8824('0x49')](_0x505525[_0x8824('0x41')][_0x8824('0x49')]);}return _0x407727[_0x8824('0xab')](_0x13b679);}})[_0x8824('0x31')](function(_0x23b368){if(_0x23b368){return _0x23b368?{'count':_0x136e1c,'rows':_0x23b368}:null;}})['then'](respondWithResult(_0x5040f6,null))['catch'](handleError(_0x5040f6,null));};exports[_0x8824('0xac')]=function(_0x2904b3,_0x503ec5,_0x2faccf){var _0x1f5fb4={'raw':![],'where':{}};var _0x2726a2={};var _0x9c18e3={'count':0x0,'rows':[]};return db[_0x8824('0x3c')][_0x8824('0x65')]({'where':{'id':_0x2904b3[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x503ec5,null))[_0x8824('0x31')](function(_0x58cd10){if(_0x58cd10){_0x2726a2[_0x8824('0x40')]=_[_0x8824('0x42')](db[_0x8824('0x8c')][_0x8824('0x3d')]);_0x2726a2[_0x8824('0x41')]=_[_0x8824('0x42')](_0x2904b3[_0x8824('0x41')]);_0x2726a2[_0x8824('0x43')]=_['intersection'](_0x2726a2[_0x8824('0x40')],_0x2726a2[_0x8824('0x41')]);_0x1f5fb4[_0x8824('0x45')]=_[_0x8824('0x44')](_0x2726a2['model'],qs[_0x8824('0x46')](_0x2904b3[_0x8824('0x41')]['fields']));_0x1f5fb4[_0x8824('0x45')]=_0x1f5fb4[_0x8824('0x45')][_0x8824('0x57')]?_0x1f5fb4['attributes']:_0x2726a2[_0x8824('0x40')];if(!_0x2904b3[_0x8824('0x41')][_0x8824('0x47')](_0x8824('0x48'))){_0x1f5fb4[_0x8824('0x29')]=qs[_0x8824('0x29')](_0x2904b3[_0x8824('0x41')]['limit']);_0x1f5fb4[_0x8824('0x49')]=qs[_0x8824('0x49')](_0x2904b3[_0x8824('0x41')]['offset']);}_0x1f5fb4['order']=qs['sort'](_0x2904b3[_0x8824('0x41')][_0x8824('0x4b')]);_0x1f5fb4['where']=qs['filters'](_['pick'](_0x2904b3[_0x8824('0x41')],_0x2726a2[_0x8824('0x43')]));_0x1f5fb4[_0x8824('0x4c')]['OpenchannelAccountId']=_0x58cd10['id'];if(_0x2904b3[_0x8824('0x41')]['filter']){_0x1f5fb4[_0x8824('0x4c')]=_[_0x8824('0x4f')](_0x1f5fb4[_0x8824('0x4c')],{'$or':_[_0x8824('0x3b')](_0x1f5fb4[_0x8824('0x45')],function(_0x39db4d){var _0x19ab0c={};_0x19ab0c[_0x39db4d]={'$like':'%'+_0x2904b3['query'][_0x8824('0x4e')]+'%'};return _0x19ab0c;})});}_0x1f5fb4=_[_0x8824('0x4f')]({},_0x1f5fb4,_0x2904b3[_0x8824('0x51')]);return db[_0x8824('0x8c')][_0x8824('0x2b')]({'where':_0x1f5fb4['where']})[_0x8824('0x31')](function(_0x112ea4){_0x9c18e3[_0x8824('0x2b')]=_0x112ea4;if(_0x2904b3[_0x8824('0x41')][_0x8824('0x52')]){_0x1f5fb4[_0x8824('0x58')]=[{'model':db[_0x8824('0x6e')],'as':'Contact','required':![]},{'model':db[_0x8824('0x9a')],'as':_0x8824('0xad'),'attributes':['name','fullname',_0x8824('0xae')],'required':![]},{'model':db[_0x8824('0xaf')],'as':_0x8824('0xb0'),'attributes':['id',_0x8824('0x36'),'color'],'where':_0x2904b3['query'][_0x8824('0xb1')]?{'id':_0x2904b3['query'][_0x8824('0xb1')]}:undefined,'required':_0x2904b3[_0x8824('0x41')][_0x8824('0xb1')]?!![]:![]}];}return db[_0x8824('0x8c')][_0x8824('0x53')](_0x1f5fb4);})[_0x8824('0x31')](function(_0x54f4c1){_0x9c18e3[_0x8824('0x54')]=_0x54f4c1;return _0x9c18e3;});}})[_0x8824('0x31')](respondWithFilteredResult(_0x503ec5,_0x1f5fb4))[_0x8824('0x55')](handleError(_0x503ec5,null));};exports[_0x8824('0xb2')]=function(_0x6fcfb3,_0x186c2f,_0x26bf4f){return db[_0x8824('0x3c')]['find']({'where':{'id':_0x6fcfb3[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x186c2f,null))[_0x8824('0x31')](function(_0x2a4821){if(_0x2a4821){return _0x2a4821[_0x8824('0xb2')](_0x6fcfb3[_0x8824('0x5b')][_0x8824('0x68')],_[_0x8824('0xb3')](_0x6fcfb3[_0x8824('0x5b')],[_0x8824('0x68'),'id'])||{})[_0x8824('0xb4')](function(_0x59b414){for(var _0xe86fbf=0x0;_0xe86fbf<_0x6fcfb3[_0x8824('0x5b')][_0x8824('0x68')][_0x8824('0x57')];_0xe86fbf+=0x1){socket[_0x8824('0xb5')]('userOpenchannelAccount:save',{'UserId':Number(_0x6fcfb3[_0x8824('0x5b')][_0x8824('0x68')][_0xe86fbf]),'OpenchannelAccountId':Number(_0x6fcfb3[_0x8824('0x56')]['id'])});}return _0x59b414;});}})[_0x8824('0x31')](respondWithResult(_0x186c2f,null))[_0x8824('0x55')](handleError(_0x186c2f,null));};exports[_0x8824('0xb6')]=function(_0x297cbc,_0x1cebc2,_0x142269){return db[_0x8824('0x3c')][_0x8824('0x59')]({'where':{'id':_0x297cbc[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x1cebc2,null))[_0x8824('0x31')](function(_0x56305c){if(_0x56305c){return _0x56305c[_0x8824('0xb6')](_0x297cbc[_0x8824('0x41')]['ids'])[_0x8824('0x31')](function(){if(_[_0x8824('0xb7')](_0x297cbc['query'][_0x8824('0x68')])){for(var _0x1b2c3c=0x0;_0x1b2c3c<_0x297cbc[_0x8824('0x41')][_0x8824('0x68')][_0x8824('0x57')];_0x1b2c3c+=0x1){socket['emit'](_0x8824('0xb8'),{'UserId':Number(_0x297cbc['query'][_0x8824('0x68')][_0x1b2c3c]),'OpenchannelAccountId':Number(_0x297cbc[_0x8824('0x56')]['id'])});}}else{socket[_0x8824('0xb5')](_0x8824('0xb8'),{'UserId':Number(_0x297cbc[_0x8824('0x41')][_0x8824('0x68')]),'OpenchannelAccountId':Number(_0x297cbc[_0x8824('0x56')]['id'])});}});}})[_0x8824('0x31')](respondWithStatusCode(_0x1cebc2,null))[_0x8824('0x55')](handleError(_0x1cebc2,null));};exports['getAgents']=function(_0x587cb8,_0x30fe5b,_0x442e04){var _0x4bf869={};var _0x49c350={};var _0x42de43;var _0x18742f;return db['OpenchannelAccount']['findOne']({'where':{'id':_0x587cb8['params']['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x30fe5b,null))[_0x8824('0x31')](function(_0x7efafc){if(_0x7efafc){_0x42de43=_0x7efafc;_0x49c350[_0x8824('0x40')]=_[_0x8824('0x42')](db[_0x8824('0x9a')][_0x8824('0x3d')]);_0x49c350[_0x8824('0x41')]=_[_0x8824('0x42')](_0x587cb8[_0x8824('0x41')]);_0x49c350['filters']=_['intersection'](_0x49c350[_0x8824('0x40')],_0x49c350[_0x8824('0x41')]);_0x4bf869[_0x8824('0x45')]=_[_0x8824('0x44')](_0x49c350[_0x8824('0x40')],qs['fields'](_0x587cb8[_0x8824('0x41')][_0x8824('0x46')]));_0x4bf869[_0x8824('0x45')]=_0x4bf869[_0x8824('0x45')]['length']?_0x4bf869[_0x8824('0x45')]:_0x49c350[_0x8824('0x40')];_0x4bf869[_0x8824('0x4a')]=qs[_0x8824('0x4b')](_0x587cb8[_0x8824('0x41')][_0x8824('0x4b')]);_0x4bf869['where']=qs['filters'](_[_0x8824('0x4d')](_0x587cb8[_0x8824('0x41')],_0x49c350['filters']));if(_0x587cb8[_0x8824('0x41')][_0x8824('0x4e')]){_0x4bf869[_0x8824('0x4c')]=_['merge'](_0x4bf869[_0x8824('0x4c')],{'$or':_[_0x8824('0x3b')](_0x4bf869[_0x8824('0x45')],function(_0x48f18a){var _0x563529={};_0x563529[_0x48f18a]={'$like':'%'+_0x587cb8[_0x8824('0x41')]['filter']+'%'};return _0x563529;})});}_0x4bf869=_['merge']({},_0x4bf869,_0x587cb8[_0x8824('0x51')]);return _0x42de43[_0x8824('0xb9')](_0x4bf869);}})[_0x8824('0x31')](function(_0x471664){if(_0x471664){_0x18742f=_0x471664['length'];if(!_0x587cb8['query']['hasOwnProperty'](_0x8824('0x48'))){_0x4bf869[_0x8824('0x29')]=qs[_0x8824('0x29')](_0x587cb8['query'][_0x8824('0x29')]);_0x4bf869['offset']=qs[_0x8824('0x49')](_0x587cb8[_0x8824('0x41')][_0x8824('0x49')]);}return _0x42de43['getAgents'](_0x4bf869);}})[_0x8824('0x31')](function(_0x50b50d){if(_0x50b50d){return _0x50b50d?{'count':_0x18742f,'rows':_0x50b50d}:null;}})[_0x8824('0x31')](respondWithResult(_0x30fe5b,null))[_0x8824('0x55')](handleError(_0x30fe5b,null));};exports[_0x8824('0x37')]=function(_0x315270,_0x22acc3,_0x3476f5){var _0x30cd3f,_0x49784b,_0x20a0b9;if(_[_0x8824('0x77')](_0x315270['body']['body'])||_0x315270['body'][_0x8824('0x5b')]===''){throw new db[(_0x8824('0x6f'))][(_0x8824('0x70'))](_0x8824('0x7a'));}if(_['isNil'](_0x315270[_0x8824('0x5b')]['to'])){}_0x30cd3f=_0x315270[_0x8824('0x5b')]['to'];return db['OpenchannelAccount']['findOne']({'where':{'id':_0x315270[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x22acc3,null))[_0x8824('0x31')](function(_0x20578d){if(_0x20578d){return db[_0x8824('0x3c')]['find']({'where':{'id':_0x20578d['id']},'include':[{'model':db[_0x8824('0xba')],'as':'List','include':[{'model':db[_0x8824('0x6e')],'as':_0x8824('0x7f'),'where':{[_0x20578d[_0x8824('0x7b')]]:_0x30cd3f},'limit':0x1,'order':[[_0x8824('0x74'),_0x8824('0x80')]]}]}]})[_0x8824('0x31')](handleEntityNotFound(_0x22acc3,null))[_0x8824('0x31')](function(_0x24c4c0){if(_0x24c4c0&&_0x24c4c0[_0x8824('0x7e')]){_0x49784b=_0x24c4c0[_0x8824('0x33')]({'plain':!![]});if(_0x49784b[_0x8824('0x7e')]&&_0x49784b['List'][_0x8824('0x7f')][_0x8824('0x57')]){return _0x49784b['List'][_0x8824('0x7f')][0x0];}return db[_0x8824('0x6e')][_0x8824('0x5a')](_['defaults'](_0x315270['body'],{'firstName':_0x30cd3f,[_0x24c4c0[_0x8824('0x7b')]]:_0x30cd3f,'phone':_0x30cd3f,'ListId':_0x49784b[_0x8824('0x76')]}));}})[_0x8824('0x31')](handleEntityNotFound(_0x22acc3,null))[_0x8824('0x31')](function(_0x313ec7){if(_0x313ec7){_0x20a0b9=_0x313ec7;return db[_0x8824('0x8c')]['find']({'where':{'ContactId':_0x20a0b9['id'],'closed':![],'OpenchannelAccountId':_0x49784b['id']}})['then'](function(_0x368e41){if(_0x368e41){return[_0x368e41,![]];}return db[_0x8824('0x8c')]['create']({'UserId':_0x315270[_0x8824('0x5c')]['id'],'ContactId':_0x20a0b9['id'],'OpenchannelAccountId':_0x49784b['id'],'lastMsgDirection':'out','firstMsgDirection':_0x8824('0xbb'),'Messages':[_[_0x8824('0x4f')](_0x315270[_0x8824('0x5b')],{'read':![],'body':_0x315270[_0x8824('0x5b')]['body'],'OpenchannelAccountId':_0x49784b['id'],'UserId':_0x315270[_0x8824('0x5c')]['id'],'ContactId':_0x20a0b9['id']})]},{'include':[{'model':db[_0x8824('0x98')],'as':_0x8824('0xbc')}]})[_0x8824('0x31')](function(_0xffa63b){return[_0xffa63b,!![]];});});}})['spread'](function(_0x43afae,_0x848fa0){if(_0x848fa0){return _0x43afae;}return db[_0x8824('0x98')][_0x8824('0x5a')](_[_0x8824('0x4f')](_0x315270['body'],{'read':![],'body':_0x315270['body'][_0x8824('0x5b')],'OpenchannelAccountId':_0x49784b['id'],'OpenchannelInteractionId':_0x43afae['id'],'UserId':_0x315270[_0x8824('0x5c')]['id'],'ContactId':_0x20a0b9['id']}))[_0x8824('0x31')](function(_0x37dcca){_0x43afae['dataValues'][_0x8824('0xbc')]=[];_0x43afae['dataValues'][_0x8824('0xbc')]['push'](_0x37dcca['dataValues']);return _0x43afae;});});}})[_0x8824('0x31')](respondWithResult(_0x22acc3,null))[_0x8824('0x55')](handleError(_0x22acc3,null));};
\ No newline at end of file