Built motion from commit 449495f6.|2.6.27
[motion2.git] / server / api / openchannelAccount / openchannelAccount.controller.js
index be9a2c6..e482a1b 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xc838=['to-csv','ejs','fs-extra','lodash','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','defaults','localhost','socket.io-emitter','redis','./openchannelAccount.socket','register','jayson/promise','client','http','request','info','request\x20sent','debug','stringify','error','code','message','OpenchannelAccount,\x20%s,\x20%s','result','catch','sendStatus','status','undefined','count','offset','limit','set','Content-Range','json','apply','reject','save','update','destroy','then','get','OpenchannelAccounts','UserProfileResource','end','send','index','Pause','map','OpenchannelAccount','rawAttributes','fieldName','key','model','name','filters','intersection','query','attributes','fields','length','order','sort','where','pick','filter','VIRTUAL','merge','includeAll','include','show','params','mandatoryDispositionPause','keys','options','find','create','body','user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','OpenchannelAccountId','getDispositions','findOne','Disposition','hasOwnProperty','nolimit','rows','removeDispositions','CannedAnswer','removeAnswers','ids','notify','openchannel','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','ListId','isNil','from','Sequelize','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','List','CmContact','Contacts','DESC','OpenchannelApplication','Applications','account','applications','list','orderBy','priority','asc','contact','lastName','threadId','OpenchannelInteraction','externalUrl','ContactId','firstName','messageId','interaction','created','autoclose','push','close','*,*,*,*','UserId','agent','queueId','OpenchannelQueue','unshift','queue','waitForTheAssignedQueue','Start','EventManager','addApplications','sequelize','Transaction','ISOLATION_LEVELS','READ_COMMITTED','bulkCreate','findAndCountAll','stack','finally','getApplications','getInteractions','Contact','User','Owner','fullname','internal','Tag','Tags','tag','findAll','addAgents','omit','spread','userOpenchannelAccount:save','removeAgents','isArray','emit','userOpenchannelAccount:remove','getAgents','body\x20is\x20mandatory\x20and\x20not\x20empty','out','Messages','dataValues','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox'];(function(_0x22b5e1,_0x82aa40){var _0x317f1b=function(_0x49c8a8){while(--_0x49c8a8){_0x22b5e1['push'](_0x22b5e1['shift']());}};_0x317f1b(++_0x82aa40);}(_0xc838,0xbd));var _0x8c83=function(_0x56649f,_0xec00f0){_0x56649f=_0x56649f-0x0;var _0x20d203=_0xc838[_0x56649f];return _0x20d203;};'use strict';var emlformat=require(_0x8c83('0x0'));var rimraf=require(_0x8c83('0x1'));var zipdir=require(_0x8c83('0x2'));var jsonpatch=require(_0x8c83('0x3'));var rp=require(_0x8c83('0x4'));var moment=require(_0x8c83('0x5'));var BPromise=require(_0x8c83('0x6'));var Mustache=require(_0x8c83('0x7'));var util=require(_0x8c83('0x8'));var path=require(_0x8c83('0x9'));var sox=require(_0x8c83('0xa'));var csv=require(_0x8c83('0xb'));var ejs=require(_0x8c83('0xc'));var fs=require('fs');var fs_extra=require(_0x8c83('0xd'));var _=require(_0x8c83('0xe'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x8c83('0xf'));var deskjs=require('desk.js');var toCsv=require(_0x8c83('0xb'));var querystring=require(_0x8c83('0x10'));var Papa=require(_0x8c83('0x11'));var Redis=require(_0x8c83('0x12'));var authService=require(_0x8c83('0x13'));var qs=require(_0x8c83('0x14'));var as=require(_0x8c83('0x15'));var hardwareService=require(_0x8c83('0x16'));var logger=require(_0x8c83('0x17'))(_0x8c83('0x18'));var utils=require(_0x8c83('0x19'));var config=require('../../config/environment');var licenseUtil=require(_0x8c83('0x1a'));var db=require('../../mysqldb')['db'];config['redis']=_[_0x8c83('0x1b')](config['redis'],{'host':_0x8c83('0x1c'),'port':0x18eb});var socket=require(_0x8c83('0x1d'))(new Redis(config[_0x8c83('0x1e')]));require(_0x8c83('0x1f'))[_0x8c83('0x20')](socket);var jayson=require(_0x8c83('0x21'));var client=jayson[_0x8c83('0x22')][_0x8c83('0x23')]({'port':0x232c});var client9002=jayson[_0x8c83('0x22')][_0x8c83('0x23')]({'port':0x232a});function respondWithRpcPromise(_0x573b7d,_0x2b4027,_0x3d82ca,_0x52d916){return new BPromise(function(_0x593c97,_0x40bc0d){var _0x4e3da8=_0x52d916||client;return _0x4e3da8[_0x8c83('0x24')](_0x573b7d,_0x3d82ca)['then'](function(_0x47d076){logger[_0x8c83('0x25')]('OpenchannelAccount,\x20%s,\x20%s',_0x2b4027,_0x8c83('0x26'));logger[_0x8c83('0x27')]('OpenchannelAccount,\x20%s,\x20%s,\x20%s',_0x2b4027,'request\x20sent',JSON[_0x8c83('0x28')](_0x47d076));if(_0x47d076[_0x8c83('0x29')]){if(_0x47d076['error'][_0x8c83('0x2a')]===0x1f4){logger[_0x8c83('0x29')]('OpenchannelAccount,\x20%s,\x20%s',_0x2b4027,_0x47d076[_0x8c83('0x29')]['message']);return _0x40bc0d(_0x47d076[_0x8c83('0x29')][_0x8c83('0x2b')]);}logger[_0x8c83('0x29')](_0x8c83('0x2c'),_0x2b4027,_0x47d076[_0x8c83('0x29')]['message']);return _0x593c97(_0x47d076['error'][_0x8c83('0x2b')]);}else{logger[_0x8c83('0x25')]('OpenchannelAccount,\x20%s,\x20%s',_0x2b4027,'request\x20sent');_0x593c97(_0x47d076[_0x8c83('0x2d')][_0x8c83('0x2b')]);}})[_0x8c83('0x2e')](function(_0x5034e1){logger[_0x8c83('0x29')]('OpenchannelAccount,\x20%s,\x20%s',_0x2b4027,_0x5034e1);_0x40bc0d(_0x5034e1);});});}function respondWithStatusCode(_0x7fb65e,_0xc5d97d){_0xc5d97d=_0xc5d97d||0xcc;return function(_0x29b5d8){if(_0x29b5d8){return _0x7fb65e[_0x8c83('0x2f')](_0xc5d97d);}return _0x7fb65e[_0x8c83('0x30')](_0xc5d97d)['end']();};}function respondWithResult(_0x4d8ff8,_0x4d728e){_0x4d728e=_0x4d728e||0xc8;return function(_0x41d7be){if(_0x41d7be){return _0x4d8ff8[_0x8c83('0x30')](_0x4d728e)['json'](_0x41d7be);}};}function respondWithFilteredResult(_0x106f71,_0x12419a){return function(_0x142201){if(_0x142201){var _0x596ff0=typeof _0x12419a['offset']===_0x8c83('0x31')&&typeof _0x12419a['limit']===_0x8c83('0x31');var _0x126a65=_0x142201[_0x8c83('0x32')];var _0x178056=_0x596ff0?0x0:_0x12419a[_0x8c83('0x33')];var _0x748adb=_0x596ff0?_0x142201['count']:_0x12419a[_0x8c83('0x33')]+_0x12419a[_0x8c83('0x34')];var _0x4c9bca;if(_0x748adb>=_0x126a65){_0x748adb=_0x126a65;_0x4c9bca=0xc8;}else{_0x4c9bca=0xce;}_0x106f71[_0x8c83('0x30')](_0x4c9bca);return _0x106f71[_0x8c83('0x35')](_0x8c83('0x36'),_0x178056+'-'+_0x748adb+'/'+_0x126a65)[_0x8c83('0x37')](_0x142201);}return null;};}function patchUpdates(_0x2d24d8){return function(_0x1ab732){try{jsonpatch[_0x8c83('0x38')](_0x1ab732,_0x2d24d8,!![]);}catch(_0x5aec21){return BPromise[_0x8c83('0x39')](_0x5aec21);}return _0x1ab732[_0x8c83('0x3a')]();};}function saveUpdates(_0x400049,_0x5f416f){return function(_0xd0128){if(_0xd0128){return _0xd0128[_0x8c83('0x3b')](_0x400049)['then'](function(_0xc32a7d){return _0xc32a7d;});}return null;};}function removeEntity(_0x2a5223,_0xfd797d){return function(_0x30cb61){if(_0x30cb61){return _0x30cb61[_0x8c83('0x3c')]()[_0x8c83('0x3d')](function(){var _0xa7663=_0x30cb61[_0x8c83('0x3e')]({'plain':!![]});var _0x2b5b06=_0x8c83('0x3f');return db[_0x8c83('0x40')][_0x8c83('0x3c')]({'where':{'type':_0x2b5b06,'resourceId':_0xa7663['id']}})['then'](function(){return _0x30cb61;});})['then'](function(){_0x2a5223[_0x8c83('0x30')](0xcc)[_0x8c83('0x41')]();});}};}function handleEntityNotFound(_0x1a18fb,_0x154afc){return function(_0x467c6f){if(!_0x467c6f){_0x1a18fb['sendStatus'](0x194);}return _0x467c6f;};}function handleError(_0x571d5f,_0x3a200c){_0x3a200c=_0x3a200c||0x1f4;return function(_0x4347d6){logger[_0x8c83('0x29')](_0x4347d6['stack']);if(_0x4347d6['name']){delete _0x4347d6['name'];}_0x571d5f['status'](_0x3a200c)[_0x8c83('0x42')](_0x4347d6);};}exports[_0x8c83('0x43')]=function(_0xd63a66,_0xbc83f8){var _0x2bc261={'include':[{'model':db[_0x8c83('0x44')],'as':'mandatoryDispositionPause'}]},_0x1b0041={},_0x1e9867={'count':0x0,'rows':[]};var _0x5bfea5=_[_0x8c83('0x45')](db[_0x8c83('0x46')][_0x8c83('0x47')],function(_0x4908b0){return{'name':_0x4908b0[_0x8c83('0x48')],'type':_0x4908b0['type'][_0x8c83('0x49')]};});_0x1b0041[_0x8c83('0x4a')]=_['map'](_0x5bfea5,_0x8c83('0x4b'));_0x1b0041['query']=_['keys'](_0xd63a66['query']);_0x1b0041[_0x8c83('0x4c')]=_[_0x8c83('0x4d')](_0x1b0041[_0x8c83('0x4a')],_0x1b0041[_0x8c83('0x4e')]);_0x2bc261[_0x8c83('0x4f')]=_[_0x8c83('0x4d')](_0x1b0041[_0x8c83('0x4a')],qs['fields'](_0xd63a66['query'][_0x8c83('0x50')]));_0x2bc261[_0x8c83('0x4f')]=_0x2bc261[_0x8c83('0x4f')][_0x8c83('0x51')]?_0x2bc261[_0x8c83('0x4f')]:_0x1b0041[_0x8c83('0x4a')];if(!_0xd63a66[_0x8c83('0x4e')]['hasOwnProperty']('nolimit')){_0x2bc261[_0x8c83('0x34')]=qs[_0x8c83('0x34')](_0xd63a66[_0x8c83('0x4e')][_0x8c83('0x34')]);_0x2bc261[_0x8c83('0x33')]=qs[_0x8c83('0x33')](_0xd63a66[_0x8c83('0x4e')][_0x8c83('0x33')]);}_0x2bc261[_0x8c83('0x52')]=qs[_0x8c83('0x53')](_0xd63a66['query']['sort']);_0x2bc261[_0x8c83('0x54')]=qs[_0x8c83('0x4c')](_[_0x8c83('0x55')](_0xd63a66['query'],_0x1b0041[_0x8c83('0x4c')]),_0x5bfea5);if(_0xd63a66[_0x8c83('0x4e')][_0x8c83('0x56')]){_0x2bc261['where']=_['merge'](_0x2bc261['where'],{'$or':_[_0x8c83('0x45')](_0x5bfea5,function(_0x501eee){if(_0x501eee['type']!==_0x8c83('0x57')){var _0x4f2aea={};_0x4f2aea[_0x501eee[_0x8c83('0x4b')]]={'$like':'%'+_0xd63a66[_0x8c83('0x4e')][_0x8c83('0x56')]+'%'};return _0x4f2aea;}})});}_0x2bc261=_[_0x8c83('0x58')]({},_0x2bc261,_0xd63a66['options']);var _0x5d8f9f={'where':_0x2bc261[_0x8c83('0x54')]};return db[_0x8c83('0x46')][_0x8c83('0x32')](_0x5d8f9f)['then'](function(_0x2900c1){_0x1e9867['count']=_0x2900c1;if(_0xd63a66[_0x8c83('0x4e')][_0x8c83('0x59')]){_0x2bc261[_0x8c83('0x5a')]=[{'all':!![]}];}return db[_0x8c83('0x46')]['findAll'](_0x2bc261);})[_0x8c83('0x3d')](function(_0x5830b5){_0x1e9867['rows']=_0x5830b5;return _0x1e9867;})[_0x8c83('0x3d')](respondWithFilteredResult(_0xbc83f8,_0x2bc261))[_0x8c83('0x2e')](handleError(_0xbc83f8,null));};exports[_0x8c83('0x5b')]=function(_0x3cf250,_0x5548a2){var _0x1a9019={'raw':![],'where':{'id':_0x3cf250[_0x8c83('0x5c')]['id']},'include':[{'model':db[_0x8c83('0x44')],'as':_0x8c83('0x5d')}]},_0x3cb313={};_0x3cb313[_0x8c83('0x4a')]=_[_0x8c83('0x5e')](db[_0x8c83('0x46')]['rawAttributes']);_0x3cb313[_0x8c83('0x4e')]=_['keys'](_0x3cf250[_0x8c83('0x4e')]);_0x3cb313[_0x8c83('0x4c')]=_['intersection'](_0x3cb313['model'],_0x3cb313[_0x8c83('0x4e')]);_0x1a9019[_0x8c83('0x4f')]=_['intersection'](_0x3cb313['model'],qs[_0x8c83('0x50')](_0x3cf250[_0x8c83('0x4e')]['fields']));_0x1a9019[_0x8c83('0x4f')]=_0x1a9019[_0x8c83('0x4f')][_0x8c83('0x51')]?_0x1a9019['attributes']:_0x3cb313[_0x8c83('0x4a')];if(_0x3cf250[_0x8c83('0x4e')][_0x8c83('0x59')]){_0x1a9019['include']=[{'all':!![]}];}_0x1a9019=_[_0x8c83('0x58')]({},_0x1a9019,_0x3cf250[_0x8c83('0x5f')]);return db[_0x8c83('0x46')][_0x8c83('0x60')](_0x1a9019)[_0x8c83('0x3d')](handleEntityNotFound(_0x5548a2,null))[_0x8c83('0x3d')](respondWithResult(_0x5548a2,null))['catch'](handleError(_0x5548a2,null));};exports['create']=function(_0xafe4df,_0xaf3a1e){return db[_0x8c83('0x46')][_0x8c83('0x61')](_0xafe4df[_0x8c83('0x62')],{})[_0x8c83('0x3d')](function(_0x1cda02){var _0x403967=_0xafe4df[_0x8c83('0x63')]['get']({'plain':!![]});if(!_0x403967)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x403967[_0x8c83('0x64')]===_0x8c83('0x63')){var _0x30ff01=_0x1cda02[_0x8c83('0x3e')]({'plain':!![]});var _0x2e7286=_0x8c83('0x3f');return db[_0x8c83('0x65')][_0x8c83('0x60')]({'where':{'name':_0x2e7286,'userProfileId':_0x403967[_0x8c83('0x66')]},'raw':!![]})[_0x8c83('0x3d')](function(_0x5ab5c1){if(_0x5ab5c1&&_0x5ab5c1[_0x8c83('0x67')]===0x0){return db[_0x8c83('0x40')][_0x8c83('0x61')]({'name':_0x30ff01[_0x8c83('0x4b')],'resourceId':_0x30ff01['id'],'type':_0x5ab5c1[_0x8c83('0x4b')],'sectionId':_0x5ab5c1['id']},{})[_0x8c83('0x3d')](function(){return _0x1cda02;});}else{return _0x1cda02;}})[_0x8c83('0x2e')](function(_0x31130c){logger[_0x8c83('0x29')](_0x8c83('0x68'),_0x31130c);throw _0x31130c;});}return _0x1cda02;})['then'](respondWithResult(_0xaf3a1e,0xc9))[_0x8c83('0x2e')](handleError(_0xaf3a1e,null));};exports['update']=function(_0x2270a9,_0x11aa71){if(_0x2270a9[_0x8c83('0x62')]['id']){delete _0x2270a9['body']['id'];}return db[_0x8c83('0x46')][_0x8c83('0x60')]({'where':{'id':_0x2270a9['params']['id']},'include':[{'model':db['Pause'],'as':'mandatoryDispositionPause'}]})[_0x8c83('0x3d')](handleEntityNotFound(_0x11aa71,null))['then'](saveUpdates(_0x2270a9[_0x8c83('0x62')],null))[_0x8c83('0x3d')](respondWithResult(_0x11aa71,null))['catch'](handleError(_0x11aa71,null));};exports['destroy']=function(_0x521666,_0x4b15d9){return db[_0x8c83('0x46')]['find']({'where':{'id':_0x521666['params']['id']}})[_0x8c83('0x3d')](handleEntityNotFound(_0x4b15d9,null))[_0x8c83('0x3d')](removeEntity(_0x4b15d9,null))['catch'](handleError(_0x4b15d9,null));};exports[_0x8c83('0x69')]=function(_0x25ab22,_0x1ee5bf){return db['OpenchannelAccount'][_0x8c83('0x69')]()[_0x8c83('0x3d')](respondWithResult(_0x1ee5bf,null))[_0x8c83('0x2e')](handleError(_0x1ee5bf,null));};exports['addDisposition']=function(_0x20f67e,_0x4d6905,_0x39af25){if(_0x20f67e[_0x8c83('0x62')]['id']){delete _0x20f67e[_0x8c83('0x62')]['id'];}return db[_0x8c83('0x46')]['find']({'where':{'id':_0x20f67e['params']['id']}})[_0x8c83('0x3d')](handleEntityNotFound(_0x4d6905,null))[_0x8c83('0x3d')](function(_0x4169b9){if(_0x4169b9){_0x20f67e['body'][_0x8c83('0x6a')]=_0x4169b9['id'];return db['Disposition'][_0x8c83('0x61')](_0x20f67e[_0x8c83('0x62')]);}})[_0x8c83('0x3d')](respondWithResult(_0x4d6905,null))[_0x8c83('0x2e')](handleError(_0x4d6905,null));};exports[_0x8c83('0x6b')]=function(_0x495248,_0x23f737,_0x3e957b){var _0xed6125={'raw':![],'where':{}};var _0x50b9d0={};var _0x52ce5a={'count':0x0,'rows':[]};return db[_0x8c83('0x46')][_0x8c83('0x6c')]({'where':{'id':_0x495248['params']['id']}})[_0x8c83('0x3d')](handleEntityNotFound(_0x23f737,null))['then'](function(_0x36953b){if(_0x36953b){_0x50b9d0[_0x8c83('0x4a')]=_[_0x8c83('0x5e')](db[_0x8c83('0x6d')]['rawAttributes']);_0x50b9d0['query']=_[_0x8c83('0x5e')](_0x495248['query']);_0x50b9d0[_0x8c83('0x4c')]=_['intersection'](_0x50b9d0['model'],_0x50b9d0[_0x8c83('0x4e')]);_0xed6125[_0x8c83('0x4f')]=_['intersection'](_0x50b9d0['model'],qs[_0x8c83('0x50')](_0x495248[_0x8c83('0x4e')]['fields']));_0xed6125[_0x8c83('0x4f')]=_0xed6125[_0x8c83('0x4f')][_0x8c83('0x51')]?_0xed6125[_0x8c83('0x4f')]:_0x50b9d0[_0x8c83('0x4a')];if(!_0x495248[_0x8c83('0x4e')][_0x8c83('0x6e')](_0x8c83('0x6f'))){_0xed6125[_0x8c83('0x34')]=qs[_0x8c83('0x34')](_0x495248[_0x8c83('0x4e')][_0x8c83('0x34')]);_0xed6125[_0x8c83('0x33')]=qs[_0x8c83('0x33')](_0x495248[_0x8c83('0x4e')][_0x8c83('0x33')]);}_0xed6125[_0x8c83('0x52')]=qs['sort'](_0x495248[_0x8c83('0x4e')]['sort']);_0xed6125[_0x8c83('0x54')]=qs['filters'](_[_0x8c83('0x55')](_0x495248[_0x8c83('0x4e')],_0x50b9d0[_0x8c83('0x4c')]));_0xed6125[_0x8c83('0x54')][_0x8c83('0x6a')]=_0x36953b['id'];if(_0x495248[_0x8c83('0x4e')]['filter']){_0xed6125[_0x8c83('0x54')]=_[_0x8c83('0x58')](_0xed6125['where'],{'$or':_[_0x8c83('0x45')](_0xed6125[_0x8c83('0x4f')],function(_0x4a8ab1){var _0x10fe62={};_0x10fe62[_0x4a8ab1]={'$like':'%'+_0x495248[_0x8c83('0x4e')][_0x8c83('0x56')]+'%'};return _0x10fe62;})});}_0xed6125=_[_0x8c83('0x58')]({},_0xed6125,_0x495248[_0x8c83('0x5f')]);return db[_0x8c83('0x6d')][_0x8c83('0x32')]({'where':_0xed6125['where']})[_0x8c83('0x3d')](function(_0x33b38d){_0x52ce5a[_0x8c83('0x32')]=_0x33b38d;if(_0x495248[_0x8c83('0x4e')][_0x8c83('0x59')]){_0xed6125[_0x8c83('0x5a')]=[{'all':!![]}];}return db['Disposition']['findAll'](_0xed6125);})[_0x8c83('0x3d')](function(_0xee91c7){_0x52ce5a[_0x8c83('0x70')]=_0xee91c7;return _0x52ce5a;});}})[_0x8c83('0x3d')](respondWithFilteredResult(_0x23f737,_0xed6125))['catch'](handleError(_0x23f737,null));};exports[_0x8c83('0x71')]=function(_0x581205,_0x54bc6d,_0x90929){return db[_0x8c83('0x46')][_0x8c83('0x60')]({'where':{'id':_0x581205[_0x8c83('0x5c')]['id']}})[_0x8c83('0x3d')](handleEntityNotFound(_0x54bc6d,null))['then'](function(_0xf0e944){if(_0xf0e944){return _0xf0e944[_0x8c83('0x71')](_0x581205['query']['ids']);}})[_0x8c83('0x3d')](respondWithStatusCode(_0x54bc6d,null))[_0x8c83('0x2e')](handleError(_0x54bc6d,null));};exports['addAnswer']=function(_0x2d0647,_0x47952f,_0xa8daa0){if(_0x2d0647[_0x8c83('0x62')]['id']){delete _0x2d0647['body']['id'];}return db[_0x8c83('0x46')][_0x8c83('0x60')]({'where':{'id':_0x2d0647['params']['id']}})[_0x8c83('0x3d')](handleEntityNotFound(_0x47952f,null))[_0x8c83('0x3d')](function(_0x114126){if(_0x114126){_0x2d0647[_0x8c83('0x62')][_0x8c83('0x6a')]=_0x114126['id'];return db['CannedAnswer']['create'](_0x2d0647[_0x8c83('0x62')]);}})[_0x8c83('0x3d')](respondWithResult(_0x47952f,null))[_0x8c83('0x2e')](handleError(_0x47952f,null));};exports['getAnswers']=function(_0x539895,_0xcceb39,_0xf036e0){var _0x199741={'raw':![],'where':{}};var _0x32302f={};var _0x5a56b5={'count':0x0,'rows':[]};return db[_0x8c83('0x46')][_0x8c83('0x6c')]({'where':{'id':_0x539895[_0x8c83('0x5c')]['id']}})[_0x8c83('0x3d')](handleEntityNotFound(_0xcceb39,null))[_0x8c83('0x3d')](function(_0x4ceb71){if(_0x4ceb71){_0x32302f['model']=_[_0x8c83('0x5e')](db[_0x8c83('0x72')][_0x8c83('0x47')]);_0x32302f[_0x8c83('0x4e')]=_[_0x8c83('0x5e')](_0x539895[_0x8c83('0x4e')]);_0x32302f[_0x8c83('0x4c')]=_[_0x8c83('0x4d')](_0x32302f['model'],_0x32302f[_0x8c83('0x4e')]);_0x199741['attributes']=_[_0x8c83('0x4d')](_0x32302f[_0x8c83('0x4a')],qs[_0x8c83('0x50')](_0x539895[_0x8c83('0x4e')][_0x8c83('0x50')]));_0x199741[_0x8c83('0x4f')]=_0x199741[_0x8c83('0x4f')][_0x8c83('0x51')]?_0x199741['attributes']:_0x32302f[_0x8c83('0x4a')];if(!_0x539895[_0x8c83('0x4e')][_0x8c83('0x6e')](_0x8c83('0x6f'))){_0x199741[_0x8c83('0x34')]=qs[_0x8c83('0x34')](_0x539895[_0x8c83('0x4e')][_0x8c83('0x34')]);_0x199741[_0x8c83('0x33')]=qs[_0x8c83('0x33')](_0x539895[_0x8c83('0x4e')][_0x8c83('0x33')]);}_0x199741[_0x8c83('0x52')]=qs['sort'](_0x539895[_0x8c83('0x4e')][_0x8c83('0x53')]);_0x199741[_0x8c83('0x54')]=qs[_0x8c83('0x4c')](_[_0x8c83('0x55')](_0x539895[_0x8c83('0x4e')],_0x32302f[_0x8c83('0x4c')]));_0x199741[_0x8c83('0x54')][_0x8c83('0x6a')]=_0x4ceb71['id'];if(_0x539895['query']['filter']){_0x199741[_0x8c83('0x54')]=_['merge'](_0x199741[_0x8c83('0x54')],{'$or':_[_0x8c83('0x45')](_0x199741[_0x8c83('0x4f')],function(_0x4614e3){var _0x101bfb={};_0x101bfb[_0x4614e3]={'$like':'%'+_0x539895[_0x8c83('0x4e')][_0x8c83('0x56')]+'%'};return _0x101bfb;})});}_0x199741=_['merge']({},_0x199741,_0x539895[_0x8c83('0x5f')]);return db[_0x8c83('0x72')]['count']({'where':_0x199741[_0x8c83('0x54')]})[_0x8c83('0x3d')](function(_0x2d58b7){_0x5a56b5[_0x8c83('0x32')]=_0x2d58b7;if(_0x539895[_0x8c83('0x4e')]['includeAll']){_0x199741[_0x8c83('0x5a')]=[{'all':!![]}];}return db[_0x8c83('0x72')]['findAll'](_0x199741);})['then'](function(_0x39d0c7){_0x5a56b5[_0x8c83('0x70')]=_0x39d0c7;return _0x5a56b5;});}})['then'](respondWithFilteredResult(_0xcceb39,_0x199741))['catch'](handleError(_0xcceb39,null));};exports[_0x8c83('0x73')]=function(_0x3ddbfe,_0x51bd82,_0x55be5b){return db['OpenchannelAccount'][_0x8c83('0x60')]({'where':{'id':_0x3ddbfe[_0x8c83('0x5c')]['id']}})[_0x8c83('0x3d')](handleEntityNotFound(_0x51bd82,null))['then'](function(_0x3348f9){if(_0x3348f9){return _0x3348f9['removeAnswers'](_0x3ddbfe[_0x8c83('0x4e')][_0x8c83('0x74')]);}})[_0x8c83('0x3d')](respondWithStatusCode(_0x51bd82,null))[_0x8c83('0x2e')](handleError(_0x51bd82,null));};exports[_0x8c83('0x75')]=function(_0x138b90,_0x59ea86,_0x4e87b4){var _0x368f80={'body':_0x138b90[_0x8c83('0x62')],'channel':_0x8c83('0x76')};var _0x131ca1=[];var _0x1b378a=[];var _0xf7375b={};var _0x5078e3=![];return db['CmContact'][_0x8c83('0x69')]()[_0x8c83('0x3d')](function(_0x176be4){if(!_0x176be4){throw new db['Sequelize'][(_0x8c83('0x77'))](_0x8c83('0x78'));}_0x131ca1=_[_0x8c83('0x79')](_[_0x8c83('0x5e')](_0x176be4),[_0x8c83('0x7a'),_0x8c83('0x7b')]);_0x1b378a=_[_0x8c83('0x79')](_[_0x8c83('0x5e')](_0x176be4),['createdAt','updatedAt','CompanyId',_0x8c83('0x7c')]);if(_0x138b90['body']['id']){delete _0x138b90[_0x8c83('0x62')]['id'];}if(_[_0x8c83('0x7d')](_0x138b90[_0x8c83('0x62')][_0x8c83('0x7e')])){throw new db[(_0x8c83('0x7f'))]['ValidationError']('from\x20is\x20mandatory');}if(_['isNil'](_0x138b90[_0x8c83('0x62')][_0x8c83('0x62')])||_0x138b90['body'][_0x8c83('0x62')]===''){throw new db['Sequelize'][(_0x8c83('0x77'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_['isNil'](_0x138b90[_0x8c83('0x62')][_0x8c83('0x80')])){throw new db[(_0x8c83('0x7f'))][(_0x8c83('0x77'))](_0x8c83('0x81')+_0x1b378a);}if(!_['includes'](_0x1b378a,_0x138b90[_0x8c83('0x62')][_0x8c83('0x80')])){throw new db[(_0x8c83('0x7f'))][(_0x8c83('0x77'))](_0x8c83('0x82')+_0x1b378a);}_0xf7375b[_0x138b90[_0x8c83('0x62')][_0x8c83('0x80')]]=_0x138b90[_0x8c83('0x62')][_0x8c83('0x7e')];})['then'](function(){return db[_0x8c83('0x46')][_0x8c83('0x60')]({'where':{'id':_0x138b90[_0x8c83('0x5c')]['id']},'include':[{'model':db[_0x8c83('0x83')],'as':_0x8c83('0x84'),'include':[{'model':db[_0x8c83('0x85')],'as':_0x8c83('0x86'),'where':_0xf7375b,'limit':0x1,'order':[[_0x8c83('0x7b'),_0x8c83('0x87')]]}]},{'model':db[_0x8c83('0x88')],'as':_0x8c83('0x89')}]});})[_0x8c83('0x3d')](handleEntityNotFound(_0x59ea86,null))[_0x8c83('0x3d')](function(_0xec1da0){if(_0xec1da0&&_0xec1da0[_0x8c83('0x84')]){_0x368f80[_0x8c83('0x8a')]=_0xec1da0;_0x368f80[_0x8c83('0x8b')]=_0xec1da0['Applications'];_0x368f80[_0x8c83('0x8c')]=_0xec1da0['List'];_0x368f80[_0x8c83('0x8b')]=_[_0x8c83('0x8d')](_0x368f80[_0x8c83('0x8b')],[_0x8c83('0x8e')],[_0x8c83('0x8f')]);if(_0x368f80['account']['Applications']){delete _0x368f80['account']['Applications'];}if(_0x368f80[_0x8c83('0x8a')][_0x8c83('0x84')]&&_0x368f80[_0x8c83('0x8a')][_0x8c83('0x84')][_0x8c83('0x86')][_0x8c83('0x51')]){return _0x368f80[_0x8c83('0x8a')][_0x8c83('0x84')][_0x8c83('0x86')][0x0];}var _0x4e352b=_[_0x8c83('0x1b')](_0x138b90['body'],{'firstName':_0x138b90[_0x8c83('0x62')][_0x8c83('0x7e')],'ListId':_0xec1da0[_0x8c83('0x7c')]});_0x4e352b[_0x138b90[_0x8c83('0x62')][_0x8c83('0x80')]]=_0x138b90[_0x8c83('0x62')][_0x8c83('0x7e')];return db[_0x8c83('0x85')][_0x8c83('0x61')](_0x4e352b,{'fields':_0x131ca1,'raw':!![]});}})[_0x8c83('0x3d')](handleEntityNotFound(_0x59ea86,null))[_0x8c83('0x3d')](function(_0x57e4d5){_0x368f80[_0x8c83('0x90')]=_0x57e4d5;if(_0x57e4d5){var _0x391309={'ContactId':_0x57e4d5['id'],'OpenchannelAccountId':_0x138b90[_0x8c83('0x5c')]['id'],'from':(_0x57e4d5['firstName']||'')+'\x20'+(_0x57e4d5[_0x8c83('0x91')]||'')};var _0x208ebd={'OpenchannelAccountId':_0x138b90[_0x8c83('0x5c')]['id'],'closed':![]};if(_0x138b90[_0x8c83('0x62')][_0x8c83('0x92')]){_0x208ebd[_0x8c83('0x92')]=_0x138b90[_0x8c83('0x62')]['threadId'];return db[_0x8c83('0x93')][_0x8c83('0x60')]({'where':_0x208ebd})[_0x8c83('0x3d')](function(_0x246715){if(_0x246715){return[_0x246715,![]];}_0x391309[_0x8c83('0x92')]=_0x138b90[_0x8c83('0x62')][_0x8c83('0x92')];_0x391309['externalUrl']=_0x138b90['body'][_0x8c83('0x94')];return db['OpenchannelInteraction']['create'](_0x391309)[_0x8c83('0x3d')](function(_0x4490e6){return[_0x4490e6,!![]];});});}else{_0x208ebd[_0x8c83('0x92')]=null;}_0x208ebd[_0x8c83('0x95')]=_0x57e4d5['id'];return db[_0x8c83('0x93')][_0x8c83('0x60')]({'where':_0x208ebd})[_0x8c83('0x3d')](function(_0x3d76ac){if(_0x3d76ac){return[_0x3d76ac,![]];}return db[_0x8c83('0x93')][_0x8c83('0x61')](_0x391309)[_0x8c83('0x3d')](function(_0x462333){return[_0x462333,!![]];});});}})['spread'](function(_0x330d16,_0xfd2fff){if(_0x330d16){_0x5078e3=_0xfd2fff;if(!_0xfd2fff){var _0x21cc3c={'from':(_0x368f80['contact'][_0x8c83('0x96')]||'')+'\x20'+(_0x368f80[_0x8c83('0x90')][_0x8c83('0x91')]||'')};if(_0x138b90[_0x8c83('0x62')][_0x8c83('0x92')]&&_0x138b90[_0x8c83('0x62')][_0x8c83('0x97')]&&_0x138b90['body'][_0x8c83('0x92')]!=_0x138b90[_0x8c83('0x62')]['messageId']){_0x21cc3c[_0x8c83('0x92')]=_0x138b90[_0x8c83('0x62')][_0x8c83('0x97')];}return _0x330d16[_0x8c83('0x3b')](_0x21cc3c);}else{return _0x330d16;}}})[_0x8c83('0x3d')](function(_0x257f48){_0x368f80[_0x8c83('0x98')]=_0x257f48[_0x8c83('0x3e')]({'plain':!![]});_0x368f80[_0x8c83('0x98')][_0x8c83('0x99')]=_0x5078e3;if(_0x368f80[_0x8c83('0x98')][_0x8c83('0x99')]){if(_0x368f80['account'][_0x8c83('0x9a')]){_0x368f80[_0x8c83('0x8b')][_0x8c83('0x9b')]({'id':0x0,'priority':_0x368f80['applications'][_0x8c83('0x51')]+0x1,'app':_0x8c83('0x9c'),'appdata':'unmanaged','interval':_0x8c83('0x9d')});}}return db['OpenchannelMessage'][_0x8c83('0x61')]({'body':_0x138b90[_0x8c83('0x62')][_0x8c83('0x62')],'OpenchannelAccountId':_0x138b90[_0x8c83('0x5c')]['id'],'OpenchannelInteractionId':_0x257f48['id'],'direction':'in','ContactId':_0x368f80['contact']['id'],'AttachmentId':_0x138b90[_0x8c83('0x62')]['AttachmentId']});})[_0x8c83('0x3d')](function(_0x993100){_0x368f80['message']=_0x993100;if(!_0x368f80[_0x8c83('0x98')]['UserId'])return;return db['User'][_0x8c83('0x60')]({'attributes':['id',_0x8c83('0x4b')],'where':{'id':_0x368f80[_0x8c83('0x98')][_0x8c83('0x9e')]}});})[_0x8c83('0x3d')](function(_0x3fad7d){if(_0x3fad7d){_0x368f80[_0x8c83('0x8b')]['unshift']({'id':0x0,'priority':0x0,'app':_0x8c83('0x9f'),'appdata':_0x3fad7d[_0x8c83('0x4b')]+','+(_0x368f80[_0x8c83('0x8a')]['waitForTheAssignedAgent']||0xa),'interval':_0x8c83('0x9d')});}if(!_0x368f80[_0x8c83('0x98')][_0x8c83('0xa0')])return;return db[_0x8c83('0xa1')]['find']({'attributes':['id',_0x8c83('0x4b')],'where':{'id':_0x368f80['interaction'][_0x8c83('0xa0')]}});})['then'](function(_0x54096e){if(_0x54096e){_0x368f80[_0x8c83('0x8b')][_0x8c83('0xa2')]({'id':0x0,'priority':0x1,'app':_0x8c83('0xa3'),'appdata':_0x54096e[_0x8c83('0x4b')]+','+(_0x368f80[_0x8c83('0x8a')][_0x8c83('0xa4')]||0x12c),'interval':'*,*,*,*'});}return respondWithRpcPromise(_0x8c83('0xa5'),'startRouting',_0x368f80);})[_0x8c83('0x3d')](function(_0x1d04ec){respondWithRpcPromise('EventManager',_0x8c83('0xa6'),{'event':_0x8c83('0x75'),'message':_0x1d04ec},client9002);return _0x1d04ec;})[_0x8c83('0x3d')](respondWithResult(_0x59ea86,null))['catch'](handleError(_0x59ea86,null));};exports[_0x8c83('0xa7')]=function(_0x57c720,_0x25829f){var _0x7e5ee8=_0x57c720['params']['id'];var _0xa39425=_0x57c720[_0x8c83('0x62')];var _0x59f2d0=0xc8;var _0x3ab85d=null;return db[_0x8c83('0xa8')]['transaction']({'isolationLevel':db[_0x8c83('0xa8')][_0x8c83('0xa9')][_0x8c83('0xaa')][_0x8c83('0xab')]},function(_0xd6f94a){return db['OpenchannelAccount'][_0x8c83('0x6c')]({'where':{'id':_0x7e5ee8},'transaction':_0xd6f94a})[_0x8c83('0x3d')](function(_0x42c353){if(_0x42c353){return db['OpenchannelApplication']['destroy']({'where':{'OpenchannelAccountId':_0x7e5ee8},'transaction':_0xd6f94a})[_0x8c83('0x3d')](function(){var _0x4196f9=_['map'](_0xa39425,function(_0x3d0dbb){_0x3d0dbb['OpenchannelAccountId']=_0x7e5ee8;return _0x3d0dbb;});return db[_0x8c83('0x88')][_0x8c83('0xac')](_0x4196f9,{'transaction':_0xd6f94a});});}else{_0x59f2d0=0x194;_0x3ab85d=[];}});})['then'](function(){if(_0x59f2d0!==0x194){return db[_0x8c83('0x88')][_0x8c83('0xad')]({'where':{'OpenchannelAccountId':_0x7e5ee8},'order':'priority'})['then'](function(_0x39512a){_0x3ab85d=_0x39512a;});}})[_0x8c83('0x2e')](function(_0x51397b){_0x59f2d0=0x1f4;logger['error'](_0x51397b[_0x8c83('0xae')]);if(_0x51397b[_0x8c83('0x4b')]){delete _0x51397b[_0x8c83('0x4b')];}_0x3ab85d=_0x51397b;})[_0x8c83('0xaf')](function(){if(_0x3ab85d===null){_0x25829f[_0x8c83('0x2f')](_0x59f2d0);}else{if(_0x59f2d0===0x1f4){_0x25829f[_0x8c83('0x30')](_0x59f2d0)['send'](_0x3ab85d);}else{_0x25829f['status'](_0x59f2d0)['json'](_0x3ab85d);}}});};exports['getApplications']=function(_0x8b1958,_0x4cec20,_0x25e87c){var _0xcc9fca={};var _0x4b1a3c={};var _0x5a352f;var _0x369cc8;return db['OpenchannelAccount'][_0x8c83('0x6c')]({'where':{'id':_0x8b1958[_0x8c83('0x5c')]['id']}})[_0x8c83('0x3d')](handleEntityNotFound(_0x4cec20,null))[_0x8c83('0x3d')](function(_0x3f6eeb){if(_0x3f6eeb){_0x5a352f=_0x3f6eeb;_0x4b1a3c['model']=_[_0x8c83('0x5e')](db['OpenchannelApplication']['rawAttributes']);_0x4b1a3c[_0x8c83('0x4e')]=_[_0x8c83('0x5e')](_0x8b1958[_0x8c83('0x4e')]);_0x4b1a3c[_0x8c83('0x4c')]=_[_0x8c83('0x4d')](_0x4b1a3c[_0x8c83('0x4a')],_0x4b1a3c[_0x8c83('0x4e')]);_0xcc9fca[_0x8c83('0x4f')]=_[_0x8c83('0x4d')](_0x4b1a3c[_0x8c83('0x4a')],qs[_0x8c83('0x50')](_0x8b1958[_0x8c83('0x4e')][_0x8c83('0x50')]));_0xcc9fca[_0x8c83('0x4f')]=_0xcc9fca[_0x8c83('0x4f')]['length']?_0xcc9fca['attributes']:_0x4b1a3c[_0x8c83('0x4a')];_0xcc9fca['order']=qs[_0x8c83('0x53')](_0x8b1958['query'][_0x8c83('0x53')]);_0xcc9fca[_0x8c83('0x54')]=qs['filters'](_[_0x8c83('0x55')](_0x8b1958[_0x8c83('0x4e')],_0x4b1a3c['filters']));if(_0x8b1958[_0x8c83('0x4e')]['filter']){_0xcc9fca[_0x8c83('0x54')]=_[_0x8c83('0x58')](_0xcc9fca[_0x8c83('0x54')],{'$or':_[_0x8c83('0x45')](_0xcc9fca['attributes'],function(_0x48d860){var _0x50733b={};_0x50733b[_0x48d860]={'$like':'%'+_0x8b1958[_0x8c83('0x4e')][_0x8c83('0x56')]+'%'};return _0x50733b;})});}_0xcc9fca=_[_0x8c83('0x58')]({},_0xcc9fca,_0x8b1958[_0x8c83('0x5f')]);return _0x5a352f[_0x8c83('0xb0')](_0xcc9fca);}})[_0x8c83('0x3d')](function(_0x51b036){if(_0x51b036){_0x369cc8=_0x51b036['length'];if(!_0x8b1958[_0x8c83('0x4e')][_0x8c83('0x6e')](_0x8c83('0x6f'))){_0xcc9fca['limit']=qs[_0x8c83('0x34')](_0x8b1958[_0x8c83('0x4e')][_0x8c83('0x34')]);_0xcc9fca[_0x8c83('0x33')]=qs['offset'](_0x8b1958[_0x8c83('0x4e')][_0x8c83('0x33')]);}return _0x5a352f[_0x8c83('0xb0')](_0xcc9fca);}})[_0x8c83('0x3d')](function(_0x1ef23d){if(_0x1ef23d){return _0x1ef23d?{'count':_0x369cc8,'rows':_0x1ef23d}:null;}})[_0x8c83('0x3d')](respondWithResult(_0x4cec20,null))[_0x8c83('0x2e')](handleError(_0x4cec20,null));};exports[_0x8c83('0xb1')]=function(_0x31f6c1,_0x66f85d,_0x5205ef){var _0x9c508c={'raw':![],'where':{}};var _0x282764={};var _0x57e34b={'count':0x0,'rows':[]};return db[_0x8c83('0x46')][_0x8c83('0x6c')]({'where':{'id':_0x31f6c1['params']['id']}})['then'](handleEntityNotFound(_0x66f85d,null))[_0x8c83('0x3d')](function(_0x50351f){if(_0x50351f){_0x282764[_0x8c83('0x4a')]=_[_0x8c83('0x5e')](db['OpenchannelInteraction'][_0x8c83('0x47')]);_0x282764['query']=_['keys'](_0x31f6c1['query']);_0x282764[_0x8c83('0x4c')]=_[_0x8c83('0x4d')](_0x282764['model'],_0x282764[_0x8c83('0x4e')]);_0x9c508c[_0x8c83('0x4f')]=_[_0x8c83('0x4d')](_0x282764[_0x8c83('0x4a')],qs[_0x8c83('0x50')](_0x31f6c1[_0x8c83('0x4e')]['fields']));_0x9c508c[_0x8c83('0x4f')]=_0x9c508c[_0x8c83('0x4f')]['length']?_0x9c508c[_0x8c83('0x4f')]:_0x282764[_0x8c83('0x4a')];if(!_0x31f6c1[_0x8c83('0x4e')][_0x8c83('0x6e')]('nolimit')){_0x9c508c[_0x8c83('0x34')]=qs['limit'](_0x31f6c1[_0x8c83('0x4e')]['limit']);_0x9c508c[_0x8c83('0x33')]=qs[_0x8c83('0x33')](_0x31f6c1['query'][_0x8c83('0x33')]);}_0x9c508c[_0x8c83('0x52')]=qs[_0x8c83('0x53')](_0x31f6c1[_0x8c83('0x4e')][_0x8c83('0x53')]);_0x9c508c[_0x8c83('0x54')]=qs['filters'](_[_0x8c83('0x55')](_0x31f6c1[_0x8c83('0x4e')],_0x282764[_0x8c83('0x4c')]));_0x9c508c[_0x8c83('0x54')][_0x8c83('0x6a')]=_0x50351f['id'];if(_0x31f6c1[_0x8c83('0x4e')][_0x8c83('0x56')]){_0x9c508c[_0x8c83('0x54')]=_['merge'](_0x9c508c[_0x8c83('0x54')],{'$or':_['map'](_0x9c508c[_0x8c83('0x4f')],function(_0x558713){var _0x2664f8={};_0x2664f8[_0x558713]={'$like':'%'+_0x31f6c1[_0x8c83('0x4e')][_0x8c83('0x56')]+'%'};return _0x2664f8;})});}_0x9c508c=_['merge']({},_0x9c508c,_0x31f6c1[_0x8c83('0x5f')]);return db[_0x8c83('0x93')][_0x8c83('0x32')]({'where':_0x9c508c[_0x8c83('0x54')]})[_0x8c83('0x3d')](function(_0x400b46){_0x57e34b[_0x8c83('0x32')]=_0x400b46;if(_0x31f6c1['query'][_0x8c83('0x59')]){_0x9c508c[_0x8c83('0x5a')]=[{'model':db[_0x8c83('0x85')],'as':_0x8c83('0xb2'),'required':![]},{'model':db[_0x8c83('0xb3')],'as':_0x8c83('0xb4'),'attributes':[_0x8c83('0x4b'),_0x8c83('0xb5'),_0x8c83('0xb6')],'required':![]},{'model':db[_0x8c83('0xb7')],'as':_0x8c83('0xb8'),'attributes':['id',_0x8c83('0x4b'),'color'],'where':_0x31f6c1[_0x8c83('0x4e')][_0x8c83('0xb9')]?{'id':_0x31f6c1[_0x8c83('0x4e')][_0x8c83('0xb9')]}:undefined,'required':_0x31f6c1[_0x8c83('0x4e')][_0x8c83('0xb9')]?!![]:![]}];}return db[_0x8c83('0x93')][_0x8c83('0xba')](_0x9c508c);})['then'](function(_0x1e3958){_0x57e34b['rows']=_0x1e3958;return _0x57e34b;});}})[_0x8c83('0x3d')](respondWithFilteredResult(_0x66f85d,_0x9c508c))['catch'](handleError(_0x66f85d,null));};exports[_0x8c83('0xbb')]=function(_0x2b0218,_0x2b6195,_0x2c17a3){return db[_0x8c83('0x46')]['find']({'where':{'id':_0x2b0218[_0x8c83('0x5c')]['id']}})['then'](handleEntityNotFound(_0x2b6195,null))[_0x8c83('0x3d')](function(_0x2d7847){if(_0x2d7847){return _0x2d7847[_0x8c83('0xbb')](_0x2b0218[_0x8c83('0x62')][_0x8c83('0x74')],_[_0x8c83('0xbc')](_0x2b0218['body'],[_0x8c83('0x74'),'id'])||{})[_0x8c83('0xbd')](function(_0x3e7e54){for(var _0x13d39f=0x0;_0x13d39f<_0x2b0218[_0x8c83('0x62')]['ids'][_0x8c83('0x51')];_0x13d39f+=0x1){socket['emit'](_0x8c83('0xbe'),{'UserId':Number(_0x2b0218[_0x8c83('0x62')][_0x8c83('0x74')][_0x13d39f]),'OpenchannelAccountId':Number(_0x2b0218['params']['id'])});}return _0x3e7e54;});}})[_0x8c83('0x3d')](respondWithResult(_0x2b6195,null))[_0x8c83('0x2e')](handleError(_0x2b6195,null));};exports[_0x8c83('0xbf')]=function(_0x4ecadb,_0x2a9993,_0x6fddd7){return db[_0x8c83('0x46')][_0x8c83('0x60')]({'where':{'id':_0x4ecadb[_0x8c83('0x5c')]['id']}})['then'](handleEntityNotFound(_0x2a9993,null))[_0x8c83('0x3d')](function(_0x228219){if(_0x228219){return _0x228219[_0x8c83('0xbf')](_0x4ecadb['query'][_0x8c83('0x74')])[_0x8c83('0x3d')](function(){if(_[_0x8c83('0xc0')](_0x4ecadb[_0x8c83('0x4e')][_0x8c83('0x74')])){for(var _0x5c3ad7=0x0;_0x5c3ad7<_0x4ecadb['query'][_0x8c83('0x74')][_0x8c83('0x51')];_0x5c3ad7+=0x1){socket[_0x8c83('0xc1')](_0x8c83('0xc2'),{'UserId':Number(_0x4ecadb['query'][_0x8c83('0x74')][_0x5c3ad7]),'OpenchannelAccountId':Number(_0x4ecadb[_0x8c83('0x5c')]['id'])});}}else{socket[_0x8c83('0xc1')]('userOpenchannelAccount:remove',{'UserId':Number(_0x4ecadb[_0x8c83('0x4e')][_0x8c83('0x74')]),'OpenchannelAccountId':Number(_0x4ecadb[_0x8c83('0x5c')]['id'])});}});}})[_0x8c83('0x3d')](respondWithStatusCode(_0x2a9993,null))[_0x8c83('0x2e')](handleError(_0x2a9993,null));};exports[_0x8c83('0xc3')]=function(_0x4ff407,_0x360558,_0x397455){var _0x183db1={};var _0x39ee93={};var _0x113e27;var _0x2c28eb;return db['OpenchannelAccount'][_0x8c83('0x6c')]({'where':{'id':_0x4ff407['params']['id']}})[_0x8c83('0x3d')](handleEntityNotFound(_0x360558,null))[_0x8c83('0x3d')](function(_0x3f2ffb){if(_0x3f2ffb){_0x113e27=_0x3f2ffb;_0x39ee93[_0x8c83('0x4a')]=_[_0x8c83('0x5e')](db[_0x8c83('0xb3')][_0x8c83('0x47')]);_0x39ee93['query']=_[_0x8c83('0x5e')](_0x4ff407['query']);_0x39ee93[_0x8c83('0x4c')]=_[_0x8c83('0x4d')](_0x39ee93[_0x8c83('0x4a')],_0x39ee93[_0x8c83('0x4e')]);_0x183db1[_0x8c83('0x4f')]=_[_0x8c83('0x4d')](_0x39ee93[_0x8c83('0x4a')],qs[_0x8c83('0x50')](_0x4ff407[_0x8c83('0x4e')]['fields']));_0x183db1[_0x8c83('0x4f')]=_0x183db1[_0x8c83('0x4f')][_0x8c83('0x51')]?_0x183db1[_0x8c83('0x4f')]:_0x39ee93[_0x8c83('0x4a')];_0x183db1['order']=qs[_0x8c83('0x53')](_0x4ff407[_0x8c83('0x4e')][_0x8c83('0x53')]);_0x183db1[_0x8c83('0x54')]=qs['filters'](_[_0x8c83('0x55')](_0x4ff407[_0x8c83('0x4e')],_0x39ee93[_0x8c83('0x4c')]));if(_0x4ff407[_0x8c83('0x4e')][_0x8c83('0x56')]){_0x183db1[_0x8c83('0x54')]=_[_0x8c83('0x58')](_0x183db1['where'],{'$or':_[_0x8c83('0x45')](_0x183db1['attributes'],function(_0x16f7a7){var _0x1f28eb={};_0x1f28eb[_0x16f7a7]={'$like':'%'+_0x4ff407[_0x8c83('0x4e')]['filter']+'%'};return _0x1f28eb;})});}_0x183db1=_[_0x8c83('0x58')]({},_0x183db1,_0x4ff407['options']);return _0x113e27[_0x8c83('0xc3')](_0x183db1);}})[_0x8c83('0x3d')](function(_0xe97b83){if(_0xe97b83){_0x2c28eb=_0xe97b83[_0x8c83('0x51')];if(!_0x4ff407[_0x8c83('0x4e')]['hasOwnProperty'](_0x8c83('0x6f'))){_0x183db1[_0x8c83('0x34')]=qs[_0x8c83('0x34')](_0x4ff407[_0x8c83('0x4e')][_0x8c83('0x34')]);_0x183db1['offset']=qs[_0x8c83('0x33')](_0x4ff407[_0x8c83('0x4e')][_0x8c83('0x33')]);}return _0x113e27[_0x8c83('0xc3')](_0x183db1);}})[_0x8c83('0x3d')](function(_0x2b9927){if(_0x2b9927){return _0x2b9927?{'count':_0x2c28eb,'rows':_0x2b9927}:null;}})[_0x8c83('0x3d')](respondWithResult(_0x360558,null))[_0x8c83('0x2e')](handleError(_0x360558,null));};exports[_0x8c83('0x42')]=function(_0xc8b063,_0x5e71ad,_0x3a8a03){var _0x4652f5,_0x3e9189,_0x2cd77f;if(_[_0x8c83('0x7d')](_0xc8b063[_0x8c83('0x62')][_0x8c83('0x62')])||_0xc8b063['body']['body']===''){throw new db[(_0x8c83('0x7f'))][(_0x8c83('0x77'))](_0x8c83('0xc4'));}if(_[_0x8c83('0x7d')](_0xc8b063[_0x8c83('0x62')]['to'])){}_0x4652f5=_0xc8b063[_0x8c83('0x62')]['to'];return db[_0x8c83('0x46')][_0x8c83('0x6c')]({'where':{'id':_0xc8b063['params']['id']}})[_0x8c83('0x3d')](handleEntityNotFound(_0x5e71ad,null))[_0x8c83('0x3d')](function(_0xc42b49){if(_0xc42b49){return db[_0x8c83('0x46')]['find']({'where':{'id':_0xc42b49['id']},'include':[{'model':db['CmList'],'as':'List','include':[{'model':db[_0x8c83('0x85')],'as':'Contacts','where':{[_0xc42b49[_0x8c83('0x80')]]:_0x4652f5},'limit':0x1,'order':[[_0x8c83('0x7b'),'DESC']]}]}]})[_0x8c83('0x3d')](handleEntityNotFound(_0x5e71ad,null))[_0x8c83('0x3d')](function(_0x4d6729){if(_0x4d6729&&_0x4d6729[_0x8c83('0x84')]){_0x3e9189=_0x4d6729[_0x8c83('0x3e')]({'plain':!![]});if(_0x3e9189[_0x8c83('0x84')]&&_0x3e9189['List'][_0x8c83('0x86')][_0x8c83('0x51')]){return _0x3e9189['List'][_0x8c83('0x86')][0x0];}return db[_0x8c83('0x85')][_0x8c83('0x61')](_['defaults'](_0xc8b063[_0x8c83('0x62')],{'firstName':_0x4652f5,[_0x4d6729[_0x8c83('0x80')]]:_0x4652f5,'phone':_0x4652f5,'ListId':_0x3e9189['ListId']}));}})[_0x8c83('0x3d')](handleEntityNotFound(_0x5e71ad,null))['then'](function(_0x44afa5){if(_0x44afa5){_0x2cd77f=_0x44afa5;return db['OpenchannelInteraction'][_0x8c83('0x60')]({'where':{'ContactId':_0x2cd77f['id'],'closed':![],'OpenchannelAccountId':_0x3e9189['id']}})[_0x8c83('0x3d')](function(_0x1c6c83){if(_0x1c6c83){return[_0x1c6c83,![]];}return db[_0x8c83('0x93')][_0x8c83('0x61')]({'UserId':_0xc8b063[_0x8c83('0x63')]['id'],'ContactId':_0x2cd77f['id'],'OpenchannelAccountId':_0x3e9189['id'],'lastMsgDirection':_0x8c83('0xc5'),'firstMsgDirection':'out','Messages':[_[_0x8c83('0x58')](_0xc8b063[_0x8c83('0x62')],{'read':![],'body':_0xc8b063[_0x8c83('0x62')][_0x8c83('0x62')],'OpenchannelAccountId':_0x3e9189['id'],'UserId':_0xc8b063[_0x8c83('0x63')]['id'],'ContactId':_0x2cd77f['id']})]},{'include':[{'model':db['OpenchannelMessage'],'as':_0x8c83('0xc6')}]})[_0x8c83('0x3d')](function(_0x324195){return[_0x324195,!![]];});});}})['spread'](function(_0x4b7ca9,_0x26395b){if(_0x26395b){return _0x4b7ca9;}return db['OpenchannelMessage'][_0x8c83('0x61')](_[_0x8c83('0x58')](_0xc8b063['body'],{'read':![],'body':_0xc8b063['body'][_0x8c83('0x62')],'OpenchannelAccountId':_0x3e9189['id'],'OpenchannelInteractionId':_0x4b7ca9['id'],'UserId':_0xc8b063['user']['id'],'ContactId':_0x2cd77f['id']}))['then'](function(_0x5002b5){_0x4b7ca9[_0x8c83('0xc7')][_0x8c83('0xc6')]=[];_0x4b7ca9[_0x8c83('0xc7')][_0x8c83('0xc6')][_0x8c83('0x9b')](_0x5002b5[_0x8c83('0xc7')]);return _0x4b7ca9;});});}})[_0x8c83('0x3d')](respondWithResult(_0x5e71ad,null))[_0x8c83('0x2e')](handleError(_0x5e71ad,null));};
\ No newline at end of file
+var _0xff22=['*,*,*,*','OpenchannelMessage','AttachmentId','UserId','User','unshift','OpenchannelQueue','queueId','queue','waitForTheAssignedQueue','Start','EventManager','sequelize','transaction','Transaction','READ_COMMITTED','bulkCreate','findAndCountAll','finally','getApplications','getInteractions','Contact','Owner','fullname','Tag','Tags','color','tag','addAgents','emit','userOpenchannelAccount:save','removeAgents','isArray','userOpenchannelAccount:remove','getAgents','out','dataValues','Messages','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','socket.io-emitter','./openchannelAccount.socket','register','jayson/promise','client','then','info','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','debug','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','message','result','sendStatus','status','end','offset','undefined','limit','count','json','apply','reject','update','destroy','get','OpenchannelAccounts','stack','name','send','index','Pause','map','OpenchannelAccount','rawAttributes','fieldName','type','model','query','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','where','filters','filter','merge','VIRTUAL','options','includeAll','include','findAll','catch','show','params','mandatoryDispositionPause','keys','length','create','body','user','role','UserProfileSection','find','autoAssociation','UserProfileResource','describe','OpenchannelAccountId','Disposition','getDispositions','pick','removeDispositions','ids','CannedAnswer','findOne','rows','removeAnswers','notify','Sequelize','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','ListId','isNil','from','ValidationError','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','List','Contacts','DESC','OpenchannelApplication','Applications','applications','list','orderBy','priority','asc','account','CmContact','firstName','lastName','threadId','OpenchannelInteraction','externalUrl','ContactId','spread','contact','messageId','interaction','created','push','close'];(function(_0x45cb28,_0x583de8){var _0x14b612=function(_0x145aa8){while(--_0x145aa8){_0x45cb28['push'](_0x45cb28['shift']());}};_0x14b612(++_0x583de8);}(_0xff22,0x1a0));var _0x2ff2=function(_0x580b3f,_0x1868fa){_0x580b3f=_0x580b3f-0x0;var _0x659700=_0xff22[_0x580b3f];return _0x659700;};'use strict';var emlformat=require(_0x2ff2('0x0'));var rimraf=require(_0x2ff2('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x2ff2('0x2'));var rp=require(_0x2ff2('0x3'));var moment=require(_0x2ff2('0x4'));var BPromise=require(_0x2ff2('0x5'));var Mustache=require(_0x2ff2('0x6'));var util=require(_0x2ff2('0x7'));var path=require(_0x2ff2('0x8'));var sox=require(_0x2ff2('0x9'));var csv=require(_0x2ff2('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x2ff2('0xb'));var _=require(_0x2ff2('0xc'));var squel=require(_0x2ff2('0xd'));var crypto=require(_0x2ff2('0xe'));var jsforce=require(_0x2ff2('0xf'));var deskjs=require(_0x2ff2('0x10'));var toCsv=require(_0x2ff2('0xa'));var querystring=require('querystring');var Papa=require(_0x2ff2('0x11'));var Redis=require(_0x2ff2('0x12'));var authService=require(_0x2ff2('0x13'));var qs=require(_0x2ff2('0x14'));var as=require(_0x2ff2('0x15'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0x2ff2('0x16'));var config=require(_0x2ff2('0x17'));var licenseUtil=require(_0x2ff2('0x18'));var db=require(_0x2ff2('0x19'))['db'];config[_0x2ff2('0x1a')]=_[_0x2ff2('0x1b')](config[_0x2ff2('0x1a')],{'host':'localhost','port':0x18eb});var socket=require(_0x2ff2('0x1c'))(new Redis(config[_0x2ff2('0x1a')]));require(_0x2ff2('0x1d'))[_0x2ff2('0x1e')](socket);var jayson=require(_0x2ff2('0x1f'));var client=jayson['client']['http']({'port':0x232c});var client9002=jayson[_0x2ff2('0x20')]['http']({'port':0x232a});function respondWithRpcPromise(_0x401f66,_0x383aba,_0x1a7adb,_0x45dc41){return new BPromise(function(_0x15c2af,_0x2f2476){var _0xca38d7=_0x45dc41||client;return _0xca38d7['request'](_0x401f66,_0x1a7adb)[_0x2ff2('0x21')](function(_0x598e53){logger[_0x2ff2('0x22')](_0x2ff2('0x23'),_0x383aba,_0x2ff2('0x24'));logger[_0x2ff2('0x25')](_0x2ff2('0x26'),_0x383aba,_0x2ff2('0x24'),JSON[_0x2ff2('0x27')](_0x598e53));if(_0x598e53[_0x2ff2('0x28')]){if(_0x598e53[_0x2ff2('0x28')]['code']===0x1f4){logger['error']('OpenchannelAccount,\x20%s,\x20%s',_0x383aba,_0x598e53['error'][_0x2ff2('0x29')]);return _0x2f2476(_0x598e53['error'][_0x2ff2('0x29')]);}logger['error'](_0x2ff2('0x23'),_0x383aba,_0x598e53['error']['message']);return _0x15c2af(_0x598e53[_0x2ff2('0x28')][_0x2ff2('0x29')]);}else{logger[_0x2ff2('0x22')](_0x2ff2('0x23'),_0x383aba,_0x2ff2('0x24'));_0x15c2af(_0x598e53[_0x2ff2('0x2a')]['message']);}})['catch'](function(_0x26e395){logger[_0x2ff2('0x28')]('OpenchannelAccount,\x20%s,\x20%s',_0x383aba,_0x26e395);_0x2f2476(_0x26e395);});});}function respondWithStatusCode(_0x2d6b12,_0x9efdcd){_0x9efdcd=_0x9efdcd||0xcc;return function(_0x248742){if(_0x248742){return _0x2d6b12[_0x2ff2('0x2b')](_0x9efdcd);}return _0x2d6b12[_0x2ff2('0x2c')](_0x9efdcd)[_0x2ff2('0x2d')]();};}function respondWithResult(_0x126b80,_0x8cdbb7){_0x8cdbb7=_0x8cdbb7||0xc8;return function(_0x5e3dec){if(_0x5e3dec){return _0x126b80[_0x2ff2('0x2c')](_0x8cdbb7)['json'](_0x5e3dec);}};}function respondWithFilteredResult(_0x1e1957,_0x49b954){return function(_0x354dff){if(_0x354dff){var _0x4e33e0=typeof _0x49b954[_0x2ff2('0x2e')]===_0x2ff2('0x2f')&&typeof _0x49b954[_0x2ff2('0x30')]===_0x2ff2('0x2f');var _0x116f9d=_0x354dff[_0x2ff2('0x31')];var _0x5f0e29=_0x4e33e0?0x0:_0x49b954[_0x2ff2('0x2e')];var _0x4d9af9=_0x4e33e0?_0x354dff['count']:_0x49b954['offset']+_0x49b954[_0x2ff2('0x30')];var _0x4b4995;if(_0x4d9af9>=_0x116f9d){_0x4d9af9=_0x116f9d;_0x4b4995=0xc8;}else{_0x4b4995=0xce;}_0x1e1957[_0x2ff2('0x2c')](_0x4b4995);return _0x1e1957['set']('Content-Range',_0x5f0e29+'-'+_0x4d9af9+'/'+_0x116f9d)[_0x2ff2('0x32')](_0x354dff);}return null;};}function patchUpdates(_0x482d6a){return function(_0x4abc99){try{jsonpatch[_0x2ff2('0x33')](_0x4abc99,_0x482d6a,!![]);}catch(_0x12a6a2){return BPromise[_0x2ff2('0x34')](_0x12a6a2);}return _0x4abc99['save']();};}function saveUpdates(_0x216451,_0x4192b5){return function(_0x3601bc){if(_0x3601bc){return _0x3601bc[_0x2ff2('0x35')](_0x216451)[_0x2ff2('0x21')](function(_0x3d8f5b){return _0x3d8f5b;});}return null;};}function removeEntity(_0x201805,_0x2d45d5){return function(_0xf4533d){if(_0xf4533d){return _0xf4533d[_0x2ff2('0x36')]()['then'](function(){var _0xc0de70=_0xf4533d[_0x2ff2('0x37')]({'plain':!![]});var _0x283cd1=_0x2ff2('0x38');return db['UserProfileResource'][_0x2ff2('0x36')]({'where':{'type':_0x283cd1,'resourceId':_0xc0de70['id']}})[_0x2ff2('0x21')](function(){return _0xf4533d;});})[_0x2ff2('0x21')](function(){_0x201805[_0x2ff2('0x2c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x5aa782,_0x7cc4ae){return function(_0x1e39da){if(!_0x1e39da){_0x5aa782[_0x2ff2('0x2b')](0x194);}return _0x1e39da;};}function handleError(_0x5a757f,_0x4f4547){_0x4f4547=_0x4f4547||0x1f4;return function(_0x2cf5f8){logger[_0x2ff2('0x28')](_0x2cf5f8[_0x2ff2('0x39')]);if(_0x2cf5f8['name']){delete _0x2cf5f8[_0x2ff2('0x3a')];}_0x5a757f[_0x2ff2('0x2c')](_0x4f4547)[_0x2ff2('0x3b')](_0x2cf5f8);};}exports[_0x2ff2('0x3c')]=function(_0x36b9c8,_0x857d96){var _0x203085={'include':[{'model':db[_0x2ff2('0x3d')],'as':'mandatoryDispositionPause'}]},_0x3fd022={},_0x31b105={'count':0x0,'rows':[]};var _0x18e7a4=_[_0x2ff2('0x3e')](db[_0x2ff2('0x3f')][_0x2ff2('0x40')],function(_0x4436c0){return{'name':_0x4436c0[_0x2ff2('0x41')],'type':_0x4436c0[_0x2ff2('0x42')]['key']};});_0x3fd022[_0x2ff2('0x43')]=_[_0x2ff2('0x3e')](_0x18e7a4,'name');_0x3fd022[_0x2ff2('0x44')]=_['keys'](_0x36b9c8[_0x2ff2('0x44')]);_0x3fd022['filters']=_[_0x2ff2('0x45')](_0x3fd022['model'],_0x3fd022[_0x2ff2('0x44')]);_0x203085[_0x2ff2('0x46')]=_[_0x2ff2('0x45')](_0x3fd022[_0x2ff2('0x43')],qs[_0x2ff2('0x47')](_0x36b9c8[_0x2ff2('0x44')][_0x2ff2('0x47')]));_0x203085[_0x2ff2('0x46')]=_0x203085[_0x2ff2('0x46')]['length']?_0x203085[_0x2ff2('0x46')]:_0x3fd022['model'];if(!_0x36b9c8[_0x2ff2('0x44')][_0x2ff2('0x48')](_0x2ff2('0x49'))){_0x203085[_0x2ff2('0x30')]=qs[_0x2ff2('0x30')](_0x36b9c8[_0x2ff2('0x44')][_0x2ff2('0x30')]);_0x203085[_0x2ff2('0x2e')]=qs['offset'](_0x36b9c8[_0x2ff2('0x44')][_0x2ff2('0x2e')]);}_0x203085[_0x2ff2('0x4a')]=qs[_0x2ff2('0x4b')](_0x36b9c8[_0x2ff2('0x44')][_0x2ff2('0x4b')]);_0x203085[_0x2ff2('0x4c')]=qs['filters'](_['pick'](_0x36b9c8['query'],_0x3fd022[_0x2ff2('0x4d')]),_0x18e7a4);if(_0x36b9c8[_0x2ff2('0x44')][_0x2ff2('0x4e')]){_0x203085[_0x2ff2('0x4c')]=_[_0x2ff2('0x4f')](_0x203085['where'],{'$or':_[_0x2ff2('0x3e')](_0x18e7a4,function(_0x502990){if(_0x502990[_0x2ff2('0x42')]!==_0x2ff2('0x50')){var _0x381479={};_0x381479[_0x502990['name']]={'$like':'%'+_0x36b9c8[_0x2ff2('0x44')]['filter']+'%'};return _0x381479;}})});}_0x203085=_[_0x2ff2('0x4f')]({},_0x203085,_0x36b9c8[_0x2ff2('0x51')]);var _0x3d3529={'where':_0x203085[_0x2ff2('0x4c')]};return db['OpenchannelAccount']['count'](_0x3d3529)[_0x2ff2('0x21')](function(_0xb22fb0){_0x31b105['count']=_0xb22fb0;if(_0x36b9c8[_0x2ff2('0x44')][_0x2ff2('0x52')]){_0x203085[_0x2ff2('0x53')]=[{'all':!![]}];}return db[_0x2ff2('0x3f')][_0x2ff2('0x54')](_0x203085);})[_0x2ff2('0x21')](function(_0x1e7bb5){_0x31b105['rows']=_0x1e7bb5;return _0x31b105;})[_0x2ff2('0x21')](respondWithFilteredResult(_0x857d96,_0x203085))[_0x2ff2('0x55')](handleError(_0x857d96,null));};exports[_0x2ff2('0x56')]=function(_0x312c98,_0x1cc1f2){var _0x34b462={'raw':![],'where':{'id':_0x312c98[_0x2ff2('0x57')]['id']},'include':[{'model':db[_0x2ff2('0x3d')],'as':_0x2ff2('0x58')}]},_0x4b333f={};_0x4b333f[_0x2ff2('0x43')]=_[_0x2ff2('0x59')](db[_0x2ff2('0x3f')][_0x2ff2('0x40')]);_0x4b333f[_0x2ff2('0x44')]=_[_0x2ff2('0x59')](_0x312c98['query']);_0x4b333f[_0x2ff2('0x4d')]=_['intersection'](_0x4b333f['model'],_0x4b333f[_0x2ff2('0x44')]);_0x34b462[_0x2ff2('0x46')]=_[_0x2ff2('0x45')](_0x4b333f[_0x2ff2('0x43')],qs[_0x2ff2('0x47')](_0x312c98[_0x2ff2('0x44')]['fields']));_0x34b462[_0x2ff2('0x46')]=_0x34b462['attributes'][_0x2ff2('0x5a')]?_0x34b462[_0x2ff2('0x46')]:_0x4b333f[_0x2ff2('0x43')];if(_0x312c98[_0x2ff2('0x44')][_0x2ff2('0x52')]){_0x34b462[_0x2ff2('0x53')]=[{'all':!![]}];}_0x34b462=_[_0x2ff2('0x4f')]({},_0x34b462,_0x312c98[_0x2ff2('0x51')]);return db[_0x2ff2('0x3f')]['find'](_0x34b462)['then'](handleEntityNotFound(_0x1cc1f2,null))[_0x2ff2('0x21')](respondWithResult(_0x1cc1f2,null))[_0x2ff2('0x55')](handleError(_0x1cc1f2,null));};exports[_0x2ff2('0x5b')]=function(_0x12a0e6,_0x52685e){return db['OpenchannelAccount'][_0x2ff2('0x5b')](_0x12a0e6[_0x2ff2('0x5c')],{})[_0x2ff2('0x21')](function(_0x336cba){var _0x1b2bae=_0x12a0e6[_0x2ff2('0x5d')][_0x2ff2('0x37')]({'plain':!![]});if(!_0x1b2bae)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x1b2bae[_0x2ff2('0x5e')]===_0x2ff2('0x5d')){var _0x247e3f=_0x336cba[_0x2ff2('0x37')]({'plain':!![]});var _0x4c495e=_0x2ff2('0x38');return db[_0x2ff2('0x5f')][_0x2ff2('0x60')]({'where':{'name':_0x4c495e,'userProfileId':_0x1b2bae['userProfileId']},'raw':!![]})['then'](function(_0x525467){if(_0x525467&&_0x525467[_0x2ff2('0x61')]===0x0){return db[_0x2ff2('0x62')][_0x2ff2('0x5b')]({'name':_0x247e3f[_0x2ff2('0x3a')],'resourceId':_0x247e3f['id'],'type':_0x525467['name'],'sectionId':_0x525467['id']},{})[_0x2ff2('0x21')](function(){return _0x336cba;});}else{return _0x336cba;}})[_0x2ff2('0x55')](function(_0x7fb3b2){logger[_0x2ff2('0x28')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x7fb3b2);throw _0x7fb3b2;});}return _0x336cba;})[_0x2ff2('0x21')](respondWithResult(_0x52685e,0xc9))[_0x2ff2('0x55')](handleError(_0x52685e,null));};exports['update']=function(_0xa2cd19,_0x14e01c){if(_0xa2cd19[_0x2ff2('0x5c')]['id']){delete _0xa2cd19[_0x2ff2('0x5c')]['id'];}return db['OpenchannelAccount'][_0x2ff2('0x60')]({'where':{'id':_0xa2cd19[_0x2ff2('0x57')]['id']},'include':[{'model':db[_0x2ff2('0x3d')],'as':_0x2ff2('0x58')}]})[_0x2ff2('0x21')](handleEntityNotFound(_0x14e01c,null))[_0x2ff2('0x21')](saveUpdates(_0xa2cd19['body'],null))[_0x2ff2('0x21')](respondWithResult(_0x14e01c,null))[_0x2ff2('0x55')](handleError(_0x14e01c,null));};exports['destroy']=function(_0x3ad493,_0x5b2a94){return db[_0x2ff2('0x3f')]['find']({'where':{'id':_0x3ad493[_0x2ff2('0x57')]['id']}})['then'](handleEntityNotFound(_0x5b2a94,null))[_0x2ff2('0x21')](removeEntity(_0x5b2a94,null))[_0x2ff2('0x55')](handleError(_0x5b2a94,null));};exports[_0x2ff2('0x63')]=function(_0x44384f,_0x262ec6){return db[_0x2ff2('0x3f')]['describe']()[_0x2ff2('0x21')](respondWithResult(_0x262ec6,null))['catch'](handleError(_0x262ec6,null));};exports['addDisposition']=function(_0x3ac3ce,_0x1f38aa,_0x16d330){if(_0x3ac3ce['body']['id']){delete _0x3ac3ce['body']['id'];}return db[_0x2ff2('0x3f')]['find']({'where':{'id':_0x3ac3ce[_0x2ff2('0x57')]['id']}})[_0x2ff2('0x21')](handleEntityNotFound(_0x1f38aa,null))[_0x2ff2('0x21')](function(_0x3fd5b9){if(_0x3fd5b9){_0x3ac3ce[_0x2ff2('0x5c')][_0x2ff2('0x64')]=_0x3fd5b9['id'];return db[_0x2ff2('0x65')]['create'](_0x3ac3ce[_0x2ff2('0x5c')]);}})[_0x2ff2('0x21')](respondWithResult(_0x1f38aa,null))[_0x2ff2('0x55')](handleError(_0x1f38aa,null));};exports[_0x2ff2('0x66')]=function(_0x3c9433,_0x259cbd,_0x214ea1){var _0x24caf8={'raw':![],'where':{}};var _0x511c3b={};var _0x5caa2b={'count':0x0,'rows':[]};return db[_0x2ff2('0x3f')]['findOne']({'where':{'id':_0x3c9433[_0x2ff2('0x57')]['id']}})[_0x2ff2('0x21')](handleEntityNotFound(_0x259cbd,null))['then'](function(_0x12eb5c){if(_0x12eb5c){_0x511c3b[_0x2ff2('0x43')]=_['keys'](db['Disposition'][_0x2ff2('0x40')]);_0x511c3b[_0x2ff2('0x44')]=_[_0x2ff2('0x59')](_0x3c9433['query']);_0x511c3b[_0x2ff2('0x4d')]=_[_0x2ff2('0x45')](_0x511c3b[_0x2ff2('0x43')],_0x511c3b[_0x2ff2('0x44')]);_0x24caf8[_0x2ff2('0x46')]=_[_0x2ff2('0x45')](_0x511c3b[_0x2ff2('0x43')],qs[_0x2ff2('0x47')](_0x3c9433[_0x2ff2('0x44')]['fields']));_0x24caf8[_0x2ff2('0x46')]=_0x24caf8[_0x2ff2('0x46')]['length']?_0x24caf8[_0x2ff2('0x46')]:_0x511c3b[_0x2ff2('0x43')];if(!_0x3c9433['query'][_0x2ff2('0x48')](_0x2ff2('0x49'))){_0x24caf8['limit']=qs[_0x2ff2('0x30')](_0x3c9433[_0x2ff2('0x44')][_0x2ff2('0x30')]);_0x24caf8[_0x2ff2('0x2e')]=qs[_0x2ff2('0x2e')](_0x3c9433['query'][_0x2ff2('0x2e')]);}_0x24caf8[_0x2ff2('0x4a')]=qs['sort'](_0x3c9433[_0x2ff2('0x44')][_0x2ff2('0x4b')]);_0x24caf8[_0x2ff2('0x4c')]=qs[_0x2ff2('0x4d')](_[_0x2ff2('0x67')](_0x3c9433[_0x2ff2('0x44')],_0x511c3b[_0x2ff2('0x4d')]));_0x24caf8[_0x2ff2('0x4c')][_0x2ff2('0x64')]=_0x12eb5c['id'];if(_0x3c9433[_0x2ff2('0x44')][_0x2ff2('0x4e')]){_0x24caf8[_0x2ff2('0x4c')]=_[_0x2ff2('0x4f')](_0x24caf8[_0x2ff2('0x4c')],{'$or':_[_0x2ff2('0x3e')](_0x24caf8['attributes'],function(_0x53b810){var _0x3a0e2f={};_0x3a0e2f[_0x53b810]={'$like':'%'+_0x3c9433['query'][_0x2ff2('0x4e')]+'%'};return _0x3a0e2f;})});}_0x24caf8=_[_0x2ff2('0x4f')]({},_0x24caf8,_0x3c9433[_0x2ff2('0x51')]);return db[_0x2ff2('0x65')][_0x2ff2('0x31')]({'where':_0x24caf8[_0x2ff2('0x4c')]})[_0x2ff2('0x21')](function(_0x578628){_0x5caa2b[_0x2ff2('0x31')]=_0x578628;if(_0x3c9433['query'][_0x2ff2('0x52')]){_0x24caf8['include']=[{'all':!![]}];}return db[_0x2ff2('0x65')][_0x2ff2('0x54')](_0x24caf8);})[_0x2ff2('0x21')](function(_0x545dcb){_0x5caa2b['rows']=_0x545dcb;return _0x5caa2b;});}})[_0x2ff2('0x21')](respondWithFilteredResult(_0x259cbd,_0x24caf8))[_0x2ff2('0x55')](handleError(_0x259cbd,null));};exports[_0x2ff2('0x68')]=function(_0x4a7d1f,_0x4d18f4,_0x48f6a3){return db[_0x2ff2('0x3f')][_0x2ff2('0x60')]({'where':{'id':_0x4a7d1f[_0x2ff2('0x57')]['id']}})['then'](handleEntityNotFound(_0x4d18f4,null))['then'](function(_0x529bbc){if(_0x529bbc){return _0x529bbc[_0x2ff2('0x68')](_0x4a7d1f[_0x2ff2('0x44')][_0x2ff2('0x69')]);}})[_0x2ff2('0x21')](respondWithStatusCode(_0x4d18f4,null))[_0x2ff2('0x55')](handleError(_0x4d18f4,null));};exports['addAnswer']=function(_0x520906,_0x533d26,_0x662700){if(_0x520906[_0x2ff2('0x5c')]['id']){delete _0x520906[_0x2ff2('0x5c')]['id'];}return db['OpenchannelAccount'][_0x2ff2('0x60')]({'where':{'id':_0x520906['params']['id']}})[_0x2ff2('0x21')](handleEntityNotFound(_0x533d26,null))[_0x2ff2('0x21')](function(_0x27ffc2){if(_0x27ffc2){_0x520906[_0x2ff2('0x5c')][_0x2ff2('0x64')]=_0x27ffc2['id'];return db[_0x2ff2('0x6a')][_0x2ff2('0x5b')](_0x520906[_0x2ff2('0x5c')]);}})[_0x2ff2('0x21')](respondWithResult(_0x533d26,null))['catch'](handleError(_0x533d26,null));};exports['getAnswers']=function(_0x3e24ca,_0x55e428,_0x45f315){var _0x31d38f={'raw':![],'where':{}};var _0x5b757b={};var _0x32edc4={'count':0x0,'rows':[]};return db[_0x2ff2('0x3f')][_0x2ff2('0x6b')]({'where':{'id':_0x3e24ca['params']['id']}})['then'](handleEntityNotFound(_0x55e428,null))['then'](function(_0x2b9b52){if(_0x2b9b52){_0x5b757b['model']=_[_0x2ff2('0x59')](db[_0x2ff2('0x6a')][_0x2ff2('0x40')]);_0x5b757b[_0x2ff2('0x44')]=_['keys'](_0x3e24ca[_0x2ff2('0x44')]);_0x5b757b[_0x2ff2('0x4d')]=_[_0x2ff2('0x45')](_0x5b757b['model'],_0x5b757b[_0x2ff2('0x44')]);_0x31d38f['attributes']=_[_0x2ff2('0x45')](_0x5b757b['model'],qs['fields'](_0x3e24ca[_0x2ff2('0x44')][_0x2ff2('0x47')]));_0x31d38f[_0x2ff2('0x46')]=_0x31d38f[_0x2ff2('0x46')][_0x2ff2('0x5a')]?_0x31d38f[_0x2ff2('0x46')]:_0x5b757b[_0x2ff2('0x43')];if(!_0x3e24ca[_0x2ff2('0x44')][_0x2ff2('0x48')](_0x2ff2('0x49'))){_0x31d38f[_0x2ff2('0x30')]=qs[_0x2ff2('0x30')](_0x3e24ca[_0x2ff2('0x44')][_0x2ff2('0x30')]);_0x31d38f[_0x2ff2('0x2e')]=qs[_0x2ff2('0x2e')](_0x3e24ca[_0x2ff2('0x44')][_0x2ff2('0x2e')]);}_0x31d38f[_0x2ff2('0x4a')]=qs[_0x2ff2('0x4b')](_0x3e24ca[_0x2ff2('0x44')][_0x2ff2('0x4b')]);_0x31d38f[_0x2ff2('0x4c')]=qs[_0x2ff2('0x4d')](_['pick'](_0x3e24ca[_0x2ff2('0x44')],_0x5b757b[_0x2ff2('0x4d')]));_0x31d38f[_0x2ff2('0x4c')][_0x2ff2('0x64')]=_0x2b9b52['id'];if(_0x3e24ca[_0x2ff2('0x44')][_0x2ff2('0x4e')]){_0x31d38f[_0x2ff2('0x4c')]=_[_0x2ff2('0x4f')](_0x31d38f[_0x2ff2('0x4c')],{'$or':_[_0x2ff2('0x3e')](_0x31d38f[_0x2ff2('0x46')],function(_0x5cf6c2){var _0x13297c={};_0x13297c[_0x5cf6c2]={'$like':'%'+_0x3e24ca[_0x2ff2('0x44')][_0x2ff2('0x4e')]+'%'};return _0x13297c;})});}_0x31d38f=_[_0x2ff2('0x4f')]({},_0x31d38f,_0x3e24ca[_0x2ff2('0x51')]);return db['CannedAnswer']['count']({'where':_0x31d38f[_0x2ff2('0x4c')]})['then'](function(_0x45a7fd){_0x32edc4[_0x2ff2('0x31')]=_0x45a7fd;if(_0x3e24ca[_0x2ff2('0x44')][_0x2ff2('0x52')]){_0x31d38f['include']=[{'all':!![]}];}return db[_0x2ff2('0x6a')][_0x2ff2('0x54')](_0x31d38f);})[_0x2ff2('0x21')](function(_0xb4fb0f){_0x32edc4[_0x2ff2('0x6c')]=_0xb4fb0f;return _0x32edc4;});}})[_0x2ff2('0x21')](respondWithFilteredResult(_0x55e428,_0x31d38f))[_0x2ff2('0x55')](handleError(_0x55e428,null));};exports[_0x2ff2('0x6d')]=function(_0x343487,_0x5b4c25,_0x1ad4ee){return db[_0x2ff2('0x3f')][_0x2ff2('0x60')]({'where':{'id':_0x343487[_0x2ff2('0x57')]['id']}})['then'](handleEntityNotFound(_0x5b4c25,null))['then'](function(_0x453a0d){if(_0x453a0d){return _0x453a0d['removeAnswers'](_0x343487[_0x2ff2('0x44')][_0x2ff2('0x69')]);}})[_0x2ff2('0x21')](respondWithStatusCode(_0x5b4c25,null))[_0x2ff2('0x55')](handleError(_0x5b4c25,null));};exports[_0x2ff2('0x6e')]=function(_0x4f0f9f,_0x5c0805,_0x5cb4c1){var _0x2a5ccb={'body':_0x4f0f9f[_0x2ff2('0x5c')],'channel':'openchannel'};var _0x1f40d5=[];var _0x1ff945=[];var _0x14ff82={};var _0x43d404=![];return db['CmContact'][_0x2ff2('0x63')]()['then'](function(_0x149973){if(!_0x149973){throw new db[(_0x2ff2('0x6f'))]['ValidationError'](_0x2ff2('0x70'));}_0x1f40d5=_[_0x2ff2('0x71')](_[_0x2ff2('0x59')](_0x149973),[_0x2ff2('0x72'),_0x2ff2('0x73')]);_0x1ff945=_['difference'](_[_0x2ff2('0x59')](_0x149973),['createdAt',_0x2ff2('0x73'),_0x2ff2('0x74'),_0x2ff2('0x75')]);if(_0x4f0f9f[_0x2ff2('0x5c')]['id']){delete _0x4f0f9f[_0x2ff2('0x5c')]['id'];}if(_[_0x2ff2('0x76')](_0x4f0f9f[_0x2ff2('0x5c')][_0x2ff2('0x77')])){throw new db[(_0x2ff2('0x6f'))][(_0x2ff2('0x78'))](_0x2ff2('0x79'));}if(_[_0x2ff2('0x76')](_0x4f0f9f['body'][_0x2ff2('0x5c')])||_0x4f0f9f['body']['body']===''){throw new db[(_0x2ff2('0x6f'))][(_0x2ff2('0x78'))](_0x2ff2('0x7a'));}if(_[_0x2ff2('0x76')](_0x4f0f9f['body'][_0x2ff2('0x7b')])){throw new db[(_0x2ff2('0x6f'))][(_0x2ff2('0x78'))](_0x2ff2('0x7c')+_0x1ff945);}if(!_['includes'](_0x1ff945,_0x4f0f9f[_0x2ff2('0x5c')]['mapKey'])){throw new db[(_0x2ff2('0x6f'))][(_0x2ff2('0x78'))]('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x1ff945);}_0x14ff82[_0x4f0f9f[_0x2ff2('0x5c')][_0x2ff2('0x7b')]]=_0x4f0f9f[_0x2ff2('0x5c')][_0x2ff2('0x77')];})[_0x2ff2('0x21')](function(){return db['OpenchannelAccount'][_0x2ff2('0x60')]({'where':{'id':_0x4f0f9f[_0x2ff2('0x57')]['id']},'include':[{'model':db[_0x2ff2('0x7d')],'as':_0x2ff2('0x7e'),'include':[{'model':db['CmContact'],'as':_0x2ff2('0x7f'),'where':_0x14ff82,'limit':0x1,'order':[['updatedAt',_0x2ff2('0x80')]]}]},{'model':db[_0x2ff2('0x81')],'as':_0x2ff2('0x82')}]});})[_0x2ff2('0x21')](handleEntityNotFound(_0x5c0805,null))[_0x2ff2('0x21')](function(_0x2f0c7d){if(_0x2f0c7d&&_0x2f0c7d[_0x2ff2('0x7e')]){_0x2a5ccb['account']=_0x2f0c7d;_0x2a5ccb[_0x2ff2('0x83')]=_0x2f0c7d[_0x2ff2('0x82')];_0x2a5ccb[_0x2ff2('0x84')]=_0x2f0c7d[_0x2ff2('0x7e')];_0x2a5ccb[_0x2ff2('0x83')]=_[_0x2ff2('0x85')](_0x2a5ccb[_0x2ff2('0x83')],[_0x2ff2('0x86')],[_0x2ff2('0x87')]);if(_0x2a5ccb[_0x2ff2('0x88')][_0x2ff2('0x82')]){delete _0x2a5ccb[_0x2ff2('0x88')]['Applications'];}if(_0x2a5ccb['account']['List']&&_0x2a5ccb[_0x2ff2('0x88')]['List']['Contacts'][_0x2ff2('0x5a')]){return _0x2a5ccb[_0x2ff2('0x88')][_0x2ff2('0x7e')]['Contacts'][0x0];}var _0x4d4c7e=_['defaults'](_0x4f0f9f[_0x2ff2('0x5c')],{'firstName':_0x4f0f9f['body'][_0x2ff2('0x77')],'ListId':_0x2f0c7d['ListId']});_0x4d4c7e[_0x4f0f9f[_0x2ff2('0x5c')][_0x2ff2('0x7b')]]=_0x4f0f9f[_0x2ff2('0x5c')][_0x2ff2('0x77')];return db[_0x2ff2('0x89')]['create'](_0x4d4c7e,{'fields':_0x1f40d5,'raw':!![]});}})[_0x2ff2('0x21')](handleEntityNotFound(_0x5c0805,null))['then'](function(_0x3c7886){_0x2a5ccb['contact']=_0x3c7886;if(_0x3c7886){var _0xd54d={'ContactId':_0x3c7886['id'],'OpenchannelAccountId':_0x4f0f9f[_0x2ff2('0x57')]['id'],'from':(_0x3c7886[_0x2ff2('0x8a')]||'')+'\x20'+(_0x3c7886[_0x2ff2('0x8b')]||'')};var _0x145633={'OpenchannelAccountId':_0x4f0f9f['params']['id'],'closed':![]};if(_0x4f0f9f['body'][_0x2ff2('0x8c')]){_0x145633['threadId']=_0x4f0f9f[_0x2ff2('0x5c')][_0x2ff2('0x8c')];return db[_0x2ff2('0x8d')][_0x2ff2('0x60')]({'where':_0x145633})[_0x2ff2('0x21')](function(_0xb1c06c){if(_0xb1c06c){return[_0xb1c06c,![]];}_0xd54d[_0x2ff2('0x8c')]=_0x4f0f9f[_0x2ff2('0x5c')][_0x2ff2('0x8c')];_0xd54d[_0x2ff2('0x8e')]=_0x4f0f9f[_0x2ff2('0x5c')][_0x2ff2('0x8e')];return db[_0x2ff2('0x8d')][_0x2ff2('0x5b')](_0xd54d)[_0x2ff2('0x21')](function(_0x2afa98){return[_0x2afa98,!![]];});});}else{_0x145633[_0x2ff2('0x8c')]=null;}_0x145633[_0x2ff2('0x8f')]=_0x3c7886['id'];return db['OpenchannelInteraction'][_0x2ff2('0x60')]({'where':_0x145633})['then'](function(_0x4424b5){if(_0x4424b5){return[_0x4424b5,![]];}return db[_0x2ff2('0x8d')]['create'](_0xd54d)['then'](function(_0x2bca73){return[_0x2bca73,!![]];});});}})[_0x2ff2('0x90')](function(_0x46dae2,_0x1a95f4){if(_0x46dae2){_0x43d404=_0x1a95f4;if(!_0x1a95f4){var _0x4f9afd={'from':(_0x2a5ccb[_0x2ff2('0x91')][_0x2ff2('0x8a')]||'')+'\x20'+(_0x2a5ccb[_0x2ff2('0x91')][_0x2ff2('0x8b')]||'')};if(_0x4f0f9f['body']['threadId']&&_0x4f0f9f[_0x2ff2('0x5c')][_0x2ff2('0x92')]&&_0x4f0f9f[_0x2ff2('0x5c')]['threadId']!=_0x4f0f9f[_0x2ff2('0x5c')][_0x2ff2('0x92')]){_0x4f9afd[_0x2ff2('0x8c')]=_0x4f0f9f['body'][_0x2ff2('0x92')];}return _0x46dae2[_0x2ff2('0x35')](_0x4f9afd);}else{return _0x46dae2;}}})[_0x2ff2('0x21')](function(_0x44710b){_0x2a5ccb['interaction']=_0x44710b[_0x2ff2('0x37')]({'plain':!![]});_0x2a5ccb[_0x2ff2('0x93')][_0x2ff2('0x94')]=_0x43d404;if(_0x2a5ccb[_0x2ff2('0x93')]['created']){if(_0x2a5ccb[_0x2ff2('0x88')]['autoclose']){_0x2a5ccb[_0x2ff2('0x83')][_0x2ff2('0x95')]({'id':0x0,'priority':_0x2a5ccb[_0x2ff2('0x83')][_0x2ff2('0x5a')]+0x1,'app':_0x2ff2('0x96'),'appdata':'unmanaged','interval':_0x2ff2('0x97')});}}return db[_0x2ff2('0x98')][_0x2ff2('0x5b')]({'body':_0x4f0f9f[_0x2ff2('0x5c')]['body'],'OpenchannelAccountId':_0x4f0f9f[_0x2ff2('0x57')]['id'],'OpenchannelInteractionId':_0x44710b['id'],'direction':'in','ContactId':_0x2a5ccb[_0x2ff2('0x91')]['id'],'AttachmentId':_0x4f0f9f[_0x2ff2('0x5c')][_0x2ff2('0x99')]});})[_0x2ff2('0x21')](function(_0xba45de){_0x2a5ccb['message']=_0xba45de;if(!_0x2a5ccb[_0x2ff2('0x93')][_0x2ff2('0x9a')])return;return db[_0x2ff2('0x9b')][_0x2ff2('0x60')]({'attributes':['id',_0x2ff2('0x3a')],'where':{'id':_0x2a5ccb[_0x2ff2('0x93')]['UserId']}});})['then'](function(_0xc7b532){if(_0xc7b532){_0x2a5ccb[_0x2ff2('0x83')][_0x2ff2('0x9c')]({'id':0x0,'priority':0x0,'app':'agent','appdata':_0xc7b532[_0x2ff2('0x3a')]+','+(_0x2a5ccb[_0x2ff2('0x88')]['waitForTheAssignedAgent']||0xa),'interval':_0x2ff2('0x97')});}if(!_0x2a5ccb[_0x2ff2('0x93')]['queueId'])return;return db[_0x2ff2('0x9d')][_0x2ff2('0x60')]({'attributes':['id',_0x2ff2('0x3a')],'where':{'id':_0x2a5ccb[_0x2ff2('0x93')][_0x2ff2('0x9e')]}});})['then'](function(_0x6370f0){if(_0x6370f0){_0x2a5ccb[_0x2ff2('0x83')][_0x2ff2('0x9c')]({'id':0x0,'priority':0x1,'app':_0x2ff2('0x9f'),'appdata':_0x6370f0['name']+','+(_0x2a5ccb[_0x2ff2('0x88')][_0x2ff2('0xa0')]||0x12c),'interval':_0x2ff2('0x97')});}return respondWithRpcPromise(_0x2ff2('0xa1'),'startRouting',_0x2a5ccb);})[_0x2ff2('0x21')](function(_0x1e6781){respondWithRpcPromise(_0x2ff2('0xa2'),_0x2ff2('0xa2'),{'event':_0x2ff2('0x6e'),'message':_0x1e6781},client9002);return _0x1e6781;})[_0x2ff2('0x21')](respondWithResult(_0x5c0805,null))[_0x2ff2('0x55')](handleError(_0x5c0805,null));};exports['addApplications']=function(_0x31fab8,_0x681ea4){var _0x2689c3=_0x31fab8[_0x2ff2('0x57')]['id'];var _0x289a9b=_0x31fab8[_0x2ff2('0x5c')];var _0xdaaf09=0xc8;var _0x129c6a=null;return db[_0x2ff2('0xa3')][_0x2ff2('0xa4')]({'isolationLevel':db[_0x2ff2('0xa3')][_0x2ff2('0xa5')]['ISOLATION_LEVELS'][_0x2ff2('0xa6')]},function(_0x12dde7){return db['OpenchannelAccount'][_0x2ff2('0x6b')]({'where':{'id':_0x2689c3},'transaction':_0x12dde7})[_0x2ff2('0x21')](function(_0x213f55){if(_0x213f55){return db[_0x2ff2('0x81')]['destroy']({'where':{'OpenchannelAccountId':_0x2689c3},'transaction':_0x12dde7})[_0x2ff2('0x21')](function(){var _0x3dcf68=_[_0x2ff2('0x3e')](_0x289a9b,function(_0x42e3d8){_0x42e3d8[_0x2ff2('0x64')]=_0x2689c3;return _0x42e3d8;});return db[_0x2ff2('0x81')][_0x2ff2('0xa7')](_0x3dcf68,{'transaction':_0x12dde7});});}else{_0xdaaf09=0x194;_0x129c6a=[];}});})[_0x2ff2('0x21')](function(){if(_0xdaaf09!==0x194){return db[_0x2ff2('0x81')][_0x2ff2('0xa8')]({'where':{'OpenchannelAccountId':_0x2689c3},'order':_0x2ff2('0x86')})['then'](function(_0x24cb95){_0x129c6a=_0x24cb95;});}})[_0x2ff2('0x55')](function(_0x21b678){_0xdaaf09=0x1f4;logger[_0x2ff2('0x28')](_0x21b678[_0x2ff2('0x39')]);if(_0x21b678['name']){delete _0x21b678[_0x2ff2('0x3a')];}_0x129c6a=_0x21b678;})[_0x2ff2('0xa9')](function(){if(_0x129c6a===null){_0x681ea4[_0x2ff2('0x2b')](_0xdaaf09);}else{if(_0xdaaf09===0x1f4){_0x681ea4[_0x2ff2('0x2c')](_0xdaaf09)[_0x2ff2('0x3b')](_0x129c6a);}else{_0x681ea4[_0x2ff2('0x2c')](_0xdaaf09)['json'](_0x129c6a);}}});};exports[_0x2ff2('0xaa')]=function(_0x2ff050,_0x48d8e9,_0x14c308){var _0x3f3b41={};var _0x1b2176={};var _0x1757c7;var _0x7c347;return db[_0x2ff2('0x3f')][_0x2ff2('0x6b')]({'where':{'id':_0x2ff050['params']['id']}})[_0x2ff2('0x21')](handleEntityNotFound(_0x48d8e9,null))[_0x2ff2('0x21')](function(_0x42e352){if(_0x42e352){_0x1757c7=_0x42e352;_0x1b2176[_0x2ff2('0x43')]=_['keys'](db[_0x2ff2('0x81')][_0x2ff2('0x40')]);_0x1b2176['query']=_[_0x2ff2('0x59')](_0x2ff050['query']);_0x1b2176[_0x2ff2('0x4d')]=_[_0x2ff2('0x45')](_0x1b2176[_0x2ff2('0x43')],_0x1b2176[_0x2ff2('0x44')]);_0x3f3b41[_0x2ff2('0x46')]=_[_0x2ff2('0x45')](_0x1b2176[_0x2ff2('0x43')],qs[_0x2ff2('0x47')](_0x2ff050[_0x2ff2('0x44')][_0x2ff2('0x47')]));_0x3f3b41['attributes']=_0x3f3b41[_0x2ff2('0x46')]['length']?_0x3f3b41[_0x2ff2('0x46')]:_0x1b2176['model'];_0x3f3b41[_0x2ff2('0x4a')]=qs[_0x2ff2('0x4b')](_0x2ff050[_0x2ff2('0x44')][_0x2ff2('0x4b')]);_0x3f3b41['where']=qs[_0x2ff2('0x4d')](_[_0x2ff2('0x67')](_0x2ff050['query'],_0x1b2176[_0x2ff2('0x4d')]));if(_0x2ff050[_0x2ff2('0x44')][_0x2ff2('0x4e')]){_0x3f3b41['where']=_['merge'](_0x3f3b41[_0x2ff2('0x4c')],{'$or':_[_0x2ff2('0x3e')](_0x3f3b41[_0x2ff2('0x46')],function(_0x48e02f){var _0x577ac3={};_0x577ac3[_0x48e02f]={'$like':'%'+_0x2ff050[_0x2ff2('0x44')][_0x2ff2('0x4e')]+'%'};return _0x577ac3;})});}_0x3f3b41=_[_0x2ff2('0x4f')]({},_0x3f3b41,_0x2ff050[_0x2ff2('0x51')]);return _0x1757c7['getApplications'](_0x3f3b41);}})[_0x2ff2('0x21')](function(_0x5be92a){if(_0x5be92a){_0x7c347=_0x5be92a[_0x2ff2('0x5a')];if(!_0x2ff050[_0x2ff2('0x44')][_0x2ff2('0x48')](_0x2ff2('0x49'))){_0x3f3b41['limit']=qs[_0x2ff2('0x30')](_0x2ff050[_0x2ff2('0x44')]['limit']);_0x3f3b41['offset']=qs['offset'](_0x2ff050[_0x2ff2('0x44')]['offset']);}return _0x1757c7[_0x2ff2('0xaa')](_0x3f3b41);}})[_0x2ff2('0x21')](function(_0x344110){if(_0x344110){return _0x344110?{'count':_0x7c347,'rows':_0x344110}:null;}})[_0x2ff2('0x21')](respondWithResult(_0x48d8e9,null))['catch'](handleError(_0x48d8e9,null));};exports[_0x2ff2('0xab')]=function(_0x4adaf8,_0x5121f3,_0x252c48){var _0x317cfe={'raw':![],'where':{}};var _0x4df228={};var _0x131375={'count':0x0,'rows':[]};return db[_0x2ff2('0x3f')]['findOne']({'where':{'id':_0x4adaf8[_0x2ff2('0x57')]['id']}})[_0x2ff2('0x21')](handleEntityNotFound(_0x5121f3,null))[_0x2ff2('0x21')](function(_0x1b0e09){if(_0x1b0e09){_0x4df228[_0x2ff2('0x43')]=_['keys'](db[_0x2ff2('0x8d')][_0x2ff2('0x40')]);_0x4df228['query']=_[_0x2ff2('0x59')](_0x4adaf8['query']);_0x4df228['filters']=_[_0x2ff2('0x45')](_0x4df228[_0x2ff2('0x43')],_0x4df228[_0x2ff2('0x44')]);_0x317cfe[_0x2ff2('0x46')]=_['intersection'](_0x4df228['model'],qs[_0x2ff2('0x47')](_0x4adaf8[_0x2ff2('0x44')][_0x2ff2('0x47')]));_0x317cfe[_0x2ff2('0x46')]=_0x317cfe[_0x2ff2('0x46')][_0x2ff2('0x5a')]?_0x317cfe[_0x2ff2('0x46')]:_0x4df228[_0x2ff2('0x43')];if(!_0x4adaf8[_0x2ff2('0x44')][_0x2ff2('0x48')](_0x2ff2('0x49'))){_0x317cfe[_0x2ff2('0x30')]=qs[_0x2ff2('0x30')](_0x4adaf8[_0x2ff2('0x44')][_0x2ff2('0x30')]);_0x317cfe[_0x2ff2('0x2e')]=qs[_0x2ff2('0x2e')](_0x4adaf8[_0x2ff2('0x44')][_0x2ff2('0x2e')]);}_0x317cfe[_0x2ff2('0x4a')]=qs[_0x2ff2('0x4b')](_0x4adaf8[_0x2ff2('0x44')][_0x2ff2('0x4b')]);_0x317cfe['where']=qs[_0x2ff2('0x4d')](_[_0x2ff2('0x67')](_0x4adaf8[_0x2ff2('0x44')],_0x4df228[_0x2ff2('0x4d')]));_0x317cfe[_0x2ff2('0x4c')]['OpenchannelAccountId']=_0x1b0e09['id'];if(_0x4adaf8[_0x2ff2('0x44')][_0x2ff2('0x4e')]){_0x317cfe['where']=_['merge'](_0x317cfe[_0x2ff2('0x4c')],{'$or':_[_0x2ff2('0x3e')](_0x317cfe[_0x2ff2('0x46')],function(_0x518b88){var _0x56b9c9={};_0x56b9c9[_0x518b88]={'$like':'%'+_0x4adaf8[_0x2ff2('0x44')][_0x2ff2('0x4e')]+'%'};return _0x56b9c9;})});}_0x317cfe=_[_0x2ff2('0x4f')]({},_0x317cfe,_0x4adaf8[_0x2ff2('0x51')]);return db['OpenchannelInteraction'][_0x2ff2('0x31')]({'where':_0x317cfe[_0x2ff2('0x4c')]})[_0x2ff2('0x21')](function(_0x466e70){_0x131375['count']=_0x466e70;if(_0x4adaf8['query'][_0x2ff2('0x52')]){_0x317cfe[_0x2ff2('0x53')]=[{'model':db[_0x2ff2('0x89')],'as':_0x2ff2('0xac'),'required':![]},{'model':db[_0x2ff2('0x9b')],'as':_0x2ff2('0xad'),'attributes':[_0x2ff2('0x3a'),_0x2ff2('0xae'),'internal'],'required':![]},{'model':db[_0x2ff2('0xaf')],'as':_0x2ff2('0xb0'),'attributes':['id',_0x2ff2('0x3a'),_0x2ff2('0xb1')],'where':_0x4adaf8[_0x2ff2('0x44')][_0x2ff2('0xb2')]?{'id':_0x4adaf8[_0x2ff2('0x44')][_0x2ff2('0xb2')]}:undefined,'required':_0x4adaf8[_0x2ff2('0x44')][_0x2ff2('0xb2')]?!![]:![]}];}return db[_0x2ff2('0x8d')]['findAll'](_0x317cfe);})[_0x2ff2('0x21')](function(_0x1a355d){_0x131375['rows']=_0x1a355d;return _0x131375;});}})[_0x2ff2('0x21')](respondWithFilteredResult(_0x5121f3,_0x317cfe))[_0x2ff2('0x55')](handleError(_0x5121f3,null));};exports[_0x2ff2('0xb3')]=function(_0x2eda78,_0x446f7a,_0x43e717){return db[_0x2ff2('0x3f')][_0x2ff2('0x60')]({'where':{'id':_0x2eda78['params']['id']}})['then'](handleEntityNotFound(_0x446f7a,null))[_0x2ff2('0x21')](function(_0x5ace94){if(_0x5ace94){return _0x5ace94[_0x2ff2('0xb3')](_0x2eda78[_0x2ff2('0x5c')][_0x2ff2('0x69')],_['omit'](_0x2eda78[_0x2ff2('0x5c')],[_0x2ff2('0x69'),'id'])||{})[_0x2ff2('0x90')](function(_0x37630d){for(var _0x3eb266=0x0;_0x3eb266<_0x2eda78[_0x2ff2('0x5c')][_0x2ff2('0x69')][_0x2ff2('0x5a')];_0x3eb266+=0x1){socket[_0x2ff2('0xb4')](_0x2ff2('0xb5'),{'UserId':Number(_0x2eda78[_0x2ff2('0x5c')][_0x2ff2('0x69')][_0x3eb266]),'OpenchannelAccountId':Number(_0x2eda78[_0x2ff2('0x57')]['id'])});}return _0x37630d;});}})['then'](respondWithResult(_0x446f7a,null))[_0x2ff2('0x55')](handleError(_0x446f7a,null));};exports['removeAgents']=function(_0xb3bde0,_0x3aaf9f,_0x48dd7c){return db['OpenchannelAccount']['find']({'where':{'id':_0xb3bde0['params']['id']}})['then'](handleEntityNotFound(_0x3aaf9f,null))[_0x2ff2('0x21')](function(_0x1ae9b0){if(_0x1ae9b0){return _0x1ae9b0[_0x2ff2('0xb6')](_0xb3bde0['query']['ids'])['then'](function(){if(_[_0x2ff2('0xb7')](_0xb3bde0['query'][_0x2ff2('0x69')])){for(var _0x185cac=0x0;_0x185cac<_0xb3bde0[_0x2ff2('0x44')][_0x2ff2('0x69')]['length'];_0x185cac+=0x1){socket['emit']('userOpenchannelAccount:remove',{'UserId':Number(_0xb3bde0[_0x2ff2('0x44')]['ids'][_0x185cac]),'OpenchannelAccountId':Number(_0xb3bde0['params']['id'])});}}else{socket[_0x2ff2('0xb4')](_0x2ff2('0xb8'),{'UserId':Number(_0xb3bde0[_0x2ff2('0x44')][_0x2ff2('0x69')]),'OpenchannelAccountId':Number(_0xb3bde0[_0x2ff2('0x57')]['id'])});}});}})[_0x2ff2('0x21')](respondWithStatusCode(_0x3aaf9f,null))[_0x2ff2('0x55')](handleError(_0x3aaf9f,null));};exports[_0x2ff2('0xb9')]=function(_0x2233f9,_0x56f2de,_0x23e279){var _0x1b060e={};var _0x3d0077={};var _0x4813b2;var _0x4866c1;return db[_0x2ff2('0x3f')][_0x2ff2('0x6b')]({'where':{'id':_0x2233f9[_0x2ff2('0x57')]['id']}})['then'](handleEntityNotFound(_0x56f2de,null))[_0x2ff2('0x21')](function(_0x2899a8){if(_0x2899a8){_0x4813b2=_0x2899a8;_0x3d0077[_0x2ff2('0x43')]=_[_0x2ff2('0x59')](db[_0x2ff2('0x9b')][_0x2ff2('0x40')]);_0x3d0077['query']=_[_0x2ff2('0x59')](_0x2233f9[_0x2ff2('0x44')]);_0x3d0077['filters']=_[_0x2ff2('0x45')](_0x3d0077[_0x2ff2('0x43')],_0x3d0077[_0x2ff2('0x44')]);_0x1b060e[_0x2ff2('0x46')]=_[_0x2ff2('0x45')](_0x3d0077[_0x2ff2('0x43')],qs[_0x2ff2('0x47')](_0x2233f9[_0x2ff2('0x44')][_0x2ff2('0x47')]));_0x1b060e['attributes']=_0x1b060e[_0x2ff2('0x46')][_0x2ff2('0x5a')]?_0x1b060e['attributes']:_0x3d0077[_0x2ff2('0x43')];_0x1b060e[_0x2ff2('0x4a')]=qs[_0x2ff2('0x4b')](_0x2233f9[_0x2ff2('0x44')][_0x2ff2('0x4b')]);_0x1b060e[_0x2ff2('0x4c')]=qs[_0x2ff2('0x4d')](_[_0x2ff2('0x67')](_0x2233f9['query'],_0x3d0077[_0x2ff2('0x4d')]));if(_0x2233f9[_0x2ff2('0x44')][_0x2ff2('0x4e')]){_0x1b060e[_0x2ff2('0x4c')]=_['merge'](_0x1b060e['where'],{'$or':_[_0x2ff2('0x3e')](_0x1b060e[_0x2ff2('0x46')],function(_0x22a6a1){var _0xe236bf={};_0xe236bf[_0x22a6a1]={'$like':'%'+_0x2233f9[_0x2ff2('0x44')][_0x2ff2('0x4e')]+'%'};return _0xe236bf;})});}_0x1b060e=_[_0x2ff2('0x4f')]({},_0x1b060e,_0x2233f9['options']);return _0x4813b2['getAgents'](_0x1b060e);}})[_0x2ff2('0x21')](function(_0xd3bc04){if(_0xd3bc04){_0x4866c1=_0xd3bc04['length'];if(!_0x2233f9[_0x2ff2('0x44')][_0x2ff2('0x48')]('nolimit')){_0x1b060e[_0x2ff2('0x30')]=qs[_0x2ff2('0x30')](_0x2233f9['query']['limit']);_0x1b060e[_0x2ff2('0x2e')]=qs[_0x2ff2('0x2e')](_0x2233f9[_0x2ff2('0x44')][_0x2ff2('0x2e')]);}return _0x4813b2['getAgents'](_0x1b060e);}})[_0x2ff2('0x21')](function(_0x4d2276){if(_0x4d2276){return _0x4d2276?{'count':_0x4866c1,'rows':_0x4d2276}:null;}})[_0x2ff2('0x21')](respondWithResult(_0x56f2de,null))['catch'](handleError(_0x56f2de,null));};exports[_0x2ff2('0x3b')]=function(_0x139dbc,_0x2d41ae,_0x546526){var _0x5a7248,_0x45e81c,_0x33a155;if(_[_0x2ff2('0x76')](_0x139dbc[_0x2ff2('0x5c')][_0x2ff2('0x5c')])||_0x139dbc[_0x2ff2('0x5c')]['body']===''){throw new db[(_0x2ff2('0x6f'))][(_0x2ff2('0x78'))](_0x2ff2('0x7a'));}if(_[_0x2ff2('0x76')](_0x139dbc[_0x2ff2('0x5c')]['to'])){}_0x5a7248=_0x139dbc[_0x2ff2('0x5c')]['to'];return db[_0x2ff2('0x3f')][_0x2ff2('0x6b')]({'where':{'id':_0x139dbc[_0x2ff2('0x57')]['id']}})['then'](handleEntityNotFound(_0x2d41ae,null))[_0x2ff2('0x21')](function(_0x955bc6){if(_0x955bc6){return db[_0x2ff2('0x3f')][_0x2ff2('0x60')]({'where':{'id':_0x955bc6['id']},'include':[{'model':db[_0x2ff2('0x7d')],'as':'List','include':[{'model':db[_0x2ff2('0x89')],'as':_0x2ff2('0x7f'),'where':{[_0x955bc6['mapKey']]:_0x5a7248},'limit':0x1,'order':[['updatedAt',_0x2ff2('0x80')]]}]}]})[_0x2ff2('0x21')](handleEntityNotFound(_0x2d41ae,null))[_0x2ff2('0x21')](function(_0x3dd8a6){if(_0x3dd8a6&&_0x3dd8a6[_0x2ff2('0x7e')]){_0x45e81c=_0x3dd8a6[_0x2ff2('0x37')]({'plain':!![]});if(_0x45e81c[_0x2ff2('0x7e')]&&_0x45e81c[_0x2ff2('0x7e')]['Contacts']['length']){return _0x45e81c[_0x2ff2('0x7e')][_0x2ff2('0x7f')][0x0];}return db[_0x2ff2('0x89')][_0x2ff2('0x5b')](_[_0x2ff2('0x1b')](_0x139dbc['body'],{'firstName':_0x5a7248,[_0x3dd8a6[_0x2ff2('0x7b')]]:_0x5a7248,'phone':_0x5a7248,'ListId':_0x45e81c[_0x2ff2('0x75')]}));}})['then'](handleEntityNotFound(_0x2d41ae,null))[_0x2ff2('0x21')](function(_0x5bd8b0){if(_0x5bd8b0){_0x33a155=_0x5bd8b0;return db[_0x2ff2('0x8d')][_0x2ff2('0x60')]({'where':{'ContactId':_0x33a155['id'],'closed':![],'OpenchannelAccountId':_0x45e81c['id']}})['then'](function(_0xe8f9ba){if(_0xe8f9ba){return[_0xe8f9ba,![]];}return db['OpenchannelInteraction'][_0x2ff2('0x5b')]({'UserId':_0x139dbc['user']['id'],'ContactId':_0x33a155['id'],'OpenchannelAccountId':_0x45e81c['id'],'lastMsgDirection':_0x2ff2('0xba'),'firstMsgDirection':_0x2ff2('0xba'),'Messages':[_[_0x2ff2('0x4f')](_0x139dbc[_0x2ff2('0x5c')],{'read':![],'body':_0x139dbc[_0x2ff2('0x5c')][_0x2ff2('0x5c')],'OpenchannelAccountId':_0x45e81c['id'],'UserId':_0x139dbc['user']['id'],'ContactId':_0x33a155['id']})]},{'include':[{'model':db[_0x2ff2('0x98')],'as':'Messages'}]})[_0x2ff2('0x21')](function(_0x2dd857){return[_0x2dd857,!![]];});});}})['spread'](function(_0x505439,_0x4eabc9){if(_0x4eabc9){return _0x505439;}return db[_0x2ff2('0x98')][_0x2ff2('0x5b')](_['merge'](_0x139dbc[_0x2ff2('0x5c')],{'read':![],'body':_0x139dbc[_0x2ff2('0x5c')][_0x2ff2('0x5c')],'OpenchannelAccountId':_0x45e81c['id'],'OpenchannelInteractionId':_0x505439['id'],'UserId':_0x139dbc['user']['id'],'ContactId':_0x33a155['id']}))['then'](function(_0x39fb44){_0x505439[_0x2ff2('0xbb')][_0x2ff2('0xbc')]=[];_0x505439[_0x2ff2('0xbb')][_0x2ff2('0xbc')][_0x2ff2('0x95')](_0x39fb44[_0x2ff2('0xbb')]);return _0x505439;});});}})[_0x2ff2('0x21')](respondWithResult(_0x2d41ae,null))[_0x2ff2('0x55')](handleError(_0x2d41ae,null));};
\ No newline at end of file