Built motion from commit (unavailable).|2.5.28
[motion2.git] / server / api / openchannelAccount / openchannelAccount.controller.js
index 89f4dc9..891b570 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x793d=['ValidationError','isNil','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','List','CmContact','Contacts','DESC','Applications','account','list','applications','priority','asc','firstName','lastName','threadId','externalUrl','OpenchannelInteraction','ContactId','spread','contact','interaction','created','autoclose','push','close','*,*,*,*','OpenchannelMessage','AttachmentId','UserId','User','waitForTheAssignedAgent','forcedOwnership','Start','startRouting','EventManager','addApplications','sequelize','transaction','OpenchannelApplication','bulkCreate','findAndCountAll','getApplications','getInteractions','Contact','Owner','fullname','internal','Tag','Tags','color','tag','addAgents','omit','emit','userOpenchannelAccount:save','removeAgents','isArray','userOpenchannelAccount:remove','getAgents','Messages','dataValues','rimraf','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./openchannelAccount.socket','register','jayson/promise','client','http','request','then','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','debug','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','result','catch','sendStatus','status','json','count','offset','limit','set','Content-Range','apply','reject','save','destroy','get','OpenchannelAccounts','UserProfileResource','end','stack','name','send','index','Pause','mandatoryDispositionPause','map','fieldName','type','key','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','OpenchannelAccount','findAll','rows','params','rawAttributes','includeAll','include','find','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','body','describe','addDisposition','OpenchannelAccountId','Disposition','getDispositions','findOne','removeDispositions','ids','CannedAnswer','getAnswers','removeAnswers','notify','Sequelize','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','ListId','from'];(function(_0x4fe9f4,_0x3163f9){var _0x382fc1=function(_0xf9bb84){while(--_0xf9bb84){_0x4fe9f4['push'](_0x4fe9f4['shift']());}};_0x382fc1(++_0x3163f9);}(_0x793d,0x106));var _0xd793=function(_0xb03f0f,_0x95a350){_0xb03f0f=_0xb03f0f-0x0;var _0x27df7f=_0x793d[_0xb03f0f];return _0x27df7f;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xd793('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0xd793('0x1'));var rp=require(_0xd793('0x2'));var moment=require('moment');var BPromise=require(_0xd793('0x3'));var Mustache=require(_0xd793('0x4'));var util=require(_0xd793('0x5'));var path=require(_0xd793('0x6'));var sox=require(_0xd793('0x7'));var csv=require(_0xd793('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xd793('0x9'));var _=require(_0xd793('0xa'));var squel=require(_0xd793('0xb'));var crypto=require(_0xd793('0xc'));var jsforce=require(_0xd793('0xd'));var deskjs=require('desk.js');var toCsv=require(_0xd793('0x8'));var querystring=require(_0xd793('0xe'));var Papa=require(_0xd793('0xf'));var Redis=require(_0xd793('0x10'));var authService=require(_0xd793('0x11'));var qs=require(_0xd793('0x12'));var as=require(_0xd793('0x13'));var hardwareService=require(_0xd793('0x14'));var logger=require('../../config/logger')(_0xd793('0x15'));var utils=require(_0xd793('0x16'));var config=require(_0xd793('0x17'));var licenseUtil=require(_0xd793('0x18'));var db=require(_0xd793('0x19'))['db'];config[_0xd793('0x1a')]=_[_0xd793('0x1b')](config[_0xd793('0x1a')],{'host':_0xd793('0x1c'),'port':0x18eb});var socket=require(_0xd793('0x1d'))(new Redis(config[_0xd793('0x1a')]));require(_0xd793('0x1e'))[_0xd793('0x1f')](socket);var jayson=require(_0xd793('0x20'));var client=jayson[_0xd793('0x21')]['http']({'port':0x232c});var client9002=jayson[_0xd793('0x21')][_0xd793('0x22')]({'port':0x232a});function respondWithRpcPromise(_0x1a4a82,_0x3387f1,_0x165c5e,_0x3f001a){return new BPromise(function(_0x3fae7c,_0x441455){var _0x192909=_0x3f001a||client;return _0x192909[_0xd793('0x23')](_0x1a4a82,_0x165c5e)[_0xd793('0x24')](function(_0x32ba5e){logger['info'](_0xd793('0x25'),_0x3387f1,_0xd793('0x26'));logger[_0xd793('0x27')](_0xd793('0x28'),_0x3387f1,'request\x20sent',JSON[_0xd793('0x29')](_0x32ba5e));if(_0x32ba5e[_0xd793('0x2a')]){if(_0x32ba5e['error'][_0xd793('0x2b')]===0x1f4){logger[_0xd793('0x2a')](_0xd793('0x25'),_0x3387f1,_0x32ba5e[_0xd793('0x2a')]['message']);return _0x441455(_0x32ba5e[_0xd793('0x2a')]['message']);}logger[_0xd793('0x2a')](_0xd793('0x25'),_0x3387f1,_0x32ba5e[_0xd793('0x2a')][_0xd793('0x2c')]);return _0x3fae7c(_0x32ba5e['error']['message']);}else{logger[_0xd793('0x2d')](_0xd793('0x25'),_0x3387f1,_0xd793('0x26'));_0x3fae7c(_0x32ba5e[_0xd793('0x2e')][_0xd793('0x2c')]);}})[_0xd793('0x2f')](function(_0x2afd4d){logger[_0xd793('0x2a')](_0xd793('0x25'),_0x3387f1,_0x2afd4d);_0x441455(_0x2afd4d);});});}function respondWithStatusCode(_0x198f86,_0x4af623){_0x4af623=_0x4af623||0xcc;return function(_0x2682c8){if(_0x2682c8){return _0x198f86[_0xd793('0x30')](_0x4af623);}return _0x198f86[_0xd793('0x31')](_0x4af623)['end']();};}function respondWithResult(_0x381fef,_0x28a3d2){_0x28a3d2=_0x28a3d2||0xc8;return function(_0x1fc65c){if(_0x1fc65c){return _0x381fef[_0xd793('0x31')](_0x28a3d2)[_0xd793('0x32')](_0x1fc65c);}};}function respondWithFilteredResult(_0x18164f,_0x4774c8){return function(_0x5cc0da){if(_0x5cc0da){var _0x2ff9c2=_0x5cc0da[_0xd793('0x33')],_0x4f77fb=_0x4774c8[_0xd793('0x34')],_0x2bb8ea=_0x4774c8['offset']+_0x4774c8[_0xd793('0x35')],_0x55ac8f;if(_0x2bb8ea>=_0x2ff9c2){_0x2bb8ea=_0x2ff9c2;_0x55ac8f=0xc8;}else{_0x55ac8f=0xce;}_0x18164f['status'](_0x55ac8f);return _0x18164f[_0xd793('0x36')](_0xd793('0x37'),_0x4f77fb+'-'+_0x2bb8ea+'/'+_0x2ff9c2)['json'](_0x5cc0da);}return null;};}function patchUpdates(_0x25ea9b){return function(_0xf93f44){try{jsonpatch[_0xd793('0x38')](_0xf93f44,_0x25ea9b,!![]);}catch(_0x12b90b){return BPromise[_0xd793('0x39')](_0x12b90b);}return _0xf93f44[_0xd793('0x3a')]();};}function saveUpdates(_0x472739,_0x4bb4b6){return function(_0x54e2d6){if(_0x54e2d6){return _0x54e2d6['update'](_0x472739)[_0xd793('0x24')](function(_0x38c0f3){return _0x38c0f3;});}return null;};}function removeEntity(_0x5ec8a7,_0x527e58){return function(_0x3ecbe8){if(_0x3ecbe8){return _0x3ecbe8[_0xd793('0x3b')]()[_0xd793('0x24')](function(){var _0x3e8461=_0x3ecbe8[_0xd793('0x3c')]({'plain':!![]});var _0x293aca=_0xd793('0x3d');return db[_0xd793('0x3e')][_0xd793('0x3b')]({'where':{'type':_0x293aca,'resourceId':_0x3e8461['id']}})[_0xd793('0x24')](function(){return _0x3ecbe8;});})[_0xd793('0x24')](function(){_0x5ec8a7[_0xd793('0x31')](0xcc)[_0xd793('0x3f')]();});}};}function handleEntityNotFound(_0x448fe5,_0x20f962){return function(_0x4ae758){if(!_0x4ae758){_0x448fe5[_0xd793('0x30')](0x194);}return _0x4ae758;};}function handleError(_0x29666a,_0x5bd0df){_0x5bd0df=_0x5bd0df||0x1f4;return function(_0x3ceab6){logger[_0xd793('0x2a')](_0x3ceab6[_0xd793('0x40')]);if(_0x3ceab6[_0xd793('0x41')]){delete _0x3ceab6[_0xd793('0x41')];}_0x29666a['status'](_0x5bd0df)[_0xd793('0x42')](_0x3ceab6);};}exports[_0xd793('0x43')]=function(_0x20a95a,_0x41a9b3){var _0x430303={'include':[{'model':db[_0xd793('0x44')],'as':_0xd793('0x45')}]},_0x1eacf0={},_0x59d6a8={'count':0x0,'rows':[]};var _0xebcdf1=_[_0xd793('0x46')](db['OpenchannelAccount']['rawAttributes'],function(_0xaf57df){return{'name':_0xaf57df[_0xd793('0x47')],'type':_0xaf57df[_0xd793('0x48')][_0xd793('0x49')]};});_0x1eacf0['model']=_[_0xd793('0x46')](_0xebcdf1,'name');_0x1eacf0[_0xd793('0x4a')]=_[_0xd793('0x4b')](_0x20a95a[_0xd793('0x4a')]);_0x1eacf0[_0xd793('0x4c')]=_[_0xd793('0x4d')](_0x1eacf0[_0xd793('0x4e')],_0x1eacf0['query']);_0x430303[_0xd793('0x4f')]=_[_0xd793('0x4d')](_0x1eacf0[_0xd793('0x4e')],qs[_0xd793('0x50')](_0x20a95a[_0xd793('0x4a')][_0xd793('0x50')]));_0x430303['attributes']=_0x430303[_0xd793('0x4f')][_0xd793('0x51')]?_0x430303[_0xd793('0x4f')]:_0x1eacf0['model'];if(!_0x20a95a[_0xd793('0x4a')][_0xd793('0x52')](_0xd793('0x53'))){_0x430303[_0xd793('0x35')]=qs[_0xd793('0x35')](_0x20a95a['query'][_0xd793('0x35')]);_0x430303[_0xd793('0x34')]=qs['offset'](_0x20a95a[_0xd793('0x4a')][_0xd793('0x34')]);}_0x430303[_0xd793('0x54')]=qs[_0xd793('0x55')](_0x20a95a[_0xd793('0x4a')][_0xd793('0x55')]);_0x430303[_0xd793('0x56')]=qs[_0xd793('0x4c')](_[_0xd793('0x57')](_0x20a95a['query'],_0x1eacf0[_0xd793('0x4c')]),_0xebcdf1);if(_0x20a95a[_0xd793('0x4a')][_0xd793('0x58')]){_0x430303[_0xd793('0x56')]=_[_0xd793('0x59')](_0x430303[_0xd793('0x56')],{'$or':_[_0xd793('0x46')](_0xebcdf1,function(_0x178f5f){if(_0x178f5f[_0xd793('0x48')]!==_0xd793('0x5a')){var _0x4b18c7={};_0x4b18c7[_0x178f5f[_0xd793('0x41')]]={'$like':'%'+_0x20a95a[_0xd793('0x4a')][_0xd793('0x58')]+'%'};return _0x4b18c7;}})});}_0x430303=_['merge']({},_0x430303,_0x20a95a[_0xd793('0x5b')]);var _0x11a433={'where':_0x430303[_0xd793('0x56')]};return db['OpenchannelAccount'][_0xd793('0x33')](_0x11a433)[_0xd793('0x24')](function(_0x56b281){_0x59d6a8['count']=_0x56b281;if(_0x20a95a[_0xd793('0x4a')]['includeAll']){_0x430303['include']=[{'all':!![]}];}return db[_0xd793('0x5c')][_0xd793('0x5d')](_0x430303);})['then'](function(_0x8ccdc0){_0x59d6a8[_0xd793('0x5e')]=_0x8ccdc0;return _0x59d6a8;})[_0xd793('0x24')](respondWithFilteredResult(_0x41a9b3,_0x430303))[_0xd793('0x2f')](handleError(_0x41a9b3,null));};exports['show']=function(_0x1fca56,_0x387e8a){var _0x1e76b8={'raw':![],'where':{'id':_0x1fca56[_0xd793('0x5f')]['id']},'include':[{'model':db[_0xd793('0x44')],'as':_0xd793('0x45')}]},_0x455e22={};_0x455e22[_0xd793('0x4e')]=_[_0xd793('0x4b')](db[_0xd793('0x5c')][_0xd793('0x60')]);_0x455e22['query']=_[_0xd793('0x4b')](_0x1fca56[_0xd793('0x4a')]);_0x455e22[_0xd793('0x4c')]=_[_0xd793('0x4d')](_0x455e22[_0xd793('0x4e')],_0x455e22[_0xd793('0x4a')]);_0x1e76b8[_0xd793('0x4f')]=_[_0xd793('0x4d')](_0x455e22[_0xd793('0x4e')],qs[_0xd793('0x50')](_0x1fca56['query'][_0xd793('0x50')]));_0x1e76b8[_0xd793('0x4f')]=_0x1e76b8[_0xd793('0x4f')]['length']?_0x1e76b8[_0xd793('0x4f')]:_0x455e22[_0xd793('0x4e')];if(_0x1fca56['query'][_0xd793('0x61')]){_0x1e76b8[_0xd793('0x62')]=[{'all':!![]}];}_0x1e76b8=_[_0xd793('0x59')]({},_0x1e76b8,_0x1fca56['options']);return db[_0xd793('0x5c')][_0xd793('0x63')](_0x1e76b8)['then'](handleEntityNotFound(_0x387e8a,null))[_0xd793('0x24')](respondWithResult(_0x387e8a,null))[_0xd793('0x2f')](handleError(_0x387e8a,null));};exports[_0xd793('0x64')]=function(_0x52db52,_0x42f8aa){return db['OpenchannelAccount'][_0xd793('0x64')](_0x52db52['body'],{})['then'](function(_0x430d96){var _0xeab51=_0x52db52[_0xd793('0x65')]['get']({'plain':!![]});if(!_0xeab51)throw new Error(_0xd793('0x66'));if(_0xeab51[_0xd793('0x67')]===_0xd793('0x65')){var _0xd6565c=_0x430d96[_0xd793('0x3c')]({'plain':!![]});var _0x1eb88b=_0xd793('0x3d');return db[_0xd793('0x68')]['find']({'where':{'name':_0x1eb88b,'userProfileId':_0xeab51[_0xd793('0x69')]},'raw':!![]})[_0xd793('0x24')](function(_0x1936d8){if(_0x1936d8&&_0x1936d8[_0xd793('0x6a')]===0x0){return db[_0xd793('0x3e')][_0xd793('0x64')]({'name':_0xd6565c[_0xd793('0x41')],'resourceId':_0xd6565c['id'],'type':_0x1936d8[_0xd793('0x41')],'sectionId':_0x1936d8['id']},{})[_0xd793('0x24')](function(){return _0x430d96;});}else{return _0x430d96;}})[_0xd793('0x2f')](function(_0x3a3eff){logger[_0xd793('0x2a')](_0xd793('0x6b'),_0x3a3eff);throw _0x3a3eff;});}return _0x430d96;})[_0xd793('0x24')](respondWithResult(_0x42f8aa,0xc9))[_0xd793('0x2f')](handleError(_0x42f8aa,null));};exports[_0xd793('0x6c')]=function(_0x573fc6,_0x3950d6){if(_0x573fc6['body']['id']){delete _0x573fc6[_0xd793('0x6d')]['id'];}return db[_0xd793('0x5c')][_0xd793('0x63')]({'where':{'id':_0x573fc6[_0xd793('0x5f')]['id']},'include':[{'model':db[_0xd793('0x44')],'as':_0xd793('0x45')}]})[_0xd793('0x24')](handleEntityNotFound(_0x3950d6,null))['then'](saveUpdates(_0x573fc6[_0xd793('0x6d')],null))[_0xd793('0x24')](respondWithResult(_0x3950d6,null))[_0xd793('0x2f')](handleError(_0x3950d6,null));};exports[_0xd793('0x3b')]=function(_0x5e94bd,_0x2b871f){return db['OpenchannelAccount'][_0xd793('0x63')]({'where':{'id':_0x5e94bd[_0xd793('0x5f')]['id']}})[_0xd793('0x24')](handleEntityNotFound(_0x2b871f,null))[_0xd793('0x24')](removeEntity(_0x2b871f,null))[_0xd793('0x2f')](handleError(_0x2b871f,null));};exports['describe']=function(_0x27158b,_0x278c8e){return db['OpenchannelAccount'][_0xd793('0x6e')]()[_0xd793('0x24')](respondWithResult(_0x278c8e,null))['catch'](handleError(_0x278c8e,null));};exports[_0xd793('0x6f')]=function(_0x41e110,_0x34b397,_0x2cfa08){if(_0x41e110[_0xd793('0x6d')]['id']){delete _0x41e110['body']['id'];}return db[_0xd793('0x5c')]['find']({'where':{'id':_0x41e110[_0xd793('0x5f')]['id']}})[_0xd793('0x24')](handleEntityNotFound(_0x34b397,null))[_0xd793('0x24')](function(_0x4e83db){if(_0x4e83db){_0x41e110[_0xd793('0x6d')][_0xd793('0x70')]=_0x4e83db['id'];return db[_0xd793('0x71')]['create'](_0x41e110['body']);}})[_0xd793('0x24')](respondWithResult(_0x34b397,null))[_0xd793('0x2f')](handleError(_0x34b397,null));};exports[_0xd793('0x72')]=function(_0x5b3bd1,_0x51b34b,_0x2c75d3){var _0x4c1c04={'raw':![],'where':{}};var _0x48bfd1={};var _0x2efe43={'count':0x0,'rows':[]};return db[_0xd793('0x5c')][_0xd793('0x73')]({'where':{'id':_0x5b3bd1[_0xd793('0x5f')]['id']}})[_0xd793('0x24')](handleEntityNotFound(_0x51b34b,null))['then'](function(_0x3e8364){if(_0x3e8364){_0x48bfd1[_0xd793('0x4e')]=_[_0xd793('0x4b')](db[_0xd793('0x71')][_0xd793('0x60')]);_0x48bfd1[_0xd793('0x4a')]=_[_0xd793('0x4b')](_0x5b3bd1[_0xd793('0x4a')]);_0x48bfd1[_0xd793('0x4c')]=_['intersection'](_0x48bfd1[_0xd793('0x4e')],_0x48bfd1[_0xd793('0x4a')]);_0x4c1c04[_0xd793('0x4f')]=_['intersection'](_0x48bfd1[_0xd793('0x4e')],qs[_0xd793('0x50')](_0x5b3bd1[_0xd793('0x4a')][_0xd793('0x50')]));_0x4c1c04[_0xd793('0x4f')]=_0x4c1c04[_0xd793('0x4f')]['length']?_0x4c1c04[_0xd793('0x4f')]:_0x48bfd1[_0xd793('0x4e')];if(!_0x5b3bd1['query'][_0xd793('0x52')](_0xd793('0x53'))){_0x4c1c04['limit']=qs[_0xd793('0x35')](_0x5b3bd1[_0xd793('0x4a')][_0xd793('0x35')]);_0x4c1c04[_0xd793('0x34')]=qs[_0xd793('0x34')](_0x5b3bd1['query'][_0xd793('0x34')]);}_0x4c1c04[_0xd793('0x54')]=qs['sort'](_0x5b3bd1[_0xd793('0x4a')][_0xd793('0x55')]);_0x4c1c04[_0xd793('0x56')]=qs[_0xd793('0x4c')](_['pick'](_0x5b3bd1[_0xd793('0x4a')],_0x48bfd1['filters']));_0x4c1c04[_0xd793('0x56')][_0xd793('0x70')]=_0x3e8364['id'];if(_0x5b3bd1[_0xd793('0x4a')][_0xd793('0x58')]){_0x4c1c04['where']=_['merge'](_0x4c1c04[_0xd793('0x56')],{'$or':_[_0xd793('0x46')](_0x4c1c04['attributes'],function(_0x2402f3){var _0x20afe3={};_0x20afe3[_0x2402f3]={'$like':'%'+_0x5b3bd1[_0xd793('0x4a')][_0xd793('0x58')]+'%'};return _0x20afe3;})});}_0x4c1c04=_['merge']({},_0x4c1c04,_0x5b3bd1['options']);return db[_0xd793('0x71')][_0xd793('0x33')]({'where':_0x4c1c04['where']})['then'](function(_0x1e2770){_0x2efe43[_0xd793('0x33')]=_0x1e2770;if(_0x5b3bd1[_0xd793('0x4a')]['includeAll']){_0x4c1c04[_0xd793('0x62')]=[{'all':!![]}];}return db[_0xd793('0x71')]['findAll'](_0x4c1c04);})['then'](function(_0xe8b31b){_0x2efe43[_0xd793('0x5e')]=_0xe8b31b;return _0x2efe43;});}})[_0xd793('0x24')](respondWithFilteredResult(_0x51b34b,_0x4c1c04))[_0xd793('0x2f')](handleError(_0x51b34b,null));};exports[_0xd793('0x74')]=function(_0x17fa83,_0x148f03,_0x2a4c29){return db[_0xd793('0x5c')]['find']({'where':{'id':_0x17fa83[_0xd793('0x5f')]['id']}})['then'](handleEntityNotFound(_0x148f03,null))[_0xd793('0x24')](function(_0x40e41c){if(_0x40e41c){return _0x40e41c[_0xd793('0x74')](_0x17fa83['query'][_0xd793('0x75')]);}})['then'](respondWithStatusCode(_0x148f03,null))[_0xd793('0x2f')](handleError(_0x148f03,null));};exports['addAnswer']=function(_0x46bb4d,_0x4bef36,_0x4db185){if(_0x46bb4d['body']['id']){delete _0x46bb4d[_0xd793('0x6d')]['id'];}return db['OpenchannelAccount'][_0xd793('0x63')]({'where':{'id':_0x46bb4d['params']['id']}})[_0xd793('0x24')](handleEntityNotFound(_0x4bef36,null))[_0xd793('0x24')](function(_0xc3cd69){if(_0xc3cd69){_0x46bb4d[_0xd793('0x6d')]['OpenchannelAccountId']=_0xc3cd69['id'];return db[_0xd793('0x76')][_0xd793('0x64')](_0x46bb4d[_0xd793('0x6d')]);}})[_0xd793('0x24')](respondWithResult(_0x4bef36,null))[_0xd793('0x2f')](handleError(_0x4bef36,null));};exports[_0xd793('0x77')]=function(_0x15a3af,_0x1cd5f3,_0x5d984a){var _0x31f209={'raw':![],'where':{}};var _0x5425b8={};var _0x5b4cd5={'count':0x0,'rows':[]};return db[_0xd793('0x5c')][_0xd793('0x73')]({'where':{'id':_0x15a3af['params']['id']}})[_0xd793('0x24')](handleEntityNotFound(_0x1cd5f3,null))[_0xd793('0x24')](function(_0x539c02){if(_0x539c02){_0x5425b8[_0xd793('0x4e')]=_['keys'](db[_0xd793('0x76')]['rawAttributes']);_0x5425b8[_0xd793('0x4a')]=_['keys'](_0x15a3af['query']);_0x5425b8[_0xd793('0x4c')]=_[_0xd793('0x4d')](_0x5425b8[_0xd793('0x4e')],_0x5425b8[_0xd793('0x4a')]);_0x31f209[_0xd793('0x4f')]=_['intersection'](_0x5425b8[_0xd793('0x4e')],qs['fields'](_0x15a3af[_0xd793('0x4a')]['fields']));_0x31f209[_0xd793('0x4f')]=_0x31f209['attributes'][_0xd793('0x51')]?_0x31f209[_0xd793('0x4f')]:_0x5425b8[_0xd793('0x4e')];if(!_0x15a3af[_0xd793('0x4a')][_0xd793('0x52')](_0xd793('0x53'))){_0x31f209['limit']=qs[_0xd793('0x35')](_0x15a3af[_0xd793('0x4a')]['limit']);_0x31f209['offset']=qs[_0xd793('0x34')](_0x15a3af[_0xd793('0x4a')][_0xd793('0x34')]);}_0x31f209[_0xd793('0x54')]=qs[_0xd793('0x55')](_0x15a3af[_0xd793('0x4a')][_0xd793('0x55')]);_0x31f209[_0xd793('0x56')]=qs[_0xd793('0x4c')](_[_0xd793('0x57')](_0x15a3af[_0xd793('0x4a')],_0x5425b8[_0xd793('0x4c')]));_0x31f209[_0xd793('0x56')]['OpenchannelAccountId']=_0x539c02['id'];if(_0x15a3af[_0xd793('0x4a')][_0xd793('0x58')]){_0x31f209['where']=_['merge'](_0x31f209['where'],{'$or':_[_0xd793('0x46')](_0x31f209[_0xd793('0x4f')],function(_0x4e0351){var _0x5b937d={};_0x5b937d[_0x4e0351]={'$like':'%'+_0x15a3af[_0xd793('0x4a')][_0xd793('0x58')]+'%'};return _0x5b937d;})});}_0x31f209=_[_0xd793('0x59')]({},_0x31f209,_0x15a3af[_0xd793('0x5b')]);return db[_0xd793('0x76')][_0xd793('0x33')]({'where':_0x31f209[_0xd793('0x56')]})['then'](function(_0x1855e8){_0x5b4cd5[_0xd793('0x33')]=_0x1855e8;if(_0x15a3af['query'][_0xd793('0x61')]){_0x31f209[_0xd793('0x62')]=[{'all':!![]}];}return db[_0xd793('0x76')]['findAll'](_0x31f209);})['then'](function(_0x545284){_0x5b4cd5[_0xd793('0x5e')]=_0x545284;return _0x5b4cd5;});}})[_0xd793('0x24')](respondWithFilteredResult(_0x1cd5f3,_0x31f209))[_0xd793('0x2f')](handleError(_0x1cd5f3,null));};exports['removeAnswers']=function(_0x151ed0,_0x5caf24,_0x4566bc){return db[_0xd793('0x5c')][_0xd793('0x63')]({'where':{'id':_0x151ed0['params']['id']}})[_0xd793('0x24')](handleEntityNotFound(_0x5caf24,null))[_0xd793('0x24')](function(_0x82ab54){if(_0x82ab54){return _0x82ab54[_0xd793('0x78')](_0x151ed0[_0xd793('0x4a')][_0xd793('0x75')]);}})['then'](respondWithStatusCode(_0x5caf24,null))['catch'](handleError(_0x5caf24,null));};exports[_0xd793('0x79')]=function(_0x205502,_0x19ec78,_0x56a98d){var _0x3211f7={'body':_0x205502[_0xd793('0x6d')],'channel':'openchannel'};var _0x363c22=[];var _0x39c8c6=[];var _0x33493b={};var _0x1e81ff=![];return db['CmContact'][_0xd793('0x6e')]()[_0xd793('0x24')](function(_0x3f316c){if(!_0x3f316c){throw new db[(_0xd793('0x7a'))]['ValidationError'](_0xd793('0x7b'));}_0x363c22=_[_0xd793('0x7c')](_[_0xd793('0x4b')](_0x3f316c),['createdAt','updatedAt']);_0x39c8c6=_[_0xd793('0x7c')](_[_0xd793('0x4b')](_0x3f316c),[_0xd793('0x7d'),_0xd793('0x7e'),_0xd793('0x7f'),_0xd793('0x80')]);if(_0x205502['body']['id']){delete _0x205502[_0xd793('0x6d')]['id'];}if(_['isNil'](_0x205502[_0xd793('0x6d')][_0xd793('0x81')])){throw new db[(_0xd793('0x7a'))][(_0xd793('0x82'))]('from\x20is\x20mandatory');}if(_[_0xd793('0x83')](_0x205502[_0xd793('0x6d')][_0xd793('0x6d')])||_0x205502[_0xd793('0x6d')][_0xd793('0x6d')]===''){throw new db['Sequelize'][(_0xd793('0x82'))](_0xd793('0x84'));}if(_[_0xd793('0x83')](_0x205502[_0xd793('0x6d')][_0xd793('0x85')])){throw new db[(_0xd793('0x7a'))]['ValidationError'](_0xd793('0x86')+_0x39c8c6);}if(!_[_0xd793('0x87')](_0x39c8c6,_0x205502[_0xd793('0x6d')]['mapKey'])){throw new db[(_0xd793('0x7a'))][(_0xd793('0x82'))](_0xd793('0x88')+_0x39c8c6);}_0x33493b[_0x205502[_0xd793('0x6d')]['mapKey']]=_0x205502[_0xd793('0x6d')][_0xd793('0x81')];})[_0xd793('0x24')](function(){return db[_0xd793('0x5c')][_0xd793('0x63')]({'where':{'id':_0x205502['params']['id']},'include':[{'model':db['CmList'],'as':_0xd793('0x89'),'include':[{'model':db[_0xd793('0x8a')],'as':_0xd793('0x8b'),'where':_0x33493b,'limit':0x1,'order':[[_0xd793('0x7e'),_0xd793('0x8c')]]}]},{'model':db['OpenchannelApplication'],'as':_0xd793('0x8d')}]});})[_0xd793('0x24')](handleEntityNotFound(_0x19ec78,null))[_0xd793('0x24')](function(_0x24255f){if(_0x24255f&&_0x24255f[_0xd793('0x89')]){_0x3211f7[_0xd793('0x8e')]=_0x24255f;_0x3211f7['applications']=_0x24255f[_0xd793('0x8d')];_0x3211f7[_0xd793('0x8f')]=_0x24255f[_0xd793('0x89')];_0x3211f7[_0xd793('0x90')]=_['orderBy'](_0x3211f7[_0xd793('0x90')],[_0xd793('0x91')],[_0xd793('0x92')]);if(_0x3211f7[_0xd793('0x8e')][_0xd793('0x8d')]){delete _0x3211f7['account']['Applications'];}if(_0x3211f7[_0xd793('0x8e')][_0xd793('0x89')]&&_0x3211f7['account'][_0xd793('0x89')][_0xd793('0x8b')]['length']){return _0x3211f7[_0xd793('0x8e')][_0xd793('0x89')][_0xd793('0x8b')][0x0];}var _0x506073=_['defaults'](_0x205502[_0xd793('0x6d')],{'firstName':_0x205502[_0xd793('0x6d')][_0xd793('0x81')],'ListId':_0x24255f[_0xd793('0x80')]});_0x506073[_0x205502[_0xd793('0x6d')][_0xd793('0x85')]]=_0x205502[_0xd793('0x6d')][_0xd793('0x81')];return db['CmContact'][_0xd793('0x64')](_0x506073,{'fields':_0x363c22,'raw':!![]});}})[_0xd793('0x24')](handleEntityNotFound(_0x19ec78,null))[_0xd793('0x24')](function(_0x3c2daf){_0x3211f7['contact']=_0x3c2daf;if(_0x3c2daf){var _0x54a8bd={'ContactId':_0x3c2daf['id'],'OpenchannelAccountId':_0x205502['params']['id'],'from':(_0x3c2daf[_0xd793('0x93')]||'')+'\x20'+(_0x3c2daf[_0xd793('0x94')]||'')};var _0x1408b8={'OpenchannelAccountId':_0x205502[_0xd793('0x5f')]['id'],'closed':![]};if(_0x205502[_0xd793('0x6d')][_0xd793('0x95')]){_0x1408b8[_0xd793('0x95')]=_0x205502[_0xd793('0x6d')][_0xd793('0x95')];return db['OpenchannelInteraction'][_0xd793('0x63')]({'where':_0x1408b8})[_0xd793('0x24')](function(_0x2db3c4){if(_0x2db3c4){return[_0x2db3c4,![]];}_0x54a8bd[_0xd793('0x95')]=_0x205502[_0xd793('0x6d')][_0xd793('0x95')];_0x54a8bd[_0xd793('0x96')]=_0x205502[_0xd793('0x6d')]['externalUrl'];return db[_0xd793('0x97')][_0xd793('0x64')](_0x54a8bd)[_0xd793('0x24')](function(_0x8d317a){return[_0x8d317a,!![]];});});}else{_0x1408b8[_0xd793('0x95')]=null;}_0x1408b8[_0xd793('0x98')]=_0x3c2daf['id'];return db['OpenchannelInteraction'][_0xd793('0x63')]({'where':_0x1408b8})[_0xd793('0x24')](function(_0x5963de){if(_0x5963de){return[_0x5963de,![]];}return db[_0xd793('0x97')][_0xd793('0x64')](_0x54a8bd)[_0xd793('0x24')](function(_0x5528a8){return[_0x5528a8,!![]];});});}})[_0xd793('0x99')](function(_0x5f1a41,_0x38eb01){if(_0x5f1a41){_0x1e81ff=_0x38eb01;if(!_0x38eb01){var _0x3aa0ff={'from':(_0x3211f7[_0xd793('0x9a')][_0xd793('0x93')]||'')+'\x20'+(_0x3211f7[_0xd793('0x9a')][_0xd793('0x94')]||'')};if(_0x205502[_0xd793('0x6d')][_0xd793('0x95')]&&_0x205502['body']['messageId']&&_0x205502[_0xd793('0x6d')][_0xd793('0x95')]!=_0x205502[_0xd793('0x6d')]['messageId']){_0x3aa0ff['threadId']=_0x205502['body']['messageId'];}return _0x5f1a41[_0xd793('0x6c')](_0x3aa0ff);}else{return _0x5f1a41;}}})['then'](function(_0x1affb9){_0x3211f7[_0xd793('0x9b')]=_0x1affb9[_0xd793('0x3c')]({'plain':!![]});_0x3211f7[_0xd793('0x9b')][_0xd793('0x9c')]=_0x1e81ff;if(_0x3211f7['interaction'][_0xd793('0x9c')]){if(_0x3211f7['account'][_0xd793('0x9d')]){_0x3211f7[_0xd793('0x90')][_0xd793('0x9e')]({'id':0x0,'priority':_0x3211f7[_0xd793('0x90')][_0xd793('0x51')]+0x1,'app':_0xd793('0x9f'),'appdata':'unmanaged','interval':_0xd793('0xa0')});}}return db[_0xd793('0xa1')][_0xd793('0x64')]({'body':_0x205502[_0xd793('0x6d')][_0xd793('0x6d')],'OpenchannelAccountId':_0x205502['params']['id'],'OpenchannelInteractionId':_0x1affb9['id'],'direction':'in','ContactId':_0x3211f7[_0xd793('0x9a')]['id'],'AttachmentId':_0x205502['body'][_0xd793('0xa2')]});})[_0xd793('0x24')](function(_0x2b8ea6){_0x3211f7[_0xd793('0x2c')]=_0x2b8ea6;if(_0x3211f7[_0xd793('0x9b')][_0xd793('0xa3')]){return db[_0xd793('0xa4')][_0xd793('0x63')]({'attributes':['id',_0xd793('0x41')],'where':{'id':_0x3211f7[_0xd793('0x9b')]['UserId']}})[_0xd793('0x24')](function(_0x2d7948){if(_0x2d7948){_0x3211f7[_0xd793('0x90')]['unshift']({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x2d7948[_0xd793('0x41')]+','+(_0x3211f7[_0xd793('0x8e')][_0xd793('0xa5')]||0xa),'interval':_0xd793('0xa0')});_0x3211f7[_0xd793('0xa6')]=![];}return respondWithRpcPromise(_0xd793('0xa7'),_0xd793('0xa8'),_0x3211f7);});}return respondWithRpcPromise(_0xd793('0xa7'),_0xd793('0xa8'),_0x3211f7);})[_0xd793('0x24')](function(_0x35e794){respondWithRpcPromise(_0xd793('0xa9'),_0xd793('0xa9'),{'event':_0xd793('0x79'),'message':_0x35e794},client9002);return _0x35e794;})['then'](respondWithResult(_0x19ec78,null))[_0xd793('0x2f')](handleError(_0x19ec78,null));};exports[_0xd793('0xaa')]=function(_0x269bf1,_0x3d87db,_0x3902d3){return db[_0xd793('0x5c')]['findOne']({'where':{'id':_0x269bf1[_0xd793('0x5f')]['id']}})[_0xd793('0x24')](handleEntityNotFound(_0x3d87db,null))['then'](function(_0x4fe3d5){if(_0x4fe3d5){return db[_0xd793('0xab')][_0xd793('0xac')](function(_0x15de69){return db[_0xd793('0xad')][_0xd793('0x3b')]({'where':{'OpenchannelAccountId':_0x269bf1[_0xd793('0x5f')]['id']},'transaction':_0x15de69})['then'](function(_0x25c6e1){var _0x197871=_['map'](_0x269bf1[_0xd793('0x6d')],function(_0x59453d){_0x59453d[_0xd793('0x70')]=_0x269bf1[_0xd793('0x5f')]['id'];return _0x59453d;});return db['OpenchannelApplication'][_0xd793('0xae')](_0x197871,{'transaction':_0x15de69});});})[_0xd793('0x24')](function(){return db[_0xd793('0xad')][_0xd793('0xaf')]({'where':{'OpenchannelAccountId':_0x269bf1[_0xd793('0x5f')]['id']},'order':'priority'});});}})['then'](respondWithResult(_0x3d87db,null))[_0xd793('0x2f')](handleError(_0x3d87db,null));};exports[_0xd793('0xb0')]=function(_0x27166a,_0x3432e6,_0x4282e1){var _0xec87d7={};var _0x1fdb56={};var _0x390116;var _0xea5fa3;return db['OpenchannelAccount']['findOne']({'where':{'id':_0x27166a[_0xd793('0x5f')]['id']}})[_0xd793('0x24')](handleEntityNotFound(_0x3432e6,null))[_0xd793('0x24')](function(_0x8b96b1){if(_0x8b96b1){_0x390116=_0x8b96b1;_0x1fdb56[_0xd793('0x4e')]=_['keys'](db[_0xd793('0xad')][_0xd793('0x60')]);_0x1fdb56[_0xd793('0x4a')]=_[_0xd793('0x4b')](_0x27166a['query']);_0x1fdb56[_0xd793('0x4c')]=_[_0xd793('0x4d')](_0x1fdb56['model'],_0x1fdb56[_0xd793('0x4a')]);_0xec87d7['attributes']=_[_0xd793('0x4d')](_0x1fdb56[_0xd793('0x4e')],qs[_0xd793('0x50')](_0x27166a[_0xd793('0x4a')]['fields']));_0xec87d7[_0xd793('0x4f')]=_0xec87d7[_0xd793('0x4f')][_0xd793('0x51')]?_0xec87d7[_0xd793('0x4f')]:_0x1fdb56[_0xd793('0x4e')];_0xec87d7[_0xd793('0x54')]=qs[_0xd793('0x55')](_0x27166a[_0xd793('0x4a')][_0xd793('0x55')]);_0xec87d7['where']=qs[_0xd793('0x4c')](_[_0xd793('0x57')](_0x27166a[_0xd793('0x4a')],_0x1fdb56[_0xd793('0x4c')]));if(_0x27166a[_0xd793('0x4a')]['filter']){_0xec87d7['where']=_[_0xd793('0x59')](_0xec87d7[_0xd793('0x56')],{'$or':_[_0xd793('0x46')](_0xec87d7[_0xd793('0x4f')],function(_0x55e24f){var _0x11645a={};_0x11645a[_0x55e24f]={'$like':'%'+_0x27166a[_0xd793('0x4a')][_0xd793('0x58')]+'%'};return _0x11645a;})});}_0xec87d7=_[_0xd793('0x59')]({},_0xec87d7,_0x27166a[_0xd793('0x5b')]);return _0x390116['getApplications'](_0xec87d7);}})[_0xd793('0x24')](function(_0x891da7){if(_0x891da7){_0xea5fa3=_0x891da7['length'];if(!_0x27166a[_0xd793('0x4a')][_0xd793('0x52')](_0xd793('0x53'))){_0xec87d7[_0xd793('0x35')]=qs[_0xd793('0x35')](_0x27166a[_0xd793('0x4a')][_0xd793('0x35')]);_0xec87d7[_0xd793('0x34')]=qs[_0xd793('0x34')](_0x27166a['query'][_0xd793('0x34')]);}return _0x390116['getApplications'](_0xec87d7);}})['then'](function(_0x411276){if(_0x411276){return _0x411276?{'count':_0xea5fa3,'rows':_0x411276}:null;}})[_0xd793('0x24')](respondWithResult(_0x3432e6,null))[_0xd793('0x2f')](handleError(_0x3432e6,null));};exports[_0xd793('0xb1')]=function(_0x5984ce,_0x114d82,_0x7b56bc){var _0xb3337a={'raw':![],'where':{}};var _0x1db24a={};var _0x39a1fc={'count':0x0,'rows':[]};return db['OpenchannelAccount']['findOne']({'where':{'id':_0x5984ce[_0xd793('0x5f')]['id']}})[_0xd793('0x24')](handleEntityNotFound(_0x114d82,null))[_0xd793('0x24')](function(_0x101084){if(_0x101084){_0x1db24a[_0xd793('0x4e')]=_[_0xd793('0x4b')](db[_0xd793('0x97')][_0xd793('0x60')]);_0x1db24a[_0xd793('0x4a')]=_[_0xd793('0x4b')](_0x5984ce[_0xd793('0x4a')]);_0x1db24a[_0xd793('0x4c')]=_[_0xd793('0x4d')](_0x1db24a[_0xd793('0x4e')],_0x1db24a[_0xd793('0x4a')]);_0xb3337a['attributes']=_[_0xd793('0x4d')](_0x1db24a['model'],qs[_0xd793('0x50')](_0x5984ce[_0xd793('0x4a')][_0xd793('0x50')]));_0xb3337a[_0xd793('0x4f')]=_0xb3337a['attributes'][_0xd793('0x51')]?_0xb3337a[_0xd793('0x4f')]:_0x1db24a[_0xd793('0x4e')];if(!_0x5984ce['query'][_0xd793('0x52')](_0xd793('0x53'))){_0xb3337a[_0xd793('0x35')]=qs['limit'](_0x5984ce[_0xd793('0x4a')]['limit']);_0xb3337a[_0xd793('0x34')]=qs[_0xd793('0x34')](_0x5984ce['query'][_0xd793('0x34')]);}_0xb3337a['order']=qs[_0xd793('0x55')](_0x5984ce[_0xd793('0x4a')][_0xd793('0x55')]);_0xb3337a[_0xd793('0x56')]=qs[_0xd793('0x4c')](_['pick'](_0x5984ce[_0xd793('0x4a')],_0x1db24a[_0xd793('0x4c')]));_0xb3337a[_0xd793('0x56')][_0xd793('0x70')]=_0x101084['id'];if(_0x5984ce['query'][_0xd793('0x58')]){_0xb3337a[_0xd793('0x56')]=_[_0xd793('0x59')](_0xb3337a[_0xd793('0x56')],{'$or':_[_0xd793('0x46')](_0xb3337a[_0xd793('0x4f')],function(_0x289eb7){var _0x2d74fc={};_0x2d74fc[_0x289eb7]={'$like':'%'+_0x5984ce['query']['filter']+'%'};return _0x2d74fc;})});}_0xb3337a=_[_0xd793('0x59')]({},_0xb3337a,_0x5984ce[_0xd793('0x5b')]);return db['OpenchannelInteraction'][_0xd793('0x33')]({'where':_0xb3337a[_0xd793('0x56')]})['then'](function(_0x5ba5a1){_0x39a1fc['count']=_0x5ba5a1;if(_0x5984ce['query'][_0xd793('0x61')]){_0xb3337a[_0xd793('0x62')]=[{'model':db[_0xd793('0x8a')],'as':_0xd793('0xb2'),'required':![]},{'model':db[_0xd793('0xa4')],'as':_0xd793('0xb3'),'attributes':[_0xd793('0x41'),_0xd793('0xb4'),_0xd793('0xb5')],'required':![]},{'model':db[_0xd793('0xb6')],'as':_0xd793('0xb7'),'attributes':['id',_0xd793('0x41'),_0xd793('0xb8')],'where':_0x5984ce['query'][_0xd793('0xb9')]?{'id':_0x5984ce[_0xd793('0x4a')][_0xd793('0xb9')]}:undefined,'required':_0x5984ce[_0xd793('0x4a')]['tag']?!![]:![]}];}return db[_0xd793('0x97')][_0xd793('0x5d')](_0xb3337a);})[_0xd793('0x24')](function(_0x42f37a){_0x39a1fc[_0xd793('0x5e')]=_0x42f37a;return _0x39a1fc;});}})[_0xd793('0x24')](respondWithFilteredResult(_0x114d82,_0xb3337a))[_0xd793('0x2f')](handleError(_0x114d82,null));};exports[_0xd793('0xba')]=function(_0x467fb7,_0x300349,_0x42fe62){return db[_0xd793('0x5c')][_0xd793('0x63')]({'where':{'id':_0x467fb7[_0xd793('0x5f')]['id']}})['then'](handleEntityNotFound(_0x300349,null))['then'](function(_0x28d5f6){if(_0x28d5f6){return _0x28d5f6['addAgents'](_0x467fb7['body']['ids'],_[_0xd793('0xbb')](_0x467fb7['body'],[_0xd793('0x75'),'id'])||{})[_0xd793('0x99')](function(_0x1490d9){for(var _0x16d62d=0x0;_0x16d62d<_0x467fb7[_0xd793('0x6d')][_0xd793('0x75')][_0xd793('0x51')];_0x16d62d+=0x1){socket[_0xd793('0xbc')](_0xd793('0xbd'),{'UserId':_0x467fb7[_0xd793('0x6d')][_0xd793('0x75')][_0x16d62d],'OpenchannelAccountId':_0x467fb7[_0xd793('0x5f')]['id']});}return _0x1490d9;});}})[_0xd793('0x24')](respondWithResult(_0x300349,null))['catch'](handleError(_0x300349,null));};exports[_0xd793('0xbe')]=function(_0x17fe4b,_0x459ca4,_0x548b1c){return db[_0xd793('0x5c')][_0xd793('0x63')]({'where':{'id':_0x17fe4b[_0xd793('0x5f')]['id']}})[_0xd793('0x24')](handleEntityNotFound(_0x459ca4,null))['then'](function(_0x11c78f){if(_0x11c78f){return _0x11c78f[_0xd793('0xbe')](_0x17fe4b['query'][_0xd793('0x75')])[_0xd793('0x24')](function(){if(_[_0xd793('0xbf')](_0x17fe4b['query'][_0xd793('0x75')])){for(var _0x2b52ec=0x0;_0x2b52ec<_0x17fe4b[_0xd793('0x4a')][_0xd793('0x75')][_0xd793('0x51')];_0x2b52ec+=0x1){socket[_0xd793('0xbc')](_0xd793('0xc0'),{'UserId':Number(_0x17fe4b[_0xd793('0x4a')][_0xd793('0x75')][_0x2b52ec]),'OpenchannelAccountId':Number(_0x17fe4b['params']['id'])});}}else{socket[_0xd793('0xbc')]('userOpenchannelAccount:remove',{'UserId':Number(_0x17fe4b['query'][_0xd793('0x75')]),'OpenchannelAccountId':Number(_0x17fe4b[_0xd793('0x5f')]['id'])});}});}})[_0xd793('0x24')](respondWithStatusCode(_0x459ca4,null))[_0xd793('0x2f')](handleError(_0x459ca4,null));};exports[_0xd793('0xc1')]=function(_0x5003da,_0x4de971,_0x258974){var _0x130f30={};var _0x11389b={};var _0x21bdc7;var _0x4b8393;return db[_0xd793('0x5c')]['findOne']({'where':{'id':_0x5003da[_0xd793('0x5f')]['id']}})[_0xd793('0x24')](handleEntityNotFound(_0x4de971,null))[_0xd793('0x24')](function(_0x12cb6b){if(_0x12cb6b){_0x21bdc7=_0x12cb6b;_0x11389b[_0xd793('0x4e')]=_['keys'](db[_0xd793('0xa4')][_0xd793('0x60')]);_0x11389b['query']=_[_0xd793('0x4b')](_0x5003da[_0xd793('0x4a')]);_0x11389b['filters']=_[_0xd793('0x4d')](_0x11389b[_0xd793('0x4e')],_0x11389b[_0xd793('0x4a')]);_0x130f30[_0xd793('0x4f')]=_[_0xd793('0x4d')](_0x11389b[_0xd793('0x4e')],qs[_0xd793('0x50')](_0x5003da[_0xd793('0x4a')][_0xd793('0x50')]));_0x130f30['attributes']=_0x130f30[_0xd793('0x4f')][_0xd793('0x51')]?_0x130f30[_0xd793('0x4f')]:_0x11389b[_0xd793('0x4e')];_0x130f30[_0xd793('0x54')]=qs[_0xd793('0x55')](_0x5003da[_0xd793('0x4a')][_0xd793('0x55')]);_0x130f30[_0xd793('0x56')]=qs[_0xd793('0x4c')](_[_0xd793('0x57')](_0x5003da[_0xd793('0x4a')],_0x11389b[_0xd793('0x4c')]));if(_0x5003da[_0xd793('0x4a')][_0xd793('0x58')]){_0x130f30[_0xd793('0x56')]=_['merge'](_0x130f30[_0xd793('0x56')],{'$or':_[_0xd793('0x46')](_0x130f30[_0xd793('0x4f')],function(_0x43bafc){var _0x486a5c={};_0x486a5c[_0x43bafc]={'$like':'%'+_0x5003da['query'][_0xd793('0x58')]+'%'};return _0x486a5c;})});}_0x130f30=_[_0xd793('0x59')]({},_0x130f30,_0x5003da[_0xd793('0x5b')]);return _0x21bdc7['getAgents'](_0x130f30);}})['then'](function(_0x2ea849){if(_0x2ea849){_0x4b8393=_0x2ea849[_0xd793('0x51')];if(!_0x5003da['query'][_0xd793('0x52')]('nolimit')){_0x130f30['limit']=qs[_0xd793('0x35')](_0x5003da[_0xd793('0x4a')][_0xd793('0x35')]);_0x130f30[_0xd793('0x34')]=qs['offset'](_0x5003da['query'][_0xd793('0x34')]);}return _0x21bdc7[_0xd793('0xc1')](_0x130f30);}})[_0xd793('0x24')](function(_0x1acaa9){if(_0x1acaa9){return _0x1acaa9?{'count':_0x4b8393,'rows':_0x1acaa9}:null;}})[_0xd793('0x24')](respondWithResult(_0x4de971,null))[_0xd793('0x2f')](handleError(_0x4de971,null));};exports['send']=function(_0x31290f,_0x26c53c,_0x344128){var _0x36b58f,_0x277ee4,_0x3b9805;if(_[_0xd793('0x83')](_0x31290f[_0xd793('0x6d')][_0xd793('0x6d')])||_0x31290f[_0xd793('0x6d')][_0xd793('0x6d')]===''){throw new db['Sequelize']['ValidationError'](_0xd793('0x84'));}if(_['isNil'](_0x31290f[_0xd793('0x6d')]['to'])){}_0x36b58f=_0x31290f[_0xd793('0x6d')]['to'];return db[_0xd793('0x5c')][_0xd793('0x73')]({'where':{'id':_0x31290f[_0xd793('0x5f')]['id']}})['then'](handleEntityNotFound(_0x26c53c,null))['then'](function(_0x551d69){if(_0x551d69){return db[_0xd793('0x5c')][_0xd793('0x63')]({'where':{'id':_0x551d69['id']},'include':[{'model':db['CmList'],'as':_0xd793('0x89'),'include':[{'model':db['CmContact'],'as':_0xd793('0x8b'),'where':{[_0x551d69[_0xd793('0x85')]]:_0x36b58f},'limit':0x1,'order':[['updatedAt',_0xd793('0x8c')]]}]}]})[_0xd793('0x24')](handleEntityNotFound(_0x26c53c,null))[_0xd793('0x24')](function(_0x450dbf){if(_0x450dbf&&_0x450dbf[_0xd793('0x89')]){_0x277ee4=_0x450dbf[_0xd793('0x3c')]({'plain':!![]});if(_0x277ee4[_0xd793('0x89')]&&_0x277ee4[_0xd793('0x89')][_0xd793('0x8b')][_0xd793('0x51')]){return _0x277ee4[_0xd793('0x89')][_0xd793('0x8b')][0x0];}return db[_0xd793('0x8a')]['create'](_[_0xd793('0x1b')](_0x31290f['body'],{'firstName':_0x36b58f,[_0x450dbf[_0xd793('0x85')]]:_0x36b58f,'phone':_0x36b58f,'ListId':_0x277ee4['ListId']}));}})[_0xd793('0x24')](handleEntityNotFound(_0x26c53c,null))[_0xd793('0x24')](function(_0x432b09){if(_0x432b09){_0x3b9805=_0x432b09;return db['OpenchannelInteraction'][_0xd793('0x63')]({'where':{'ContactId':_0x3b9805['id'],'closed':![],'OpenchannelAccountId':_0x277ee4['id']}})[_0xd793('0x24')](function(_0x2c3bdb){if(_0x2c3bdb){return[_0x2c3bdb,![]];}return db[_0xd793('0x97')][_0xd793('0x64')]({'UserId':_0x31290f['user']['id'],'ContactId':_0x3b9805['id'],'OpenchannelAccountId':_0x277ee4['id'],'lastMsgDirection':'out','Messages':[_[_0xd793('0x59')](_0x31290f['body'],{'read':![],'body':_0x31290f[_0xd793('0x6d')]['body'],'OpenchannelAccountId':_0x277ee4['id'],'UserId':_0x31290f[_0xd793('0x65')]['id'],'ContactId':_0x3b9805['id']})]},{'include':[{'model':db[_0xd793('0xa1')],'as':_0xd793('0xc2')}]})[_0xd793('0x24')](function(_0xdb74d2){return[_0xdb74d2,!![]];});});}})[_0xd793('0x99')](function(_0x440c5d,_0x315cd5){if(_0x315cd5){return _0x440c5d;}return db[_0xd793('0xa1')][_0xd793('0x64')](_[_0xd793('0x59')](_0x31290f['body'],{'read':![],'body':_0x31290f[_0xd793('0x6d')][_0xd793('0x6d')],'OpenchannelAccountId':_0x277ee4['id'],'OpenchannelInteractionId':_0x440c5d['id'],'UserId':_0x31290f[_0xd793('0x65')]['id'],'ContactId':_0x3b9805['id']}))['then'](function(_0x4b502e){_0x440c5d[_0xd793('0xc3')]['Messages']=[];_0x440c5d[_0xd793('0xc3')]['Messages']['push'](_0x4b502e[_0xd793('0xc3')]);return _0x440c5d;});});}})[_0xd793('0x24')](respondWithResult(_0x26c53c,null))['catch'](handleError(_0x26c53c,null));};
\ No newline at end of file
+var _0xf6c3=['map','OpenchannelAccount','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','nolimit','limit','order','sort','where','filter','VIRTUAL','merge','options','includeAll','include','findAll','catch','show','params','mandatoryDispositionPause','length','user','role','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','find','describe','addDisposition','OpenchannelAccountId','create','getDispositions','findOne','Disposition','hasOwnProperty','rows','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','CmContact','ValidationError','difference','createdAt','updatedAt','CompanyId','ListId','isNil','Sequelize','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','from','CmList','List','Contacts','DESC','Applications','account','list','applications','orderBy','priority','asc','defaults','contact','firstName','lastName','threadId','OpenchannelInteraction','externalUrl','spread','messageId','interaction','created','autoclose','push','close','unmanaged','OpenchannelMessage','AttachmentId','UserId','User','unshift','agent','*,*,*,*','forcedOwnership','Start','startRouting','EventManager','notify','addApplications','transaction','OpenchannelApplication','findAndCountAll','getApplications','pick','Owner','Tag','Tags','color','tag','addAgents','omit','emit','userOpenchannelAccount:save','removeAgents','isArray','userOpenchannelAccount:remove','getAgents','Messages','dataValues','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/license/util','redis','localhost','socket.io-emitter','./openchannelAccount.socket','register','jayson/promise','client','http','request','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','debug','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','result','sendStatus','status','end','count','offset','Content-Range','json','apply','reject','save','update','destroy','get','OpenchannelAccounts','UserProfileResource','then','stack','name','send','Pause'];(function(_0x37512d,_0x44495e){var _0x133f49=function(_0x10b685){while(--_0x10b685){_0x37512d['push'](_0x37512d['shift']());}};_0x133f49(++_0x44495e);}(_0xf6c3,0x13d));var _0x3f6c=function(_0x46cba9,_0x4707af){_0x46cba9=_0x46cba9-0x0;var _0xd65e51=_0xf6c3[_0x46cba9];return _0xd65e51;};'use strict';var emlformat=require(_0x3f6c('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x3f6c('0x1'));var jsonpatch=require(_0x3f6c('0x2'));var rp=require(_0x3f6c('0x3'));var moment=require('moment');var BPromise=require(_0x3f6c('0x4'));var Mustache=require(_0x3f6c('0x5'));var util=require(_0x3f6c('0x6'));var path=require(_0x3f6c('0x7'));var sox=require(_0x3f6c('0x8'));var csv=require(_0x3f6c('0x9'));var ejs=require(_0x3f6c('0xa'));var fs=require('fs');var fs_extra=require(_0x3f6c('0xb'));var _=require(_0x3f6c('0xc'));var squel=require(_0x3f6c('0xd'));var crypto=require(_0x3f6c('0xe'));var jsforce=require(_0x3f6c('0xf'));var deskjs=require(_0x3f6c('0x10'));var toCsv=require(_0x3f6c('0x9'));var querystring=require(_0x3f6c('0x11'));var Papa=require(_0x3f6c('0x12'));var Redis=require(_0x3f6c('0x13'));var authService=require(_0x3f6c('0x14'));var qs=require(_0x3f6c('0x15'));var as=require(_0x3f6c('0x16'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x3f6c('0x17'));var utils=require(_0x3f6c('0x18'));var config=require('../../config/environment');var licenseUtil=require(_0x3f6c('0x19'));var db=require('../../mysqldb')['db'];config[_0x3f6c('0x1a')]=_['defaults'](config[_0x3f6c('0x1a')],{'host':_0x3f6c('0x1b'),'port':0x18eb});var socket=require(_0x3f6c('0x1c'))(new Redis(config[_0x3f6c('0x1a')]));require(_0x3f6c('0x1d'))[_0x3f6c('0x1e')](socket);var jayson=require(_0x3f6c('0x1f'));var client=jayson[_0x3f6c('0x20')][_0x3f6c('0x21')]({'port':0x232c});var client9002=jayson[_0x3f6c('0x20')]['http']({'port':0x232a});function respondWithRpcPromise(_0x395fe0,_0x5b2fc2,_0x3e1b9f,_0x3e866b){return new BPromise(function(_0x134021,_0x350485){var _0x160c91=_0x3e866b||client;return _0x160c91[_0x3f6c('0x22')](_0x395fe0,_0x3e1b9f)['then'](function(_0x2af57c){logger['info'](_0x3f6c('0x23'),_0x5b2fc2,_0x3f6c('0x24'));logger[_0x3f6c('0x25')](_0x3f6c('0x26'),_0x5b2fc2,_0x3f6c('0x24'),JSON[_0x3f6c('0x27')](_0x2af57c));if(_0x2af57c[_0x3f6c('0x28')]){if(_0x2af57c[_0x3f6c('0x28')][_0x3f6c('0x29')]===0x1f4){logger[_0x3f6c('0x28')]('OpenchannelAccount,\x20%s,\x20%s',_0x5b2fc2,_0x2af57c[_0x3f6c('0x28')]['message']);return _0x350485(_0x2af57c[_0x3f6c('0x28')][_0x3f6c('0x2a')]);}logger[_0x3f6c('0x28')](_0x3f6c('0x23'),_0x5b2fc2,_0x2af57c[_0x3f6c('0x28')]['message']);return _0x134021(_0x2af57c[_0x3f6c('0x28')][_0x3f6c('0x2a')]);}else{logger[_0x3f6c('0x2b')]('OpenchannelAccount,\x20%s,\x20%s',_0x5b2fc2,'request\x20sent');_0x134021(_0x2af57c[_0x3f6c('0x2c')][_0x3f6c('0x2a')]);}})['catch'](function(_0x31c5f8){logger['error'](_0x3f6c('0x23'),_0x5b2fc2,_0x31c5f8);_0x350485(_0x31c5f8);});});}function respondWithStatusCode(_0x1c2b8b,_0x229354){_0x229354=_0x229354||0xcc;return function(_0x108b72){if(_0x108b72){return _0x1c2b8b[_0x3f6c('0x2d')](_0x229354);}return _0x1c2b8b[_0x3f6c('0x2e')](_0x229354)[_0x3f6c('0x2f')]();};}function respondWithResult(_0x17859c,_0x17643e){_0x17643e=_0x17643e||0xc8;return function(_0x184afe){if(_0x184afe){return _0x17859c[_0x3f6c('0x2e')](_0x17643e)['json'](_0x184afe);}};}function respondWithFilteredResult(_0xe80094,_0x4bb084){return function(_0xe00b93){if(_0xe00b93){var _0x2fea6c=_0xe00b93[_0x3f6c('0x30')],_0x445f2f=_0x4bb084['offset'],_0x540283=_0x4bb084[_0x3f6c('0x31')]+_0x4bb084['limit'],_0x25f1c1;if(_0x540283>=_0x2fea6c){_0x540283=_0x2fea6c;_0x25f1c1=0xc8;}else{_0x25f1c1=0xce;}_0xe80094[_0x3f6c('0x2e')](_0x25f1c1);return _0xe80094['set'](_0x3f6c('0x32'),_0x445f2f+'-'+_0x540283+'/'+_0x2fea6c)[_0x3f6c('0x33')](_0xe00b93);}return null;};}function patchUpdates(_0x255cb0){return function(_0x377754){try{jsonpatch[_0x3f6c('0x34')](_0x377754,_0x255cb0,!![]);}catch(_0x3f6050){return BPromise[_0x3f6c('0x35')](_0x3f6050);}return _0x377754[_0x3f6c('0x36')]();};}function saveUpdates(_0x2e8174,_0x5bacf9){return function(_0x1a9d97){if(_0x1a9d97){return _0x1a9d97[_0x3f6c('0x37')](_0x2e8174)['then'](function(_0x566a2b){return _0x566a2b;});}return null;};}function removeEntity(_0x422b98,_0x1978d4){return function(_0xe0b4b){if(_0xe0b4b){return _0xe0b4b[_0x3f6c('0x38')]()['then'](function(){var _0x502bee=_0xe0b4b[_0x3f6c('0x39')]({'plain':!![]});var _0x58b64e=_0x3f6c('0x3a');return db[_0x3f6c('0x3b')]['destroy']({'where':{'type':_0x58b64e,'resourceId':_0x502bee['id']}})[_0x3f6c('0x3c')](function(){return _0xe0b4b;});})['then'](function(){_0x422b98[_0x3f6c('0x2e')](0xcc)[_0x3f6c('0x2f')]();});}};}function handleEntityNotFound(_0x3edaec,_0x563f50){return function(_0x1f3b7d){if(!_0x1f3b7d){_0x3edaec[_0x3f6c('0x2d')](0x194);}return _0x1f3b7d;};}function handleError(_0x545aeb,_0x381609){_0x381609=_0x381609||0x1f4;return function(_0x34ec29){logger[_0x3f6c('0x28')](_0x34ec29[_0x3f6c('0x3d')]);if(_0x34ec29[_0x3f6c('0x3e')]){delete _0x34ec29[_0x3f6c('0x3e')];}_0x545aeb[_0x3f6c('0x2e')](_0x381609)[_0x3f6c('0x3f')](_0x34ec29);};}exports['index']=function(_0x777a8d,_0x39dbaa){var _0x19f081={'include':[{'model':db[_0x3f6c('0x40')],'as':'mandatoryDispositionPause'}]},_0x3d4c87={},_0x1c0d04={'count':0x0,'rows':[]};var _0x4adcb3=_[_0x3f6c('0x41')](db[_0x3f6c('0x42')][_0x3f6c('0x43')],function(_0x5345d3){return{'name':_0x5345d3[_0x3f6c('0x44')],'type':_0x5345d3[_0x3f6c('0x45')][_0x3f6c('0x46')]};});_0x3d4c87[_0x3f6c('0x47')]=_[_0x3f6c('0x41')](_0x4adcb3,_0x3f6c('0x3e'));_0x3d4c87[_0x3f6c('0x48')]=_[_0x3f6c('0x49')](_0x777a8d['query']);_0x3d4c87[_0x3f6c('0x4a')]=_[_0x3f6c('0x4b')](_0x3d4c87['model'],_0x3d4c87['query']);_0x19f081[_0x3f6c('0x4c')]=_[_0x3f6c('0x4b')](_0x3d4c87[_0x3f6c('0x47')],qs[_0x3f6c('0x4d')](_0x777a8d[_0x3f6c('0x48')][_0x3f6c('0x4d')]));_0x19f081[_0x3f6c('0x4c')]=_0x19f081[_0x3f6c('0x4c')]['length']?_0x19f081[_0x3f6c('0x4c')]:_0x3d4c87['model'];if(!_0x777a8d[_0x3f6c('0x48')]['hasOwnProperty'](_0x3f6c('0x4e'))){_0x19f081['limit']=qs[_0x3f6c('0x4f')](_0x777a8d[_0x3f6c('0x48')]['limit']);_0x19f081[_0x3f6c('0x31')]=qs['offset'](_0x777a8d[_0x3f6c('0x48')][_0x3f6c('0x31')]);}_0x19f081[_0x3f6c('0x50')]=qs['sort'](_0x777a8d[_0x3f6c('0x48')][_0x3f6c('0x51')]);_0x19f081[_0x3f6c('0x52')]=qs[_0x3f6c('0x4a')](_['pick'](_0x777a8d[_0x3f6c('0x48')],_0x3d4c87[_0x3f6c('0x4a')]),_0x4adcb3);if(_0x777a8d[_0x3f6c('0x48')][_0x3f6c('0x53')]){_0x19f081['where']=_['merge'](_0x19f081[_0x3f6c('0x52')],{'$or':_[_0x3f6c('0x41')](_0x4adcb3,function(_0x13131a){if(_0x13131a[_0x3f6c('0x45')]!==_0x3f6c('0x54')){var _0x5bb281={};_0x5bb281[_0x13131a['name']]={'$like':'%'+_0x777a8d[_0x3f6c('0x48')][_0x3f6c('0x53')]+'%'};return _0x5bb281;}})});}_0x19f081=_[_0x3f6c('0x55')]({},_0x19f081,_0x777a8d[_0x3f6c('0x56')]);var _0x30b270={'where':_0x19f081[_0x3f6c('0x52')]};return db['OpenchannelAccount'][_0x3f6c('0x30')](_0x30b270)[_0x3f6c('0x3c')](function(_0x6e16ac){_0x1c0d04[_0x3f6c('0x30')]=_0x6e16ac;if(_0x777a8d[_0x3f6c('0x48')][_0x3f6c('0x57')]){_0x19f081[_0x3f6c('0x58')]=[{'all':!![]}];}return db[_0x3f6c('0x42')][_0x3f6c('0x59')](_0x19f081);})['then'](function(_0x20b309){_0x1c0d04['rows']=_0x20b309;return _0x1c0d04;})['then'](respondWithFilteredResult(_0x39dbaa,_0x19f081))[_0x3f6c('0x5a')](handleError(_0x39dbaa,null));};exports[_0x3f6c('0x5b')]=function(_0x450ba3,_0x2c8d72){var _0x1abcfb={'raw':![],'where':{'id':_0x450ba3[_0x3f6c('0x5c')]['id']},'include':[{'model':db['Pause'],'as':_0x3f6c('0x5d')}]},_0x1191ca={};_0x1191ca[_0x3f6c('0x47')]=_[_0x3f6c('0x49')](db[_0x3f6c('0x42')][_0x3f6c('0x43')]);_0x1191ca[_0x3f6c('0x48')]=_[_0x3f6c('0x49')](_0x450ba3[_0x3f6c('0x48')]);_0x1191ca['filters']=_[_0x3f6c('0x4b')](_0x1191ca[_0x3f6c('0x47')],_0x1191ca[_0x3f6c('0x48')]);_0x1abcfb['attributes']=_[_0x3f6c('0x4b')](_0x1191ca['model'],qs[_0x3f6c('0x4d')](_0x450ba3[_0x3f6c('0x48')][_0x3f6c('0x4d')]));_0x1abcfb[_0x3f6c('0x4c')]=_0x1abcfb[_0x3f6c('0x4c')][_0x3f6c('0x5e')]?_0x1abcfb[_0x3f6c('0x4c')]:_0x1191ca['model'];if(_0x450ba3[_0x3f6c('0x48')][_0x3f6c('0x57')]){_0x1abcfb[_0x3f6c('0x58')]=[{'all':!![]}];}_0x1abcfb=_['merge']({},_0x1abcfb,_0x450ba3[_0x3f6c('0x56')]);return db[_0x3f6c('0x42')]['find'](_0x1abcfb)[_0x3f6c('0x3c')](handleEntityNotFound(_0x2c8d72,null))[_0x3f6c('0x3c')](respondWithResult(_0x2c8d72,null))[_0x3f6c('0x5a')](handleError(_0x2c8d72,null));};exports['create']=function(_0x45b539,_0x145bdb){return db[_0x3f6c('0x42')]['create'](_0x45b539['body'],{})[_0x3f6c('0x3c')](function(_0x1f7969){var _0x20e128=_0x45b539[_0x3f6c('0x5f')]['get']({'plain':!![]});if(!_0x20e128)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x20e128[_0x3f6c('0x60')]===_0x3f6c('0x5f')){var _0xf5eae7=_0x1f7969[_0x3f6c('0x39')]({'plain':!![]});var _0x4f863f='OpenchannelAccounts';return db[_0x3f6c('0x61')]['find']({'where':{'name':_0x4f863f,'userProfileId':_0x20e128['userProfileId']},'raw':!![]})[_0x3f6c('0x3c')](function(_0x5ace69){if(_0x5ace69&&_0x5ace69[_0x3f6c('0x62')]===0x0){return db[_0x3f6c('0x3b')]['create']({'name':_0xf5eae7[_0x3f6c('0x3e')],'resourceId':_0xf5eae7['id'],'type':_0x5ace69[_0x3f6c('0x3e')],'sectionId':_0x5ace69['id']},{})[_0x3f6c('0x3c')](function(){return _0x1f7969;});}else{return _0x1f7969;}})[_0x3f6c('0x5a')](function(_0x531e2f){logger[_0x3f6c('0x28')](_0x3f6c('0x63'),_0x531e2f);throw _0x531e2f;});}return _0x1f7969;})[_0x3f6c('0x3c')](respondWithResult(_0x145bdb,0xc9))[_0x3f6c('0x5a')](handleError(_0x145bdb,null));};exports[_0x3f6c('0x37')]=function(_0x191615,_0x133e64){if(_0x191615[_0x3f6c('0x64')]['id']){delete _0x191615['body']['id'];}return db[_0x3f6c('0x42')][_0x3f6c('0x65')]({'where':{'id':_0x191615['params']['id']},'include':[{'model':db[_0x3f6c('0x40')],'as':_0x3f6c('0x5d')}]})[_0x3f6c('0x3c')](handleEntityNotFound(_0x133e64,null))[_0x3f6c('0x3c')](saveUpdates(_0x191615[_0x3f6c('0x64')],null))['then'](respondWithResult(_0x133e64,null))['catch'](handleError(_0x133e64,null));};exports[_0x3f6c('0x38')]=function(_0x341a57,_0x58a940){return db[_0x3f6c('0x42')][_0x3f6c('0x65')]({'where':{'id':_0x341a57[_0x3f6c('0x5c')]['id']}})[_0x3f6c('0x3c')](handleEntityNotFound(_0x58a940,null))[_0x3f6c('0x3c')](removeEntity(_0x58a940,null))[_0x3f6c('0x5a')](handleError(_0x58a940,null));};exports['describe']=function(_0x1b8972,_0x4385ea){return db[_0x3f6c('0x42')][_0x3f6c('0x66')]()['then'](respondWithResult(_0x4385ea,null))[_0x3f6c('0x5a')](handleError(_0x4385ea,null));};exports[_0x3f6c('0x67')]=function(_0x474505,_0x14e141,_0x4a7e7b){if(_0x474505['body']['id']){delete _0x474505[_0x3f6c('0x64')]['id'];}return db['OpenchannelAccount']['find']({'where':{'id':_0x474505[_0x3f6c('0x5c')]['id']}})['then'](handleEntityNotFound(_0x14e141,null))[_0x3f6c('0x3c')](function(_0x52529b){if(_0x52529b){_0x474505['body'][_0x3f6c('0x68')]=_0x52529b['id'];return db['Disposition'][_0x3f6c('0x69')](_0x474505[_0x3f6c('0x64')]);}})['then'](respondWithResult(_0x14e141,null))[_0x3f6c('0x5a')](handleError(_0x14e141,null));};exports[_0x3f6c('0x6a')]=function(_0x5aefd2,_0x193097,_0x47aa44){var _0x1c7294={'raw':![],'where':{}};var _0x6e3c30={};var _0x3ad1={'count':0x0,'rows':[]};return db[_0x3f6c('0x42')][_0x3f6c('0x6b')]({'where':{'id':_0x5aefd2[_0x3f6c('0x5c')]['id']}})['then'](handleEntityNotFound(_0x193097,null))['then'](function(_0x9aac07){if(_0x9aac07){_0x6e3c30['model']=_['keys'](db[_0x3f6c('0x6c')]['rawAttributes']);_0x6e3c30[_0x3f6c('0x48')]=_[_0x3f6c('0x49')](_0x5aefd2['query']);_0x6e3c30[_0x3f6c('0x4a')]=_['intersection'](_0x6e3c30[_0x3f6c('0x47')],_0x6e3c30['query']);_0x1c7294[_0x3f6c('0x4c')]=_[_0x3f6c('0x4b')](_0x6e3c30[_0x3f6c('0x47')],qs[_0x3f6c('0x4d')](_0x5aefd2[_0x3f6c('0x48')][_0x3f6c('0x4d')]));_0x1c7294[_0x3f6c('0x4c')]=_0x1c7294[_0x3f6c('0x4c')][_0x3f6c('0x5e')]?_0x1c7294[_0x3f6c('0x4c')]:_0x6e3c30['model'];if(!_0x5aefd2[_0x3f6c('0x48')][_0x3f6c('0x6d')](_0x3f6c('0x4e'))){_0x1c7294[_0x3f6c('0x4f')]=qs['limit'](_0x5aefd2[_0x3f6c('0x48')][_0x3f6c('0x4f')]);_0x1c7294[_0x3f6c('0x31')]=qs[_0x3f6c('0x31')](_0x5aefd2[_0x3f6c('0x48')][_0x3f6c('0x31')]);}_0x1c7294[_0x3f6c('0x50')]=qs['sort'](_0x5aefd2[_0x3f6c('0x48')][_0x3f6c('0x51')]);_0x1c7294[_0x3f6c('0x52')]=qs['filters'](_['pick'](_0x5aefd2['query'],_0x6e3c30[_0x3f6c('0x4a')]));_0x1c7294[_0x3f6c('0x52')]['OpenchannelAccountId']=_0x9aac07['id'];if(_0x5aefd2[_0x3f6c('0x48')][_0x3f6c('0x53')]){_0x1c7294[_0x3f6c('0x52')]=_['merge'](_0x1c7294['where'],{'$or':_[_0x3f6c('0x41')](_0x1c7294[_0x3f6c('0x4c')],function(_0x434602){var _0x57ec37={};_0x57ec37[_0x434602]={'$like':'%'+_0x5aefd2[_0x3f6c('0x48')][_0x3f6c('0x53')]+'%'};return _0x57ec37;})});}_0x1c7294=_[_0x3f6c('0x55')]({},_0x1c7294,_0x5aefd2[_0x3f6c('0x56')]);return db['Disposition'][_0x3f6c('0x30')]({'where':_0x1c7294[_0x3f6c('0x52')]})['then'](function(_0x31974d){_0x3ad1['count']=_0x31974d;if(_0x5aefd2[_0x3f6c('0x48')]['includeAll']){_0x1c7294[_0x3f6c('0x58')]=[{'all':!![]}];}return db[_0x3f6c('0x6c')][_0x3f6c('0x59')](_0x1c7294);})['then'](function(_0x74e9bd){_0x3ad1[_0x3f6c('0x6e')]=_0x74e9bd;return _0x3ad1;});}})[_0x3f6c('0x3c')](respondWithFilteredResult(_0x193097,_0x1c7294))[_0x3f6c('0x5a')](handleError(_0x193097,null));};exports[_0x3f6c('0x6f')]=function(_0x109aa4,_0x443dc9,_0x906af2){return db['OpenchannelAccount'][_0x3f6c('0x65')]({'where':{'id':_0x109aa4[_0x3f6c('0x5c')]['id']}})[_0x3f6c('0x3c')](handleEntityNotFound(_0x443dc9,null))[_0x3f6c('0x3c')](function(_0x3413f4){if(_0x3413f4){return _0x3413f4['removeDispositions'](_0x109aa4[_0x3f6c('0x48')][_0x3f6c('0x70')]);}})['then'](respondWithStatusCode(_0x443dc9,null))[_0x3f6c('0x5a')](handleError(_0x443dc9,null));};exports[_0x3f6c('0x71')]=function(_0x415135,_0x259b83,_0xf4cb9d){if(_0x415135[_0x3f6c('0x64')]['id']){delete _0x415135[_0x3f6c('0x64')]['id'];}return db['OpenchannelAccount'][_0x3f6c('0x65')]({'where':{'id':_0x415135[_0x3f6c('0x5c')]['id']}})['then'](handleEntityNotFound(_0x259b83,null))[_0x3f6c('0x3c')](function(_0x312f5a){if(_0x312f5a){_0x415135['body'][_0x3f6c('0x68')]=_0x312f5a['id'];return db[_0x3f6c('0x72')][_0x3f6c('0x69')](_0x415135[_0x3f6c('0x64')]);}})[_0x3f6c('0x3c')](respondWithResult(_0x259b83,null))[_0x3f6c('0x5a')](handleError(_0x259b83,null));};exports[_0x3f6c('0x73')]=function(_0x371bb8,_0x56d1a7,_0x7b07ad){var _0x78fa56={'raw':![],'where':{}};var _0x3f4713={};var _0x29ae6e={'count':0x0,'rows':[]};return db[_0x3f6c('0x42')][_0x3f6c('0x6b')]({'where':{'id':_0x371bb8[_0x3f6c('0x5c')]['id']}})[_0x3f6c('0x3c')](handleEntityNotFound(_0x56d1a7,null))[_0x3f6c('0x3c')](function(_0x2eb4ad){if(_0x2eb4ad){_0x3f4713[_0x3f6c('0x47')]=_['keys'](db[_0x3f6c('0x72')][_0x3f6c('0x43')]);_0x3f4713[_0x3f6c('0x48')]=_[_0x3f6c('0x49')](_0x371bb8['query']);_0x3f4713['filters']=_['intersection'](_0x3f4713[_0x3f6c('0x47')],_0x3f4713[_0x3f6c('0x48')]);_0x78fa56[_0x3f6c('0x4c')]=_[_0x3f6c('0x4b')](_0x3f4713['model'],qs['fields'](_0x371bb8['query'][_0x3f6c('0x4d')]));_0x78fa56['attributes']=_0x78fa56[_0x3f6c('0x4c')][_0x3f6c('0x5e')]?_0x78fa56[_0x3f6c('0x4c')]:_0x3f4713[_0x3f6c('0x47')];if(!_0x371bb8[_0x3f6c('0x48')]['hasOwnProperty']('nolimit')){_0x78fa56[_0x3f6c('0x4f')]=qs['limit'](_0x371bb8[_0x3f6c('0x48')][_0x3f6c('0x4f')]);_0x78fa56[_0x3f6c('0x31')]=qs[_0x3f6c('0x31')](_0x371bb8[_0x3f6c('0x48')][_0x3f6c('0x31')]);}_0x78fa56[_0x3f6c('0x50')]=qs[_0x3f6c('0x51')](_0x371bb8[_0x3f6c('0x48')]['sort']);_0x78fa56[_0x3f6c('0x52')]=qs[_0x3f6c('0x4a')](_['pick'](_0x371bb8[_0x3f6c('0x48')],_0x3f4713['filters']));_0x78fa56['where'][_0x3f6c('0x68')]=_0x2eb4ad['id'];if(_0x371bb8[_0x3f6c('0x48')]['filter']){_0x78fa56[_0x3f6c('0x52')]=_[_0x3f6c('0x55')](_0x78fa56[_0x3f6c('0x52')],{'$or':_[_0x3f6c('0x41')](_0x78fa56[_0x3f6c('0x4c')],function(_0x479921){var _0x2fadc6={};_0x2fadc6[_0x479921]={'$like':'%'+_0x371bb8['query'][_0x3f6c('0x53')]+'%'};return _0x2fadc6;})});}_0x78fa56=_['merge']({},_0x78fa56,_0x371bb8['options']);return db['CannedAnswer'][_0x3f6c('0x30')]({'where':_0x78fa56[_0x3f6c('0x52')]})[_0x3f6c('0x3c')](function(_0x47fe52){_0x29ae6e['count']=_0x47fe52;if(_0x371bb8[_0x3f6c('0x48')][_0x3f6c('0x57')]){_0x78fa56[_0x3f6c('0x58')]=[{'all':!![]}];}return db[_0x3f6c('0x72')][_0x3f6c('0x59')](_0x78fa56);})[_0x3f6c('0x3c')](function(_0x1a02d9){_0x29ae6e[_0x3f6c('0x6e')]=_0x1a02d9;return _0x29ae6e;});}})[_0x3f6c('0x3c')](respondWithFilteredResult(_0x56d1a7,_0x78fa56))[_0x3f6c('0x5a')](handleError(_0x56d1a7,null));};exports[_0x3f6c('0x74')]=function(_0x2a5e60,_0x5cd6d1,_0x1ea24a){return db[_0x3f6c('0x42')][_0x3f6c('0x65')]({'where':{'id':_0x2a5e60[_0x3f6c('0x5c')]['id']}})[_0x3f6c('0x3c')](handleEntityNotFound(_0x5cd6d1,null))[_0x3f6c('0x3c')](function(_0x5f2684){if(_0x5f2684){return _0x5f2684[_0x3f6c('0x74')](_0x2a5e60[_0x3f6c('0x48')]['ids']);}})[_0x3f6c('0x3c')](respondWithStatusCode(_0x5cd6d1,null))[_0x3f6c('0x5a')](handleError(_0x5cd6d1,null));};exports['notify']=function(_0x297fc3,_0x57d9db,_0x163c1b){var _0x46a103={'body':_0x297fc3[_0x3f6c('0x64')],'channel':'openchannel'};var _0x17b154=[];var _0x54d4b5=[];var _0x14d6d2={};var _0x7e8eee=![];return db[_0x3f6c('0x75')][_0x3f6c('0x66')]()[_0x3f6c('0x3c')](function(_0x415656){if(!_0x415656){throw new db['Sequelize'][(_0x3f6c('0x76'))]('no\x20available\x20attributes');}_0x17b154=_[_0x3f6c('0x77')](_[_0x3f6c('0x49')](_0x415656),['createdAt','updatedAt']);_0x54d4b5=_[_0x3f6c('0x77')](_[_0x3f6c('0x49')](_0x415656),[_0x3f6c('0x78'),_0x3f6c('0x79'),_0x3f6c('0x7a'),_0x3f6c('0x7b')]);if(_0x297fc3[_0x3f6c('0x64')]['id']){delete _0x297fc3[_0x3f6c('0x64')]['id'];}if(_[_0x3f6c('0x7c')](_0x297fc3['body']['from'])){throw new db[(_0x3f6c('0x7d'))][(_0x3f6c('0x76'))](_0x3f6c('0x7e'));}if(_[_0x3f6c('0x7c')](_0x297fc3[_0x3f6c('0x64')]['body'])||_0x297fc3[_0x3f6c('0x64')][_0x3f6c('0x64')]===''){throw new db[(_0x3f6c('0x7d'))]['ValidationError'](_0x3f6c('0x7f'));}if(_[_0x3f6c('0x7c')](_0x297fc3['body'][_0x3f6c('0x80')])){throw new db[(_0x3f6c('0x7d'))]['ValidationError']('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x54d4b5);}if(!_[_0x3f6c('0x81')](_0x54d4b5,_0x297fc3[_0x3f6c('0x64')][_0x3f6c('0x80')])){throw new db[(_0x3f6c('0x7d'))][(_0x3f6c('0x76'))](_0x3f6c('0x82')+_0x54d4b5);}_0x14d6d2[_0x297fc3['body']['mapKey']]=_0x297fc3[_0x3f6c('0x64')][_0x3f6c('0x83')];})[_0x3f6c('0x3c')](function(){return db[_0x3f6c('0x42')][_0x3f6c('0x65')]({'where':{'id':_0x297fc3[_0x3f6c('0x5c')]['id']},'include':[{'model':db[_0x3f6c('0x84')],'as':_0x3f6c('0x85'),'include':[{'model':db[_0x3f6c('0x75')],'as':_0x3f6c('0x86'),'where':_0x14d6d2,'limit':0x1,'order':[['updatedAt',_0x3f6c('0x87')]]}]},{'model':db['OpenchannelApplication'],'as':_0x3f6c('0x88')}]});})[_0x3f6c('0x3c')](handleEntityNotFound(_0x57d9db,null))[_0x3f6c('0x3c')](function(_0x42d4d1){if(_0x42d4d1&&_0x42d4d1[_0x3f6c('0x85')]){_0x46a103[_0x3f6c('0x89')]=_0x42d4d1;_0x46a103['applications']=_0x42d4d1['Applications'];_0x46a103[_0x3f6c('0x8a')]=_0x42d4d1['List'];_0x46a103[_0x3f6c('0x8b')]=_[_0x3f6c('0x8c')](_0x46a103[_0x3f6c('0x8b')],[_0x3f6c('0x8d')],[_0x3f6c('0x8e')]);if(_0x46a103[_0x3f6c('0x89')][_0x3f6c('0x88')]){delete _0x46a103[_0x3f6c('0x89')][_0x3f6c('0x88')];}if(_0x46a103[_0x3f6c('0x89')][_0x3f6c('0x85')]&&_0x46a103[_0x3f6c('0x89')]['List'][_0x3f6c('0x86')][_0x3f6c('0x5e')]){return _0x46a103[_0x3f6c('0x89')][_0x3f6c('0x85')][_0x3f6c('0x86')][0x0];}var _0x1b0111=_[_0x3f6c('0x8f')](_0x297fc3[_0x3f6c('0x64')],{'firstName':_0x297fc3['body']['from'],'ListId':_0x42d4d1['ListId']});_0x1b0111[_0x297fc3['body']['mapKey']]=_0x297fc3[_0x3f6c('0x64')][_0x3f6c('0x83')];return db['CmContact'][_0x3f6c('0x69')](_0x1b0111,{'fields':_0x17b154,'raw':!![]});}})[_0x3f6c('0x3c')](handleEntityNotFound(_0x57d9db,null))[_0x3f6c('0x3c')](function(_0x33719d){_0x46a103[_0x3f6c('0x90')]=_0x33719d;if(_0x33719d){var _0x4538ce={'ContactId':_0x33719d['id'],'OpenchannelAccountId':_0x297fc3[_0x3f6c('0x5c')]['id'],'from':(_0x33719d[_0x3f6c('0x91')]||'')+'\x20'+(_0x33719d[_0x3f6c('0x92')]||'')};var _0x2637b9={'OpenchannelAccountId':_0x297fc3[_0x3f6c('0x5c')]['id'],'closed':![]};if(_0x297fc3['body'][_0x3f6c('0x93')]){_0x2637b9[_0x3f6c('0x93')]=_0x297fc3['body'][_0x3f6c('0x93')];return db[_0x3f6c('0x94')][_0x3f6c('0x65')]({'where':_0x2637b9})[_0x3f6c('0x3c')](function(_0x198ed9){if(_0x198ed9){return[_0x198ed9,![]];}_0x4538ce['threadId']=_0x297fc3[_0x3f6c('0x64')]['threadId'];_0x4538ce[_0x3f6c('0x95')]=_0x297fc3[_0x3f6c('0x64')][_0x3f6c('0x95')];return db[_0x3f6c('0x94')][_0x3f6c('0x69')](_0x4538ce)[_0x3f6c('0x3c')](function(_0x37590f){return[_0x37590f,!![]];});});}else{_0x2637b9[_0x3f6c('0x93')]=null;}_0x2637b9['ContactId']=_0x33719d['id'];return db[_0x3f6c('0x94')]['find']({'where':_0x2637b9})[_0x3f6c('0x3c')](function(_0x450557){if(_0x450557){return[_0x450557,![]];}return db[_0x3f6c('0x94')][_0x3f6c('0x69')](_0x4538ce)[_0x3f6c('0x3c')](function(_0x4b1cd0){return[_0x4b1cd0,!![]];});});}})[_0x3f6c('0x96')](function(_0x47d665,_0x9938a1){if(_0x47d665){_0x7e8eee=_0x9938a1;if(!_0x9938a1){var _0x4e8679={'from':(_0x46a103[_0x3f6c('0x90')][_0x3f6c('0x91')]||'')+'\x20'+(_0x46a103[_0x3f6c('0x90')][_0x3f6c('0x92')]||'')};if(_0x297fc3['body'][_0x3f6c('0x93')]&&_0x297fc3[_0x3f6c('0x64')][_0x3f6c('0x97')]&&_0x297fc3[_0x3f6c('0x64')][_0x3f6c('0x93')]!=_0x297fc3[_0x3f6c('0x64')][_0x3f6c('0x97')]){_0x4e8679[_0x3f6c('0x93')]=_0x297fc3[_0x3f6c('0x64')][_0x3f6c('0x97')];}return _0x47d665[_0x3f6c('0x37')](_0x4e8679);}else{return _0x47d665;}}})[_0x3f6c('0x3c')](function(_0x2d3a41){_0x46a103[_0x3f6c('0x98')]=_0x2d3a41[_0x3f6c('0x39')]({'plain':!![]});_0x46a103[_0x3f6c('0x98')][_0x3f6c('0x99')]=_0x7e8eee;if(_0x46a103['interaction'][_0x3f6c('0x99')]){if(_0x46a103[_0x3f6c('0x89')][_0x3f6c('0x9a')]){_0x46a103[_0x3f6c('0x8b')][_0x3f6c('0x9b')]({'id':0x0,'priority':_0x46a103[_0x3f6c('0x8b')][_0x3f6c('0x5e')]+0x1,'app':_0x3f6c('0x9c'),'appdata':_0x3f6c('0x9d'),'interval':'*,*,*,*'});}}return db[_0x3f6c('0x9e')]['create']({'body':_0x297fc3[_0x3f6c('0x64')][_0x3f6c('0x64')],'OpenchannelAccountId':_0x297fc3['params']['id'],'OpenchannelInteractionId':_0x2d3a41['id'],'direction':'in','ContactId':_0x46a103[_0x3f6c('0x90')]['id'],'AttachmentId':_0x297fc3[_0x3f6c('0x64')][_0x3f6c('0x9f')]});})[_0x3f6c('0x3c')](function(_0x9dd1a){_0x46a103[_0x3f6c('0x2a')]=_0x9dd1a;if(_0x46a103[_0x3f6c('0x98')][_0x3f6c('0xa0')]){return db[_0x3f6c('0xa1')][_0x3f6c('0x65')]({'attributes':['id',_0x3f6c('0x3e')],'where':{'id':_0x46a103[_0x3f6c('0x98')][_0x3f6c('0xa0')]}})['then'](function(_0x29de2f){if(_0x29de2f){_0x46a103['applications'][_0x3f6c('0xa2')]({'id':0x0,'priority':0x0,'app':_0x3f6c('0xa3'),'appdata':_0x29de2f[_0x3f6c('0x3e')]+','+(_0x46a103[_0x3f6c('0x89')]['waitForTheAssignedAgent']||0xa),'interval':_0x3f6c('0xa4')});_0x46a103[_0x3f6c('0xa5')]=![];}return respondWithRpcPromise(_0x3f6c('0xa6'),_0x3f6c('0xa7'),_0x46a103);});}return respondWithRpcPromise(_0x3f6c('0xa6'),_0x3f6c('0xa7'),_0x46a103);})[_0x3f6c('0x3c')](function(_0x34e812){respondWithRpcPromise(_0x3f6c('0xa8'),_0x3f6c('0xa8'),{'event':_0x3f6c('0xa9'),'message':_0x34e812},client9002);return _0x34e812;})[_0x3f6c('0x3c')](respondWithResult(_0x57d9db,null))[_0x3f6c('0x5a')](handleError(_0x57d9db,null));};exports[_0x3f6c('0xaa')]=function(_0x458102,_0x35a8a4,_0x459500){return db[_0x3f6c('0x42')][_0x3f6c('0x6b')]({'where':{'id':_0x458102[_0x3f6c('0x5c')]['id']}})['then'](handleEntityNotFound(_0x35a8a4,null))['then'](function(_0x6f8b8e){if(_0x6f8b8e){return db['sequelize'][_0x3f6c('0xab')](function(_0x12ee53){return db['OpenchannelApplication']['destroy']({'where':{'OpenchannelAccountId':_0x458102[_0x3f6c('0x5c')]['id']},'transaction':_0x12ee53})[_0x3f6c('0x3c')](function(_0x377f9b){var _0x358e6d=_[_0x3f6c('0x41')](_0x458102[_0x3f6c('0x64')],function(_0x1646f8){_0x1646f8[_0x3f6c('0x68')]=_0x458102[_0x3f6c('0x5c')]['id'];return _0x1646f8;});return db['OpenchannelApplication']['bulkCreate'](_0x358e6d,{'transaction':_0x12ee53});});})[_0x3f6c('0x3c')](function(){return db[_0x3f6c('0xac')][_0x3f6c('0xad')]({'where':{'OpenchannelAccountId':_0x458102[_0x3f6c('0x5c')]['id']},'order':'priority'});});}})['then'](respondWithResult(_0x35a8a4,null))[_0x3f6c('0x5a')](handleError(_0x35a8a4,null));};exports[_0x3f6c('0xae')]=function(_0x216fff,_0x5508ba,_0x82bea3){var _0x37ae7c={};var _0x2fb5a6={};var _0x5880e9;var _0x2b2ae7;return db[_0x3f6c('0x42')][_0x3f6c('0x6b')]({'where':{'id':_0x216fff[_0x3f6c('0x5c')]['id']}})['then'](handleEntityNotFound(_0x5508ba,null))[_0x3f6c('0x3c')](function(_0x1b4a6b){if(_0x1b4a6b){_0x5880e9=_0x1b4a6b;_0x2fb5a6[_0x3f6c('0x47')]=_[_0x3f6c('0x49')](db[_0x3f6c('0xac')]['rawAttributes']);_0x2fb5a6[_0x3f6c('0x48')]=_[_0x3f6c('0x49')](_0x216fff[_0x3f6c('0x48')]);_0x2fb5a6['filters']=_[_0x3f6c('0x4b')](_0x2fb5a6[_0x3f6c('0x47')],_0x2fb5a6[_0x3f6c('0x48')]);_0x37ae7c[_0x3f6c('0x4c')]=_['intersection'](_0x2fb5a6[_0x3f6c('0x47')],qs['fields'](_0x216fff['query']['fields']));_0x37ae7c[_0x3f6c('0x4c')]=_0x37ae7c[_0x3f6c('0x4c')][_0x3f6c('0x5e')]?_0x37ae7c['attributes']:_0x2fb5a6[_0x3f6c('0x47')];_0x37ae7c[_0x3f6c('0x50')]=qs[_0x3f6c('0x51')](_0x216fff[_0x3f6c('0x48')][_0x3f6c('0x51')]);_0x37ae7c[_0x3f6c('0x52')]=qs[_0x3f6c('0x4a')](_[_0x3f6c('0xaf')](_0x216fff[_0x3f6c('0x48')],_0x2fb5a6[_0x3f6c('0x4a')]));if(_0x216fff[_0x3f6c('0x48')][_0x3f6c('0x53')]){_0x37ae7c['where']=_[_0x3f6c('0x55')](_0x37ae7c[_0x3f6c('0x52')],{'$or':_[_0x3f6c('0x41')](_0x37ae7c[_0x3f6c('0x4c')],function(_0x2a6e7e){var _0x29b27d={};_0x29b27d[_0x2a6e7e]={'$like':'%'+_0x216fff[_0x3f6c('0x48')][_0x3f6c('0x53')]+'%'};return _0x29b27d;})});}_0x37ae7c=_['merge']({},_0x37ae7c,_0x216fff[_0x3f6c('0x56')]);return _0x5880e9[_0x3f6c('0xae')](_0x37ae7c);}})['then'](function(_0x5600f5){if(_0x5600f5){_0x2b2ae7=_0x5600f5[_0x3f6c('0x5e')];if(!_0x216fff[_0x3f6c('0x48')][_0x3f6c('0x6d')](_0x3f6c('0x4e'))){_0x37ae7c[_0x3f6c('0x4f')]=qs[_0x3f6c('0x4f')](_0x216fff[_0x3f6c('0x48')]['limit']);_0x37ae7c['offset']=qs['offset'](_0x216fff['query'][_0x3f6c('0x31')]);}return _0x5880e9[_0x3f6c('0xae')](_0x37ae7c);}})[_0x3f6c('0x3c')](function(_0x514ba6){if(_0x514ba6){return _0x514ba6?{'count':_0x2b2ae7,'rows':_0x514ba6}:null;}})[_0x3f6c('0x3c')](respondWithResult(_0x5508ba,null))[_0x3f6c('0x5a')](handleError(_0x5508ba,null));};exports['getInteractions']=function(_0x246165,_0x125aa7,_0xacf0b7){var _0x2099ac={'raw':![],'where':{}};var _0x55f167={};var _0x56dc0f={'count':0x0,'rows':[]};return db['OpenchannelAccount'][_0x3f6c('0x6b')]({'where':{'id':_0x246165[_0x3f6c('0x5c')]['id']}})[_0x3f6c('0x3c')](handleEntityNotFound(_0x125aa7,null))['then'](function(_0x46d584){if(_0x46d584){_0x55f167[_0x3f6c('0x47')]=_['keys'](db[_0x3f6c('0x94')][_0x3f6c('0x43')]);_0x55f167[_0x3f6c('0x48')]=_['keys'](_0x246165[_0x3f6c('0x48')]);_0x55f167[_0x3f6c('0x4a')]=_['intersection'](_0x55f167[_0x3f6c('0x47')],_0x55f167[_0x3f6c('0x48')]);_0x2099ac[_0x3f6c('0x4c')]=_[_0x3f6c('0x4b')](_0x55f167[_0x3f6c('0x47')],qs[_0x3f6c('0x4d')](_0x246165[_0x3f6c('0x48')][_0x3f6c('0x4d')]));_0x2099ac['attributes']=_0x2099ac[_0x3f6c('0x4c')]['length']?_0x2099ac['attributes']:_0x55f167['model'];if(!_0x246165[_0x3f6c('0x48')][_0x3f6c('0x6d')](_0x3f6c('0x4e'))){_0x2099ac[_0x3f6c('0x4f')]=qs[_0x3f6c('0x4f')](_0x246165[_0x3f6c('0x48')][_0x3f6c('0x4f')]);_0x2099ac[_0x3f6c('0x31')]=qs[_0x3f6c('0x31')](_0x246165[_0x3f6c('0x48')][_0x3f6c('0x31')]);}_0x2099ac[_0x3f6c('0x50')]=qs[_0x3f6c('0x51')](_0x246165[_0x3f6c('0x48')]['sort']);_0x2099ac[_0x3f6c('0x52')]=qs['filters'](_[_0x3f6c('0xaf')](_0x246165['query'],_0x55f167[_0x3f6c('0x4a')]));_0x2099ac[_0x3f6c('0x52')][_0x3f6c('0x68')]=_0x46d584['id'];if(_0x246165[_0x3f6c('0x48')]['filter']){_0x2099ac[_0x3f6c('0x52')]=_[_0x3f6c('0x55')](_0x2099ac[_0x3f6c('0x52')],{'$or':_[_0x3f6c('0x41')](_0x2099ac['attributes'],function(_0x307108){var _0x68e3fe={};_0x68e3fe[_0x307108]={'$like':'%'+_0x246165[_0x3f6c('0x48')]['filter']+'%'};return _0x68e3fe;})});}_0x2099ac=_[_0x3f6c('0x55')]({},_0x2099ac,_0x246165[_0x3f6c('0x56')]);return db['OpenchannelInteraction']['count']({'where':_0x2099ac[_0x3f6c('0x52')]})[_0x3f6c('0x3c')](function(_0x149840){_0x56dc0f[_0x3f6c('0x30')]=_0x149840;if(_0x246165[_0x3f6c('0x48')]['includeAll']){_0x2099ac[_0x3f6c('0x58')]=[{'model':db[_0x3f6c('0x75')],'as':'Contact','required':![]},{'model':db['User'],'as':_0x3f6c('0xb0'),'attributes':['name','fullname','internal'],'required':![]},{'model':db[_0x3f6c('0xb1')],'as':_0x3f6c('0xb2'),'attributes':['id',_0x3f6c('0x3e'),_0x3f6c('0xb3')],'where':_0x246165['query'][_0x3f6c('0xb4')]?{'id':_0x246165['query'][_0x3f6c('0xb4')]}:undefined,'required':_0x246165[_0x3f6c('0x48')][_0x3f6c('0xb4')]?!![]:![]}];}return db[_0x3f6c('0x94')][_0x3f6c('0x59')](_0x2099ac);})[_0x3f6c('0x3c')](function(_0x307924){_0x56dc0f[_0x3f6c('0x6e')]=_0x307924;return _0x56dc0f;});}})[_0x3f6c('0x3c')](respondWithFilteredResult(_0x125aa7,_0x2099ac))[_0x3f6c('0x5a')](handleError(_0x125aa7,null));};exports[_0x3f6c('0xb5')]=function(_0x177714,_0x5ce448,_0x4bccd1){return db['OpenchannelAccount'][_0x3f6c('0x65')]({'where':{'id':_0x177714[_0x3f6c('0x5c')]['id']}})['then'](handleEntityNotFound(_0x5ce448,null))[_0x3f6c('0x3c')](function(_0x52657c){if(_0x52657c){return _0x52657c[_0x3f6c('0xb5')](_0x177714[_0x3f6c('0x64')][_0x3f6c('0x70')],_[_0x3f6c('0xb6')](_0x177714[_0x3f6c('0x64')],['ids','id'])||{})['spread'](function(_0x4262fa){for(var _0x5c3d96=0x0;_0x5c3d96<_0x177714[_0x3f6c('0x64')][_0x3f6c('0x70')][_0x3f6c('0x5e')];_0x5c3d96+=0x1){socket[_0x3f6c('0xb7')](_0x3f6c('0xb8'),{'UserId':_0x177714[_0x3f6c('0x64')][_0x3f6c('0x70')][_0x5c3d96],'OpenchannelAccountId':_0x177714['params']['id']});}return _0x4262fa;});}})[_0x3f6c('0x3c')](respondWithResult(_0x5ce448,null))[_0x3f6c('0x5a')](handleError(_0x5ce448,null));};exports[_0x3f6c('0xb9')]=function(_0x262d31,_0x56830c,_0x5289e1){return db[_0x3f6c('0x42')][_0x3f6c('0x65')]({'where':{'id':_0x262d31[_0x3f6c('0x5c')]['id']}})['then'](handleEntityNotFound(_0x56830c,null))['then'](function(_0x32792b){if(_0x32792b){return _0x32792b['removeAgents'](_0x262d31[_0x3f6c('0x48')][_0x3f6c('0x70')])[_0x3f6c('0x3c')](function(){if(_[_0x3f6c('0xba')](_0x262d31['query'][_0x3f6c('0x70')])){for(var _0x375a82=0x0;_0x375a82<_0x262d31[_0x3f6c('0x48')][_0x3f6c('0x70')][_0x3f6c('0x5e')];_0x375a82+=0x1){socket['emit'](_0x3f6c('0xbb'),{'UserId':Number(_0x262d31[_0x3f6c('0x48')][_0x3f6c('0x70')][_0x375a82]),'OpenchannelAccountId':Number(_0x262d31[_0x3f6c('0x5c')]['id'])});}}else{socket['emit'](_0x3f6c('0xbb'),{'UserId':Number(_0x262d31[_0x3f6c('0x48')]['ids']),'OpenchannelAccountId':Number(_0x262d31[_0x3f6c('0x5c')]['id'])});}});}})[_0x3f6c('0x3c')](respondWithStatusCode(_0x56830c,null))[_0x3f6c('0x5a')](handleError(_0x56830c,null));};exports[_0x3f6c('0xbc')]=function(_0x26ce04,_0x3c37e9,_0x19449c){var _0x10abbd={};var _0x3b70dc={};var _0x1f2129;var _0x407a88;return db[_0x3f6c('0x42')][_0x3f6c('0x6b')]({'where':{'id':_0x26ce04['params']['id']}})[_0x3f6c('0x3c')](handleEntityNotFound(_0x3c37e9,null))[_0x3f6c('0x3c')](function(_0x1dd2e9){if(_0x1dd2e9){_0x1f2129=_0x1dd2e9;_0x3b70dc[_0x3f6c('0x47')]=_[_0x3f6c('0x49')](db[_0x3f6c('0xa1')]['rawAttributes']);_0x3b70dc[_0x3f6c('0x48')]=_[_0x3f6c('0x49')](_0x26ce04[_0x3f6c('0x48')]);_0x3b70dc[_0x3f6c('0x4a')]=_[_0x3f6c('0x4b')](_0x3b70dc['model'],_0x3b70dc[_0x3f6c('0x48')]);_0x10abbd[_0x3f6c('0x4c')]=_[_0x3f6c('0x4b')](_0x3b70dc[_0x3f6c('0x47')],qs[_0x3f6c('0x4d')](_0x26ce04[_0x3f6c('0x48')]['fields']));_0x10abbd[_0x3f6c('0x4c')]=_0x10abbd[_0x3f6c('0x4c')][_0x3f6c('0x5e')]?_0x10abbd[_0x3f6c('0x4c')]:_0x3b70dc['model'];_0x10abbd['order']=qs[_0x3f6c('0x51')](_0x26ce04[_0x3f6c('0x48')]['sort']);_0x10abbd[_0x3f6c('0x52')]=qs['filters'](_[_0x3f6c('0xaf')](_0x26ce04[_0x3f6c('0x48')],_0x3b70dc[_0x3f6c('0x4a')]));if(_0x26ce04[_0x3f6c('0x48')][_0x3f6c('0x53')]){_0x10abbd[_0x3f6c('0x52')]=_['merge'](_0x10abbd[_0x3f6c('0x52')],{'$or':_[_0x3f6c('0x41')](_0x10abbd[_0x3f6c('0x4c')],function(_0x28b291){var _0x784c28={};_0x784c28[_0x28b291]={'$like':'%'+_0x26ce04[_0x3f6c('0x48')][_0x3f6c('0x53')]+'%'};return _0x784c28;})});}_0x10abbd=_[_0x3f6c('0x55')]({},_0x10abbd,_0x26ce04[_0x3f6c('0x56')]);return _0x1f2129[_0x3f6c('0xbc')](_0x10abbd);}})[_0x3f6c('0x3c')](function(_0x389872){if(_0x389872){_0x407a88=_0x389872[_0x3f6c('0x5e')];if(!_0x26ce04[_0x3f6c('0x48')]['hasOwnProperty'](_0x3f6c('0x4e'))){_0x10abbd[_0x3f6c('0x4f')]=qs[_0x3f6c('0x4f')](_0x26ce04[_0x3f6c('0x48')][_0x3f6c('0x4f')]);_0x10abbd['offset']=qs[_0x3f6c('0x31')](_0x26ce04[_0x3f6c('0x48')][_0x3f6c('0x31')]);}return _0x1f2129['getAgents'](_0x10abbd);}})[_0x3f6c('0x3c')](function(_0x425b2b){if(_0x425b2b){return _0x425b2b?{'count':_0x407a88,'rows':_0x425b2b}:null;}})['then'](respondWithResult(_0x3c37e9,null))[_0x3f6c('0x5a')](handleError(_0x3c37e9,null));};exports[_0x3f6c('0x3f')]=function(_0x1c457e,_0x32739b,_0x36f731){var _0x2a1db3,_0x1a0853,_0x3d9204;if(_[_0x3f6c('0x7c')](_0x1c457e[_0x3f6c('0x64')][_0x3f6c('0x64')])||_0x1c457e[_0x3f6c('0x64')]['body']===''){throw new db[(_0x3f6c('0x7d'))]['ValidationError'](_0x3f6c('0x7f'));}if(_[_0x3f6c('0x7c')](_0x1c457e[_0x3f6c('0x64')]['to'])){}_0x2a1db3=_0x1c457e[_0x3f6c('0x64')]['to'];return db[_0x3f6c('0x42')]['findOne']({'where':{'id':_0x1c457e[_0x3f6c('0x5c')]['id']}})[_0x3f6c('0x3c')](handleEntityNotFound(_0x32739b,null))[_0x3f6c('0x3c')](function(_0x24ea16){if(_0x24ea16){return db[_0x3f6c('0x42')][_0x3f6c('0x65')]({'where':{'id':_0x24ea16['id']},'include':[{'model':db['CmList'],'as':'List','include':[{'model':db[_0x3f6c('0x75')],'as':_0x3f6c('0x86'),'where':{[_0x24ea16[_0x3f6c('0x80')]]:_0x2a1db3},'limit':0x1,'order':[[_0x3f6c('0x79'),'DESC']]}]}]})[_0x3f6c('0x3c')](handleEntityNotFound(_0x32739b,null))[_0x3f6c('0x3c')](function(_0x31f011){if(_0x31f011&&_0x31f011[_0x3f6c('0x85')]){_0x1a0853=_0x31f011[_0x3f6c('0x39')]({'plain':!![]});if(_0x1a0853[_0x3f6c('0x85')]&&_0x1a0853[_0x3f6c('0x85')][_0x3f6c('0x86')][_0x3f6c('0x5e')]){return _0x1a0853[_0x3f6c('0x85')][_0x3f6c('0x86')][0x0];}return db['CmContact'][_0x3f6c('0x69')](_[_0x3f6c('0x8f')](_0x1c457e[_0x3f6c('0x64')],{'firstName':_0x2a1db3,[_0x31f011['mapKey']]:_0x2a1db3,'phone':_0x2a1db3,'ListId':_0x1a0853[_0x3f6c('0x7b')]}));}})[_0x3f6c('0x3c')](handleEntityNotFound(_0x32739b,null))[_0x3f6c('0x3c')](function(_0x20f21c){if(_0x20f21c){_0x3d9204=_0x20f21c;return db['OpenchannelInteraction'][_0x3f6c('0x65')]({'where':{'ContactId':_0x3d9204['id'],'closed':![],'OpenchannelAccountId':_0x1a0853['id']}})[_0x3f6c('0x3c')](function(_0x453b41){if(_0x453b41){return[_0x453b41,![]];}return db[_0x3f6c('0x94')][_0x3f6c('0x69')]({'UserId':_0x1c457e[_0x3f6c('0x5f')]['id'],'ContactId':_0x3d9204['id'],'OpenchannelAccountId':_0x1a0853['id'],'lastMsgDirection':'out','Messages':[_[_0x3f6c('0x55')](_0x1c457e[_0x3f6c('0x64')],{'read':![],'body':_0x1c457e[_0x3f6c('0x64')][_0x3f6c('0x64')],'OpenchannelAccountId':_0x1a0853['id'],'UserId':_0x1c457e[_0x3f6c('0x5f')]['id'],'ContactId':_0x3d9204['id']})]},{'include':[{'model':db['OpenchannelMessage'],'as':_0x3f6c('0xbd')}]})[_0x3f6c('0x3c')](function(_0x1385f5){return[_0x1385f5,!![]];});});}})[_0x3f6c('0x96')](function(_0x41d1f6,_0x2d2a31){if(_0x2d2a31){return _0x41d1f6;}return db[_0x3f6c('0x9e')][_0x3f6c('0x69')](_[_0x3f6c('0x55')](_0x1c457e[_0x3f6c('0x64')],{'read':![],'body':_0x1c457e[_0x3f6c('0x64')][_0x3f6c('0x64')],'OpenchannelAccountId':_0x1a0853['id'],'OpenchannelInteractionId':_0x41d1f6['id'],'UserId':_0x1c457e[_0x3f6c('0x5f')]['id'],'ContactId':_0x3d9204['id']}))[_0x3f6c('0x3c')](function(_0xb91c27){_0x41d1f6[_0x3f6c('0xbe')][_0x3f6c('0xbd')]=[];_0x41d1f6[_0x3f6c('0xbe')]['Messages'][_0x3f6c('0x9b')](_0xb91c27['dataValues']);return _0x41d1f6;});});}})[_0x3f6c('0x3c')](respondWithResult(_0x32739b,null))[_0x3f6c('0x5a')](handleError(_0x32739b,null));};
\ No newline at end of file