Built motion from commit da617fac.|2.6.6
[motion2.git] / server / api / openchannelAccount / openchannelAccount.controller.js
index 7b894b9..d4f0707 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 _0x89b2=['Tag','Tags','color','tag','addAgents','emit','userOpenchannelAccount:save','removeAgents','userOpenchannelAccount:remove','getAgents','send','updatedAt','out','dataValues','Messages','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','fs-extra','crypto','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/license/util','../../mysqldb','defaults','localhost','socket.io-emitter','redis','./openchannelAccount.socket','register','jayson/promise','client','http','request','then','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','catch','sendStatus','status','end','json','undefined','limit','count','offset','set','apply','reject','save','update','destroy','get','UserProfileResource','stack','name','Pause','mandatoryDispositionPause','rawAttributes','fieldName','type','key','model','query','keys','intersection','attributes','fields','hasOwnProperty','order','sort','where','pick','filters','filter','merge','map','VIRTUAL','OpenchannelAccount','includeAll','include','rows','show','params','length','options','find','create','user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','describe','addDisposition','OpenchannelAccountId','Disposition','getDispositions','findOne','findAll','removeDispositions','ids','CannedAnswer','nolimit','removeAnswers','notify','openchannel','CmContact','Sequelize','ValidationError','difference','createdAt','CompanyId','ListId','isNil','from','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','List','Contacts','DESC','Applications','account','applications','list','orderBy','priority','asc','lastName','threadId','OpenchannelInteraction','externalUrl','ContactId','contact','firstName','messageId','interaction','created','push','close','*,*,*,*','OpenchannelMessage','User','forcedOwnership','Start','startRouting','EventManager','addApplications','transaction','sequelize','Transaction','OpenchannelApplication','finally','getApplications','getInteractions','Contact','fullname','internal'];(function(_0x199bc4,_0x338105){var _0x136ffb=function(_0x3e7ced){while(--_0x3e7ced){_0x199bc4['push'](_0x199bc4['shift']());}};_0x136ffb(++_0x338105);}(_0x89b2,0xc6));var _0x289b=function(_0x486f0b,_0x19a9b7){_0x486f0b=_0x486f0b-0x0;var _0x12ccaf=_0x89b2[_0x486f0b];return _0x12ccaf;};'use strict';var emlformat=require(_0x289b('0x0'));var rimraf=require(_0x289b('0x1'));var zipdir=require(_0x289b('0x2'));var jsonpatch=require(_0x289b('0x3'));var rp=require(_0x289b('0x4'));var moment=require(_0x289b('0x5'));var BPromise=require(_0x289b('0x6'));var Mustache=require(_0x289b('0x7'));var util=require(_0x289b('0x8'));var path=require(_0x289b('0x9'));var sox=require(_0x289b('0xa'));var csv=require(_0x289b('0xb'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x289b('0xc'));var _=require('lodash');var squel=require('squel');var crypto=require(_0x289b('0xd'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x289b('0xe'));var Papa=require(_0x289b('0xf'));var Redis=require(_0x289b('0x10'));var authService=require(_0x289b('0x11'));var qs=require(_0x289b('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x289b('0x13'));var logger=require('../../config/logger')(_0x289b('0x14'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x289b('0x15'));var db=require(_0x289b('0x16'))['db'];config['redis']=_[_0x289b('0x17')](config['redis'],{'host':_0x289b('0x18'),'port':0x18eb});var socket=require(_0x289b('0x19'))(new Redis(config[_0x289b('0x1a')]));require(_0x289b('0x1b'))[_0x289b('0x1c')](socket);var jayson=require(_0x289b('0x1d'));var client=jayson[_0x289b('0x1e')][_0x289b('0x1f')]({'port':0x232c});var client9002=jayson[_0x289b('0x1e')][_0x289b('0x1f')]({'port':0x232a});function respondWithRpcPromise(_0x1a6807,_0x345a5f,_0x405a2c,_0x3a7c07){return new BPromise(function(_0x5e3dcd,_0x117ef9){var _0x1d36dd=_0x3a7c07||client;return _0x1d36dd[_0x289b('0x20')](_0x1a6807,_0x405a2c)[_0x289b('0x21')](function(_0x39ba6f){logger['info'](_0x289b('0x22'),_0x345a5f,_0x289b('0x23'));logger['debug'](_0x289b('0x24'),_0x345a5f,_0x289b('0x23'),JSON[_0x289b('0x25')](_0x39ba6f));if(_0x39ba6f[_0x289b('0x26')]){if(_0x39ba6f[_0x289b('0x26')][_0x289b('0x27')]===0x1f4){logger[_0x289b('0x26')](_0x289b('0x22'),_0x345a5f,_0x39ba6f[_0x289b('0x26')][_0x289b('0x28')]);return _0x117ef9(_0x39ba6f[_0x289b('0x26')][_0x289b('0x28')]);}logger[_0x289b('0x26')](_0x289b('0x22'),_0x345a5f,_0x39ba6f['error'][_0x289b('0x28')]);return _0x5e3dcd(_0x39ba6f['error']['message']);}else{logger[_0x289b('0x29')](_0x289b('0x22'),_0x345a5f,_0x289b('0x23'));_0x5e3dcd(_0x39ba6f['result'][_0x289b('0x28')]);}})[_0x289b('0x2a')](function(_0x51c0c0){logger[_0x289b('0x26')](_0x289b('0x22'),_0x345a5f,_0x51c0c0);_0x117ef9(_0x51c0c0);});});}function respondWithStatusCode(_0x58b6fa,_0x5d8a23){_0x5d8a23=_0x5d8a23||0xcc;return function(_0x24a37f){if(_0x24a37f){return _0x58b6fa[_0x289b('0x2b')](_0x5d8a23);}return _0x58b6fa[_0x289b('0x2c')](_0x5d8a23)[_0x289b('0x2d')]();};}function respondWithResult(_0x3fa519,_0x3e63b5){_0x3e63b5=_0x3e63b5||0xc8;return function(_0x2fdaeb){if(_0x2fdaeb){return _0x3fa519[_0x289b('0x2c')](_0x3e63b5)[_0x289b('0x2e')](_0x2fdaeb);}};}function respondWithFilteredResult(_0x5958da,_0x7b8fd0){return function(_0x4ceaec){if(_0x4ceaec){var _0x598002=typeof _0x7b8fd0['offset']===_0x289b('0x2f')&&typeof _0x7b8fd0[_0x289b('0x30')]===_0x289b('0x2f');var _0x10fc50=_0x4ceaec[_0x289b('0x31')];var _0x271aa8=_0x598002?0x0:_0x7b8fd0[_0x289b('0x32')];var _0xca1604=_0x598002?_0x4ceaec[_0x289b('0x31')]:_0x7b8fd0[_0x289b('0x32')]+_0x7b8fd0['limit'];var _0x94c5a5;if(_0xca1604>=_0x10fc50){_0xca1604=_0x10fc50;_0x94c5a5=0xc8;}else{_0x94c5a5=0xce;}_0x5958da[_0x289b('0x2c')](_0x94c5a5);return _0x5958da[_0x289b('0x33')]('Content-Range',_0x271aa8+'-'+_0xca1604+'/'+_0x10fc50)[_0x289b('0x2e')](_0x4ceaec);}return null;};}function patchUpdates(_0xcfa83e){return function(_0x42f535){try{jsonpatch[_0x289b('0x34')](_0x42f535,_0xcfa83e,!![]);}catch(_0x4e7d64){return BPromise[_0x289b('0x35')](_0x4e7d64);}return _0x42f535[_0x289b('0x36')]();};}function saveUpdates(_0x24f8b6,_0x199609){return function(_0x1444f2){if(_0x1444f2){return _0x1444f2[_0x289b('0x37')](_0x24f8b6)[_0x289b('0x21')](function(_0x173ec3){return _0x173ec3;});}return null;};}function removeEntity(_0x3c031e,_0x55289d){return function(_0x1dcd42){if(_0x1dcd42){return _0x1dcd42[_0x289b('0x38')]()['then'](function(){var _0x5d4c9d=_0x1dcd42[_0x289b('0x39')]({'plain':!![]});var _0x18dd30='OpenchannelAccounts';return db[_0x289b('0x3a')][_0x289b('0x38')]({'where':{'type':_0x18dd30,'resourceId':_0x5d4c9d['id']}})[_0x289b('0x21')](function(){return _0x1dcd42;});})['then'](function(){_0x3c031e['status'](0xcc)[_0x289b('0x2d')]();});}};}function handleEntityNotFound(_0xcf9121,_0x27c9bf){return function(_0x428d11){if(!_0x428d11){_0xcf9121[_0x289b('0x2b')](0x194);}return _0x428d11;};}function handleError(_0x47ea18,_0x17596f){_0x17596f=_0x17596f||0x1f4;return function(_0x3a76e5){logger[_0x289b('0x26')](_0x3a76e5[_0x289b('0x3b')]);if(_0x3a76e5[_0x289b('0x3c')]){delete _0x3a76e5[_0x289b('0x3c')];}_0x47ea18[_0x289b('0x2c')](_0x17596f)['send'](_0x3a76e5);};}exports['index']=function(_0x55d195,_0x37a4d1){var _0x25ffab={'include':[{'model':db[_0x289b('0x3d')],'as':_0x289b('0x3e')}]},_0x15090a={},_0x39b472={'count':0x0,'rows':[]};var _0x20c064=_['map'](db['OpenchannelAccount'][_0x289b('0x3f')],function(_0x353de1){return{'name':_0x353de1[_0x289b('0x40')],'type':_0x353de1[_0x289b('0x41')][_0x289b('0x42')]};});_0x15090a[_0x289b('0x43')]=_['map'](_0x20c064,_0x289b('0x3c'));_0x15090a[_0x289b('0x44')]=_[_0x289b('0x45')](_0x55d195[_0x289b('0x44')]);_0x15090a['filters']=_[_0x289b('0x46')](_0x15090a['model'],_0x15090a[_0x289b('0x44')]);_0x25ffab[_0x289b('0x47')]=_['intersection'](_0x15090a[_0x289b('0x43')],qs[_0x289b('0x48')](_0x55d195['query'][_0x289b('0x48')]));_0x25ffab[_0x289b('0x47')]=_0x25ffab[_0x289b('0x47')]['length']?_0x25ffab[_0x289b('0x47')]:_0x15090a[_0x289b('0x43')];if(!_0x55d195[_0x289b('0x44')][_0x289b('0x49')]('nolimit')){_0x25ffab[_0x289b('0x30')]=qs[_0x289b('0x30')](_0x55d195['query'][_0x289b('0x30')]);_0x25ffab['offset']=qs[_0x289b('0x32')](_0x55d195[_0x289b('0x44')]['offset']);}_0x25ffab[_0x289b('0x4a')]=qs['sort'](_0x55d195[_0x289b('0x44')][_0x289b('0x4b')]);_0x25ffab[_0x289b('0x4c')]=qs['filters'](_[_0x289b('0x4d')](_0x55d195[_0x289b('0x44')],_0x15090a[_0x289b('0x4e')]),_0x20c064);if(_0x55d195[_0x289b('0x44')][_0x289b('0x4f')]){_0x25ffab[_0x289b('0x4c')]=_[_0x289b('0x50')](_0x25ffab[_0x289b('0x4c')],{'$or':_[_0x289b('0x51')](_0x20c064,function(_0x3fab7){if(_0x3fab7[_0x289b('0x41')]!==_0x289b('0x52')){var _0x141abe={};_0x141abe[_0x3fab7[_0x289b('0x3c')]]={'$like':'%'+_0x55d195['query'][_0x289b('0x4f')]+'%'};return _0x141abe;}})});}_0x25ffab=_[_0x289b('0x50')]({},_0x25ffab,_0x55d195['options']);var _0x1f5086={'where':_0x25ffab[_0x289b('0x4c')]};return db[_0x289b('0x53')][_0x289b('0x31')](_0x1f5086)['then'](function(_0x4d9759){_0x39b472[_0x289b('0x31')]=_0x4d9759;if(_0x55d195[_0x289b('0x44')][_0x289b('0x54')]){_0x25ffab[_0x289b('0x55')]=[{'all':!![]}];}return db[_0x289b('0x53')]['findAll'](_0x25ffab);})['then'](function(_0x14e4f4){_0x39b472[_0x289b('0x56')]=_0x14e4f4;return _0x39b472;})[_0x289b('0x21')](respondWithFilteredResult(_0x37a4d1,_0x25ffab))[_0x289b('0x2a')](handleError(_0x37a4d1,null));};exports[_0x289b('0x57')]=function(_0x30fe9d,_0x241ac7){var _0x3ab297={'raw':![],'where':{'id':_0x30fe9d[_0x289b('0x58')]['id']},'include':[{'model':db[_0x289b('0x3d')],'as':_0x289b('0x3e')}]},_0x47736a={};_0x47736a[_0x289b('0x43')]=_[_0x289b('0x45')](db[_0x289b('0x53')]['rawAttributes']);_0x47736a[_0x289b('0x44')]=_[_0x289b('0x45')](_0x30fe9d[_0x289b('0x44')]);_0x47736a[_0x289b('0x4e')]=_[_0x289b('0x46')](_0x47736a[_0x289b('0x43')],_0x47736a['query']);_0x3ab297[_0x289b('0x47')]=_['intersection'](_0x47736a['model'],qs['fields'](_0x30fe9d[_0x289b('0x44')]['fields']));_0x3ab297['attributes']=_0x3ab297[_0x289b('0x47')][_0x289b('0x59')]?_0x3ab297['attributes']:_0x47736a[_0x289b('0x43')];if(_0x30fe9d['query'][_0x289b('0x54')]){_0x3ab297[_0x289b('0x55')]=[{'all':!![]}];}_0x3ab297=_[_0x289b('0x50')]({},_0x3ab297,_0x30fe9d[_0x289b('0x5a')]);return db[_0x289b('0x53')][_0x289b('0x5b')](_0x3ab297)[_0x289b('0x21')](handleEntityNotFound(_0x241ac7,null))[_0x289b('0x21')](respondWithResult(_0x241ac7,null))[_0x289b('0x2a')](handleError(_0x241ac7,null));};exports['create']=function(_0x1db13c,_0x3a3a3b){return db[_0x289b('0x53')][_0x289b('0x5c')](_0x1db13c['body'],{})[_0x289b('0x21')](function(_0x3448e0){var _0x38a278=_0x1db13c[_0x289b('0x5d')][_0x289b('0x39')]({'plain':!![]});if(!_0x38a278)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x38a278[_0x289b('0x5e')]===_0x289b('0x5d')){var _0x322c7d=_0x3448e0[_0x289b('0x39')]({'plain':!![]});var _0x5a1a8e='OpenchannelAccounts';return db[_0x289b('0x5f')]['find']({'where':{'name':_0x5a1a8e,'userProfileId':_0x38a278[_0x289b('0x60')]},'raw':!![]})[_0x289b('0x21')](function(_0x45498e){if(_0x45498e&&_0x45498e[_0x289b('0x61')]===0x0){return db['UserProfileResource'][_0x289b('0x5c')]({'name':_0x322c7d[_0x289b('0x3c')],'resourceId':_0x322c7d['id'],'type':_0x45498e[_0x289b('0x3c')],'sectionId':_0x45498e['id']},{})[_0x289b('0x21')](function(){return _0x3448e0;});}else{return _0x3448e0;}})[_0x289b('0x2a')](function(_0x34abe4){logger[_0x289b('0x26')](_0x289b('0x62'),_0x34abe4);throw _0x34abe4;});}return _0x3448e0;})[_0x289b('0x21')](respondWithResult(_0x3a3a3b,0xc9))['catch'](handleError(_0x3a3a3b,null));};exports[_0x289b('0x37')]=function(_0x48bf52,_0x1edc52){if(_0x48bf52[_0x289b('0x63')]['id']){delete _0x48bf52[_0x289b('0x63')]['id'];}return db[_0x289b('0x53')][_0x289b('0x5b')]({'where':{'id':_0x48bf52[_0x289b('0x58')]['id']},'include':[{'model':db[_0x289b('0x3d')],'as':_0x289b('0x3e')}]})[_0x289b('0x21')](handleEntityNotFound(_0x1edc52,null))[_0x289b('0x21')](saveUpdates(_0x48bf52['body'],null))[_0x289b('0x21')](respondWithResult(_0x1edc52,null))[_0x289b('0x2a')](handleError(_0x1edc52,null));};exports['destroy']=function(_0x28e003,_0x146df6){return db[_0x289b('0x53')][_0x289b('0x5b')]({'where':{'id':_0x28e003['params']['id']}})['then'](handleEntityNotFound(_0x146df6,null))[_0x289b('0x21')](removeEntity(_0x146df6,null))[_0x289b('0x2a')](handleError(_0x146df6,null));};exports[_0x289b('0x64')]=function(_0xd3cf71,_0x3ca4b0){return db['OpenchannelAccount'][_0x289b('0x64')]()[_0x289b('0x21')](respondWithResult(_0x3ca4b0,null))[_0x289b('0x2a')](handleError(_0x3ca4b0,null));};exports[_0x289b('0x65')]=function(_0x2b1f10,_0x579a70,_0x51110a){if(_0x2b1f10['body']['id']){delete _0x2b1f10[_0x289b('0x63')]['id'];}return db[_0x289b('0x53')][_0x289b('0x5b')]({'where':{'id':_0x2b1f10[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x579a70,null))['then'](function(_0x412a4e){if(_0x412a4e){_0x2b1f10[_0x289b('0x63')][_0x289b('0x66')]=_0x412a4e['id'];return db[_0x289b('0x67')][_0x289b('0x5c')](_0x2b1f10['body']);}})['then'](respondWithResult(_0x579a70,null))[_0x289b('0x2a')](handleError(_0x579a70,null));};exports[_0x289b('0x68')]=function(_0xddb5de,_0x314eca,_0x332ebb){var _0x50dcdb={'raw':![],'where':{}};var _0x5234f6={};var _0x2551f8={'count':0x0,'rows':[]};return db[_0x289b('0x53')][_0x289b('0x69')]({'where':{'id':_0xddb5de[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x314eca,null))[_0x289b('0x21')](function(_0x560056){if(_0x560056){_0x5234f6[_0x289b('0x43')]=_[_0x289b('0x45')](db[_0x289b('0x67')]['rawAttributes']);_0x5234f6[_0x289b('0x44')]=_['keys'](_0xddb5de[_0x289b('0x44')]);_0x5234f6[_0x289b('0x4e')]=_[_0x289b('0x46')](_0x5234f6[_0x289b('0x43')],_0x5234f6[_0x289b('0x44')]);_0x50dcdb[_0x289b('0x47')]=_['intersection'](_0x5234f6[_0x289b('0x43')],qs[_0x289b('0x48')](_0xddb5de[_0x289b('0x44')]['fields']));_0x50dcdb[_0x289b('0x47')]=_0x50dcdb[_0x289b('0x47')][_0x289b('0x59')]?_0x50dcdb['attributes']:_0x5234f6[_0x289b('0x43')];if(!_0xddb5de[_0x289b('0x44')][_0x289b('0x49')]('nolimit')){_0x50dcdb[_0x289b('0x30')]=qs[_0x289b('0x30')](_0xddb5de[_0x289b('0x44')][_0x289b('0x30')]);_0x50dcdb[_0x289b('0x32')]=qs['offset'](_0xddb5de[_0x289b('0x44')][_0x289b('0x32')]);}_0x50dcdb[_0x289b('0x4a')]=qs[_0x289b('0x4b')](_0xddb5de[_0x289b('0x44')][_0x289b('0x4b')]);_0x50dcdb['where']=qs[_0x289b('0x4e')](_[_0x289b('0x4d')](_0xddb5de['query'],_0x5234f6[_0x289b('0x4e')]));_0x50dcdb[_0x289b('0x4c')][_0x289b('0x66')]=_0x560056['id'];if(_0xddb5de[_0x289b('0x44')]['filter']){_0x50dcdb[_0x289b('0x4c')]=_[_0x289b('0x50')](_0x50dcdb['where'],{'$or':_[_0x289b('0x51')](_0x50dcdb[_0x289b('0x47')],function(_0x52a8bf){var _0x48d129={};_0x48d129[_0x52a8bf]={'$like':'%'+_0xddb5de['query'][_0x289b('0x4f')]+'%'};return _0x48d129;})});}_0x50dcdb=_[_0x289b('0x50')]({},_0x50dcdb,_0xddb5de[_0x289b('0x5a')]);return db[_0x289b('0x67')]['count']({'where':_0x50dcdb[_0x289b('0x4c')]})[_0x289b('0x21')](function(_0x277647){_0x2551f8[_0x289b('0x31')]=_0x277647;if(_0xddb5de[_0x289b('0x44')][_0x289b('0x54')]){_0x50dcdb['include']=[{'all':!![]}];}return db[_0x289b('0x67')][_0x289b('0x6a')](_0x50dcdb);})[_0x289b('0x21')](function(_0x1fa0ec){_0x2551f8[_0x289b('0x56')]=_0x1fa0ec;return _0x2551f8;});}})[_0x289b('0x21')](respondWithFilteredResult(_0x314eca,_0x50dcdb))['catch'](handleError(_0x314eca,null));};exports['removeDispositions']=function(_0x5afc98,_0x466de8,_0x4e5aa9){return db[_0x289b('0x53')][_0x289b('0x5b')]({'where':{'id':_0x5afc98['params']['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x466de8,null))['then'](function(_0x1e5066){if(_0x1e5066){return _0x1e5066[_0x289b('0x6b')](_0x5afc98[_0x289b('0x44')][_0x289b('0x6c')]);}})['then'](respondWithStatusCode(_0x466de8,null))[_0x289b('0x2a')](handleError(_0x466de8,null));};exports['addAnswer']=function(_0x27602a,_0x3ad774,_0x484d70){if(_0x27602a['body']['id']){delete _0x27602a[_0x289b('0x63')]['id'];}return db[_0x289b('0x53')]['find']({'where':{'id':_0x27602a[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x3ad774,null))['then'](function(_0x559c91){if(_0x559c91){_0x27602a[_0x289b('0x63')][_0x289b('0x66')]=_0x559c91['id'];return db[_0x289b('0x6d')][_0x289b('0x5c')](_0x27602a[_0x289b('0x63')]);}})[_0x289b('0x21')](respondWithResult(_0x3ad774,null))[_0x289b('0x2a')](handleError(_0x3ad774,null));};exports['getAnswers']=function(_0x17f15c,_0x1ae101,_0x110bad){var _0x279c90={'raw':![],'where':{}};var _0x42128b={};var _0x4ee7d0={'count':0x0,'rows':[]};return db[_0x289b('0x53')][_0x289b('0x69')]({'where':{'id':_0x17f15c['params']['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x1ae101,null))[_0x289b('0x21')](function(_0x524e8c){if(_0x524e8c){_0x42128b['model']=_[_0x289b('0x45')](db[_0x289b('0x6d')][_0x289b('0x3f')]);_0x42128b['query']=_[_0x289b('0x45')](_0x17f15c[_0x289b('0x44')]);_0x42128b['filters']=_[_0x289b('0x46')](_0x42128b[_0x289b('0x43')],_0x42128b[_0x289b('0x44')]);_0x279c90[_0x289b('0x47')]=_[_0x289b('0x46')](_0x42128b[_0x289b('0x43')],qs['fields'](_0x17f15c['query'][_0x289b('0x48')]));_0x279c90[_0x289b('0x47')]=_0x279c90[_0x289b('0x47')][_0x289b('0x59')]?_0x279c90[_0x289b('0x47')]:_0x42128b['model'];if(!_0x17f15c[_0x289b('0x44')]['hasOwnProperty'](_0x289b('0x6e'))){_0x279c90['limit']=qs[_0x289b('0x30')](_0x17f15c[_0x289b('0x44')][_0x289b('0x30')]);_0x279c90['offset']=qs['offset'](_0x17f15c[_0x289b('0x44')][_0x289b('0x32')]);}_0x279c90[_0x289b('0x4a')]=qs['sort'](_0x17f15c[_0x289b('0x44')][_0x289b('0x4b')]);_0x279c90[_0x289b('0x4c')]=qs[_0x289b('0x4e')](_['pick'](_0x17f15c['query'],_0x42128b['filters']));_0x279c90[_0x289b('0x4c')][_0x289b('0x66')]=_0x524e8c['id'];if(_0x17f15c[_0x289b('0x44')][_0x289b('0x4f')]){_0x279c90['where']=_['merge'](_0x279c90[_0x289b('0x4c')],{'$or':_['map'](_0x279c90[_0x289b('0x47')],function(_0x43514b){var _0x53ff05={};_0x53ff05[_0x43514b]={'$like':'%'+_0x17f15c['query'][_0x289b('0x4f')]+'%'};return _0x53ff05;})});}_0x279c90=_[_0x289b('0x50')]({},_0x279c90,_0x17f15c[_0x289b('0x5a')]);return db[_0x289b('0x6d')][_0x289b('0x31')]({'where':_0x279c90[_0x289b('0x4c')]})['then'](function(_0x18e58d){_0x4ee7d0['count']=_0x18e58d;if(_0x17f15c['query']['includeAll']){_0x279c90['include']=[{'all':!![]}];}return db['CannedAnswer'][_0x289b('0x6a')](_0x279c90);})[_0x289b('0x21')](function(_0xc82e72){_0x4ee7d0[_0x289b('0x56')]=_0xc82e72;return _0x4ee7d0;});}})[_0x289b('0x21')](respondWithFilteredResult(_0x1ae101,_0x279c90))[_0x289b('0x2a')](handleError(_0x1ae101,null));};exports['removeAnswers']=function(_0x1bae6f,_0x4ef426,_0x32c505){return db[_0x289b('0x53')][_0x289b('0x5b')]({'where':{'id':_0x1bae6f[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x4ef426,null))[_0x289b('0x21')](function(_0x44f777){if(_0x44f777){return _0x44f777[_0x289b('0x6f')](_0x1bae6f[_0x289b('0x44')][_0x289b('0x6c')]);}})[_0x289b('0x21')](respondWithStatusCode(_0x4ef426,null))['catch'](handleError(_0x4ef426,null));};exports[_0x289b('0x70')]=function(_0x3d764e,_0x139c4c,_0x3d1eb2){var _0x1b96e5={'body':_0x3d764e['body'],'channel':_0x289b('0x71')};var _0x2a2596=[];var _0x2592a2=[];var _0xa01544={};var _0x5b690f=![];return db[_0x289b('0x72')][_0x289b('0x64')]()['then'](function(_0xe93d96){if(!_0xe93d96){throw new db[(_0x289b('0x73'))][(_0x289b('0x74'))]('no\x20available\x20attributes');}_0x2a2596=_[_0x289b('0x75')](_[_0x289b('0x45')](_0xe93d96),[_0x289b('0x76'),'updatedAt']);_0x2592a2=_[_0x289b('0x75')](_[_0x289b('0x45')](_0xe93d96),['createdAt','updatedAt',_0x289b('0x77'),_0x289b('0x78')]);if(_0x3d764e[_0x289b('0x63')]['id']){delete _0x3d764e[_0x289b('0x63')]['id'];}if(_[_0x289b('0x79')](_0x3d764e['body'][_0x289b('0x7a')])){throw new db['Sequelize'][(_0x289b('0x74'))]('from\x20is\x20mandatory');}if(_[_0x289b('0x79')](_0x3d764e[_0x289b('0x63')][_0x289b('0x63')])||_0x3d764e['body'][_0x289b('0x63')]===''){throw new db[(_0x289b('0x73'))]['ValidationError'](_0x289b('0x7b'));}if(_[_0x289b('0x79')](_0x3d764e[_0x289b('0x63')][_0x289b('0x7c')])){throw new db[(_0x289b('0x73'))]['ValidationError']('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x2592a2);}if(!_[_0x289b('0x7d')](_0x2592a2,_0x3d764e[_0x289b('0x63')]['mapKey'])){throw new db[(_0x289b('0x73'))][(_0x289b('0x74'))](_0x289b('0x7e')+_0x2592a2);}_0xa01544[_0x3d764e[_0x289b('0x63')][_0x289b('0x7c')]]=_0x3d764e['body']['from'];})[_0x289b('0x21')](function(){return db[_0x289b('0x53')]['find']({'where':{'id':_0x3d764e[_0x289b('0x58')]['id']},'include':[{'model':db[_0x289b('0x7f')],'as':_0x289b('0x80'),'include':[{'model':db[_0x289b('0x72')],'as':_0x289b('0x81'),'where':_0xa01544,'limit':0x1,'order':[['updatedAt',_0x289b('0x82')]]}]},{'model':db['OpenchannelApplication'],'as':_0x289b('0x83')}]});})[_0x289b('0x21')](handleEntityNotFound(_0x139c4c,null))[_0x289b('0x21')](function(_0x234ff8){if(_0x234ff8&&_0x234ff8['List']){_0x1b96e5[_0x289b('0x84')]=_0x234ff8;_0x1b96e5[_0x289b('0x85')]=_0x234ff8[_0x289b('0x83')];_0x1b96e5[_0x289b('0x86')]=_0x234ff8[_0x289b('0x80')];_0x1b96e5['applications']=_[_0x289b('0x87')](_0x1b96e5['applications'],[_0x289b('0x88')],[_0x289b('0x89')]);if(_0x1b96e5[_0x289b('0x84')][_0x289b('0x83')]){delete _0x1b96e5[_0x289b('0x84')][_0x289b('0x83')];}if(_0x1b96e5[_0x289b('0x84')][_0x289b('0x80')]&&_0x1b96e5[_0x289b('0x84')][_0x289b('0x80')][_0x289b('0x81')]['length']){return _0x1b96e5[_0x289b('0x84')][_0x289b('0x80')]['Contacts'][0x0];}var _0x159e0c=_[_0x289b('0x17')](_0x3d764e['body'],{'firstName':_0x3d764e['body'][_0x289b('0x7a')],'ListId':_0x234ff8[_0x289b('0x78')]});_0x159e0c[_0x3d764e[_0x289b('0x63')][_0x289b('0x7c')]]=_0x3d764e[_0x289b('0x63')][_0x289b('0x7a')];return db[_0x289b('0x72')][_0x289b('0x5c')](_0x159e0c,{'fields':_0x2a2596,'raw':!![]});}})[_0x289b('0x21')](handleEntityNotFound(_0x139c4c,null))[_0x289b('0x21')](function(_0x107930){_0x1b96e5['contact']=_0x107930;if(_0x107930){var _0x237d43={'ContactId':_0x107930['id'],'OpenchannelAccountId':_0x3d764e[_0x289b('0x58')]['id'],'from':(_0x107930['firstName']||'')+'\x20'+(_0x107930[_0x289b('0x8a')]||'')};var _0x158b71={'OpenchannelAccountId':_0x3d764e[_0x289b('0x58')]['id'],'closed':![]};if(_0x3d764e['body'][_0x289b('0x8b')]){_0x158b71[_0x289b('0x8b')]=_0x3d764e[_0x289b('0x63')]['threadId'];return db[_0x289b('0x8c')][_0x289b('0x5b')]({'where':_0x158b71})[_0x289b('0x21')](function(_0x2017d8){if(_0x2017d8){return[_0x2017d8,![]];}_0x237d43[_0x289b('0x8b')]=_0x3d764e['body'][_0x289b('0x8b')];_0x237d43[_0x289b('0x8d')]=_0x3d764e[_0x289b('0x63')][_0x289b('0x8d')];return db[_0x289b('0x8c')][_0x289b('0x5c')](_0x237d43)['then'](function(_0x15e242){return[_0x15e242,!![]];});});}else{_0x158b71[_0x289b('0x8b')]=null;}_0x158b71[_0x289b('0x8e')]=_0x107930['id'];return db[_0x289b('0x8c')][_0x289b('0x5b')]({'where':_0x158b71})[_0x289b('0x21')](function(_0x38d25b){if(_0x38d25b){return[_0x38d25b,![]];}return db['OpenchannelInteraction']['create'](_0x237d43)[_0x289b('0x21')](function(_0x2872ff){return[_0x2872ff,!![]];});});}})['spread'](function(_0x4cb784,_0x33c7b2){if(_0x4cb784){_0x5b690f=_0x33c7b2;if(!_0x33c7b2){var _0x31ca63={'from':(_0x1b96e5[_0x289b('0x8f')][_0x289b('0x90')]||'')+'\x20'+(_0x1b96e5[_0x289b('0x8f')][_0x289b('0x8a')]||'')};if(_0x3d764e[_0x289b('0x63')][_0x289b('0x8b')]&&_0x3d764e[_0x289b('0x63')][_0x289b('0x91')]&&_0x3d764e[_0x289b('0x63')][_0x289b('0x8b')]!=_0x3d764e['body']['messageId']){_0x31ca63['threadId']=_0x3d764e[_0x289b('0x63')][_0x289b('0x91')];}return _0x4cb784['update'](_0x31ca63);}else{return _0x4cb784;}}})[_0x289b('0x21')](function(_0x2c2913){_0x1b96e5[_0x289b('0x92')]=_0x2c2913[_0x289b('0x39')]({'plain':!![]});_0x1b96e5[_0x289b('0x92')]['created']=_0x5b690f;if(_0x1b96e5[_0x289b('0x92')][_0x289b('0x93')]){if(_0x1b96e5[_0x289b('0x84')]['autoclose']){_0x1b96e5['applications'][_0x289b('0x94')]({'id':0x0,'priority':_0x1b96e5['applications']['length']+0x1,'app':_0x289b('0x95'),'appdata':'unmanaged','interval':_0x289b('0x96')});}}return db[_0x289b('0x97')]['create']({'body':_0x3d764e['body']['body'],'OpenchannelAccountId':_0x3d764e[_0x289b('0x58')]['id'],'OpenchannelInteractionId':_0x2c2913['id'],'direction':'in','ContactId':_0x1b96e5[_0x289b('0x8f')]['id'],'AttachmentId':_0x3d764e[_0x289b('0x63')]['AttachmentId']});})[_0x289b('0x21')](function(_0x1a788c){_0x1b96e5[_0x289b('0x28')]=_0x1a788c;if(_0x1b96e5['interaction']['UserId']){return db[_0x289b('0x98')][_0x289b('0x5b')]({'attributes':['id','name'],'where':{'id':_0x1b96e5['interaction']['UserId']}})[_0x289b('0x21')](function(_0x23a807){if(_0x23a807){_0x1b96e5[_0x289b('0x85')]['unshift']({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x23a807[_0x289b('0x3c')]+','+(_0x1b96e5[_0x289b('0x84')]['waitForTheAssignedAgent']||0xa),'interval':_0x289b('0x96')});_0x1b96e5[_0x289b('0x99')]=![];}return respondWithRpcPromise(_0x289b('0x9a'),'startRouting',_0x1b96e5);});}return respondWithRpcPromise(_0x289b('0x9a'),_0x289b('0x9b'),_0x1b96e5);})[_0x289b('0x21')](function(_0x2e6aaf){respondWithRpcPromise(_0x289b('0x9c'),_0x289b('0x9c'),{'event':'notify','message':_0x2e6aaf},client9002);return _0x2e6aaf;})[_0x289b('0x21')](respondWithResult(_0x139c4c,null))[_0x289b('0x2a')](handleError(_0x139c4c,null));};exports[_0x289b('0x9d')]=function(_0x2078c5,_0x2e446f){var _0xe5fd98=_0x2078c5[_0x289b('0x58')]['id'];var _0x43ccc0=_0x2078c5[_0x289b('0x63')];var _0x2f8537=0xc8;var _0x38eccd=null;return db['sequelize'][_0x289b('0x9e')]({'isolationLevel':db[_0x289b('0x9f')][_0x289b('0xa0')]['ISOLATION_LEVELS']['READ_COMMITTED']},function(_0x4fe7aa){return db[_0x289b('0x53')][_0x289b('0x69')]({'where':{'id':_0xe5fd98},'transaction':_0x4fe7aa})[_0x289b('0x21')](function(_0x103972){if(_0x103972){return db[_0x289b('0xa1')][_0x289b('0x38')]({'where':{'OpenchannelAccountId':_0xe5fd98},'transaction':_0x4fe7aa})['then'](function(){var _0x4133a6=_[_0x289b('0x51')](_0x43ccc0,function(_0x580750){_0x580750[_0x289b('0x66')]=_0xe5fd98;return _0x580750;});return db['OpenchannelApplication']['bulkCreate'](_0x4133a6,{'transaction':_0x4fe7aa});});}else{_0x2f8537=0x194;_0x38eccd=[];}});})[_0x289b('0x21')](function(){if(_0x2f8537!==0x194){return db[_0x289b('0xa1')]['findAndCountAll']({'where':{'OpenchannelAccountId':_0xe5fd98},'order':'priority'})[_0x289b('0x21')](function(_0x2b4ae2){_0x38eccd=_0x2b4ae2;});}})[_0x289b('0x2a')](function(_0x3fdf3d){_0x2f8537=0x1f4;logger['error'](_0x3fdf3d[_0x289b('0x3b')]);if(_0x3fdf3d[_0x289b('0x3c')]){delete _0x3fdf3d[_0x289b('0x3c')];}_0x38eccd=_0x3fdf3d;})[_0x289b('0xa2')](function(){if(_0x38eccd===null){_0x2e446f[_0x289b('0x2b')](_0x2f8537);}else{if(_0x2f8537===0x1f4){_0x2e446f[_0x289b('0x2c')](_0x2f8537)['send'](_0x38eccd);}else{_0x2e446f[_0x289b('0x2c')](_0x2f8537)[_0x289b('0x2e')](_0x38eccd);}}});};exports[_0x289b('0xa3')]=function(_0x14d5b6,_0x309a18,_0x45ad81){var _0x414377={};var _0xfbadfa={};var _0x358f3b;var _0x4f74d8;return db[_0x289b('0x53')][_0x289b('0x69')]({'where':{'id':_0x14d5b6[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x309a18,null))[_0x289b('0x21')](function(_0x4d16ba){if(_0x4d16ba){_0x358f3b=_0x4d16ba;_0xfbadfa[_0x289b('0x43')]=_[_0x289b('0x45')](db[_0x289b('0xa1')]['rawAttributes']);_0xfbadfa[_0x289b('0x44')]=_[_0x289b('0x45')](_0x14d5b6[_0x289b('0x44')]);_0xfbadfa[_0x289b('0x4e')]=_[_0x289b('0x46')](_0xfbadfa[_0x289b('0x43')],_0xfbadfa['query']);_0x414377[_0x289b('0x47')]=_[_0x289b('0x46')](_0xfbadfa[_0x289b('0x43')],qs[_0x289b('0x48')](_0x14d5b6[_0x289b('0x44')][_0x289b('0x48')]));_0x414377['attributes']=_0x414377[_0x289b('0x47')][_0x289b('0x59')]?_0x414377[_0x289b('0x47')]:_0xfbadfa[_0x289b('0x43')];_0x414377[_0x289b('0x4a')]=qs[_0x289b('0x4b')](_0x14d5b6['query'][_0x289b('0x4b')]);_0x414377[_0x289b('0x4c')]=qs['filters'](_[_0x289b('0x4d')](_0x14d5b6['query'],_0xfbadfa[_0x289b('0x4e')]));if(_0x14d5b6[_0x289b('0x44')][_0x289b('0x4f')]){_0x414377['where']=_[_0x289b('0x50')](_0x414377['where'],{'$or':_['map'](_0x414377[_0x289b('0x47')],function(_0x40c601){var _0x6d62e1={};_0x6d62e1[_0x40c601]={'$like':'%'+_0x14d5b6[_0x289b('0x44')][_0x289b('0x4f')]+'%'};return _0x6d62e1;})});}_0x414377=_[_0x289b('0x50')]({},_0x414377,_0x14d5b6[_0x289b('0x5a')]);return _0x358f3b['getApplications'](_0x414377);}})[_0x289b('0x21')](function(_0x28e9dd){if(_0x28e9dd){_0x4f74d8=_0x28e9dd[_0x289b('0x59')];if(!_0x14d5b6[_0x289b('0x44')][_0x289b('0x49')](_0x289b('0x6e'))){_0x414377['limit']=qs[_0x289b('0x30')](_0x14d5b6[_0x289b('0x44')][_0x289b('0x30')]);_0x414377['offset']=qs[_0x289b('0x32')](_0x14d5b6[_0x289b('0x44')][_0x289b('0x32')]);}return _0x358f3b['getApplications'](_0x414377);}})[_0x289b('0x21')](function(_0x4215d1){if(_0x4215d1){return _0x4215d1?{'count':_0x4f74d8,'rows':_0x4215d1}:null;}})['then'](respondWithResult(_0x309a18,null))['catch'](handleError(_0x309a18,null));};exports[_0x289b('0xa4')]=function(_0x3f6f40,_0x51a9b7,_0x2a1dea){var _0x179211={'raw':![],'where':{}};var _0x418d26={};var _0x558d8e={'count':0x0,'rows':[]};return db[_0x289b('0x53')][_0x289b('0x69')]({'where':{'id':_0x3f6f40[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x51a9b7,null))['then'](function(_0x20b339){if(_0x20b339){_0x418d26[_0x289b('0x43')]=_[_0x289b('0x45')](db[_0x289b('0x8c')][_0x289b('0x3f')]);_0x418d26[_0x289b('0x44')]=_[_0x289b('0x45')](_0x3f6f40[_0x289b('0x44')]);_0x418d26[_0x289b('0x4e')]=_['intersection'](_0x418d26[_0x289b('0x43')],_0x418d26[_0x289b('0x44')]);_0x179211['attributes']=_['intersection'](_0x418d26[_0x289b('0x43')],qs['fields'](_0x3f6f40[_0x289b('0x44')][_0x289b('0x48')]));_0x179211[_0x289b('0x47')]=_0x179211[_0x289b('0x47')][_0x289b('0x59')]?_0x179211[_0x289b('0x47')]:_0x418d26[_0x289b('0x43')];if(!_0x3f6f40['query']['hasOwnProperty'](_0x289b('0x6e'))){_0x179211[_0x289b('0x30')]=qs['limit'](_0x3f6f40[_0x289b('0x44')]['limit']);_0x179211[_0x289b('0x32')]=qs['offset'](_0x3f6f40['query'][_0x289b('0x32')]);}_0x179211[_0x289b('0x4a')]=qs[_0x289b('0x4b')](_0x3f6f40['query'][_0x289b('0x4b')]);_0x179211[_0x289b('0x4c')]=qs[_0x289b('0x4e')](_[_0x289b('0x4d')](_0x3f6f40['query'],_0x418d26[_0x289b('0x4e')]));_0x179211[_0x289b('0x4c')][_0x289b('0x66')]=_0x20b339['id'];if(_0x3f6f40[_0x289b('0x44')]['filter']){_0x179211['where']=_[_0x289b('0x50')](_0x179211[_0x289b('0x4c')],{'$or':_[_0x289b('0x51')](_0x179211['attributes'],function(_0x4292fd){var _0x4b0a0b={};_0x4b0a0b[_0x4292fd]={'$like':'%'+_0x3f6f40[_0x289b('0x44')][_0x289b('0x4f')]+'%'};return _0x4b0a0b;})});}_0x179211=_[_0x289b('0x50')]({},_0x179211,_0x3f6f40['options']);return db[_0x289b('0x8c')]['count']({'where':_0x179211[_0x289b('0x4c')]})['then'](function(_0x208d87){_0x558d8e[_0x289b('0x31')]=_0x208d87;if(_0x3f6f40[_0x289b('0x44')][_0x289b('0x54')]){_0x179211[_0x289b('0x55')]=[{'model':db[_0x289b('0x72')],'as':_0x289b('0xa5'),'required':![]},{'model':db[_0x289b('0x98')],'as':'Owner','attributes':[_0x289b('0x3c'),_0x289b('0xa6'),_0x289b('0xa7')],'required':![]},{'model':db[_0x289b('0xa8')],'as':_0x289b('0xa9'),'attributes':['id',_0x289b('0x3c'),_0x289b('0xaa')],'where':_0x3f6f40[_0x289b('0x44')][_0x289b('0xab')]?{'id':_0x3f6f40[_0x289b('0x44')][_0x289b('0xab')]}:undefined,'required':_0x3f6f40['query'][_0x289b('0xab')]?!![]:![]}];}return db[_0x289b('0x8c')][_0x289b('0x6a')](_0x179211);})['then'](function(_0x23ac83){_0x558d8e['rows']=_0x23ac83;return _0x558d8e;});}})['then'](respondWithFilteredResult(_0x51a9b7,_0x179211))[_0x289b('0x2a')](handleError(_0x51a9b7,null));};exports[_0x289b('0xac')]=function(_0x46929f,_0x37683d,_0x2f5677){return db[_0x289b('0x53')][_0x289b('0x5b')]({'where':{'id':_0x46929f[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x37683d,null))[_0x289b('0x21')](function(_0x598a87){if(_0x598a87){return _0x598a87[_0x289b('0xac')](_0x46929f[_0x289b('0x63')][_0x289b('0x6c')],_['omit'](_0x46929f['body'],[_0x289b('0x6c'),'id'])||{})['spread'](function(_0x46789f){for(var _0x2f75f8=0x0;_0x2f75f8<_0x46929f['body'][_0x289b('0x6c')][_0x289b('0x59')];_0x2f75f8+=0x1){socket[_0x289b('0xad')](_0x289b('0xae'),{'UserId':Number(_0x46929f['body']['ids'][_0x2f75f8]),'OpenchannelAccountId':Number(_0x46929f[_0x289b('0x58')]['id'])});}return _0x46789f;});}})[_0x289b('0x21')](respondWithResult(_0x37683d,null))[_0x289b('0x2a')](handleError(_0x37683d,null));};exports[_0x289b('0xaf')]=function(_0x75c67e,_0x1e1a0c,_0x318c1f){return db['OpenchannelAccount'][_0x289b('0x5b')]({'where':{'id':_0x75c67e[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x1e1a0c,null))[_0x289b('0x21')](function(_0x18beee){if(_0x18beee){return _0x18beee[_0x289b('0xaf')](_0x75c67e[_0x289b('0x44')][_0x289b('0x6c')])['then'](function(){if(_['isArray'](_0x75c67e[_0x289b('0x44')][_0x289b('0x6c')])){for(var _0x5e2552=0x0;_0x5e2552<_0x75c67e[_0x289b('0x44')]['ids']['length'];_0x5e2552+=0x1){socket[_0x289b('0xad')]('userOpenchannelAccount:remove',{'UserId':Number(_0x75c67e[_0x289b('0x44')][_0x289b('0x6c')][_0x5e2552]),'OpenchannelAccountId':Number(_0x75c67e[_0x289b('0x58')]['id'])});}}else{socket[_0x289b('0xad')](_0x289b('0xb0'),{'UserId':Number(_0x75c67e[_0x289b('0x44')][_0x289b('0x6c')]),'OpenchannelAccountId':Number(_0x75c67e[_0x289b('0x58')]['id'])});}});}})[_0x289b('0x21')](respondWithStatusCode(_0x1e1a0c,null))[_0x289b('0x2a')](handleError(_0x1e1a0c,null));};exports[_0x289b('0xb1')]=function(_0x3033f1,_0x5d8aeb,_0x49a0dd){var _0x4b9271={};var _0x276e97={};var _0x2d91ed;var _0x3895fe;return db['OpenchannelAccount'][_0x289b('0x69')]({'where':{'id':_0x3033f1['params']['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x5d8aeb,null))[_0x289b('0x21')](function(_0xdcaa40){if(_0xdcaa40){_0x2d91ed=_0xdcaa40;_0x276e97[_0x289b('0x43')]=_[_0x289b('0x45')](db[_0x289b('0x98')]['rawAttributes']);_0x276e97[_0x289b('0x44')]=_[_0x289b('0x45')](_0x3033f1['query']);_0x276e97[_0x289b('0x4e')]=_['intersection'](_0x276e97[_0x289b('0x43')],_0x276e97[_0x289b('0x44')]);_0x4b9271['attributes']=_[_0x289b('0x46')](_0x276e97[_0x289b('0x43')],qs[_0x289b('0x48')](_0x3033f1[_0x289b('0x44')][_0x289b('0x48')]));_0x4b9271[_0x289b('0x47')]=_0x4b9271[_0x289b('0x47')][_0x289b('0x59')]?_0x4b9271[_0x289b('0x47')]:_0x276e97[_0x289b('0x43')];_0x4b9271[_0x289b('0x4a')]=qs['sort'](_0x3033f1['query'][_0x289b('0x4b')]);_0x4b9271[_0x289b('0x4c')]=qs[_0x289b('0x4e')](_['pick'](_0x3033f1['query'],_0x276e97['filters']));if(_0x3033f1[_0x289b('0x44')][_0x289b('0x4f')]){_0x4b9271['where']=_[_0x289b('0x50')](_0x4b9271[_0x289b('0x4c')],{'$or':_['map'](_0x4b9271[_0x289b('0x47')],function(_0x378c94){var _0x40f8a9={};_0x40f8a9[_0x378c94]={'$like':'%'+_0x3033f1['query'][_0x289b('0x4f')]+'%'};return _0x40f8a9;})});}_0x4b9271=_[_0x289b('0x50')]({},_0x4b9271,_0x3033f1['options']);return _0x2d91ed[_0x289b('0xb1')](_0x4b9271);}})[_0x289b('0x21')](function(_0x196c44){if(_0x196c44){_0x3895fe=_0x196c44[_0x289b('0x59')];if(!_0x3033f1['query']['hasOwnProperty'](_0x289b('0x6e'))){_0x4b9271[_0x289b('0x30')]=qs[_0x289b('0x30')](_0x3033f1[_0x289b('0x44')][_0x289b('0x30')]);_0x4b9271[_0x289b('0x32')]=qs[_0x289b('0x32')](_0x3033f1[_0x289b('0x44')][_0x289b('0x32')]);}return _0x2d91ed[_0x289b('0xb1')](_0x4b9271);}})[_0x289b('0x21')](function(_0x55d7bc){if(_0x55d7bc){return _0x55d7bc?{'count':_0x3895fe,'rows':_0x55d7bc}:null;}})['then'](respondWithResult(_0x5d8aeb,null))[_0x289b('0x2a')](handleError(_0x5d8aeb,null));};exports[_0x289b('0xb2')]=function(_0x5ae118,_0x5e9267,_0x37269a){var _0x3db392,_0x450043,_0x3225d9;if(_[_0x289b('0x79')](_0x5ae118[_0x289b('0x63')][_0x289b('0x63')])||_0x5ae118[_0x289b('0x63')][_0x289b('0x63')]===''){throw new db[(_0x289b('0x73'))][(_0x289b('0x74'))](_0x289b('0x7b'));}if(_[_0x289b('0x79')](_0x5ae118['body']['to'])){}_0x3db392=_0x5ae118['body']['to'];return db[_0x289b('0x53')]['findOne']({'where':{'id':_0x5ae118['params']['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x5e9267,null))['then'](function(_0x5b73be){if(_0x5b73be){return db[_0x289b('0x53')][_0x289b('0x5b')]({'where':{'id':_0x5b73be['id']},'include':[{'model':db[_0x289b('0x7f')],'as':_0x289b('0x80'),'include':[{'model':db['CmContact'],'as':_0x289b('0x81'),'where':{[_0x5b73be[_0x289b('0x7c')]]:_0x3db392},'limit':0x1,'order':[[_0x289b('0xb3'),'DESC']]}]}]})['then'](handleEntityNotFound(_0x5e9267,null))[_0x289b('0x21')](function(_0x43981a){if(_0x43981a&&_0x43981a[_0x289b('0x80')]){_0x450043=_0x43981a[_0x289b('0x39')]({'plain':!![]});if(_0x450043[_0x289b('0x80')]&&_0x450043[_0x289b('0x80')][_0x289b('0x81')]['length']){return _0x450043[_0x289b('0x80')][_0x289b('0x81')][0x0];}return db[_0x289b('0x72')][_0x289b('0x5c')](_[_0x289b('0x17')](_0x5ae118[_0x289b('0x63')],{'firstName':_0x3db392,[_0x43981a[_0x289b('0x7c')]]:_0x3db392,'phone':_0x3db392,'ListId':_0x450043[_0x289b('0x78')]}));}})[_0x289b('0x21')](handleEntityNotFound(_0x5e9267,null))[_0x289b('0x21')](function(_0x391b34){if(_0x391b34){_0x3225d9=_0x391b34;return db['OpenchannelInteraction'][_0x289b('0x5b')]({'where':{'ContactId':_0x3225d9['id'],'closed':![],'OpenchannelAccountId':_0x450043['id']}})[_0x289b('0x21')](function(_0x2062aa){if(_0x2062aa){return[_0x2062aa,![]];}return db['OpenchannelInteraction']['create']({'UserId':_0x5ae118[_0x289b('0x5d')]['id'],'ContactId':_0x3225d9['id'],'OpenchannelAccountId':_0x450043['id'],'lastMsgDirection':_0x289b('0xb4'),'firstMsgDirection':_0x289b('0xb4'),'Messages':[_['merge'](_0x5ae118['body'],{'read':![],'body':_0x5ae118['body']['body'],'OpenchannelAccountId':_0x450043['id'],'UserId':_0x5ae118[_0x289b('0x5d')]['id'],'ContactId':_0x3225d9['id']})]},{'include':[{'model':db[_0x289b('0x97')],'as':'Messages'}]})[_0x289b('0x21')](function(_0x5a93d4){return[_0x5a93d4,!![]];});});}})['spread'](function(_0x3bb6dd,_0x303876){if(_0x303876){return _0x3bb6dd;}return db[_0x289b('0x97')][_0x289b('0x5c')](_['merge'](_0x5ae118['body'],{'read':![],'body':_0x5ae118[_0x289b('0x63')][_0x289b('0x63')],'OpenchannelAccountId':_0x450043['id'],'OpenchannelInteractionId':_0x3bb6dd['id'],'UserId':_0x5ae118[_0x289b('0x5d')]['id'],'ContactId':_0x3225d9['id']}))[_0x289b('0x21')](function(_0x190816){_0x3bb6dd[_0x289b('0xb5')][_0x289b('0xb6')]=[];_0x3bb6dd[_0x289b('0xb5')]['Messages']['push'](_0x190816[_0x289b('0xb5')]);return _0x3bb6dd;});});}})[_0x289b('0x21')](respondWithResult(_0x5e9267,null))['catch'](handleError(_0x5e9267,null));};
\ No newline at end of file