Built motion from commit (unavailable).|2.5.29
[motion2.git] / server / api / openchannelAccount / openchannelAccount.controller.js
index 891b570..97fc573 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf6c3=['map','OpenchannelAccount','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','nolimit','limit','order','sort','where','filter','VIRTUAL','merge','options','includeAll','include','findAll','catch','show','params','mandatoryDispositionPause','length','user','role','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','find','describe','addDisposition','OpenchannelAccountId','create','getDispositions','findOne','Disposition','hasOwnProperty','rows','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','CmContact','ValidationError','difference','createdAt','updatedAt','CompanyId','ListId','isNil','Sequelize','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','from','CmList','List','Contacts','DESC','Applications','account','list','applications','orderBy','priority','asc','defaults','contact','firstName','lastName','threadId','OpenchannelInteraction','externalUrl','spread','messageId','interaction','created','autoclose','push','close','unmanaged','OpenchannelMessage','AttachmentId','UserId','User','unshift','agent','*,*,*,*','forcedOwnership','Start','startRouting','EventManager','notify','addApplications','transaction','OpenchannelApplication','findAndCountAll','getApplications','pick','Owner','Tag','Tags','color','tag','addAgents','omit','emit','userOpenchannelAccount:save','removeAgents','isArray','userOpenchannelAccount:remove','getAgents','Messages','dataValues','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/license/util','redis','localhost','socket.io-emitter','./openchannelAccount.socket','register','jayson/promise','client','http','request','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','debug','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','result','sendStatus','status','end','count','offset','Content-Range','json','apply','reject','save','update','destroy','get','OpenchannelAccounts','UserProfileResource','then','stack','name','send','Pause'];(function(_0x37512d,_0x44495e){var _0x133f49=function(_0x10b685){while(--_0x10b685){_0x37512d['push'](_0x37512d['shift']());}};_0x133f49(++_0x44495e);}(_0xf6c3,0x13d));var _0x3f6c=function(_0x46cba9,_0x4707af){_0x46cba9=_0x46cba9-0x0;var _0xd65e51=_0xf6c3[_0x46cba9];return _0xd65e51;};'use strict';var emlformat=require(_0x3f6c('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x3f6c('0x1'));var jsonpatch=require(_0x3f6c('0x2'));var rp=require(_0x3f6c('0x3'));var moment=require('moment');var BPromise=require(_0x3f6c('0x4'));var Mustache=require(_0x3f6c('0x5'));var util=require(_0x3f6c('0x6'));var path=require(_0x3f6c('0x7'));var sox=require(_0x3f6c('0x8'));var csv=require(_0x3f6c('0x9'));var ejs=require(_0x3f6c('0xa'));var fs=require('fs');var fs_extra=require(_0x3f6c('0xb'));var _=require(_0x3f6c('0xc'));var squel=require(_0x3f6c('0xd'));var crypto=require(_0x3f6c('0xe'));var jsforce=require(_0x3f6c('0xf'));var deskjs=require(_0x3f6c('0x10'));var toCsv=require(_0x3f6c('0x9'));var querystring=require(_0x3f6c('0x11'));var Papa=require(_0x3f6c('0x12'));var Redis=require(_0x3f6c('0x13'));var authService=require(_0x3f6c('0x14'));var qs=require(_0x3f6c('0x15'));var as=require(_0x3f6c('0x16'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x3f6c('0x17'));var utils=require(_0x3f6c('0x18'));var config=require('../../config/environment');var licenseUtil=require(_0x3f6c('0x19'));var db=require('../../mysqldb')['db'];config[_0x3f6c('0x1a')]=_['defaults'](config[_0x3f6c('0x1a')],{'host':_0x3f6c('0x1b'),'port':0x18eb});var socket=require(_0x3f6c('0x1c'))(new Redis(config[_0x3f6c('0x1a')]));require(_0x3f6c('0x1d'))[_0x3f6c('0x1e')](socket);var jayson=require(_0x3f6c('0x1f'));var client=jayson[_0x3f6c('0x20')][_0x3f6c('0x21')]({'port':0x232c});var client9002=jayson[_0x3f6c('0x20')]['http']({'port':0x232a});function respondWithRpcPromise(_0x395fe0,_0x5b2fc2,_0x3e1b9f,_0x3e866b){return new BPromise(function(_0x134021,_0x350485){var _0x160c91=_0x3e866b||client;return _0x160c91[_0x3f6c('0x22')](_0x395fe0,_0x3e1b9f)['then'](function(_0x2af57c){logger['info'](_0x3f6c('0x23'),_0x5b2fc2,_0x3f6c('0x24'));logger[_0x3f6c('0x25')](_0x3f6c('0x26'),_0x5b2fc2,_0x3f6c('0x24'),JSON[_0x3f6c('0x27')](_0x2af57c));if(_0x2af57c[_0x3f6c('0x28')]){if(_0x2af57c[_0x3f6c('0x28')][_0x3f6c('0x29')]===0x1f4){logger[_0x3f6c('0x28')]('OpenchannelAccount,\x20%s,\x20%s',_0x5b2fc2,_0x2af57c[_0x3f6c('0x28')]['message']);return _0x350485(_0x2af57c[_0x3f6c('0x28')][_0x3f6c('0x2a')]);}logger[_0x3f6c('0x28')](_0x3f6c('0x23'),_0x5b2fc2,_0x2af57c[_0x3f6c('0x28')]['message']);return _0x134021(_0x2af57c[_0x3f6c('0x28')][_0x3f6c('0x2a')]);}else{logger[_0x3f6c('0x2b')]('OpenchannelAccount,\x20%s,\x20%s',_0x5b2fc2,'request\x20sent');_0x134021(_0x2af57c[_0x3f6c('0x2c')][_0x3f6c('0x2a')]);}})['catch'](function(_0x31c5f8){logger['error'](_0x3f6c('0x23'),_0x5b2fc2,_0x31c5f8);_0x350485(_0x31c5f8);});});}function respondWithStatusCode(_0x1c2b8b,_0x229354){_0x229354=_0x229354||0xcc;return function(_0x108b72){if(_0x108b72){return _0x1c2b8b[_0x3f6c('0x2d')](_0x229354);}return _0x1c2b8b[_0x3f6c('0x2e')](_0x229354)[_0x3f6c('0x2f')]();};}function respondWithResult(_0x17859c,_0x17643e){_0x17643e=_0x17643e||0xc8;return function(_0x184afe){if(_0x184afe){return _0x17859c[_0x3f6c('0x2e')](_0x17643e)['json'](_0x184afe);}};}function respondWithFilteredResult(_0xe80094,_0x4bb084){return function(_0xe00b93){if(_0xe00b93){var _0x2fea6c=_0xe00b93[_0x3f6c('0x30')],_0x445f2f=_0x4bb084['offset'],_0x540283=_0x4bb084[_0x3f6c('0x31')]+_0x4bb084['limit'],_0x25f1c1;if(_0x540283>=_0x2fea6c){_0x540283=_0x2fea6c;_0x25f1c1=0xc8;}else{_0x25f1c1=0xce;}_0xe80094[_0x3f6c('0x2e')](_0x25f1c1);return _0xe80094['set'](_0x3f6c('0x32'),_0x445f2f+'-'+_0x540283+'/'+_0x2fea6c)[_0x3f6c('0x33')](_0xe00b93);}return null;};}function patchUpdates(_0x255cb0){return function(_0x377754){try{jsonpatch[_0x3f6c('0x34')](_0x377754,_0x255cb0,!![]);}catch(_0x3f6050){return BPromise[_0x3f6c('0x35')](_0x3f6050);}return _0x377754[_0x3f6c('0x36')]();};}function saveUpdates(_0x2e8174,_0x5bacf9){return function(_0x1a9d97){if(_0x1a9d97){return _0x1a9d97[_0x3f6c('0x37')](_0x2e8174)['then'](function(_0x566a2b){return _0x566a2b;});}return null;};}function removeEntity(_0x422b98,_0x1978d4){return function(_0xe0b4b){if(_0xe0b4b){return _0xe0b4b[_0x3f6c('0x38')]()['then'](function(){var _0x502bee=_0xe0b4b[_0x3f6c('0x39')]({'plain':!![]});var _0x58b64e=_0x3f6c('0x3a');return db[_0x3f6c('0x3b')]['destroy']({'where':{'type':_0x58b64e,'resourceId':_0x502bee['id']}})[_0x3f6c('0x3c')](function(){return _0xe0b4b;});})['then'](function(){_0x422b98[_0x3f6c('0x2e')](0xcc)[_0x3f6c('0x2f')]();});}};}function handleEntityNotFound(_0x3edaec,_0x563f50){return function(_0x1f3b7d){if(!_0x1f3b7d){_0x3edaec[_0x3f6c('0x2d')](0x194);}return _0x1f3b7d;};}function handleError(_0x545aeb,_0x381609){_0x381609=_0x381609||0x1f4;return function(_0x34ec29){logger[_0x3f6c('0x28')](_0x34ec29[_0x3f6c('0x3d')]);if(_0x34ec29[_0x3f6c('0x3e')]){delete _0x34ec29[_0x3f6c('0x3e')];}_0x545aeb[_0x3f6c('0x2e')](_0x381609)[_0x3f6c('0x3f')](_0x34ec29);};}exports['index']=function(_0x777a8d,_0x39dbaa){var _0x19f081={'include':[{'model':db[_0x3f6c('0x40')],'as':'mandatoryDispositionPause'}]},_0x3d4c87={},_0x1c0d04={'count':0x0,'rows':[]};var _0x4adcb3=_[_0x3f6c('0x41')](db[_0x3f6c('0x42')][_0x3f6c('0x43')],function(_0x5345d3){return{'name':_0x5345d3[_0x3f6c('0x44')],'type':_0x5345d3[_0x3f6c('0x45')][_0x3f6c('0x46')]};});_0x3d4c87[_0x3f6c('0x47')]=_[_0x3f6c('0x41')](_0x4adcb3,_0x3f6c('0x3e'));_0x3d4c87[_0x3f6c('0x48')]=_[_0x3f6c('0x49')](_0x777a8d['query']);_0x3d4c87[_0x3f6c('0x4a')]=_[_0x3f6c('0x4b')](_0x3d4c87['model'],_0x3d4c87['query']);_0x19f081[_0x3f6c('0x4c')]=_[_0x3f6c('0x4b')](_0x3d4c87[_0x3f6c('0x47')],qs[_0x3f6c('0x4d')](_0x777a8d[_0x3f6c('0x48')][_0x3f6c('0x4d')]));_0x19f081[_0x3f6c('0x4c')]=_0x19f081[_0x3f6c('0x4c')]['length']?_0x19f081[_0x3f6c('0x4c')]:_0x3d4c87['model'];if(!_0x777a8d[_0x3f6c('0x48')]['hasOwnProperty'](_0x3f6c('0x4e'))){_0x19f081['limit']=qs[_0x3f6c('0x4f')](_0x777a8d[_0x3f6c('0x48')]['limit']);_0x19f081[_0x3f6c('0x31')]=qs['offset'](_0x777a8d[_0x3f6c('0x48')][_0x3f6c('0x31')]);}_0x19f081[_0x3f6c('0x50')]=qs['sort'](_0x777a8d[_0x3f6c('0x48')][_0x3f6c('0x51')]);_0x19f081[_0x3f6c('0x52')]=qs[_0x3f6c('0x4a')](_['pick'](_0x777a8d[_0x3f6c('0x48')],_0x3d4c87[_0x3f6c('0x4a')]),_0x4adcb3);if(_0x777a8d[_0x3f6c('0x48')][_0x3f6c('0x53')]){_0x19f081['where']=_['merge'](_0x19f081[_0x3f6c('0x52')],{'$or':_[_0x3f6c('0x41')](_0x4adcb3,function(_0x13131a){if(_0x13131a[_0x3f6c('0x45')]!==_0x3f6c('0x54')){var _0x5bb281={};_0x5bb281[_0x13131a['name']]={'$like':'%'+_0x777a8d[_0x3f6c('0x48')][_0x3f6c('0x53')]+'%'};return _0x5bb281;}})});}_0x19f081=_[_0x3f6c('0x55')]({},_0x19f081,_0x777a8d[_0x3f6c('0x56')]);var _0x30b270={'where':_0x19f081[_0x3f6c('0x52')]};return db['OpenchannelAccount'][_0x3f6c('0x30')](_0x30b270)[_0x3f6c('0x3c')](function(_0x6e16ac){_0x1c0d04[_0x3f6c('0x30')]=_0x6e16ac;if(_0x777a8d[_0x3f6c('0x48')][_0x3f6c('0x57')]){_0x19f081[_0x3f6c('0x58')]=[{'all':!![]}];}return db[_0x3f6c('0x42')][_0x3f6c('0x59')](_0x19f081);})['then'](function(_0x20b309){_0x1c0d04['rows']=_0x20b309;return _0x1c0d04;})['then'](respondWithFilteredResult(_0x39dbaa,_0x19f081))[_0x3f6c('0x5a')](handleError(_0x39dbaa,null));};exports[_0x3f6c('0x5b')]=function(_0x450ba3,_0x2c8d72){var _0x1abcfb={'raw':![],'where':{'id':_0x450ba3[_0x3f6c('0x5c')]['id']},'include':[{'model':db['Pause'],'as':_0x3f6c('0x5d')}]},_0x1191ca={};_0x1191ca[_0x3f6c('0x47')]=_[_0x3f6c('0x49')](db[_0x3f6c('0x42')][_0x3f6c('0x43')]);_0x1191ca[_0x3f6c('0x48')]=_[_0x3f6c('0x49')](_0x450ba3[_0x3f6c('0x48')]);_0x1191ca['filters']=_[_0x3f6c('0x4b')](_0x1191ca[_0x3f6c('0x47')],_0x1191ca[_0x3f6c('0x48')]);_0x1abcfb['attributes']=_[_0x3f6c('0x4b')](_0x1191ca['model'],qs[_0x3f6c('0x4d')](_0x450ba3[_0x3f6c('0x48')][_0x3f6c('0x4d')]));_0x1abcfb[_0x3f6c('0x4c')]=_0x1abcfb[_0x3f6c('0x4c')][_0x3f6c('0x5e')]?_0x1abcfb[_0x3f6c('0x4c')]:_0x1191ca['model'];if(_0x450ba3[_0x3f6c('0x48')][_0x3f6c('0x57')]){_0x1abcfb[_0x3f6c('0x58')]=[{'all':!![]}];}_0x1abcfb=_['merge']({},_0x1abcfb,_0x450ba3[_0x3f6c('0x56')]);return db[_0x3f6c('0x42')]['find'](_0x1abcfb)[_0x3f6c('0x3c')](handleEntityNotFound(_0x2c8d72,null))[_0x3f6c('0x3c')](respondWithResult(_0x2c8d72,null))[_0x3f6c('0x5a')](handleError(_0x2c8d72,null));};exports['create']=function(_0x45b539,_0x145bdb){return db[_0x3f6c('0x42')]['create'](_0x45b539['body'],{})[_0x3f6c('0x3c')](function(_0x1f7969){var _0x20e128=_0x45b539[_0x3f6c('0x5f')]['get']({'plain':!![]});if(!_0x20e128)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x20e128[_0x3f6c('0x60')]===_0x3f6c('0x5f')){var _0xf5eae7=_0x1f7969[_0x3f6c('0x39')]({'plain':!![]});var _0x4f863f='OpenchannelAccounts';return db[_0x3f6c('0x61')]['find']({'where':{'name':_0x4f863f,'userProfileId':_0x20e128['userProfileId']},'raw':!![]})[_0x3f6c('0x3c')](function(_0x5ace69){if(_0x5ace69&&_0x5ace69[_0x3f6c('0x62')]===0x0){return db[_0x3f6c('0x3b')]['create']({'name':_0xf5eae7[_0x3f6c('0x3e')],'resourceId':_0xf5eae7['id'],'type':_0x5ace69[_0x3f6c('0x3e')],'sectionId':_0x5ace69['id']},{})[_0x3f6c('0x3c')](function(){return _0x1f7969;});}else{return _0x1f7969;}})[_0x3f6c('0x5a')](function(_0x531e2f){logger[_0x3f6c('0x28')](_0x3f6c('0x63'),_0x531e2f);throw _0x531e2f;});}return _0x1f7969;})[_0x3f6c('0x3c')](respondWithResult(_0x145bdb,0xc9))[_0x3f6c('0x5a')](handleError(_0x145bdb,null));};exports[_0x3f6c('0x37')]=function(_0x191615,_0x133e64){if(_0x191615[_0x3f6c('0x64')]['id']){delete _0x191615['body']['id'];}return db[_0x3f6c('0x42')][_0x3f6c('0x65')]({'where':{'id':_0x191615['params']['id']},'include':[{'model':db[_0x3f6c('0x40')],'as':_0x3f6c('0x5d')}]})[_0x3f6c('0x3c')](handleEntityNotFound(_0x133e64,null))[_0x3f6c('0x3c')](saveUpdates(_0x191615[_0x3f6c('0x64')],null))['then'](respondWithResult(_0x133e64,null))['catch'](handleError(_0x133e64,null));};exports[_0x3f6c('0x38')]=function(_0x341a57,_0x58a940){return db[_0x3f6c('0x42')][_0x3f6c('0x65')]({'where':{'id':_0x341a57[_0x3f6c('0x5c')]['id']}})[_0x3f6c('0x3c')](handleEntityNotFound(_0x58a940,null))[_0x3f6c('0x3c')](removeEntity(_0x58a940,null))[_0x3f6c('0x5a')](handleError(_0x58a940,null));};exports['describe']=function(_0x1b8972,_0x4385ea){return db[_0x3f6c('0x42')][_0x3f6c('0x66')]()['then'](respondWithResult(_0x4385ea,null))[_0x3f6c('0x5a')](handleError(_0x4385ea,null));};exports[_0x3f6c('0x67')]=function(_0x474505,_0x14e141,_0x4a7e7b){if(_0x474505['body']['id']){delete _0x474505[_0x3f6c('0x64')]['id'];}return db['OpenchannelAccount']['find']({'where':{'id':_0x474505[_0x3f6c('0x5c')]['id']}})['then'](handleEntityNotFound(_0x14e141,null))[_0x3f6c('0x3c')](function(_0x52529b){if(_0x52529b){_0x474505['body'][_0x3f6c('0x68')]=_0x52529b['id'];return db['Disposition'][_0x3f6c('0x69')](_0x474505[_0x3f6c('0x64')]);}})['then'](respondWithResult(_0x14e141,null))[_0x3f6c('0x5a')](handleError(_0x14e141,null));};exports[_0x3f6c('0x6a')]=function(_0x5aefd2,_0x193097,_0x47aa44){var _0x1c7294={'raw':![],'where':{}};var _0x6e3c30={};var _0x3ad1={'count':0x0,'rows':[]};return db[_0x3f6c('0x42')][_0x3f6c('0x6b')]({'where':{'id':_0x5aefd2[_0x3f6c('0x5c')]['id']}})['then'](handleEntityNotFound(_0x193097,null))['then'](function(_0x9aac07){if(_0x9aac07){_0x6e3c30['model']=_['keys'](db[_0x3f6c('0x6c')]['rawAttributes']);_0x6e3c30[_0x3f6c('0x48')]=_[_0x3f6c('0x49')](_0x5aefd2['query']);_0x6e3c30[_0x3f6c('0x4a')]=_['intersection'](_0x6e3c30[_0x3f6c('0x47')],_0x6e3c30['query']);_0x1c7294[_0x3f6c('0x4c')]=_[_0x3f6c('0x4b')](_0x6e3c30[_0x3f6c('0x47')],qs[_0x3f6c('0x4d')](_0x5aefd2[_0x3f6c('0x48')][_0x3f6c('0x4d')]));_0x1c7294[_0x3f6c('0x4c')]=_0x1c7294[_0x3f6c('0x4c')][_0x3f6c('0x5e')]?_0x1c7294[_0x3f6c('0x4c')]:_0x6e3c30['model'];if(!_0x5aefd2[_0x3f6c('0x48')][_0x3f6c('0x6d')](_0x3f6c('0x4e'))){_0x1c7294[_0x3f6c('0x4f')]=qs['limit'](_0x5aefd2[_0x3f6c('0x48')][_0x3f6c('0x4f')]);_0x1c7294[_0x3f6c('0x31')]=qs[_0x3f6c('0x31')](_0x5aefd2[_0x3f6c('0x48')][_0x3f6c('0x31')]);}_0x1c7294[_0x3f6c('0x50')]=qs['sort'](_0x5aefd2[_0x3f6c('0x48')][_0x3f6c('0x51')]);_0x1c7294[_0x3f6c('0x52')]=qs['filters'](_['pick'](_0x5aefd2['query'],_0x6e3c30[_0x3f6c('0x4a')]));_0x1c7294[_0x3f6c('0x52')]['OpenchannelAccountId']=_0x9aac07['id'];if(_0x5aefd2[_0x3f6c('0x48')][_0x3f6c('0x53')]){_0x1c7294[_0x3f6c('0x52')]=_['merge'](_0x1c7294['where'],{'$or':_[_0x3f6c('0x41')](_0x1c7294[_0x3f6c('0x4c')],function(_0x434602){var _0x57ec37={};_0x57ec37[_0x434602]={'$like':'%'+_0x5aefd2[_0x3f6c('0x48')][_0x3f6c('0x53')]+'%'};return _0x57ec37;})});}_0x1c7294=_[_0x3f6c('0x55')]({},_0x1c7294,_0x5aefd2[_0x3f6c('0x56')]);return db['Disposition'][_0x3f6c('0x30')]({'where':_0x1c7294[_0x3f6c('0x52')]})['then'](function(_0x31974d){_0x3ad1['count']=_0x31974d;if(_0x5aefd2[_0x3f6c('0x48')]['includeAll']){_0x1c7294[_0x3f6c('0x58')]=[{'all':!![]}];}return db[_0x3f6c('0x6c')][_0x3f6c('0x59')](_0x1c7294);})['then'](function(_0x74e9bd){_0x3ad1[_0x3f6c('0x6e')]=_0x74e9bd;return _0x3ad1;});}})[_0x3f6c('0x3c')](respondWithFilteredResult(_0x193097,_0x1c7294))[_0x3f6c('0x5a')](handleError(_0x193097,null));};exports[_0x3f6c('0x6f')]=function(_0x109aa4,_0x443dc9,_0x906af2){return db['OpenchannelAccount'][_0x3f6c('0x65')]({'where':{'id':_0x109aa4[_0x3f6c('0x5c')]['id']}})[_0x3f6c('0x3c')](handleEntityNotFound(_0x443dc9,null))[_0x3f6c('0x3c')](function(_0x3413f4){if(_0x3413f4){return _0x3413f4['removeDispositions'](_0x109aa4[_0x3f6c('0x48')][_0x3f6c('0x70')]);}})['then'](respondWithStatusCode(_0x443dc9,null))[_0x3f6c('0x5a')](handleError(_0x443dc9,null));};exports[_0x3f6c('0x71')]=function(_0x415135,_0x259b83,_0xf4cb9d){if(_0x415135[_0x3f6c('0x64')]['id']){delete _0x415135[_0x3f6c('0x64')]['id'];}return db['OpenchannelAccount'][_0x3f6c('0x65')]({'where':{'id':_0x415135[_0x3f6c('0x5c')]['id']}})['then'](handleEntityNotFound(_0x259b83,null))[_0x3f6c('0x3c')](function(_0x312f5a){if(_0x312f5a){_0x415135['body'][_0x3f6c('0x68')]=_0x312f5a['id'];return db[_0x3f6c('0x72')][_0x3f6c('0x69')](_0x415135[_0x3f6c('0x64')]);}})[_0x3f6c('0x3c')](respondWithResult(_0x259b83,null))[_0x3f6c('0x5a')](handleError(_0x259b83,null));};exports[_0x3f6c('0x73')]=function(_0x371bb8,_0x56d1a7,_0x7b07ad){var _0x78fa56={'raw':![],'where':{}};var _0x3f4713={};var _0x29ae6e={'count':0x0,'rows':[]};return db[_0x3f6c('0x42')][_0x3f6c('0x6b')]({'where':{'id':_0x371bb8[_0x3f6c('0x5c')]['id']}})[_0x3f6c('0x3c')](handleEntityNotFound(_0x56d1a7,null))[_0x3f6c('0x3c')](function(_0x2eb4ad){if(_0x2eb4ad){_0x3f4713[_0x3f6c('0x47')]=_['keys'](db[_0x3f6c('0x72')][_0x3f6c('0x43')]);_0x3f4713[_0x3f6c('0x48')]=_[_0x3f6c('0x49')](_0x371bb8['query']);_0x3f4713['filters']=_['intersection'](_0x3f4713[_0x3f6c('0x47')],_0x3f4713[_0x3f6c('0x48')]);_0x78fa56[_0x3f6c('0x4c')]=_[_0x3f6c('0x4b')](_0x3f4713['model'],qs['fields'](_0x371bb8['query'][_0x3f6c('0x4d')]));_0x78fa56['attributes']=_0x78fa56[_0x3f6c('0x4c')][_0x3f6c('0x5e')]?_0x78fa56[_0x3f6c('0x4c')]:_0x3f4713[_0x3f6c('0x47')];if(!_0x371bb8[_0x3f6c('0x48')]['hasOwnProperty']('nolimit')){_0x78fa56[_0x3f6c('0x4f')]=qs['limit'](_0x371bb8[_0x3f6c('0x48')][_0x3f6c('0x4f')]);_0x78fa56[_0x3f6c('0x31')]=qs[_0x3f6c('0x31')](_0x371bb8[_0x3f6c('0x48')][_0x3f6c('0x31')]);}_0x78fa56[_0x3f6c('0x50')]=qs[_0x3f6c('0x51')](_0x371bb8[_0x3f6c('0x48')]['sort']);_0x78fa56[_0x3f6c('0x52')]=qs[_0x3f6c('0x4a')](_['pick'](_0x371bb8[_0x3f6c('0x48')],_0x3f4713['filters']));_0x78fa56['where'][_0x3f6c('0x68')]=_0x2eb4ad['id'];if(_0x371bb8[_0x3f6c('0x48')]['filter']){_0x78fa56[_0x3f6c('0x52')]=_[_0x3f6c('0x55')](_0x78fa56[_0x3f6c('0x52')],{'$or':_[_0x3f6c('0x41')](_0x78fa56[_0x3f6c('0x4c')],function(_0x479921){var _0x2fadc6={};_0x2fadc6[_0x479921]={'$like':'%'+_0x371bb8['query'][_0x3f6c('0x53')]+'%'};return _0x2fadc6;})});}_0x78fa56=_['merge']({},_0x78fa56,_0x371bb8['options']);return db['CannedAnswer'][_0x3f6c('0x30')]({'where':_0x78fa56[_0x3f6c('0x52')]})[_0x3f6c('0x3c')](function(_0x47fe52){_0x29ae6e['count']=_0x47fe52;if(_0x371bb8[_0x3f6c('0x48')][_0x3f6c('0x57')]){_0x78fa56[_0x3f6c('0x58')]=[{'all':!![]}];}return db[_0x3f6c('0x72')][_0x3f6c('0x59')](_0x78fa56);})[_0x3f6c('0x3c')](function(_0x1a02d9){_0x29ae6e[_0x3f6c('0x6e')]=_0x1a02d9;return _0x29ae6e;});}})[_0x3f6c('0x3c')](respondWithFilteredResult(_0x56d1a7,_0x78fa56))[_0x3f6c('0x5a')](handleError(_0x56d1a7,null));};exports[_0x3f6c('0x74')]=function(_0x2a5e60,_0x5cd6d1,_0x1ea24a){return db[_0x3f6c('0x42')][_0x3f6c('0x65')]({'where':{'id':_0x2a5e60[_0x3f6c('0x5c')]['id']}})[_0x3f6c('0x3c')](handleEntityNotFound(_0x5cd6d1,null))[_0x3f6c('0x3c')](function(_0x5f2684){if(_0x5f2684){return _0x5f2684[_0x3f6c('0x74')](_0x2a5e60[_0x3f6c('0x48')]['ids']);}})[_0x3f6c('0x3c')](respondWithStatusCode(_0x5cd6d1,null))[_0x3f6c('0x5a')](handleError(_0x5cd6d1,null));};exports['notify']=function(_0x297fc3,_0x57d9db,_0x163c1b){var _0x46a103={'body':_0x297fc3[_0x3f6c('0x64')],'channel':'openchannel'};var _0x17b154=[];var _0x54d4b5=[];var _0x14d6d2={};var _0x7e8eee=![];return db[_0x3f6c('0x75')][_0x3f6c('0x66')]()[_0x3f6c('0x3c')](function(_0x415656){if(!_0x415656){throw new db['Sequelize'][(_0x3f6c('0x76'))]('no\x20available\x20attributes');}_0x17b154=_[_0x3f6c('0x77')](_[_0x3f6c('0x49')](_0x415656),['createdAt','updatedAt']);_0x54d4b5=_[_0x3f6c('0x77')](_[_0x3f6c('0x49')](_0x415656),[_0x3f6c('0x78'),_0x3f6c('0x79'),_0x3f6c('0x7a'),_0x3f6c('0x7b')]);if(_0x297fc3[_0x3f6c('0x64')]['id']){delete _0x297fc3[_0x3f6c('0x64')]['id'];}if(_[_0x3f6c('0x7c')](_0x297fc3['body']['from'])){throw new db[(_0x3f6c('0x7d'))][(_0x3f6c('0x76'))](_0x3f6c('0x7e'));}if(_[_0x3f6c('0x7c')](_0x297fc3[_0x3f6c('0x64')]['body'])||_0x297fc3[_0x3f6c('0x64')][_0x3f6c('0x64')]===''){throw new db[(_0x3f6c('0x7d'))]['ValidationError'](_0x3f6c('0x7f'));}if(_[_0x3f6c('0x7c')](_0x297fc3['body'][_0x3f6c('0x80')])){throw new db[(_0x3f6c('0x7d'))]['ValidationError']('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x54d4b5);}if(!_[_0x3f6c('0x81')](_0x54d4b5,_0x297fc3[_0x3f6c('0x64')][_0x3f6c('0x80')])){throw new db[(_0x3f6c('0x7d'))][(_0x3f6c('0x76'))](_0x3f6c('0x82')+_0x54d4b5);}_0x14d6d2[_0x297fc3['body']['mapKey']]=_0x297fc3[_0x3f6c('0x64')][_0x3f6c('0x83')];})[_0x3f6c('0x3c')](function(){return db[_0x3f6c('0x42')][_0x3f6c('0x65')]({'where':{'id':_0x297fc3[_0x3f6c('0x5c')]['id']},'include':[{'model':db[_0x3f6c('0x84')],'as':_0x3f6c('0x85'),'include':[{'model':db[_0x3f6c('0x75')],'as':_0x3f6c('0x86'),'where':_0x14d6d2,'limit':0x1,'order':[['updatedAt',_0x3f6c('0x87')]]}]},{'model':db['OpenchannelApplication'],'as':_0x3f6c('0x88')}]});})[_0x3f6c('0x3c')](handleEntityNotFound(_0x57d9db,null))[_0x3f6c('0x3c')](function(_0x42d4d1){if(_0x42d4d1&&_0x42d4d1[_0x3f6c('0x85')]){_0x46a103[_0x3f6c('0x89')]=_0x42d4d1;_0x46a103['applications']=_0x42d4d1['Applications'];_0x46a103[_0x3f6c('0x8a')]=_0x42d4d1['List'];_0x46a103[_0x3f6c('0x8b')]=_[_0x3f6c('0x8c')](_0x46a103[_0x3f6c('0x8b')],[_0x3f6c('0x8d')],[_0x3f6c('0x8e')]);if(_0x46a103[_0x3f6c('0x89')][_0x3f6c('0x88')]){delete _0x46a103[_0x3f6c('0x89')][_0x3f6c('0x88')];}if(_0x46a103[_0x3f6c('0x89')][_0x3f6c('0x85')]&&_0x46a103[_0x3f6c('0x89')]['List'][_0x3f6c('0x86')][_0x3f6c('0x5e')]){return _0x46a103[_0x3f6c('0x89')][_0x3f6c('0x85')][_0x3f6c('0x86')][0x0];}var _0x1b0111=_[_0x3f6c('0x8f')](_0x297fc3[_0x3f6c('0x64')],{'firstName':_0x297fc3['body']['from'],'ListId':_0x42d4d1['ListId']});_0x1b0111[_0x297fc3['body']['mapKey']]=_0x297fc3[_0x3f6c('0x64')][_0x3f6c('0x83')];return db['CmContact'][_0x3f6c('0x69')](_0x1b0111,{'fields':_0x17b154,'raw':!![]});}})[_0x3f6c('0x3c')](handleEntityNotFound(_0x57d9db,null))[_0x3f6c('0x3c')](function(_0x33719d){_0x46a103[_0x3f6c('0x90')]=_0x33719d;if(_0x33719d){var _0x4538ce={'ContactId':_0x33719d['id'],'OpenchannelAccountId':_0x297fc3[_0x3f6c('0x5c')]['id'],'from':(_0x33719d[_0x3f6c('0x91')]||'')+'\x20'+(_0x33719d[_0x3f6c('0x92')]||'')};var _0x2637b9={'OpenchannelAccountId':_0x297fc3[_0x3f6c('0x5c')]['id'],'closed':![]};if(_0x297fc3['body'][_0x3f6c('0x93')]){_0x2637b9[_0x3f6c('0x93')]=_0x297fc3['body'][_0x3f6c('0x93')];return db[_0x3f6c('0x94')][_0x3f6c('0x65')]({'where':_0x2637b9})[_0x3f6c('0x3c')](function(_0x198ed9){if(_0x198ed9){return[_0x198ed9,![]];}_0x4538ce['threadId']=_0x297fc3[_0x3f6c('0x64')]['threadId'];_0x4538ce[_0x3f6c('0x95')]=_0x297fc3[_0x3f6c('0x64')][_0x3f6c('0x95')];return db[_0x3f6c('0x94')][_0x3f6c('0x69')](_0x4538ce)[_0x3f6c('0x3c')](function(_0x37590f){return[_0x37590f,!![]];});});}else{_0x2637b9[_0x3f6c('0x93')]=null;}_0x2637b9['ContactId']=_0x33719d['id'];return db[_0x3f6c('0x94')]['find']({'where':_0x2637b9})[_0x3f6c('0x3c')](function(_0x450557){if(_0x450557){return[_0x450557,![]];}return db[_0x3f6c('0x94')][_0x3f6c('0x69')](_0x4538ce)[_0x3f6c('0x3c')](function(_0x4b1cd0){return[_0x4b1cd0,!![]];});});}})[_0x3f6c('0x96')](function(_0x47d665,_0x9938a1){if(_0x47d665){_0x7e8eee=_0x9938a1;if(!_0x9938a1){var _0x4e8679={'from':(_0x46a103[_0x3f6c('0x90')][_0x3f6c('0x91')]||'')+'\x20'+(_0x46a103[_0x3f6c('0x90')][_0x3f6c('0x92')]||'')};if(_0x297fc3['body'][_0x3f6c('0x93')]&&_0x297fc3[_0x3f6c('0x64')][_0x3f6c('0x97')]&&_0x297fc3[_0x3f6c('0x64')][_0x3f6c('0x93')]!=_0x297fc3[_0x3f6c('0x64')][_0x3f6c('0x97')]){_0x4e8679[_0x3f6c('0x93')]=_0x297fc3[_0x3f6c('0x64')][_0x3f6c('0x97')];}return _0x47d665[_0x3f6c('0x37')](_0x4e8679);}else{return _0x47d665;}}})[_0x3f6c('0x3c')](function(_0x2d3a41){_0x46a103[_0x3f6c('0x98')]=_0x2d3a41[_0x3f6c('0x39')]({'plain':!![]});_0x46a103[_0x3f6c('0x98')][_0x3f6c('0x99')]=_0x7e8eee;if(_0x46a103['interaction'][_0x3f6c('0x99')]){if(_0x46a103[_0x3f6c('0x89')][_0x3f6c('0x9a')]){_0x46a103[_0x3f6c('0x8b')][_0x3f6c('0x9b')]({'id':0x0,'priority':_0x46a103[_0x3f6c('0x8b')][_0x3f6c('0x5e')]+0x1,'app':_0x3f6c('0x9c'),'appdata':_0x3f6c('0x9d'),'interval':'*,*,*,*'});}}return db[_0x3f6c('0x9e')]['create']({'body':_0x297fc3[_0x3f6c('0x64')][_0x3f6c('0x64')],'OpenchannelAccountId':_0x297fc3['params']['id'],'OpenchannelInteractionId':_0x2d3a41['id'],'direction':'in','ContactId':_0x46a103[_0x3f6c('0x90')]['id'],'AttachmentId':_0x297fc3[_0x3f6c('0x64')][_0x3f6c('0x9f')]});})[_0x3f6c('0x3c')](function(_0x9dd1a){_0x46a103[_0x3f6c('0x2a')]=_0x9dd1a;if(_0x46a103[_0x3f6c('0x98')][_0x3f6c('0xa0')]){return db[_0x3f6c('0xa1')][_0x3f6c('0x65')]({'attributes':['id',_0x3f6c('0x3e')],'where':{'id':_0x46a103[_0x3f6c('0x98')][_0x3f6c('0xa0')]}})['then'](function(_0x29de2f){if(_0x29de2f){_0x46a103['applications'][_0x3f6c('0xa2')]({'id':0x0,'priority':0x0,'app':_0x3f6c('0xa3'),'appdata':_0x29de2f[_0x3f6c('0x3e')]+','+(_0x46a103[_0x3f6c('0x89')]['waitForTheAssignedAgent']||0xa),'interval':_0x3f6c('0xa4')});_0x46a103[_0x3f6c('0xa5')]=![];}return respondWithRpcPromise(_0x3f6c('0xa6'),_0x3f6c('0xa7'),_0x46a103);});}return respondWithRpcPromise(_0x3f6c('0xa6'),_0x3f6c('0xa7'),_0x46a103);})[_0x3f6c('0x3c')](function(_0x34e812){respondWithRpcPromise(_0x3f6c('0xa8'),_0x3f6c('0xa8'),{'event':_0x3f6c('0xa9'),'message':_0x34e812},client9002);return _0x34e812;})[_0x3f6c('0x3c')](respondWithResult(_0x57d9db,null))[_0x3f6c('0x5a')](handleError(_0x57d9db,null));};exports[_0x3f6c('0xaa')]=function(_0x458102,_0x35a8a4,_0x459500){return db[_0x3f6c('0x42')][_0x3f6c('0x6b')]({'where':{'id':_0x458102[_0x3f6c('0x5c')]['id']}})['then'](handleEntityNotFound(_0x35a8a4,null))['then'](function(_0x6f8b8e){if(_0x6f8b8e){return db['sequelize'][_0x3f6c('0xab')](function(_0x12ee53){return db['OpenchannelApplication']['destroy']({'where':{'OpenchannelAccountId':_0x458102[_0x3f6c('0x5c')]['id']},'transaction':_0x12ee53})[_0x3f6c('0x3c')](function(_0x377f9b){var _0x358e6d=_[_0x3f6c('0x41')](_0x458102[_0x3f6c('0x64')],function(_0x1646f8){_0x1646f8[_0x3f6c('0x68')]=_0x458102[_0x3f6c('0x5c')]['id'];return _0x1646f8;});return db['OpenchannelApplication']['bulkCreate'](_0x358e6d,{'transaction':_0x12ee53});});})[_0x3f6c('0x3c')](function(){return db[_0x3f6c('0xac')][_0x3f6c('0xad')]({'where':{'OpenchannelAccountId':_0x458102[_0x3f6c('0x5c')]['id']},'order':'priority'});});}})['then'](respondWithResult(_0x35a8a4,null))[_0x3f6c('0x5a')](handleError(_0x35a8a4,null));};exports[_0x3f6c('0xae')]=function(_0x216fff,_0x5508ba,_0x82bea3){var _0x37ae7c={};var _0x2fb5a6={};var _0x5880e9;var _0x2b2ae7;return db[_0x3f6c('0x42')][_0x3f6c('0x6b')]({'where':{'id':_0x216fff[_0x3f6c('0x5c')]['id']}})['then'](handleEntityNotFound(_0x5508ba,null))[_0x3f6c('0x3c')](function(_0x1b4a6b){if(_0x1b4a6b){_0x5880e9=_0x1b4a6b;_0x2fb5a6[_0x3f6c('0x47')]=_[_0x3f6c('0x49')](db[_0x3f6c('0xac')]['rawAttributes']);_0x2fb5a6[_0x3f6c('0x48')]=_[_0x3f6c('0x49')](_0x216fff[_0x3f6c('0x48')]);_0x2fb5a6['filters']=_[_0x3f6c('0x4b')](_0x2fb5a6[_0x3f6c('0x47')],_0x2fb5a6[_0x3f6c('0x48')]);_0x37ae7c[_0x3f6c('0x4c')]=_['intersection'](_0x2fb5a6[_0x3f6c('0x47')],qs['fields'](_0x216fff['query']['fields']));_0x37ae7c[_0x3f6c('0x4c')]=_0x37ae7c[_0x3f6c('0x4c')][_0x3f6c('0x5e')]?_0x37ae7c['attributes']:_0x2fb5a6[_0x3f6c('0x47')];_0x37ae7c[_0x3f6c('0x50')]=qs[_0x3f6c('0x51')](_0x216fff[_0x3f6c('0x48')][_0x3f6c('0x51')]);_0x37ae7c[_0x3f6c('0x52')]=qs[_0x3f6c('0x4a')](_[_0x3f6c('0xaf')](_0x216fff[_0x3f6c('0x48')],_0x2fb5a6[_0x3f6c('0x4a')]));if(_0x216fff[_0x3f6c('0x48')][_0x3f6c('0x53')]){_0x37ae7c['where']=_[_0x3f6c('0x55')](_0x37ae7c[_0x3f6c('0x52')],{'$or':_[_0x3f6c('0x41')](_0x37ae7c[_0x3f6c('0x4c')],function(_0x2a6e7e){var _0x29b27d={};_0x29b27d[_0x2a6e7e]={'$like':'%'+_0x216fff[_0x3f6c('0x48')][_0x3f6c('0x53')]+'%'};return _0x29b27d;})});}_0x37ae7c=_['merge']({},_0x37ae7c,_0x216fff[_0x3f6c('0x56')]);return _0x5880e9[_0x3f6c('0xae')](_0x37ae7c);}})['then'](function(_0x5600f5){if(_0x5600f5){_0x2b2ae7=_0x5600f5[_0x3f6c('0x5e')];if(!_0x216fff[_0x3f6c('0x48')][_0x3f6c('0x6d')](_0x3f6c('0x4e'))){_0x37ae7c[_0x3f6c('0x4f')]=qs[_0x3f6c('0x4f')](_0x216fff[_0x3f6c('0x48')]['limit']);_0x37ae7c['offset']=qs['offset'](_0x216fff['query'][_0x3f6c('0x31')]);}return _0x5880e9[_0x3f6c('0xae')](_0x37ae7c);}})[_0x3f6c('0x3c')](function(_0x514ba6){if(_0x514ba6){return _0x514ba6?{'count':_0x2b2ae7,'rows':_0x514ba6}:null;}})[_0x3f6c('0x3c')](respondWithResult(_0x5508ba,null))[_0x3f6c('0x5a')](handleError(_0x5508ba,null));};exports['getInteractions']=function(_0x246165,_0x125aa7,_0xacf0b7){var _0x2099ac={'raw':![],'where':{}};var _0x55f167={};var _0x56dc0f={'count':0x0,'rows':[]};return db['OpenchannelAccount'][_0x3f6c('0x6b')]({'where':{'id':_0x246165[_0x3f6c('0x5c')]['id']}})[_0x3f6c('0x3c')](handleEntityNotFound(_0x125aa7,null))['then'](function(_0x46d584){if(_0x46d584){_0x55f167[_0x3f6c('0x47')]=_['keys'](db[_0x3f6c('0x94')][_0x3f6c('0x43')]);_0x55f167[_0x3f6c('0x48')]=_['keys'](_0x246165[_0x3f6c('0x48')]);_0x55f167[_0x3f6c('0x4a')]=_['intersection'](_0x55f167[_0x3f6c('0x47')],_0x55f167[_0x3f6c('0x48')]);_0x2099ac[_0x3f6c('0x4c')]=_[_0x3f6c('0x4b')](_0x55f167[_0x3f6c('0x47')],qs[_0x3f6c('0x4d')](_0x246165[_0x3f6c('0x48')][_0x3f6c('0x4d')]));_0x2099ac['attributes']=_0x2099ac[_0x3f6c('0x4c')]['length']?_0x2099ac['attributes']:_0x55f167['model'];if(!_0x246165[_0x3f6c('0x48')][_0x3f6c('0x6d')](_0x3f6c('0x4e'))){_0x2099ac[_0x3f6c('0x4f')]=qs[_0x3f6c('0x4f')](_0x246165[_0x3f6c('0x48')][_0x3f6c('0x4f')]);_0x2099ac[_0x3f6c('0x31')]=qs[_0x3f6c('0x31')](_0x246165[_0x3f6c('0x48')][_0x3f6c('0x31')]);}_0x2099ac[_0x3f6c('0x50')]=qs[_0x3f6c('0x51')](_0x246165[_0x3f6c('0x48')]['sort']);_0x2099ac[_0x3f6c('0x52')]=qs['filters'](_[_0x3f6c('0xaf')](_0x246165['query'],_0x55f167[_0x3f6c('0x4a')]));_0x2099ac[_0x3f6c('0x52')][_0x3f6c('0x68')]=_0x46d584['id'];if(_0x246165[_0x3f6c('0x48')]['filter']){_0x2099ac[_0x3f6c('0x52')]=_[_0x3f6c('0x55')](_0x2099ac[_0x3f6c('0x52')],{'$or':_[_0x3f6c('0x41')](_0x2099ac['attributes'],function(_0x307108){var _0x68e3fe={};_0x68e3fe[_0x307108]={'$like':'%'+_0x246165[_0x3f6c('0x48')]['filter']+'%'};return _0x68e3fe;})});}_0x2099ac=_[_0x3f6c('0x55')]({},_0x2099ac,_0x246165[_0x3f6c('0x56')]);return db['OpenchannelInteraction']['count']({'where':_0x2099ac[_0x3f6c('0x52')]})[_0x3f6c('0x3c')](function(_0x149840){_0x56dc0f[_0x3f6c('0x30')]=_0x149840;if(_0x246165[_0x3f6c('0x48')]['includeAll']){_0x2099ac[_0x3f6c('0x58')]=[{'model':db[_0x3f6c('0x75')],'as':'Contact','required':![]},{'model':db['User'],'as':_0x3f6c('0xb0'),'attributes':['name','fullname','internal'],'required':![]},{'model':db[_0x3f6c('0xb1')],'as':_0x3f6c('0xb2'),'attributes':['id',_0x3f6c('0x3e'),_0x3f6c('0xb3')],'where':_0x246165['query'][_0x3f6c('0xb4')]?{'id':_0x246165['query'][_0x3f6c('0xb4')]}:undefined,'required':_0x246165[_0x3f6c('0x48')][_0x3f6c('0xb4')]?!![]:![]}];}return db[_0x3f6c('0x94')][_0x3f6c('0x59')](_0x2099ac);})[_0x3f6c('0x3c')](function(_0x307924){_0x56dc0f[_0x3f6c('0x6e')]=_0x307924;return _0x56dc0f;});}})[_0x3f6c('0x3c')](respondWithFilteredResult(_0x125aa7,_0x2099ac))[_0x3f6c('0x5a')](handleError(_0x125aa7,null));};exports[_0x3f6c('0xb5')]=function(_0x177714,_0x5ce448,_0x4bccd1){return db['OpenchannelAccount'][_0x3f6c('0x65')]({'where':{'id':_0x177714[_0x3f6c('0x5c')]['id']}})['then'](handleEntityNotFound(_0x5ce448,null))[_0x3f6c('0x3c')](function(_0x52657c){if(_0x52657c){return _0x52657c[_0x3f6c('0xb5')](_0x177714[_0x3f6c('0x64')][_0x3f6c('0x70')],_[_0x3f6c('0xb6')](_0x177714[_0x3f6c('0x64')],['ids','id'])||{})['spread'](function(_0x4262fa){for(var _0x5c3d96=0x0;_0x5c3d96<_0x177714[_0x3f6c('0x64')][_0x3f6c('0x70')][_0x3f6c('0x5e')];_0x5c3d96+=0x1){socket[_0x3f6c('0xb7')](_0x3f6c('0xb8'),{'UserId':_0x177714[_0x3f6c('0x64')][_0x3f6c('0x70')][_0x5c3d96],'OpenchannelAccountId':_0x177714['params']['id']});}return _0x4262fa;});}})[_0x3f6c('0x3c')](respondWithResult(_0x5ce448,null))[_0x3f6c('0x5a')](handleError(_0x5ce448,null));};exports[_0x3f6c('0xb9')]=function(_0x262d31,_0x56830c,_0x5289e1){return db[_0x3f6c('0x42')][_0x3f6c('0x65')]({'where':{'id':_0x262d31[_0x3f6c('0x5c')]['id']}})['then'](handleEntityNotFound(_0x56830c,null))['then'](function(_0x32792b){if(_0x32792b){return _0x32792b['removeAgents'](_0x262d31[_0x3f6c('0x48')][_0x3f6c('0x70')])[_0x3f6c('0x3c')](function(){if(_[_0x3f6c('0xba')](_0x262d31['query'][_0x3f6c('0x70')])){for(var _0x375a82=0x0;_0x375a82<_0x262d31[_0x3f6c('0x48')][_0x3f6c('0x70')][_0x3f6c('0x5e')];_0x375a82+=0x1){socket['emit'](_0x3f6c('0xbb'),{'UserId':Number(_0x262d31[_0x3f6c('0x48')][_0x3f6c('0x70')][_0x375a82]),'OpenchannelAccountId':Number(_0x262d31[_0x3f6c('0x5c')]['id'])});}}else{socket['emit'](_0x3f6c('0xbb'),{'UserId':Number(_0x262d31[_0x3f6c('0x48')]['ids']),'OpenchannelAccountId':Number(_0x262d31[_0x3f6c('0x5c')]['id'])});}});}})[_0x3f6c('0x3c')](respondWithStatusCode(_0x56830c,null))[_0x3f6c('0x5a')](handleError(_0x56830c,null));};exports[_0x3f6c('0xbc')]=function(_0x26ce04,_0x3c37e9,_0x19449c){var _0x10abbd={};var _0x3b70dc={};var _0x1f2129;var _0x407a88;return db[_0x3f6c('0x42')][_0x3f6c('0x6b')]({'where':{'id':_0x26ce04['params']['id']}})[_0x3f6c('0x3c')](handleEntityNotFound(_0x3c37e9,null))[_0x3f6c('0x3c')](function(_0x1dd2e9){if(_0x1dd2e9){_0x1f2129=_0x1dd2e9;_0x3b70dc[_0x3f6c('0x47')]=_[_0x3f6c('0x49')](db[_0x3f6c('0xa1')]['rawAttributes']);_0x3b70dc[_0x3f6c('0x48')]=_[_0x3f6c('0x49')](_0x26ce04[_0x3f6c('0x48')]);_0x3b70dc[_0x3f6c('0x4a')]=_[_0x3f6c('0x4b')](_0x3b70dc['model'],_0x3b70dc[_0x3f6c('0x48')]);_0x10abbd[_0x3f6c('0x4c')]=_[_0x3f6c('0x4b')](_0x3b70dc[_0x3f6c('0x47')],qs[_0x3f6c('0x4d')](_0x26ce04[_0x3f6c('0x48')]['fields']));_0x10abbd[_0x3f6c('0x4c')]=_0x10abbd[_0x3f6c('0x4c')][_0x3f6c('0x5e')]?_0x10abbd[_0x3f6c('0x4c')]:_0x3b70dc['model'];_0x10abbd['order']=qs[_0x3f6c('0x51')](_0x26ce04[_0x3f6c('0x48')]['sort']);_0x10abbd[_0x3f6c('0x52')]=qs['filters'](_[_0x3f6c('0xaf')](_0x26ce04[_0x3f6c('0x48')],_0x3b70dc[_0x3f6c('0x4a')]));if(_0x26ce04[_0x3f6c('0x48')][_0x3f6c('0x53')]){_0x10abbd[_0x3f6c('0x52')]=_['merge'](_0x10abbd[_0x3f6c('0x52')],{'$or':_[_0x3f6c('0x41')](_0x10abbd[_0x3f6c('0x4c')],function(_0x28b291){var _0x784c28={};_0x784c28[_0x28b291]={'$like':'%'+_0x26ce04[_0x3f6c('0x48')][_0x3f6c('0x53')]+'%'};return _0x784c28;})});}_0x10abbd=_[_0x3f6c('0x55')]({},_0x10abbd,_0x26ce04[_0x3f6c('0x56')]);return _0x1f2129[_0x3f6c('0xbc')](_0x10abbd);}})[_0x3f6c('0x3c')](function(_0x389872){if(_0x389872){_0x407a88=_0x389872[_0x3f6c('0x5e')];if(!_0x26ce04[_0x3f6c('0x48')]['hasOwnProperty'](_0x3f6c('0x4e'))){_0x10abbd[_0x3f6c('0x4f')]=qs[_0x3f6c('0x4f')](_0x26ce04[_0x3f6c('0x48')][_0x3f6c('0x4f')]);_0x10abbd['offset']=qs[_0x3f6c('0x31')](_0x26ce04[_0x3f6c('0x48')][_0x3f6c('0x31')]);}return _0x1f2129['getAgents'](_0x10abbd);}})[_0x3f6c('0x3c')](function(_0x425b2b){if(_0x425b2b){return _0x425b2b?{'count':_0x407a88,'rows':_0x425b2b}:null;}})['then'](respondWithResult(_0x3c37e9,null))[_0x3f6c('0x5a')](handleError(_0x3c37e9,null));};exports[_0x3f6c('0x3f')]=function(_0x1c457e,_0x32739b,_0x36f731){var _0x2a1db3,_0x1a0853,_0x3d9204;if(_[_0x3f6c('0x7c')](_0x1c457e[_0x3f6c('0x64')][_0x3f6c('0x64')])||_0x1c457e[_0x3f6c('0x64')]['body']===''){throw new db[(_0x3f6c('0x7d'))]['ValidationError'](_0x3f6c('0x7f'));}if(_[_0x3f6c('0x7c')](_0x1c457e[_0x3f6c('0x64')]['to'])){}_0x2a1db3=_0x1c457e[_0x3f6c('0x64')]['to'];return db[_0x3f6c('0x42')]['findOne']({'where':{'id':_0x1c457e[_0x3f6c('0x5c')]['id']}})[_0x3f6c('0x3c')](handleEntityNotFound(_0x32739b,null))[_0x3f6c('0x3c')](function(_0x24ea16){if(_0x24ea16){return db[_0x3f6c('0x42')][_0x3f6c('0x65')]({'where':{'id':_0x24ea16['id']},'include':[{'model':db['CmList'],'as':'List','include':[{'model':db[_0x3f6c('0x75')],'as':_0x3f6c('0x86'),'where':{[_0x24ea16[_0x3f6c('0x80')]]:_0x2a1db3},'limit':0x1,'order':[[_0x3f6c('0x79'),'DESC']]}]}]})[_0x3f6c('0x3c')](handleEntityNotFound(_0x32739b,null))[_0x3f6c('0x3c')](function(_0x31f011){if(_0x31f011&&_0x31f011[_0x3f6c('0x85')]){_0x1a0853=_0x31f011[_0x3f6c('0x39')]({'plain':!![]});if(_0x1a0853[_0x3f6c('0x85')]&&_0x1a0853[_0x3f6c('0x85')][_0x3f6c('0x86')][_0x3f6c('0x5e')]){return _0x1a0853[_0x3f6c('0x85')][_0x3f6c('0x86')][0x0];}return db['CmContact'][_0x3f6c('0x69')](_[_0x3f6c('0x8f')](_0x1c457e[_0x3f6c('0x64')],{'firstName':_0x2a1db3,[_0x31f011['mapKey']]:_0x2a1db3,'phone':_0x2a1db3,'ListId':_0x1a0853[_0x3f6c('0x7b')]}));}})[_0x3f6c('0x3c')](handleEntityNotFound(_0x32739b,null))[_0x3f6c('0x3c')](function(_0x20f21c){if(_0x20f21c){_0x3d9204=_0x20f21c;return db['OpenchannelInteraction'][_0x3f6c('0x65')]({'where':{'ContactId':_0x3d9204['id'],'closed':![],'OpenchannelAccountId':_0x1a0853['id']}})[_0x3f6c('0x3c')](function(_0x453b41){if(_0x453b41){return[_0x453b41,![]];}return db[_0x3f6c('0x94')][_0x3f6c('0x69')]({'UserId':_0x1c457e[_0x3f6c('0x5f')]['id'],'ContactId':_0x3d9204['id'],'OpenchannelAccountId':_0x1a0853['id'],'lastMsgDirection':'out','Messages':[_[_0x3f6c('0x55')](_0x1c457e[_0x3f6c('0x64')],{'read':![],'body':_0x1c457e[_0x3f6c('0x64')][_0x3f6c('0x64')],'OpenchannelAccountId':_0x1a0853['id'],'UserId':_0x1c457e[_0x3f6c('0x5f')]['id'],'ContactId':_0x3d9204['id']})]},{'include':[{'model':db['OpenchannelMessage'],'as':_0x3f6c('0xbd')}]})[_0x3f6c('0x3c')](function(_0x1385f5){return[_0x1385f5,!![]];});});}})[_0x3f6c('0x96')](function(_0x41d1f6,_0x2d2a31){if(_0x2d2a31){return _0x41d1f6;}return db[_0x3f6c('0x9e')][_0x3f6c('0x69')](_[_0x3f6c('0x55')](_0x1c457e[_0x3f6c('0x64')],{'read':![],'body':_0x1c457e[_0x3f6c('0x64')][_0x3f6c('0x64')],'OpenchannelAccountId':_0x1a0853['id'],'OpenchannelInteractionId':_0x41d1f6['id'],'UserId':_0x1c457e[_0x3f6c('0x5f')]['id'],'ContactId':_0x3d9204['id']}))[_0x3f6c('0x3c')](function(_0xb91c27){_0x41d1f6[_0x3f6c('0xbe')][_0x3f6c('0xbd')]=[];_0x41d1f6[_0x3f6c('0xbe')]['Messages'][_0x3f6c('0x9b')](_0xb91c27['dataValues']);return _0x41d1f6;});});}})[_0x3f6c('0x3c')](respondWithResult(_0x32739b,null))[_0x3f6c('0x5a')](handleError(_0x32739b,null));};
\ No newline at end of file
+var _0xb4d1=['sox','squel','desk.js','to-csv','querystring','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./openchannelAccount.socket','jayson/promise','client','http','request','then','info','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','OpenchannelAccount,\x20%s,\x20%s,\x20%s','error','message','result','catch','sendStatus','status','end','undefined','count','offset','limit','set','Content-Range','json','apply','update','destroy','OpenchannelAccounts','UserProfileResource','stack','name','send','index','Pause','mandatoryDispositionPause','OpenchannelAccount','rawAttributes','type','key','model','map','query','keys','filters','intersection','attributes','fields','nolimit','order','sort','where','pick','filter','merge','options','includeAll','include','findAll','rows','show','params','length','find','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','OpenchannelAccountId','getDispositions','findOne','Disposition','hasOwnProperty','removeDispositions','ids','addAnswer','CannedAnswer','removeAnswers','notify','openchannel','Sequelize','ValidationError','difference','createdAt','updatedAt','CompanyId','ListId','from\x20is\x20mandatory','isNil','body\x20is\x20mandatory\x20and\x20not\x20empty','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','from','CmList','List','CmContact','Contacts','DESC','account','applications','Applications','list','orderBy','priority','asc','mapKey','contact','firstName','lastName','threadId','OpenchannelInteraction','externalUrl','ContactId','spread','messageId','interaction','autoclose','push','close','OpenchannelMessage','AttachmentId','UserId','User','unshift','agent','waitForTheAssignedAgent','forcedOwnership','Start','startRouting','EventManager','addApplications','sequelize','transaction','OpenchannelApplication','bulkCreate','getApplications','getInteractions','Owner','fullname','internal','Tag','color','tag','addAgents','omit','emit','userOpenchannelAccount:save','removeAgents','isArray','userOpenchannelAccount:remove','getAgents','dataValues','Messages','rimraf','zip-dir','fast-json-patch','moment','bluebird'];(function(_0x24eab9,_0x3d944a){var _0x2ccb3a=function(_0x37bf07){while(--_0x37bf07){_0x24eab9['push'](_0x24eab9['shift']());}};_0x2ccb3a(++_0x3d944a);}(_0xb4d1,0x165));var _0x1b4d=function(_0x18ab2a,_0x4debcd){_0x18ab2a=_0x18ab2a-0x0;var _0x16dcee=_0xb4d1[_0x18ab2a];return _0x16dcee;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x1b4d('0x0'));var zipdir=require(_0x1b4d('0x1'));var jsonpatch=require(_0x1b4d('0x2'));var rp=require('request-promise');var moment=require(_0x1b4d('0x3'));var BPromise=require(_0x1b4d('0x4'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require(_0x1b4d('0x5'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x1b4d('0x6'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x1b4d('0x7'));var toCsv=require(_0x1b4d('0x8'));var querystring=require(_0x1b4d('0x9'));var Papa=require(_0x1b4d('0xa'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x1b4d('0xb'));var as=require(_0x1b4d('0xc'));var hardwareService=require(_0x1b4d('0xd'));var logger=require('../../config/logger')(_0x1b4d('0xe'));var utils=require('../../config/utils');var config=require(_0x1b4d('0xf'));var licenseUtil=require(_0x1b4d('0x10'));var db=require(_0x1b4d('0x11'))['db'];config[_0x1b4d('0x12')]=_[_0x1b4d('0x13')](config[_0x1b4d('0x12')],{'host':_0x1b4d('0x14'),'port':0x18eb});var socket=require(_0x1b4d('0x15'))(new Redis(config[_0x1b4d('0x12')]));require(_0x1b4d('0x16'))['register'](socket);var jayson=require(_0x1b4d('0x17'));var client=jayson[_0x1b4d('0x18')][_0x1b4d('0x19')]({'port':0x232c});var client9002=jayson[_0x1b4d('0x18')][_0x1b4d('0x19')]({'port':0x232a});function respondWithRpcPromise(_0x53ecb8,_0x32593d,_0x57681d,_0xa97257){return new BPromise(function(_0x5af783,_0x359d12){var _0x4dfd60=_0xa97257||client;return _0x4dfd60[_0x1b4d('0x1a')](_0x53ecb8,_0x57681d)[_0x1b4d('0x1b')](function(_0x125c0a){logger[_0x1b4d('0x1c')](_0x1b4d('0x1d'),_0x32593d,_0x1b4d('0x1e'));logger['debug'](_0x1b4d('0x1f'),_0x32593d,_0x1b4d('0x1e'),JSON['stringify'](_0x125c0a));if(_0x125c0a[_0x1b4d('0x20')]){if(_0x125c0a[_0x1b4d('0x20')]['code']===0x1f4){logger['error']('OpenchannelAccount,\x20%s,\x20%s',_0x32593d,_0x125c0a[_0x1b4d('0x20')]['message']);return _0x359d12(_0x125c0a[_0x1b4d('0x20')][_0x1b4d('0x21')]);}logger[_0x1b4d('0x20')](_0x1b4d('0x1d'),_0x32593d,_0x125c0a[_0x1b4d('0x20')][_0x1b4d('0x21')]);return _0x5af783(_0x125c0a['error']['message']);}else{logger[_0x1b4d('0x1c')](_0x1b4d('0x1d'),_0x32593d,_0x1b4d('0x1e'));_0x5af783(_0x125c0a[_0x1b4d('0x22')][_0x1b4d('0x21')]);}})[_0x1b4d('0x23')](function(_0x2ebac5){logger[_0x1b4d('0x20')](_0x1b4d('0x1d'),_0x32593d,_0x2ebac5);_0x359d12(_0x2ebac5);});});}function respondWithStatusCode(_0x2a1fe4,_0x4fe5cc){_0x4fe5cc=_0x4fe5cc||0xcc;return function(_0xba1e51){if(_0xba1e51){return _0x2a1fe4[_0x1b4d('0x24')](_0x4fe5cc);}return _0x2a1fe4[_0x1b4d('0x25')](_0x4fe5cc)[_0x1b4d('0x26')]();};}function respondWithResult(_0x5758f9,_0x478bcf){_0x478bcf=_0x478bcf||0xc8;return function(_0x20d072){if(_0x20d072){return _0x5758f9[_0x1b4d('0x25')](_0x478bcf)['json'](_0x20d072);}};}function respondWithFilteredResult(_0x10a42e,_0x555ee0){return function(_0x3b36ec){if(_0x3b36ec){var _0x20475a=typeof _0x555ee0['offset']===_0x1b4d('0x27')&&typeof _0x555ee0['limit']===_0x1b4d('0x27');var _0x1f64a5=_0x3b36ec[_0x1b4d('0x28')];var _0x21487e=_0x20475a?0x0:_0x555ee0[_0x1b4d('0x29')];var _0x3f4a02=_0x20475a?_0x3b36ec[_0x1b4d('0x28')]:_0x555ee0[_0x1b4d('0x29')]+_0x555ee0[_0x1b4d('0x2a')];var _0x339650;if(_0x3f4a02>=_0x1f64a5){_0x3f4a02=_0x1f64a5;_0x339650=0xc8;}else{_0x339650=0xce;}_0x10a42e[_0x1b4d('0x25')](_0x339650);return _0x10a42e[_0x1b4d('0x2b')](_0x1b4d('0x2c'),_0x21487e+'-'+_0x3f4a02+'/'+_0x1f64a5)[_0x1b4d('0x2d')](_0x3b36ec);}return null;};}function patchUpdates(_0x22aaf8){return function(_0x57c54e){try{jsonpatch[_0x1b4d('0x2e')](_0x57c54e,_0x22aaf8,!![]);}catch(_0x44ce5a){return BPromise['reject'](_0x44ce5a);}return _0x57c54e['save']();};}function saveUpdates(_0xea0446,_0x5e3b19){return function(_0x1b9009){if(_0x1b9009){return _0x1b9009[_0x1b4d('0x2f')](_0xea0446)['then'](function(_0x5630db){return _0x5630db;});}return null;};}function removeEntity(_0x22d577,_0x20b634){return function(_0x859d6d){if(_0x859d6d){return _0x859d6d[_0x1b4d('0x30')]()['then'](function(){var _0x48fce5=_0x859d6d['get']({'plain':!![]});var _0x543193=_0x1b4d('0x31');return db[_0x1b4d('0x32')]['destroy']({'where':{'type':_0x543193,'resourceId':_0x48fce5['id']}})[_0x1b4d('0x1b')](function(){return _0x859d6d;});})[_0x1b4d('0x1b')](function(){_0x22d577[_0x1b4d('0x25')](0xcc)[_0x1b4d('0x26')]();});}};}function handleEntityNotFound(_0x2e471d,_0xf86cf4){return function(_0x46bf76){if(!_0x46bf76){_0x2e471d[_0x1b4d('0x24')](0x194);}return _0x46bf76;};}function handleError(_0x63ad45,_0x536273){_0x536273=_0x536273||0x1f4;return function(_0x58b1c0){logger['error'](_0x58b1c0[_0x1b4d('0x33')]);if(_0x58b1c0[_0x1b4d('0x34')]){delete _0x58b1c0['name'];}_0x63ad45[_0x1b4d('0x25')](_0x536273)[_0x1b4d('0x35')](_0x58b1c0);};}exports[_0x1b4d('0x36')]=function(_0x4af65c,_0x46f93c){var _0x457131={'include':[{'model':db[_0x1b4d('0x37')],'as':_0x1b4d('0x38')}]},_0x3b40bd={},_0xd90123={'count':0x0,'rows':[]};var _0x5acf0a=_['map'](db[_0x1b4d('0x39')][_0x1b4d('0x3a')],function(_0x5008df){return{'name':_0x5008df['fieldName'],'type':_0x5008df[_0x1b4d('0x3b')][_0x1b4d('0x3c')]};});_0x3b40bd[_0x1b4d('0x3d')]=_[_0x1b4d('0x3e')](_0x5acf0a,_0x1b4d('0x34'));_0x3b40bd[_0x1b4d('0x3f')]=_[_0x1b4d('0x40')](_0x4af65c['query']);_0x3b40bd[_0x1b4d('0x41')]=_[_0x1b4d('0x42')](_0x3b40bd[_0x1b4d('0x3d')],_0x3b40bd[_0x1b4d('0x3f')]);_0x457131[_0x1b4d('0x43')]=_[_0x1b4d('0x42')](_0x3b40bd[_0x1b4d('0x3d')],qs[_0x1b4d('0x44')](_0x4af65c[_0x1b4d('0x3f')]['fields']));_0x457131[_0x1b4d('0x43')]=_0x457131[_0x1b4d('0x43')]['length']?_0x457131[_0x1b4d('0x43')]:_0x3b40bd[_0x1b4d('0x3d')];if(!_0x4af65c[_0x1b4d('0x3f')]['hasOwnProperty'](_0x1b4d('0x45'))){_0x457131['limit']=qs['limit'](_0x4af65c[_0x1b4d('0x3f')][_0x1b4d('0x2a')]);_0x457131['offset']=qs['offset'](_0x4af65c['query']['offset']);}_0x457131[_0x1b4d('0x46')]=qs[_0x1b4d('0x47')](_0x4af65c[_0x1b4d('0x3f')][_0x1b4d('0x47')]);_0x457131[_0x1b4d('0x48')]=qs[_0x1b4d('0x41')](_[_0x1b4d('0x49')](_0x4af65c['query'],_0x3b40bd['filters']),_0x5acf0a);if(_0x4af65c[_0x1b4d('0x3f')][_0x1b4d('0x4a')]){_0x457131['where']=_[_0x1b4d('0x4b')](_0x457131[_0x1b4d('0x48')],{'$or':_[_0x1b4d('0x3e')](_0x5acf0a,function(_0x3475ca){if(_0x3475ca[_0x1b4d('0x3b')]!=='VIRTUAL'){var _0x4a115c={};_0x4a115c[_0x3475ca[_0x1b4d('0x34')]]={'$like':'%'+_0x4af65c[_0x1b4d('0x3f')][_0x1b4d('0x4a')]+'%'};return _0x4a115c;}})});}_0x457131=_[_0x1b4d('0x4b')]({},_0x457131,_0x4af65c[_0x1b4d('0x4c')]);var _0x5c4471={'where':_0x457131[_0x1b4d('0x48')]};return db['OpenchannelAccount'][_0x1b4d('0x28')](_0x5c4471)['then'](function(_0x49279a){_0xd90123[_0x1b4d('0x28')]=_0x49279a;if(_0x4af65c[_0x1b4d('0x3f')][_0x1b4d('0x4d')]){_0x457131[_0x1b4d('0x4e')]=[{'all':!![]}];}return db[_0x1b4d('0x39')][_0x1b4d('0x4f')](_0x457131);})[_0x1b4d('0x1b')](function(_0x58ba6e){_0xd90123[_0x1b4d('0x50')]=_0x58ba6e;return _0xd90123;})[_0x1b4d('0x1b')](respondWithFilteredResult(_0x46f93c,_0x457131))[_0x1b4d('0x23')](handleError(_0x46f93c,null));};exports[_0x1b4d('0x51')]=function(_0x3c17b2,_0x5b855e){var _0xe26461={'raw':![],'where':{'id':_0x3c17b2[_0x1b4d('0x52')]['id']},'include':[{'model':db['Pause'],'as':_0x1b4d('0x38')}]},_0x2c0a21={};_0x2c0a21[_0x1b4d('0x3d')]=_[_0x1b4d('0x40')](db['OpenchannelAccount'][_0x1b4d('0x3a')]);_0x2c0a21[_0x1b4d('0x3f')]=_[_0x1b4d('0x40')](_0x3c17b2['query']);_0x2c0a21[_0x1b4d('0x41')]=_[_0x1b4d('0x42')](_0x2c0a21[_0x1b4d('0x3d')],_0x2c0a21[_0x1b4d('0x3f')]);_0xe26461['attributes']=_[_0x1b4d('0x42')](_0x2c0a21[_0x1b4d('0x3d')],qs[_0x1b4d('0x44')](_0x3c17b2[_0x1b4d('0x3f')]['fields']));_0xe26461[_0x1b4d('0x43')]=_0xe26461[_0x1b4d('0x43')][_0x1b4d('0x53')]?_0xe26461[_0x1b4d('0x43')]:_0x2c0a21[_0x1b4d('0x3d')];if(_0x3c17b2[_0x1b4d('0x3f')][_0x1b4d('0x4d')]){_0xe26461[_0x1b4d('0x4e')]=[{'all':!![]}];}_0xe26461=_[_0x1b4d('0x4b')]({},_0xe26461,_0x3c17b2[_0x1b4d('0x4c')]);return db[_0x1b4d('0x39')][_0x1b4d('0x54')](_0xe26461)[_0x1b4d('0x1b')](handleEntityNotFound(_0x5b855e,null))[_0x1b4d('0x1b')](respondWithResult(_0x5b855e,null))['catch'](handleError(_0x5b855e,null));};exports[_0x1b4d('0x55')]=function(_0x255bc1,_0x3807b4){return db[_0x1b4d('0x39')][_0x1b4d('0x55')](_0x255bc1[_0x1b4d('0x56')],{})[_0x1b4d('0x1b')](function(_0xc6b53b){var _0x2d3ac9=_0x255bc1[_0x1b4d('0x57')][_0x1b4d('0x58')]({'plain':!![]});if(!_0x2d3ac9)throw new Error(_0x1b4d('0x59'));if(_0x2d3ac9[_0x1b4d('0x5a')]==='user'){var _0x1fa6e7=_0xc6b53b[_0x1b4d('0x58')]({'plain':!![]});var _0x1d85f9=_0x1b4d('0x31');return db[_0x1b4d('0x5b')][_0x1b4d('0x54')]({'where':{'name':_0x1d85f9,'userProfileId':_0x2d3ac9['userProfileId']},'raw':!![]})[_0x1b4d('0x1b')](function(_0x48b39e){if(_0x48b39e&&_0x48b39e[_0x1b4d('0x5c')]===0x0){return db[_0x1b4d('0x32')][_0x1b4d('0x55')]({'name':_0x1fa6e7['name'],'resourceId':_0x1fa6e7['id'],'type':_0x48b39e[_0x1b4d('0x34')],'sectionId':_0x48b39e['id']},{})['then'](function(){return _0xc6b53b;});}else{return _0xc6b53b;}})[_0x1b4d('0x23')](function(_0x1aa154){logger[_0x1b4d('0x20')](_0x1b4d('0x5d'),_0x1aa154);throw _0x1aa154;});}return _0xc6b53b;})[_0x1b4d('0x1b')](respondWithResult(_0x3807b4,0xc9))[_0x1b4d('0x23')](handleError(_0x3807b4,null));};exports[_0x1b4d('0x2f')]=function(_0x34da54,_0x4b73b1){if(_0x34da54['body']['id']){delete _0x34da54[_0x1b4d('0x56')]['id'];}return db[_0x1b4d('0x39')]['find']({'where':{'id':_0x34da54[_0x1b4d('0x52')]['id']},'include':[{'model':db['Pause'],'as':_0x1b4d('0x38')}]})[_0x1b4d('0x1b')](handleEntityNotFound(_0x4b73b1,null))['then'](saveUpdates(_0x34da54['body'],null))[_0x1b4d('0x1b')](respondWithResult(_0x4b73b1,null))[_0x1b4d('0x23')](handleError(_0x4b73b1,null));};exports[_0x1b4d('0x30')]=function(_0x2ee0ad,_0x2ecb31){return db[_0x1b4d('0x39')][_0x1b4d('0x54')]({'where':{'id':_0x2ee0ad[_0x1b4d('0x52')]['id']}})[_0x1b4d('0x1b')](handleEntityNotFound(_0x2ecb31,null))[_0x1b4d('0x1b')](removeEntity(_0x2ecb31,null))[_0x1b4d('0x23')](handleError(_0x2ecb31,null));};exports['describe']=function(_0x18b1d6,_0x25cdc2){return db[_0x1b4d('0x39')][_0x1b4d('0x5e')]()[_0x1b4d('0x1b')](respondWithResult(_0x25cdc2,null))[_0x1b4d('0x23')](handleError(_0x25cdc2,null));};exports[_0x1b4d('0x5f')]=function(_0x7311c8,_0x178e19,_0x1c5891){if(_0x7311c8[_0x1b4d('0x56')]['id']){delete _0x7311c8[_0x1b4d('0x56')]['id'];}return db['OpenchannelAccount'][_0x1b4d('0x54')]({'where':{'id':_0x7311c8[_0x1b4d('0x52')]['id']}})[_0x1b4d('0x1b')](handleEntityNotFound(_0x178e19,null))[_0x1b4d('0x1b')](function(_0x487c32){if(_0x487c32){_0x7311c8['body'][_0x1b4d('0x60')]=_0x487c32['id'];return db['Disposition'][_0x1b4d('0x55')](_0x7311c8[_0x1b4d('0x56')]);}})[_0x1b4d('0x1b')](respondWithResult(_0x178e19,null))['catch'](handleError(_0x178e19,null));};exports[_0x1b4d('0x61')]=function(_0x12a495,_0x1377a1,_0x5522da){var _0x18306d={'raw':![],'where':{}};var _0x45c6ec={};var _0x2254c7={'count':0x0,'rows':[]};return db[_0x1b4d('0x39')][_0x1b4d('0x62')]({'where':{'id':_0x12a495[_0x1b4d('0x52')]['id']}})[_0x1b4d('0x1b')](handleEntityNotFound(_0x1377a1,null))[_0x1b4d('0x1b')](function(_0x19a7a4){if(_0x19a7a4){_0x45c6ec[_0x1b4d('0x3d')]=_[_0x1b4d('0x40')](db[_0x1b4d('0x63')][_0x1b4d('0x3a')]);_0x45c6ec[_0x1b4d('0x3f')]=_['keys'](_0x12a495['query']);_0x45c6ec[_0x1b4d('0x41')]=_['intersection'](_0x45c6ec[_0x1b4d('0x3d')],_0x45c6ec['query']);_0x18306d[_0x1b4d('0x43')]=_['intersection'](_0x45c6ec['model'],qs['fields'](_0x12a495[_0x1b4d('0x3f')][_0x1b4d('0x44')]));_0x18306d[_0x1b4d('0x43')]=_0x18306d[_0x1b4d('0x43')][_0x1b4d('0x53')]?_0x18306d[_0x1b4d('0x43')]:_0x45c6ec[_0x1b4d('0x3d')];if(!_0x12a495[_0x1b4d('0x3f')][_0x1b4d('0x64')](_0x1b4d('0x45'))){_0x18306d['limit']=qs[_0x1b4d('0x2a')](_0x12a495[_0x1b4d('0x3f')][_0x1b4d('0x2a')]);_0x18306d[_0x1b4d('0x29')]=qs[_0x1b4d('0x29')](_0x12a495[_0x1b4d('0x3f')][_0x1b4d('0x29')]);}_0x18306d['order']=qs[_0x1b4d('0x47')](_0x12a495[_0x1b4d('0x3f')][_0x1b4d('0x47')]);_0x18306d[_0x1b4d('0x48')]=qs[_0x1b4d('0x41')](_[_0x1b4d('0x49')](_0x12a495[_0x1b4d('0x3f')],_0x45c6ec['filters']));_0x18306d['where'][_0x1b4d('0x60')]=_0x19a7a4['id'];if(_0x12a495[_0x1b4d('0x3f')]['filter']){_0x18306d[_0x1b4d('0x48')]=_[_0x1b4d('0x4b')](_0x18306d[_0x1b4d('0x48')],{'$or':_['map'](_0x18306d[_0x1b4d('0x43')],function(_0x3fadf8){var _0x189461={};_0x189461[_0x3fadf8]={'$like':'%'+_0x12a495[_0x1b4d('0x3f')][_0x1b4d('0x4a')]+'%'};return _0x189461;})});}_0x18306d=_[_0x1b4d('0x4b')]({},_0x18306d,_0x12a495[_0x1b4d('0x4c')]);return db['Disposition'][_0x1b4d('0x28')]({'where':_0x18306d[_0x1b4d('0x48')]})[_0x1b4d('0x1b')](function(_0x3e5b25){_0x2254c7[_0x1b4d('0x28')]=_0x3e5b25;if(_0x12a495[_0x1b4d('0x3f')][_0x1b4d('0x4d')]){_0x18306d[_0x1b4d('0x4e')]=[{'all':!![]}];}return db['Disposition']['findAll'](_0x18306d);})[_0x1b4d('0x1b')](function(_0x225c85){_0x2254c7[_0x1b4d('0x50')]=_0x225c85;return _0x2254c7;});}})['then'](respondWithFilteredResult(_0x1377a1,_0x18306d))[_0x1b4d('0x23')](handleError(_0x1377a1,null));};exports['removeDispositions']=function(_0x1984d9,_0x13de55,_0x44ac91){return db[_0x1b4d('0x39')]['find']({'where':{'id':_0x1984d9[_0x1b4d('0x52')]['id']}})['then'](handleEntityNotFound(_0x13de55,null))[_0x1b4d('0x1b')](function(_0x2b376f){if(_0x2b376f){return _0x2b376f[_0x1b4d('0x65')](_0x1984d9[_0x1b4d('0x3f')][_0x1b4d('0x66')]);}})[_0x1b4d('0x1b')](respondWithStatusCode(_0x13de55,null))[_0x1b4d('0x23')](handleError(_0x13de55,null));};exports[_0x1b4d('0x67')]=function(_0x3284b0,_0x29dc0d,_0x859415){if(_0x3284b0[_0x1b4d('0x56')]['id']){delete _0x3284b0[_0x1b4d('0x56')]['id'];}return db[_0x1b4d('0x39')][_0x1b4d('0x54')]({'where':{'id':_0x3284b0[_0x1b4d('0x52')]['id']}})[_0x1b4d('0x1b')](handleEntityNotFound(_0x29dc0d,null))[_0x1b4d('0x1b')](function(_0x3bee8a){if(_0x3bee8a){_0x3284b0[_0x1b4d('0x56')][_0x1b4d('0x60')]=_0x3bee8a['id'];return db[_0x1b4d('0x68')][_0x1b4d('0x55')](_0x3284b0[_0x1b4d('0x56')]);}})[_0x1b4d('0x1b')](respondWithResult(_0x29dc0d,null))[_0x1b4d('0x23')](handleError(_0x29dc0d,null));};exports['getAnswers']=function(_0x3ed40f,_0x200ede,_0x234ddd){var _0x363c19={'raw':![],'where':{}};var _0x570512={};var _0x1c21ab={'count':0x0,'rows':[]};return db['OpenchannelAccount']['findOne']({'where':{'id':_0x3ed40f['params']['id']}})[_0x1b4d('0x1b')](handleEntityNotFound(_0x200ede,null))['then'](function(_0x287fde){if(_0x287fde){_0x570512[_0x1b4d('0x3d')]=_[_0x1b4d('0x40')](db[_0x1b4d('0x68')][_0x1b4d('0x3a')]);_0x570512['query']=_[_0x1b4d('0x40')](_0x3ed40f[_0x1b4d('0x3f')]);_0x570512[_0x1b4d('0x41')]=_[_0x1b4d('0x42')](_0x570512[_0x1b4d('0x3d')],_0x570512[_0x1b4d('0x3f')]);_0x363c19[_0x1b4d('0x43')]=_[_0x1b4d('0x42')](_0x570512[_0x1b4d('0x3d')],qs[_0x1b4d('0x44')](_0x3ed40f[_0x1b4d('0x3f')][_0x1b4d('0x44')]));_0x363c19['attributes']=_0x363c19['attributes'][_0x1b4d('0x53')]?_0x363c19[_0x1b4d('0x43')]:_0x570512[_0x1b4d('0x3d')];if(!_0x3ed40f['query']['hasOwnProperty'](_0x1b4d('0x45'))){_0x363c19[_0x1b4d('0x2a')]=qs[_0x1b4d('0x2a')](_0x3ed40f['query'][_0x1b4d('0x2a')]);_0x363c19[_0x1b4d('0x29')]=qs[_0x1b4d('0x29')](_0x3ed40f[_0x1b4d('0x3f')][_0x1b4d('0x29')]);}_0x363c19[_0x1b4d('0x46')]=qs['sort'](_0x3ed40f['query'][_0x1b4d('0x47')]);_0x363c19[_0x1b4d('0x48')]=qs['filters'](_[_0x1b4d('0x49')](_0x3ed40f[_0x1b4d('0x3f')],_0x570512[_0x1b4d('0x41')]));_0x363c19['where'][_0x1b4d('0x60')]=_0x287fde['id'];if(_0x3ed40f[_0x1b4d('0x3f')][_0x1b4d('0x4a')]){_0x363c19[_0x1b4d('0x48')]=_[_0x1b4d('0x4b')](_0x363c19['where'],{'$or':_[_0x1b4d('0x3e')](_0x363c19['attributes'],function(_0x46f546){var _0x4d28d1={};_0x4d28d1[_0x46f546]={'$like':'%'+_0x3ed40f['query']['filter']+'%'};return _0x4d28d1;})});}_0x363c19=_['merge']({},_0x363c19,_0x3ed40f['options']);return db[_0x1b4d('0x68')][_0x1b4d('0x28')]({'where':_0x363c19[_0x1b4d('0x48')]})[_0x1b4d('0x1b')](function(_0x340fa4){_0x1c21ab['count']=_0x340fa4;if(_0x3ed40f['query'][_0x1b4d('0x4d')]){_0x363c19[_0x1b4d('0x4e')]=[{'all':!![]}];}return db['CannedAnswer'][_0x1b4d('0x4f')](_0x363c19);})[_0x1b4d('0x1b')](function(_0xcb523d){_0x1c21ab[_0x1b4d('0x50')]=_0xcb523d;return _0x1c21ab;});}})[_0x1b4d('0x1b')](respondWithFilteredResult(_0x200ede,_0x363c19))['catch'](handleError(_0x200ede,null));};exports[_0x1b4d('0x69')]=function(_0x522181,_0x2f8a0e,_0xcd1b93){return db[_0x1b4d('0x39')][_0x1b4d('0x54')]({'where':{'id':_0x522181[_0x1b4d('0x52')]['id']}})[_0x1b4d('0x1b')](handleEntityNotFound(_0x2f8a0e,null))['then'](function(_0x1793d1){if(_0x1793d1){return _0x1793d1[_0x1b4d('0x69')](_0x522181[_0x1b4d('0x3f')][_0x1b4d('0x66')]);}})[_0x1b4d('0x1b')](respondWithStatusCode(_0x2f8a0e,null))[_0x1b4d('0x23')](handleError(_0x2f8a0e,null));};exports[_0x1b4d('0x6a')]=function(_0x4eec8e,_0x24b42e,_0xd80d10){var _0xf0557c={'body':_0x4eec8e[_0x1b4d('0x56')],'channel':_0x1b4d('0x6b')};var _0x11aaed=[];var _0x5137f2=[];var _0x1c566f={};var _0x63955a=![];return db['CmContact'][_0x1b4d('0x5e')]()[_0x1b4d('0x1b')](function(_0xb77616){if(!_0xb77616){throw new db[(_0x1b4d('0x6c'))][(_0x1b4d('0x6d'))]('no\x20available\x20attributes');}_0x11aaed=_[_0x1b4d('0x6e')](_[_0x1b4d('0x40')](_0xb77616),[_0x1b4d('0x6f'),_0x1b4d('0x70')]);_0x5137f2=_['difference'](_[_0x1b4d('0x40')](_0xb77616),['createdAt',_0x1b4d('0x70'),_0x1b4d('0x71'),_0x1b4d('0x72')]);if(_0x4eec8e[_0x1b4d('0x56')]['id']){delete _0x4eec8e['body']['id'];}if(_['isNil'](_0x4eec8e[_0x1b4d('0x56')]['from'])){throw new db[(_0x1b4d('0x6c'))][(_0x1b4d('0x6d'))](_0x1b4d('0x73'));}if(_[_0x1b4d('0x74')](_0x4eec8e[_0x1b4d('0x56')][_0x1b4d('0x56')])||_0x4eec8e['body'][_0x1b4d('0x56')]===''){throw new db[(_0x1b4d('0x6c'))][(_0x1b4d('0x6d'))](_0x1b4d('0x75'));}if(_['isNil'](_0x4eec8e[_0x1b4d('0x56')]['mapKey'])){throw new db[(_0x1b4d('0x6c'))][(_0x1b4d('0x6d'))]('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x5137f2);}if(!_[_0x1b4d('0x76')](_0x5137f2,_0x4eec8e[_0x1b4d('0x56')]['mapKey'])){throw new db[(_0x1b4d('0x6c'))][(_0x1b4d('0x6d'))](_0x1b4d('0x77')+_0x5137f2);}_0x1c566f[_0x4eec8e['body']['mapKey']]=_0x4eec8e[_0x1b4d('0x56')][_0x1b4d('0x78')];})[_0x1b4d('0x1b')](function(){return db[_0x1b4d('0x39')]['find']({'where':{'id':_0x4eec8e[_0x1b4d('0x52')]['id']},'include':[{'model':db[_0x1b4d('0x79')],'as':_0x1b4d('0x7a'),'include':[{'model':db[_0x1b4d('0x7b')],'as':_0x1b4d('0x7c'),'where':_0x1c566f,'limit':0x1,'order':[[_0x1b4d('0x70'),_0x1b4d('0x7d')]]}]},{'model':db['OpenchannelApplication'],'as':'Applications'}]});})[_0x1b4d('0x1b')](handleEntityNotFound(_0x24b42e,null))[_0x1b4d('0x1b')](function(_0x2c732b){if(_0x2c732b&&_0x2c732b[_0x1b4d('0x7a')]){_0xf0557c[_0x1b4d('0x7e')]=_0x2c732b;_0xf0557c[_0x1b4d('0x7f')]=_0x2c732b[_0x1b4d('0x80')];_0xf0557c[_0x1b4d('0x81')]=_0x2c732b[_0x1b4d('0x7a')];_0xf0557c[_0x1b4d('0x7f')]=_[_0x1b4d('0x82')](_0xf0557c['applications'],[_0x1b4d('0x83')],[_0x1b4d('0x84')]);if(_0xf0557c[_0x1b4d('0x7e')][_0x1b4d('0x80')]){delete _0xf0557c['account'][_0x1b4d('0x80')];}if(_0xf0557c['account']['List']&&_0xf0557c[_0x1b4d('0x7e')][_0x1b4d('0x7a')][_0x1b4d('0x7c')]['length']){return _0xf0557c['account'][_0x1b4d('0x7a')][_0x1b4d('0x7c')][0x0];}var _0x32e869=_[_0x1b4d('0x13')](_0x4eec8e[_0x1b4d('0x56')],{'firstName':_0x4eec8e['body'][_0x1b4d('0x78')],'ListId':_0x2c732b['ListId']});_0x32e869[_0x4eec8e[_0x1b4d('0x56')][_0x1b4d('0x85')]]=_0x4eec8e[_0x1b4d('0x56')][_0x1b4d('0x78')];return db[_0x1b4d('0x7b')][_0x1b4d('0x55')](_0x32e869,{'fields':_0x11aaed,'raw':!![]});}})['then'](handleEntityNotFound(_0x24b42e,null))[_0x1b4d('0x1b')](function(_0x2ebd17){_0xf0557c[_0x1b4d('0x86')]=_0x2ebd17;if(_0x2ebd17){var _0x3c62b7={'ContactId':_0x2ebd17['id'],'OpenchannelAccountId':_0x4eec8e[_0x1b4d('0x52')]['id'],'from':(_0x2ebd17[_0x1b4d('0x87')]||'')+'\x20'+(_0x2ebd17[_0x1b4d('0x88')]||'')};var _0x3e60cf={'OpenchannelAccountId':_0x4eec8e[_0x1b4d('0x52')]['id'],'closed':![]};if(_0x4eec8e[_0x1b4d('0x56')]['threadId']){_0x3e60cf['threadId']=_0x4eec8e[_0x1b4d('0x56')][_0x1b4d('0x89')];return db[_0x1b4d('0x8a')][_0x1b4d('0x54')]({'where':_0x3e60cf})[_0x1b4d('0x1b')](function(_0x54fdc1){if(_0x54fdc1){return[_0x54fdc1,![]];}_0x3c62b7[_0x1b4d('0x89')]=_0x4eec8e[_0x1b4d('0x56')][_0x1b4d('0x89')];_0x3c62b7[_0x1b4d('0x8b')]=_0x4eec8e[_0x1b4d('0x56')][_0x1b4d('0x8b')];return db[_0x1b4d('0x8a')][_0x1b4d('0x55')](_0x3c62b7)[_0x1b4d('0x1b')](function(_0x3c2648){return[_0x3c2648,!![]];});});}else{_0x3e60cf[_0x1b4d('0x89')]=null;}_0x3e60cf[_0x1b4d('0x8c')]=_0x2ebd17['id'];return db[_0x1b4d('0x8a')][_0x1b4d('0x54')]({'where':_0x3e60cf})['then'](function(_0x3fd046){if(_0x3fd046){return[_0x3fd046,![]];}return db['OpenchannelInteraction'][_0x1b4d('0x55')](_0x3c62b7)['then'](function(_0x30e133){return[_0x30e133,!![]];});});}})[_0x1b4d('0x8d')](function(_0x3ed387,_0x2cc569){if(_0x3ed387){_0x63955a=_0x2cc569;if(!_0x2cc569){var _0x2111c9={'from':(_0xf0557c[_0x1b4d('0x86')][_0x1b4d('0x87')]||'')+'\x20'+(_0xf0557c[_0x1b4d('0x86')][_0x1b4d('0x88')]||'')};if(_0x4eec8e[_0x1b4d('0x56')][_0x1b4d('0x89')]&&_0x4eec8e[_0x1b4d('0x56')][_0x1b4d('0x8e')]&&_0x4eec8e[_0x1b4d('0x56')][_0x1b4d('0x89')]!=_0x4eec8e[_0x1b4d('0x56')][_0x1b4d('0x8e')]){_0x2111c9[_0x1b4d('0x89')]=_0x4eec8e['body'][_0x1b4d('0x8e')];}return _0x3ed387[_0x1b4d('0x2f')](_0x2111c9);}else{return _0x3ed387;}}})['then'](function(_0x34935c){_0xf0557c[_0x1b4d('0x8f')]=_0x34935c[_0x1b4d('0x58')]({'plain':!![]});_0xf0557c[_0x1b4d('0x8f')]['created']=_0x63955a;if(_0xf0557c['interaction']['created']){if(_0xf0557c[_0x1b4d('0x7e')][_0x1b4d('0x90')]){_0xf0557c[_0x1b4d('0x7f')][_0x1b4d('0x91')]({'id':0x0,'priority':_0xf0557c[_0x1b4d('0x7f')][_0x1b4d('0x53')]+0x1,'app':_0x1b4d('0x92'),'appdata':'unmanaged','interval':'*,*,*,*'});}}return db[_0x1b4d('0x93')][_0x1b4d('0x55')]({'body':_0x4eec8e[_0x1b4d('0x56')][_0x1b4d('0x56')],'OpenchannelAccountId':_0x4eec8e[_0x1b4d('0x52')]['id'],'OpenchannelInteractionId':_0x34935c['id'],'direction':'in','ContactId':_0xf0557c[_0x1b4d('0x86')]['id'],'AttachmentId':_0x4eec8e[_0x1b4d('0x56')][_0x1b4d('0x94')]});})[_0x1b4d('0x1b')](function(_0x228035){_0xf0557c[_0x1b4d('0x21')]=_0x228035;if(_0xf0557c[_0x1b4d('0x8f')][_0x1b4d('0x95')]){return db[_0x1b4d('0x96')]['find']({'attributes':['id',_0x1b4d('0x34')],'where':{'id':_0xf0557c[_0x1b4d('0x8f')][_0x1b4d('0x95')]}})[_0x1b4d('0x1b')](function(_0x2c1d8b){if(_0x2c1d8b){_0xf0557c['applications'][_0x1b4d('0x97')]({'id':0x0,'priority':0x0,'app':_0x1b4d('0x98'),'appdata':_0x2c1d8b['name']+','+(_0xf0557c[_0x1b4d('0x7e')][_0x1b4d('0x99')]||0xa),'interval':'*,*,*,*'});_0xf0557c[_0x1b4d('0x9a')]=![];}return respondWithRpcPromise(_0x1b4d('0x9b'),_0x1b4d('0x9c'),_0xf0557c);});}return respondWithRpcPromise('Start',_0x1b4d('0x9c'),_0xf0557c);})[_0x1b4d('0x1b')](function(_0x2dd7ba){respondWithRpcPromise(_0x1b4d('0x9d'),'EventManager',{'event':_0x1b4d('0x6a'),'message':_0x2dd7ba},client9002);return _0x2dd7ba;})[_0x1b4d('0x1b')](respondWithResult(_0x24b42e,null))[_0x1b4d('0x23')](handleError(_0x24b42e,null));};exports[_0x1b4d('0x9e')]=function(_0x34544b,_0x4f39f5,_0x25034a){return db[_0x1b4d('0x39')]['findOne']({'where':{'id':_0x34544b[_0x1b4d('0x52')]['id']}})['then'](handleEntityNotFound(_0x4f39f5,null))[_0x1b4d('0x1b')](function(_0x8f15f4){if(_0x8f15f4){return db[_0x1b4d('0x9f')][_0x1b4d('0xa0')](function(_0xebf480){return db[_0x1b4d('0xa1')][_0x1b4d('0x30')]({'where':{'OpenchannelAccountId':_0x34544b[_0x1b4d('0x52')]['id']},'transaction':_0xebf480})[_0x1b4d('0x1b')](function(_0x22e519){var _0x2f56b9=_[_0x1b4d('0x3e')](_0x34544b['body'],function(_0x19e2d4){_0x19e2d4[_0x1b4d('0x60')]=_0x34544b[_0x1b4d('0x52')]['id'];return _0x19e2d4;});return db[_0x1b4d('0xa1')][_0x1b4d('0xa2')](_0x2f56b9,{'transaction':_0xebf480});});})[_0x1b4d('0x1b')](function(){return db[_0x1b4d('0xa1')]['findAndCountAll']({'where':{'OpenchannelAccountId':_0x34544b[_0x1b4d('0x52')]['id']},'order':_0x1b4d('0x83')});});}})['then'](respondWithResult(_0x4f39f5,null))[_0x1b4d('0x23')](handleError(_0x4f39f5,null));};exports[_0x1b4d('0xa3')]=function(_0x14b19b,_0x3cfb4a,_0x35a23e){var _0x32d2af={};var _0x1ad7a0={};var _0x20573e;var _0x226aa0;return db[_0x1b4d('0x39')]['findOne']({'where':{'id':_0x14b19b[_0x1b4d('0x52')]['id']}})[_0x1b4d('0x1b')](handleEntityNotFound(_0x3cfb4a,null))[_0x1b4d('0x1b')](function(_0x585552){if(_0x585552){_0x20573e=_0x585552;_0x1ad7a0[_0x1b4d('0x3d')]=_[_0x1b4d('0x40')](db['OpenchannelApplication'][_0x1b4d('0x3a')]);_0x1ad7a0[_0x1b4d('0x3f')]=_[_0x1b4d('0x40')](_0x14b19b[_0x1b4d('0x3f')]);_0x1ad7a0[_0x1b4d('0x41')]=_[_0x1b4d('0x42')](_0x1ad7a0[_0x1b4d('0x3d')],_0x1ad7a0[_0x1b4d('0x3f')]);_0x32d2af[_0x1b4d('0x43')]=_[_0x1b4d('0x42')](_0x1ad7a0[_0x1b4d('0x3d')],qs[_0x1b4d('0x44')](_0x14b19b[_0x1b4d('0x3f')][_0x1b4d('0x44')]));_0x32d2af[_0x1b4d('0x43')]=_0x32d2af[_0x1b4d('0x43')][_0x1b4d('0x53')]?_0x32d2af[_0x1b4d('0x43')]:_0x1ad7a0['model'];_0x32d2af[_0x1b4d('0x46')]=qs['sort'](_0x14b19b[_0x1b4d('0x3f')][_0x1b4d('0x47')]);_0x32d2af[_0x1b4d('0x48')]=qs['filters'](_['pick'](_0x14b19b[_0x1b4d('0x3f')],_0x1ad7a0['filters']));if(_0x14b19b['query']['filter']){_0x32d2af[_0x1b4d('0x48')]=_[_0x1b4d('0x4b')](_0x32d2af[_0x1b4d('0x48')],{'$or':_[_0x1b4d('0x3e')](_0x32d2af[_0x1b4d('0x43')],function(_0x3de472){var _0x51f7ed={};_0x51f7ed[_0x3de472]={'$like':'%'+_0x14b19b[_0x1b4d('0x3f')][_0x1b4d('0x4a')]+'%'};return _0x51f7ed;})});}_0x32d2af=_[_0x1b4d('0x4b')]({},_0x32d2af,_0x14b19b[_0x1b4d('0x4c')]);return _0x20573e[_0x1b4d('0xa3')](_0x32d2af);}})[_0x1b4d('0x1b')](function(_0x848acc){if(_0x848acc){_0x226aa0=_0x848acc[_0x1b4d('0x53')];if(!_0x14b19b[_0x1b4d('0x3f')][_0x1b4d('0x64')](_0x1b4d('0x45'))){_0x32d2af[_0x1b4d('0x2a')]=qs[_0x1b4d('0x2a')](_0x14b19b[_0x1b4d('0x3f')][_0x1b4d('0x2a')]);_0x32d2af[_0x1b4d('0x29')]=qs[_0x1b4d('0x29')](_0x14b19b[_0x1b4d('0x3f')][_0x1b4d('0x29')]);}return _0x20573e[_0x1b4d('0xa3')](_0x32d2af);}})[_0x1b4d('0x1b')](function(_0x25e851){if(_0x25e851){return _0x25e851?{'count':_0x226aa0,'rows':_0x25e851}:null;}})[_0x1b4d('0x1b')](respondWithResult(_0x3cfb4a,null))['catch'](handleError(_0x3cfb4a,null));};exports[_0x1b4d('0xa4')]=function(_0x5c9472,_0x2e6152,_0x259688){var _0x117147={'raw':![],'where':{}};var _0x1be18d={};var _0x5781d3={'count':0x0,'rows':[]};return db[_0x1b4d('0x39')]['findOne']({'where':{'id':_0x5c9472[_0x1b4d('0x52')]['id']}})[_0x1b4d('0x1b')](handleEntityNotFound(_0x2e6152,null))[_0x1b4d('0x1b')](function(_0x3e8f98){if(_0x3e8f98){_0x1be18d['model']=_[_0x1b4d('0x40')](db[_0x1b4d('0x8a')][_0x1b4d('0x3a')]);_0x1be18d['query']=_[_0x1b4d('0x40')](_0x5c9472['query']);_0x1be18d['filters']=_[_0x1b4d('0x42')](_0x1be18d[_0x1b4d('0x3d')],_0x1be18d[_0x1b4d('0x3f')]);_0x117147[_0x1b4d('0x43')]=_[_0x1b4d('0x42')](_0x1be18d[_0x1b4d('0x3d')],qs[_0x1b4d('0x44')](_0x5c9472[_0x1b4d('0x3f')][_0x1b4d('0x44')]));_0x117147[_0x1b4d('0x43')]=_0x117147[_0x1b4d('0x43')]['length']?_0x117147[_0x1b4d('0x43')]:_0x1be18d[_0x1b4d('0x3d')];if(!_0x5c9472[_0x1b4d('0x3f')][_0x1b4d('0x64')](_0x1b4d('0x45'))){_0x117147[_0x1b4d('0x2a')]=qs['limit'](_0x5c9472[_0x1b4d('0x3f')][_0x1b4d('0x2a')]);_0x117147[_0x1b4d('0x29')]=qs['offset'](_0x5c9472[_0x1b4d('0x3f')]['offset']);}_0x117147['order']=qs['sort'](_0x5c9472[_0x1b4d('0x3f')][_0x1b4d('0x47')]);_0x117147[_0x1b4d('0x48')]=qs[_0x1b4d('0x41')](_[_0x1b4d('0x49')](_0x5c9472[_0x1b4d('0x3f')],_0x1be18d[_0x1b4d('0x41')]));_0x117147[_0x1b4d('0x48')]['OpenchannelAccountId']=_0x3e8f98['id'];if(_0x5c9472[_0x1b4d('0x3f')]['filter']){_0x117147['where']=_[_0x1b4d('0x4b')](_0x117147[_0x1b4d('0x48')],{'$or':_[_0x1b4d('0x3e')](_0x117147[_0x1b4d('0x43')],function(_0x103282){var _0x14ffc4={};_0x14ffc4[_0x103282]={'$like':'%'+_0x5c9472[_0x1b4d('0x3f')][_0x1b4d('0x4a')]+'%'};return _0x14ffc4;})});}_0x117147=_[_0x1b4d('0x4b')]({},_0x117147,_0x5c9472[_0x1b4d('0x4c')]);return db[_0x1b4d('0x8a')]['count']({'where':_0x117147[_0x1b4d('0x48')]})[_0x1b4d('0x1b')](function(_0x125bec){_0x5781d3[_0x1b4d('0x28')]=_0x125bec;if(_0x5c9472[_0x1b4d('0x3f')][_0x1b4d('0x4d')]){_0x117147[_0x1b4d('0x4e')]=[{'model':db['CmContact'],'as':'Contact','required':![]},{'model':db[_0x1b4d('0x96')],'as':_0x1b4d('0xa5'),'attributes':['name',_0x1b4d('0xa6'),_0x1b4d('0xa7')],'required':![]},{'model':db[_0x1b4d('0xa8')],'as':'Tags','attributes':['id',_0x1b4d('0x34'),_0x1b4d('0xa9')],'where':_0x5c9472['query'][_0x1b4d('0xaa')]?{'id':_0x5c9472['query']['tag']}:undefined,'required':_0x5c9472['query'][_0x1b4d('0xaa')]?!![]:![]}];}return db[_0x1b4d('0x8a')][_0x1b4d('0x4f')](_0x117147);})[_0x1b4d('0x1b')](function(_0x195337){_0x5781d3['rows']=_0x195337;return _0x5781d3;});}})['then'](respondWithFilteredResult(_0x2e6152,_0x117147))[_0x1b4d('0x23')](handleError(_0x2e6152,null));};exports['addAgents']=function(_0x349b8d,_0x497f68,_0x1743ce){return db[_0x1b4d('0x39')][_0x1b4d('0x54')]({'where':{'id':_0x349b8d[_0x1b4d('0x52')]['id']}})[_0x1b4d('0x1b')](handleEntityNotFound(_0x497f68,null))['then'](function(_0x6bdd23){if(_0x6bdd23){return _0x6bdd23[_0x1b4d('0xab')](_0x349b8d[_0x1b4d('0x56')][_0x1b4d('0x66')],_[_0x1b4d('0xac')](_0x349b8d[_0x1b4d('0x56')],[_0x1b4d('0x66'),'id'])||{})[_0x1b4d('0x8d')](function(_0x46a6f4){for(var _0x569f5b=0x0;_0x569f5b<_0x349b8d[_0x1b4d('0x56')]['ids'][_0x1b4d('0x53')];_0x569f5b+=0x1){socket[_0x1b4d('0xad')](_0x1b4d('0xae'),{'UserId':_0x349b8d[_0x1b4d('0x56')][_0x1b4d('0x66')][_0x569f5b],'OpenchannelAccountId':_0x349b8d[_0x1b4d('0x52')]['id']});}return _0x46a6f4;});}})['then'](respondWithResult(_0x497f68,null))[_0x1b4d('0x23')](handleError(_0x497f68,null));};exports['removeAgents']=function(_0x290be1,_0x3c1e23,_0x380452){return db[_0x1b4d('0x39')][_0x1b4d('0x54')]({'where':{'id':_0x290be1[_0x1b4d('0x52')]['id']}})[_0x1b4d('0x1b')](handleEntityNotFound(_0x3c1e23,null))[_0x1b4d('0x1b')](function(_0x4dc46e){if(_0x4dc46e){return _0x4dc46e[_0x1b4d('0xaf')](_0x290be1[_0x1b4d('0x3f')][_0x1b4d('0x66')])['then'](function(){if(_[_0x1b4d('0xb0')](_0x290be1[_0x1b4d('0x3f')]['ids'])){for(var _0x30a7bb=0x0;_0x30a7bb<_0x290be1['query'][_0x1b4d('0x66')][_0x1b4d('0x53')];_0x30a7bb+=0x1){socket[_0x1b4d('0xad')]('userOpenchannelAccount:remove',{'UserId':Number(_0x290be1[_0x1b4d('0x3f')][_0x1b4d('0x66')][_0x30a7bb]),'OpenchannelAccountId':Number(_0x290be1['params']['id'])});}}else{socket['emit'](_0x1b4d('0xb1'),{'UserId':Number(_0x290be1['query'][_0x1b4d('0x66')]),'OpenchannelAccountId':Number(_0x290be1['params']['id'])});}});}})[_0x1b4d('0x1b')](respondWithStatusCode(_0x3c1e23,null))[_0x1b4d('0x23')](handleError(_0x3c1e23,null));};exports[_0x1b4d('0xb2')]=function(_0x199f8f,_0x308dd,_0x57fc0a){var _0x23a334={};var _0x1d2916={};var _0xe47f22;var _0x3bcea1;return db[_0x1b4d('0x39')][_0x1b4d('0x62')]({'where':{'id':_0x199f8f['params']['id']}})['then'](handleEntityNotFound(_0x308dd,null))[_0x1b4d('0x1b')](function(_0x4e7741){if(_0x4e7741){_0xe47f22=_0x4e7741;_0x1d2916[_0x1b4d('0x3d')]=_[_0x1b4d('0x40')](db['User']['rawAttributes']);_0x1d2916['query']=_[_0x1b4d('0x40')](_0x199f8f[_0x1b4d('0x3f')]);_0x1d2916[_0x1b4d('0x41')]=_[_0x1b4d('0x42')](_0x1d2916[_0x1b4d('0x3d')],_0x1d2916[_0x1b4d('0x3f')]);_0x23a334['attributes']=_[_0x1b4d('0x42')](_0x1d2916[_0x1b4d('0x3d')],qs['fields'](_0x199f8f['query'][_0x1b4d('0x44')]));_0x23a334[_0x1b4d('0x43')]=_0x23a334[_0x1b4d('0x43')][_0x1b4d('0x53')]?_0x23a334[_0x1b4d('0x43')]:_0x1d2916[_0x1b4d('0x3d')];_0x23a334[_0x1b4d('0x46')]=qs['sort'](_0x199f8f['query']['sort']);_0x23a334[_0x1b4d('0x48')]=qs[_0x1b4d('0x41')](_[_0x1b4d('0x49')](_0x199f8f[_0x1b4d('0x3f')],_0x1d2916[_0x1b4d('0x41')]));if(_0x199f8f[_0x1b4d('0x3f')][_0x1b4d('0x4a')]){_0x23a334[_0x1b4d('0x48')]=_[_0x1b4d('0x4b')](_0x23a334[_0x1b4d('0x48')],{'$or':_['map'](_0x23a334[_0x1b4d('0x43')],function(_0x390a2e){var _0x540df7={};_0x540df7[_0x390a2e]={'$like':'%'+_0x199f8f[_0x1b4d('0x3f')][_0x1b4d('0x4a')]+'%'};return _0x540df7;})});}_0x23a334=_[_0x1b4d('0x4b')]({},_0x23a334,_0x199f8f[_0x1b4d('0x4c')]);return _0xe47f22[_0x1b4d('0xb2')](_0x23a334);}})[_0x1b4d('0x1b')](function(_0x4280fc){if(_0x4280fc){_0x3bcea1=_0x4280fc['length'];if(!_0x199f8f['query'][_0x1b4d('0x64')](_0x1b4d('0x45'))){_0x23a334[_0x1b4d('0x2a')]=qs['limit'](_0x199f8f[_0x1b4d('0x3f')][_0x1b4d('0x2a')]);_0x23a334[_0x1b4d('0x29')]=qs[_0x1b4d('0x29')](_0x199f8f[_0x1b4d('0x3f')]['offset']);}return _0xe47f22[_0x1b4d('0xb2')](_0x23a334);}})['then'](function(_0x5e54ec){if(_0x5e54ec){return _0x5e54ec?{'count':_0x3bcea1,'rows':_0x5e54ec}:null;}})['then'](respondWithResult(_0x308dd,null))['catch'](handleError(_0x308dd,null));};exports[_0x1b4d('0x35')]=function(_0x294428,_0x542552,_0x1aa166){var _0x393c0f,_0x496df2,_0x3f3b45;if(_[_0x1b4d('0x74')](_0x294428[_0x1b4d('0x56')]['body'])||_0x294428[_0x1b4d('0x56')][_0x1b4d('0x56')]===''){throw new db[(_0x1b4d('0x6c'))][(_0x1b4d('0x6d'))](_0x1b4d('0x75'));}if(_[_0x1b4d('0x74')](_0x294428[_0x1b4d('0x56')]['to'])){}_0x393c0f=_0x294428[_0x1b4d('0x56')]['to'];return db['OpenchannelAccount']['findOne']({'where':{'id':_0x294428['params']['id']}})[_0x1b4d('0x1b')](handleEntityNotFound(_0x542552,null))['then'](function(_0xb01857){if(_0xb01857){return db[_0x1b4d('0x39')]['find']({'where':{'id':_0xb01857['id']},'include':[{'model':db[_0x1b4d('0x79')],'as':'List','include':[{'model':db[_0x1b4d('0x7b')],'as':_0x1b4d('0x7c'),'where':{[_0xb01857[_0x1b4d('0x85')]]:_0x393c0f},'limit':0x1,'order':[['updatedAt',_0x1b4d('0x7d')]]}]}]})['then'](handleEntityNotFound(_0x542552,null))['then'](function(_0x54a8b9){if(_0x54a8b9&&_0x54a8b9[_0x1b4d('0x7a')]){_0x496df2=_0x54a8b9[_0x1b4d('0x58')]({'plain':!![]});if(_0x496df2[_0x1b4d('0x7a')]&&_0x496df2[_0x1b4d('0x7a')][_0x1b4d('0x7c')]['length']){return _0x496df2[_0x1b4d('0x7a')][_0x1b4d('0x7c')][0x0];}return db['CmContact'][_0x1b4d('0x55')](_[_0x1b4d('0x13')](_0x294428[_0x1b4d('0x56')],{'firstName':_0x393c0f,[_0x54a8b9[_0x1b4d('0x85')]]:_0x393c0f,'phone':_0x393c0f,'ListId':_0x496df2['ListId']}));}})['then'](handleEntityNotFound(_0x542552,null))[_0x1b4d('0x1b')](function(_0x3c8a77){if(_0x3c8a77){_0x3f3b45=_0x3c8a77;return db[_0x1b4d('0x8a')][_0x1b4d('0x54')]({'where':{'ContactId':_0x3f3b45['id'],'closed':![],'OpenchannelAccountId':_0x496df2['id']}})['then'](function(_0x43c138){if(_0x43c138){return[_0x43c138,![]];}return db[_0x1b4d('0x8a')][_0x1b4d('0x55')]({'UserId':_0x294428[_0x1b4d('0x57')]['id'],'ContactId':_0x3f3b45['id'],'OpenchannelAccountId':_0x496df2['id'],'lastMsgDirection':'out','Messages':[_['merge'](_0x294428[_0x1b4d('0x56')],{'read':![],'body':_0x294428[_0x1b4d('0x56')][_0x1b4d('0x56')],'OpenchannelAccountId':_0x496df2['id'],'UserId':_0x294428['user']['id'],'ContactId':_0x3f3b45['id']})]},{'include':[{'model':db[_0x1b4d('0x93')],'as':'Messages'}]})[_0x1b4d('0x1b')](function(_0x5a3444){return[_0x5a3444,!![]];});});}})[_0x1b4d('0x8d')](function(_0x53c08a,_0x4380a){if(_0x4380a){return _0x53c08a;}return db[_0x1b4d('0x93')]['create'](_[_0x1b4d('0x4b')](_0x294428['body'],{'read':![],'body':_0x294428[_0x1b4d('0x56')][_0x1b4d('0x56')],'OpenchannelAccountId':_0x496df2['id'],'OpenchannelInteractionId':_0x53c08a['id'],'UserId':_0x294428[_0x1b4d('0x57')]['id'],'ContactId':_0x3f3b45['id']}))['then'](function(_0x3a3cc6){_0x53c08a[_0x1b4d('0xb3')][_0x1b4d('0xb4')]=[];_0x53c08a[_0x1b4d('0xb3')][_0x1b4d('0xb4')]['push'](_0x3a3cc6[_0x1b4d('0xb3')]);return _0x53c08a;});});}})['then'](respondWithResult(_0x542552,null))['catch'](handleError(_0x542552,null));};
\ No newline at end of file