Built motion from commit da617fac.|2.6.6
[motion2.git] / server / api / openchannelAccount / openchannelAccount.controller.js
index c19ccc8..e867693 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x9957=['OpenchannelAccount,\x20%s,\x20%s','request\x20sent','result','status','json','offset','limit','set','Content-Range','apply','reject','save','destroy','get','OpenchannelAccounts','UserProfileResource','stack','name','send','index','Pause','mandatoryDispositionPause','map','OpenchannelAccount','rawAttributes','fieldName','type','key','model','query','keys','fields','attributes','order','sort','filters','filter','merge','where','VIRTUAL','options','count','includeAll','include','findAll','rows','catch','show','params','intersection','length','find','create','body','user','UserProfileSection','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','describe','addDisposition','OpenchannelAccountId','Disposition','getDispositions','hasOwnProperty','nolimit','pick','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','notify','openchannel','CmContact','Sequelize','ValidationError','createdAt','updatedAt','difference','ListId','isNil','from','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','List','Contacts','OpenchannelApplication','account','applications','Applications','list','orderBy','contact','firstName','lastName','threadId','OpenchannelInteraction','externalUrl','messageId','interaction','created','autoclose','push','close','unmanaged','AttachmentId','UserId','User','unshift','waitForTheAssignedAgent','*,*,*,*','Start','startRouting','EventManager','addApplications','findOne','transaction','bulkCreate','findAndCountAll','priority','getApplications','Owner','internal','Tag','Tags','color','tag','addAgents','spread','userOpenchannelAccount:save','removeAgents','isArray','emit','userOpenchannelAccount:remove','getAgents','DESC','out','OpenchannelMessage','dataValues','Messages','html-pdf','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','register','jayson/promise','client','http','request','then','info','debug','stringify','error','code','message'];(function(_0x5f3f88,_0x562baf){var _0xd08119=function(_0x42dbf7){while(--_0x42dbf7){_0x5f3f88['push'](_0x5f3f88['shift']());}};_0xd08119(++_0x562baf);}(_0x9957,0x93));var _0x7995=function(_0x501510,_0x61caa9){_0x501510=_0x501510-0x0;var _0x1e6ee5=_0x9957[_0x501510];return _0x1e6ee5;};'use strict';var pdf=require(_0x7995('0x0'));var emlformat=require(_0x7995('0x1'));var rimraf=require(_0x7995('0x2'));var zipdir=require(_0x7995('0x3'));var jsonpatch=require('fast-json-patch');var rp=require(_0x7995('0x4'));var moment=require(_0x7995('0x5'));var BPromise=require(_0x7995('0x6'));var Mustache=require(_0x7995('0x7'));var util=require('util');var path=require(_0x7995('0x8'));var sox=require(_0x7995('0x9'));var csv=require(_0x7995('0xa'));var ejs=require(_0x7995('0xb'));var fs=require('fs');var _=require(_0x7995('0xc'));var squel=require(_0x7995('0xd'));var crypto=require('crypto');var jsforce=require(_0x7995('0xe'));var deskjs=require(_0x7995('0xf'));var toCsv=require('to-csv');var querystring=require(_0x7995('0x10'));var Papa=require(_0x7995('0x11'));var Redis=require(_0x7995('0x12'));var authService=require(_0x7995('0x13'));var qs=require(_0x7995('0x14'));var as=require(_0x7995('0x15'));var hardwareService=require(_0x7995('0x16'));var logger=require('../../config/logger')(_0x7995('0x17'));var utils=require(_0x7995('0x18'));var config=require('../../config/environment');var licenseUtil=require(_0x7995('0x19'));var db=require(_0x7995('0x1a'))['db'];config[_0x7995('0x1b')]=_[_0x7995('0x1c')](config[_0x7995('0x1b')],{'host':_0x7995('0x1d'),'port':0x18eb});var socket=require(_0x7995('0x1e'))(new Redis(config['redis']));require('./openchannelAccount.socket')[_0x7995('0x1f')](socket);var jayson=require(_0x7995('0x20'));var client=jayson[_0x7995('0x21')][_0x7995('0x22')]({'port':0x232c});var client9002=jayson[_0x7995('0x21')][_0x7995('0x22')]({'port':0x232a});function respondWithRpcPromise(_0x2202ce,_0x41cbf0,_0x5377e5,_0x2eeacc){return new BPromise(function(_0x565d97,_0x2f832e){var _0x37f297=_0x2eeacc||client;return _0x37f297[_0x7995('0x23')](_0x2202ce,_0x5377e5)[_0x7995('0x24')](function(_0x1e1415){logger[_0x7995('0x25')]('OpenchannelAccount,\x20%s,\x20%s',_0x41cbf0,'request\x20sent');logger[_0x7995('0x26')]('OpenchannelAccount,\x20%s,\x20%s,\x20%s',_0x41cbf0,'request\x20sent',JSON[_0x7995('0x27')](_0x1e1415));if(_0x1e1415[_0x7995('0x28')]){if(_0x1e1415['error'][_0x7995('0x29')]===0x1f4){logger['error']('OpenchannelAccount,\x20%s,\x20%s',_0x41cbf0,_0x1e1415[_0x7995('0x28')][_0x7995('0x2a')]);return _0x2f832e(_0x1e1415[_0x7995('0x28')][_0x7995('0x2a')]);}logger[_0x7995('0x28')](_0x7995('0x2b'),_0x41cbf0,_0x1e1415['error'][_0x7995('0x2a')]);return _0x565d97(_0x1e1415[_0x7995('0x28')][_0x7995('0x2a')]);}else{logger[_0x7995('0x25')](_0x7995('0x2b'),_0x41cbf0,_0x7995('0x2c'));_0x565d97(_0x1e1415[_0x7995('0x2d')][_0x7995('0x2a')]);}})['catch'](function(_0x39df42){logger[_0x7995('0x28')](_0x7995('0x2b'),_0x41cbf0,_0x39df42);_0x2f832e(_0x39df42);});});}function respondWithStatusCode(_0x268ce7,_0x3a3fcf){_0x3a3fcf=_0x3a3fcf||0xcc;return function(_0x2a307e){if(_0x2a307e){return _0x268ce7['sendStatus'](_0x3a3fcf);}return _0x268ce7[_0x7995('0x2e')](_0x3a3fcf)['end']();};}function respondWithResult(_0x229742,_0x49bc7e){_0x49bc7e=_0x49bc7e||0xc8;return function(_0xf16cc2){if(_0xf16cc2){return _0x229742[_0x7995('0x2e')](_0x49bc7e)[_0x7995('0x2f')](_0xf16cc2);}};}function respondWithFilteredResult(_0x4b6f99,_0x9b2a15){return function(_0x514445){if(_0x514445){var _0x456a28=_0x514445['count'],_0x3250e0=_0x9b2a15['offset'],_0x4253e5=_0x9b2a15[_0x7995('0x30')]+_0x9b2a15[_0x7995('0x31')],_0x574574;if(_0x4253e5>=_0x456a28){_0x4253e5=_0x456a28;_0x574574=0xc8;}else{_0x574574=0xce;}_0x4b6f99[_0x7995('0x2e')](_0x574574);return _0x4b6f99[_0x7995('0x32')](_0x7995('0x33'),_0x3250e0+'-'+_0x4253e5+'/'+_0x456a28)[_0x7995('0x2f')](_0x514445);}return null;};}function patchUpdates(_0x538841){return function(_0x481c74){try{jsonpatch[_0x7995('0x34')](_0x481c74,_0x538841,!![]);}catch(_0x5524af){return BPromise[_0x7995('0x35')](_0x5524af);}return _0x481c74[_0x7995('0x36')]();};}function saveUpdates(_0x29fac5,_0x1e9fa4){return function(_0x1f7d27){if(_0x1f7d27){return _0x1f7d27['update'](_0x29fac5)[_0x7995('0x24')](function(_0x33e24e){return _0x33e24e;});}return null;};}function removeEntity(_0x5dd802,_0x48db25){return function(_0x577412){if(_0x577412){return _0x577412[_0x7995('0x37')]()[_0x7995('0x24')](function(){var _0x4a176f=_0x577412[_0x7995('0x38')]({'plain':!![]});var _0x51b95d=_0x7995('0x39');return db[_0x7995('0x3a')][_0x7995('0x37')]({'where':{'type':_0x51b95d,'resourceId':_0x4a176f['id']}})['then'](function(){return _0x577412;});})['then'](function(){_0x5dd802[_0x7995('0x2e')](0xcc)['end']();});}};}function handleEntityNotFound(_0x5d2428,_0x3e99cd){return function(_0xe328b1){if(!_0xe328b1){_0x5d2428['sendStatus'](0x194);}return _0xe328b1;};}function handleError(_0x1baa15,_0x1922b4){_0x1922b4=_0x1922b4||0x1f4;return function(_0x2b772f){logger[_0x7995('0x28')](_0x2b772f[_0x7995('0x3b')]);if(_0x2b772f['name']){delete _0x2b772f[_0x7995('0x3c')];}_0x1baa15[_0x7995('0x2e')](_0x1922b4)[_0x7995('0x3d')](_0x2b772f);};}exports[_0x7995('0x3e')]=function(_0x4b1541,_0x2be2c0){var _0x235df7={'include':[{'model':db[_0x7995('0x3f')],'as':_0x7995('0x40')}]},_0x3eb04f={},_0xe5ea43={'count':0x0,'rows':[]};var _0x5688a1=_[_0x7995('0x41')](db[_0x7995('0x42')][_0x7995('0x43')],function(_0x2ea47f){return{'name':_0x2ea47f[_0x7995('0x44')],'type':_0x2ea47f[_0x7995('0x45')][_0x7995('0x46')]};});_0x3eb04f[_0x7995('0x47')]=_[_0x7995('0x41')](_0x5688a1,_0x7995('0x3c'));_0x3eb04f[_0x7995('0x48')]=_[_0x7995('0x49')](_0x4b1541[_0x7995('0x48')]);_0x3eb04f['filters']=_['intersection'](_0x3eb04f[_0x7995('0x47')],_0x3eb04f[_0x7995('0x48')]);_0x235df7['attributes']=_['intersection'](_0x3eb04f[_0x7995('0x47')],qs['fields'](_0x4b1541['query'][_0x7995('0x4a')]));_0x235df7[_0x7995('0x4b')]=_0x235df7[_0x7995('0x4b')]['length']?_0x235df7[_0x7995('0x4b')]:_0x3eb04f['model'];if(!_0x4b1541[_0x7995('0x48')]['hasOwnProperty']('nolimit')){_0x235df7[_0x7995('0x31')]=qs[_0x7995('0x31')](_0x4b1541[_0x7995('0x48')][_0x7995('0x31')]);_0x235df7['offset']=qs[_0x7995('0x30')](_0x4b1541[_0x7995('0x48')][_0x7995('0x30')]);}_0x235df7[_0x7995('0x4c')]=qs['sort'](_0x4b1541['query'][_0x7995('0x4d')]);_0x235df7['where']=qs[_0x7995('0x4e')](_['pick'](_0x4b1541[_0x7995('0x48')],_0x3eb04f['filters']),_0x5688a1);if(_0x4b1541[_0x7995('0x48')][_0x7995('0x4f')]){_0x235df7['where']=_[_0x7995('0x50')](_0x235df7[_0x7995('0x51')],{'$or':_[_0x7995('0x41')](_0x5688a1,function(_0xb70a51){if(_0xb70a51['type']!==_0x7995('0x52')){var _0x3e787d={};_0x3e787d[_0xb70a51[_0x7995('0x3c')]]={'$like':'%'+_0x4b1541['query'][_0x7995('0x4f')]+'%'};return _0x3e787d;}})});}_0x235df7=_[_0x7995('0x50')]({},_0x235df7,_0x4b1541[_0x7995('0x53')]);var _0x3d8ae3={'where':_0x235df7[_0x7995('0x51')]};return db['OpenchannelAccount'][_0x7995('0x54')](_0x3d8ae3)[_0x7995('0x24')](function(_0x5921b9){_0xe5ea43[_0x7995('0x54')]=_0x5921b9;if(_0x4b1541['query'][_0x7995('0x55')]){_0x235df7[_0x7995('0x56')]=[{'all':!![]}];}return db[_0x7995('0x42')][_0x7995('0x57')](_0x235df7);})[_0x7995('0x24')](function(_0x14b537){_0xe5ea43[_0x7995('0x58')]=_0x14b537;return _0xe5ea43;})['then'](respondWithFilteredResult(_0x2be2c0,_0x235df7))[_0x7995('0x59')](handleError(_0x2be2c0,null));};exports[_0x7995('0x5a')]=function(_0x418eb9,_0x4ffc8a){var _0x19da63={'raw':![],'where':{'id':_0x418eb9[_0x7995('0x5b')]['id']},'include':[{'model':db['Pause'],'as':'mandatoryDispositionPause'}]},_0x1fe77e={};_0x1fe77e['model']=_[_0x7995('0x49')](db[_0x7995('0x42')]['rawAttributes']);_0x1fe77e[_0x7995('0x48')]=_[_0x7995('0x49')](_0x418eb9[_0x7995('0x48')]);_0x1fe77e[_0x7995('0x4e')]=_[_0x7995('0x5c')](_0x1fe77e['model'],_0x1fe77e[_0x7995('0x48')]);_0x19da63['attributes']=_[_0x7995('0x5c')](_0x1fe77e[_0x7995('0x47')],qs[_0x7995('0x4a')](_0x418eb9['query']['fields']));_0x19da63['attributes']=_0x19da63['attributes'][_0x7995('0x5d')]?_0x19da63[_0x7995('0x4b')]:_0x1fe77e[_0x7995('0x47')];if(_0x418eb9[_0x7995('0x48')][_0x7995('0x55')]){_0x19da63[_0x7995('0x56')]=[{'all':!![]}];}_0x19da63=_[_0x7995('0x50')]({},_0x19da63,_0x418eb9[_0x7995('0x53')]);return db[_0x7995('0x42')][_0x7995('0x5e')](_0x19da63)[_0x7995('0x24')](handleEntityNotFound(_0x4ffc8a,null))[_0x7995('0x24')](respondWithResult(_0x4ffc8a,null))[_0x7995('0x59')](handleError(_0x4ffc8a,null));};exports[_0x7995('0x5f')]=function(_0x1ea1dc,_0x416133){return db[_0x7995('0x42')][_0x7995('0x5f')](_0x1ea1dc[_0x7995('0x60')],{})['then'](function(_0x56a374){var _0x630737=_0x1ea1dc[_0x7995('0x61')][_0x7995('0x38')]({'plain':!![]});if(!_0x630737)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x630737['role']===_0x7995('0x61')){var _0x197b52=_0x56a374[_0x7995('0x38')]({'plain':!![]});var _0x332a85='OpenchannelAccounts';return db[_0x7995('0x62')][_0x7995('0x5e')]({'where':{'name':_0x332a85,'userProfileId':_0x630737[_0x7995('0x63')]},'raw':!![]})[_0x7995('0x24')](function(_0x502d43){if(_0x502d43&&_0x502d43['autoAssociation']===0x0){return db[_0x7995('0x3a')][_0x7995('0x5f')]({'name':_0x197b52[_0x7995('0x3c')],'resourceId':_0x197b52['id'],'type':_0x502d43[_0x7995('0x3c')],'sectionId':_0x502d43['id']},{})[_0x7995('0x24')](function(){return _0x56a374;});}else{return _0x56a374;}})[_0x7995('0x59')](function(_0x1d4689){logger[_0x7995('0x28')](_0x7995('0x64'),_0x1d4689);throw _0x1d4689;});}return _0x56a374;})['then'](respondWithResult(_0x416133,0xc9))[_0x7995('0x59')](handleError(_0x416133,null));};exports[_0x7995('0x65')]=function(_0xdf9e38,_0x1ecfdb){if(_0xdf9e38['body']['id']){delete _0xdf9e38['body']['id'];}return db[_0x7995('0x42')][_0x7995('0x5e')]({'where':{'id':_0xdf9e38['params']['id']},'include':[{'model':db[_0x7995('0x3f')],'as':_0x7995('0x40')}]})[_0x7995('0x24')](handleEntityNotFound(_0x1ecfdb,null))[_0x7995('0x24')](saveUpdates(_0xdf9e38[_0x7995('0x60')],null))['then'](respondWithResult(_0x1ecfdb,null))[_0x7995('0x59')](handleError(_0x1ecfdb,null));};exports['destroy']=function(_0x3e0a46,_0xe31dcb){return db[_0x7995('0x42')][_0x7995('0x5e')]({'where':{'id':_0x3e0a46[_0x7995('0x5b')]['id']}})[_0x7995('0x24')](handleEntityNotFound(_0xe31dcb,null))[_0x7995('0x24')](removeEntity(_0xe31dcb,null))[_0x7995('0x59')](handleError(_0xe31dcb,null));};exports[_0x7995('0x66')]=function(_0x3f2bde,_0x2618c4){return db[_0x7995('0x42')]['describe']()[_0x7995('0x24')](respondWithResult(_0x2618c4,null))[_0x7995('0x59')](handleError(_0x2618c4,null));};exports[_0x7995('0x67')]=function(_0xc2b660,_0x2c6548,_0x54a2e0){if(_0xc2b660['body']['id']){delete _0xc2b660[_0x7995('0x60')]['id'];}return db[_0x7995('0x42')][_0x7995('0x5e')]({'where':{'id':_0xc2b660[_0x7995('0x5b')]['id']}})['then'](handleEntityNotFound(_0x2c6548,null))[_0x7995('0x24')](function(_0x50a12e){if(_0x50a12e){_0xc2b660['body'][_0x7995('0x68')]=_0x50a12e['id'];return db[_0x7995('0x69')][_0x7995('0x5f')](_0xc2b660[_0x7995('0x60')]);}})[_0x7995('0x24')](respondWithResult(_0x2c6548,null))[_0x7995('0x59')](handleError(_0x2c6548,null));};exports[_0x7995('0x6a')]=function(_0x13dc73,_0x3fde86,_0x2466df){var _0x560b0a={'raw':![],'where':{}};var _0x2dc1f7={};var _0x8908cd={'count':0x0,'rows':[]};return db[_0x7995('0x42')]['findOne']({'where':{'id':_0x13dc73[_0x7995('0x5b')]['id']}})[_0x7995('0x24')](handleEntityNotFound(_0x3fde86,null))[_0x7995('0x24')](function(_0x3a7d9d){if(_0x3a7d9d){_0x2dc1f7[_0x7995('0x47')]=_[_0x7995('0x49')](db[_0x7995('0x69')][_0x7995('0x43')]);_0x2dc1f7[_0x7995('0x48')]=_[_0x7995('0x49')](_0x13dc73[_0x7995('0x48')]);_0x2dc1f7['filters']=_['intersection'](_0x2dc1f7[_0x7995('0x47')],_0x2dc1f7[_0x7995('0x48')]);_0x560b0a[_0x7995('0x4b')]=_[_0x7995('0x5c')](_0x2dc1f7['model'],qs[_0x7995('0x4a')](_0x13dc73[_0x7995('0x48')]['fields']));_0x560b0a['attributes']=_0x560b0a[_0x7995('0x4b')][_0x7995('0x5d')]?_0x560b0a['attributes']:_0x2dc1f7[_0x7995('0x47')];if(!_0x13dc73['query'][_0x7995('0x6b')](_0x7995('0x6c'))){_0x560b0a['limit']=qs['limit'](_0x13dc73[_0x7995('0x48')]['limit']);_0x560b0a[_0x7995('0x30')]=qs[_0x7995('0x30')](_0x13dc73[_0x7995('0x48')][_0x7995('0x30')]);}_0x560b0a[_0x7995('0x4c')]=qs[_0x7995('0x4d')](_0x13dc73[_0x7995('0x48')][_0x7995('0x4d')]);_0x560b0a[_0x7995('0x51')]=qs[_0x7995('0x4e')](_[_0x7995('0x6d')](_0x13dc73[_0x7995('0x48')],_0x2dc1f7[_0x7995('0x4e')]));_0x560b0a[_0x7995('0x51')][_0x7995('0x68')]=_0x3a7d9d['id'];if(_0x13dc73[_0x7995('0x48')][_0x7995('0x4f')]){_0x560b0a[_0x7995('0x51')]=_[_0x7995('0x50')](_0x560b0a[_0x7995('0x51')],{'$or':_[_0x7995('0x41')](_0x560b0a[_0x7995('0x4b')],function(_0x11fe75){var _0x280fbb={};_0x280fbb[_0x11fe75]={'$like':'%'+_0x13dc73[_0x7995('0x48')][_0x7995('0x4f')]+'%'};return _0x280fbb;})});}_0x560b0a=_[_0x7995('0x50')]({},_0x560b0a,_0x13dc73[_0x7995('0x53')]);return db['Disposition'][_0x7995('0x54')]({'where':_0x560b0a[_0x7995('0x51')]})['then'](function(_0x4c85cb){_0x8908cd[_0x7995('0x54')]=_0x4c85cb;if(_0x13dc73[_0x7995('0x48')][_0x7995('0x55')]){_0x560b0a[_0x7995('0x56')]=[{'all':!![]}];}return db[_0x7995('0x69')][_0x7995('0x57')](_0x560b0a);})['then'](function(_0x2f8a2d){_0x8908cd[_0x7995('0x58')]=_0x2f8a2d;return _0x8908cd;});}})[_0x7995('0x24')](respondWithFilteredResult(_0x3fde86,_0x560b0a))[_0x7995('0x59')](handleError(_0x3fde86,null));};exports[_0x7995('0x6e')]=function(_0x3f0bff,_0x151d99,_0xc93dcb){return db['OpenchannelAccount'][_0x7995('0x5e')]({'where':{'id':_0x3f0bff[_0x7995('0x5b')]['id']}})['then'](handleEntityNotFound(_0x151d99,null))['then'](function(_0xd24c64){if(_0xd24c64){return _0xd24c64[_0x7995('0x6e')](_0x3f0bff[_0x7995('0x48')][_0x7995('0x6f')]);}})[_0x7995('0x24')](respondWithStatusCode(_0x151d99,null))['catch'](handleError(_0x151d99,null));};exports[_0x7995('0x70')]=function(_0x406054,_0x528b22,_0x209977){if(_0x406054[_0x7995('0x60')]['id']){delete _0x406054['body']['id'];}return db[_0x7995('0x42')]['find']({'where':{'id':_0x406054[_0x7995('0x5b')]['id']}})[_0x7995('0x24')](handleEntityNotFound(_0x528b22,null))[_0x7995('0x24')](function(_0x428a1b){if(_0x428a1b){_0x406054[_0x7995('0x60')]['OpenchannelAccountId']=_0x428a1b['id'];return db[_0x7995('0x71')][_0x7995('0x5f')](_0x406054[_0x7995('0x60')]);}})['then'](respondWithResult(_0x528b22,null))[_0x7995('0x59')](handleError(_0x528b22,null));};exports[_0x7995('0x72')]=function(_0x350ed3,_0x308a26,_0x5d7018){var _0x3356fd={'raw':![],'where':{}};var _0xf59a39={};var _0x3a5f5e={'count':0x0,'rows':[]};return db['OpenchannelAccount']['findOne']({'where':{'id':_0x350ed3[_0x7995('0x5b')]['id']}})[_0x7995('0x24')](handleEntityNotFound(_0x308a26,null))['then'](function(_0x590373){if(_0x590373){_0xf59a39[_0x7995('0x47')]=_[_0x7995('0x49')](db[_0x7995('0x71')][_0x7995('0x43')]);_0xf59a39[_0x7995('0x48')]=_['keys'](_0x350ed3['query']);_0xf59a39[_0x7995('0x4e')]=_['intersection'](_0xf59a39['model'],_0xf59a39[_0x7995('0x48')]);_0x3356fd[_0x7995('0x4b')]=_[_0x7995('0x5c')](_0xf59a39['model'],qs[_0x7995('0x4a')](_0x350ed3[_0x7995('0x48')][_0x7995('0x4a')]));_0x3356fd[_0x7995('0x4b')]=_0x3356fd[_0x7995('0x4b')]['length']?_0x3356fd[_0x7995('0x4b')]:_0xf59a39[_0x7995('0x47')];if(!_0x350ed3[_0x7995('0x48')][_0x7995('0x6b')]('nolimit')){_0x3356fd[_0x7995('0x31')]=qs[_0x7995('0x31')](_0x350ed3['query'][_0x7995('0x31')]);_0x3356fd[_0x7995('0x30')]=qs['offset'](_0x350ed3[_0x7995('0x48')]['offset']);}_0x3356fd[_0x7995('0x4c')]=qs['sort'](_0x350ed3[_0x7995('0x48')]['sort']);_0x3356fd[_0x7995('0x51')]=qs[_0x7995('0x4e')](_['pick'](_0x350ed3[_0x7995('0x48')],_0xf59a39['filters']));_0x3356fd['where'][_0x7995('0x68')]=_0x590373['id'];if(_0x350ed3[_0x7995('0x48')][_0x7995('0x4f')]){_0x3356fd[_0x7995('0x51')]=_['merge'](_0x3356fd[_0x7995('0x51')],{'$or':_[_0x7995('0x41')](_0x3356fd['attributes'],function(_0x4ca4b2){var _0xc2648d={};_0xc2648d[_0x4ca4b2]={'$like':'%'+_0x350ed3['query'][_0x7995('0x4f')]+'%'};return _0xc2648d;})});}_0x3356fd=_[_0x7995('0x50')]({},_0x3356fd,_0x350ed3[_0x7995('0x53')]);return db['CannedAnswer']['count']({'where':_0x3356fd[_0x7995('0x51')]})['then'](function(_0x12e9d9){_0x3a5f5e[_0x7995('0x54')]=_0x12e9d9;if(_0x350ed3[_0x7995('0x48')][_0x7995('0x55')]){_0x3356fd['include']=[{'all':!![]}];}return db['CannedAnswer']['findAll'](_0x3356fd);})[_0x7995('0x24')](function(_0x340a57){_0x3a5f5e[_0x7995('0x58')]=_0x340a57;return _0x3a5f5e;});}})[_0x7995('0x24')](respondWithFilteredResult(_0x308a26,_0x3356fd))[_0x7995('0x59')](handleError(_0x308a26,null));};exports[_0x7995('0x73')]=function(_0x59a793,_0x53cbec,_0x1a2902){return db['OpenchannelAccount']['find']({'where':{'id':_0x59a793[_0x7995('0x5b')]['id']}})['then'](handleEntityNotFound(_0x53cbec,null))['then'](function(_0x35c3f3){if(_0x35c3f3){return _0x35c3f3[_0x7995('0x73')](_0x59a793[_0x7995('0x48')]['ids']);}})[_0x7995('0x24')](respondWithStatusCode(_0x53cbec,null))[_0x7995('0x59')](handleError(_0x53cbec,null));};exports[_0x7995('0x74')]=function(_0x340f6d,_0x227372,_0x178746){var _0x41e3aa={'body':_0x340f6d[_0x7995('0x60')],'channel':_0x7995('0x75')};var _0x570b71=[];var _0x3eb3fa=[];var _0x87a539={};var _0x3c6678=![];return db[_0x7995('0x76')][_0x7995('0x66')]()['then'](function(_0x1ea316){if(!_0x1ea316){throw new db[(_0x7995('0x77'))][(_0x7995('0x78'))]('no\x20available\x20attributes');}_0x570b71=_['difference'](_['keys'](_0x1ea316),[_0x7995('0x79'),_0x7995('0x7a')]);_0x3eb3fa=_[_0x7995('0x7b')](_[_0x7995('0x49')](_0x1ea316),[_0x7995('0x79'),_0x7995('0x7a'),'CompanyId',_0x7995('0x7c')]);if(_0x340f6d['body']['id']){delete _0x340f6d[_0x7995('0x60')]['id'];}if(_[_0x7995('0x7d')](_0x340f6d[_0x7995('0x60')][_0x7995('0x7e')])){throw new db[(_0x7995('0x77'))][(_0x7995('0x78'))](_0x7995('0x7f'));}if(_[_0x7995('0x7d')](_0x340f6d[_0x7995('0x60')][_0x7995('0x60')])||_0x340f6d[_0x7995('0x60')]['body']===''){throw new db[(_0x7995('0x77'))]['ValidationError'](_0x7995('0x80'));}if(_[_0x7995('0x7d')](_0x340f6d['body']['mapKey'])){throw new db[(_0x7995('0x77'))][(_0x7995('0x78'))](_0x7995('0x81')+_0x3eb3fa);}if(!_[_0x7995('0x82')](_0x3eb3fa,_0x340f6d[_0x7995('0x60')][_0x7995('0x83')])){throw new db[(_0x7995('0x77'))][(_0x7995('0x78'))](_0x7995('0x84')+_0x3eb3fa);}_0x87a539[_0x340f6d[_0x7995('0x60')][_0x7995('0x83')]]=_0x340f6d[_0x7995('0x60')]['from'];})['then'](function(){return db[_0x7995('0x42')][_0x7995('0x5e')]({'where':{'id':_0x340f6d[_0x7995('0x5b')]['id']},'include':[{'model':db[_0x7995('0x85')],'as':_0x7995('0x86'),'include':[{'model':db['CmContact'],'as':_0x7995('0x87'),'where':_0x87a539,'limit':0x1,'order':[[_0x7995('0x7a'),'DESC']]}]},{'model':db[_0x7995('0x88')],'as':'Applications'}]});})[_0x7995('0x24')](handleEntityNotFound(_0x227372,null))[_0x7995('0x24')](function(_0x234a40){if(_0x234a40&&_0x234a40['List']){_0x41e3aa[_0x7995('0x89')]=_0x234a40;_0x41e3aa[_0x7995('0x8a')]=_0x234a40[_0x7995('0x8b')];_0x41e3aa[_0x7995('0x8c')]=_0x234a40[_0x7995('0x86')];_0x41e3aa[_0x7995('0x8a')]=_[_0x7995('0x8d')](_0x41e3aa['applications'],['priority'],['asc']);if(_0x41e3aa[_0x7995('0x89')][_0x7995('0x8b')]){delete _0x41e3aa['account']['Applications'];}if(_0x41e3aa[_0x7995('0x89')][_0x7995('0x86')]&&_0x41e3aa['account']['List']['Contacts']['length']){return _0x41e3aa[_0x7995('0x89')][_0x7995('0x86')][_0x7995('0x87')][0x0];}var _0x421e44=_['defaults'](_0x340f6d[_0x7995('0x60')],{'firstName':_0x340f6d[_0x7995('0x60')]['from'],'ListId':_0x234a40[_0x7995('0x7c')]});_0x421e44[_0x340f6d[_0x7995('0x60')][_0x7995('0x83')]]=_0x340f6d['body'][_0x7995('0x7e')];return db[_0x7995('0x76')]['create'](_0x421e44,{'fields':_0x570b71,'raw':!![]});}})[_0x7995('0x24')](handleEntityNotFound(_0x227372,null))[_0x7995('0x24')](function(_0x1fc75e){_0x41e3aa[_0x7995('0x8e')]=_0x1fc75e;if(_0x1fc75e){var _0x1d907c={'ContactId':_0x1fc75e['id'],'OpenchannelAccountId':_0x340f6d[_0x7995('0x5b')]['id'],'from':(_0x1fc75e[_0x7995('0x8f')]||'')+'\x20'+(_0x1fc75e[_0x7995('0x90')]||'')};var _0x4254de={'OpenchannelAccountId':_0x340f6d[_0x7995('0x5b')]['id'],'closed':![]};if(_0x340f6d[_0x7995('0x60')][_0x7995('0x91')]){_0x4254de[_0x7995('0x91')]=_0x340f6d['body'][_0x7995('0x91')];return db[_0x7995('0x92')][_0x7995('0x5e')]({'where':_0x4254de})[_0x7995('0x24')](function(_0x59e356){if(_0x59e356){return[_0x59e356,![]];}_0x1d907c[_0x7995('0x91')]=_0x340f6d[_0x7995('0x60')][_0x7995('0x91')];_0x1d907c['externalUrl']=_0x340f6d[_0x7995('0x60')][_0x7995('0x93')];return db[_0x7995('0x92')][_0x7995('0x5f')](_0x1d907c)[_0x7995('0x24')](function(_0x3a7285){return[_0x3a7285,!![]];});});}else{_0x4254de[_0x7995('0x91')]=null;}_0x4254de['ContactId']=_0x1fc75e['id'];return db[_0x7995('0x92')]['find']({'where':_0x4254de})[_0x7995('0x24')](function(_0x164c61){if(_0x164c61){return[_0x164c61,![]];}return db[_0x7995('0x92')]['create'](_0x1d907c)[_0x7995('0x24')](function(_0x5a1892){return[_0x5a1892,!![]];});});}})['spread'](function(_0x4ee5ee,_0x4b3170){if(_0x4ee5ee){_0x3c6678=_0x4b3170;if(!_0x4b3170){var _0x31cbe6={'from':(_0x41e3aa[_0x7995('0x8e')]['firstName']||'')+'\x20'+(_0x41e3aa[_0x7995('0x8e')][_0x7995('0x90')]||'')};if(_0x340f6d['body'][_0x7995('0x91')]&&_0x340f6d[_0x7995('0x60')][_0x7995('0x94')]&&_0x340f6d[_0x7995('0x60')][_0x7995('0x91')]!=_0x340f6d['body'][_0x7995('0x94')]){_0x31cbe6[_0x7995('0x91')]=_0x340f6d[_0x7995('0x60')][_0x7995('0x94')];}return _0x4ee5ee['update'](_0x31cbe6);}else{return _0x4ee5ee;}}})[_0x7995('0x24')](function(_0x217ed4){_0x41e3aa[_0x7995('0x95')]=_0x217ed4[_0x7995('0x38')]({'plain':!![]});_0x41e3aa[_0x7995('0x95')][_0x7995('0x96')]=_0x3c6678;if(_0x41e3aa[_0x7995('0x95')][_0x7995('0x96')]){if(_0x41e3aa[_0x7995('0x89')][_0x7995('0x97')]){_0x41e3aa['applications'][_0x7995('0x98')]({'id':0x0,'priority':_0x41e3aa['applications'][_0x7995('0x5d')]+0x1,'app':_0x7995('0x99'),'appdata':_0x7995('0x9a'),'interval':'*,*,*,*'});}}return db['OpenchannelMessage'][_0x7995('0x5f')]({'body':_0x340f6d[_0x7995('0x60')]['body'],'OpenchannelAccountId':_0x340f6d[_0x7995('0x5b')]['id'],'OpenchannelInteractionId':_0x217ed4['id'],'direction':'in','ContactId':_0x41e3aa['contact']['id'],'AttachmentId':_0x340f6d[_0x7995('0x60')][_0x7995('0x9b')]});})[_0x7995('0x24')](function(_0x4e5667){_0x41e3aa['message']=_0x4e5667;if(_0x41e3aa['interaction'][_0x7995('0x9c')]){return db[_0x7995('0x9d')][_0x7995('0x5e')]({'attributes':['id',_0x7995('0x3c')],'where':{'id':_0x41e3aa['interaction'][_0x7995('0x9c')]}})[_0x7995('0x24')](function(_0x8b820b){if(_0x8b820b){_0x41e3aa[_0x7995('0x8a')][_0x7995('0x9e')]({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x8b820b['name']+','+(_0x41e3aa['account'][_0x7995('0x9f')]||0xa),'interval':_0x7995('0xa0')});_0x41e3aa['forcedOwnership']=![];}return respondWithRpcPromise(_0x7995('0xa1'),'startRouting',_0x41e3aa);});}return respondWithRpcPromise(_0x7995('0xa1'),_0x7995('0xa2'),_0x41e3aa);})[_0x7995('0x24')](function(_0x467913){respondWithRpcPromise('EventManager',_0x7995('0xa3'),{'event':_0x7995('0x74'),'message':_0x467913},client9002);return _0x467913;})[_0x7995('0x24')](respondWithResult(_0x227372,null))[_0x7995('0x59')](handleError(_0x227372,null));};exports[_0x7995('0xa4')]=function(_0x197adc,_0x1d200d,_0x152c2a){return db[_0x7995('0x42')][_0x7995('0xa5')]({'where':{'id':_0x197adc[_0x7995('0x5b')]['id']}})[_0x7995('0x24')](handleEntityNotFound(_0x1d200d,null))[_0x7995('0x24')](function(_0x2122af){if(_0x2122af){return db['sequelize'][_0x7995('0xa6')](function(_0x58e0c0){return db[_0x7995('0x88')][_0x7995('0x37')]({'where':{'OpenchannelAccountId':_0x197adc['params']['id']},'transaction':_0x58e0c0})[_0x7995('0x24')](function(_0x55dc6c){var _0x17c3f9=_[_0x7995('0x41')](_0x197adc['body'],function(_0x4985f3){_0x4985f3['OpenchannelAccountId']=_0x197adc[_0x7995('0x5b')]['id'];return _0x4985f3;});return db[_0x7995('0x88')][_0x7995('0xa7')](_0x17c3f9,{'transaction':_0x58e0c0});});})[_0x7995('0x24')](function(){return db['OpenchannelApplication'][_0x7995('0xa8')]({'where':{'OpenchannelAccountId':_0x197adc[_0x7995('0x5b')]['id']},'order':_0x7995('0xa9')});});}})[_0x7995('0x24')](respondWithResult(_0x1d200d,null))[_0x7995('0x59')](handleError(_0x1d200d,null));};exports[_0x7995('0xaa')]=function(_0x3e8479,_0x2b874e,_0x47f0d9){var _0x2e93a9={};var _0x5e12c4={};var _0x2cc43d;var _0x35f0f8;return db['OpenchannelAccount'][_0x7995('0xa5')]({'where':{'id':_0x3e8479[_0x7995('0x5b')]['id']}})[_0x7995('0x24')](handleEntityNotFound(_0x2b874e,null))[_0x7995('0x24')](function(_0x20949f){if(_0x20949f){_0x2cc43d=_0x20949f;_0x5e12c4[_0x7995('0x47')]=_['keys'](db[_0x7995('0x88')][_0x7995('0x43')]);_0x5e12c4[_0x7995('0x48')]=_[_0x7995('0x49')](_0x3e8479[_0x7995('0x48')]);_0x5e12c4[_0x7995('0x4e')]=_[_0x7995('0x5c')](_0x5e12c4[_0x7995('0x47')],_0x5e12c4[_0x7995('0x48')]);_0x2e93a9[_0x7995('0x4b')]=_[_0x7995('0x5c')](_0x5e12c4[_0x7995('0x47')],qs[_0x7995('0x4a')](_0x3e8479[_0x7995('0x48')][_0x7995('0x4a')]));_0x2e93a9[_0x7995('0x4b')]=_0x2e93a9[_0x7995('0x4b')][_0x7995('0x5d')]?_0x2e93a9[_0x7995('0x4b')]:_0x5e12c4[_0x7995('0x47')];_0x2e93a9[_0x7995('0x4c')]=qs['sort'](_0x3e8479['query'][_0x7995('0x4d')]);_0x2e93a9[_0x7995('0x51')]=qs['filters'](_[_0x7995('0x6d')](_0x3e8479['query'],_0x5e12c4[_0x7995('0x4e')]));if(_0x3e8479['query'][_0x7995('0x4f')]){_0x2e93a9[_0x7995('0x51')]=_[_0x7995('0x50')](_0x2e93a9[_0x7995('0x51')],{'$or':_[_0x7995('0x41')](_0x2e93a9[_0x7995('0x4b')],function(_0xd82313){var _0x1fa59d={};_0x1fa59d[_0xd82313]={'$like':'%'+_0x3e8479[_0x7995('0x48')][_0x7995('0x4f')]+'%'};return _0x1fa59d;})});}_0x2e93a9=_['merge']({},_0x2e93a9,_0x3e8479[_0x7995('0x53')]);return _0x2cc43d[_0x7995('0xaa')](_0x2e93a9);}})[_0x7995('0x24')](function(_0x3c83dd){if(_0x3c83dd){_0x35f0f8=_0x3c83dd['length'];if(!_0x3e8479[_0x7995('0x48')][_0x7995('0x6b')](_0x7995('0x6c'))){_0x2e93a9[_0x7995('0x31')]=qs['limit'](_0x3e8479[_0x7995('0x48')][_0x7995('0x31')]);_0x2e93a9[_0x7995('0x30')]=qs[_0x7995('0x30')](_0x3e8479[_0x7995('0x48')][_0x7995('0x30')]);}return _0x2cc43d[_0x7995('0xaa')](_0x2e93a9);}})[_0x7995('0x24')](function(_0x209aec){if(_0x209aec){return _0x209aec?{'count':_0x35f0f8,'rows':_0x209aec}:null;}})['then'](respondWithResult(_0x2b874e,null))[_0x7995('0x59')](handleError(_0x2b874e,null));};exports['getInteractions']=function(_0x363aad,_0x243d34,_0x35b217){var _0x19fa6d={'raw':![],'where':{}};var _0x4787b4={};var _0x40a98f={'count':0x0,'rows':[]};return db[_0x7995('0x42')][_0x7995('0xa5')]({'where':{'id':_0x363aad[_0x7995('0x5b')]['id']}})[_0x7995('0x24')](handleEntityNotFound(_0x243d34,null))[_0x7995('0x24')](function(_0x3661ab){if(_0x3661ab){_0x4787b4[_0x7995('0x47')]=_[_0x7995('0x49')](db[_0x7995('0x92')][_0x7995('0x43')]);_0x4787b4[_0x7995('0x48')]=_[_0x7995('0x49')](_0x363aad[_0x7995('0x48')]);_0x4787b4['filters']=_['intersection'](_0x4787b4[_0x7995('0x47')],_0x4787b4[_0x7995('0x48')]);_0x19fa6d[_0x7995('0x4b')]=_['intersection'](_0x4787b4[_0x7995('0x47')],qs[_0x7995('0x4a')](_0x363aad[_0x7995('0x48')]['fields']));_0x19fa6d[_0x7995('0x4b')]=_0x19fa6d[_0x7995('0x4b')][_0x7995('0x5d')]?_0x19fa6d[_0x7995('0x4b')]:_0x4787b4[_0x7995('0x47')];if(!_0x363aad[_0x7995('0x48')][_0x7995('0x6b')](_0x7995('0x6c'))){_0x19fa6d[_0x7995('0x31')]=qs[_0x7995('0x31')](_0x363aad[_0x7995('0x48')]['limit']);_0x19fa6d['offset']=qs[_0x7995('0x30')](_0x363aad['query'][_0x7995('0x30')]);}_0x19fa6d[_0x7995('0x4c')]=qs[_0x7995('0x4d')](_0x363aad[_0x7995('0x48')][_0x7995('0x4d')]);_0x19fa6d['where']=qs['filters'](_[_0x7995('0x6d')](_0x363aad[_0x7995('0x48')],_0x4787b4[_0x7995('0x4e')]));_0x19fa6d[_0x7995('0x51')][_0x7995('0x68')]=_0x3661ab['id'];if(_0x363aad[_0x7995('0x48')][_0x7995('0x4f')]){_0x19fa6d[_0x7995('0x51')]=_[_0x7995('0x50')](_0x19fa6d[_0x7995('0x51')],{'$or':_['map'](_0x19fa6d[_0x7995('0x4b')],function(_0x267ffa){var _0x38e67a={};_0x38e67a[_0x267ffa]={'$like':'%'+_0x363aad[_0x7995('0x48')]['filter']+'%'};return _0x38e67a;})});}_0x19fa6d=_['merge']({},_0x19fa6d,_0x363aad['options']);return db['OpenchannelInteraction']['count']({'where':_0x19fa6d[_0x7995('0x51')]})['then'](function(_0x4e55a8){_0x40a98f[_0x7995('0x54')]=_0x4e55a8;if(_0x363aad[_0x7995('0x48')][_0x7995('0x55')]){_0x19fa6d['include']=[{'model':db[_0x7995('0x76')],'as':'Contact','required':![]},{'model':db[_0x7995('0x9d')],'as':_0x7995('0xab'),'attributes':[_0x7995('0x3c'),'fullname',_0x7995('0xac')],'required':![]},{'model':db[_0x7995('0xad')],'as':_0x7995('0xae'),'attributes':['id','name',_0x7995('0xaf')],'where':_0x363aad[_0x7995('0x48')][_0x7995('0xb0')]?{'id':_0x363aad[_0x7995('0x48')][_0x7995('0xb0')]}:undefined,'required':_0x363aad['query'][_0x7995('0xb0')]?!![]:![]}];}return db[_0x7995('0x92')][_0x7995('0x57')](_0x19fa6d);})['then'](function(_0x20852c){_0x40a98f[_0x7995('0x58')]=_0x20852c;return _0x40a98f;});}})[_0x7995('0x24')](respondWithFilteredResult(_0x243d34,_0x19fa6d))[_0x7995('0x59')](handleError(_0x243d34,null));};exports[_0x7995('0xb1')]=function(_0x510dc8,_0x2995a3,_0x193f29){return db[_0x7995('0x42')][_0x7995('0x5e')]({'where':{'id':_0x510dc8[_0x7995('0x5b')]['id']}})[_0x7995('0x24')](handleEntityNotFound(_0x2995a3,null))[_0x7995('0x24')](function(_0x5baca7){if(_0x5baca7){return _0x5baca7['addAgents'](_0x510dc8[_0x7995('0x60')][_0x7995('0x6f')],_['omit'](_0x510dc8['body'],[_0x7995('0x6f'),'id'])||{})[_0x7995('0xb2')](function(_0xbf2fab){for(var _0x13eb92=0x0;_0x13eb92<_0x510dc8[_0x7995('0x60')][_0x7995('0x6f')][_0x7995('0x5d')];_0x13eb92+=0x1){socket['emit'](_0x7995('0xb3'),{'UserId':_0x510dc8[_0x7995('0x60')][_0x7995('0x6f')][_0x13eb92],'OpenchannelAccountId':_0x510dc8[_0x7995('0x5b')]['id']});}return _0xbf2fab;});}})[_0x7995('0x24')](respondWithResult(_0x2995a3,null))[_0x7995('0x59')](handleError(_0x2995a3,null));};exports['removeAgents']=function(_0x1d7c33,_0x406712,_0x1aefc3){return db[_0x7995('0x42')][_0x7995('0x5e')]({'where':{'id':_0x1d7c33[_0x7995('0x5b')]['id']}})[_0x7995('0x24')](handleEntityNotFound(_0x406712,null))['then'](function(_0x8c33c0){if(_0x8c33c0){return _0x8c33c0[_0x7995('0xb4')](_0x1d7c33[_0x7995('0x48')][_0x7995('0x6f')])['then'](function(){if(_[_0x7995('0xb5')](_0x1d7c33['query'][_0x7995('0x6f')])){for(var _0x440c83=0x0;_0x440c83<_0x1d7c33['query']['ids']['length'];_0x440c83+=0x1){socket[_0x7995('0xb6')](_0x7995('0xb7'),{'UserId':Number(_0x1d7c33[_0x7995('0x48')][_0x7995('0x6f')][_0x440c83]),'OpenchannelAccountId':Number(_0x1d7c33[_0x7995('0x5b')]['id'])});}}else{socket[_0x7995('0xb6')](_0x7995('0xb7'),{'UserId':Number(_0x1d7c33[_0x7995('0x48')][_0x7995('0x6f')]),'OpenchannelAccountId':Number(_0x1d7c33[_0x7995('0x5b')]['id'])});}});}})[_0x7995('0x24')](respondWithStatusCode(_0x406712,null))[_0x7995('0x59')](handleError(_0x406712,null));};exports['getAgents']=function(_0x5264dc,_0x2695eb,_0x4c66ad){var _0x58a2e8={};var _0x1a786e={};var _0x363250;var _0x3c8f6d;return db[_0x7995('0x42')][_0x7995('0xa5')]({'where':{'id':_0x5264dc[_0x7995('0x5b')]['id']}})[_0x7995('0x24')](handleEntityNotFound(_0x2695eb,null))[_0x7995('0x24')](function(_0x38ef8b){if(_0x38ef8b){_0x363250=_0x38ef8b;_0x1a786e[_0x7995('0x47')]=_[_0x7995('0x49')](db[_0x7995('0x9d')]['rawAttributes']);_0x1a786e[_0x7995('0x48')]=_[_0x7995('0x49')](_0x5264dc[_0x7995('0x48')]);_0x1a786e[_0x7995('0x4e')]=_[_0x7995('0x5c')](_0x1a786e[_0x7995('0x47')],_0x1a786e[_0x7995('0x48')]);_0x58a2e8['attributes']=_[_0x7995('0x5c')](_0x1a786e[_0x7995('0x47')],qs[_0x7995('0x4a')](_0x5264dc[_0x7995('0x48')][_0x7995('0x4a')]));_0x58a2e8['attributes']=_0x58a2e8[_0x7995('0x4b')]['length']?_0x58a2e8[_0x7995('0x4b')]:_0x1a786e[_0x7995('0x47')];_0x58a2e8[_0x7995('0x4c')]=qs['sort'](_0x5264dc[_0x7995('0x48')][_0x7995('0x4d')]);_0x58a2e8[_0x7995('0x51')]=qs[_0x7995('0x4e')](_[_0x7995('0x6d')](_0x5264dc[_0x7995('0x48')],_0x1a786e[_0x7995('0x4e')]));if(_0x5264dc['query']['filter']){_0x58a2e8[_0x7995('0x51')]=_[_0x7995('0x50')](_0x58a2e8[_0x7995('0x51')],{'$or':_[_0x7995('0x41')](_0x58a2e8[_0x7995('0x4b')],function(_0x10dd0c){var _0x552f15={};_0x552f15[_0x10dd0c]={'$like':'%'+_0x5264dc[_0x7995('0x48')][_0x7995('0x4f')]+'%'};return _0x552f15;})});}_0x58a2e8=_[_0x7995('0x50')]({},_0x58a2e8,_0x5264dc[_0x7995('0x53')]);return _0x363250['getAgents'](_0x58a2e8);}})['then'](function(_0x5b93e6){if(_0x5b93e6){_0x3c8f6d=_0x5b93e6[_0x7995('0x5d')];if(!_0x5264dc['query'][_0x7995('0x6b')](_0x7995('0x6c'))){_0x58a2e8['limit']=qs[_0x7995('0x31')](_0x5264dc[_0x7995('0x48')][_0x7995('0x31')]);_0x58a2e8[_0x7995('0x30')]=qs[_0x7995('0x30')](_0x5264dc['query']['offset']);}return _0x363250[_0x7995('0xb8')](_0x58a2e8);}})[_0x7995('0x24')](function(_0x2cfa1d){if(_0x2cfa1d){return _0x2cfa1d?{'count':_0x3c8f6d,'rows':_0x2cfa1d}:null;}})[_0x7995('0x24')](respondWithResult(_0x2695eb,null))[_0x7995('0x59')](handleError(_0x2695eb,null));};exports['send']=function(_0xd0da6e,_0x19eb9f,_0x3e3679){var _0x2d0bfa,_0x1949f5,_0x53b372;if(_['isNil'](_0xd0da6e['body']['body'])||_0xd0da6e[_0x7995('0x60')][_0x7995('0x60')]===''){throw new db['Sequelize'][(_0x7995('0x78'))](_0x7995('0x80'));}if(_['isNil'](_0xd0da6e['body']['to'])){}_0x2d0bfa=_0xd0da6e[_0x7995('0x60')]['to'];return db[_0x7995('0x42')][_0x7995('0xa5')]({'where':{'id':_0xd0da6e[_0x7995('0x5b')]['id']}})[_0x7995('0x24')](handleEntityNotFound(_0x19eb9f,null))[_0x7995('0x24')](function(_0x2aa426){if(_0x2aa426){return db['OpenchannelAccount']['find']({'where':{'id':_0x2aa426['id']},'include':[{'model':db[_0x7995('0x85')],'as':_0x7995('0x86'),'include':[{'model':db[_0x7995('0x76')],'as':'Contacts','where':{[_0x2aa426[_0x7995('0x83')]]:_0x2d0bfa},'limit':0x1,'order':[[_0x7995('0x7a'),_0x7995('0xb9')]]}]}]})[_0x7995('0x24')](handleEntityNotFound(_0x19eb9f,null))[_0x7995('0x24')](function(_0x812c9e){if(_0x812c9e&&_0x812c9e[_0x7995('0x86')]){_0x1949f5=_0x812c9e[_0x7995('0x38')]({'plain':!![]});if(_0x1949f5[_0x7995('0x86')]&&_0x1949f5['List']['Contacts'][_0x7995('0x5d')]){return _0x1949f5['List'][_0x7995('0x87')][0x0];}return db['CmContact'][_0x7995('0x5f')](_[_0x7995('0x1c')](_0xd0da6e[_0x7995('0x60')],{'firstName':_0x2d0bfa,[_0x812c9e['mapKey']]:_0x2d0bfa,'phone':_0x2d0bfa,'ListId':_0x1949f5['ListId']}));}})[_0x7995('0x24')](handleEntityNotFound(_0x19eb9f,null))[_0x7995('0x24')](function(_0x3ab4dd){if(_0x3ab4dd){_0x53b372=_0x3ab4dd;return db[_0x7995('0x92')][_0x7995('0x5e')]({'where':{'ContactId':_0x53b372['id'],'closed':![],'OpenchannelAccountId':_0x1949f5['id']}})[_0x7995('0x24')](function(_0xb0164a){if(_0xb0164a){return[_0xb0164a,![]];}return db[_0x7995('0x92')][_0x7995('0x5f')]({'UserId':_0xd0da6e[_0x7995('0x61')]['id'],'ContactId':_0x53b372['id'],'OpenchannelAccountId':_0x1949f5['id'],'lastMsgDirection':_0x7995('0xba'),'Messages':[_['merge'](_0xd0da6e[_0x7995('0x60')],{'read':![],'body':_0xd0da6e[_0x7995('0x60')][_0x7995('0x60')],'OpenchannelAccountId':_0x1949f5['id'],'UserId':_0xd0da6e[_0x7995('0x61')]['id'],'ContactId':_0x53b372['id']})]},{'include':[{'model':db[_0x7995('0xbb')],'as':'Messages'}]})[_0x7995('0x24')](function(_0x44068f){return[_0x44068f,!![]];});});}})[_0x7995('0xb2')](function(_0x3946cb,_0x3f3128){if(_0x3f3128){return _0x3946cb;}return db[_0x7995('0xbb')][_0x7995('0x5f')](_[_0x7995('0x50')](_0xd0da6e[_0x7995('0x60')],{'read':![],'body':_0xd0da6e['body']['body'],'OpenchannelAccountId':_0x1949f5['id'],'OpenchannelInteractionId':_0x3946cb['id'],'UserId':_0xd0da6e[_0x7995('0x61')]['id'],'ContactId':_0x53b372['id']}))[_0x7995('0x24')](function(_0x1cad65){_0x3946cb[_0x7995('0xbc')][_0x7995('0xbd')]=[];_0x3946cb['dataValues'][_0x7995('0xbd')][_0x7995('0x98')](_0x1cad65[_0x7995('0xbc')]);return _0x3946cb;});});}})[_0x7995('0x24')](respondWithResult(_0x19eb9f,null))[_0x7995('0x59')](handleError(_0x19eb9f,null));};
\ No newline at end of file
+var _0x1738=['orderBy','asc','contact','firstName','lastName','threadId','OpenchannelInteraction','externalUrl','ContactId','spread','messageId','interaction','created','autoclose','push','close','unmanaged','*,*,*,*','OpenchannelMessage','AttachmentId','UserId','User','unshift','waitForTheAssignedAgent','startRouting','Start','EventManager','addApplications','sequelize','transaction','Transaction','ISOLATION_LEVELS','READ_COMMITTED','OpenchannelApplication','bulkCreate','findAndCountAll','priority','getApplications','getInteractions','Contact','Owner','fullname','internal','Tag','tag','addAgents','emit','userOpenchannelAccount:save','removeAgents','isArray','userOpenchannelAccount:remove','getAgents','body\x20is\x20mandatory\x20and\x20not\x20empty','out','Messages','dataValues','eml-format','rimraf','request-promise','moment','bluebird','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','defaults','redis','localhost','socket.io-emitter','register','jayson/promise','client','http','request','then','info','request\x20sent','debug','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','OpenchannelAccount,\x20%s,\x20%s','message','result','catch','status','end','json','offset','undefined','limit','set','Content-Range','reject','save','update','destroy','get','OpenchannelAccounts','sendStatus','stack','send','Pause','mandatoryDispositionPause','map','rawAttributes','type','key','query','filters','intersection','attributes','model','fields','length','hasOwnProperty','nolimit','sort','where','filter','merge','VIRTUAL','options','OpenchannelAccount','count','include','findAll','params','keys','includeAll','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','user','UserProfileSection','userProfileId','UserProfileResource','name','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','Disposition','getDispositions','findOne','order','pick','OpenchannelAccountId','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','rows','removeAnswers','notify','openchannel','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','ListId','from','isNil','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','CmList','List','Contacts','DESC','Applications','account','applications','list'];(function(_0x4ce803,_0x35cd6b){var _0x384b19=function(_0x25d1ae){while(--_0x25d1ae){_0x4ce803['push'](_0x4ce803['shift']());}};_0x384b19(++_0x35cd6b);}(_0x1738,0x1bc));var _0x8173=function(_0x2553aa,_0x420113){_0x2553aa=_0x2553aa-0x0;var _0x315462=_0x1738[_0x2553aa];return _0x315462;};'use strict';var emlformat=require(_0x8173('0x0'));var rimraf=require(_0x8173('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x8173('0x2'));var moment=require(_0x8173('0x3'));var BPromise=require(_0x8173('0x4'));var Mustache=require('mustache');var util=require('util');var path=require(_0x8173('0x5'));var sox=require(_0x8173('0x6'));var csv=require(_0x8173('0x7'));var ejs=require(_0x8173('0x8'));var fs=require('fs');var fs_extra=require(_0x8173('0x9'));var _=require(_0x8173('0xa'));var squel=require(_0x8173('0xb'));var crypto=require(_0x8173('0xc'));var jsforce=require(_0x8173('0xd'));var deskjs=require(_0x8173('0xe'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x8173('0xf'));var Redis=require(_0x8173('0x10'));var authService=require(_0x8173('0x11'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x8173('0x12'));var logger=require(_0x8173('0x13'))(_0x8173('0x14'));var utils=require(_0x8173('0x15'));var config=require(_0x8173('0x16'));var licenseUtil=require('../../config/license/util');var db=require(_0x8173('0x17'))['db'];config['redis']=_[_0x8173('0x18')](config[_0x8173('0x19')],{'host':_0x8173('0x1a'),'port':0x18eb});var socket=require(_0x8173('0x1b'))(new Redis(config[_0x8173('0x19')]));require('./openchannelAccount.socket')[_0x8173('0x1c')](socket);var jayson=require(_0x8173('0x1d'));var client=jayson[_0x8173('0x1e')]['http']({'port':0x232c});var client9002=jayson['client'][_0x8173('0x1f')]({'port':0x232a});function respondWithRpcPromise(_0x40bf0e,_0x2e7ca5,_0x58fcf1,_0x2932b2){return new BPromise(function(_0x114b42,_0x4d1fa2){var _0x70e7fc=_0x2932b2||client;return _0x70e7fc[_0x8173('0x20')](_0x40bf0e,_0x58fcf1)[_0x8173('0x21')](function(_0x312eae){logger[_0x8173('0x22')]('OpenchannelAccount,\x20%s,\x20%s',_0x2e7ca5,_0x8173('0x23'));logger[_0x8173('0x24')](_0x8173('0x25'),_0x2e7ca5,_0x8173('0x23'),JSON[_0x8173('0x26')](_0x312eae));if(_0x312eae[_0x8173('0x27')]){if(_0x312eae[_0x8173('0x27')][_0x8173('0x28')]===0x1f4){logger[_0x8173('0x27')](_0x8173('0x29'),_0x2e7ca5,_0x312eae['error'][_0x8173('0x2a')]);return _0x4d1fa2(_0x312eae[_0x8173('0x27')]['message']);}logger[_0x8173('0x27')]('OpenchannelAccount,\x20%s,\x20%s',_0x2e7ca5,_0x312eae[_0x8173('0x27')]['message']);return _0x114b42(_0x312eae[_0x8173('0x27')]['message']);}else{logger[_0x8173('0x22')](_0x8173('0x29'),_0x2e7ca5,'request\x20sent');_0x114b42(_0x312eae[_0x8173('0x2b')]['message']);}})[_0x8173('0x2c')](function(_0x189acd){logger[_0x8173('0x27')](_0x8173('0x29'),_0x2e7ca5,_0x189acd);_0x4d1fa2(_0x189acd);});});}function respondWithStatusCode(_0x273820,_0x39cb27){_0x39cb27=_0x39cb27||0xcc;return function(_0x27b92a){if(_0x27b92a){return _0x273820['sendStatus'](_0x39cb27);}return _0x273820[_0x8173('0x2d')](_0x39cb27)[_0x8173('0x2e')]();};}function respondWithResult(_0x4fbe19,_0x52c249){_0x52c249=_0x52c249||0xc8;return function(_0x2eea21){if(_0x2eea21){return _0x4fbe19[_0x8173('0x2d')](_0x52c249)[_0x8173('0x2f')](_0x2eea21);}};}function respondWithFilteredResult(_0x5ee6e0,_0x50a935){return function(_0x223a9c){if(_0x223a9c){var _0x469a51=typeof _0x50a935[_0x8173('0x30')]===_0x8173('0x31')&&typeof _0x50a935['limit']===_0x8173('0x31');var _0x547b3a=_0x223a9c['count'];var _0xb2f261=_0x469a51?0x0:_0x50a935[_0x8173('0x30')];var _0x4c8b01=_0x469a51?_0x223a9c['count']:_0x50a935[_0x8173('0x30')]+_0x50a935[_0x8173('0x32')];var _0x36c282;if(_0x4c8b01>=_0x547b3a){_0x4c8b01=_0x547b3a;_0x36c282=0xc8;}else{_0x36c282=0xce;}_0x5ee6e0['status'](_0x36c282);return _0x5ee6e0[_0x8173('0x33')](_0x8173('0x34'),_0xb2f261+'-'+_0x4c8b01+'/'+_0x547b3a)[_0x8173('0x2f')](_0x223a9c);}return null;};}function patchUpdates(_0x464998){return function(_0x262222){try{jsonpatch['apply'](_0x262222,_0x464998,!![]);}catch(_0x448e32){return BPromise[_0x8173('0x35')](_0x448e32);}return _0x262222[_0x8173('0x36')]();};}function saveUpdates(_0x5c27ba,_0x2d7823){return function(_0x2aa38f){if(_0x2aa38f){return _0x2aa38f[_0x8173('0x37')](_0x5c27ba)[_0x8173('0x21')](function(_0x16a4a2){return _0x16a4a2;});}return null;};}function removeEntity(_0x41ae06,_0x2dea9a){return function(_0x29a6b6){if(_0x29a6b6){return _0x29a6b6[_0x8173('0x38')]()['then'](function(){var _0x46bde2=_0x29a6b6[_0x8173('0x39')]({'plain':!![]});var _0x1ba0bb=_0x8173('0x3a');return db['UserProfileResource'][_0x8173('0x38')]({'where':{'type':_0x1ba0bb,'resourceId':_0x46bde2['id']}})[_0x8173('0x21')](function(){return _0x29a6b6;});})[_0x8173('0x21')](function(){_0x41ae06[_0x8173('0x2d')](0xcc)['end']();});}};}function handleEntityNotFound(_0x40395d,_0x257619){return function(_0x45888a){if(!_0x45888a){_0x40395d[_0x8173('0x3b')](0x194);}return _0x45888a;};}function handleError(_0x5c5bf4,_0x4416e8){_0x4416e8=_0x4416e8||0x1f4;return function(_0x2ab1e4){logger[_0x8173('0x27')](_0x2ab1e4[_0x8173('0x3c')]);if(_0x2ab1e4['name']){delete _0x2ab1e4['name'];}_0x5c5bf4['status'](_0x4416e8)[_0x8173('0x3d')](_0x2ab1e4);};}exports['index']=function(_0x36dcb8,_0x4c36ae){var _0x5c2eef={'include':[{'model':db[_0x8173('0x3e')],'as':_0x8173('0x3f')}]},_0x2247fd={},_0xc6875b={'count':0x0,'rows':[]};var _0x374c51=_[_0x8173('0x40')](db['OpenchannelAccount'][_0x8173('0x41')],function(_0x34651a){return{'name':_0x34651a['fieldName'],'type':_0x34651a[_0x8173('0x42')][_0x8173('0x43')]};});_0x2247fd['model']=_[_0x8173('0x40')](_0x374c51,'name');_0x2247fd['query']=_['keys'](_0x36dcb8[_0x8173('0x44')]);_0x2247fd[_0x8173('0x45')]=_[_0x8173('0x46')](_0x2247fd['model'],_0x2247fd[_0x8173('0x44')]);_0x5c2eef[_0x8173('0x47')]=_[_0x8173('0x46')](_0x2247fd[_0x8173('0x48')],qs[_0x8173('0x49')](_0x36dcb8[_0x8173('0x44')][_0x8173('0x49')]));_0x5c2eef['attributes']=_0x5c2eef[_0x8173('0x47')][_0x8173('0x4a')]?_0x5c2eef[_0x8173('0x47')]:_0x2247fd[_0x8173('0x48')];if(!_0x36dcb8[_0x8173('0x44')][_0x8173('0x4b')](_0x8173('0x4c'))){_0x5c2eef['limit']=qs[_0x8173('0x32')](_0x36dcb8[_0x8173('0x44')][_0x8173('0x32')]);_0x5c2eef[_0x8173('0x30')]=qs[_0x8173('0x30')](_0x36dcb8[_0x8173('0x44')]['offset']);}_0x5c2eef['order']=qs[_0x8173('0x4d')](_0x36dcb8[_0x8173('0x44')]['sort']);_0x5c2eef[_0x8173('0x4e')]=qs['filters'](_['pick'](_0x36dcb8[_0x8173('0x44')],_0x2247fd[_0x8173('0x45')]),_0x374c51);if(_0x36dcb8[_0x8173('0x44')][_0x8173('0x4f')]){_0x5c2eef[_0x8173('0x4e')]=_[_0x8173('0x50')](_0x5c2eef[_0x8173('0x4e')],{'$or':_[_0x8173('0x40')](_0x374c51,function(_0x2194de){if(_0x2194de[_0x8173('0x42')]!==_0x8173('0x51')){var _0x22d907={};_0x22d907[_0x2194de['name']]={'$like':'%'+_0x36dcb8['query'][_0x8173('0x4f')]+'%'};return _0x22d907;}})});}_0x5c2eef=_[_0x8173('0x50')]({},_0x5c2eef,_0x36dcb8[_0x8173('0x52')]);var _0x426d6={'where':_0x5c2eef[_0x8173('0x4e')]};return db[_0x8173('0x53')][_0x8173('0x54')](_0x426d6)[_0x8173('0x21')](function(_0x2f04bb){_0xc6875b[_0x8173('0x54')]=_0x2f04bb;if(_0x36dcb8[_0x8173('0x44')]['includeAll']){_0x5c2eef[_0x8173('0x55')]=[{'all':!![]}];}return db['OpenchannelAccount'][_0x8173('0x56')](_0x5c2eef);})[_0x8173('0x21')](function(_0x565e06){_0xc6875b['rows']=_0x565e06;return _0xc6875b;})[_0x8173('0x21')](respondWithFilteredResult(_0x4c36ae,_0x5c2eef))[_0x8173('0x2c')](handleError(_0x4c36ae,null));};exports['show']=function(_0xeb218e,_0x5ab9e1){var _0x5d06c3={'raw':![],'where':{'id':_0xeb218e[_0x8173('0x57')]['id']},'include':[{'model':db[_0x8173('0x3e')],'as':_0x8173('0x3f')}]},_0x4c8ee0={};_0x4c8ee0[_0x8173('0x48')]=_['keys'](db[_0x8173('0x53')][_0x8173('0x41')]);_0x4c8ee0[_0x8173('0x44')]=_[_0x8173('0x58')](_0xeb218e[_0x8173('0x44')]);_0x4c8ee0[_0x8173('0x45')]=_['intersection'](_0x4c8ee0[_0x8173('0x48')],_0x4c8ee0[_0x8173('0x44')]);_0x5d06c3[_0x8173('0x47')]=_[_0x8173('0x46')](_0x4c8ee0[_0x8173('0x48')],qs['fields'](_0xeb218e[_0x8173('0x44')][_0x8173('0x49')]));_0x5d06c3[_0x8173('0x47')]=_0x5d06c3[_0x8173('0x47')]['length']?_0x5d06c3[_0x8173('0x47')]:_0x4c8ee0[_0x8173('0x48')];if(_0xeb218e['query'][_0x8173('0x59')]){_0x5d06c3[_0x8173('0x55')]=[{'all':!![]}];}_0x5d06c3=_[_0x8173('0x50')]({},_0x5d06c3,_0xeb218e[_0x8173('0x52')]);return db[_0x8173('0x53')][_0x8173('0x5a')](_0x5d06c3)[_0x8173('0x21')](handleEntityNotFound(_0x5ab9e1,null))[_0x8173('0x21')](respondWithResult(_0x5ab9e1,null))[_0x8173('0x2c')](handleError(_0x5ab9e1,null));};exports['create']=function(_0x1dab4a,_0x3e4d5e){return db[_0x8173('0x53')][_0x8173('0x5b')](_0x1dab4a[_0x8173('0x5c')],{})[_0x8173('0x21')](function(_0x551bf0){var _0x2feeff=_0x1dab4a['user']['get']({'plain':!![]});if(!_0x2feeff)throw new Error(_0x8173('0x5d'));if(_0x2feeff['role']===_0x8173('0x5e')){var _0x580f5c=_0x551bf0[_0x8173('0x39')]({'plain':!![]});var _0x7f471c='OpenchannelAccounts';return db[_0x8173('0x5f')][_0x8173('0x5a')]({'where':{'name':_0x7f471c,'userProfileId':_0x2feeff[_0x8173('0x60')]},'raw':!![]})[_0x8173('0x21')](function(_0x5f280b){if(_0x5f280b&&_0x5f280b['autoAssociation']===0x0){return db[_0x8173('0x61')][_0x8173('0x5b')]({'name':_0x580f5c[_0x8173('0x62')],'resourceId':_0x580f5c['id'],'type':_0x5f280b[_0x8173('0x62')],'sectionId':_0x5f280b['id']},{})[_0x8173('0x21')](function(){return _0x551bf0;});}else{return _0x551bf0;}})['catch'](function(_0x52b3df){logger[_0x8173('0x27')](_0x8173('0x63'),_0x52b3df);throw _0x52b3df;});}return _0x551bf0;})[_0x8173('0x21')](respondWithResult(_0x3e4d5e,0xc9))[_0x8173('0x2c')](handleError(_0x3e4d5e,null));};exports['update']=function(_0x5148e4,_0x3890c7){if(_0x5148e4['body']['id']){delete _0x5148e4[_0x8173('0x5c')]['id'];}return db[_0x8173('0x53')][_0x8173('0x5a')]({'where':{'id':_0x5148e4[_0x8173('0x57')]['id']},'include':[{'model':db[_0x8173('0x3e')],'as':'mandatoryDispositionPause'}]})[_0x8173('0x21')](handleEntityNotFound(_0x3890c7,null))[_0x8173('0x21')](saveUpdates(_0x5148e4[_0x8173('0x5c')],null))[_0x8173('0x21')](respondWithResult(_0x3890c7,null))[_0x8173('0x2c')](handleError(_0x3890c7,null));};exports['destroy']=function(_0x1775f8,_0x4cf730){return db[_0x8173('0x53')]['find']({'where':{'id':_0x1775f8[_0x8173('0x57')]['id']}})[_0x8173('0x21')](handleEntityNotFound(_0x4cf730,null))[_0x8173('0x21')](removeEntity(_0x4cf730,null))['catch'](handleError(_0x4cf730,null));};exports[_0x8173('0x64')]=function(_0x353c0c,_0x41233c){return db['OpenchannelAccount'][_0x8173('0x64')]()['then'](respondWithResult(_0x41233c,null))[_0x8173('0x2c')](handleError(_0x41233c,null));};exports['addDisposition']=function(_0x182ccc,_0x3d79ef,_0x13373a){if(_0x182ccc[_0x8173('0x5c')]['id']){delete _0x182ccc[_0x8173('0x5c')]['id'];}return db[_0x8173('0x53')][_0x8173('0x5a')]({'where':{'id':_0x182ccc['params']['id']}})[_0x8173('0x21')](handleEntityNotFound(_0x3d79ef,null))[_0x8173('0x21')](function(_0x3293e4){if(_0x3293e4){_0x182ccc[_0x8173('0x5c')]['OpenchannelAccountId']=_0x3293e4['id'];return db[_0x8173('0x65')][_0x8173('0x5b')](_0x182ccc[_0x8173('0x5c')]);}})[_0x8173('0x21')](respondWithResult(_0x3d79ef,null))[_0x8173('0x2c')](handleError(_0x3d79ef,null));};exports[_0x8173('0x66')]=function(_0x4290c2,_0x2fb923,_0x56d3d8){var _0x56b779={'raw':![],'where':{}};var _0x5568e1={};var _0x363c04={'count':0x0,'rows':[]};return db['OpenchannelAccount'][_0x8173('0x67')]({'where':{'id':_0x4290c2[_0x8173('0x57')]['id']}})[_0x8173('0x21')](handleEntityNotFound(_0x2fb923,null))[_0x8173('0x21')](function(_0x3b0fe3){if(_0x3b0fe3){_0x5568e1[_0x8173('0x48')]=_[_0x8173('0x58')](db[_0x8173('0x65')]['rawAttributes']);_0x5568e1[_0x8173('0x44')]=_[_0x8173('0x58')](_0x4290c2[_0x8173('0x44')]);_0x5568e1[_0x8173('0x45')]=_[_0x8173('0x46')](_0x5568e1[_0x8173('0x48')],_0x5568e1['query']);_0x56b779[_0x8173('0x47')]=_[_0x8173('0x46')](_0x5568e1['model'],qs['fields'](_0x4290c2[_0x8173('0x44')][_0x8173('0x49')]));_0x56b779[_0x8173('0x47')]=_0x56b779[_0x8173('0x47')][_0x8173('0x4a')]?_0x56b779[_0x8173('0x47')]:_0x5568e1[_0x8173('0x48')];if(!_0x4290c2[_0x8173('0x44')][_0x8173('0x4b')](_0x8173('0x4c'))){_0x56b779[_0x8173('0x32')]=qs[_0x8173('0x32')](_0x4290c2[_0x8173('0x44')]['limit']);_0x56b779[_0x8173('0x30')]=qs[_0x8173('0x30')](_0x4290c2[_0x8173('0x44')][_0x8173('0x30')]);}_0x56b779[_0x8173('0x68')]=qs[_0x8173('0x4d')](_0x4290c2['query'][_0x8173('0x4d')]);_0x56b779['where']=qs[_0x8173('0x45')](_[_0x8173('0x69')](_0x4290c2[_0x8173('0x44')],_0x5568e1[_0x8173('0x45')]));_0x56b779[_0x8173('0x4e')][_0x8173('0x6a')]=_0x3b0fe3['id'];if(_0x4290c2['query']['filter']){_0x56b779[_0x8173('0x4e')]=_[_0x8173('0x50')](_0x56b779[_0x8173('0x4e')],{'$or':_[_0x8173('0x40')](_0x56b779[_0x8173('0x47')],function(_0x14494e){var _0x260c00={};_0x260c00[_0x14494e]={'$like':'%'+_0x4290c2[_0x8173('0x44')][_0x8173('0x4f')]+'%'};return _0x260c00;})});}_0x56b779=_[_0x8173('0x50')]({},_0x56b779,_0x4290c2[_0x8173('0x52')]);return db['Disposition'][_0x8173('0x54')]({'where':_0x56b779['where']})[_0x8173('0x21')](function(_0x4eb89a){_0x363c04[_0x8173('0x54')]=_0x4eb89a;if(_0x4290c2[_0x8173('0x44')][_0x8173('0x59')]){_0x56b779[_0x8173('0x55')]=[{'all':!![]}];}return db[_0x8173('0x65')][_0x8173('0x56')](_0x56b779);})['then'](function(_0x15a48f){_0x363c04['rows']=_0x15a48f;return _0x363c04;});}})[_0x8173('0x21')](respondWithFilteredResult(_0x2fb923,_0x56b779))[_0x8173('0x2c')](handleError(_0x2fb923,null));};exports['removeDispositions']=function(_0x5322d3,_0x45b5d1,_0x498dc6){return db[_0x8173('0x53')][_0x8173('0x5a')]({'where':{'id':_0x5322d3['params']['id']}})['then'](handleEntityNotFound(_0x45b5d1,null))[_0x8173('0x21')](function(_0x2a2603){if(_0x2a2603){return _0x2a2603[_0x8173('0x6b')](_0x5322d3['query'][_0x8173('0x6c')]);}})['then'](respondWithStatusCode(_0x45b5d1,null))['catch'](handleError(_0x45b5d1,null));};exports[_0x8173('0x6d')]=function(_0x31cab8,_0x22727d,_0x1bbea4){if(_0x31cab8[_0x8173('0x5c')]['id']){delete _0x31cab8['body']['id'];}return db[_0x8173('0x53')][_0x8173('0x5a')]({'where':{'id':_0x31cab8['params']['id']}})[_0x8173('0x21')](handleEntityNotFound(_0x22727d,null))[_0x8173('0x21')](function(_0x39ed10){if(_0x39ed10){_0x31cab8[_0x8173('0x5c')][_0x8173('0x6a')]=_0x39ed10['id'];return db[_0x8173('0x6e')][_0x8173('0x5b')](_0x31cab8['body']);}})[_0x8173('0x21')](respondWithResult(_0x22727d,null))['catch'](handleError(_0x22727d,null));};exports[_0x8173('0x6f')]=function(_0x3c78f1,_0x45c8e6,_0x25de7e){var _0x40aeea={'raw':![],'where':{}};var _0x367f80={};var _0x3d3ce5={'count':0x0,'rows':[]};return db[_0x8173('0x53')][_0x8173('0x67')]({'where':{'id':_0x3c78f1[_0x8173('0x57')]['id']}})['then'](handleEntityNotFound(_0x45c8e6,null))['then'](function(_0x24f500){if(_0x24f500){_0x367f80[_0x8173('0x48')]=_[_0x8173('0x58')](db['CannedAnswer'][_0x8173('0x41')]);_0x367f80[_0x8173('0x44')]=_[_0x8173('0x58')](_0x3c78f1[_0x8173('0x44')]);_0x367f80[_0x8173('0x45')]=_[_0x8173('0x46')](_0x367f80['model'],_0x367f80[_0x8173('0x44')]);_0x40aeea[_0x8173('0x47')]=_[_0x8173('0x46')](_0x367f80[_0x8173('0x48')],qs['fields'](_0x3c78f1[_0x8173('0x44')][_0x8173('0x49')]));_0x40aeea[_0x8173('0x47')]=_0x40aeea['attributes'][_0x8173('0x4a')]?_0x40aeea[_0x8173('0x47')]:_0x367f80[_0x8173('0x48')];if(!_0x3c78f1['query']['hasOwnProperty'](_0x8173('0x4c'))){_0x40aeea[_0x8173('0x32')]=qs[_0x8173('0x32')](_0x3c78f1['query'][_0x8173('0x32')]);_0x40aeea[_0x8173('0x30')]=qs[_0x8173('0x30')](_0x3c78f1[_0x8173('0x44')][_0x8173('0x30')]);}_0x40aeea[_0x8173('0x68')]=qs[_0x8173('0x4d')](_0x3c78f1[_0x8173('0x44')][_0x8173('0x4d')]);_0x40aeea[_0x8173('0x4e')]=qs[_0x8173('0x45')](_[_0x8173('0x69')](_0x3c78f1[_0x8173('0x44')],_0x367f80[_0x8173('0x45')]));_0x40aeea['where']['OpenchannelAccountId']=_0x24f500['id'];if(_0x3c78f1[_0x8173('0x44')][_0x8173('0x4f')]){_0x40aeea['where']=_[_0x8173('0x50')](_0x40aeea[_0x8173('0x4e')],{'$or':_[_0x8173('0x40')](_0x40aeea[_0x8173('0x47')],function(_0x4100c8){var _0x533596={};_0x533596[_0x4100c8]={'$like':'%'+_0x3c78f1[_0x8173('0x44')][_0x8173('0x4f')]+'%'};return _0x533596;})});}_0x40aeea=_['merge']({},_0x40aeea,_0x3c78f1[_0x8173('0x52')]);return db['CannedAnswer'][_0x8173('0x54')]({'where':_0x40aeea[_0x8173('0x4e')]})['then'](function(_0x189484){_0x3d3ce5[_0x8173('0x54')]=_0x189484;if(_0x3c78f1[_0x8173('0x44')][_0x8173('0x59')]){_0x40aeea[_0x8173('0x55')]=[{'all':!![]}];}return db[_0x8173('0x6e')]['findAll'](_0x40aeea);})[_0x8173('0x21')](function(_0x2da352){_0x3d3ce5[_0x8173('0x70')]=_0x2da352;return _0x3d3ce5;});}})['then'](respondWithFilteredResult(_0x45c8e6,_0x40aeea))[_0x8173('0x2c')](handleError(_0x45c8e6,null));};exports[_0x8173('0x71')]=function(_0x17a47d,_0x518a1e,_0x51a996){return db[_0x8173('0x53')][_0x8173('0x5a')]({'where':{'id':_0x17a47d['params']['id']}})['then'](handleEntityNotFound(_0x518a1e,null))[_0x8173('0x21')](function(_0x34735c){if(_0x34735c){return _0x34735c[_0x8173('0x71')](_0x17a47d[_0x8173('0x44')][_0x8173('0x6c')]);}})[_0x8173('0x21')](respondWithStatusCode(_0x518a1e,null))[_0x8173('0x2c')](handleError(_0x518a1e,null));};exports[_0x8173('0x72')]=function(_0x3f63b1,_0x13b259,_0x2793a5){var _0x54801f={'body':_0x3f63b1[_0x8173('0x5c')],'channel':_0x8173('0x73')};var _0x32f6ae=[];var _0x4d304c=[];var _0x547d22={};var _0x22979f=![];return db[_0x8173('0x74')][_0x8173('0x64')]()[_0x8173('0x21')](function(_0x33b49e){if(!_0x33b49e){throw new db[(_0x8173('0x75'))][(_0x8173('0x76'))](_0x8173('0x77'));}_0x32f6ae=_[_0x8173('0x78')](_[_0x8173('0x58')](_0x33b49e),[_0x8173('0x79'),_0x8173('0x7a')]);_0x4d304c=_['difference'](_[_0x8173('0x58')](_0x33b49e),[_0x8173('0x79'),_0x8173('0x7a'),_0x8173('0x7b'),_0x8173('0x7c')]);if(_0x3f63b1[_0x8173('0x5c')]['id']){delete _0x3f63b1[_0x8173('0x5c')]['id'];}if(_['isNil'](_0x3f63b1['body'][_0x8173('0x7d')])){throw new db[(_0x8173('0x75'))][(_0x8173('0x76'))]('from\x20is\x20mandatory');}if(_['isNil'](_0x3f63b1[_0x8173('0x5c')][_0x8173('0x5c')])||_0x3f63b1[_0x8173('0x5c')][_0x8173('0x5c')]===''){throw new db[(_0x8173('0x75'))][(_0x8173('0x76'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x8173('0x7e')](_0x3f63b1[_0x8173('0x5c')][_0x8173('0x7f')])){throw new db[(_0x8173('0x75'))][(_0x8173('0x76'))](_0x8173('0x80')+_0x4d304c);}if(!_[_0x8173('0x81')](_0x4d304c,_0x3f63b1[_0x8173('0x5c')][_0x8173('0x7f')])){throw new db[(_0x8173('0x75'))][(_0x8173('0x76'))]('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x4d304c);}_0x547d22[_0x3f63b1[_0x8173('0x5c')][_0x8173('0x7f')]]=_0x3f63b1[_0x8173('0x5c')]['from'];})[_0x8173('0x21')](function(){return db[_0x8173('0x53')][_0x8173('0x5a')]({'where':{'id':_0x3f63b1[_0x8173('0x57')]['id']},'include':[{'model':db[_0x8173('0x82')],'as':_0x8173('0x83'),'include':[{'model':db['CmContact'],'as':_0x8173('0x84'),'where':_0x547d22,'limit':0x1,'order':[[_0x8173('0x7a'),_0x8173('0x85')]]}]},{'model':db['OpenchannelApplication'],'as':_0x8173('0x86')}]});})[_0x8173('0x21')](handleEntityNotFound(_0x13b259,null))['then'](function(_0x406298){if(_0x406298&&_0x406298[_0x8173('0x83')]){_0x54801f[_0x8173('0x87')]=_0x406298;_0x54801f[_0x8173('0x88')]=_0x406298[_0x8173('0x86')];_0x54801f[_0x8173('0x89')]=_0x406298['List'];_0x54801f[_0x8173('0x88')]=_[_0x8173('0x8a')](_0x54801f[_0x8173('0x88')],['priority'],[_0x8173('0x8b')]);if(_0x54801f[_0x8173('0x87')][_0x8173('0x86')]){delete _0x54801f[_0x8173('0x87')][_0x8173('0x86')];}if(_0x54801f[_0x8173('0x87')][_0x8173('0x83')]&&_0x54801f[_0x8173('0x87')][_0x8173('0x83')]['Contacts'][_0x8173('0x4a')]){return _0x54801f[_0x8173('0x87')][_0x8173('0x83')][_0x8173('0x84')][0x0];}var _0x33151a=_[_0x8173('0x18')](_0x3f63b1[_0x8173('0x5c')],{'firstName':_0x3f63b1[_0x8173('0x5c')][_0x8173('0x7d')],'ListId':_0x406298[_0x8173('0x7c')]});_0x33151a[_0x3f63b1[_0x8173('0x5c')]['mapKey']]=_0x3f63b1[_0x8173('0x5c')]['from'];return db['CmContact'][_0x8173('0x5b')](_0x33151a,{'fields':_0x32f6ae,'raw':!![]});}})[_0x8173('0x21')](handleEntityNotFound(_0x13b259,null))[_0x8173('0x21')](function(_0xec2ba4){_0x54801f[_0x8173('0x8c')]=_0xec2ba4;if(_0xec2ba4){var _0x34bba0={'ContactId':_0xec2ba4['id'],'OpenchannelAccountId':_0x3f63b1[_0x8173('0x57')]['id'],'from':(_0xec2ba4[_0x8173('0x8d')]||'')+'\x20'+(_0xec2ba4[_0x8173('0x8e')]||'')};var _0x538ffd={'OpenchannelAccountId':_0x3f63b1[_0x8173('0x57')]['id'],'closed':![]};if(_0x3f63b1[_0x8173('0x5c')][_0x8173('0x8f')]){_0x538ffd['threadId']=_0x3f63b1['body'][_0x8173('0x8f')];return db[_0x8173('0x90')]['find']({'where':_0x538ffd})[_0x8173('0x21')](function(_0x1992be){if(_0x1992be){return[_0x1992be,![]];}_0x34bba0[_0x8173('0x8f')]=_0x3f63b1[_0x8173('0x5c')][_0x8173('0x8f')];_0x34bba0[_0x8173('0x91')]=_0x3f63b1[_0x8173('0x5c')][_0x8173('0x91')];return db[_0x8173('0x90')][_0x8173('0x5b')](_0x34bba0)[_0x8173('0x21')](function(_0x2268ac){return[_0x2268ac,!![]];});});}else{_0x538ffd[_0x8173('0x8f')]=null;}_0x538ffd[_0x8173('0x92')]=_0xec2ba4['id'];return db[_0x8173('0x90')][_0x8173('0x5a')]({'where':_0x538ffd})[_0x8173('0x21')](function(_0xa7cece){if(_0xa7cece){return[_0xa7cece,![]];}return db['OpenchannelInteraction'][_0x8173('0x5b')](_0x34bba0)[_0x8173('0x21')](function(_0x5c480e){return[_0x5c480e,!![]];});});}})[_0x8173('0x93')](function(_0x10a060,_0x4cf1ca){if(_0x10a060){_0x22979f=_0x4cf1ca;if(!_0x4cf1ca){var _0x2e7dd4={'from':(_0x54801f[_0x8173('0x8c')][_0x8173('0x8d')]||'')+'\x20'+(_0x54801f[_0x8173('0x8c')][_0x8173('0x8e')]||'')};if(_0x3f63b1['body'][_0x8173('0x8f')]&&_0x3f63b1['body'][_0x8173('0x94')]&&_0x3f63b1[_0x8173('0x5c')][_0x8173('0x8f')]!=_0x3f63b1[_0x8173('0x5c')][_0x8173('0x94')]){_0x2e7dd4[_0x8173('0x8f')]=_0x3f63b1[_0x8173('0x5c')][_0x8173('0x94')];}return _0x10a060[_0x8173('0x37')](_0x2e7dd4);}else{return _0x10a060;}}})[_0x8173('0x21')](function(_0x12fdbd){_0x54801f['interaction']=_0x12fdbd[_0x8173('0x39')]({'plain':!![]});_0x54801f[_0x8173('0x95')]['created']=_0x22979f;if(_0x54801f['interaction'][_0x8173('0x96')]){if(_0x54801f[_0x8173('0x87')][_0x8173('0x97')]){_0x54801f[_0x8173('0x88')][_0x8173('0x98')]({'id':0x0,'priority':_0x54801f['applications'][_0x8173('0x4a')]+0x1,'app':_0x8173('0x99'),'appdata':_0x8173('0x9a'),'interval':_0x8173('0x9b')});}}return db[_0x8173('0x9c')][_0x8173('0x5b')]({'body':_0x3f63b1[_0x8173('0x5c')][_0x8173('0x5c')],'OpenchannelAccountId':_0x3f63b1[_0x8173('0x57')]['id'],'OpenchannelInteractionId':_0x12fdbd['id'],'direction':'in','ContactId':_0x54801f[_0x8173('0x8c')]['id'],'AttachmentId':_0x3f63b1[_0x8173('0x5c')][_0x8173('0x9d')]});})[_0x8173('0x21')](function(_0x42ddb6){_0x54801f['message']=_0x42ddb6;if(_0x54801f['interaction'][_0x8173('0x9e')]){return db[_0x8173('0x9f')]['find']({'attributes':['id','name'],'where':{'id':_0x54801f[_0x8173('0x95')]['UserId']}})[_0x8173('0x21')](function(_0x5abf83){if(_0x5abf83){_0x54801f[_0x8173('0x88')][_0x8173('0xa0')]({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x5abf83[_0x8173('0x62')]+','+(_0x54801f[_0x8173('0x87')][_0x8173('0xa1')]||0xa),'interval':_0x8173('0x9b')});_0x54801f['forcedOwnership']=![];}return respondWithRpcPromise('Start',_0x8173('0xa2'),_0x54801f);});}return respondWithRpcPromise(_0x8173('0xa3'),_0x8173('0xa2'),_0x54801f);})[_0x8173('0x21')](function(_0x493115){respondWithRpcPromise('EventManager',_0x8173('0xa4'),{'event':_0x8173('0x72'),'message':_0x493115},client9002);return _0x493115;})[_0x8173('0x21')](respondWithResult(_0x13b259,null))['catch'](handleError(_0x13b259,null));};exports[_0x8173('0xa5')]=function(_0x3639eb,_0x2bed39){var _0x405185=_0x3639eb[_0x8173('0x57')]['id'];var _0x16d7b1=_0x3639eb[_0x8173('0x5c')];var _0x51dba6=0xc8;var _0x500991=null;return db[_0x8173('0xa6')][_0x8173('0xa7')]({'isolationLevel':db[_0x8173('0xa6')][_0x8173('0xa8')][_0x8173('0xa9')][_0x8173('0xaa')]},function(_0x249b62){return db[_0x8173('0x53')][_0x8173('0x67')]({'where':{'id':_0x405185},'transaction':_0x249b62})[_0x8173('0x21')](function(_0x514630){if(_0x514630){return db[_0x8173('0xab')][_0x8173('0x38')]({'where':{'OpenchannelAccountId':_0x405185},'transaction':_0x249b62})[_0x8173('0x21')](function(){var _0x48b21a=_[_0x8173('0x40')](_0x16d7b1,function(_0xf12a99){_0xf12a99[_0x8173('0x6a')]=_0x405185;return _0xf12a99;});return db[_0x8173('0xab')][_0x8173('0xac')](_0x48b21a,{'transaction':_0x249b62});});}else{_0x51dba6=0x194;_0x500991=[];}});})['then'](function(){if(_0x51dba6!==0x194){return db[_0x8173('0xab')][_0x8173('0xad')]({'where':{'OpenchannelAccountId':_0x405185},'order':_0x8173('0xae')})[_0x8173('0x21')](function(_0x24b4b2){_0x500991=_0x24b4b2;});}})[_0x8173('0x2c')](function(_0x35557c){_0x51dba6=0x1f4;logger[_0x8173('0x27')](_0x35557c[_0x8173('0x3c')]);if(_0x35557c[_0x8173('0x62')]){delete _0x35557c[_0x8173('0x62')];}_0x500991=_0x35557c;})['finally'](function(){if(_0x500991===null){_0x2bed39['sendStatus'](_0x51dba6);}else{if(_0x51dba6===0x1f4){_0x2bed39[_0x8173('0x2d')](_0x51dba6)[_0x8173('0x3d')](_0x500991);}else{_0x2bed39['status'](_0x51dba6)[_0x8173('0x2f')](_0x500991);}}});};exports[_0x8173('0xaf')]=function(_0x7f3719,_0xeca401,_0x3d8478){var _0x15494f={};var _0xab3c80={};var _0x1113fa;var _0x48ebea;return db[_0x8173('0x53')]['findOne']({'where':{'id':_0x7f3719['params']['id']}})[_0x8173('0x21')](handleEntityNotFound(_0xeca401,null))[_0x8173('0x21')](function(_0x647a56){if(_0x647a56){_0x1113fa=_0x647a56;_0xab3c80[_0x8173('0x48')]=_[_0x8173('0x58')](db[_0x8173('0xab')]['rawAttributes']);_0xab3c80['query']=_[_0x8173('0x58')](_0x7f3719['query']);_0xab3c80[_0x8173('0x45')]=_[_0x8173('0x46')](_0xab3c80[_0x8173('0x48')],_0xab3c80['query']);_0x15494f[_0x8173('0x47')]=_[_0x8173('0x46')](_0xab3c80[_0x8173('0x48')],qs['fields'](_0x7f3719[_0x8173('0x44')][_0x8173('0x49')]));_0x15494f[_0x8173('0x47')]=_0x15494f[_0x8173('0x47')][_0x8173('0x4a')]?_0x15494f[_0x8173('0x47')]:_0xab3c80['model'];_0x15494f['order']=qs[_0x8173('0x4d')](_0x7f3719[_0x8173('0x44')][_0x8173('0x4d')]);_0x15494f[_0x8173('0x4e')]=qs[_0x8173('0x45')](_[_0x8173('0x69')](_0x7f3719[_0x8173('0x44')],_0xab3c80[_0x8173('0x45')]));if(_0x7f3719[_0x8173('0x44')][_0x8173('0x4f')]){_0x15494f[_0x8173('0x4e')]=_[_0x8173('0x50')](_0x15494f[_0x8173('0x4e')],{'$or':_[_0x8173('0x40')](_0x15494f[_0x8173('0x47')],function(_0xe4dd43){var _0x189451={};_0x189451[_0xe4dd43]={'$like':'%'+_0x7f3719[_0x8173('0x44')]['filter']+'%'};return _0x189451;})});}_0x15494f=_[_0x8173('0x50')]({},_0x15494f,_0x7f3719[_0x8173('0x52')]);return _0x1113fa[_0x8173('0xaf')](_0x15494f);}})[_0x8173('0x21')](function(_0x245762){if(_0x245762){_0x48ebea=_0x245762['length'];if(!_0x7f3719['query'][_0x8173('0x4b')]('nolimit')){_0x15494f[_0x8173('0x32')]=qs[_0x8173('0x32')](_0x7f3719['query']['limit']);_0x15494f[_0x8173('0x30')]=qs[_0x8173('0x30')](_0x7f3719[_0x8173('0x44')][_0x8173('0x30')]);}return _0x1113fa[_0x8173('0xaf')](_0x15494f);}})['then'](function(_0x56d856){if(_0x56d856){return _0x56d856?{'count':_0x48ebea,'rows':_0x56d856}:null;}})[_0x8173('0x21')](respondWithResult(_0xeca401,null))['catch'](handleError(_0xeca401,null));};exports[_0x8173('0xb0')]=function(_0x5ecfc0,_0x2956ec,_0x4a628f){var _0x2eb7cd={'raw':![],'where':{}};var _0x10d14e={};var _0x137295={'count':0x0,'rows':[]};return db['OpenchannelAccount'][_0x8173('0x67')]({'where':{'id':_0x5ecfc0[_0x8173('0x57')]['id']}})[_0x8173('0x21')](handleEntityNotFound(_0x2956ec,null))[_0x8173('0x21')](function(_0x1e3d1c){if(_0x1e3d1c){_0x10d14e[_0x8173('0x48')]=_[_0x8173('0x58')](db['OpenchannelInteraction'][_0x8173('0x41')]);_0x10d14e['query']=_[_0x8173('0x58')](_0x5ecfc0[_0x8173('0x44')]);_0x10d14e['filters']=_['intersection'](_0x10d14e['model'],_0x10d14e[_0x8173('0x44')]);_0x2eb7cd[_0x8173('0x47')]=_['intersection'](_0x10d14e[_0x8173('0x48')],qs[_0x8173('0x49')](_0x5ecfc0[_0x8173('0x44')]['fields']));_0x2eb7cd[_0x8173('0x47')]=_0x2eb7cd['attributes'][_0x8173('0x4a')]?_0x2eb7cd['attributes']:_0x10d14e['model'];if(!_0x5ecfc0[_0x8173('0x44')][_0x8173('0x4b')](_0x8173('0x4c'))){_0x2eb7cd[_0x8173('0x32')]=qs['limit'](_0x5ecfc0[_0x8173('0x44')]['limit']);_0x2eb7cd[_0x8173('0x30')]=qs[_0x8173('0x30')](_0x5ecfc0[_0x8173('0x44')][_0x8173('0x30')]);}_0x2eb7cd[_0x8173('0x68')]=qs['sort'](_0x5ecfc0[_0x8173('0x44')][_0x8173('0x4d')]);_0x2eb7cd['where']=qs[_0x8173('0x45')](_[_0x8173('0x69')](_0x5ecfc0['query'],_0x10d14e[_0x8173('0x45')]));_0x2eb7cd[_0x8173('0x4e')]['OpenchannelAccountId']=_0x1e3d1c['id'];if(_0x5ecfc0[_0x8173('0x44')][_0x8173('0x4f')]){_0x2eb7cd[_0x8173('0x4e')]=_[_0x8173('0x50')](_0x2eb7cd[_0x8173('0x4e')],{'$or':_[_0x8173('0x40')](_0x2eb7cd['attributes'],function(_0x155030){var _0x48dcc8={};_0x48dcc8[_0x155030]={'$like':'%'+_0x5ecfc0['query'][_0x8173('0x4f')]+'%'};return _0x48dcc8;})});}_0x2eb7cd=_['merge']({},_0x2eb7cd,_0x5ecfc0[_0x8173('0x52')]);return db[_0x8173('0x90')]['count']({'where':_0x2eb7cd['where']})[_0x8173('0x21')](function(_0x3fb802){_0x137295[_0x8173('0x54')]=_0x3fb802;if(_0x5ecfc0[_0x8173('0x44')][_0x8173('0x59')]){_0x2eb7cd[_0x8173('0x55')]=[{'model':db[_0x8173('0x74')],'as':_0x8173('0xb1'),'required':![]},{'model':db[_0x8173('0x9f')],'as':_0x8173('0xb2'),'attributes':['name',_0x8173('0xb3'),_0x8173('0xb4')],'required':![]},{'model':db[_0x8173('0xb5')],'as':'Tags','attributes':['id','name','color'],'where':_0x5ecfc0['query'][_0x8173('0xb6')]?{'id':_0x5ecfc0[_0x8173('0x44')][_0x8173('0xb6')]}:undefined,'required':_0x5ecfc0[_0x8173('0x44')][_0x8173('0xb6')]?!![]:![]}];}return db['OpenchannelInteraction']['findAll'](_0x2eb7cd);})['then'](function(_0x4b7cf4){_0x137295['rows']=_0x4b7cf4;return _0x137295;});}})[_0x8173('0x21')](respondWithFilteredResult(_0x2956ec,_0x2eb7cd))[_0x8173('0x2c')](handleError(_0x2956ec,null));};exports[_0x8173('0xb7')]=function(_0x2abef3,_0x208ac4,_0x2f327e){return db[_0x8173('0x53')][_0x8173('0x5a')]({'where':{'id':_0x2abef3[_0x8173('0x57')]['id']}})['then'](handleEntityNotFound(_0x208ac4,null))['then'](function(_0x2d54a0){if(_0x2d54a0){return _0x2d54a0[_0x8173('0xb7')](_0x2abef3[_0x8173('0x5c')][_0x8173('0x6c')],_['omit'](_0x2abef3[_0x8173('0x5c')],['ids','id'])||{})[_0x8173('0x93')](function(_0x4b832c){for(var _0x3e4970=0x0;_0x3e4970<_0x2abef3[_0x8173('0x5c')][_0x8173('0x6c')][_0x8173('0x4a')];_0x3e4970+=0x1){socket[_0x8173('0xb8')](_0x8173('0xb9'),{'UserId':Number(_0x2abef3[_0x8173('0x5c')][_0x8173('0x6c')][_0x3e4970]),'OpenchannelAccountId':Number(_0x2abef3[_0x8173('0x57')]['id'])});}return _0x4b832c;});}})[_0x8173('0x21')](respondWithResult(_0x208ac4,null))[_0x8173('0x2c')](handleError(_0x208ac4,null));};exports[_0x8173('0xba')]=function(_0x3464b0,_0x1b877c,_0xf956e1){return db['OpenchannelAccount'][_0x8173('0x5a')]({'where':{'id':_0x3464b0[_0x8173('0x57')]['id']}})[_0x8173('0x21')](handleEntityNotFound(_0x1b877c,null))[_0x8173('0x21')](function(_0x1c63cc){if(_0x1c63cc){return _0x1c63cc[_0x8173('0xba')](_0x3464b0[_0x8173('0x44')][_0x8173('0x6c')])['then'](function(){if(_[_0x8173('0xbb')](_0x3464b0[_0x8173('0x44')][_0x8173('0x6c')])){for(var _0x42e5e7=0x0;_0x42e5e7<_0x3464b0[_0x8173('0x44')][_0x8173('0x6c')]['length'];_0x42e5e7+=0x1){socket[_0x8173('0xb8')]('userOpenchannelAccount:remove',{'UserId':Number(_0x3464b0[_0x8173('0x44')][_0x8173('0x6c')][_0x42e5e7]),'OpenchannelAccountId':Number(_0x3464b0['params']['id'])});}}else{socket[_0x8173('0xb8')](_0x8173('0xbc'),{'UserId':Number(_0x3464b0[_0x8173('0x44')]['ids']),'OpenchannelAccountId':Number(_0x3464b0[_0x8173('0x57')]['id'])});}});}})[_0x8173('0x21')](respondWithStatusCode(_0x1b877c,null))[_0x8173('0x2c')](handleError(_0x1b877c,null));};exports[_0x8173('0xbd')]=function(_0x2cfcd6,_0x3fbcd1,_0x473238){var _0x35573f={};var _0x40809b={};var _0x4272d6;var _0x35d85c;return db[_0x8173('0x53')][_0x8173('0x67')]({'where':{'id':_0x2cfcd6[_0x8173('0x57')]['id']}})[_0x8173('0x21')](handleEntityNotFound(_0x3fbcd1,null))[_0x8173('0x21')](function(_0x48e336){if(_0x48e336){_0x4272d6=_0x48e336;_0x40809b[_0x8173('0x48')]=_[_0x8173('0x58')](db[_0x8173('0x9f')][_0x8173('0x41')]);_0x40809b['query']=_['keys'](_0x2cfcd6[_0x8173('0x44')]);_0x40809b[_0x8173('0x45')]=_['intersection'](_0x40809b[_0x8173('0x48')],_0x40809b['query']);_0x35573f[_0x8173('0x47')]=_[_0x8173('0x46')](_0x40809b[_0x8173('0x48')],qs['fields'](_0x2cfcd6['query']['fields']));_0x35573f[_0x8173('0x47')]=_0x35573f[_0x8173('0x47')][_0x8173('0x4a')]?_0x35573f['attributes']:_0x40809b[_0x8173('0x48')];_0x35573f[_0x8173('0x68')]=qs[_0x8173('0x4d')](_0x2cfcd6[_0x8173('0x44')][_0x8173('0x4d')]);_0x35573f[_0x8173('0x4e')]=qs['filters'](_[_0x8173('0x69')](_0x2cfcd6[_0x8173('0x44')],_0x40809b[_0x8173('0x45')]));if(_0x2cfcd6['query'][_0x8173('0x4f')]){_0x35573f[_0x8173('0x4e')]=_[_0x8173('0x50')](_0x35573f['where'],{'$or':_['map'](_0x35573f['attributes'],function(_0x55d25b){var _0x55cfbf={};_0x55cfbf[_0x55d25b]={'$like':'%'+_0x2cfcd6['query'][_0x8173('0x4f')]+'%'};return _0x55cfbf;})});}_0x35573f=_['merge']({},_0x35573f,_0x2cfcd6[_0x8173('0x52')]);return _0x4272d6[_0x8173('0xbd')](_0x35573f);}})[_0x8173('0x21')](function(_0xd833ff){if(_0xd833ff){_0x35d85c=_0xd833ff[_0x8173('0x4a')];if(!_0x2cfcd6[_0x8173('0x44')][_0x8173('0x4b')]('nolimit')){_0x35573f[_0x8173('0x32')]=qs[_0x8173('0x32')](_0x2cfcd6[_0x8173('0x44')]['limit']);_0x35573f[_0x8173('0x30')]=qs[_0x8173('0x30')](_0x2cfcd6[_0x8173('0x44')][_0x8173('0x30')]);}return _0x4272d6[_0x8173('0xbd')](_0x35573f);}})[_0x8173('0x21')](function(_0x6884f){if(_0x6884f){return _0x6884f?{'count':_0x35d85c,'rows':_0x6884f}:null;}})[_0x8173('0x21')](respondWithResult(_0x3fbcd1,null))['catch'](handleError(_0x3fbcd1,null));};exports[_0x8173('0x3d')]=function(_0x20f4d0,_0x4ba412,_0x5a7651){var _0x4a84cc,_0x2eb627,_0x5d695d;if(_[_0x8173('0x7e')](_0x20f4d0[_0x8173('0x5c')]['body'])||_0x20f4d0['body'][_0x8173('0x5c')]===''){throw new db[(_0x8173('0x75'))][(_0x8173('0x76'))](_0x8173('0xbe'));}if(_[_0x8173('0x7e')](_0x20f4d0[_0x8173('0x5c')]['to'])){}_0x4a84cc=_0x20f4d0['body']['to'];return db['OpenchannelAccount'][_0x8173('0x67')]({'where':{'id':_0x20f4d0['params']['id']}})['then'](handleEntityNotFound(_0x4ba412,null))['then'](function(_0x27b520){if(_0x27b520){return db[_0x8173('0x53')]['find']({'where':{'id':_0x27b520['id']},'include':[{'model':db['CmList'],'as':_0x8173('0x83'),'include':[{'model':db[_0x8173('0x74')],'as':_0x8173('0x84'),'where':{[_0x27b520[_0x8173('0x7f')]]:_0x4a84cc},'limit':0x1,'order':[[_0x8173('0x7a'),_0x8173('0x85')]]}]}]})[_0x8173('0x21')](handleEntityNotFound(_0x4ba412,null))[_0x8173('0x21')](function(_0x231119){if(_0x231119&&_0x231119['List']){_0x2eb627=_0x231119[_0x8173('0x39')]({'plain':!![]});if(_0x2eb627[_0x8173('0x83')]&&_0x2eb627[_0x8173('0x83')][_0x8173('0x84')][_0x8173('0x4a')]){return _0x2eb627[_0x8173('0x83')]['Contacts'][0x0];}return db[_0x8173('0x74')][_0x8173('0x5b')](_['defaults'](_0x20f4d0[_0x8173('0x5c')],{'firstName':_0x4a84cc,[_0x231119[_0x8173('0x7f')]]:_0x4a84cc,'phone':_0x4a84cc,'ListId':_0x2eb627[_0x8173('0x7c')]}));}})[_0x8173('0x21')](handleEntityNotFound(_0x4ba412,null))[_0x8173('0x21')](function(_0x5c63f2){if(_0x5c63f2){_0x5d695d=_0x5c63f2;return db['OpenchannelInteraction'][_0x8173('0x5a')]({'where':{'ContactId':_0x5d695d['id'],'closed':![],'OpenchannelAccountId':_0x2eb627['id']}})['then'](function(_0x8cb3f0){if(_0x8cb3f0){return[_0x8cb3f0,![]];}return db[_0x8173('0x90')]['create']({'UserId':_0x20f4d0[_0x8173('0x5e')]['id'],'ContactId':_0x5d695d['id'],'OpenchannelAccountId':_0x2eb627['id'],'lastMsgDirection':_0x8173('0xbf'),'firstMsgDirection':_0x8173('0xbf'),'Messages':[_[_0x8173('0x50')](_0x20f4d0[_0x8173('0x5c')],{'read':![],'body':_0x20f4d0[_0x8173('0x5c')][_0x8173('0x5c')],'OpenchannelAccountId':_0x2eb627['id'],'UserId':_0x20f4d0[_0x8173('0x5e')]['id'],'ContactId':_0x5d695d['id']})]},{'include':[{'model':db[_0x8173('0x9c')],'as':'Messages'}]})[_0x8173('0x21')](function(_0xc91783){return[_0xc91783,!![]];});});}})[_0x8173('0x93')](function(_0x83eedd,_0x404109){if(_0x404109){return _0x83eedd;}return db[_0x8173('0x9c')]['create'](_[_0x8173('0x50')](_0x20f4d0[_0x8173('0x5c')],{'read':![],'body':_0x20f4d0[_0x8173('0x5c')]['body'],'OpenchannelAccountId':_0x2eb627['id'],'OpenchannelInteractionId':_0x83eedd['id'],'UserId':_0x20f4d0[_0x8173('0x5e')]['id'],'ContactId':_0x5d695d['id']}))[_0x8173('0x21')](function(_0x7b12e7){_0x83eedd['dataValues'][_0x8173('0xc0')]=[];_0x83eedd[_0x8173('0xc1')][_0x8173('0xc0')]['push'](_0x7b12e7['dataValues']);return _0x83eedd;});});}})['then'](respondWithResult(_0x4ba412,null))[_0x8173('0x2c')](handleError(_0x4ba412,null));};
\ No newline at end of file