Built motion from commit da617fac.|2.6.6
[motion2.git] / server / api / openchannelAccount / openchannelAccount.controller.js
index b15980d..d4f0707 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x51f4=['getAgents','body\x20is\x20mandatory\x20and\x20not\x20empty','out','OpenchannelMessage','Messages','dataValues','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','util','path','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./openchannelAccount.socket','register','client','http','request','then','info','OpenchannelAccount,\x20%s,\x20%s','debug','OpenchannelAccount,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','result','end','status','json','offset','limit','count','set','Content-Range','apply','reject','save','update','get','OpenchannelAccounts','UserProfileResource','destroy','sendStatus','stack','name','send','index','Pause','mandatoryDispositionPause','OpenchannelAccount','rawAttributes','fieldName','type','map','query','keys','filters','intersection','model','attributes','fields','length','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','findAll','rows','catch','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','describe','addDisposition','OpenchannelAccountId','getDispositions','hasOwnProperty','Disposition','removeDispositions','ids','addAnswer','CannedAnswer','findOne','notify','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','updatedAt','CompanyId','isNil','from\x20is\x20mandatory','mapKey','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','from','CmList','List','Applications','applications','list','orderBy','priority','asc','account','Contacts','ListId','contact','firstName','lastName','OpenchannelInteraction','threadId','externalUrl','ContactId','spread','messageId','interaction','created','autoclose','push','close','unmanaged','*,*,*,*','AttachmentId','UserId','User','unshift','agent','waitForTheAssignedAgent','forcedOwnership','Start','startRouting','EventManager','addApplications','transaction','sequelize','Transaction','ISOLATION_LEVELS','READ_COMMITTED','OpenchannelApplication','findAndCountAll','finally','getApplications','getInteractions','Contact','Owner','fullname','internal','Tag','Tags','color','tag','addAgents','omit','emit'];(function(_0xb03a44,_0x4a835b){var _0x2ebf41=function(_0x3bf587){while(--_0x3bf587){_0xb03a44['push'](_0xb03a44['shift']());}};_0x2ebf41(++_0x4a835b);}(_0x51f4,0x18c));var _0x451f=function(_0x321bb2,_0x202794){_0x321bb2=_0x321bb2-0x0;var _0x9c12ed=_0x51f4[_0x321bb2];return _0x9c12ed;};'use strict';var emlformat=require(_0x451f('0x0'));var rimraf=require(_0x451f('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x451f('0x2'));var rp=require(_0x451f('0x3'));var moment=require(_0x451f('0x4'));var BPromise=require(_0x451f('0x5'));var Mustache=require('mustache');var util=require(_0x451f('0x6'));var path=require(_0x451f('0x7'));var sox=require('sox');var csv=require(_0x451f('0x8'));var ejs=require(_0x451f('0x9'));var fs=require('fs');var fs_extra=require(_0x451f('0xa'));var _=require(_0x451f('0xb'));var squel=require(_0x451f('0xc'));var crypto=require('crypto');var jsforce=require(_0x451f('0xd'));var deskjs=require(_0x451f('0xe'));var toCsv=require('to-csv');var querystring=require(_0x451f('0xf'));var Papa=require(_0x451f('0x10'));var Redis=require('ioredis');var authService=require(_0x451f('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x451f('0x12'));var hardwareService=require(_0x451f('0x13'));var logger=require(_0x451f('0x14'))(_0x451f('0x15'));var utils=require(_0x451f('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0x451f('0x17'));var db=require(_0x451f('0x18'))['db'];config[_0x451f('0x19')]=_[_0x451f('0x1a')](config[_0x451f('0x19')],{'host':_0x451f('0x1b'),'port':0x18eb});var socket=require(_0x451f('0x1c'))(new Redis(config[_0x451f('0x19')]));require(_0x451f('0x1d'))[_0x451f('0x1e')](socket);var jayson=require('jayson/promise');var client=jayson[_0x451f('0x1f')][_0x451f('0x20')]({'port':0x232c});var client9002=jayson[_0x451f('0x1f')][_0x451f('0x20')]({'port':0x232a});function respondWithRpcPromise(_0xbb5d02,_0x4eeecc,_0xe7a416,_0x1aa6a7){return new BPromise(function(_0x10da1d,_0x45ecb3){var _0x48494f=_0x1aa6a7||client;return _0x48494f[_0x451f('0x21')](_0xbb5d02,_0xe7a416)[_0x451f('0x22')](function(_0x2e7549){logger[_0x451f('0x23')](_0x451f('0x24'),_0x4eeecc,'request\x20sent');logger[_0x451f('0x25')](_0x451f('0x26'),_0x4eeecc,_0x451f('0x27'),JSON[_0x451f('0x28')](_0x2e7549));if(_0x2e7549['error']){if(_0x2e7549[_0x451f('0x29')][_0x451f('0x2a')]===0x1f4){logger[_0x451f('0x29')](_0x451f('0x24'),_0x4eeecc,_0x2e7549[_0x451f('0x29')][_0x451f('0x2b')]);return _0x45ecb3(_0x2e7549[_0x451f('0x29')][_0x451f('0x2b')]);}logger[_0x451f('0x29')](_0x451f('0x24'),_0x4eeecc,_0x2e7549['error'][_0x451f('0x2b')]);return _0x10da1d(_0x2e7549[_0x451f('0x29')][_0x451f('0x2b')]);}else{logger['info'](_0x451f('0x24'),_0x4eeecc,_0x451f('0x27'));_0x10da1d(_0x2e7549[_0x451f('0x2c')]['message']);}})['catch'](function(_0x1f1381){logger[_0x451f('0x29')](_0x451f('0x24'),_0x4eeecc,_0x1f1381);_0x45ecb3(_0x1f1381);});});}function respondWithStatusCode(_0xef0bf4,_0xc839b){_0xc839b=_0xc839b||0xcc;return function(_0x16c355){if(_0x16c355){return _0xef0bf4['sendStatus'](_0xc839b);}return _0xef0bf4['status'](_0xc839b)[_0x451f('0x2d')]();};}function respondWithResult(_0x35f5fc,_0x3a81ab){_0x3a81ab=_0x3a81ab||0xc8;return function(_0x458206){if(_0x458206){return _0x35f5fc[_0x451f('0x2e')](_0x3a81ab)[_0x451f('0x2f')](_0x458206);}};}function respondWithFilteredResult(_0x302d98,_0x2d11b1){return function(_0x271049){if(_0x271049){var _0x1c6f91=typeof _0x2d11b1[_0x451f('0x30')]==='undefined'&&typeof _0x2d11b1[_0x451f('0x31')]==='undefined';var _0x236a70=_0x271049[_0x451f('0x32')];var _0x53d15c=_0x1c6f91?0x0:_0x2d11b1[_0x451f('0x30')];var _0x4238b0=_0x1c6f91?_0x271049[_0x451f('0x32')]:_0x2d11b1[_0x451f('0x30')]+_0x2d11b1[_0x451f('0x31')];var _0x3c24b3;if(_0x4238b0>=_0x236a70){_0x4238b0=_0x236a70;_0x3c24b3=0xc8;}else{_0x3c24b3=0xce;}_0x302d98[_0x451f('0x2e')](_0x3c24b3);return _0x302d98[_0x451f('0x33')](_0x451f('0x34'),_0x53d15c+'-'+_0x4238b0+'/'+_0x236a70)[_0x451f('0x2f')](_0x271049);}return null;};}function patchUpdates(_0xc7384d){return function(_0x994b1){try{jsonpatch[_0x451f('0x35')](_0x994b1,_0xc7384d,!![]);}catch(_0x4f0d5a){return BPromise[_0x451f('0x36')](_0x4f0d5a);}return _0x994b1[_0x451f('0x37')]();};}function saveUpdates(_0x4d8cf8,_0x399fa3){return function(_0x4e2164){if(_0x4e2164){return _0x4e2164[_0x451f('0x38')](_0x4d8cf8)[_0x451f('0x22')](function(_0x2cb6c3){return _0x2cb6c3;});}return null;};}function removeEntity(_0x28733c,_0x3de04d){return function(_0x540441){if(_0x540441){return _0x540441['destroy']()[_0x451f('0x22')](function(){var _0x44d3e7=_0x540441[_0x451f('0x39')]({'plain':!![]});var _0x23346c=_0x451f('0x3a');return db[_0x451f('0x3b')][_0x451f('0x3c')]({'where':{'type':_0x23346c,'resourceId':_0x44d3e7['id']}})[_0x451f('0x22')](function(){return _0x540441;});})['then'](function(){_0x28733c[_0x451f('0x2e')](0xcc)[_0x451f('0x2d')]();});}};}function handleEntityNotFound(_0x3e8298,_0x51b7fb){return function(_0x48ad0f){if(!_0x48ad0f){_0x3e8298[_0x451f('0x3d')](0x194);}return _0x48ad0f;};}function handleError(_0x309c72,_0x2351fa){_0x2351fa=_0x2351fa||0x1f4;return function(_0x4d0dfe){logger['error'](_0x4d0dfe[_0x451f('0x3e')]);if(_0x4d0dfe[_0x451f('0x3f')]){delete _0x4d0dfe[_0x451f('0x3f')];}_0x309c72[_0x451f('0x2e')](_0x2351fa)[_0x451f('0x40')](_0x4d0dfe);};}exports[_0x451f('0x41')]=function(_0x5a77fd,_0x429a27){var _0x46e0e9={'include':[{'model':db[_0x451f('0x42')],'as':_0x451f('0x43')}]},_0x1038fd={},_0x4045bc={'count':0x0,'rows':[]};var _0x2ae4f6=_['map'](db[_0x451f('0x44')][_0x451f('0x45')],function(_0x2a3f49){return{'name':_0x2a3f49[_0x451f('0x46')],'type':_0x2a3f49[_0x451f('0x47')]['key']};});_0x1038fd['model']=_[_0x451f('0x48')](_0x2ae4f6,_0x451f('0x3f'));_0x1038fd[_0x451f('0x49')]=_[_0x451f('0x4a')](_0x5a77fd[_0x451f('0x49')]);_0x1038fd[_0x451f('0x4b')]=_[_0x451f('0x4c')](_0x1038fd[_0x451f('0x4d')],_0x1038fd[_0x451f('0x49')]);_0x46e0e9[_0x451f('0x4e')]=_[_0x451f('0x4c')](_0x1038fd[_0x451f('0x4d')],qs[_0x451f('0x4f')](_0x5a77fd[_0x451f('0x49')][_0x451f('0x4f')]));_0x46e0e9[_0x451f('0x4e')]=_0x46e0e9[_0x451f('0x4e')][_0x451f('0x50')]?_0x46e0e9[_0x451f('0x4e')]:_0x1038fd[_0x451f('0x4d')];if(!_0x5a77fd[_0x451f('0x49')]['hasOwnProperty'](_0x451f('0x51'))){_0x46e0e9['limit']=qs['limit'](_0x5a77fd[_0x451f('0x49')][_0x451f('0x31')]);_0x46e0e9[_0x451f('0x30')]=qs['offset'](_0x5a77fd[_0x451f('0x49')][_0x451f('0x30')]);}_0x46e0e9[_0x451f('0x52')]=qs[_0x451f('0x53')](_0x5a77fd['query'][_0x451f('0x53')]);_0x46e0e9[_0x451f('0x54')]=qs['filters'](_[_0x451f('0x55')](_0x5a77fd['query'],_0x1038fd['filters']),_0x2ae4f6);if(_0x5a77fd[_0x451f('0x49')][_0x451f('0x56')]){_0x46e0e9['where']=_[_0x451f('0x57')](_0x46e0e9['where'],{'$or':_[_0x451f('0x48')](_0x2ae4f6,function(_0x57ad00){if(_0x57ad00['type']!==_0x451f('0x58')){var _0xf1d45={};_0xf1d45[_0x57ad00[_0x451f('0x3f')]]={'$like':'%'+_0x5a77fd[_0x451f('0x49')][_0x451f('0x56')]+'%'};return _0xf1d45;}})});}_0x46e0e9=_['merge']({},_0x46e0e9,_0x5a77fd['options']);var _0x565ef9={'where':_0x46e0e9['where']};return db[_0x451f('0x44')][_0x451f('0x32')](_0x565ef9)[_0x451f('0x22')](function(_0x3a2ec6){_0x4045bc['count']=_0x3a2ec6;if(_0x5a77fd[_0x451f('0x49')][_0x451f('0x59')]){_0x46e0e9[_0x451f('0x5a')]=[{'all':!![]}];}return db[_0x451f('0x44')][_0x451f('0x5b')](_0x46e0e9);})[_0x451f('0x22')](function(_0x32750b){_0x4045bc[_0x451f('0x5c')]=_0x32750b;return _0x4045bc;})['then'](respondWithFilteredResult(_0x429a27,_0x46e0e9))[_0x451f('0x5d')](handleError(_0x429a27,null));};exports['show']=function(_0x427bdf,_0x17f7e1){var _0x2e9dd8={'raw':![],'where':{'id':_0x427bdf['params']['id']},'include':[{'model':db[_0x451f('0x42')],'as':_0x451f('0x43')}]},_0x50b42c={};_0x50b42c[_0x451f('0x4d')]=_[_0x451f('0x4a')](db[_0x451f('0x44')][_0x451f('0x45')]);_0x50b42c[_0x451f('0x49')]=_[_0x451f('0x4a')](_0x427bdf[_0x451f('0x49')]);_0x50b42c['filters']=_[_0x451f('0x4c')](_0x50b42c[_0x451f('0x4d')],_0x50b42c['query']);_0x2e9dd8['attributes']=_['intersection'](_0x50b42c[_0x451f('0x4d')],qs[_0x451f('0x4f')](_0x427bdf[_0x451f('0x49')][_0x451f('0x4f')]));_0x2e9dd8[_0x451f('0x4e')]=_0x2e9dd8[_0x451f('0x4e')][_0x451f('0x50')]?_0x2e9dd8['attributes']:_0x50b42c[_0x451f('0x4d')];if(_0x427bdf[_0x451f('0x49')]['includeAll']){_0x2e9dd8[_0x451f('0x5a')]=[{'all':!![]}];}_0x2e9dd8=_['merge']({},_0x2e9dd8,_0x427bdf[_0x451f('0x5e')]);return db[_0x451f('0x44')][_0x451f('0x5f')](_0x2e9dd8)[_0x451f('0x22')](handleEntityNotFound(_0x17f7e1,null))[_0x451f('0x22')](respondWithResult(_0x17f7e1,null))[_0x451f('0x5d')](handleError(_0x17f7e1,null));};exports[_0x451f('0x60')]=function(_0x463e77,_0x3a5488){return db['OpenchannelAccount'][_0x451f('0x60')](_0x463e77[_0x451f('0x61')],{})['then'](function(_0x3662b6){var _0x4018b6=_0x463e77[_0x451f('0x62')][_0x451f('0x39')]({'plain':!![]});if(!_0x4018b6)throw new Error(_0x451f('0x63'));if(_0x4018b6[_0x451f('0x64')]===_0x451f('0x62')){var _0x4a4640=_0x3662b6[_0x451f('0x39')]({'plain':!![]});var _0x19e7c8=_0x451f('0x3a');return db[_0x451f('0x65')]['find']({'where':{'name':_0x19e7c8,'userProfileId':_0x4018b6[_0x451f('0x66')]},'raw':!![]})[_0x451f('0x22')](function(_0x4aee5b){if(_0x4aee5b&&_0x4aee5b[_0x451f('0x67')]===0x0){return db[_0x451f('0x3b')][_0x451f('0x60')]({'name':_0x4a4640[_0x451f('0x3f')],'resourceId':_0x4a4640['id'],'type':_0x4aee5b[_0x451f('0x3f')],'sectionId':_0x4aee5b['id']},{})[_0x451f('0x22')](function(){return _0x3662b6;});}else{return _0x3662b6;}})[_0x451f('0x5d')](function(_0x295c60){logger['error'](_0x451f('0x68'),_0x295c60);throw _0x295c60;});}return _0x3662b6;})[_0x451f('0x22')](respondWithResult(_0x3a5488,0xc9))[_0x451f('0x5d')](handleError(_0x3a5488,null));};exports[_0x451f('0x38')]=function(_0x3c243f,_0xab6aef){if(_0x3c243f['body']['id']){delete _0x3c243f[_0x451f('0x61')]['id'];}return db['OpenchannelAccount'][_0x451f('0x5f')]({'where':{'id':_0x3c243f[_0x451f('0x69')]['id']},'include':[{'model':db['Pause'],'as':_0x451f('0x43')}]})[_0x451f('0x22')](handleEntityNotFound(_0xab6aef,null))[_0x451f('0x22')](saveUpdates(_0x3c243f[_0x451f('0x61')],null))[_0x451f('0x22')](respondWithResult(_0xab6aef,null))[_0x451f('0x5d')](handleError(_0xab6aef,null));};exports[_0x451f('0x3c')]=function(_0x26c46b,_0x14c61c){return db[_0x451f('0x44')][_0x451f('0x5f')]({'where':{'id':_0x26c46b[_0x451f('0x69')]['id']}})[_0x451f('0x22')](handleEntityNotFound(_0x14c61c,null))[_0x451f('0x22')](removeEntity(_0x14c61c,null))[_0x451f('0x5d')](handleError(_0x14c61c,null));};exports[_0x451f('0x6a')]=function(_0x18ef4,_0x124a4a){return db[_0x451f('0x44')][_0x451f('0x6a')]()[_0x451f('0x22')](respondWithResult(_0x124a4a,null))['catch'](handleError(_0x124a4a,null));};exports[_0x451f('0x6b')]=function(_0x4d5fe9,_0x3a1473,_0x4aeb94){if(_0x4d5fe9['body']['id']){delete _0x4d5fe9['body']['id'];}return db[_0x451f('0x44')][_0x451f('0x5f')]({'where':{'id':_0x4d5fe9[_0x451f('0x69')]['id']}})[_0x451f('0x22')](handleEntityNotFound(_0x3a1473,null))[_0x451f('0x22')](function(_0x373fea){if(_0x373fea){_0x4d5fe9[_0x451f('0x61')][_0x451f('0x6c')]=_0x373fea['id'];return db['Disposition'][_0x451f('0x60')](_0x4d5fe9[_0x451f('0x61')]);}})[_0x451f('0x22')](respondWithResult(_0x3a1473,null))[_0x451f('0x5d')](handleError(_0x3a1473,null));};exports[_0x451f('0x6d')]=function(_0x501b5e,_0xe23e34,_0xda18e8){var _0x5752e8={'raw':![],'where':{}};var _0x1a6bce={};var _0x26bcc3={'count':0x0,'rows':[]};return db['OpenchannelAccount']['findOne']({'where':{'id':_0x501b5e[_0x451f('0x69')]['id']}})[_0x451f('0x22')](handleEntityNotFound(_0xe23e34,null))[_0x451f('0x22')](function(_0x2b432e){if(_0x2b432e){_0x1a6bce[_0x451f('0x4d')]=_['keys'](db['Disposition'][_0x451f('0x45')]);_0x1a6bce['query']=_[_0x451f('0x4a')](_0x501b5e['query']);_0x1a6bce['filters']=_[_0x451f('0x4c')](_0x1a6bce['model'],_0x1a6bce[_0x451f('0x49')]);_0x5752e8[_0x451f('0x4e')]=_['intersection'](_0x1a6bce[_0x451f('0x4d')],qs['fields'](_0x501b5e[_0x451f('0x49')][_0x451f('0x4f')]));_0x5752e8[_0x451f('0x4e')]=_0x5752e8[_0x451f('0x4e')]['length']?_0x5752e8[_0x451f('0x4e')]:_0x1a6bce['model'];if(!_0x501b5e[_0x451f('0x49')][_0x451f('0x6e')](_0x451f('0x51'))){_0x5752e8['limit']=qs['limit'](_0x501b5e['query'][_0x451f('0x31')]);_0x5752e8[_0x451f('0x30')]=qs['offset'](_0x501b5e[_0x451f('0x49')][_0x451f('0x30')]);}_0x5752e8[_0x451f('0x52')]=qs[_0x451f('0x53')](_0x501b5e[_0x451f('0x49')][_0x451f('0x53')]);_0x5752e8['where']=qs[_0x451f('0x4b')](_['pick'](_0x501b5e[_0x451f('0x49')],_0x1a6bce[_0x451f('0x4b')]));_0x5752e8[_0x451f('0x54')][_0x451f('0x6c')]=_0x2b432e['id'];if(_0x501b5e[_0x451f('0x49')][_0x451f('0x56')]){_0x5752e8[_0x451f('0x54')]=_[_0x451f('0x57')](_0x5752e8[_0x451f('0x54')],{'$or':_[_0x451f('0x48')](_0x5752e8[_0x451f('0x4e')],function(_0x2ba32b){var _0x255bf0={};_0x255bf0[_0x2ba32b]={'$like':'%'+_0x501b5e[_0x451f('0x49')]['filter']+'%'};return _0x255bf0;})});}_0x5752e8=_[_0x451f('0x57')]({},_0x5752e8,_0x501b5e[_0x451f('0x5e')]);return db[_0x451f('0x6f')][_0x451f('0x32')]({'where':_0x5752e8['where']})[_0x451f('0x22')](function(_0x3473d4){_0x26bcc3[_0x451f('0x32')]=_0x3473d4;if(_0x501b5e[_0x451f('0x49')][_0x451f('0x59')]){_0x5752e8[_0x451f('0x5a')]=[{'all':!![]}];}return db[_0x451f('0x6f')]['findAll'](_0x5752e8);})[_0x451f('0x22')](function(_0x2b04a7){_0x26bcc3[_0x451f('0x5c')]=_0x2b04a7;return _0x26bcc3;});}})[_0x451f('0x22')](respondWithFilteredResult(_0xe23e34,_0x5752e8))[_0x451f('0x5d')](handleError(_0xe23e34,null));};exports[_0x451f('0x70')]=function(_0xbf965d,_0x16085b,_0x1549d0){return db[_0x451f('0x44')][_0x451f('0x5f')]({'where':{'id':_0xbf965d[_0x451f('0x69')]['id']}})[_0x451f('0x22')](handleEntityNotFound(_0x16085b,null))[_0x451f('0x22')](function(_0x240c6d){if(_0x240c6d){return _0x240c6d[_0x451f('0x70')](_0xbf965d[_0x451f('0x49')][_0x451f('0x71')]);}})['then'](respondWithStatusCode(_0x16085b,null))[_0x451f('0x5d')](handleError(_0x16085b,null));};exports[_0x451f('0x72')]=function(_0x537436,_0x3fabb5,_0x48f8bb){if(_0x537436['body']['id']){delete _0x537436['body']['id'];}return db[_0x451f('0x44')]['find']({'where':{'id':_0x537436['params']['id']}})[_0x451f('0x22')](handleEntityNotFound(_0x3fabb5,null))[_0x451f('0x22')](function(_0x8f39ea){if(_0x8f39ea){_0x537436['body'][_0x451f('0x6c')]=_0x8f39ea['id'];return db[_0x451f('0x73')][_0x451f('0x60')](_0x537436[_0x451f('0x61')]);}})[_0x451f('0x22')](respondWithResult(_0x3fabb5,null))['catch'](handleError(_0x3fabb5,null));};exports['getAnswers']=function(_0x2b916b,_0x327b13,_0x459da6){var _0x5cec83={'raw':![],'where':{}};var _0x3bcc5a={};var _0x116be4={'count':0x0,'rows':[]};return db[_0x451f('0x44')][_0x451f('0x74')]({'where':{'id':_0x2b916b[_0x451f('0x69')]['id']}})['then'](handleEntityNotFound(_0x327b13,null))[_0x451f('0x22')](function(_0x54008d){if(_0x54008d){_0x3bcc5a[_0x451f('0x4d')]=_[_0x451f('0x4a')](db['CannedAnswer']['rawAttributes']);_0x3bcc5a[_0x451f('0x49')]=_['keys'](_0x2b916b[_0x451f('0x49')]);_0x3bcc5a[_0x451f('0x4b')]=_['intersection'](_0x3bcc5a[_0x451f('0x4d')],_0x3bcc5a[_0x451f('0x49')]);_0x5cec83[_0x451f('0x4e')]=_[_0x451f('0x4c')](_0x3bcc5a[_0x451f('0x4d')],qs[_0x451f('0x4f')](_0x2b916b['query'][_0x451f('0x4f')]));_0x5cec83[_0x451f('0x4e')]=_0x5cec83['attributes'][_0x451f('0x50')]?_0x5cec83['attributes']:_0x3bcc5a['model'];if(!_0x2b916b[_0x451f('0x49')][_0x451f('0x6e')]('nolimit')){_0x5cec83[_0x451f('0x31')]=qs[_0x451f('0x31')](_0x2b916b[_0x451f('0x49')][_0x451f('0x31')]);_0x5cec83[_0x451f('0x30')]=qs[_0x451f('0x30')](_0x2b916b[_0x451f('0x49')][_0x451f('0x30')]);}_0x5cec83[_0x451f('0x52')]=qs[_0x451f('0x53')](_0x2b916b[_0x451f('0x49')][_0x451f('0x53')]);_0x5cec83['where']=qs[_0x451f('0x4b')](_[_0x451f('0x55')](_0x2b916b[_0x451f('0x49')],_0x3bcc5a[_0x451f('0x4b')]));_0x5cec83['where'][_0x451f('0x6c')]=_0x54008d['id'];if(_0x2b916b[_0x451f('0x49')][_0x451f('0x56')]){_0x5cec83[_0x451f('0x54')]=_[_0x451f('0x57')](_0x5cec83[_0x451f('0x54')],{'$or':_[_0x451f('0x48')](_0x5cec83[_0x451f('0x4e')],function(_0x2d88a2){var _0x59bcdd={};_0x59bcdd[_0x2d88a2]={'$like':'%'+_0x2b916b[_0x451f('0x49')][_0x451f('0x56')]+'%'};return _0x59bcdd;})});}_0x5cec83=_[_0x451f('0x57')]({},_0x5cec83,_0x2b916b[_0x451f('0x5e')]);return db[_0x451f('0x73')][_0x451f('0x32')]({'where':_0x5cec83[_0x451f('0x54')]})[_0x451f('0x22')](function(_0x2ecb77){_0x116be4['count']=_0x2ecb77;if(_0x2b916b[_0x451f('0x49')]['includeAll']){_0x5cec83['include']=[{'all':!![]}];}return db[_0x451f('0x73')]['findAll'](_0x5cec83);})['then'](function(_0x3be339){_0x116be4[_0x451f('0x5c')]=_0x3be339;return _0x116be4;});}})[_0x451f('0x22')](respondWithFilteredResult(_0x327b13,_0x5cec83))[_0x451f('0x5d')](handleError(_0x327b13,null));};exports['removeAnswers']=function(_0x39d831,_0x5590eb,_0x3a4080){return db['OpenchannelAccount'][_0x451f('0x5f')]({'where':{'id':_0x39d831['params']['id']}})[_0x451f('0x22')](handleEntityNotFound(_0x5590eb,null))[_0x451f('0x22')](function(_0x7e9b4c){if(_0x7e9b4c){return _0x7e9b4c['removeAnswers'](_0x39d831[_0x451f('0x49')][_0x451f('0x71')]);}})['then'](respondWithStatusCode(_0x5590eb,null))[_0x451f('0x5d')](handleError(_0x5590eb,null));};exports[_0x451f('0x75')]=function(_0x521b1b,_0x16c990,_0x454d3e){var _0x18da54={'body':_0x521b1b['body'],'channel':'openchannel'};var _0x4facae=[];var _0x4a269c=[];var _0x1131c5={};var _0x245543=![];return db[_0x451f('0x76')][_0x451f('0x6a')]()[_0x451f('0x22')](function(_0x488f98){if(!_0x488f98){throw new db[(_0x451f('0x77'))][(_0x451f('0x78'))](_0x451f('0x79'));}_0x4facae=_[_0x451f('0x7a')](_['keys'](_0x488f98),['createdAt',_0x451f('0x7b')]);_0x4a269c=_[_0x451f('0x7a')](_[_0x451f('0x4a')](_0x488f98),['createdAt','updatedAt',_0x451f('0x7c'),'ListId']);if(_0x521b1b[_0x451f('0x61')]['id']){delete _0x521b1b[_0x451f('0x61')]['id'];}if(_[_0x451f('0x7d')](_0x521b1b[_0x451f('0x61')]['from'])){throw new db[(_0x451f('0x77'))][(_0x451f('0x78'))](_0x451f('0x7e'));}if(_[_0x451f('0x7d')](_0x521b1b['body']['body'])||_0x521b1b[_0x451f('0x61')][_0x451f('0x61')]===''){throw new db[(_0x451f('0x77'))][(_0x451f('0x78'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x451f('0x7d')](_0x521b1b[_0x451f('0x61')]['mapKey'])){throw new db[(_0x451f('0x77'))][(_0x451f('0x78'))]('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x4a269c);}if(!_['includes'](_0x4a269c,_0x521b1b[_0x451f('0x61')][_0x451f('0x7f')])){throw new db['Sequelize'][(_0x451f('0x78'))](_0x451f('0x80')+_0x4a269c);}_0x1131c5[_0x521b1b[_0x451f('0x61')][_0x451f('0x7f')]]=_0x521b1b['body'][_0x451f('0x81')];})[_0x451f('0x22')](function(){return db[_0x451f('0x44')][_0x451f('0x5f')]({'where':{'id':_0x521b1b['params']['id']},'include':[{'model':db[_0x451f('0x82')],'as':_0x451f('0x83'),'include':[{'model':db[_0x451f('0x76')],'as':'Contacts','where':_0x1131c5,'limit':0x1,'order':[[_0x451f('0x7b'),'DESC']]}]},{'model':db['OpenchannelApplication'],'as':_0x451f('0x84')}]});})[_0x451f('0x22')](handleEntityNotFound(_0x16c990,null))[_0x451f('0x22')](function(_0x4b9bc4){if(_0x4b9bc4&&_0x4b9bc4['List']){_0x18da54['account']=_0x4b9bc4;_0x18da54[_0x451f('0x85')]=_0x4b9bc4['Applications'];_0x18da54[_0x451f('0x86')]=_0x4b9bc4[_0x451f('0x83')];_0x18da54[_0x451f('0x85')]=_[_0x451f('0x87')](_0x18da54[_0x451f('0x85')],[_0x451f('0x88')],[_0x451f('0x89')]);if(_0x18da54[_0x451f('0x8a')][_0x451f('0x84')]){delete _0x18da54['account']['Applications'];}if(_0x18da54['account'][_0x451f('0x83')]&&_0x18da54[_0x451f('0x8a')][_0x451f('0x83')][_0x451f('0x8b')][_0x451f('0x50')]){return _0x18da54['account']['List'][_0x451f('0x8b')][0x0];}var _0x15481d=_[_0x451f('0x1a')](_0x521b1b[_0x451f('0x61')],{'firstName':_0x521b1b['body'][_0x451f('0x81')],'ListId':_0x4b9bc4[_0x451f('0x8c')]});_0x15481d[_0x521b1b[_0x451f('0x61')][_0x451f('0x7f')]]=_0x521b1b[_0x451f('0x61')]['from'];return db[_0x451f('0x76')]['create'](_0x15481d,{'fields':_0x4facae,'raw':!![]});}})[_0x451f('0x22')](handleEntityNotFound(_0x16c990,null))[_0x451f('0x22')](function(_0x2b1a9e){_0x18da54[_0x451f('0x8d')]=_0x2b1a9e;if(_0x2b1a9e){var _0x3c4187={'ContactId':_0x2b1a9e['id'],'OpenchannelAccountId':_0x521b1b[_0x451f('0x69')]['id'],'from':(_0x2b1a9e[_0x451f('0x8e')]||'')+'\x20'+(_0x2b1a9e[_0x451f('0x8f')]||'')};var _0x530151={'OpenchannelAccountId':_0x521b1b[_0x451f('0x69')]['id'],'closed':![]};if(_0x521b1b[_0x451f('0x61')]['threadId']){_0x530151['threadId']=_0x521b1b[_0x451f('0x61')]['threadId'];return db[_0x451f('0x90')]['find']({'where':_0x530151})[_0x451f('0x22')](function(_0x310e5c){if(_0x310e5c){return[_0x310e5c,![]];}_0x3c4187[_0x451f('0x91')]=_0x521b1b[_0x451f('0x61')]['threadId'];_0x3c4187[_0x451f('0x92')]=_0x521b1b['body'][_0x451f('0x92')];return db[_0x451f('0x90')]['create'](_0x3c4187)[_0x451f('0x22')](function(_0x50f489){return[_0x50f489,!![]];});});}else{_0x530151[_0x451f('0x91')]=null;}_0x530151[_0x451f('0x93')]=_0x2b1a9e['id'];return db[_0x451f('0x90')]['find']({'where':_0x530151})[_0x451f('0x22')](function(_0x139637){if(_0x139637){return[_0x139637,![]];}return db[_0x451f('0x90')]['create'](_0x3c4187)[_0x451f('0x22')](function(_0x51ec21){return[_0x51ec21,!![]];});});}})[_0x451f('0x94')](function(_0xe6aceb,_0x1303f7){if(_0xe6aceb){_0x245543=_0x1303f7;if(!_0x1303f7){var _0x522032={'from':(_0x18da54['contact'][_0x451f('0x8e')]||'')+'\x20'+(_0x18da54[_0x451f('0x8d')][_0x451f('0x8f')]||'')};if(_0x521b1b[_0x451f('0x61')][_0x451f('0x91')]&&_0x521b1b[_0x451f('0x61')][_0x451f('0x95')]&&_0x521b1b[_0x451f('0x61')]['threadId']!=_0x521b1b[_0x451f('0x61')][_0x451f('0x95')]){_0x522032[_0x451f('0x91')]=_0x521b1b[_0x451f('0x61')]['messageId'];}return _0xe6aceb['update'](_0x522032);}else{return _0xe6aceb;}}})[_0x451f('0x22')](function(_0x1bf365){_0x18da54['interaction']=_0x1bf365[_0x451f('0x39')]({'plain':!![]});_0x18da54[_0x451f('0x96')][_0x451f('0x97')]=_0x245543;if(_0x18da54[_0x451f('0x96')][_0x451f('0x97')]){if(_0x18da54[_0x451f('0x8a')][_0x451f('0x98')]){_0x18da54[_0x451f('0x85')][_0x451f('0x99')]({'id':0x0,'priority':_0x18da54['applications'][_0x451f('0x50')]+0x1,'app':_0x451f('0x9a'),'appdata':_0x451f('0x9b'),'interval':_0x451f('0x9c')});}}return db['OpenchannelMessage'][_0x451f('0x60')]({'body':_0x521b1b[_0x451f('0x61')][_0x451f('0x61')],'OpenchannelAccountId':_0x521b1b[_0x451f('0x69')]['id'],'OpenchannelInteractionId':_0x1bf365['id'],'direction':'in','ContactId':_0x18da54[_0x451f('0x8d')]['id'],'AttachmentId':_0x521b1b['body'][_0x451f('0x9d')]});})[_0x451f('0x22')](function(_0x83f7e2){_0x18da54['message']=_0x83f7e2;if(_0x18da54['interaction'][_0x451f('0x9e')]){return db[_0x451f('0x9f')][_0x451f('0x5f')]({'attributes':['id','name'],'where':{'id':_0x18da54['interaction'][_0x451f('0x9e')]}})['then'](function(_0x3a0e57){if(_0x3a0e57){_0x18da54[_0x451f('0x85')][_0x451f('0xa0')]({'id':0x0,'priority':0x0,'app':_0x451f('0xa1'),'appdata':_0x3a0e57[_0x451f('0x3f')]+','+(_0x18da54[_0x451f('0x8a')][_0x451f('0xa2')]||0xa),'interval':_0x451f('0x9c')});_0x18da54[_0x451f('0xa3')]=![];}return respondWithRpcPromise(_0x451f('0xa4'),_0x451f('0xa5'),_0x18da54);});}return respondWithRpcPromise('Start','startRouting',_0x18da54);})[_0x451f('0x22')](function(_0x412dca){respondWithRpcPromise(_0x451f('0xa6'),'EventManager',{'event':_0x451f('0x75'),'message':_0x412dca},client9002);return _0x412dca;})[_0x451f('0x22')](respondWithResult(_0x16c990,null))[_0x451f('0x5d')](handleError(_0x16c990,null));};exports[_0x451f('0xa7')]=function(_0x51a36c,_0x5a7fda){var _0x107d9b=_0x51a36c[_0x451f('0x69')]['id'];var _0x5e0962=_0x51a36c[_0x451f('0x61')];var _0x54fc22=0xc8;var _0x4e9750=null;return db['sequelize'][_0x451f('0xa8')]({'isolationLevel':db[_0x451f('0xa9')][_0x451f('0xaa')][_0x451f('0xab')][_0x451f('0xac')]},function(_0x481f50){return db[_0x451f('0x44')]['findOne']({'where':{'id':_0x107d9b},'transaction':_0x481f50})[_0x451f('0x22')](function(_0xa0d6b5){if(_0xa0d6b5){return db['OpenchannelApplication']['destroy']({'where':{'OpenchannelAccountId':_0x107d9b},'transaction':_0x481f50})['then'](function(){var _0x2a5ca3=_[_0x451f('0x48')](_0x5e0962,function(_0x5748f8){_0x5748f8[_0x451f('0x6c')]=_0x107d9b;return _0x5748f8;});return db[_0x451f('0xad')]['bulkCreate'](_0x2a5ca3,{'transaction':_0x481f50});});}else{_0x54fc22=0x194;_0x4e9750=[];}});})[_0x451f('0x22')](function(){if(_0x54fc22!==0x194){return db[_0x451f('0xad')][_0x451f('0xae')]({'where':{'OpenchannelAccountId':_0x107d9b},'order':'priority'})[_0x451f('0x22')](function(_0x4301c4){_0x4e9750=_0x4301c4;});}})[_0x451f('0x5d')](function(_0x36049b){_0x54fc22=0x1f4;logger['error'](_0x36049b[_0x451f('0x3e')]);if(_0x36049b[_0x451f('0x3f')]){delete _0x36049b[_0x451f('0x3f')];}_0x4e9750=_0x36049b;})[_0x451f('0xaf')](function(){if(_0x4e9750===null){_0x5a7fda['sendStatus'](_0x54fc22);}else{if(_0x54fc22===0x1f4){_0x5a7fda[_0x451f('0x2e')](_0x54fc22)['send'](_0x4e9750);}else{_0x5a7fda[_0x451f('0x2e')](_0x54fc22)[_0x451f('0x2f')](_0x4e9750);}}});};exports[_0x451f('0xb0')]=function(_0xa79db9,_0x52364d,_0x427712){var _0x4267e4={};var _0x59b9ce={};var _0x43e036;var _0x10ab1a;return db[_0x451f('0x44')][_0x451f('0x74')]({'where':{'id':_0xa79db9[_0x451f('0x69')]['id']}})[_0x451f('0x22')](handleEntityNotFound(_0x52364d,null))[_0x451f('0x22')](function(_0x3b0e35){if(_0x3b0e35){_0x43e036=_0x3b0e35;_0x59b9ce['model']=_[_0x451f('0x4a')](db[_0x451f('0xad')]['rawAttributes']);_0x59b9ce[_0x451f('0x49')]=_[_0x451f('0x4a')](_0xa79db9[_0x451f('0x49')]);_0x59b9ce[_0x451f('0x4b')]=_[_0x451f('0x4c')](_0x59b9ce['model'],_0x59b9ce[_0x451f('0x49')]);_0x4267e4[_0x451f('0x4e')]=_[_0x451f('0x4c')](_0x59b9ce[_0x451f('0x4d')],qs[_0x451f('0x4f')](_0xa79db9['query']['fields']));_0x4267e4[_0x451f('0x4e')]=_0x4267e4[_0x451f('0x4e')][_0x451f('0x50')]?_0x4267e4[_0x451f('0x4e')]:_0x59b9ce[_0x451f('0x4d')];_0x4267e4[_0x451f('0x52')]=qs['sort'](_0xa79db9[_0x451f('0x49')][_0x451f('0x53')]);_0x4267e4[_0x451f('0x54')]=qs[_0x451f('0x4b')](_[_0x451f('0x55')](_0xa79db9[_0x451f('0x49')],_0x59b9ce[_0x451f('0x4b')]));if(_0xa79db9[_0x451f('0x49')]['filter']){_0x4267e4[_0x451f('0x54')]=_[_0x451f('0x57')](_0x4267e4[_0x451f('0x54')],{'$or':_[_0x451f('0x48')](_0x4267e4['attributes'],function(_0x4fb4db){var _0x2ea1d0={};_0x2ea1d0[_0x4fb4db]={'$like':'%'+_0xa79db9[_0x451f('0x49')][_0x451f('0x56')]+'%'};return _0x2ea1d0;})});}_0x4267e4=_[_0x451f('0x57')]({},_0x4267e4,_0xa79db9[_0x451f('0x5e')]);return _0x43e036['getApplications'](_0x4267e4);}})[_0x451f('0x22')](function(_0x1a2569){if(_0x1a2569){_0x10ab1a=_0x1a2569[_0x451f('0x50')];if(!_0xa79db9['query'][_0x451f('0x6e')](_0x451f('0x51'))){_0x4267e4['limit']=qs['limit'](_0xa79db9[_0x451f('0x49')][_0x451f('0x31')]);_0x4267e4[_0x451f('0x30')]=qs['offset'](_0xa79db9[_0x451f('0x49')][_0x451f('0x30')]);}return _0x43e036[_0x451f('0xb0')](_0x4267e4);}})[_0x451f('0x22')](function(_0x3ab6d9){if(_0x3ab6d9){return _0x3ab6d9?{'count':_0x10ab1a,'rows':_0x3ab6d9}:null;}})[_0x451f('0x22')](respondWithResult(_0x52364d,null))[_0x451f('0x5d')](handleError(_0x52364d,null));};exports[_0x451f('0xb1')]=function(_0xfc4656,_0x5d6465,_0x5a18bc){var _0x4a9f2d={'raw':![],'where':{}};var _0x3e1a07={};var _0x1f7a39={'count':0x0,'rows':[]};return db[_0x451f('0x44')]['findOne']({'where':{'id':_0xfc4656[_0x451f('0x69')]['id']}})[_0x451f('0x22')](handleEntityNotFound(_0x5d6465,null))[_0x451f('0x22')](function(_0x1ad5a7){if(_0x1ad5a7){_0x3e1a07['model']=_[_0x451f('0x4a')](db[_0x451f('0x90')][_0x451f('0x45')]);_0x3e1a07[_0x451f('0x49')]=_[_0x451f('0x4a')](_0xfc4656['query']);_0x3e1a07['filters']=_[_0x451f('0x4c')](_0x3e1a07[_0x451f('0x4d')],_0x3e1a07[_0x451f('0x49')]);_0x4a9f2d['attributes']=_['intersection'](_0x3e1a07[_0x451f('0x4d')],qs[_0x451f('0x4f')](_0xfc4656[_0x451f('0x49')]['fields']));_0x4a9f2d[_0x451f('0x4e')]=_0x4a9f2d[_0x451f('0x4e')][_0x451f('0x50')]?_0x4a9f2d[_0x451f('0x4e')]:_0x3e1a07[_0x451f('0x4d')];if(!_0xfc4656[_0x451f('0x49')][_0x451f('0x6e')]('nolimit')){_0x4a9f2d[_0x451f('0x31')]=qs[_0x451f('0x31')](_0xfc4656[_0x451f('0x49')][_0x451f('0x31')]);_0x4a9f2d['offset']=qs[_0x451f('0x30')](_0xfc4656[_0x451f('0x49')]['offset']);}_0x4a9f2d[_0x451f('0x52')]=qs[_0x451f('0x53')](_0xfc4656[_0x451f('0x49')][_0x451f('0x53')]);_0x4a9f2d[_0x451f('0x54')]=qs[_0x451f('0x4b')](_['pick'](_0xfc4656[_0x451f('0x49')],_0x3e1a07[_0x451f('0x4b')]));_0x4a9f2d[_0x451f('0x54')][_0x451f('0x6c')]=_0x1ad5a7['id'];if(_0xfc4656[_0x451f('0x49')][_0x451f('0x56')]){_0x4a9f2d[_0x451f('0x54')]=_[_0x451f('0x57')](_0x4a9f2d['where'],{'$or':_['map'](_0x4a9f2d['attributes'],function(_0x4412f0){var _0x455d58={};_0x455d58[_0x4412f0]={'$like':'%'+_0xfc4656['query']['filter']+'%'};return _0x455d58;})});}_0x4a9f2d=_[_0x451f('0x57')]({},_0x4a9f2d,_0xfc4656['options']);return db[_0x451f('0x90')][_0x451f('0x32')]({'where':_0x4a9f2d[_0x451f('0x54')]})['then'](function(_0x2a2a7a){_0x1f7a39['count']=_0x2a2a7a;if(_0xfc4656[_0x451f('0x49')]['includeAll']){_0x4a9f2d[_0x451f('0x5a')]=[{'model':db['CmContact'],'as':_0x451f('0xb2'),'required':![]},{'model':db['User'],'as':_0x451f('0xb3'),'attributes':[_0x451f('0x3f'),_0x451f('0xb4'),_0x451f('0xb5')],'required':![]},{'model':db[_0x451f('0xb6')],'as':_0x451f('0xb7'),'attributes':['id','name',_0x451f('0xb8')],'where':_0xfc4656[_0x451f('0x49')][_0x451f('0xb9')]?{'id':_0xfc4656[_0x451f('0x49')][_0x451f('0xb9')]}:undefined,'required':_0xfc4656[_0x451f('0x49')][_0x451f('0xb9')]?!![]:![]}];}return db[_0x451f('0x90')][_0x451f('0x5b')](_0x4a9f2d);})[_0x451f('0x22')](function(_0x28aa45){_0x1f7a39[_0x451f('0x5c')]=_0x28aa45;return _0x1f7a39;});}})['then'](respondWithFilteredResult(_0x5d6465,_0x4a9f2d))[_0x451f('0x5d')](handleError(_0x5d6465,null));};exports[_0x451f('0xba')]=function(_0x284143,_0x5a3c2c,_0x3de319){return db['OpenchannelAccount'][_0x451f('0x5f')]({'where':{'id':_0x284143[_0x451f('0x69')]['id']}})[_0x451f('0x22')](handleEntityNotFound(_0x5a3c2c,null))[_0x451f('0x22')](function(_0x53fbb1){if(_0x53fbb1){return _0x53fbb1[_0x451f('0xba')](_0x284143[_0x451f('0x61')][_0x451f('0x71')],_[_0x451f('0xbb')](_0x284143['body'],[_0x451f('0x71'),'id'])||{})[_0x451f('0x94')](function(_0x5eb88b){for(var _0x40d049=0x0;_0x40d049<_0x284143[_0x451f('0x61')]['ids'][_0x451f('0x50')];_0x40d049+=0x1){socket[_0x451f('0xbc')]('userOpenchannelAccount:save',{'UserId':Number(_0x284143[_0x451f('0x61')][_0x451f('0x71')][_0x40d049]),'OpenchannelAccountId':Number(_0x284143[_0x451f('0x69')]['id'])});}return _0x5eb88b;});}})[_0x451f('0x22')](respondWithResult(_0x5a3c2c,null))[_0x451f('0x5d')](handleError(_0x5a3c2c,null));};exports['removeAgents']=function(_0x28ebd4,_0x5bfe21,_0x1de8b8){return db['OpenchannelAccount'][_0x451f('0x5f')]({'where':{'id':_0x28ebd4['params']['id']}})[_0x451f('0x22')](handleEntityNotFound(_0x5bfe21,null))[_0x451f('0x22')](function(_0x509007){if(_0x509007){return _0x509007['removeAgents'](_0x28ebd4[_0x451f('0x49')][_0x451f('0x71')])[_0x451f('0x22')](function(){if(_['isArray'](_0x28ebd4[_0x451f('0x49')][_0x451f('0x71')])){for(var _0x56d39b=0x0;_0x56d39b<_0x28ebd4[_0x451f('0x49')]['ids']['length'];_0x56d39b+=0x1){socket['emit']('userOpenchannelAccount:remove',{'UserId':Number(_0x28ebd4[_0x451f('0x49')]['ids'][_0x56d39b]),'OpenchannelAccountId':Number(_0x28ebd4[_0x451f('0x69')]['id'])});}}else{socket[_0x451f('0xbc')]('userOpenchannelAccount:remove',{'UserId':Number(_0x28ebd4[_0x451f('0x49')][_0x451f('0x71')]),'OpenchannelAccountId':Number(_0x28ebd4[_0x451f('0x69')]['id'])});}});}})[_0x451f('0x22')](respondWithStatusCode(_0x5bfe21,null))[_0x451f('0x5d')](handleError(_0x5bfe21,null));};exports['getAgents']=function(_0x3b57fc,_0x514ce8,_0x4830ad){var _0x13d23c={};var _0x2ed796={};var _0x38e15f;var _0x5be2ba;return db[_0x451f('0x44')][_0x451f('0x74')]({'where':{'id':_0x3b57fc[_0x451f('0x69')]['id']}})[_0x451f('0x22')](handleEntityNotFound(_0x514ce8,null))['then'](function(_0x9ea51c){if(_0x9ea51c){_0x38e15f=_0x9ea51c;_0x2ed796[_0x451f('0x4d')]=_[_0x451f('0x4a')](db[_0x451f('0x9f')][_0x451f('0x45')]);_0x2ed796[_0x451f('0x49')]=_[_0x451f('0x4a')](_0x3b57fc['query']);_0x2ed796[_0x451f('0x4b')]=_[_0x451f('0x4c')](_0x2ed796['model'],_0x2ed796['query']);_0x13d23c['attributes']=_[_0x451f('0x4c')](_0x2ed796[_0x451f('0x4d')],qs['fields'](_0x3b57fc['query']['fields']));_0x13d23c[_0x451f('0x4e')]=_0x13d23c[_0x451f('0x4e')]['length']?_0x13d23c[_0x451f('0x4e')]:_0x2ed796[_0x451f('0x4d')];_0x13d23c[_0x451f('0x52')]=qs[_0x451f('0x53')](_0x3b57fc[_0x451f('0x49')]['sort']);_0x13d23c['where']=qs[_0x451f('0x4b')](_[_0x451f('0x55')](_0x3b57fc[_0x451f('0x49')],_0x2ed796[_0x451f('0x4b')]));if(_0x3b57fc[_0x451f('0x49')][_0x451f('0x56')]){_0x13d23c['where']=_['merge'](_0x13d23c[_0x451f('0x54')],{'$or':_[_0x451f('0x48')](_0x13d23c[_0x451f('0x4e')],function(_0x1052c9){var _0x358b9f={};_0x358b9f[_0x1052c9]={'$like':'%'+_0x3b57fc[_0x451f('0x49')][_0x451f('0x56')]+'%'};return _0x358b9f;})});}_0x13d23c=_[_0x451f('0x57')]({},_0x13d23c,_0x3b57fc[_0x451f('0x5e')]);return _0x38e15f[_0x451f('0xbd')](_0x13d23c);}})['then'](function(_0x39879f){if(_0x39879f){_0x5be2ba=_0x39879f[_0x451f('0x50')];if(!_0x3b57fc[_0x451f('0x49')][_0x451f('0x6e')](_0x451f('0x51'))){_0x13d23c['limit']=qs[_0x451f('0x31')](_0x3b57fc['query'][_0x451f('0x31')]);_0x13d23c['offset']=qs['offset'](_0x3b57fc[_0x451f('0x49')]['offset']);}return _0x38e15f['getAgents'](_0x13d23c);}})[_0x451f('0x22')](function(_0x2ee3c2){if(_0x2ee3c2){return _0x2ee3c2?{'count':_0x5be2ba,'rows':_0x2ee3c2}:null;}})[_0x451f('0x22')](respondWithResult(_0x514ce8,null))[_0x451f('0x5d')](handleError(_0x514ce8,null));};exports[_0x451f('0x40')]=function(_0xa5d76e,_0x59cfd7,_0x2464c0){var _0x3abe61,_0x5705b7,_0x1cca8b;if(_[_0x451f('0x7d')](_0xa5d76e[_0x451f('0x61')][_0x451f('0x61')])||_0xa5d76e[_0x451f('0x61')][_0x451f('0x61')]===''){throw new db[(_0x451f('0x77'))][(_0x451f('0x78'))](_0x451f('0xbe'));}if(_[_0x451f('0x7d')](_0xa5d76e[_0x451f('0x61')]['to'])){}_0x3abe61=_0xa5d76e[_0x451f('0x61')]['to'];return db[_0x451f('0x44')][_0x451f('0x74')]({'where':{'id':_0xa5d76e[_0x451f('0x69')]['id']}})['then'](handleEntityNotFound(_0x59cfd7,null))[_0x451f('0x22')](function(_0x38e215){if(_0x38e215){return db[_0x451f('0x44')][_0x451f('0x5f')]({'where':{'id':_0x38e215['id']},'include':[{'model':db[_0x451f('0x82')],'as':_0x451f('0x83'),'include':[{'model':db['CmContact'],'as':_0x451f('0x8b'),'where':{[_0x38e215[_0x451f('0x7f')]]:_0x3abe61},'limit':0x1,'order':[[_0x451f('0x7b'),'DESC']]}]}]})[_0x451f('0x22')](handleEntityNotFound(_0x59cfd7,null))[_0x451f('0x22')](function(_0x6bc420){if(_0x6bc420&&_0x6bc420[_0x451f('0x83')]){_0x5705b7=_0x6bc420[_0x451f('0x39')]({'plain':!![]});if(_0x5705b7[_0x451f('0x83')]&&_0x5705b7[_0x451f('0x83')][_0x451f('0x8b')][_0x451f('0x50')]){return _0x5705b7['List'][_0x451f('0x8b')][0x0];}return db[_0x451f('0x76')]['create'](_[_0x451f('0x1a')](_0xa5d76e[_0x451f('0x61')],{'firstName':_0x3abe61,[_0x6bc420[_0x451f('0x7f')]]:_0x3abe61,'phone':_0x3abe61,'ListId':_0x5705b7[_0x451f('0x8c')]}));}})['then'](handleEntityNotFound(_0x59cfd7,null))[_0x451f('0x22')](function(_0x328b11){if(_0x328b11){_0x1cca8b=_0x328b11;return db[_0x451f('0x90')]['find']({'where':{'ContactId':_0x1cca8b['id'],'closed':![],'OpenchannelAccountId':_0x5705b7['id']}})['then'](function(_0x15fb1c){if(_0x15fb1c){return[_0x15fb1c,![]];}return db[_0x451f('0x90')][_0x451f('0x60')]({'UserId':_0xa5d76e[_0x451f('0x62')]['id'],'ContactId':_0x1cca8b['id'],'OpenchannelAccountId':_0x5705b7['id'],'lastMsgDirection':_0x451f('0xbf'),'Messages':[_[_0x451f('0x57')](_0xa5d76e[_0x451f('0x61')],{'read':![],'body':_0xa5d76e[_0x451f('0x61')][_0x451f('0x61')],'OpenchannelAccountId':_0x5705b7['id'],'UserId':_0xa5d76e[_0x451f('0x62')]['id'],'ContactId':_0x1cca8b['id']})]},{'include':[{'model':db[_0x451f('0xc0')],'as':_0x451f('0xc1')}]})[_0x451f('0x22')](function(_0x30b0fa){return[_0x30b0fa,!![]];});});}})[_0x451f('0x94')](function(_0x78fc8a,_0x1cb2d4){if(_0x1cb2d4){return _0x78fc8a;}return db[_0x451f('0xc0')][_0x451f('0x60')](_[_0x451f('0x57')](_0xa5d76e[_0x451f('0x61')],{'read':![],'body':_0xa5d76e[_0x451f('0x61')][_0x451f('0x61')],'OpenchannelAccountId':_0x5705b7['id'],'OpenchannelInteractionId':_0x78fc8a['id'],'UserId':_0xa5d76e[_0x451f('0x62')]['id'],'ContactId':_0x1cca8b['id']}))[_0x451f('0x22')](function(_0x371aa5){_0x78fc8a[_0x451f('0xc2')][_0x451f('0xc1')]=[];_0x78fc8a['dataValues'][_0x451f('0xc1')][_0x451f('0x99')](_0x371aa5[_0x451f('0xc2')]);return _0x78fc8a;});});}})[_0x451f('0x22')](respondWithResult(_0x59cfd7,null))[_0x451f('0x5d')](handleError(_0x59cfd7,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