Built motion from commit 00bf23f6.|2.6.16
[motion2.git] / server / api / openchannelAccount / openchannelAccount.controller.js
index 1ea9c57..c4fead4 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x3d76=['where','filters','pick','merge','filter','count','includeAll','include','findAll','rows','show','params','options','create','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','find','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','describe','addDisposition','Disposition','getDispositions','findOne','removeDispositions','CannedAnswer','getAnswers','removeAnswers','ids','notify','no\x20available\x20attributes','difference','createdAt','CompanyId','isNil','from','ValidationError','from\x20is\x20mandatory','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','CmList','List','Contacts','updatedAt','DESC','OpenchannelApplication','Applications','applications','list','orderBy','asc','account','ListId','CmContact','firstName','threadId','externalUrl','OpenchannelInteraction','ContactId','spread','contact','lastName','messageId','interaction','created','push','unmanaged','OpenchannelMessage','AttachmentId','UserId','unshift','agent','waitForTheAssignedAgent','*,*,*,*','forcedOwnership','startRouting','Start','EventManager','sequelize','OpenchannelAccountId','bulkCreate','findAndCountAll','getApplications','getInteractions','Contact','User','fullname','Tags','color','tag','addAgents','emit','removeAgents','isArray','userOpenchannelAccount:remove','getAgents','out','dataValues','html-pdf','eml-format','fast-json-patch','request-promise','moment','bluebird','mustache','path','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./openchannelAccount.socket','client','http','test','Sequelize','The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.','then','info','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','debug','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','status','end','json','offset','set','apply','reject','save','update','OpenchannelAccounts','destroy','stack','name','send','Pause','mandatoryDispositionPause','map','OpenchannelAccount','rawAttributes','fieldName','type','model','query','keys','attributes','intersection','fields','length','hasOwnProperty','nolimit','limit','order','sort'];(function(_0x5f3f88,_0x562baf){var _0xd08119=function(_0x42dbf7){while(--_0x42dbf7){_0x5f3f88['push'](_0x5f3f88['shift']());}};_0xd08119(++_0x562baf);}(_0x3d76,0x1d8));var _0x63d7=function(_0x602ca8,_0x568e82){_0x602ca8=_0x602ca8-0x0;var _0x26e8ab=_0x3d76[_0x602ca8];return _0x26e8ab;};'use strict';var pdf=require(_0x63d7('0x0'));var emlformat=require(_0x63d7('0x1'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x63d7('0x2'));var rp=require(_0x63d7('0x3'));var moment=require(_0x63d7('0x4'));var BPromise=require(_0x63d7('0x5'));var Mustache=require(_0x63d7('0x6'));var util=require('util');var path=require(_0x63d7('0x7'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x63d7('0x8'));var fs=require('fs');var _=require(_0x63d7('0x9'));var squel=require(_0x63d7('0xa'));var crypto=require(_0x63d7('0xb'));var jsforce=require(_0x63d7('0xc'));var deskjs=require(_0x63d7('0xd'));var toCsv=require('to-csv');var querystring=require(_0x63d7('0xe'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x63d7('0xf'));var as=require(_0x63d7('0x10'));var hardwareService=require(_0x63d7('0x11'));var logger=require('../../config/logger')(_0x63d7('0x12'));var utils=require('../../config/utils');var config=require(_0x63d7('0x13'));var db=require(_0x63d7('0x14'))['db'];config[_0x63d7('0x15')]=_[_0x63d7('0x16')](config['redis'],{'host':_0x63d7('0x17'),'port':0x18eb});var socket=require(_0x63d7('0x18'))(new Redis(config['redis']));require(_0x63d7('0x19'))['register'](socket);var jayson=require('jayson/promise');var client=jayson[_0x63d7('0x1a')][_0x63d7('0x1b')]({'port':0x232c});var client9002=jayson['client']['http']({'port':0x232a});function checkPasswordPattern(_0x5ca234,_0x2bee1d,_0x469bf9){if(_0x469bf9){var _0x530302=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x530302[_0x63d7('0x1c')](_0x2bee1d)){return _0x5ca234;}else{throw new db[(_0x63d7('0x1d'))]['ValidationError'](_0x63d7('0x1e'));}}else{return _0x5ca234;}}function respondWithRpcPromise(_0x4ea4f2,_0x2c7ecd,_0xf700e5,_0x1c752f){return new BPromise(function(_0x5fc791,_0x40f322){var _0x33d93f=_0x1c752f||client;return _0x33d93f['request'](_0x4ea4f2,_0xf700e5)[_0x63d7('0x1f')](function(_0xef2952){logger[_0x63d7('0x20')](_0x63d7('0x21'),_0x2c7ecd,_0x63d7('0x22'));logger[_0x63d7('0x23')](_0x63d7('0x24'),_0x2c7ecd,'request\x20sent',JSON[_0x63d7('0x25')](_0xef2952));if(_0xef2952[_0x63d7('0x26')]){if(_0xef2952['error'][_0x63d7('0x27')]===0x1f4){logger[_0x63d7('0x26')](_0x63d7('0x21'),_0x2c7ecd,_0xef2952[_0x63d7('0x26')][_0x63d7('0x28')]);return _0x40f322(_0xef2952[_0x63d7('0x26')][_0x63d7('0x28')]);}logger[_0x63d7('0x26')](_0x63d7('0x21'),_0x2c7ecd,_0xef2952[_0x63d7('0x26')][_0x63d7('0x28')]);return _0x5fc791(_0xef2952[_0x63d7('0x26')][_0x63d7('0x28')]);}else{logger[_0x63d7('0x20')]('OpenchannelAccount,\x20%s,\x20%s',_0x2c7ecd,_0x63d7('0x22'));_0x5fc791(_0xef2952[_0x63d7('0x29')][_0x63d7('0x28')]);}})[_0x63d7('0x2a')](function(_0x37a3f1){logger['error'](_0x63d7('0x21'),_0x2c7ecd,_0x37a3f1);_0x40f322(_0x37a3f1);});});}function respondWithStatusCode(_0x1bf75c,_0x1f46cd){_0x1f46cd=_0x1f46cd||0xcc;return function(_0x457f2f){if(_0x457f2f){return _0x1bf75c[_0x63d7('0x2b')](_0x1f46cd);}return _0x1bf75c[_0x63d7('0x2c')](_0x1f46cd)[_0x63d7('0x2d')]();};}function respondWithResult(_0x4ed6c4,_0x56e9c5){_0x56e9c5=_0x56e9c5||0xc8;return function(_0x2f2f60){if(_0x2f2f60){return _0x4ed6c4[_0x63d7('0x2c')](_0x56e9c5)[_0x63d7('0x2e')](_0x2f2f60);}};}function respondWithFilteredResult(_0x31d76c,_0x44851d){return function(_0x4acdac){if(_0x4acdac){var _0x3391c5=_0x4acdac['count'],_0x2bce07=_0x44851d[_0x63d7('0x2f')],_0x42dd5f=_0x44851d[_0x63d7('0x2f')]+_0x44851d['limit'],_0x5a9a2a;if(_0x42dd5f>=_0x3391c5){_0x42dd5f=_0x3391c5;_0x5a9a2a=0xc8;}else{_0x5a9a2a=0xce;}_0x31d76c[_0x63d7('0x2c')](_0x5a9a2a);return _0x31d76c[_0x63d7('0x30')]('Content-Range',_0x2bce07+'-'+_0x42dd5f+'/'+_0x3391c5)[_0x63d7('0x2e')](_0x4acdac);}return null;};}function patchUpdates(_0x22ada0){return function(_0x835200){try{jsonpatch[_0x63d7('0x31')](_0x835200,_0x22ada0,!![]);}catch(_0x38ffaf){return BPromise[_0x63d7('0x32')](_0x38ffaf);}return _0x835200[_0x63d7('0x33')]();};}function saveUpdates(_0x403104,_0x5d26f3){return function(_0x45a247){if(_0x45a247){return _0x45a247[_0x63d7('0x34')](_0x403104)[_0x63d7('0x1f')](function(_0x26c18c){return _0x26c18c;});}return null;};}function removeEntity(_0x33d6cf,_0x4af9d9){return function(_0x4492fa){if(_0x4492fa){return _0x4492fa['destroy']()[_0x63d7('0x1f')](function(){var _0x1485b3=_0x4492fa['get']({'plain':!![]});var _0x4842bb=_0x63d7('0x35');return db['UserProfileResource'][_0x63d7('0x36')]({'where':{'type':_0x4842bb,'resourceId':_0x1485b3['id']}})[_0x63d7('0x1f')](function(){return _0x4492fa;});})[_0x63d7('0x1f')](function(){_0x33d6cf['status'](0xcc)[_0x63d7('0x2d')]();});}};}function handleEntityNotFound(_0x1defde,_0x3c6e88){return function(_0x1761d9){if(!_0x1761d9){_0x1defde['sendStatus'](0x194);}return _0x1761d9;};}function handleError(_0x839325,_0x40f0fa){_0x40f0fa=_0x40f0fa||0x1f4;return function(_0x5bbee0){logger[_0x63d7('0x26')](_0x5bbee0[_0x63d7('0x37')]);if(_0x5bbee0[_0x63d7('0x38')]){delete _0x5bbee0[_0x63d7('0x38')];}_0x839325[_0x63d7('0x2c')](_0x40f0fa)[_0x63d7('0x39')](_0x5bbee0);};}exports['index']=function(_0x2bbca4,_0x414229){var _0x37fd6d={'include':[{'model':db[_0x63d7('0x3a')],'as':_0x63d7('0x3b')}]},_0x3926ed={},_0x23553e={'count':0x0,'rows':[]};var _0x3e909f=_[_0x63d7('0x3c')](db[_0x63d7('0x3d')][_0x63d7('0x3e')],function(_0x12e175){return{'name':_0x12e175[_0x63d7('0x3f')],'type':_0x12e175[_0x63d7('0x40')]['key']};});_0x3926ed[_0x63d7('0x41')]=_[_0x63d7('0x3c')](_0x3e909f,_0x63d7('0x38'));_0x3926ed[_0x63d7('0x42')]=_[_0x63d7('0x43')](_0x2bbca4[_0x63d7('0x42')]);_0x3926ed['filters']=_['intersection'](_0x3926ed[_0x63d7('0x41')],_0x3926ed['query']);_0x37fd6d[_0x63d7('0x44')]=_[_0x63d7('0x45')](_0x3926ed[_0x63d7('0x41')],qs[_0x63d7('0x46')](_0x2bbca4['query'][_0x63d7('0x46')]));_0x37fd6d[_0x63d7('0x44')]=_0x37fd6d[_0x63d7('0x44')][_0x63d7('0x47')]?_0x37fd6d[_0x63d7('0x44')]:_0x3926ed[_0x63d7('0x41')];if(!_0x2bbca4[_0x63d7('0x42')][_0x63d7('0x48')](_0x63d7('0x49'))){_0x37fd6d[_0x63d7('0x4a')]=qs[_0x63d7('0x4a')](_0x2bbca4[_0x63d7('0x42')][_0x63d7('0x4a')]);_0x37fd6d[_0x63d7('0x2f')]=qs['offset'](_0x2bbca4['query'][_0x63d7('0x2f')]);}_0x37fd6d[_0x63d7('0x4b')]=qs[_0x63d7('0x4c')](_0x2bbca4[_0x63d7('0x42')][_0x63d7('0x4c')]);_0x37fd6d[_0x63d7('0x4d')]=qs[_0x63d7('0x4e')](_[_0x63d7('0x4f')](_0x2bbca4[_0x63d7('0x42')],_0x3926ed['filters']));if(_0x2bbca4[_0x63d7('0x42')]['filter']){_0x37fd6d[_0x63d7('0x4d')]=_[_0x63d7('0x50')](_0x37fd6d[_0x63d7('0x4d')],{'$or':_[_0x63d7('0x3c')](_0x3e909f,function(_0x220955){if(_0x220955[_0x63d7('0x40')]!=='VIRTUAL'){var _0x5afa2c={};_0x5afa2c[_0x220955[_0x63d7('0x38')]]={'$like':'%'+_0x2bbca4[_0x63d7('0x42')][_0x63d7('0x51')]+'%'};return _0x5afa2c;}})});}_0x37fd6d=_[_0x63d7('0x50')]({},_0x37fd6d,_0x2bbca4['options']);var _0x3acf7f={'where':_0x37fd6d[_0x63d7('0x4d')]};return db[_0x63d7('0x3d')][_0x63d7('0x52')](_0x3acf7f)[_0x63d7('0x1f')](function(_0x356794){_0x23553e[_0x63d7('0x52')]=_0x356794;if(_0x2bbca4[_0x63d7('0x42')][_0x63d7('0x53')]){_0x37fd6d[_0x63d7('0x54')]=[{'all':!![]}];}return db['OpenchannelAccount'][_0x63d7('0x55')](_0x37fd6d);})[_0x63d7('0x1f')](function(_0x42b1cc){_0x23553e[_0x63d7('0x56')]=_0x42b1cc;return _0x23553e;})[_0x63d7('0x1f')](respondWithFilteredResult(_0x414229,_0x37fd6d))[_0x63d7('0x2a')](handleError(_0x414229,null));};exports[_0x63d7('0x57')]=function(_0x23e5a3,_0x34533b){var _0x41c93d={'raw':![],'where':{'id':_0x23e5a3[_0x63d7('0x58')]['id']},'include':[{'model':db[_0x63d7('0x3a')],'as':_0x63d7('0x3b')}]},_0x3e6cf2={};_0x3e6cf2[_0x63d7('0x41')]=_['keys'](db['OpenchannelAccount']['rawAttributes']);_0x3e6cf2[_0x63d7('0x42')]=_['keys'](_0x23e5a3['query']);_0x3e6cf2[_0x63d7('0x4e')]=_['intersection'](_0x3e6cf2['model'],_0x3e6cf2['query']);_0x41c93d[_0x63d7('0x44')]=_[_0x63d7('0x45')](_0x3e6cf2[_0x63d7('0x41')],qs[_0x63d7('0x46')](_0x23e5a3['query'][_0x63d7('0x46')]));_0x41c93d[_0x63d7('0x44')]=_0x41c93d[_0x63d7('0x44')][_0x63d7('0x47')]?_0x41c93d['attributes']:_0x3e6cf2[_0x63d7('0x41')];if(_0x23e5a3[_0x63d7('0x42')][_0x63d7('0x53')]){_0x41c93d[_0x63d7('0x54')]=[{'all':!![]}];}_0x41c93d=_[_0x63d7('0x50')]({},_0x41c93d,_0x23e5a3[_0x63d7('0x59')]);return db[_0x63d7('0x3d')]['find'](_0x41c93d)['then'](handleEntityNotFound(_0x34533b,null))['then'](respondWithResult(_0x34533b,null))[_0x63d7('0x2a')](handleError(_0x34533b,null));};exports[_0x63d7('0x5a')]=function(_0x572979,_0x5dfa89){return db[_0x63d7('0x3d')][_0x63d7('0x5a')](_0x572979['body'],{})[_0x63d7('0x1f')](function(_0x49d9da){var _0x1ac764=_0x572979[_0x63d7('0x5b')][_0x63d7('0x5c')]({'plain':!![]});if(!_0x1ac764)throw new Error(_0x63d7('0x5d'));if(_0x1ac764['role']===_0x63d7('0x5b')){var _0x4dae68=_0x49d9da[_0x63d7('0x5c')]({'plain':!![]});var _0x32bb3c=_0x63d7('0x35');return db[_0x63d7('0x5e')][_0x63d7('0x5f')]({'where':{'name':_0x32bb3c,'userProfileId':_0x1ac764[_0x63d7('0x60')]},'raw':!![]})[_0x63d7('0x1f')](function(_0x3224e7){if(_0x3224e7&&_0x3224e7[_0x63d7('0x61')]===0x0){return db[_0x63d7('0x62')][_0x63d7('0x5a')]({'name':_0x4dae68[_0x63d7('0x38')],'resourceId':_0x4dae68['id'],'type':_0x3224e7[_0x63d7('0x38')],'sectionId':_0x3224e7['id']},{})['then'](function(){return _0x49d9da;});}else{return _0x49d9da;}})[_0x63d7('0x2a')](function(_0x3d0453){logger['error'](_0x63d7('0x63'),_0x3d0453);throw _0x3d0453;});}return _0x49d9da;})[_0x63d7('0x1f')](respondWithResult(_0x5dfa89,0xc9))[_0x63d7('0x2a')](handleError(_0x5dfa89,null));};exports[_0x63d7('0x34')]=function(_0x3ec4a1,_0x4ff136){if(_0x3ec4a1[_0x63d7('0x64')]['id']){delete _0x3ec4a1['body']['id'];}return db[_0x63d7('0x3d')][_0x63d7('0x5f')]({'where':{'id':_0x3ec4a1[_0x63d7('0x58')]['id']},'include':[{'model':db['Pause'],'as':'mandatoryDispositionPause'}]})[_0x63d7('0x1f')](handleEntityNotFound(_0x4ff136,null))[_0x63d7('0x1f')](saveUpdates(_0x3ec4a1[_0x63d7('0x64')],null))[_0x63d7('0x1f')](respondWithResult(_0x4ff136,null))[_0x63d7('0x2a')](handleError(_0x4ff136,null));};exports[_0x63d7('0x36')]=function(_0x59481a,_0xc2fe0f){return db[_0x63d7('0x3d')][_0x63d7('0x5f')]({'where':{'id':_0x59481a[_0x63d7('0x58')]['id']}})[_0x63d7('0x1f')](handleEntityNotFound(_0xc2fe0f,null))[_0x63d7('0x1f')](removeEntity(_0xc2fe0f,null))[_0x63d7('0x2a')](handleError(_0xc2fe0f,null));};exports[_0x63d7('0x65')]=function(_0x5863f9,_0x26fa6c){return db[_0x63d7('0x3d')][_0x63d7('0x65')]()[_0x63d7('0x1f')](respondWithResult(_0x26fa6c,null))[_0x63d7('0x2a')](handleError(_0x26fa6c,null));};exports[_0x63d7('0x66')]=function(_0x2b0efc,_0x7f5ac,_0x3cdef5){if(_0x2b0efc[_0x63d7('0x64')]['id']){delete _0x2b0efc[_0x63d7('0x64')]['id'];}return db[_0x63d7('0x3d')][_0x63d7('0x5f')]({'where':{'id':_0x2b0efc[_0x63d7('0x58')]['id']}})[_0x63d7('0x1f')](handleEntityNotFound(_0x7f5ac,null))[_0x63d7('0x1f')](function(_0x2b1732){if(_0x2b1732){_0x2b0efc[_0x63d7('0x64')]['OpnechannelAccountId']=_0x2b1732['id'];return db[_0x63d7('0x67')][_0x63d7('0x5a')](_0x2b0efc[_0x63d7('0x64')]);}})[_0x63d7('0x1f')](respondWithResult(_0x7f5ac,null))[_0x63d7('0x2a')](handleError(_0x7f5ac,null));};exports[_0x63d7('0x68')]=function(_0xe7cdde,_0x4d5e08,_0x39833b){var _0x57781c={'raw':![],'where':{}};var _0x1051a3={};var _0x109fbe={'count':0x0,'rows':[]};return db[_0x63d7('0x3d')][_0x63d7('0x69')]({'where':{'id':_0xe7cdde['params']['id']}})['then'](handleEntityNotFound(_0x4d5e08,null))[_0x63d7('0x1f')](function(_0x2c1e76){if(_0x2c1e76){_0x1051a3['model']=_[_0x63d7('0x43')](db[_0x63d7('0x67')]['rawAttributes']);_0x1051a3[_0x63d7('0x42')]=_[_0x63d7('0x43')](_0xe7cdde[_0x63d7('0x42')]);_0x1051a3[_0x63d7('0x4e')]=_['intersection'](_0x1051a3['model'],_0x1051a3[_0x63d7('0x42')]);_0x57781c[_0x63d7('0x44')]=_[_0x63d7('0x45')](_0x1051a3['model'],qs[_0x63d7('0x46')](_0xe7cdde[_0x63d7('0x42')]['fields']));_0x57781c['attributes']=_0x57781c[_0x63d7('0x44')][_0x63d7('0x47')]?_0x57781c['attributes']:_0x1051a3[_0x63d7('0x41')];if(!_0xe7cdde[_0x63d7('0x42')][_0x63d7('0x48')]('nolimit')){_0x57781c[_0x63d7('0x4a')]=qs[_0x63d7('0x4a')](_0xe7cdde[_0x63d7('0x42')][_0x63d7('0x4a')]);_0x57781c['offset']=qs[_0x63d7('0x2f')](_0xe7cdde[_0x63d7('0x42')][_0x63d7('0x2f')]);}_0x57781c[_0x63d7('0x4b')]=qs[_0x63d7('0x4c')](_0xe7cdde[_0x63d7('0x42')][_0x63d7('0x4c')]);_0x57781c[_0x63d7('0x4d')]=qs['filters'](_[_0x63d7('0x4f')](_0xe7cdde[_0x63d7('0x42')],_0x1051a3[_0x63d7('0x4e')]));_0x57781c[_0x63d7('0x4d')]['OpenchannelAccountId']=_0x2c1e76['id'];if(_0xe7cdde[_0x63d7('0x42')][_0x63d7('0x51')]){_0x57781c['where']=_[_0x63d7('0x50')](_0x57781c[_0x63d7('0x4d')],{'$or':_[_0x63d7('0x3c')](_0x57781c['attributes'],function(_0x302d04){var _0x1745ca={};_0x1745ca[_0x302d04]={'$like':'%'+_0xe7cdde['query'][_0x63d7('0x51')]+'%'};return _0x1745ca;})});}_0x57781c=_[_0x63d7('0x50')]({},_0x57781c,_0xe7cdde[_0x63d7('0x59')]);return db[_0x63d7('0x67')][_0x63d7('0x52')]({'where':_0x57781c['where']})[_0x63d7('0x1f')](function(_0x2e42ff){_0x109fbe[_0x63d7('0x52')]=_0x2e42ff;if(_0xe7cdde['query'][_0x63d7('0x53')]){_0x57781c[_0x63d7('0x54')]=[{'all':!![]}];}return db[_0x63d7('0x67')][_0x63d7('0x55')](_0x57781c);})['then'](function(_0xad8b18){_0x109fbe['rows']=_0xad8b18;return _0x109fbe;});}})[_0x63d7('0x1f')](respondWithFilteredResult(_0x4d5e08,_0x57781c))[_0x63d7('0x2a')](handleError(_0x4d5e08,null));};exports['removeDispositions']=function(_0x2a28e7,_0xc764c0,_0x3ae31a){return db[_0x63d7('0x3d')]['find']({'where':{'id':_0x2a28e7['params']['id']}})[_0x63d7('0x1f')](handleEntityNotFound(_0xc764c0,null))[_0x63d7('0x1f')](function(_0x5956c6){if(_0x5956c6){return _0x5956c6[_0x63d7('0x6a')](_0x2a28e7[_0x63d7('0x42')]['ids']);}})[_0x63d7('0x1f')](respondWithStatusCode(_0xc764c0,null))['catch'](handleError(_0xc764c0,null));};exports['addAnswer']=function(_0x4dface,_0x707f08,_0x5e1a13){if(_0x4dface[_0x63d7('0x64')]['id']){delete _0x4dface[_0x63d7('0x64')]['id'];}return db[_0x63d7('0x3d')][_0x63d7('0x5f')]({'where':{'id':_0x4dface[_0x63d7('0x58')]['id']}})[_0x63d7('0x1f')](handleEntityNotFound(_0x707f08,null))[_0x63d7('0x1f')](function(_0x885b46){if(_0x885b46){_0x4dface[_0x63d7('0x64')]['OpenchannelAccountId']=_0x885b46['id'];return db[_0x63d7('0x6b')][_0x63d7('0x5a')](_0x4dface[_0x63d7('0x64')]);}})['then'](respondWithResult(_0x707f08,null))['catch'](handleError(_0x707f08,null));};exports[_0x63d7('0x6c')]=function(_0x4dbd1a,_0x7bce0c,_0x440941){var _0xa01b43={'raw':![],'where':{}};var _0x4fadca={};var _0x379d46={'count':0x0,'rows':[]};return db[_0x63d7('0x3d')][_0x63d7('0x69')]({'where':{'id':_0x4dbd1a[_0x63d7('0x58')]['id']}})['then'](handleEntityNotFound(_0x7bce0c,null))[_0x63d7('0x1f')](function(_0xfc02a){if(_0xfc02a){_0x4fadca[_0x63d7('0x41')]=_[_0x63d7('0x43')](db[_0x63d7('0x6b')]['rawAttributes']);_0x4fadca['query']=_[_0x63d7('0x43')](_0x4dbd1a[_0x63d7('0x42')]);_0x4fadca[_0x63d7('0x4e')]=_[_0x63d7('0x45')](_0x4fadca['model'],_0x4fadca[_0x63d7('0x42')]);_0xa01b43[_0x63d7('0x44')]=_['intersection'](_0x4fadca[_0x63d7('0x41')],qs[_0x63d7('0x46')](_0x4dbd1a[_0x63d7('0x42')][_0x63d7('0x46')]));_0xa01b43[_0x63d7('0x44')]=_0xa01b43[_0x63d7('0x44')][_0x63d7('0x47')]?_0xa01b43[_0x63d7('0x44')]:_0x4fadca[_0x63d7('0x41')];if(!_0x4dbd1a[_0x63d7('0x42')][_0x63d7('0x48')](_0x63d7('0x49'))){_0xa01b43[_0x63d7('0x4a')]=qs[_0x63d7('0x4a')](_0x4dbd1a['query'][_0x63d7('0x4a')]);_0xa01b43[_0x63d7('0x2f')]=qs[_0x63d7('0x2f')](_0x4dbd1a['query'][_0x63d7('0x2f')]);}_0xa01b43[_0x63d7('0x4b')]=qs[_0x63d7('0x4c')](_0x4dbd1a[_0x63d7('0x42')][_0x63d7('0x4c')]);_0xa01b43[_0x63d7('0x4d')]=qs[_0x63d7('0x4e')](_[_0x63d7('0x4f')](_0x4dbd1a['query'],_0x4fadca['filters']));_0xa01b43['where']['OpenchannelAccountId']=_0xfc02a['id'];if(_0x4dbd1a[_0x63d7('0x42')][_0x63d7('0x51')]){_0xa01b43[_0x63d7('0x4d')]=_[_0x63d7('0x50')](_0xa01b43[_0x63d7('0x4d')],{'$or':_[_0x63d7('0x3c')](_0xa01b43[_0x63d7('0x44')],function(_0x12ac26){var _0x1a778f={};_0x1a778f[_0x12ac26]={'$like':'%'+_0x4dbd1a[_0x63d7('0x42')][_0x63d7('0x51')]+'%'};return _0x1a778f;})});}_0xa01b43=_['merge']({},_0xa01b43,_0x4dbd1a[_0x63d7('0x59')]);return db[_0x63d7('0x6b')][_0x63d7('0x52')]({'where':_0xa01b43['where']})[_0x63d7('0x1f')](function(_0x33969a){_0x379d46[_0x63d7('0x52')]=_0x33969a;if(_0x4dbd1a[_0x63d7('0x42')][_0x63d7('0x53')]){_0xa01b43[_0x63d7('0x54')]=[{'all':!![]}];}return db[_0x63d7('0x6b')]['findAll'](_0xa01b43);})[_0x63d7('0x1f')](function(_0xfefdf3){_0x379d46[_0x63d7('0x56')]=_0xfefdf3;return _0x379d46;});}})[_0x63d7('0x1f')](respondWithFilteredResult(_0x7bce0c,_0xa01b43))['catch'](handleError(_0x7bce0c,null));};exports[_0x63d7('0x6d')]=function(_0x19146c,_0x5c3174,_0x4f4b87){return db[_0x63d7('0x3d')][_0x63d7('0x5f')]({'where':{'id':_0x19146c[_0x63d7('0x58')]['id']}})['then'](handleEntityNotFound(_0x5c3174,null))['then'](function(_0x2dfdfb){if(_0x2dfdfb){return _0x2dfdfb[_0x63d7('0x6d')](_0x19146c['query'][_0x63d7('0x6e')]);}})['then'](respondWithStatusCode(_0x5c3174,null))['catch'](handleError(_0x5c3174,null));};exports[_0x63d7('0x6f')]=function(_0x3d161b,_0x38cd91,_0x4a045e){var _0x72be6c={'body':_0x3d161b[_0x63d7('0x64')],'channel':'openchannel'};var _0x3d4259=[];var _0x1a3472=[];var _0x47eb62={};var _0x305a1e=![];return db['CmContact'][_0x63d7('0x65')]()[_0x63d7('0x1f')](function(_0x450c65){if(!_0x450c65){throw new db[(_0x63d7('0x1d'))]['ValidationError'](_0x63d7('0x70'));}_0x3d4259=_[_0x63d7('0x71')](_[_0x63d7('0x43')](_0x450c65),[_0x63d7('0x72'),'updatedAt']);_0x1a3472=_[_0x63d7('0x71')](_['keys'](_0x450c65),[_0x63d7('0x72'),'updatedAt',_0x63d7('0x73'),'ListId']);if(_0x3d161b[_0x63d7('0x64')]['id']){delete _0x3d161b[_0x63d7('0x64')]['id'];}if(_[_0x63d7('0x74')](_0x3d161b[_0x63d7('0x64')][_0x63d7('0x75')])){throw new db[(_0x63d7('0x1d'))][(_0x63d7('0x76'))](_0x63d7('0x77'));}if(_['isNil'](_0x3d161b[_0x63d7('0x64')][_0x63d7('0x64')])||_0x3d161b[_0x63d7('0x64')][_0x63d7('0x64')]===''){throw new db[(_0x63d7('0x1d'))][(_0x63d7('0x76'))](_0x63d7('0x78'));}if(_[_0x63d7('0x74')](_0x3d161b[_0x63d7('0x64')][_0x63d7('0x79')])){throw new db['Sequelize'][(_0x63d7('0x76'))](_0x63d7('0x7a')+_0x1a3472);}if(!_[_0x63d7('0x7b')](_0x1a3472,_0x3d161b[_0x63d7('0x64')]['mapKey'])){throw new db[(_0x63d7('0x1d'))][(_0x63d7('0x76'))](_0x63d7('0x7c')+_0x1a3472);}_0x47eb62[_0x3d161b[_0x63d7('0x64')][_0x63d7('0x79')]]=_0x3d161b['body'][_0x63d7('0x75')];})[_0x63d7('0x1f')](function(){return db[_0x63d7('0x3d')][_0x63d7('0x5f')]({'where':{'id':_0x3d161b[_0x63d7('0x58')]['id']},'include':[{'model':db[_0x63d7('0x7d')],'as':_0x63d7('0x7e'),'include':[{'model':db['CmContact'],'as':_0x63d7('0x7f'),'where':_0x47eb62,'limit':0x1,'order':[[_0x63d7('0x80'),_0x63d7('0x81')]]}]},{'model':db[_0x63d7('0x82')],'as':_0x63d7('0x83')}]});})['then'](handleEntityNotFound(_0x38cd91,null))[_0x63d7('0x1f')](function(_0x40d133){if(_0x40d133&&_0x40d133[_0x63d7('0x7e')]){_0x72be6c['account']=_0x40d133;_0x72be6c[_0x63d7('0x84')]=_0x40d133['Applications'];_0x72be6c[_0x63d7('0x85')]=_0x40d133[_0x63d7('0x7e')];_0x72be6c[_0x63d7('0x84')]=_[_0x63d7('0x86')](_0x72be6c[_0x63d7('0x84')],['priority'],[_0x63d7('0x87')]);if(_0x72be6c['account'][_0x63d7('0x83')]){delete _0x72be6c[_0x63d7('0x88')][_0x63d7('0x83')];}if(_0x72be6c[_0x63d7('0x88')][_0x63d7('0x7e')]&&_0x72be6c['account'][_0x63d7('0x7e')][_0x63d7('0x7f')][_0x63d7('0x47')]){return _0x72be6c[_0x63d7('0x88')][_0x63d7('0x7e')]['Contacts'][0x0];}var _0x1caa22=_[_0x63d7('0x16')](_0x3d161b[_0x63d7('0x64')],{'firstName':_0x3d161b[_0x63d7('0x64')][_0x63d7('0x75')],'ListId':_0x40d133[_0x63d7('0x89')]});_0x1caa22[_0x3d161b[_0x63d7('0x64')]['mapKey']]=_0x3d161b[_0x63d7('0x64')][_0x63d7('0x75')];return db[_0x63d7('0x8a')][_0x63d7('0x5a')](_0x1caa22,{'fields':_0x3d4259,'raw':!![]});}})['then'](handleEntityNotFound(_0x38cd91,null))[_0x63d7('0x1f')](function(_0x175691){_0x72be6c['contact']=_0x175691;if(_0x175691){var _0x144760={'ContactId':_0x175691['id'],'OpenchannelAccountId':_0x3d161b['params']['id'],'from':(_0x175691[_0x63d7('0x8b')]||'')+'\x20'+(_0x175691['lastName']||'')};var _0x316ce8={'OpenchannelAccountId':_0x3d161b['params']['id'],'closed':![]};if(_0x3d161b[_0x63d7('0x64')][_0x63d7('0x8c')]){_0x316ce8[_0x63d7('0x8c')]=_0x3d161b[_0x63d7('0x64')][_0x63d7('0x8c')];return db['OpenchannelInteraction']['find']({'where':_0x316ce8})[_0x63d7('0x1f')](function(_0x31ee3f){if(_0x31ee3f){return[_0x31ee3f,![]];}_0x144760['threadId']=_0x3d161b[_0x63d7('0x64')][_0x63d7('0x8c')];_0x144760[_0x63d7('0x8d')]=_0x3d161b[_0x63d7('0x64')][_0x63d7('0x8d')];return db[_0x63d7('0x8e')][_0x63d7('0x5a')](_0x144760)[_0x63d7('0x1f')](function(_0x4e6acc){return[_0x4e6acc,!![]];});});}else{_0x316ce8[_0x63d7('0x8c')]=null;}_0x316ce8[_0x63d7('0x8f')]=_0x175691['id'];return db[_0x63d7('0x8e')][_0x63d7('0x5f')]({'where':_0x316ce8})[_0x63d7('0x1f')](function(_0x1a67c4){if(_0x1a67c4){return[_0x1a67c4,![]];}return db[_0x63d7('0x8e')][_0x63d7('0x5a')](_0x144760)[_0x63d7('0x1f')](function(_0x4ee337){return[_0x4ee337,!![]];});});}})[_0x63d7('0x90')](function(_0x7238f,_0x3bcf10){if(_0x7238f){_0x305a1e=_0x3bcf10;if(!_0x3bcf10){var _0x58fb68={'from':(_0x72be6c[_0x63d7('0x91')]['firstName']||'')+'\x20'+(_0x72be6c[_0x63d7('0x91')][_0x63d7('0x92')]||'')};if(_0x3d161b[_0x63d7('0x64')]['threadId']&&_0x3d161b[_0x63d7('0x64')][_0x63d7('0x93')]&&_0x3d161b['body'][_0x63d7('0x8c')]!=_0x3d161b[_0x63d7('0x64')][_0x63d7('0x93')]){_0x58fb68['threadId']=_0x3d161b['body'][_0x63d7('0x93')];}return _0x7238f[_0x63d7('0x34')](_0x58fb68);}else{return _0x7238f;}}})[_0x63d7('0x1f')](function(_0x627d21){_0x72be6c[_0x63d7('0x94')]=_0x627d21['get']({'plain':!![]});_0x72be6c[_0x63d7('0x94')][_0x63d7('0x95')]=_0x305a1e;if(_0x72be6c[_0x63d7('0x94')][_0x63d7('0x95')]){if(_0x72be6c[_0x63d7('0x88')]['autoclose']){_0x72be6c[_0x63d7('0x84')][_0x63d7('0x96')]({'id':0x0,'priority':_0x72be6c[_0x63d7('0x84')][_0x63d7('0x47')]+0x1,'app':'close','appdata':_0x63d7('0x97'),'interval':'*,*,*,*'});}}return db[_0x63d7('0x98')][_0x63d7('0x5a')]({'body':_0x3d161b[_0x63d7('0x64')]['body'],'OpenchannelAccountId':_0x3d161b[_0x63d7('0x58')]['id'],'OpenchannelInteractionId':_0x627d21['id'],'direction':'in','ContactId':_0x72be6c[_0x63d7('0x91')]['id'],'AttachmentId':_0x3d161b[_0x63d7('0x64')][_0x63d7('0x99')]});})[_0x63d7('0x1f')](function(_0x3eec2a){_0x72be6c[_0x63d7('0x28')]=_0x3eec2a;if(_0x72be6c[_0x63d7('0x94')][_0x63d7('0x9a')]){return db['User'][_0x63d7('0x5f')]({'attributes':['id',_0x63d7('0x38')],'where':{'id':_0x72be6c[_0x63d7('0x94')][_0x63d7('0x9a')]}})['then'](function(_0x3fdec8){if(_0x3fdec8){_0x72be6c[_0x63d7('0x84')][_0x63d7('0x9b')]({'id':0x0,'priority':0x0,'app':_0x63d7('0x9c'),'appdata':_0x3fdec8[_0x63d7('0x38')]+','+(_0x72be6c[_0x63d7('0x88')][_0x63d7('0x9d')]||0xa),'interval':_0x63d7('0x9e')});_0x72be6c[_0x63d7('0x9f')]=![];}return respondWithRpcPromise('Start',_0x63d7('0xa0'),_0x72be6c);});}return respondWithRpcPromise(_0x63d7('0xa1'),_0x63d7('0xa0'),_0x72be6c);})[_0x63d7('0x1f')](function(_0x48d284){respondWithRpcPromise('EventManager',_0x63d7('0xa2'),{'event':_0x63d7('0x6f'),'message':_0x48d284},client9002);return _0x48d284;})[_0x63d7('0x1f')](respondWithResult(_0x38cd91,null))[_0x63d7('0x2a')](handleError(_0x38cd91,null));};exports['addApplications']=function(_0x3c888e,_0xa66d90,_0x3dd676){return db[_0x63d7('0x3d')][_0x63d7('0x69')]({'where':{'id':_0x3c888e['params']['id']}})[_0x63d7('0x1f')](handleEntityNotFound(_0xa66d90,null))['then'](function(_0x376711){if(_0x376711){return db[_0x63d7('0xa3')]['transaction'](function(_0x51c328){return db[_0x63d7('0x82')]['destroy']({'where':{'OpenchannelAccountId':_0x3c888e[_0x63d7('0x58')]['id']},'transaction':_0x51c328})[_0x63d7('0x1f')](function(_0x1efe89){var _0x52f53c=_[_0x63d7('0x3c')](_0x3c888e[_0x63d7('0x64')],function(_0x5ce0b8){_0x5ce0b8[_0x63d7('0xa4')]=_0x3c888e[_0x63d7('0x58')]['id'];return _0x5ce0b8;});return db[_0x63d7('0x82')][_0x63d7('0xa5')](_0x52f53c,{'transaction':_0x51c328});});})[_0x63d7('0x1f')](function(){return db[_0x63d7('0x82')][_0x63d7('0xa6')]({'where':{'OpenchannelAccountId':_0x3c888e['params']['id']},'order':'priority'});});}})['then'](respondWithResult(_0xa66d90,null))[_0x63d7('0x2a')](handleError(_0xa66d90,null));};exports[_0x63d7('0xa7')]=function(_0x1acc6e,_0x5c623c,_0x597d70){var _0x5bd991={};var _0x226733={};var _0xe1fc8c;var _0x4d4191;return db['OpenchannelAccount']['findOne']({'where':{'id':_0x1acc6e[_0x63d7('0x58')]['id']}})['then'](handleEntityNotFound(_0x5c623c,null))['then'](function(_0x26148f){if(_0x26148f){_0xe1fc8c=_0x26148f;_0x226733['model']=_[_0x63d7('0x43')](db[_0x63d7('0x82')][_0x63d7('0x3e')]);_0x226733['query']=_[_0x63d7('0x43')](_0x1acc6e[_0x63d7('0x42')]);_0x226733[_0x63d7('0x4e')]=_['intersection'](_0x226733['model'],_0x226733[_0x63d7('0x42')]);_0x5bd991[_0x63d7('0x44')]=_['intersection'](_0x226733[_0x63d7('0x41')],qs[_0x63d7('0x46')](_0x1acc6e[_0x63d7('0x42')][_0x63d7('0x46')]));_0x5bd991[_0x63d7('0x44')]=_0x5bd991['attributes'][_0x63d7('0x47')]?_0x5bd991[_0x63d7('0x44')]:_0x226733[_0x63d7('0x41')];_0x5bd991[_0x63d7('0x4b')]=qs[_0x63d7('0x4c')](_0x1acc6e['query'][_0x63d7('0x4c')]);_0x5bd991['where']=qs[_0x63d7('0x4e')](_[_0x63d7('0x4f')](_0x1acc6e[_0x63d7('0x42')],_0x226733['filters']));if(_0x1acc6e[_0x63d7('0x42')][_0x63d7('0x51')]){_0x5bd991[_0x63d7('0x4d')]=_[_0x63d7('0x50')](_0x5bd991['where'],{'$or':_['map'](_0x5bd991[_0x63d7('0x44')],function(_0x292a29){var _0x3d98b8={};_0x3d98b8[_0x292a29]={'$like':'%'+_0x1acc6e['query'][_0x63d7('0x51')]+'%'};return _0x3d98b8;})});}_0x5bd991=_['merge']({},_0x5bd991,_0x1acc6e['options']);return _0xe1fc8c['getApplications'](_0x5bd991);}})[_0x63d7('0x1f')](function(_0x2e6eb1){if(_0x2e6eb1){_0x4d4191=_0x2e6eb1[_0x63d7('0x47')];if(!_0x1acc6e[_0x63d7('0x42')][_0x63d7('0x48')](_0x63d7('0x49'))){_0x5bd991[_0x63d7('0x4a')]=qs['limit'](_0x1acc6e[_0x63d7('0x42')][_0x63d7('0x4a')]);_0x5bd991[_0x63d7('0x2f')]=qs['offset'](_0x1acc6e['query'][_0x63d7('0x2f')]);}return _0xe1fc8c[_0x63d7('0xa7')](_0x5bd991);}})[_0x63d7('0x1f')](function(_0x4f2546){if(_0x4f2546){return _0x4f2546?{'count':_0x4d4191,'rows':_0x4f2546}:null;}})[_0x63d7('0x1f')](respondWithResult(_0x5c623c,null))[_0x63d7('0x2a')](handleError(_0x5c623c,null));};exports[_0x63d7('0xa8')]=function(_0x56dfe0,_0x2caf82,_0x152cbc){var _0x34c6cd={'raw':![],'where':{}};var _0x70c143={};var _0x72a64c={'count':0x0,'rows':[]};return db['OpenchannelAccount'][_0x63d7('0x69')]({'where':{'id':_0x56dfe0[_0x63d7('0x58')]['id']}})[_0x63d7('0x1f')](handleEntityNotFound(_0x2caf82,null))[_0x63d7('0x1f')](function(_0x500054){if(_0x500054){_0x70c143['model']=_[_0x63d7('0x43')](db['OpenchannelInteraction'][_0x63d7('0x3e')]);_0x70c143[_0x63d7('0x42')]=_[_0x63d7('0x43')](_0x56dfe0[_0x63d7('0x42')]);_0x70c143[_0x63d7('0x4e')]=_['intersection'](_0x70c143['model'],_0x70c143[_0x63d7('0x42')]);_0x34c6cd[_0x63d7('0x44')]=_[_0x63d7('0x45')](_0x70c143[_0x63d7('0x41')],qs[_0x63d7('0x46')](_0x56dfe0['query'][_0x63d7('0x46')]));_0x34c6cd[_0x63d7('0x44')]=_0x34c6cd[_0x63d7('0x44')][_0x63d7('0x47')]?_0x34c6cd[_0x63d7('0x44')]:_0x70c143[_0x63d7('0x41')];if(!_0x56dfe0[_0x63d7('0x42')][_0x63d7('0x48')]('nolimit')){_0x34c6cd[_0x63d7('0x4a')]=qs['limit'](_0x56dfe0[_0x63d7('0x42')][_0x63d7('0x4a')]);_0x34c6cd[_0x63d7('0x2f')]=qs[_0x63d7('0x2f')](_0x56dfe0[_0x63d7('0x42')][_0x63d7('0x2f')]);}_0x34c6cd[_0x63d7('0x4b')]=qs[_0x63d7('0x4c')](_0x56dfe0['query'][_0x63d7('0x4c')]);_0x34c6cd[_0x63d7('0x4d')]=qs[_0x63d7('0x4e')](_['pick'](_0x56dfe0['query'],_0x70c143[_0x63d7('0x4e')]));_0x34c6cd[_0x63d7('0x4d')][_0x63d7('0xa4')]=_0x500054['id'];if(_0x56dfe0[_0x63d7('0x42')]['filter']){_0x34c6cd[_0x63d7('0x4d')]=_[_0x63d7('0x50')](_0x34c6cd[_0x63d7('0x4d')],{'$or':_[_0x63d7('0x3c')](_0x34c6cd[_0x63d7('0x44')],function(_0x569700){var _0x32a38d={};_0x32a38d[_0x569700]={'$like':'%'+_0x56dfe0['query']['filter']+'%'};return _0x32a38d;})});}_0x34c6cd=_['merge']({},_0x34c6cd,_0x56dfe0['options']);return db[_0x63d7('0x8e')][_0x63d7('0x52')]({'where':_0x34c6cd[_0x63d7('0x4d')]})[_0x63d7('0x1f')](function(_0x26d088){_0x72a64c['count']=_0x26d088;if(_0x56dfe0['query'][_0x63d7('0x53')]){_0x34c6cd['include']=[{'model':db[_0x63d7('0x8a')],'as':_0x63d7('0xa9'),'required':![]},{'model':db[_0x63d7('0xaa')],'as':'Owner','attributes':['name',_0x63d7('0xab'),'internal'],'required':![]},{'model':db['Tag'],'as':_0x63d7('0xac'),'attributes':['id','name',_0x63d7('0xad')],'where':_0x56dfe0[_0x63d7('0x42')][_0x63d7('0xae')]?{'id':_0x56dfe0[_0x63d7('0x42')][_0x63d7('0xae')]}:undefined,'required':_0x56dfe0[_0x63d7('0x42')][_0x63d7('0xae')]?!![]:![]}];}return db[_0x63d7('0x8e')][_0x63d7('0x55')](_0x34c6cd);})[_0x63d7('0x1f')](function(_0x1508ab){_0x72a64c['rows']=_0x1508ab;return _0x72a64c;});}})['then'](respondWithFilteredResult(_0x2caf82,_0x34c6cd))[_0x63d7('0x2a')](handleError(_0x2caf82,null));};exports[_0x63d7('0xaf')]=function(_0x13e0e6,_0x298366,_0xa222f1){return db[_0x63d7('0x3d')]['find']({'where':{'id':_0x13e0e6['params']['id']}})['then'](handleEntityNotFound(_0x298366,null))[_0x63d7('0x1f')](function(_0x148794){if(_0x148794){return _0x148794[_0x63d7('0xaf')](_0x13e0e6[_0x63d7('0x64')]['ids'],_['omit'](_0x13e0e6[_0x63d7('0x64')],['ids','id'])||{})['spread'](function(_0x15a3c7){for(var _0x93adb4=0x0;_0x93adb4<_0x13e0e6[_0x63d7('0x64')][_0x63d7('0x6e')]['length'];_0x93adb4+=0x1){socket[_0x63d7('0xb0')]('userOpenchannelAccount:save',{'UserId':_0x13e0e6[_0x63d7('0x64')][_0x63d7('0x6e')][_0x93adb4],'OpenchannelAccountId':_0x13e0e6[_0x63d7('0x58')]['id']});}return _0x15a3c7;});}})[_0x63d7('0x1f')](respondWithResult(_0x298366,null))[_0x63d7('0x2a')](handleError(_0x298366,null));};exports[_0x63d7('0xb1')]=function(_0x1285e8,_0x1b108c,_0x5da0cd){return db[_0x63d7('0x3d')]['find']({'where':{'id':_0x1285e8[_0x63d7('0x58')]['id']}})[_0x63d7('0x1f')](handleEntityNotFound(_0x1b108c,null))[_0x63d7('0x1f')](function(_0x522229){if(_0x522229){return _0x522229[_0x63d7('0xb1')](_0x1285e8[_0x63d7('0x42')]['ids'])[_0x63d7('0x1f')](function(){if(_[_0x63d7('0xb2')](_0x1285e8[_0x63d7('0x42')][_0x63d7('0x6e')])){for(var _0xc266bf=0x0;_0xc266bf<_0x1285e8[_0x63d7('0x42')]['ids'][_0x63d7('0x47')];_0xc266bf+=0x1){socket[_0x63d7('0xb0')](_0x63d7('0xb3'),{'UserId':Number(_0x1285e8['query']['ids'][_0xc266bf]),'OpenchannelAccountId':Number(_0x1285e8[_0x63d7('0x58')]['id'])});}}else{socket[_0x63d7('0xb0')]('userOpenchannelAccount:remove',{'UserId':Number(_0x1285e8[_0x63d7('0x42')][_0x63d7('0x6e')]),'OpenchannelAccountId':Number(_0x1285e8['params']['id'])});}});}})['then'](respondWithStatusCode(_0x1b108c,null))[_0x63d7('0x2a')](handleError(_0x1b108c,null));};exports[_0x63d7('0xb4')]=function(_0x7908ff,_0x5d42e0,_0x453993){var _0x3d3cd5={};var _0x43adec={};var _0x2a1ff3;var _0x3d549e;return db[_0x63d7('0x3d')][_0x63d7('0x69')]({'where':{'id':_0x7908ff[_0x63d7('0x58')]['id']}})['then'](handleEntityNotFound(_0x5d42e0,null))['then'](function(_0x338423){if(_0x338423){_0x2a1ff3=_0x338423;_0x43adec[_0x63d7('0x41')]=_[_0x63d7('0x43')](db[_0x63d7('0xaa')][_0x63d7('0x3e')]);_0x43adec['query']=_[_0x63d7('0x43')](_0x7908ff[_0x63d7('0x42')]);_0x43adec['filters']=_[_0x63d7('0x45')](_0x43adec[_0x63d7('0x41')],_0x43adec[_0x63d7('0x42')]);_0x3d3cd5[_0x63d7('0x44')]=_['intersection'](_0x43adec['model'],qs[_0x63d7('0x46')](_0x7908ff[_0x63d7('0x42')]['fields']));_0x3d3cd5[_0x63d7('0x44')]=_0x3d3cd5[_0x63d7('0x44')][_0x63d7('0x47')]?_0x3d3cd5[_0x63d7('0x44')]:_0x43adec['model'];_0x3d3cd5[_0x63d7('0x4b')]=qs[_0x63d7('0x4c')](_0x7908ff['query']['sort']);_0x3d3cd5[_0x63d7('0x4d')]=qs[_0x63d7('0x4e')](_['pick'](_0x7908ff[_0x63d7('0x42')],_0x43adec[_0x63d7('0x4e')]));if(_0x7908ff[_0x63d7('0x42')][_0x63d7('0x51')]){_0x3d3cd5[_0x63d7('0x4d')]=_[_0x63d7('0x50')](_0x3d3cd5['where'],{'$or':_[_0x63d7('0x3c')](_0x3d3cd5[_0x63d7('0x44')],function(_0x1875d0){var _0x3a2d70={};_0x3a2d70[_0x1875d0]={'$like':'%'+_0x7908ff[_0x63d7('0x42')][_0x63d7('0x51')]+'%'};return _0x3a2d70;})});}_0x3d3cd5=_[_0x63d7('0x50')]({},_0x3d3cd5,_0x7908ff[_0x63d7('0x59')]);return _0x2a1ff3[_0x63d7('0xb4')](_0x3d3cd5);}})['then'](function(_0x2c8047){if(_0x2c8047){_0x3d549e=_0x2c8047[_0x63d7('0x47')];if(!_0x7908ff[_0x63d7('0x42')][_0x63d7('0x48')](_0x63d7('0x49'))){_0x3d3cd5[_0x63d7('0x4a')]=qs[_0x63d7('0x4a')](_0x7908ff['query'][_0x63d7('0x4a')]);_0x3d3cd5[_0x63d7('0x2f')]=qs[_0x63d7('0x2f')](_0x7908ff[_0x63d7('0x42')][_0x63d7('0x2f')]);}return _0x2a1ff3['getAgents'](_0x3d3cd5);}})[_0x63d7('0x1f')](function(_0x2eacd5){if(_0x2eacd5){return _0x2eacd5?{'count':_0x3d549e,'rows':_0x2eacd5}:null;}})[_0x63d7('0x1f')](respondWithResult(_0x5d42e0,null))[_0x63d7('0x2a')](handleError(_0x5d42e0,null));};exports[_0x63d7('0x39')]=function(_0x2155e1,_0x50f944,_0x6c277a){var _0x48707b,_0x2ba960,_0x1de516;if(_[_0x63d7('0x74')](_0x2155e1[_0x63d7('0x64')]['body'])||_0x2155e1[_0x63d7('0x64')][_0x63d7('0x64')]===''){throw new db['Sequelize'][(_0x63d7('0x76'))](_0x63d7('0x78'));}if(_['isNil'](_0x2155e1[_0x63d7('0x64')]['to'])){}_0x48707b=_0x2155e1['body']['to'];return db[_0x63d7('0x3d')][_0x63d7('0x69')]({'where':{'id':_0x2155e1[_0x63d7('0x58')]['id']}})[_0x63d7('0x1f')](handleEntityNotFound(_0x50f944,null))[_0x63d7('0x1f')](function(_0x535984){if(_0x535984){return db['OpenchannelAccount']['find']({'where':{'id':_0x535984['id']},'include':[{'model':db['CmList'],'as':_0x63d7('0x7e'),'include':[{'model':db[_0x63d7('0x8a')],'as':_0x63d7('0x7f'),'where':{[_0x535984[_0x63d7('0x79')]]:_0x48707b},'limit':0x1,'order':[[_0x63d7('0x80'),_0x63d7('0x81')]]}]}]})['then'](handleEntityNotFound(_0x50f944,null))[_0x63d7('0x1f')](function(_0x3b267f){if(_0x3b267f&&_0x3b267f[_0x63d7('0x7e')]){_0x2ba960=_0x3b267f[_0x63d7('0x5c')]({'plain':!![]});if(_0x2ba960[_0x63d7('0x7e')]&&_0x2ba960[_0x63d7('0x7e')][_0x63d7('0x7f')][_0x63d7('0x47')]){return _0x2ba960['List'][_0x63d7('0x7f')][0x0];}return db['CmContact'][_0x63d7('0x5a')](_[_0x63d7('0x16')](_0x2155e1[_0x63d7('0x64')],{'firstName':_0x48707b,[_0x3b267f[_0x63d7('0x79')]]:_0x48707b,'phone':_0x48707b,'ListId':_0x2ba960[_0x63d7('0x89')]}));}})[_0x63d7('0x1f')](handleEntityNotFound(_0x50f944,null))['then'](function(_0x5b395b){if(_0x5b395b){_0x1de516=_0x5b395b;return db[_0x63d7('0x8e')][_0x63d7('0x5f')]({'where':{'ContactId':_0x1de516['id'],'closed':![],'OpenchannelAccountId':_0x2ba960['id']}})[_0x63d7('0x1f')](function(_0x5f4579){if(_0x5f4579){return[_0x5f4579,![]];}return db[_0x63d7('0x8e')][_0x63d7('0x5a')]({'UserId':_0x2155e1[_0x63d7('0x5b')]['id'],'ContactId':_0x1de516['id'],'OpenchannelAccountId':_0x2ba960['id'],'lastMsgDirection':_0x63d7('0xb5'),'Messages':[_['merge'](_0x2155e1[_0x63d7('0x64')],{'read':![],'body':_0x2155e1[_0x63d7('0x64')]['body'],'OpenchannelAccountId':_0x2ba960['id'],'UserId':_0x2155e1['user']['id'],'ContactId':_0x1de516['id']})]},{'include':[{'model':db[_0x63d7('0x98')],'as':'Messages'}]})[_0x63d7('0x1f')](function(_0x21fbb1){return[_0x21fbb1,!![]];});});}})[_0x63d7('0x90')](function(_0x15a250,_0x1dd6e1){if(_0x1dd6e1){return _0x15a250;}return db[_0x63d7('0x98')][_0x63d7('0x5a')](_['merge'](_0x2155e1[_0x63d7('0x64')],{'read':![],'body':_0x2155e1[_0x63d7('0x64')][_0x63d7('0x64')],'OpenchannelAccountId':_0x2ba960['id'],'OpenchannelInteractionId':_0x15a250['id'],'UserId':_0x2155e1[_0x63d7('0x5b')]['id'],'ContactId':_0x1de516['id']}))[_0x63d7('0x1f')](function(_0xc43278){_0x15a250[_0x63d7('0xb6')]['Messages']=[];_0x15a250[_0x63d7('0xb6')]['Messages']['push'](_0xc43278[_0x63d7('0xb6')]);return _0x15a250;});});}})[_0x63d7('0x1f')](respondWithResult(_0x50f944,null))[_0x63d7('0x2a')](handleError(_0x50f944,null));};
\ No newline at end of file
+var _0x8248=['params','length','include','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','OpenchannelAccounts','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','OpenchannelAccountId','getDispositions','findOne','Disposition','removeDispositions','ids','addAnswer','CannedAnswer','removeAnswers','notify','openchannel','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','ListId','isNil','from','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','List','Contacts','DESC','Applications','account','applications','list','orderBy','priority','asc','defaults','contact','firstName','threadId','OpenchannelInteraction','externalUrl','ContactId','lastName','messageId','interaction','created','autoclose','push','close','unmanaged','*,*,*,*','OpenchannelMessage','UserId','User','unshift','agent','waitForTheAssignedAgent','forcedOwnership','Start','startRouting','EventManager','addApplications','sequelize','transaction','Transaction','ISOLATION_LEVELS','OpenchannelApplication','bulkCreate','findAndCountAll','finally','getApplications','getInteractions','Owner','internal','Tag','Tags','tag','addAgents','omit','spread','emit','removeAgents','isArray','userOpenchannelAccount:remove','getAgents','CmList','out','Messages','eml-format','rimraf','fast-json-patch','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','../../components/parsers/advancedSearch','../../config/utils','../../config/environment','../../config/license/util','redis','socket.io-emitter','./openchannelAccount.socket','register','jayson/promise','client','http','info','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','sendStatus','status','end','json','limit','undefined','count','set','Content-Range','apply','reject','update','then','destroy','get','UserProfileResource','stack','name','send','index','Pause','mandatoryDispositionPause','map','OpenchannelAccount','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','offset','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','findAll','rows','catch'];(function(_0x51b0dc,_0x5307b7){var _0x13fa89=function(_0x2c880f){while(--_0x2c880f){_0x51b0dc['push'](_0x51b0dc['shift']());}};_0x13fa89(++_0x5307b7);}(_0x8248,0x67));var _0x8824=function(_0x4c7225,_0x4dc28d){_0x4c7225=_0x4c7225-0x0;var _0x19f1ed=_0x8248[_0x4c7225];return _0x19f1ed;};'use strict';var emlformat=require(_0x8824('0x0'));var rimraf=require(_0x8824('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x8824('0x2'));var rp=require('request-promise');var moment=require(_0x8824('0x3'));var BPromise=require(_0x8824('0x4'));var Mustache=require('mustache');var util=require(_0x8824('0x5'));var path=require(_0x8824('0x6'));var sox=require(_0x8824('0x7'));var csv=require(_0x8824('0x8'));var ejs=require(_0x8824('0x9'));var fs=require('fs');var fs_extra=require(_0x8824('0xa'));var _=require(_0x8824('0xb'));var squel=require(_0x8824('0xc'));var crypto=require(_0x8824('0xd'));var jsforce=require(_0x8824('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x8824('0x8'));var querystring=require(_0x8824('0xf'));var Papa=require(_0x8824('0x10'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x8824('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0x8824('0x12'));var config=require(_0x8824('0x13'));var licenseUtil=require(_0x8824('0x14'));var db=require('../../mysqldb')['db'];config[_0x8824('0x15')]=_['defaults'](config[_0x8824('0x15')],{'host':'localhost','port':0x18eb});var socket=require(_0x8824('0x16'))(new Redis(config[_0x8824('0x15')]));require(_0x8824('0x17'))[_0x8824('0x18')](socket);var jayson=require(_0x8824('0x19'));var client=jayson[_0x8824('0x1a')][_0x8824('0x1b')]({'port':0x232c});var client9002=jayson[_0x8824('0x1a')][_0x8824('0x1b')]({'port':0x232a});function respondWithRpcPromise(_0x447946,_0x367ffe,_0x34afb5,_0x37bb4c){return new BPromise(function(_0x21ebd4,_0x5ce033){var _0x1635e4=_0x37bb4c||client;return _0x1635e4['request'](_0x447946,_0x34afb5)['then'](function(_0x32cd83){logger[_0x8824('0x1c')](_0x8824('0x1d'),_0x367ffe,_0x8824('0x1e'));logger['debug'](_0x8824('0x1f'),_0x367ffe,'request\x20sent',JSON[_0x8824('0x20')](_0x32cd83));if(_0x32cd83['error']){if(_0x32cd83[_0x8824('0x21')][_0x8824('0x22')]===0x1f4){logger[_0x8824('0x21')](_0x8824('0x1d'),_0x367ffe,_0x32cd83[_0x8824('0x21')][_0x8824('0x23')]);return _0x5ce033(_0x32cd83[_0x8824('0x21')]['message']);}logger[_0x8824('0x21')](_0x8824('0x1d'),_0x367ffe,_0x32cd83[_0x8824('0x21')][_0x8824('0x23')]);return _0x21ebd4(_0x32cd83['error'][_0x8824('0x23')]);}else{logger['info']('OpenchannelAccount,\x20%s,\x20%s',_0x367ffe,_0x8824('0x1e'));_0x21ebd4(_0x32cd83[_0x8824('0x24')][_0x8824('0x23')]);}})['catch'](function(_0xd89d43){logger[_0x8824('0x21')](_0x8824('0x1d'),_0x367ffe,_0xd89d43);_0x5ce033(_0xd89d43);});});}function respondWithStatusCode(_0x44d4d6,_0x4a967d){_0x4a967d=_0x4a967d||0xcc;return function(_0x321695){if(_0x321695){return _0x44d4d6[_0x8824('0x25')](_0x4a967d);}return _0x44d4d6[_0x8824('0x26')](_0x4a967d)[_0x8824('0x27')]();};}function respondWithResult(_0x181562,_0xc22bd4){_0xc22bd4=_0xc22bd4||0xc8;return function(_0x253a41){if(_0x253a41){return _0x181562[_0x8824('0x26')](_0xc22bd4)[_0x8824('0x28')](_0x253a41);}};}function respondWithFilteredResult(_0xfe4d0b,_0x4bb39a){return function(_0x137523){if(_0x137523){var _0x5bac2d=typeof _0x4bb39a['offset']==='undefined'&&typeof _0x4bb39a[_0x8824('0x29')]===_0x8824('0x2a');var _0x2d946c=_0x137523[_0x8824('0x2b')];var _0x34260c=_0x5bac2d?0x0:_0x4bb39a['offset'];var _0x532b25=_0x5bac2d?_0x137523['count']:_0x4bb39a['offset']+_0x4bb39a['limit'];var _0x17a995;if(_0x532b25>=_0x2d946c){_0x532b25=_0x2d946c;_0x17a995=0xc8;}else{_0x17a995=0xce;}_0xfe4d0b['status'](_0x17a995);return _0xfe4d0b[_0x8824('0x2c')](_0x8824('0x2d'),_0x34260c+'-'+_0x532b25+'/'+_0x2d946c)[_0x8824('0x28')](_0x137523);}return null;};}function patchUpdates(_0x49dac8){return function(_0x51cf4e){try{jsonpatch[_0x8824('0x2e')](_0x51cf4e,_0x49dac8,!![]);}catch(_0xc91479){return BPromise[_0x8824('0x2f')](_0xc91479);}return _0x51cf4e['save']();};}function saveUpdates(_0x6fd49f,_0x329072){return function(_0x524976){if(_0x524976){return _0x524976[_0x8824('0x30')](_0x6fd49f)[_0x8824('0x31')](function(_0x1ce485){return _0x1ce485;});}return null;};}function removeEntity(_0x200adb,_0xc6cb29){return function(_0x4a4ca7){if(_0x4a4ca7){return _0x4a4ca7[_0x8824('0x32')]()[_0x8824('0x31')](function(){var _0x122b76=_0x4a4ca7[_0x8824('0x33')]({'plain':!![]});var _0x1714c6='OpenchannelAccounts';return db[_0x8824('0x34')][_0x8824('0x32')]({'where':{'type':_0x1714c6,'resourceId':_0x122b76['id']}})[_0x8824('0x31')](function(){return _0x4a4ca7;});})[_0x8824('0x31')](function(){_0x200adb[_0x8824('0x26')](0xcc)[_0x8824('0x27')]();});}};}function handleEntityNotFound(_0x19b775,_0x18f4ff){return function(_0xa86d7){if(!_0xa86d7){_0x19b775[_0x8824('0x25')](0x194);}return _0xa86d7;};}function handleError(_0x29be04,_0x572a7d){_0x572a7d=_0x572a7d||0x1f4;return function(_0x27af2c){logger[_0x8824('0x21')](_0x27af2c[_0x8824('0x35')]);if(_0x27af2c[_0x8824('0x36')]){delete _0x27af2c[_0x8824('0x36')];}_0x29be04['status'](_0x572a7d)[_0x8824('0x37')](_0x27af2c);};}exports[_0x8824('0x38')]=function(_0x5cff82,_0x2c95d2){var _0x452bc4={'include':[{'model':db[_0x8824('0x39')],'as':_0x8824('0x3a')}]},_0x1e7cae={},_0x312020={'count':0x0,'rows':[]};var _0xac8792=_[_0x8824('0x3b')](db[_0x8824('0x3c')][_0x8824('0x3d')],function(_0x3a1fd5){return{'name':_0x3a1fd5[_0x8824('0x3e')],'type':_0x3a1fd5[_0x8824('0x3f')]['key']};});_0x1e7cae[_0x8824('0x40')]=_[_0x8824('0x3b')](_0xac8792,_0x8824('0x36'));_0x1e7cae[_0x8824('0x41')]=_[_0x8824('0x42')](_0x5cff82[_0x8824('0x41')]);_0x1e7cae[_0x8824('0x43')]=_[_0x8824('0x44')](_0x1e7cae[_0x8824('0x40')],_0x1e7cae[_0x8824('0x41')]);_0x452bc4[_0x8824('0x45')]=_[_0x8824('0x44')](_0x1e7cae['model'],qs[_0x8824('0x46')](_0x5cff82[_0x8824('0x41')]['fields']));_0x452bc4[_0x8824('0x45')]=_0x452bc4[_0x8824('0x45')]['length']?_0x452bc4[_0x8824('0x45')]:_0x1e7cae[_0x8824('0x40')];if(!_0x5cff82['query'][_0x8824('0x47')](_0x8824('0x48'))){_0x452bc4[_0x8824('0x29')]=qs[_0x8824('0x29')](_0x5cff82['query'][_0x8824('0x29')]);_0x452bc4['offset']=qs[_0x8824('0x49')](_0x5cff82[_0x8824('0x41')]['offset']);}_0x452bc4[_0x8824('0x4a')]=qs['sort'](_0x5cff82[_0x8824('0x41')][_0x8824('0x4b')]);_0x452bc4[_0x8824('0x4c')]=qs[_0x8824('0x43')](_[_0x8824('0x4d')](_0x5cff82['query'],_0x1e7cae[_0x8824('0x43')]),_0xac8792);if(_0x5cff82['query'][_0x8824('0x4e')]){_0x452bc4['where']=_[_0x8824('0x4f')](_0x452bc4[_0x8824('0x4c')],{'$or':_[_0x8824('0x3b')](_0xac8792,function(_0x35502e){if(_0x35502e[_0x8824('0x3f')]!==_0x8824('0x50')){var _0x1c88ea={};_0x1c88ea[_0x35502e[_0x8824('0x36')]]={'$like':'%'+_0x5cff82['query'][_0x8824('0x4e')]+'%'};return _0x1c88ea;}})});}_0x452bc4=_[_0x8824('0x4f')]({},_0x452bc4,_0x5cff82[_0x8824('0x51')]);var _0x84fb40={'where':_0x452bc4['where']};return db[_0x8824('0x3c')]['count'](_0x84fb40)[_0x8824('0x31')](function(_0xfb9dc5){_0x312020[_0x8824('0x2b')]=_0xfb9dc5;if(_0x5cff82[_0x8824('0x41')][_0x8824('0x52')]){_0x452bc4['include']=[{'all':!![]}];}return db[_0x8824('0x3c')][_0x8824('0x53')](_0x452bc4);})[_0x8824('0x31')](function(_0x161bd6){_0x312020[_0x8824('0x54')]=_0x161bd6;return _0x312020;})['then'](respondWithFilteredResult(_0x2c95d2,_0x452bc4))[_0x8824('0x55')](handleError(_0x2c95d2,null));};exports['show']=function(_0x28a274,_0x3ac5f7){var _0x60dd4f={'raw':![],'where':{'id':_0x28a274[_0x8824('0x56')]['id']},'include':[{'model':db['Pause'],'as':_0x8824('0x3a')}]},_0x39853f={};_0x39853f[_0x8824('0x40')]=_['keys'](db['OpenchannelAccount'][_0x8824('0x3d')]);_0x39853f[_0x8824('0x41')]=_[_0x8824('0x42')](_0x28a274[_0x8824('0x41')]);_0x39853f['filters']=_[_0x8824('0x44')](_0x39853f[_0x8824('0x40')],_0x39853f[_0x8824('0x41')]);_0x60dd4f[_0x8824('0x45')]=_['intersection'](_0x39853f['model'],qs[_0x8824('0x46')](_0x28a274[_0x8824('0x41')][_0x8824('0x46')]));_0x60dd4f['attributes']=_0x60dd4f[_0x8824('0x45')][_0x8824('0x57')]?_0x60dd4f['attributes']:_0x39853f['model'];if(_0x28a274[_0x8824('0x41')][_0x8824('0x52')]){_0x60dd4f[_0x8824('0x58')]=[{'all':!![]}];}_0x60dd4f=_['merge']({},_0x60dd4f,_0x28a274[_0x8824('0x51')]);return db[_0x8824('0x3c')][_0x8824('0x59')](_0x60dd4f)[_0x8824('0x31')](handleEntityNotFound(_0x3ac5f7,null))[_0x8824('0x31')](respondWithResult(_0x3ac5f7,null))[_0x8824('0x55')](handleError(_0x3ac5f7,null));};exports['create']=function(_0x46b57b,_0xbe90c1){return db[_0x8824('0x3c')][_0x8824('0x5a')](_0x46b57b[_0x8824('0x5b')],{})[_0x8824('0x31')](function(_0x3e9cb5){var _0x1cb16f=_0x46b57b[_0x8824('0x5c')][_0x8824('0x33')]({'plain':!![]});if(!_0x1cb16f)throw new Error(_0x8824('0x5d'));if(_0x1cb16f['role']===_0x8824('0x5c')){var _0x46b8ac=_0x3e9cb5[_0x8824('0x33')]({'plain':!![]});var _0x27e5e9=_0x8824('0x5e');return db['UserProfileSection']['find']({'where':{'name':_0x27e5e9,'userProfileId':_0x1cb16f[_0x8824('0x5f')]},'raw':!![]})[_0x8824('0x31')](function(_0x404251){if(_0x404251&&_0x404251['autoAssociation']===0x0){return db[_0x8824('0x34')]['create']({'name':_0x46b8ac[_0x8824('0x36')],'resourceId':_0x46b8ac['id'],'type':_0x404251[_0x8824('0x36')],'sectionId':_0x404251['id']},{})[_0x8824('0x31')](function(){return _0x3e9cb5;});}else{return _0x3e9cb5;}})[_0x8824('0x55')](function(_0x1abc59){logger[_0x8824('0x21')](_0x8824('0x60'),_0x1abc59);throw _0x1abc59;});}return _0x3e9cb5;})[_0x8824('0x31')](respondWithResult(_0xbe90c1,0xc9))['catch'](handleError(_0xbe90c1,null));};exports[_0x8824('0x30')]=function(_0x244dd4,_0x3f62d6){if(_0x244dd4[_0x8824('0x5b')]['id']){delete _0x244dd4['body']['id'];}return db[_0x8824('0x3c')][_0x8824('0x59')]({'where':{'id':_0x244dd4['params']['id']},'include':[{'model':db[_0x8824('0x39')],'as':'mandatoryDispositionPause'}]})[_0x8824('0x31')](handleEntityNotFound(_0x3f62d6,null))['then'](saveUpdates(_0x244dd4[_0x8824('0x5b')],null))[_0x8824('0x31')](respondWithResult(_0x3f62d6,null))[_0x8824('0x55')](handleError(_0x3f62d6,null));};exports[_0x8824('0x32')]=function(_0x215358,_0x484025){return db[_0x8824('0x3c')]['find']({'where':{'id':_0x215358[_0x8824('0x56')]['id']}})['then'](handleEntityNotFound(_0x484025,null))['then'](removeEntity(_0x484025,null))[_0x8824('0x55')](handleError(_0x484025,null));};exports[_0x8824('0x61')]=function(_0x11f001,_0x112682){return db['OpenchannelAccount'][_0x8824('0x61')]()['then'](respondWithResult(_0x112682,null))['catch'](handleError(_0x112682,null));};exports[_0x8824('0x62')]=function(_0x442588,_0x18cc36,_0x24d8a7){if(_0x442588[_0x8824('0x5b')]['id']){delete _0x442588[_0x8824('0x5b')]['id'];}return db[_0x8824('0x3c')]['find']({'where':{'id':_0x442588[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x18cc36,null))['then'](function(_0x4d680e){if(_0x4d680e){_0x442588[_0x8824('0x5b')][_0x8824('0x63')]=_0x4d680e['id'];return db['Disposition']['create'](_0x442588[_0x8824('0x5b')]);}})[_0x8824('0x31')](respondWithResult(_0x18cc36,null))[_0x8824('0x55')](handleError(_0x18cc36,null));};exports[_0x8824('0x64')]=function(_0x10f942,_0x24a9b0,_0x17b563){var _0x3c3e3b={'raw':![],'where':{}};var _0xae8665={};var _0x42d7bb={'count':0x0,'rows':[]};return db[_0x8824('0x3c')][_0x8824('0x65')]({'where':{'id':_0x10f942[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x24a9b0,null))[_0x8824('0x31')](function(_0x1476d8){if(_0x1476d8){_0xae8665[_0x8824('0x40')]=_[_0x8824('0x42')](db[_0x8824('0x66')][_0x8824('0x3d')]);_0xae8665['query']=_['keys'](_0x10f942['query']);_0xae8665[_0x8824('0x43')]=_['intersection'](_0xae8665[_0x8824('0x40')],_0xae8665[_0x8824('0x41')]);_0x3c3e3b[_0x8824('0x45')]=_['intersection'](_0xae8665[_0x8824('0x40')],qs[_0x8824('0x46')](_0x10f942[_0x8824('0x41')][_0x8824('0x46')]));_0x3c3e3b[_0x8824('0x45')]=_0x3c3e3b[_0x8824('0x45')][_0x8824('0x57')]?_0x3c3e3b[_0x8824('0x45')]:_0xae8665[_0x8824('0x40')];if(!_0x10f942['query'][_0x8824('0x47')](_0x8824('0x48'))){_0x3c3e3b['limit']=qs[_0x8824('0x29')](_0x10f942[_0x8824('0x41')][_0x8824('0x29')]);_0x3c3e3b[_0x8824('0x49')]=qs[_0x8824('0x49')](_0x10f942['query'][_0x8824('0x49')]);}_0x3c3e3b[_0x8824('0x4a')]=qs[_0x8824('0x4b')](_0x10f942[_0x8824('0x41')][_0x8824('0x4b')]);_0x3c3e3b[_0x8824('0x4c')]=qs[_0x8824('0x43')](_['pick'](_0x10f942[_0x8824('0x41')],_0xae8665[_0x8824('0x43')]));_0x3c3e3b['where'][_0x8824('0x63')]=_0x1476d8['id'];if(_0x10f942[_0x8824('0x41')][_0x8824('0x4e')]){_0x3c3e3b[_0x8824('0x4c')]=_[_0x8824('0x4f')](_0x3c3e3b['where'],{'$or':_[_0x8824('0x3b')](_0x3c3e3b[_0x8824('0x45')],function(_0x33d0e6){var _0x22ddd5={};_0x22ddd5[_0x33d0e6]={'$like':'%'+_0x10f942[_0x8824('0x41')][_0x8824('0x4e')]+'%'};return _0x22ddd5;})});}_0x3c3e3b=_[_0x8824('0x4f')]({},_0x3c3e3b,_0x10f942['options']);return db[_0x8824('0x66')][_0x8824('0x2b')]({'where':_0x3c3e3b[_0x8824('0x4c')]})[_0x8824('0x31')](function(_0x187112){_0x42d7bb['count']=_0x187112;if(_0x10f942[_0x8824('0x41')][_0x8824('0x52')]){_0x3c3e3b['include']=[{'all':!![]}];}return db[_0x8824('0x66')][_0x8824('0x53')](_0x3c3e3b);})[_0x8824('0x31')](function(_0x497911){_0x42d7bb[_0x8824('0x54')]=_0x497911;return _0x42d7bb;});}})['then'](respondWithFilteredResult(_0x24a9b0,_0x3c3e3b))[_0x8824('0x55')](handleError(_0x24a9b0,null));};exports[_0x8824('0x67')]=function(_0x4125e3,_0x5ba86c,_0x3be598){return db[_0x8824('0x3c')][_0x8824('0x59')]({'where':{'id':_0x4125e3[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x5ba86c,null))['then'](function(_0x5515a4){if(_0x5515a4){return _0x5515a4[_0x8824('0x67')](_0x4125e3[_0x8824('0x41')][_0x8824('0x68')]);}})['then'](respondWithStatusCode(_0x5ba86c,null))[_0x8824('0x55')](handleError(_0x5ba86c,null));};exports[_0x8824('0x69')]=function(_0x21c1e2,_0x46956e,_0x43775c){if(_0x21c1e2['body']['id']){delete _0x21c1e2[_0x8824('0x5b')]['id'];}return db[_0x8824('0x3c')][_0x8824('0x59')]({'where':{'id':_0x21c1e2[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x46956e,null))[_0x8824('0x31')](function(_0x10747b){if(_0x10747b){_0x21c1e2['body'][_0x8824('0x63')]=_0x10747b['id'];return db['CannedAnswer'][_0x8824('0x5a')](_0x21c1e2['body']);}})[_0x8824('0x31')](respondWithResult(_0x46956e,null))[_0x8824('0x55')](handleError(_0x46956e,null));};exports['getAnswers']=function(_0x30868b,_0x3bc341,_0x48465a){var _0x2eb894={'raw':![],'where':{}};var _0x541754={};var _0x320f16={'count':0x0,'rows':[]};return db[_0x8824('0x3c')]['findOne']({'where':{'id':_0x30868b['params']['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x3bc341,null))[_0x8824('0x31')](function(_0x1a91c7){if(_0x1a91c7){_0x541754[_0x8824('0x40')]=_[_0x8824('0x42')](db['CannedAnswer']['rawAttributes']);_0x541754[_0x8824('0x41')]=_['keys'](_0x30868b['query']);_0x541754['filters']=_[_0x8824('0x44')](_0x541754[_0x8824('0x40')],_0x541754[_0x8824('0x41')]);_0x2eb894[_0x8824('0x45')]=_[_0x8824('0x44')](_0x541754[_0x8824('0x40')],qs[_0x8824('0x46')](_0x30868b[_0x8824('0x41')][_0x8824('0x46')]));_0x2eb894[_0x8824('0x45')]=_0x2eb894[_0x8824('0x45')]['length']?_0x2eb894[_0x8824('0x45')]:_0x541754[_0x8824('0x40')];if(!_0x30868b[_0x8824('0x41')][_0x8824('0x47')](_0x8824('0x48'))){_0x2eb894[_0x8824('0x29')]=qs[_0x8824('0x29')](_0x30868b[_0x8824('0x41')]['limit']);_0x2eb894[_0x8824('0x49')]=qs[_0x8824('0x49')](_0x30868b[_0x8824('0x41')]['offset']);}_0x2eb894[_0x8824('0x4a')]=qs[_0x8824('0x4b')](_0x30868b[_0x8824('0x41')][_0x8824('0x4b')]);_0x2eb894['where']=qs[_0x8824('0x43')](_[_0x8824('0x4d')](_0x30868b['query'],_0x541754[_0x8824('0x43')]));_0x2eb894['where'][_0x8824('0x63')]=_0x1a91c7['id'];if(_0x30868b['query'][_0x8824('0x4e')]){_0x2eb894[_0x8824('0x4c')]=_[_0x8824('0x4f')](_0x2eb894[_0x8824('0x4c')],{'$or':_[_0x8824('0x3b')](_0x2eb894['attributes'],function(_0x50bc87){var _0x58cd08={};_0x58cd08[_0x50bc87]={'$like':'%'+_0x30868b[_0x8824('0x41')][_0x8824('0x4e')]+'%'};return _0x58cd08;})});}_0x2eb894=_[_0x8824('0x4f')]({},_0x2eb894,_0x30868b[_0x8824('0x51')]);return db['CannedAnswer'][_0x8824('0x2b')]({'where':_0x2eb894[_0x8824('0x4c')]})[_0x8824('0x31')](function(_0x375ab7){_0x320f16['count']=_0x375ab7;if(_0x30868b[_0x8824('0x41')]['includeAll']){_0x2eb894[_0x8824('0x58')]=[{'all':!![]}];}return db[_0x8824('0x6a')][_0x8824('0x53')](_0x2eb894);})['then'](function(_0xca0f36){_0x320f16['rows']=_0xca0f36;return _0x320f16;});}})[_0x8824('0x31')](respondWithFilteredResult(_0x3bc341,_0x2eb894))['catch'](handleError(_0x3bc341,null));};exports[_0x8824('0x6b')]=function(_0x3e6feb,_0x1ad890,_0x484e25){return db[_0x8824('0x3c')][_0x8824('0x59')]({'where':{'id':_0x3e6feb[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x1ad890,null))[_0x8824('0x31')](function(_0x135008){if(_0x135008){return _0x135008['removeAnswers'](_0x3e6feb[_0x8824('0x41')][_0x8824('0x68')]);}})[_0x8824('0x31')](respondWithStatusCode(_0x1ad890,null))['catch'](handleError(_0x1ad890,null));};exports[_0x8824('0x6c')]=function(_0x2beffc,_0x25d193,_0x3cce8f){var _0x9c20a0={'body':_0x2beffc[_0x8824('0x5b')],'channel':_0x8824('0x6d')};var _0x160884=[];var _0x3e2425=[];var _0x10f73d={};var _0x2a7115=![];return db[_0x8824('0x6e')][_0x8824('0x61')]()[_0x8824('0x31')](function(_0x112cee){if(!_0x112cee){throw new db[(_0x8824('0x6f'))][(_0x8824('0x70'))](_0x8824('0x71'));}_0x160884=_[_0x8824('0x72')](_[_0x8824('0x42')](_0x112cee),[_0x8824('0x73'),_0x8824('0x74')]);_0x3e2425=_[_0x8824('0x72')](_['keys'](_0x112cee),['createdAt',_0x8824('0x74'),_0x8824('0x75'),_0x8824('0x76')]);if(_0x2beffc[_0x8824('0x5b')]['id']){delete _0x2beffc[_0x8824('0x5b')]['id'];}if(_[_0x8824('0x77')](_0x2beffc[_0x8824('0x5b')][_0x8824('0x78')])){throw new db[(_0x8824('0x6f'))][(_0x8824('0x70'))](_0x8824('0x79'));}if(_[_0x8824('0x77')](_0x2beffc[_0x8824('0x5b')][_0x8824('0x5b')])||_0x2beffc['body'][_0x8824('0x5b')]===''){throw new db[(_0x8824('0x6f'))][(_0x8824('0x70'))](_0x8824('0x7a'));}if(_[_0x8824('0x77')](_0x2beffc[_0x8824('0x5b')][_0x8824('0x7b')])){throw new db[(_0x8824('0x6f'))][(_0x8824('0x70'))]('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x3e2425);}if(!_[_0x8824('0x7c')](_0x3e2425,_0x2beffc['body']['mapKey'])){throw new db[(_0x8824('0x6f'))][(_0x8824('0x70'))](_0x8824('0x7d')+_0x3e2425);}_0x10f73d[_0x2beffc[_0x8824('0x5b')][_0x8824('0x7b')]]=_0x2beffc[_0x8824('0x5b')][_0x8824('0x78')];})[_0x8824('0x31')](function(){return db[_0x8824('0x3c')][_0x8824('0x59')]({'where':{'id':_0x2beffc['params']['id']},'include':[{'model':db['CmList'],'as':_0x8824('0x7e'),'include':[{'model':db[_0x8824('0x6e')],'as':_0x8824('0x7f'),'where':_0x10f73d,'limit':0x1,'order':[[_0x8824('0x74'),_0x8824('0x80')]]}]},{'model':db['OpenchannelApplication'],'as':_0x8824('0x81')}]});})[_0x8824('0x31')](handleEntityNotFound(_0x25d193,null))[_0x8824('0x31')](function(_0x1473d5){if(_0x1473d5&&_0x1473d5[_0x8824('0x7e')]){_0x9c20a0[_0x8824('0x82')]=_0x1473d5;_0x9c20a0[_0x8824('0x83')]=_0x1473d5[_0x8824('0x81')];_0x9c20a0[_0x8824('0x84')]=_0x1473d5['List'];_0x9c20a0[_0x8824('0x83')]=_[_0x8824('0x85')](_0x9c20a0['applications'],[_0x8824('0x86')],[_0x8824('0x87')]);if(_0x9c20a0[_0x8824('0x82')][_0x8824('0x81')]){delete _0x9c20a0[_0x8824('0x82')][_0x8824('0x81')];}if(_0x9c20a0[_0x8824('0x82')][_0x8824('0x7e')]&&_0x9c20a0['account'][_0x8824('0x7e')][_0x8824('0x7f')][_0x8824('0x57')]){return _0x9c20a0['account'][_0x8824('0x7e')][_0x8824('0x7f')][0x0];}var _0x25d1fa=_[_0x8824('0x88')](_0x2beffc[_0x8824('0x5b')],{'firstName':_0x2beffc[_0x8824('0x5b')][_0x8824('0x78')],'ListId':_0x1473d5[_0x8824('0x76')]});_0x25d1fa[_0x2beffc['body'][_0x8824('0x7b')]]=_0x2beffc[_0x8824('0x5b')]['from'];return db[_0x8824('0x6e')][_0x8824('0x5a')](_0x25d1fa,{'fields':_0x160884,'raw':!![]});}})['then'](handleEntityNotFound(_0x25d193,null))[_0x8824('0x31')](function(_0x20fd8a){_0x9c20a0[_0x8824('0x89')]=_0x20fd8a;if(_0x20fd8a){var _0x3f707c={'ContactId':_0x20fd8a['id'],'OpenchannelAccountId':_0x2beffc[_0x8824('0x56')]['id'],'from':(_0x20fd8a[_0x8824('0x8a')]||'')+'\x20'+(_0x20fd8a['lastName']||'')};var _0x226978={'OpenchannelAccountId':_0x2beffc[_0x8824('0x56')]['id'],'closed':![]};if(_0x2beffc[_0x8824('0x5b')][_0x8824('0x8b')]){_0x226978['threadId']=_0x2beffc[_0x8824('0x5b')]['threadId'];return db[_0x8824('0x8c')][_0x8824('0x59')]({'where':_0x226978})[_0x8824('0x31')](function(_0x50d81a){if(_0x50d81a){return[_0x50d81a,![]];}_0x3f707c[_0x8824('0x8b')]=_0x2beffc['body']['threadId'];_0x3f707c[_0x8824('0x8d')]=_0x2beffc[_0x8824('0x5b')][_0x8824('0x8d')];return db[_0x8824('0x8c')][_0x8824('0x5a')](_0x3f707c)[_0x8824('0x31')](function(_0x3f94e9){return[_0x3f94e9,!![]];});});}else{_0x226978[_0x8824('0x8b')]=null;}_0x226978[_0x8824('0x8e')]=_0x20fd8a['id'];return db[_0x8824('0x8c')][_0x8824('0x59')]({'where':_0x226978})[_0x8824('0x31')](function(_0x4d0f41){if(_0x4d0f41){return[_0x4d0f41,![]];}return db['OpenchannelInteraction'][_0x8824('0x5a')](_0x3f707c)[_0x8824('0x31')](function(_0x5328fd){return[_0x5328fd,!![]];});});}})['spread'](function(_0x220ad5,_0x2de9c8){if(_0x220ad5){_0x2a7115=_0x2de9c8;if(!_0x2de9c8){var _0x30d533={'from':(_0x9c20a0['contact'][_0x8824('0x8a')]||'')+'\x20'+(_0x9c20a0[_0x8824('0x89')][_0x8824('0x8f')]||'')};if(_0x2beffc['body'][_0x8824('0x8b')]&&_0x2beffc[_0x8824('0x5b')][_0x8824('0x90')]&&_0x2beffc[_0x8824('0x5b')][_0x8824('0x8b')]!=_0x2beffc['body'][_0x8824('0x90')]){_0x30d533[_0x8824('0x8b')]=_0x2beffc['body'][_0x8824('0x90')];}return _0x220ad5[_0x8824('0x30')](_0x30d533);}else{return _0x220ad5;}}})[_0x8824('0x31')](function(_0x25f6f4){_0x9c20a0[_0x8824('0x91')]=_0x25f6f4[_0x8824('0x33')]({'plain':!![]});_0x9c20a0['interaction'][_0x8824('0x92')]=_0x2a7115;if(_0x9c20a0[_0x8824('0x91')][_0x8824('0x92')]){if(_0x9c20a0[_0x8824('0x82')][_0x8824('0x93')]){_0x9c20a0[_0x8824('0x83')][_0x8824('0x94')]({'id':0x0,'priority':_0x9c20a0[_0x8824('0x83')][_0x8824('0x57')]+0x1,'app':_0x8824('0x95'),'appdata':_0x8824('0x96'),'interval':_0x8824('0x97')});}}return db[_0x8824('0x98')][_0x8824('0x5a')]({'body':_0x2beffc['body'][_0x8824('0x5b')],'OpenchannelAccountId':_0x2beffc[_0x8824('0x56')]['id'],'OpenchannelInteractionId':_0x25f6f4['id'],'direction':'in','ContactId':_0x9c20a0[_0x8824('0x89')]['id'],'AttachmentId':_0x2beffc[_0x8824('0x5b')]['AttachmentId']});})[_0x8824('0x31')](function(_0xaa912c){_0x9c20a0[_0x8824('0x23')]=_0xaa912c;if(_0x9c20a0[_0x8824('0x91')][_0x8824('0x99')]){return db[_0x8824('0x9a')][_0x8824('0x59')]({'attributes':['id',_0x8824('0x36')],'where':{'id':_0x9c20a0[_0x8824('0x91')][_0x8824('0x99')]}})[_0x8824('0x31')](function(_0x1420e2){if(_0x1420e2){_0x9c20a0[_0x8824('0x83')][_0x8824('0x9b')]({'id':0x0,'priority':0x0,'app':_0x8824('0x9c'),'appdata':_0x1420e2[_0x8824('0x36')]+','+(_0x9c20a0[_0x8824('0x82')][_0x8824('0x9d')]||0xa),'interval':_0x8824('0x97')});_0x9c20a0[_0x8824('0x9e')]=![];}return respondWithRpcPromise(_0x8824('0x9f'),_0x8824('0xa0'),_0x9c20a0);});}return respondWithRpcPromise(_0x8824('0x9f'),'startRouting',_0x9c20a0);})[_0x8824('0x31')](function(_0x27aab8){respondWithRpcPromise(_0x8824('0xa1'),_0x8824('0xa1'),{'event':_0x8824('0x6c'),'message':_0x27aab8},client9002);return _0x27aab8;})[_0x8824('0x31')](respondWithResult(_0x25d193,null))[_0x8824('0x55')](handleError(_0x25d193,null));};exports[_0x8824('0xa2')]=function(_0xe3229b,_0xb46043){var _0x3e6ddc=_0xe3229b['params']['id'];var _0xe10c06=_0xe3229b['body'];var _0x46aeeb=0xc8;var _0x1ae778=null;return db[_0x8824('0xa3')][_0x8824('0xa4')]({'isolationLevel':db[_0x8824('0xa3')][_0x8824('0xa5')][_0x8824('0xa6')]['READ_COMMITTED']},function(_0x4566a4){return db[_0x8824('0x3c')]['findOne']({'where':{'id':_0x3e6ddc},'transaction':_0x4566a4})[_0x8824('0x31')](function(_0x273225){if(_0x273225){return db[_0x8824('0xa7')][_0x8824('0x32')]({'where':{'OpenchannelAccountId':_0x3e6ddc},'transaction':_0x4566a4})[_0x8824('0x31')](function(){var _0x26ca8d=_[_0x8824('0x3b')](_0xe10c06,function(_0x294098){_0x294098[_0x8824('0x63')]=_0x3e6ddc;return _0x294098;});return db[_0x8824('0xa7')][_0x8824('0xa8')](_0x26ca8d,{'transaction':_0x4566a4});});}else{_0x46aeeb=0x194;_0x1ae778=[];}});})[_0x8824('0x31')](function(){if(_0x46aeeb!==0x194){return db[_0x8824('0xa7')][_0x8824('0xa9')]({'where':{'OpenchannelAccountId':_0x3e6ddc},'order':_0x8824('0x86')})[_0x8824('0x31')](function(_0x25f1f7){_0x1ae778=_0x25f1f7;});}})[_0x8824('0x55')](function(_0x316e4f){_0x46aeeb=0x1f4;logger[_0x8824('0x21')](_0x316e4f[_0x8824('0x35')]);if(_0x316e4f['name']){delete _0x316e4f[_0x8824('0x36')];}_0x1ae778=_0x316e4f;})[_0x8824('0xaa')](function(){if(_0x1ae778===null){_0xb46043[_0x8824('0x25')](_0x46aeeb);}else{if(_0x46aeeb===0x1f4){_0xb46043[_0x8824('0x26')](_0x46aeeb)['send'](_0x1ae778);}else{_0xb46043[_0x8824('0x26')](_0x46aeeb)[_0x8824('0x28')](_0x1ae778);}}});};exports[_0x8824('0xab')]=function(_0x505525,_0x5040f6,_0x25d0eb){var _0x13b679={};var _0x5e146e={};var _0x407727;var _0x136e1c;return db[_0x8824('0x3c')][_0x8824('0x65')]({'where':{'id':_0x505525[_0x8824('0x56')]['id']}})['then'](handleEntityNotFound(_0x5040f6,null))[_0x8824('0x31')](function(_0x1487ec){if(_0x1487ec){_0x407727=_0x1487ec;_0x5e146e[_0x8824('0x40')]=_[_0x8824('0x42')](db[_0x8824('0xa7')]['rawAttributes']);_0x5e146e[_0x8824('0x41')]=_[_0x8824('0x42')](_0x505525['query']);_0x5e146e[_0x8824('0x43')]=_['intersection'](_0x5e146e[_0x8824('0x40')],_0x5e146e[_0x8824('0x41')]);_0x13b679[_0x8824('0x45')]=_['intersection'](_0x5e146e[_0x8824('0x40')],qs[_0x8824('0x46')](_0x505525[_0x8824('0x41')][_0x8824('0x46')]));_0x13b679[_0x8824('0x45')]=_0x13b679[_0x8824('0x45')][_0x8824('0x57')]?_0x13b679[_0x8824('0x45')]:_0x5e146e[_0x8824('0x40')];_0x13b679[_0x8824('0x4a')]=qs['sort'](_0x505525[_0x8824('0x41')]['sort']);_0x13b679[_0x8824('0x4c')]=qs[_0x8824('0x43')](_['pick'](_0x505525[_0x8824('0x41')],_0x5e146e[_0x8824('0x43')]));if(_0x505525[_0x8824('0x41')][_0x8824('0x4e')]){_0x13b679[_0x8824('0x4c')]=_[_0x8824('0x4f')](_0x13b679[_0x8824('0x4c')],{'$or':_[_0x8824('0x3b')](_0x13b679[_0x8824('0x45')],function(_0x5baf15){var _0x5b7299={};_0x5b7299[_0x5baf15]={'$like':'%'+_0x505525['query']['filter']+'%'};return _0x5b7299;})});}_0x13b679=_[_0x8824('0x4f')]({},_0x13b679,_0x505525['options']);return _0x407727[_0x8824('0xab')](_0x13b679);}})[_0x8824('0x31')](function(_0x31a7c3){if(_0x31a7c3){_0x136e1c=_0x31a7c3['length'];if(!_0x505525['query'][_0x8824('0x47')](_0x8824('0x48'))){_0x13b679['limit']=qs[_0x8824('0x29')](_0x505525[_0x8824('0x41')][_0x8824('0x29')]);_0x13b679['offset']=qs[_0x8824('0x49')](_0x505525[_0x8824('0x41')][_0x8824('0x49')]);}return _0x407727[_0x8824('0xab')](_0x13b679);}})[_0x8824('0x31')](function(_0x23b368){if(_0x23b368){return _0x23b368?{'count':_0x136e1c,'rows':_0x23b368}:null;}})['then'](respondWithResult(_0x5040f6,null))['catch'](handleError(_0x5040f6,null));};exports[_0x8824('0xac')]=function(_0x2904b3,_0x503ec5,_0x2faccf){var _0x1f5fb4={'raw':![],'where':{}};var _0x2726a2={};var _0x9c18e3={'count':0x0,'rows':[]};return db[_0x8824('0x3c')][_0x8824('0x65')]({'where':{'id':_0x2904b3[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x503ec5,null))[_0x8824('0x31')](function(_0x58cd10){if(_0x58cd10){_0x2726a2[_0x8824('0x40')]=_[_0x8824('0x42')](db[_0x8824('0x8c')][_0x8824('0x3d')]);_0x2726a2[_0x8824('0x41')]=_[_0x8824('0x42')](_0x2904b3[_0x8824('0x41')]);_0x2726a2[_0x8824('0x43')]=_['intersection'](_0x2726a2[_0x8824('0x40')],_0x2726a2[_0x8824('0x41')]);_0x1f5fb4[_0x8824('0x45')]=_[_0x8824('0x44')](_0x2726a2['model'],qs[_0x8824('0x46')](_0x2904b3[_0x8824('0x41')]['fields']));_0x1f5fb4[_0x8824('0x45')]=_0x1f5fb4[_0x8824('0x45')][_0x8824('0x57')]?_0x1f5fb4['attributes']:_0x2726a2[_0x8824('0x40')];if(!_0x2904b3[_0x8824('0x41')][_0x8824('0x47')](_0x8824('0x48'))){_0x1f5fb4[_0x8824('0x29')]=qs[_0x8824('0x29')](_0x2904b3[_0x8824('0x41')]['limit']);_0x1f5fb4[_0x8824('0x49')]=qs[_0x8824('0x49')](_0x2904b3[_0x8824('0x41')]['offset']);}_0x1f5fb4['order']=qs['sort'](_0x2904b3[_0x8824('0x41')][_0x8824('0x4b')]);_0x1f5fb4['where']=qs['filters'](_['pick'](_0x2904b3[_0x8824('0x41')],_0x2726a2[_0x8824('0x43')]));_0x1f5fb4[_0x8824('0x4c')]['OpenchannelAccountId']=_0x58cd10['id'];if(_0x2904b3[_0x8824('0x41')]['filter']){_0x1f5fb4[_0x8824('0x4c')]=_[_0x8824('0x4f')](_0x1f5fb4[_0x8824('0x4c')],{'$or':_[_0x8824('0x3b')](_0x1f5fb4[_0x8824('0x45')],function(_0x39db4d){var _0x19ab0c={};_0x19ab0c[_0x39db4d]={'$like':'%'+_0x2904b3['query'][_0x8824('0x4e')]+'%'};return _0x19ab0c;})});}_0x1f5fb4=_[_0x8824('0x4f')]({},_0x1f5fb4,_0x2904b3[_0x8824('0x51')]);return db[_0x8824('0x8c')][_0x8824('0x2b')]({'where':_0x1f5fb4['where']})[_0x8824('0x31')](function(_0x112ea4){_0x9c18e3[_0x8824('0x2b')]=_0x112ea4;if(_0x2904b3[_0x8824('0x41')][_0x8824('0x52')]){_0x1f5fb4[_0x8824('0x58')]=[{'model':db[_0x8824('0x6e')],'as':'Contact','required':![]},{'model':db[_0x8824('0x9a')],'as':_0x8824('0xad'),'attributes':['name','fullname',_0x8824('0xae')],'required':![]},{'model':db[_0x8824('0xaf')],'as':_0x8824('0xb0'),'attributes':['id',_0x8824('0x36'),'color'],'where':_0x2904b3['query'][_0x8824('0xb1')]?{'id':_0x2904b3['query'][_0x8824('0xb1')]}:undefined,'required':_0x2904b3[_0x8824('0x41')][_0x8824('0xb1')]?!![]:![]}];}return db[_0x8824('0x8c')][_0x8824('0x53')](_0x1f5fb4);})[_0x8824('0x31')](function(_0x54f4c1){_0x9c18e3[_0x8824('0x54')]=_0x54f4c1;return _0x9c18e3;});}})[_0x8824('0x31')](respondWithFilteredResult(_0x503ec5,_0x1f5fb4))[_0x8824('0x55')](handleError(_0x503ec5,null));};exports[_0x8824('0xb2')]=function(_0x6fcfb3,_0x186c2f,_0x26bf4f){return db[_0x8824('0x3c')]['find']({'where':{'id':_0x6fcfb3[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x186c2f,null))[_0x8824('0x31')](function(_0x2a4821){if(_0x2a4821){return _0x2a4821[_0x8824('0xb2')](_0x6fcfb3[_0x8824('0x5b')][_0x8824('0x68')],_[_0x8824('0xb3')](_0x6fcfb3[_0x8824('0x5b')],[_0x8824('0x68'),'id'])||{})[_0x8824('0xb4')](function(_0x59b414){for(var _0xe86fbf=0x0;_0xe86fbf<_0x6fcfb3[_0x8824('0x5b')][_0x8824('0x68')][_0x8824('0x57')];_0xe86fbf+=0x1){socket[_0x8824('0xb5')]('userOpenchannelAccount:save',{'UserId':Number(_0x6fcfb3[_0x8824('0x5b')][_0x8824('0x68')][_0xe86fbf]),'OpenchannelAccountId':Number(_0x6fcfb3[_0x8824('0x56')]['id'])});}return _0x59b414;});}})[_0x8824('0x31')](respondWithResult(_0x186c2f,null))[_0x8824('0x55')](handleError(_0x186c2f,null));};exports[_0x8824('0xb6')]=function(_0x297cbc,_0x1cebc2,_0x142269){return db[_0x8824('0x3c')][_0x8824('0x59')]({'where':{'id':_0x297cbc[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x1cebc2,null))[_0x8824('0x31')](function(_0x56305c){if(_0x56305c){return _0x56305c[_0x8824('0xb6')](_0x297cbc[_0x8824('0x41')]['ids'])[_0x8824('0x31')](function(){if(_[_0x8824('0xb7')](_0x297cbc['query'][_0x8824('0x68')])){for(var _0x1b2c3c=0x0;_0x1b2c3c<_0x297cbc[_0x8824('0x41')][_0x8824('0x68')][_0x8824('0x57')];_0x1b2c3c+=0x1){socket['emit'](_0x8824('0xb8'),{'UserId':Number(_0x297cbc['query'][_0x8824('0x68')][_0x1b2c3c]),'OpenchannelAccountId':Number(_0x297cbc[_0x8824('0x56')]['id'])});}}else{socket[_0x8824('0xb5')](_0x8824('0xb8'),{'UserId':Number(_0x297cbc[_0x8824('0x41')][_0x8824('0x68')]),'OpenchannelAccountId':Number(_0x297cbc[_0x8824('0x56')]['id'])});}});}})[_0x8824('0x31')](respondWithStatusCode(_0x1cebc2,null))[_0x8824('0x55')](handleError(_0x1cebc2,null));};exports['getAgents']=function(_0x587cb8,_0x30fe5b,_0x442e04){var _0x4bf869={};var _0x49c350={};var _0x42de43;var _0x18742f;return db['OpenchannelAccount']['findOne']({'where':{'id':_0x587cb8['params']['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x30fe5b,null))[_0x8824('0x31')](function(_0x7efafc){if(_0x7efafc){_0x42de43=_0x7efafc;_0x49c350[_0x8824('0x40')]=_[_0x8824('0x42')](db[_0x8824('0x9a')][_0x8824('0x3d')]);_0x49c350[_0x8824('0x41')]=_[_0x8824('0x42')](_0x587cb8[_0x8824('0x41')]);_0x49c350['filters']=_['intersection'](_0x49c350[_0x8824('0x40')],_0x49c350[_0x8824('0x41')]);_0x4bf869[_0x8824('0x45')]=_[_0x8824('0x44')](_0x49c350[_0x8824('0x40')],qs['fields'](_0x587cb8[_0x8824('0x41')][_0x8824('0x46')]));_0x4bf869[_0x8824('0x45')]=_0x4bf869[_0x8824('0x45')]['length']?_0x4bf869[_0x8824('0x45')]:_0x49c350[_0x8824('0x40')];_0x4bf869[_0x8824('0x4a')]=qs[_0x8824('0x4b')](_0x587cb8[_0x8824('0x41')][_0x8824('0x4b')]);_0x4bf869['where']=qs['filters'](_[_0x8824('0x4d')](_0x587cb8[_0x8824('0x41')],_0x49c350['filters']));if(_0x587cb8[_0x8824('0x41')][_0x8824('0x4e')]){_0x4bf869[_0x8824('0x4c')]=_['merge'](_0x4bf869[_0x8824('0x4c')],{'$or':_[_0x8824('0x3b')](_0x4bf869[_0x8824('0x45')],function(_0x48f18a){var _0x563529={};_0x563529[_0x48f18a]={'$like':'%'+_0x587cb8[_0x8824('0x41')]['filter']+'%'};return _0x563529;})});}_0x4bf869=_['merge']({},_0x4bf869,_0x587cb8[_0x8824('0x51')]);return _0x42de43[_0x8824('0xb9')](_0x4bf869);}})[_0x8824('0x31')](function(_0x471664){if(_0x471664){_0x18742f=_0x471664['length'];if(!_0x587cb8['query']['hasOwnProperty'](_0x8824('0x48'))){_0x4bf869[_0x8824('0x29')]=qs[_0x8824('0x29')](_0x587cb8['query'][_0x8824('0x29')]);_0x4bf869['offset']=qs[_0x8824('0x49')](_0x587cb8[_0x8824('0x41')][_0x8824('0x49')]);}return _0x42de43['getAgents'](_0x4bf869);}})[_0x8824('0x31')](function(_0x50b50d){if(_0x50b50d){return _0x50b50d?{'count':_0x18742f,'rows':_0x50b50d}:null;}})[_0x8824('0x31')](respondWithResult(_0x30fe5b,null))[_0x8824('0x55')](handleError(_0x30fe5b,null));};exports[_0x8824('0x37')]=function(_0x315270,_0x22acc3,_0x3476f5){var _0x30cd3f,_0x49784b,_0x20a0b9;if(_[_0x8824('0x77')](_0x315270['body']['body'])||_0x315270['body'][_0x8824('0x5b')]===''){throw new db[(_0x8824('0x6f'))][(_0x8824('0x70'))](_0x8824('0x7a'));}if(_['isNil'](_0x315270[_0x8824('0x5b')]['to'])){}_0x30cd3f=_0x315270[_0x8824('0x5b')]['to'];return db['OpenchannelAccount']['findOne']({'where':{'id':_0x315270[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x22acc3,null))[_0x8824('0x31')](function(_0x20578d){if(_0x20578d){return db[_0x8824('0x3c')]['find']({'where':{'id':_0x20578d['id']},'include':[{'model':db[_0x8824('0xba')],'as':'List','include':[{'model':db[_0x8824('0x6e')],'as':_0x8824('0x7f'),'where':{[_0x20578d[_0x8824('0x7b')]]:_0x30cd3f},'limit':0x1,'order':[[_0x8824('0x74'),_0x8824('0x80')]]}]}]})[_0x8824('0x31')](handleEntityNotFound(_0x22acc3,null))[_0x8824('0x31')](function(_0x24c4c0){if(_0x24c4c0&&_0x24c4c0[_0x8824('0x7e')]){_0x49784b=_0x24c4c0[_0x8824('0x33')]({'plain':!![]});if(_0x49784b[_0x8824('0x7e')]&&_0x49784b['List'][_0x8824('0x7f')][_0x8824('0x57')]){return _0x49784b['List'][_0x8824('0x7f')][0x0];}return db[_0x8824('0x6e')][_0x8824('0x5a')](_['defaults'](_0x315270['body'],{'firstName':_0x30cd3f,[_0x24c4c0[_0x8824('0x7b')]]:_0x30cd3f,'phone':_0x30cd3f,'ListId':_0x49784b[_0x8824('0x76')]}));}})[_0x8824('0x31')](handleEntityNotFound(_0x22acc3,null))[_0x8824('0x31')](function(_0x313ec7){if(_0x313ec7){_0x20a0b9=_0x313ec7;return db[_0x8824('0x8c')]['find']({'where':{'ContactId':_0x20a0b9['id'],'closed':![],'OpenchannelAccountId':_0x49784b['id']}})['then'](function(_0x368e41){if(_0x368e41){return[_0x368e41,![]];}return db[_0x8824('0x8c')]['create']({'UserId':_0x315270[_0x8824('0x5c')]['id'],'ContactId':_0x20a0b9['id'],'OpenchannelAccountId':_0x49784b['id'],'lastMsgDirection':'out','firstMsgDirection':_0x8824('0xbb'),'Messages':[_[_0x8824('0x4f')](_0x315270[_0x8824('0x5b')],{'read':![],'body':_0x315270[_0x8824('0x5b')]['body'],'OpenchannelAccountId':_0x49784b['id'],'UserId':_0x315270[_0x8824('0x5c')]['id'],'ContactId':_0x20a0b9['id']})]},{'include':[{'model':db[_0x8824('0x98')],'as':_0x8824('0xbc')}]})[_0x8824('0x31')](function(_0xffa63b){return[_0xffa63b,!![]];});});}})['spread'](function(_0x43afae,_0x848fa0){if(_0x848fa0){return _0x43afae;}return db[_0x8824('0x98')][_0x8824('0x5a')](_[_0x8824('0x4f')](_0x315270['body'],{'read':![],'body':_0x315270['body'][_0x8824('0x5b')],'OpenchannelAccountId':_0x49784b['id'],'OpenchannelInteractionId':_0x43afae['id'],'UserId':_0x315270[_0x8824('0x5c')]['id'],'ContactId':_0x20a0b9['id']}))[_0x8824('0x31')](function(_0x37dcca){_0x43afae['dataValues'][_0x8824('0xbc')]=[];_0x43afae['dataValues'][_0x8824('0xbc')]['push'](_0x37dcca['dataValues']);return _0x43afae;});});}})[_0x8824('0x31')](respondWithResult(_0x22acc3,null))[_0x8824('0x55')](handleError(_0x22acc3,null));};
\ No newline at end of file