Built motion from commit da617fac.|2.6.6
[motion2.git] / server / api / openchannelAccount / openchannelAccount.controller.js
index f1ecd84..d4f0707 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xafc4=['merge','options','count','includeAll','include','findAll','rows','show','params','find','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','describe','addDisposition','Disposition','getDispositions','findOne','OpenchannelAccountId','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','openchannel','CmContact','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','ListId','from','isNil','Sequelize','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','mapKey','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','List','Contacts','Applications','account','applications','list','orderBy','asc','contact','firstName','lastName','threadId','OpenchannelInteraction','externalUrl','spread','messageId','interaction','created','autoclose','close','unmanaged','OpenchannelMessage','AttachmentId','UserId','User','unshift','agent','waitForTheAssignedAgent','*,*,*,*','forcedOwnership','Start','startRouting','EventManager','notify','addApplications','sequelize','OpenchannelApplication','bulkCreate','getApplications','Owner','Tag','Tags','color','tag','addAgents','omit','userOpenchannelAccount:save','removeAgents','isArray','userOpenchannelAccount:remove','getAgents','send','body\x20is\x20mandatory\x20and\x20not\x20empty','DESC','out','dataValues','Messages','push','html-pdf','rimraf','fast-json-patch','request-promise','moment','bluebird','sox','to-csv','ejs','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','api','../../config/utils','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','register','jayson/promise','client','http','request','then','info','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','end','offset','limit','status','set','Content-Range','apply','reject','save','update','destroy','OpenchannelAccounts','UserProfileResource','name','index','Pause','mandatoryDispositionPause','map','OpenchannelAccount','rawAttributes','fieldName','type','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter'];(function(_0x4b9b50,_0x313b7d){var _0x204cfa=function(_0x2031d6){while(--_0x2031d6){_0x4b9b50['push'](_0x4b9b50['shift']());}};_0x204cfa(++_0x313b7d);}(_0xafc4,0x69));var _0x4afc=function(_0x1d1c66,_0x33b222){_0x1d1c66=_0x1d1c66-0x0;var _0x675bc2=_0xafc4[_0x1d1c66];return _0x675bc2;};'use strict';var pdf=require(_0x4afc('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x4afc('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x4afc('0x2'));var rp=require(_0x4afc('0x3'));var moment=require(_0x4afc('0x4'));var BPromise=require(_0x4afc('0x5'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require(_0x4afc('0x6'));var csv=require(_0x4afc('0x7'));var ejs=require(_0x4afc('0x8'));var fs=require('fs');var _=require(_0x4afc('0x9'));var squel=require(_0x4afc('0xa'));var crypto=require(_0x4afc('0xb'));var jsforce=require('jsforce');var deskjs=require(_0x4afc('0xc'));var toCsv=require(_0x4afc('0x7'));var querystring=require(_0x4afc('0xd'));var Papa=require(_0x4afc('0xe'));var Redis=require(_0x4afc('0xf'));var authService=require(_0x4afc('0x10'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x4afc('0x11'));var logger=require('../../config/logger')(_0x4afc('0x12'));var utils=require(_0x4afc('0x13'));var config=require('../../config/environment');var licenseUtil=require(_0x4afc('0x14'));var db=require(_0x4afc('0x15'))['db'];config[_0x4afc('0x16')]=_[_0x4afc('0x17')](config[_0x4afc('0x16')],{'host':_0x4afc('0x18'),'port':0x18eb});var socket=require(_0x4afc('0x19'))(new Redis(config[_0x4afc('0x16')]));require('./openchannelAccount.socket')[_0x4afc('0x1a')](socket);var jayson=require(_0x4afc('0x1b'));var client=jayson[_0x4afc('0x1c')][_0x4afc('0x1d')]({'port':0x232c});var client9002=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x2452ae,_0x4f3127,_0x23ae30,_0x24ed6d){return new BPromise(function(_0x2b928b,_0x31eec4){var _0x3a306f=_0x24ed6d||client;return _0x3a306f[_0x4afc('0x1e')](_0x2452ae,_0x23ae30)[_0x4afc('0x1f')](function(_0x3ad418){logger[_0x4afc('0x20')](_0x4afc('0x21'),_0x4f3127,_0x4afc('0x22'));logger['debug'](_0x4afc('0x23'),_0x4f3127,_0x4afc('0x22'),JSON[_0x4afc('0x24')](_0x3ad418));if(_0x3ad418[_0x4afc('0x25')]){if(_0x3ad418['error'][_0x4afc('0x26')]===0x1f4){logger[_0x4afc('0x25')](_0x4afc('0x21'),_0x4f3127,_0x3ad418[_0x4afc('0x25')][_0x4afc('0x27')]);return _0x31eec4(_0x3ad418[_0x4afc('0x25')][_0x4afc('0x27')]);}logger['error'](_0x4afc('0x21'),_0x4f3127,_0x3ad418[_0x4afc('0x25')]['message']);return _0x2b928b(_0x3ad418[_0x4afc('0x25')]['message']);}else{logger[_0x4afc('0x20')](_0x4afc('0x21'),_0x4f3127,_0x4afc('0x22'));_0x2b928b(_0x3ad418[_0x4afc('0x28')][_0x4afc('0x27')]);}})[_0x4afc('0x29')](function(_0x40a0db){logger[_0x4afc('0x25')](_0x4afc('0x21'),_0x4f3127,_0x40a0db);_0x31eec4(_0x40a0db);});});}function respondWithStatusCode(_0x100220,_0x4e8273){_0x4e8273=_0x4e8273||0xcc;return function(_0x359c07){if(_0x359c07){return _0x100220[_0x4afc('0x2a')](_0x4e8273);}return _0x100220['status'](_0x4e8273)[_0x4afc('0x2b')]();};}function respondWithResult(_0x244f6c,_0x2d6112){_0x2d6112=_0x2d6112||0xc8;return function(_0x4e254d){if(_0x4e254d){return _0x244f6c['status'](_0x2d6112)['json'](_0x4e254d);}};}function respondWithFilteredResult(_0x426e9d,_0x5db47e){return function(_0x5e4747){if(_0x5e4747){var _0xd26d2f=_0x5e4747['count'],_0x628e42=_0x5db47e[_0x4afc('0x2c')],_0x494fe7=_0x5db47e[_0x4afc('0x2c')]+_0x5db47e[_0x4afc('0x2d')],_0x514278;if(_0x494fe7>=_0xd26d2f){_0x494fe7=_0xd26d2f;_0x514278=0xc8;}else{_0x514278=0xce;}_0x426e9d[_0x4afc('0x2e')](_0x514278);return _0x426e9d[_0x4afc('0x2f')](_0x4afc('0x30'),_0x628e42+'-'+_0x494fe7+'/'+_0xd26d2f)['json'](_0x5e4747);}return null;};}function patchUpdates(_0x290391){return function(_0x3d1693){try{jsonpatch[_0x4afc('0x31')](_0x3d1693,_0x290391,!![]);}catch(_0x2f178c){return BPromise[_0x4afc('0x32')](_0x2f178c);}return _0x3d1693[_0x4afc('0x33')]();};}function saveUpdates(_0xbabe1e,_0x406789){return function(_0x5ac7a8){if(_0x5ac7a8){return _0x5ac7a8[_0x4afc('0x34')](_0xbabe1e)['then'](function(_0x539b61){return _0x539b61;});}return null;};}function removeEntity(_0x324a12,_0x33ebbc){return function(_0x266f7f){if(_0x266f7f){return _0x266f7f[_0x4afc('0x35')]()[_0x4afc('0x1f')](function(){var _0x3f50cc=_0x266f7f['get']({'plain':!![]});var _0x380f9f=_0x4afc('0x36');return db[_0x4afc('0x37')][_0x4afc('0x35')]({'where':{'type':_0x380f9f,'resourceId':_0x3f50cc['id']}})[_0x4afc('0x1f')](function(){return _0x266f7f;});})[_0x4afc('0x1f')](function(){_0x324a12['status'](0xcc)[_0x4afc('0x2b')]();});}};}function handleEntityNotFound(_0x2ddce1,_0x91565d){return function(_0x283bc2){if(!_0x283bc2){_0x2ddce1['sendStatus'](0x194);}return _0x283bc2;};}function handleError(_0x4be1e6,_0x43c341){_0x43c341=_0x43c341||0x1f4;return function(_0x22bd75){logger[_0x4afc('0x25')](_0x22bd75['stack']);if(_0x22bd75['name']){delete _0x22bd75[_0x4afc('0x38')];}_0x4be1e6['status'](_0x43c341)['send'](_0x22bd75);};}exports[_0x4afc('0x39')]=function(_0x1dc853,_0x2be40e){var _0x3e41f5={'include':[{'model':db[_0x4afc('0x3a')],'as':_0x4afc('0x3b')}]},_0x395bc6={},_0x4420fb={'count':0x0,'rows':[]};var _0x3ccc5a=_[_0x4afc('0x3c')](db[_0x4afc('0x3d')][_0x4afc('0x3e')],function(_0x15c6cb){return{'name':_0x15c6cb[_0x4afc('0x3f')],'type':_0x15c6cb[_0x4afc('0x40')]['key']};});_0x395bc6[_0x4afc('0x41')]=_[_0x4afc('0x3c')](_0x3ccc5a,_0x4afc('0x38'));_0x395bc6[_0x4afc('0x42')]=_[_0x4afc('0x43')](_0x1dc853[_0x4afc('0x42')]);_0x395bc6[_0x4afc('0x44')]=_['intersection'](_0x395bc6['model'],_0x395bc6['query']);_0x3e41f5[_0x4afc('0x45')]=_[_0x4afc('0x46')](_0x395bc6['model'],qs[_0x4afc('0x47')](_0x1dc853[_0x4afc('0x42')][_0x4afc('0x47')]));_0x3e41f5[_0x4afc('0x45')]=_0x3e41f5['attributes'][_0x4afc('0x48')]?_0x3e41f5[_0x4afc('0x45')]:_0x395bc6[_0x4afc('0x41')];if(!_0x1dc853[_0x4afc('0x42')][_0x4afc('0x49')](_0x4afc('0x4a'))){_0x3e41f5['limit']=qs[_0x4afc('0x2d')](_0x1dc853['query'][_0x4afc('0x2d')]);_0x3e41f5[_0x4afc('0x2c')]=qs[_0x4afc('0x2c')](_0x1dc853['query']['offset']);}_0x3e41f5[_0x4afc('0x4b')]=qs[_0x4afc('0x4c')](_0x1dc853[_0x4afc('0x42')][_0x4afc('0x4c')]);_0x3e41f5[_0x4afc('0x4d')]=qs[_0x4afc('0x44')](_[_0x4afc('0x4e')](_0x1dc853[_0x4afc('0x42')],_0x395bc6['filters']),_0x3ccc5a);if(_0x1dc853[_0x4afc('0x42')][_0x4afc('0x4f')]){_0x3e41f5['where']=_[_0x4afc('0x50')](_0x3e41f5['where'],{'$or':_[_0x4afc('0x3c')](_0x3ccc5a,function(_0x24a731){if(_0x24a731[_0x4afc('0x40')]!=='VIRTUAL'){var _0xd0f517={};_0xd0f517[_0x24a731[_0x4afc('0x38')]]={'$like':'%'+_0x1dc853[_0x4afc('0x42')][_0x4afc('0x4f')]+'%'};return _0xd0f517;}})});}_0x3e41f5=_[_0x4afc('0x50')]({},_0x3e41f5,_0x1dc853[_0x4afc('0x51')]);var _0x5d9d90={'where':_0x3e41f5['where']};return db['OpenchannelAccount'][_0x4afc('0x52')](_0x5d9d90)[_0x4afc('0x1f')](function(_0x42e274){_0x4420fb[_0x4afc('0x52')]=_0x42e274;if(_0x1dc853[_0x4afc('0x42')][_0x4afc('0x53')]){_0x3e41f5[_0x4afc('0x54')]=[{'all':!![]}];}return db[_0x4afc('0x3d')][_0x4afc('0x55')](_0x3e41f5);})[_0x4afc('0x1f')](function(_0x48dbe3){_0x4420fb[_0x4afc('0x56')]=_0x48dbe3;return _0x4420fb;})['then'](respondWithFilteredResult(_0x2be40e,_0x3e41f5))['catch'](handleError(_0x2be40e,null));};exports[_0x4afc('0x57')]=function(_0x5c7606,_0x428d78){var _0x355198={'raw':![],'where':{'id':_0x5c7606[_0x4afc('0x58')]['id']},'include':[{'model':db['Pause'],'as':_0x4afc('0x3b')}]},_0x2fe2ae={};_0x2fe2ae['model']=_[_0x4afc('0x43')](db[_0x4afc('0x3d')][_0x4afc('0x3e')]);_0x2fe2ae[_0x4afc('0x42')]=_[_0x4afc('0x43')](_0x5c7606[_0x4afc('0x42')]);_0x2fe2ae[_0x4afc('0x44')]=_[_0x4afc('0x46')](_0x2fe2ae[_0x4afc('0x41')],_0x2fe2ae[_0x4afc('0x42')]);_0x355198[_0x4afc('0x45')]=_[_0x4afc('0x46')](_0x2fe2ae['model'],qs[_0x4afc('0x47')](_0x5c7606[_0x4afc('0x42')][_0x4afc('0x47')]));_0x355198[_0x4afc('0x45')]=_0x355198[_0x4afc('0x45')][_0x4afc('0x48')]?_0x355198[_0x4afc('0x45')]:_0x2fe2ae[_0x4afc('0x41')];if(_0x5c7606[_0x4afc('0x42')][_0x4afc('0x53')]){_0x355198[_0x4afc('0x54')]=[{'all':!![]}];}_0x355198=_[_0x4afc('0x50')]({},_0x355198,_0x5c7606[_0x4afc('0x51')]);return db['OpenchannelAccount'][_0x4afc('0x59')](_0x355198)['then'](handleEntityNotFound(_0x428d78,null))[_0x4afc('0x1f')](respondWithResult(_0x428d78,null))[_0x4afc('0x29')](handleError(_0x428d78,null));};exports[_0x4afc('0x5a')]=function(_0x2d9f3d,_0x518d6f){return db['OpenchannelAccount'][_0x4afc('0x5a')](_0x2d9f3d[_0x4afc('0x5b')],{})['then'](function(_0x40021e){var _0x3af52c=_0x2d9f3d[_0x4afc('0x5c')][_0x4afc('0x5d')]({'plain':!![]});if(!_0x3af52c)throw new Error(_0x4afc('0x5e'));if(_0x3af52c[_0x4afc('0x5f')]===_0x4afc('0x5c')){var _0x13891d=_0x40021e[_0x4afc('0x5d')]({'plain':!![]});var _0x3369a8=_0x4afc('0x36');return db[_0x4afc('0x60')][_0x4afc('0x59')]({'where':{'name':_0x3369a8,'userProfileId':_0x3af52c[_0x4afc('0x61')]},'raw':!![]})['then'](function(_0x42c65e){if(_0x42c65e&&_0x42c65e[_0x4afc('0x62')]===0x0){return db[_0x4afc('0x37')][_0x4afc('0x5a')]({'name':_0x13891d[_0x4afc('0x38')],'resourceId':_0x13891d['id'],'type':_0x42c65e[_0x4afc('0x38')],'sectionId':_0x42c65e['id']},{})[_0x4afc('0x1f')](function(){return _0x40021e;});}else{return _0x40021e;}})['catch'](function(_0x1771e8){logger[_0x4afc('0x25')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x1771e8);throw _0x1771e8;});}return _0x40021e;})['then'](respondWithResult(_0x518d6f,0xc9))[_0x4afc('0x29')](handleError(_0x518d6f,null));};exports[_0x4afc('0x34')]=function(_0x2d7066,_0x389040){if(_0x2d7066[_0x4afc('0x5b')]['id']){delete _0x2d7066[_0x4afc('0x5b')]['id'];}return db[_0x4afc('0x3d')][_0x4afc('0x59')]({'where':{'id':_0x2d7066[_0x4afc('0x58')]['id']},'include':[{'model':db[_0x4afc('0x3a')],'as':'mandatoryDispositionPause'}]})['then'](handleEntityNotFound(_0x389040,null))[_0x4afc('0x1f')](saveUpdates(_0x2d7066[_0x4afc('0x5b')],null))['then'](respondWithResult(_0x389040,null))[_0x4afc('0x29')](handleError(_0x389040,null));};exports[_0x4afc('0x35')]=function(_0x5be1a7,_0x56573a){return db[_0x4afc('0x3d')][_0x4afc('0x59')]({'where':{'id':_0x5be1a7[_0x4afc('0x58')]['id']}})['then'](handleEntityNotFound(_0x56573a,null))[_0x4afc('0x1f')](removeEntity(_0x56573a,null))['catch'](handleError(_0x56573a,null));};exports['describe']=function(_0x10e5c6,_0x37b5aa){return db[_0x4afc('0x3d')][_0x4afc('0x63')]()[_0x4afc('0x1f')](respondWithResult(_0x37b5aa,null))[_0x4afc('0x29')](handleError(_0x37b5aa,null));};exports[_0x4afc('0x64')]=function(_0xe05d53,_0x3d1825,_0x4a616e){if(_0xe05d53[_0x4afc('0x5b')]['id']){delete _0xe05d53[_0x4afc('0x5b')]['id'];}return db[_0x4afc('0x3d')]['find']({'where':{'id':_0xe05d53['params']['id']}})['then'](handleEntityNotFound(_0x3d1825,null))[_0x4afc('0x1f')](function(_0x135931){if(_0x135931){_0xe05d53[_0x4afc('0x5b')]['OpenchannelAccountId']=_0x135931['id'];return db[_0x4afc('0x65')]['create'](_0xe05d53['body']);}})['then'](respondWithResult(_0x3d1825,null))[_0x4afc('0x29')](handleError(_0x3d1825,null));};exports[_0x4afc('0x66')]=function(_0x315fc3,_0x4e0fb6,_0x1e56b7){var _0x45cfea={'raw':![],'where':{}};var _0x18ab12={};var _0x5e3e9b={'count':0x0,'rows':[]};return db[_0x4afc('0x3d')][_0x4afc('0x67')]({'where':{'id':_0x315fc3[_0x4afc('0x58')]['id']}})[_0x4afc('0x1f')](handleEntityNotFound(_0x4e0fb6,null))[_0x4afc('0x1f')](function(_0x481263){if(_0x481263){_0x18ab12['model']=_[_0x4afc('0x43')](db[_0x4afc('0x65')][_0x4afc('0x3e')]);_0x18ab12['query']=_[_0x4afc('0x43')](_0x315fc3[_0x4afc('0x42')]);_0x18ab12[_0x4afc('0x44')]=_[_0x4afc('0x46')](_0x18ab12[_0x4afc('0x41')],_0x18ab12['query']);_0x45cfea[_0x4afc('0x45')]=_[_0x4afc('0x46')](_0x18ab12['model'],qs[_0x4afc('0x47')](_0x315fc3[_0x4afc('0x42')][_0x4afc('0x47')]));_0x45cfea['attributes']=_0x45cfea[_0x4afc('0x45')][_0x4afc('0x48')]?_0x45cfea[_0x4afc('0x45')]:_0x18ab12[_0x4afc('0x41')];if(!_0x315fc3[_0x4afc('0x42')][_0x4afc('0x49')](_0x4afc('0x4a'))){_0x45cfea[_0x4afc('0x2d')]=qs['limit'](_0x315fc3[_0x4afc('0x42')]['limit']);_0x45cfea['offset']=qs[_0x4afc('0x2c')](_0x315fc3[_0x4afc('0x42')][_0x4afc('0x2c')]);}_0x45cfea['order']=qs['sort'](_0x315fc3[_0x4afc('0x42')][_0x4afc('0x4c')]);_0x45cfea[_0x4afc('0x4d')]=qs[_0x4afc('0x44')](_[_0x4afc('0x4e')](_0x315fc3[_0x4afc('0x42')],_0x18ab12[_0x4afc('0x44')]));_0x45cfea[_0x4afc('0x4d')][_0x4afc('0x68')]=_0x481263['id'];if(_0x315fc3[_0x4afc('0x42')][_0x4afc('0x4f')]){_0x45cfea[_0x4afc('0x4d')]=_[_0x4afc('0x50')](_0x45cfea[_0x4afc('0x4d')],{'$or':_[_0x4afc('0x3c')](_0x45cfea[_0x4afc('0x45')],function(_0x4f8b24){var _0x2d7d36={};_0x2d7d36[_0x4f8b24]={'$like':'%'+_0x315fc3[_0x4afc('0x42')][_0x4afc('0x4f')]+'%'};return _0x2d7d36;})});}_0x45cfea=_[_0x4afc('0x50')]({},_0x45cfea,_0x315fc3[_0x4afc('0x51')]);return db[_0x4afc('0x65')][_0x4afc('0x52')]({'where':_0x45cfea[_0x4afc('0x4d')]})[_0x4afc('0x1f')](function(_0x4d3da7){_0x5e3e9b[_0x4afc('0x52')]=_0x4d3da7;if(_0x315fc3[_0x4afc('0x42')][_0x4afc('0x53')]){_0x45cfea[_0x4afc('0x54')]=[{'all':!![]}];}return db['Disposition'][_0x4afc('0x55')](_0x45cfea);})[_0x4afc('0x1f')](function(_0x4ce81a){_0x5e3e9b[_0x4afc('0x56')]=_0x4ce81a;return _0x5e3e9b;});}})[_0x4afc('0x1f')](respondWithFilteredResult(_0x4e0fb6,_0x45cfea))[_0x4afc('0x29')](handleError(_0x4e0fb6,null));};exports[_0x4afc('0x69')]=function(_0xf9b232,_0x253d25,_0x2b20ad){return db['OpenchannelAccount'][_0x4afc('0x59')]({'where':{'id':_0xf9b232[_0x4afc('0x58')]['id']}})['then'](handleEntityNotFound(_0x253d25,null))[_0x4afc('0x1f')](function(_0x41a3a9){if(_0x41a3a9){return _0x41a3a9[_0x4afc('0x69')](_0xf9b232['query'][_0x4afc('0x6a')]);}})[_0x4afc('0x1f')](respondWithStatusCode(_0x253d25,null))[_0x4afc('0x29')](handleError(_0x253d25,null));};exports[_0x4afc('0x6b')]=function(_0x4a6f77,_0x1bbe21,_0x29297c){if(_0x4a6f77['body']['id']){delete _0x4a6f77[_0x4afc('0x5b')]['id'];}return db[_0x4afc('0x3d')][_0x4afc('0x59')]({'where':{'id':_0x4a6f77['params']['id']}})['then'](handleEntityNotFound(_0x1bbe21,null))[_0x4afc('0x1f')](function(_0x41116b){if(_0x41116b){_0x4a6f77[_0x4afc('0x5b')][_0x4afc('0x68')]=_0x41116b['id'];return db[_0x4afc('0x6c')][_0x4afc('0x5a')](_0x4a6f77[_0x4afc('0x5b')]);}})[_0x4afc('0x1f')](respondWithResult(_0x1bbe21,null))[_0x4afc('0x29')](handleError(_0x1bbe21,null));};exports[_0x4afc('0x6d')]=function(_0x32a7a3,_0x6d81f2,_0x2775ec){var _0x257d02={'raw':![],'where':{}};var _0x23a491={};var _0x143340={'count':0x0,'rows':[]};return db['OpenchannelAccount'][_0x4afc('0x67')]({'where':{'id':_0x32a7a3[_0x4afc('0x58')]['id']}})['then'](handleEntityNotFound(_0x6d81f2,null))[_0x4afc('0x1f')](function(_0x4d92e6){if(_0x4d92e6){_0x23a491['model']=_[_0x4afc('0x43')](db['CannedAnswer']['rawAttributes']);_0x23a491[_0x4afc('0x42')]=_['keys'](_0x32a7a3[_0x4afc('0x42')]);_0x23a491['filters']=_[_0x4afc('0x46')](_0x23a491[_0x4afc('0x41')],_0x23a491[_0x4afc('0x42')]);_0x257d02[_0x4afc('0x45')]=_[_0x4afc('0x46')](_0x23a491['model'],qs[_0x4afc('0x47')](_0x32a7a3[_0x4afc('0x42')]['fields']));_0x257d02['attributes']=_0x257d02[_0x4afc('0x45')][_0x4afc('0x48')]?_0x257d02[_0x4afc('0x45')]:_0x23a491[_0x4afc('0x41')];if(!_0x32a7a3[_0x4afc('0x42')]['hasOwnProperty'](_0x4afc('0x4a'))){_0x257d02[_0x4afc('0x2d')]=qs[_0x4afc('0x2d')](_0x32a7a3[_0x4afc('0x42')]['limit']);_0x257d02[_0x4afc('0x2c')]=qs['offset'](_0x32a7a3[_0x4afc('0x42')][_0x4afc('0x2c')]);}_0x257d02[_0x4afc('0x4b')]=qs[_0x4afc('0x4c')](_0x32a7a3[_0x4afc('0x42')][_0x4afc('0x4c')]);_0x257d02[_0x4afc('0x4d')]=qs[_0x4afc('0x44')](_[_0x4afc('0x4e')](_0x32a7a3[_0x4afc('0x42')],_0x23a491[_0x4afc('0x44')]));_0x257d02['where'][_0x4afc('0x68')]=_0x4d92e6['id'];if(_0x32a7a3['query'][_0x4afc('0x4f')]){_0x257d02['where']=_['merge'](_0x257d02[_0x4afc('0x4d')],{'$or':_['map'](_0x257d02['attributes'],function(_0x360d43){var _0x489c9d={};_0x489c9d[_0x360d43]={'$like':'%'+_0x32a7a3[_0x4afc('0x42')][_0x4afc('0x4f')]+'%'};return _0x489c9d;})});}_0x257d02=_['merge']({},_0x257d02,_0x32a7a3[_0x4afc('0x51')]);return db[_0x4afc('0x6c')]['count']({'where':_0x257d02[_0x4afc('0x4d')]})[_0x4afc('0x1f')](function(_0x3ec068){_0x143340['count']=_0x3ec068;if(_0x32a7a3[_0x4afc('0x42')][_0x4afc('0x53')]){_0x257d02[_0x4afc('0x54')]=[{'all':!![]}];}return db[_0x4afc('0x6c')][_0x4afc('0x55')](_0x257d02);})[_0x4afc('0x1f')](function(_0x5cc914){_0x143340['rows']=_0x5cc914;return _0x143340;});}})[_0x4afc('0x1f')](respondWithFilteredResult(_0x6d81f2,_0x257d02))[_0x4afc('0x29')](handleError(_0x6d81f2,null));};exports['removeAnswers']=function(_0x28381d,_0x2ff7a1,_0x4f2536){return db[_0x4afc('0x3d')][_0x4afc('0x59')]({'where':{'id':_0x28381d[_0x4afc('0x58')]['id']}})[_0x4afc('0x1f')](handleEntityNotFound(_0x2ff7a1,null))[_0x4afc('0x1f')](function(_0x4b1bbc){if(_0x4b1bbc){return _0x4b1bbc[_0x4afc('0x6e')](_0x28381d[_0x4afc('0x42')][_0x4afc('0x6a')]);}})[_0x4afc('0x1f')](respondWithStatusCode(_0x2ff7a1,null))[_0x4afc('0x29')](handleError(_0x2ff7a1,null));};exports['notify']=function(_0x793480,_0x37f9ea,_0x31b518){var _0x57a878={'body':_0x793480[_0x4afc('0x5b')],'channel':_0x4afc('0x6f')};var _0x5bcfa7=[];var _0x530119=[];var _0x4c27a2={};var _0x1119a9=![];return db[_0x4afc('0x70')]['describe']()[_0x4afc('0x1f')](function(_0x46fe46){if(!_0x46fe46){throw new db['Sequelize'][(_0x4afc('0x71'))](_0x4afc('0x72'));}_0x5bcfa7=_[_0x4afc('0x73')](_[_0x4afc('0x43')](_0x46fe46),[_0x4afc('0x74'),_0x4afc('0x75')]);_0x530119=_[_0x4afc('0x73')](_[_0x4afc('0x43')](_0x46fe46),[_0x4afc('0x74'),'updatedAt',_0x4afc('0x76'),_0x4afc('0x77')]);if(_0x793480[_0x4afc('0x5b')]['id']){delete _0x793480[_0x4afc('0x5b')]['id'];}if(_['isNil'](_0x793480[_0x4afc('0x5b')][_0x4afc('0x78')])){throw new db['Sequelize']['ValidationError']('from\x20is\x20mandatory');}if(_[_0x4afc('0x79')](_0x793480[_0x4afc('0x5b')][_0x4afc('0x5b')])||_0x793480['body'][_0x4afc('0x5b')]===''){throw new db[(_0x4afc('0x7a'))][(_0x4afc('0x71'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x4afc('0x79')](_0x793480['body']['mapKey'])){throw new db[(_0x4afc('0x7a'))][(_0x4afc('0x71'))](_0x4afc('0x7b')+_0x530119);}if(!_['includes'](_0x530119,_0x793480[_0x4afc('0x5b')][_0x4afc('0x7c')])){throw new db[(_0x4afc('0x7a'))][(_0x4afc('0x71'))](_0x4afc('0x7d')+_0x530119);}_0x4c27a2[_0x793480[_0x4afc('0x5b')][_0x4afc('0x7c')]]=_0x793480[_0x4afc('0x5b')][_0x4afc('0x78')];})['then'](function(){return db['OpenchannelAccount'][_0x4afc('0x59')]({'where':{'id':_0x793480[_0x4afc('0x58')]['id']},'include':[{'model':db[_0x4afc('0x7e')],'as':_0x4afc('0x7f'),'include':[{'model':db['CmContact'],'as':_0x4afc('0x80'),'where':_0x4c27a2,'limit':0x1,'order':[['updatedAt','DESC']]}]},{'model':db['OpenchannelApplication'],'as':_0x4afc('0x81')}]});})[_0x4afc('0x1f')](handleEntityNotFound(_0x37f9ea,null))[_0x4afc('0x1f')](function(_0x3e26e9){if(_0x3e26e9&&_0x3e26e9[_0x4afc('0x7f')]){_0x57a878[_0x4afc('0x82')]=_0x3e26e9;_0x57a878[_0x4afc('0x83')]=_0x3e26e9[_0x4afc('0x81')];_0x57a878[_0x4afc('0x84')]=_0x3e26e9[_0x4afc('0x7f')];_0x57a878[_0x4afc('0x83')]=_[_0x4afc('0x85')](_0x57a878[_0x4afc('0x83')],['priority'],[_0x4afc('0x86')]);if(_0x57a878[_0x4afc('0x82')][_0x4afc('0x81')]){delete _0x57a878[_0x4afc('0x82')]['Applications'];}if(_0x57a878[_0x4afc('0x82')][_0x4afc('0x7f')]&&_0x57a878['account'][_0x4afc('0x7f')][_0x4afc('0x80')][_0x4afc('0x48')]){return _0x57a878[_0x4afc('0x82')]['List'][_0x4afc('0x80')][0x0];}var _0x12aadc=_[_0x4afc('0x17')](_0x793480['body'],{'firstName':_0x793480[_0x4afc('0x5b')][_0x4afc('0x78')],'ListId':_0x3e26e9['ListId']});_0x12aadc[_0x793480[_0x4afc('0x5b')]['mapKey']]=_0x793480[_0x4afc('0x5b')][_0x4afc('0x78')];return db[_0x4afc('0x70')][_0x4afc('0x5a')](_0x12aadc,{'fields':_0x5bcfa7,'raw':!![]});}})[_0x4afc('0x1f')](handleEntityNotFound(_0x37f9ea,null))[_0x4afc('0x1f')](function(_0x3aff77){_0x57a878[_0x4afc('0x87')]=_0x3aff77;if(_0x3aff77){var _0x518a6f={'ContactId':_0x3aff77['id'],'OpenchannelAccountId':_0x793480['params']['id'],'from':(_0x3aff77[_0x4afc('0x88')]||'')+'\x20'+(_0x3aff77[_0x4afc('0x89')]||'')};var _0x434314={'OpenchannelAccountId':_0x793480['params']['id'],'closed':![]};if(_0x793480[_0x4afc('0x5b')][_0x4afc('0x8a')]){_0x434314['threadId']=_0x793480[_0x4afc('0x5b')][_0x4afc('0x8a')];return db[_0x4afc('0x8b')]['find']({'where':_0x434314})[_0x4afc('0x1f')](function(_0x43a30c){if(_0x43a30c){return[_0x43a30c,![]];}_0x518a6f[_0x4afc('0x8a')]=_0x793480['body'][_0x4afc('0x8a')];_0x518a6f[_0x4afc('0x8c')]=_0x793480[_0x4afc('0x5b')][_0x4afc('0x8c')];return db[_0x4afc('0x8b')][_0x4afc('0x5a')](_0x518a6f)[_0x4afc('0x1f')](function(_0x2e1881){return[_0x2e1881,!![]];});});}else{_0x434314[_0x4afc('0x8a')]=null;}_0x434314['ContactId']=_0x3aff77['id'];return db[_0x4afc('0x8b')][_0x4afc('0x59')]({'where':_0x434314})[_0x4afc('0x1f')](function(_0x4ee2aa){if(_0x4ee2aa){return[_0x4ee2aa,![]];}return db['OpenchannelInteraction'][_0x4afc('0x5a')](_0x518a6f)[_0x4afc('0x1f')](function(_0x2ddf9f){return[_0x2ddf9f,!![]];});});}})[_0x4afc('0x8d')](function(_0xc8fba2,_0x4118f3){if(_0xc8fba2){_0x1119a9=_0x4118f3;if(!_0x4118f3){var _0x1ef0de={'from':(_0x57a878[_0x4afc('0x87')][_0x4afc('0x88')]||'')+'\x20'+(_0x57a878['contact'][_0x4afc('0x89')]||'')};if(_0x793480[_0x4afc('0x5b')][_0x4afc('0x8a')]&&_0x793480['body'][_0x4afc('0x8e')]&&_0x793480[_0x4afc('0x5b')][_0x4afc('0x8a')]!=_0x793480['body'][_0x4afc('0x8e')]){_0x1ef0de[_0x4afc('0x8a')]=_0x793480[_0x4afc('0x5b')][_0x4afc('0x8e')];}return _0xc8fba2[_0x4afc('0x34')](_0x1ef0de);}else{return _0xc8fba2;}}})[_0x4afc('0x1f')](function(_0x4b9745){_0x57a878[_0x4afc('0x8f')]=_0x4b9745['get']({'plain':!![]});_0x57a878['interaction'][_0x4afc('0x90')]=_0x1119a9;if(_0x57a878['interaction'][_0x4afc('0x90')]){if(_0x57a878[_0x4afc('0x82')][_0x4afc('0x91')]){_0x57a878[_0x4afc('0x83')]['push']({'id':0x0,'priority':_0x57a878[_0x4afc('0x83')]['length']+0x1,'app':_0x4afc('0x92'),'appdata':_0x4afc('0x93'),'interval':'*,*,*,*'});}}return db[_0x4afc('0x94')][_0x4afc('0x5a')]({'body':_0x793480[_0x4afc('0x5b')][_0x4afc('0x5b')],'OpenchannelAccountId':_0x793480['params']['id'],'OpenchannelInteractionId':_0x4b9745['id'],'direction':'in','ContactId':_0x57a878[_0x4afc('0x87')]['id'],'AttachmentId':_0x793480['body'][_0x4afc('0x95')]});})[_0x4afc('0x1f')](function(_0x4c8632){_0x57a878[_0x4afc('0x27')]=_0x4c8632;if(_0x57a878[_0x4afc('0x8f')][_0x4afc('0x96')]){return db[_0x4afc('0x97')]['find']({'attributes':['id',_0x4afc('0x38')],'where':{'id':_0x57a878['interaction'][_0x4afc('0x96')]}})[_0x4afc('0x1f')](function(_0x3377c5){if(_0x3377c5){_0x57a878[_0x4afc('0x83')][_0x4afc('0x98')]({'id':0x0,'priority':0x0,'app':_0x4afc('0x99'),'appdata':_0x3377c5['name']+','+(_0x57a878['account'][_0x4afc('0x9a')]||0xa),'interval':_0x4afc('0x9b')});_0x57a878[_0x4afc('0x9c')]=![];}return respondWithRpcPromise(_0x4afc('0x9d'),_0x4afc('0x9e'),_0x57a878);});}return respondWithRpcPromise(_0x4afc('0x9d'),'startRouting',_0x57a878);})[_0x4afc('0x1f')](function(_0x17771b){respondWithRpcPromise(_0x4afc('0x9f'),_0x4afc('0x9f'),{'event':_0x4afc('0xa0'),'message':_0x17771b},client9002);return _0x17771b;})['then'](respondWithResult(_0x37f9ea,null))[_0x4afc('0x29')](handleError(_0x37f9ea,null));};exports[_0x4afc('0xa1')]=function(_0x2e2f0a,_0x54cbfa,_0x17443e){return db[_0x4afc('0x3d')][_0x4afc('0x67')]({'where':{'id':_0x2e2f0a[_0x4afc('0x58')]['id']}})[_0x4afc('0x1f')](handleEntityNotFound(_0x54cbfa,null))[_0x4afc('0x1f')](function(_0x164b69){if(_0x164b69){return db[_0x4afc('0xa2')]['transaction'](function(_0x20ba44){return db[_0x4afc('0xa3')][_0x4afc('0x35')]({'where':{'OpenchannelAccountId':_0x2e2f0a[_0x4afc('0x58')]['id']},'transaction':_0x20ba44})[_0x4afc('0x1f')](function(_0xc36399){var _0x23a727=_['map'](_0x2e2f0a[_0x4afc('0x5b')],function(_0x45e4f4){_0x45e4f4[_0x4afc('0x68')]=_0x2e2f0a[_0x4afc('0x58')]['id'];return _0x45e4f4;});return db[_0x4afc('0xa3')][_0x4afc('0xa4')](_0x23a727,{'transaction':_0x20ba44});});})[_0x4afc('0x1f')](function(){return db['OpenchannelApplication']['findAndCountAll']({'where':{'OpenchannelAccountId':_0x2e2f0a[_0x4afc('0x58')]['id']},'order':'priority'});});}})[_0x4afc('0x1f')](respondWithResult(_0x54cbfa,null))[_0x4afc('0x29')](handleError(_0x54cbfa,null));};exports[_0x4afc('0xa5')]=function(_0x51dd4d,_0x75a628,_0x1ea1cb){var _0x1033a8={};var _0x31757b={};var _0x4a62e1;var _0x481418;return db[_0x4afc('0x3d')][_0x4afc('0x67')]({'where':{'id':_0x51dd4d[_0x4afc('0x58')]['id']}})['then'](handleEntityNotFound(_0x75a628,null))[_0x4afc('0x1f')](function(_0x48830a){if(_0x48830a){_0x4a62e1=_0x48830a;_0x31757b[_0x4afc('0x41')]=_['keys'](db[_0x4afc('0xa3')]['rawAttributes']);_0x31757b[_0x4afc('0x42')]=_['keys'](_0x51dd4d[_0x4afc('0x42')]);_0x31757b[_0x4afc('0x44')]=_[_0x4afc('0x46')](_0x31757b['model'],_0x31757b[_0x4afc('0x42')]);_0x1033a8['attributes']=_[_0x4afc('0x46')](_0x31757b['model'],qs[_0x4afc('0x47')](_0x51dd4d[_0x4afc('0x42')]['fields']));_0x1033a8[_0x4afc('0x45')]=_0x1033a8['attributes']['length']?_0x1033a8[_0x4afc('0x45')]:_0x31757b[_0x4afc('0x41')];_0x1033a8[_0x4afc('0x4b')]=qs[_0x4afc('0x4c')](_0x51dd4d[_0x4afc('0x42')][_0x4afc('0x4c')]);_0x1033a8[_0x4afc('0x4d')]=qs[_0x4afc('0x44')](_[_0x4afc('0x4e')](_0x51dd4d['query'],_0x31757b[_0x4afc('0x44')]));if(_0x51dd4d[_0x4afc('0x42')][_0x4afc('0x4f')]){_0x1033a8[_0x4afc('0x4d')]=_[_0x4afc('0x50')](_0x1033a8['where'],{'$or':_[_0x4afc('0x3c')](_0x1033a8['attributes'],function(_0x399644){var _0x14c79c={};_0x14c79c[_0x399644]={'$like':'%'+_0x51dd4d['query'][_0x4afc('0x4f')]+'%'};return _0x14c79c;})});}_0x1033a8=_[_0x4afc('0x50')]({},_0x1033a8,_0x51dd4d['options']);return _0x4a62e1[_0x4afc('0xa5')](_0x1033a8);}})[_0x4afc('0x1f')](function(_0xffddad){if(_0xffddad){_0x481418=_0xffddad['length'];if(!_0x51dd4d['query'][_0x4afc('0x49')](_0x4afc('0x4a'))){_0x1033a8[_0x4afc('0x2d')]=qs[_0x4afc('0x2d')](_0x51dd4d[_0x4afc('0x42')][_0x4afc('0x2d')]);_0x1033a8[_0x4afc('0x2c')]=qs['offset'](_0x51dd4d[_0x4afc('0x42')][_0x4afc('0x2c')]);}return _0x4a62e1[_0x4afc('0xa5')](_0x1033a8);}})[_0x4afc('0x1f')](function(_0x1a3f6a){if(_0x1a3f6a){return _0x1a3f6a?{'count':_0x481418,'rows':_0x1a3f6a}:null;}})[_0x4afc('0x1f')](respondWithResult(_0x75a628,null))[_0x4afc('0x29')](handleError(_0x75a628,null));};exports['getInteractions']=function(_0xc0ff4e,_0x5a492d,_0x2177a3){var _0x21a41f={'raw':![],'where':{}};var _0xbe1818={};var _0x354f3a={'count':0x0,'rows':[]};return db[_0x4afc('0x3d')]['findOne']({'where':{'id':_0xc0ff4e['params']['id']}})[_0x4afc('0x1f')](handleEntityNotFound(_0x5a492d,null))['then'](function(_0x5d8cb3){if(_0x5d8cb3){_0xbe1818[_0x4afc('0x41')]=_[_0x4afc('0x43')](db['OpenchannelInteraction'][_0x4afc('0x3e')]);_0xbe1818[_0x4afc('0x42')]=_['keys'](_0xc0ff4e[_0x4afc('0x42')]);_0xbe1818[_0x4afc('0x44')]=_[_0x4afc('0x46')](_0xbe1818[_0x4afc('0x41')],_0xbe1818[_0x4afc('0x42')]);_0x21a41f['attributes']=_['intersection'](_0xbe1818[_0x4afc('0x41')],qs[_0x4afc('0x47')](_0xc0ff4e[_0x4afc('0x42')]['fields']));_0x21a41f['attributes']=_0x21a41f['attributes']['length']?_0x21a41f[_0x4afc('0x45')]:_0xbe1818[_0x4afc('0x41')];if(!_0xc0ff4e[_0x4afc('0x42')][_0x4afc('0x49')]('nolimit')){_0x21a41f[_0x4afc('0x2d')]=qs[_0x4afc('0x2d')](_0xc0ff4e[_0x4afc('0x42')][_0x4afc('0x2d')]);_0x21a41f['offset']=qs[_0x4afc('0x2c')](_0xc0ff4e[_0x4afc('0x42')][_0x4afc('0x2c')]);}_0x21a41f[_0x4afc('0x4b')]=qs[_0x4afc('0x4c')](_0xc0ff4e[_0x4afc('0x42')]['sort']);_0x21a41f[_0x4afc('0x4d')]=qs[_0x4afc('0x44')](_['pick'](_0xc0ff4e[_0x4afc('0x42')],_0xbe1818['filters']));_0x21a41f['where'][_0x4afc('0x68')]=_0x5d8cb3['id'];if(_0xc0ff4e[_0x4afc('0x42')][_0x4afc('0x4f')]){_0x21a41f[_0x4afc('0x4d')]=_[_0x4afc('0x50')](_0x21a41f[_0x4afc('0x4d')],{'$or':_[_0x4afc('0x3c')](_0x21a41f['attributes'],function(_0x253e57){var _0x36f6ad={};_0x36f6ad[_0x253e57]={'$like':'%'+_0xc0ff4e['query'][_0x4afc('0x4f')]+'%'};return _0x36f6ad;})});}_0x21a41f=_[_0x4afc('0x50')]({},_0x21a41f,_0xc0ff4e['options']);return db[_0x4afc('0x8b')][_0x4afc('0x52')]({'where':_0x21a41f[_0x4afc('0x4d')]})['then'](function(_0x409be5){_0x354f3a[_0x4afc('0x52')]=_0x409be5;if(_0xc0ff4e[_0x4afc('0x42')]['includeAll']){_0x21a41f['include']=[{'model':db[_0x4afc('0x70')],'as':'Contact','required':![]},{'model':db[_0x4afc('0x97')],'as':_0x4afc('0xa6'),'attributes':[_0x4afc('0x38'),'fullname','internal'],'required':![]},{'model':db[_0x4afc('0xa7')],'as':_0x4afc('0xa8'),'attributes':['id',_0x4afc('0x38'),_0x4afc('0xa9')],'where':_0xc0ff4e[_0x4afc('0x42')][_0x4afc('0xaa')]?{'id':_0xc0ff4e['query'][_0x4afc('0xaa')]}:undefined,'required':_0xc0ff4e[_0x4afc('0x42')][_0x4afc('0xaa')]?!![]:![]}];}return db[_0x4afc('0x8b')][_0x4afc('0x55')](_0x21a41f);})['then'](function(_0x1da8c0){_0x354f3a[_0x4afc('0x56')]=_0x1da8c0;return _0x354f3a;});}})[_0x4afc('0x1f')](respondWithFilteredResult(_0x5a492d,_0x21a41f))['catch'](handleError(_0x5a492d,null));};exports[_0x4afc('0xab')]=function(_0x133d22,_0x5256df,_0x537fae){return db[_0x4afc('0x3d')][_0x4afc('0x59')]({'where':{'id':_0x133d22[_0x4afc('0x58')]['id']}})[_0x4afc('0x1f')](handleEntityNotFound(_0x5256df,null))[_0x4afc('0x1f')](function(_0x4f68fa){if(_0x4f68fa){return _0x4f68fa[_0x4afc('0xab')](_0x133d22[_0x4afc('0x5b')]['ids'],_[_0x4afc('0xac')](_0x133d22[_0x4afc('0x5b')],['ids','id'])||{})[_0x4afc('0x8d')](function(_0x17940a){for(var _0x3b3226=0x0;_0x3b3226<_0x133d22[_0x4afc('0x5b')][_0x4afc('0x6a')][_0x4afc('0x48')];_0x3b3226+=0x1){socket['emit'](_0x4afc('0xad'),{'UserId':_0x133d22[_0x4afc('0x5b')][_0x4afc('0x6a')][_0x3b3226],'OpenchannelAccountId':_0x133d22[_0x4afc('0x58')]['id']});}return _0x17940a;});}})['then'](respondWithResult(_0x5256df,null))[_0x4afc('0x29')](handleError(_0x5256df,null));};exports[_0x4afc('0xae')]=function(_0x3cac2f,_0x127814,_0x49ee03){return db[_0x4afc('0x3d')][_0x4afc('0x59')]({'where':{'id':_0x3cac2f[_0x4afc('0x58')]['id']}})[_0x4afc('0x1f')](handleEntityNotFound(_0x127814,null))[_0x4afc('0x1f')](function(_0x338de8){if(_0x338de8){return _0x338de8[_0x4afc('0xae')](_0x3cac2f['query']['ids'])['then'](function(){if(_[_0x4afc('0xaf')](_0x3cac2f['query'][_0x4afc('0x6a')])){for(var _0x4e05af=0x0;_0x4e05af<_0x3cac2f[_0x4afc('0x42')][_0x4afc('0x6a')][_0x4afc('0x48')];_0x4e05af+=0x1){socket['emit'](_0x4afc('0xb0'),{'UserId':Number(_0x3cac2f[_0x4afc('0x42')][_0x4afc('0x6a')][_0x4e05af]),'OpenchannelAccountId':Number(_0x3cac2f[_0x4afc('0x58')]['id'])});}}else{socket['emit'](_0x4afc('0xb0'),{'UserId':Number(_0x3cac2f[_0x4afc('0x42')][_0x4afc('0x6a')]),'OpenchannelAccountId':Number(_0x3cac2f['params']['id'])});}});}})[_0x4afc('0x1f')](respondWithStatusCode(_0x127814,null))[_0x4afc('0x29')](handleError(_0x127814,null));};exports['getAgents']=function(_0x43f64e,_0x2e041a,_0x6ad393){var _0x1d6bd2={};var _0x2864fa={};var _0x48d0ee;var _0x563172;return db[_0x4afc('0x3d')][_0x4afc('0x67')]({'where':{'id':_0x43f64e[_0x4afc('0x58')]['id']}})[_0x4afc('0x1f')](handleEntityNotFound(_0x2e041a,null))[_0x4afc('0x1f')](function(_0x5152ab){if(_0x5152ab){_0x48d0ee=_0x5152ab;_0x2864fa[_0x4afc('0x41')]=_[_0x4afc('0x43')](db[_0x4afc('0x97')][_0x4afc('0x3e')]);_0x2864fa['query']=_[_0x4afc('0x43')](_0x43f64e[_0x4afc('0x42')]);_0x2864fa[_0x4afc('0x44')]=_[_0x4afc('0x46')](_0x2864fa[_0x4afc('0x41')],_0x2864fa[_0x4afc('0x42')]);_0x1d6bd2[_0x4afc('0x45')]=_['intersection'](_0x2864fa[_0x4afc('0x41')],qs[_0x4afc('0x47')](_0x43f64e[_0x4afc('0x42')]['fields']));_0x1d6bd2['attributes']=_0x1d6bd2['attributes']['length']?_0x1d6bd2['attributes']:_0x2864fa[_0x4afc('0x41')];_0x1d6bd2['order']=qs[_0x4afc('0x4c')](_0x43f64e[_0x4afc('0x42')][_0x4afc('0x4c')]);_0x1d6bd2['where']=qs[_0x4afc('0x44')](_[_0x4afc('0x4e')](_0x43f64e[_0x4afc('0x42')],_0x2864fa[_0x4afc('0x44')]));if(_0x43f64e[_0x4afc('0x42')][_0x4afc('0x4f')]){_0x1d6bd2[_0x4afc('0x4d')]=_[_0x4afc('0x50')](_0x1d6bd2['where'],{'$or':_[_0x4afc('0x3c')](_0x1d6bd2[_0x4afc('0x45')],function(_0x5f3751){var _0x2d7590={};_0x2d7590[_0x5f3751]={'$like':'%'+_0x43f64e[_0x4afc('0x42')]['filter']+'%'};return _0x2d7590;})});}_0x1d6bd2=_['merge']({},_0x1d6bd2,_0x43f64e[_0x4afc('0x51')]);return _0x48d0ee[_0x4afc('0xb1')](_0x1d6bd2);}})[_0x4afc('0x1f')](function(_0x444e1a){if(_0x444e1a){_0x563172=_0x444e1a['length'];if(!_0x43f64e[_0x4afc('0x42')][_0x4afc('0x49')](_0x4afc('0x4a'))){_0x1d6bd2[_0x4afc('0x2d')]=qs['limit'](_0x43f64e['query']['limit']);_0x1d6bd2[_0x4afc('0x2c')]=qs[_0x4afc('0x2c')](_0x43f64e['query'][_0x4afc('0x2c')]);}return _0x48d0ee['getAgents'](_0x1d6bd2);}})['then'](function(_0x319692){if(_0x319692){return _0x319692?{'count':_0x563172,'rows':_0x319692}:null;}})['then'](respondWithResult(_0x2e041a,null))[_0x4afc('0x29')](handleError(_0x2e041a,null));};exports[_0x4afc('0xb2')]=function(_0x33ee71,_0x172a8a,_0x316e76){var _0x485f68,_0x39c4b5,_0x5bb7b9;if(_[_0x4afc('0x79')](_0x33ee71[_0x4afc('0x5b')][_0x4afc('0x5b')])||_0x33ee71[_0x4afc('0x5b')][_0x4afc('0x5b')]===''){throw new db['Sequelize'][(_0x4afc('0x71'))](_0x4afc('0xb3'));}if(_[_0x4afc('0x79')](_0x33ee71[_0x4afc('0x5b')]['to'])){}_0x485f68=_0x33ee71['body']['to'];return db[_0x4afc('0x3d')][_0x4afc('0x67')]({'where':{'id':_0x33ee71['params']['id']}})[_0x4afc('0x1f')](handleEntityNotFound(_0x172a8a,null))['then'](function(_0x588d22){if(_0x588d22){return db[_0x4afc('0x3d')][_0x4afc('0x59')]({'where':{'id':_0x588d22['id']},'include':[{'model':db[_0x4afc('0x7e')],'as':_0x4afc('0x7f'),'include':[{'model':db[_0x4afc('0x70')],'as':_0x4afc('0x80'),'where':{[_0x588d22[_0x4afc('0x7c')]]:_0x485f68},'limit':0x1,'order':[[_0x4afc('0x75'),_0x4afc('0xb4')]]}]}]})[_0x4afc('0x1f')](handleEntityNotFound(_0x172a8a,null))['then'](function(_0x46d574){if(_0x46d574&&_0x46d574[_0x4afc('0x7f')]){_0x39c4b5=_0x46d574[_0x4afc('0x5d')]({'plain':!![]});if(_0x39c4b5[_0x4afc('0x7f')]&&_0x39c4b5['List'][_0x4afc('0x80')][_0x4afc('0x48')]){return _0x39c4b5[_0x4afc('0x7f')][_0x4afc('0x80')][0x0];}return db[_0x4afc('0x70')][_0x4afc('0x5a')](_[_0x4afc('0x17')](_0x33ee71['body'],{'firstName':_0x485f68,[_0x46d574['mapKey']]:_0x485f68,'phone':_0x485f68,'ListId':_0x39c4b5['ListId']}));}})['then'](handleEntityNotFound(_0x172a8a,null))[_0x4afc('0x1f')](function(_0x3af1d3){if(_0x3af1d3){_0x5bb7b9=_0x3af1d3;return db[_0x4afc('0x8b')][_0x4afc('0x59')]({'where':{'ContactId':_0x5bb7b9['id'],'closed':![],'OpenchannelAccountId':_0x39c4b5['id']}})[_0x4afc('0x1f')](function(_0x938d9a){if(_0x938d9a){return[_0x938d9a,![]];}return db[_0x4afc('0x8b')]['create']({'UserId':_0x33ee71[_0x4afc('0x5c')]['id'],'ContactId':_0x5bb7b9['id'],'OpenchannelAccountId':_0x39c4b5['id'],'lastMsgDirection':_0x4afc('0xb5'),'Messages':[_[_0x4afc('0x50')](_0x33ee71[_0x4afc('0x5b')],{'read':![],'body':_0x33ee71[_0x4afc('0x5b')][_0x4afc('0x5b')],'OpenchannelAccountId':_0x39c4b5['id'],'UserId':_0x33ee71[_0x4afc('0x5c')]['id'],'ContactId':_0x5bb7b9['id']})]},{'include':[{'model':db['OpenchannelMessage'],'as':'Messages'}]})[_0x4afc('0x1f')](function(_0x2fb006){return[_0x2fb006,!![]];});});}})[_0x4afc('0x8d')](function(_0xa1b979,_0xef44ed){if(_0xef44ed){return _0xa1b979;}return db[_0x4afc('0x94')][_0x4afc('0x5a')](_[_0x4afc('0x50')](_0x33ee71[_0x4afc('0x5b')],{'read':![],'body':_0x33ee71[_0x4afc('0x5b')]['body'],'OpenchannelAccountId':_0x39c4b5['id'],'OpenchannelInteractionId':_0xa1b979['id'],'UserId':_0x33ee71[_0x4afc('0x5c')]['id'],'ContactId':_0x5bb7b9['id']}))[_0x4afc('0x1f')](function(_0x394182){_0xa1b979[_0x4afc('0xb6')][_0x4afc('0xb7')]=[];_0xa1b979[_0x4afc('0xb6')][_0x4afc('0xb7')][_0x4afc('0xb8')](_0x394182[_0x4afc('0xb6')]);return _0xa1b979;});});}})[_0x4afc('0x1f')](respondWithResult(_0x172a8a,null))[_0x4afc('0x29')](handleError(_0x172a8a,null));};
\ No newline at end of file
+var _0x89b2=['Tag','Tags','color','tag','addAgents','emit','userOpenchannelAccount:save','removeAgents','userOpenchannelAccount:remove','getAgents','send','updatedAt','out','dataValues','Messages','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','fs-extra','crypto','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/license/util','../../mysqldb','defaults','localhost','socket.io-emitter','redis','./openchannelAccount.socket','register','jayson/promise','client','http','request','then','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','catch','sendStatus','status','end','json','undefined','limit','count','offset','set','apply','reject','save','update','destroy','get','UserProfileResource','stack','name','Pause','mandatoryDispositionPause','rawAttributes','fieldName','type','key','model','query','keys','intersection','attributes','fields','hasOwnProperty','order','sort','where','pick','filters','filter','merge','map','VIRTUAL','OpenchannelAccount','includeAll','include','rows','show','params','length','options','find','create','user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','describe','addDisposition','OpenchannelAccountId','Disposition','getDispositions','findOne','findAll','removeDispositions','ids','CannedAnswer','nolimit','removeAnswers','notify','openchannel','CmContact','Sequelize','ValidationError','difference','createdAt','CompanyId','ListId','isNil','from','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','List','Contacts','DESC','Applications','account','applications','list','orderBy','priority','asc','lastName','threadId','OpenchannelInteraction','externalUrl','ContactId','contact','firstName','messageId','interaction','created','push','close','*,*,*,*','OpenchannelMessage','User','forcedOwnership','Start','startRouting','EventManager','addApplications','transaction','sequelize','Transaction','OpenchannelApplication','finally','getApplications','getInteractions','Contact','fullname','internal'];(function(_0x199bc4,_0x338105){var _0x136ffb=function(_0x3e7ced){while(--_0x3e7ced){_0x199bc4['push'](_0x199bc4['shift']());}};_0x136ffb(++_0x338105);}(_0x89b2,0xc6));var _0x289b=function(_0x486f0b,_0x19a9b7){_0x486f0b=_0x486f0b-0x0;var _0x12ccaf=_0x89b2[_0x486f0b];return _0x12ccaf;};'use strict';var emlformat=require(_0x289b('0x0'));var rimraf=require(_0x289b('0x1'));var zipdir=require(_0x289b('0x2'));var jsonpatch=require(_0x289b('0x3'));var rp=require(_0x289b('0x4'));var moment=require(_0x289b('0x5'));var BPromise=require(_0x289b('0x6'));var Mustache=require(_0x289b('0x7'));var util=require(_0x289b('0x8'));var path=require(_0x289b('0x9'));var sox=require(_0x289b('0xa'));var csv=require(_0x289b('0xb'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x289b('0xc'));var _=require('lodash');var squel=require('squel');var crypto=require(_0x289b('0xd'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x289b('0xe'));var Papa=require(_0x289b('0xf'));var Redis=require(_0x289b('0x10'));var authService=require(_0x289b('0x11'));var qs=require(_0x289b('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x289b('0x13'));var logger=require('../../config/logger')(_0x289b('0x14'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x289b('0x15'));var db=require(_0x289b('0x16'))['db'];config['redis']=_[_0x289b('0x17')](config['redis'],{'host':_0x289b('0x18'),'port':0x18eb});var socket=require(_0x289b('0x19'))(new Redis(config[_0x289b('0x1a')]));require(_0x289b('0x1b'))[_0x289b('0x1c')](socket);var jayson=require(_0x289b('0x1d'));var client=jayson[_0x289b('0x1e')][_0x289b('0x1f')]({'port':0x232c});var client9002=jayson[_0x289b('0x1e')][_0x289b('0x1f')]({'port':0x232a});function respondWithRpcPromise(_0x1a6807,_0x345a5f,_0x405a2c,_0x3a7c07){return new BPromise(function(_0x5e3dcd,_0x117ef9){var _0x1d36dd=_0x3a7c07||client;return _0x1d36dd[_0x289b('0x20')](_0x1a6807,_0x405a2c)[_0x289b('0x21')](function(_0x39ba6f){logger['info'](_0x289b('0x22'),_0x345a5f,_0x289b('0x23'));logger['debug'](_0x289b('0x24'),_0x345a5f,_0x289b('0x23'),JSON[_0x289b('0x25')](_0x39ba6f));if(_0x39ba6f[_0x289b('0x26')]){if(_0x39ba6f[_0x289b('0x26')][_0x289b('0x27')]===0x1f4){logger[_0x289b('0x26')](_0x289b('0x22'),_0x345a5f,_0x39ba6f[_0x289b('0x26')][_0x289b('0x28')]);return _0x117ef9(_0x39ba6f[_0x289b('0x26')][_0x289b('0x28')]);}logger[_0x289b('0x26')](_0x289b('0x22'),_0x345a5f,_0x39ba6f['error'][_0x289b('0x28')]);return _0x5e3dcd(_0x39ba6f['error']['message']);}else{logger[_0x289b('0x29')](_0x289b('0x22'),_0x345a5f,_0x289b('0x23'));_0x5e3dcd(_0x39ba6f['result'][_0x289b('0x28')]);}})[_0x289b('0x2a')](function(_0x51c0c0){logger[_0x289b('0x26')](_0x289b('0x22'),_0x345a5f,_0x51c0c0);_0x117ef9(_0x51c0c0);});});}function respondWithStatusCode(_0x58b6fa,_0x5d8a23){_0x5d8a23=_0x5d8a23||0xcc;return function(_0x24a37f){if(_0x24a37f){return _0x58b6fa[_0x289b('0x2b')](_0x5d8a23);}return _0x58b6fa[_0x289b('0x2c')](_0x5d8a23)[_0x289b('0x2d')]();};}function respondWithResult(_0x3fa519,_0x3e63b5){_0x3e63b5=_0x3e63b5||0xc8;return function(_0x2fdaeb){if(_0x2fdaeb){return _0x3fa519[_0x289b('0x2c')](_0x3e63b5)[_0x289b('0x2e')](_0x2fdaeb);}};}function respondWithFilteredResult(_0x5958da,_0x7b8fd0){return function(_0x4ceaec){if(_0x4ceaec){var _0x598002=typeof _0x7b8fd0['offset']===_0x289b('0x2f')&&typeof _0x7b8fd0[_0x289b('0x30')]===_0x289b('0x2f');var _0x10fc50=_0x4ceaec[_0x289b('0x31')];var _0x271aa8=_0x598002?0x0:_0x7b8fd0[_0x289b('0x32')];var _0xca1604=_0x598002?_0x4ceaec[_0x289b('0x31')]:_0x7b8fd0[_0x289b('0x32')]+_0x7b8fd0['limit'];var _0x94c5a5;if(_0xca1604>=_0x10fc50){_0xca1604=_0x10fc50;_0x94c5a5=0xc8;}else{_0x94c5a5=0xce;}_0x5958da[_0x289b('0x2c')](_0x94c5a5);return _0x5958da[_0x289b('0x33')]('Content-Range',_0x271aa8+'-'+_0xca1604+'/'+_0x10fc50)[_0x289b('0x2e')](_0x4ceaec);}return null;};}function patchUpdates(_0xcfa83e){return function(_0x42f535){try{jsonpatch[_0x289b('0x34')](_0x42f535,_0xcfa83e,!![]);}catch(_0x4e7d64){return BPromise[_0x289b('0x35')](_0x4e7d64);}return _0x42f535[_0x289b('0x36')]();};}function saveUpdates(_0x24f8b6,_0x199609){return function(_0x1444f2){if(_0x1444f2){return _0x1444f2[_0x289b('0x37')](_0x24f8b6)[_0x289b('0x21')](function(_0x173ec3){return _0x173ec3;});}return null;};}function removeEntity(_0x3c031e,_0x55289d){return function(_0x1dcd42){if(_0x1dcd42){return _0x1dcd42[_0x289b('0x38')]()['then'](function(){var _0x5d4c9d=_0x1dcd42[_0x289b('0x39')]({'plain':!![]});var _0x18dd30='OpenchannelAccounts';return db[_0x289b('0x3a')][_0x289b('0x38')]({'where':{'type':_0x18dd30,'resourceId':_0x5d4c9d['id']}})[_0x289b('0x21')](function(){return _0x1dcd42;});})['then'](function(){_0x3c031e['status'](0xcc)[_0x289b('0x2d')]();});}};}function handleEntityNotFound(_0xcf9121,_0x27c9bf){return function(_0x428d11){if(!_0x428d11){_0xcf9121[_0x289b('0x2b')](0x194);}return _0x428d11;};}function handleError(_0x47ea18,_0x17596f){_0x17596f=_0x17596f||0x1f4;return function(_0x3a76e5){logger[_0x289b('0x26')](_0x3a76e5[_0x289b('0x3b')]);if(_0x3a76e5[_0x289b('0x3c')]){delete _0x3a76e5[_0x289b('0x3c')];}_0x47ea18[_0x289b('0x2c')](_0x17596f)['send'](_0x3a76e5);};}exports['index']=function(_0x55d195,_0x37a4d1){var _0x25ffab={'include':[{'model':db[_0x289b('0x3d')],'as':_0x289b('0x3e')}]},_0x15090a={},_0x39b472={'count':0x0,'rows':[]};var _0x20c064=_['map'](db['OpenchannelAccount'][_0x289b('0x3f')],function(_0x353de1){return{'name':_0x353de1[_0x289b('0x40')],'type':_0x353de1[_0x289b('0x41')][_0x289b('0x42')]};});_0x15090a[_0x289b('0x43')]=_['map'](_0x20c064,_0x289b('0x3c'));_0x15090a[_0x289b('0x44')]=_[_0x289b('0x45')](_0x55d195[_0x289b('0x44')]);_0x15090a['filters']=_[_0x289b('0x46')](_0x15090a['model'],_0x15090a[_0x289b('0x44')]);_0x25ffab[_0x289b('0x47')]=_['intersection'](_0x15090a[_0x289b('0x43')],qs[_0x289b('0x48')](_0x55d195['query'][_0x289b('0x48')]));_0x25ffab[_0x289b('0x47')]=_0x25ffab[_0x289b('0x47')]['length']?_0x25ffab[_0x289b('0x47')]:_0x15090a[_0x289b('0x43')];if(!_0x55d195[_0x289b('0x44')][_0x289b('0x49')]('nolimit')){_0x25ffab[_0x289b('0x30')]=qs[_0x289b('0x30')](_0x55d195['query'][_0x289b('0x30')]);_0x25ffab['offset']=qs[_0x289b('0x32')](_0x55d195[_0x289b('0x44')]['offset']);}_0x25ffab[_0x289b('0x4a')]=qs['sort'](_0x55d195[_0x289b('0x44')][_0x289b('0x4b')]);_0x25ffab[_0x289b('0x4c')]=qs['filters'](_[_0x289b('0x4d')](_0x55d195[_0x289b('0x44')],_0x15090a[_0x289b('0x4e')]),_0x20c064);if(_0x55d195[_0x289b('0x44')][_0x289b('0x4f')]){_0x25ffab[_0x289b('0x4c')]=_[_0x289b('0x50')](_0x25ffab[_0x289b('0x4c')],{'$or':_[_0x289b('0x51')](_0x20c064,function(_0x3fab7){if(_0x3fab7[_0x289b('0x41')]!==_0x289b('0x52')){var _0x141abe={};_0x141abe[_0x3fab7[_0x289b('0x3c')]]={'$like':'%'+_0x55d195['query'][_0x289b('0x4f')]+'%'};return _0x141abe;}})});}_0x25ffab=_[_0x289b('0x50')]({},_0x25ffab,_0x55d195['options']);var _0x1f5086={'where':_0x25ffab[_0x289b('0x4c')]};return db[_0x289b('0x53')][_0x289b('0x31')](_0x1f5086)['then'](function(_0x4d9759){_0x39b472[_0x289b('0x31')]=_0x4d9759;if(_0x55d195[_0x289b('0x44')][_0x289b('0x54')]){_0x25ffab[_0x289b('0x55')]=[{'all':!![]}];}return db[_0x289b('0x53')]['findAll'](_0x25ffab);})['then'](function(_0x14e4f4){_0x39b472[_0x289b('0x56')]=_0x14e4f4;return _0x39b472;})[_0x289b('0x21')](respondWithFilteredResult(_0x37a4d1,_0x25ffab))[_0x289b('0x2a')](handleError(_0x37a4d1,null));};exports[_0x289b('0x57')]=function(_0x30fe9d,_0x241ac7){var _0x3ab297={'raw':![],'where':{'id':_0x30fe9d[_0x289b('0x58')]['id']},'include':[{'model':db[_0x289b('0x3d')],'as':_0x289b('0x3e')}]},_0x47736a={};_0x47736a[_0x289b('0x43')]=_[_0x289b('0x45')](db[_0x289b('0x53')]['rawAttributes']);_0x47736a[_0x289b('0x44')]=_[_0x289b('0x45')](_0x30fe9d[_0x289b('0x44')]);_0x47736a[_0x289b('0x4e')]=_[_0x289b('0x46')](_0x47736a[_0x289b('0x43')],_0x47736a['query']);_0x3ab297[_0x289b('0x47')]=_['intersection'](_0x47736a['model'],qs['fields'](_0x30fe9d[_0x289b('0x44')]['fields']));_0x3ab297['attributes']=_0x3ab297[_0x289b('0x47')][_0x289b('0x59')]?_0x3ab297['attributes']:_0x47736a[_0x289b('0x43')];if(_0x30fe9d['query'][_0x289b('0x54')]){_0x3ab297[_0x289b('0x55')]=[{'all':!![]}];}_0x3ab297=_[_0x289b('0x50')]({},_0x3ab297,_0x30fe9d[_0x289b('0x5a')]);return db[_0x289b('0x53')][_0x289b('0x5b')](_0x3ab297)[_0x289b('0x21')](handleEntityNotFound(_0x241ac7,null))[_0x289b('0x21')](respondWithResult(_0x241ac7,null))[_0x289b('0x2a')](handleError(_0x241ac7,null));};exports['create']=function(_0x1db13c,_0x3a3a3b){return db[_0x289b('0x53')][_0x289b('0x5c')](_0x1db13c['body'],{})[_0x289b('0x21')](function(_0x3448e0){var _0x38a278=_0x1db13c[_0x289b('0x5d')][_0x289b('0x39')]({'plain':!![]});if(!_0x38a278)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x38a278[_0x289b('0x5e')]===_0x289b('0x5d')){var _0x322c7d=_0x3448e0[_0x289b('0x39')]({'plain':!![]});var _0x5a1a8e='OpenchannelAccounts';return db[_0x289b('0x5f')]['find']({'where':{'name':_0x5a1a8e,'userProfileId':_0x38a278[_0x289b('0x60')]},'raw':!![]})[_0x289b('0x21')](function(_0x45498e){if(_0x45498e&&_0x45498e[_0x289b('0x61')]===0x0){return db['UserProfileResource'][_0x289b('0x5c')]({'name':_0x322c7d[_0x289b('0x3c')],'resourceId':_0x322c7d['id'],'type':_0x45498e[_0x289b('0x3c')],'sectionId':_0x45498e['id']},{})[_0x289b('0x21')](function(){return _0x3448e0;});}else{return _0x3448e0;}})[_0x289b('0x2a')](function(_0x34abe4){logger[_0x289b('0x26')](_0x289b('0x62'),_0x34abe4);throw _0x34abe4;});}return _0x3448e0;})[_0x289b('0x21')](respondWithResult(_0x3a3a3b,0xc9))['catch'](handleError(_0x3a3a3b,null));};exports[_0x289b('0x37')]=function(_0x48bf52,_0x1edc52){if(_0x48bf52[_0x289b('0x63')]['id']){delete _0x48bf52[_0x289b('0x63')]['id'];}return db[_0x289b('0x53')][_0x289b('0x5b')]({'where':{'id':_0x48bf52[_0x289b('0x58')]['id']},'include':[{'model':db[_0x289b('0x3d')],'as':_0x289b('0x3e')}]})[_0x289b('0x21')](handleEntityNotFound(_0x1edc52,null))[_0x289b('0x21')](saveUpdates(_0x48bf52['body'],null))[_0x289b('0x21')](respondWithResult(_0x1edc52,null))[_0x289b('0x2a')](handleError(_0x1edc52,null));};exports['destroy']=function(_0x28e003,_0x146df6){return db[_0x289b('0x53')][_0x289b('0x5b')]({'where':{'id':_0x28e003['params']['id']}})['then'](handleEntityNotFound(_0x146df6,null))[_0x289b('0x21')](removeEntity(_0x146df6,null))[_0x289b('0x2a')](handleError(_0x146df6,null));};exports[_0x289b('0x64')]=function(_0xd3cf71,_0x3ca4b0){return db['OpenchannelAccount'][_0x289b('0x64')]()[_0x289b('0x21')](respondWithResult(_0x3ca4b0,null))[_0x289b('0x2a')](handleError(_0x3ca4b0,null));};exports[_0x289b('0x65')]=function(_0x2b1f10,_0x579a70,_0x51110a){if(_0x2b1f10['body']['id']){delete _0x2b1f10[_0x289b('0x63')]['id'];}return db[_0x289b('0x53')][_0x289b('0x5b')]({'where':{'id':_0x2b1f10[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x579a70,null))['then'](function(_0x412a4e){if(_0x412a4e){_0x2b1f10[_0x289b('0x63')][_0x289b('0x66')]=_0x412a4e['id'];return db[_0x289b('0x67')][_0x289b('0x5c')](_0x2b1f10['body']);}})['then'](respondWithResult(_0x579a70,null))[_0x289b('0x2a')](handleError(_0x579a70,null));};exports[_0x289b('0x68')]=function(_0xddb5de,_0x314eca,_0x332ebb){var _0x50dcdb={'raw':![],'where':{}};var _0x5234f6={};var _0x2551f8={'count':0x0,'rows':[]};return db[_0x289b('0x53')][_0x289b('0x69')]({'where':{'id':_0xddb5de[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x314eca,null))[_0x289b('0x21')](function(_0x560056){if(_0x560056){_0x5234f6[_0x289b('0x43')]=_[_0x289b('0x45')](db[_0x289b('0x67')]['rawAttributes']);_0x5234f6[_0x289b('0x44')]=_['keys'](_0xddb5de[_0x289b('0x44')]);_0x5234f6[_0x289b('0x4e')]=_[_0x289b('0x46')](_0x5234f6[_0x289b('0x43')],_0x5234f6[_0x289b('0x44')]);_0x50dcdb[_0x289b('0x47')]=_['intersection'](_0x5234f6[_0x289b('0x43')],qs[_0x289b('0x48')](_0xddb5de[_0x289b('0x44')]['fields']));_0x50dcdb[_0x289b('0x47')]=_0x50dcdb[_0x289b('0x47')][_0x289b('0x59')]?_0x50dcdb['attributes']:_0x5234f6[_0x289b('0x43')];if(!_0xddb5de[_0x289b('0x44')][_0x289b('0x49')]('nolimit')){_0x50dcdb[_0x289b('0x30')]=qs[_0x289b('0x30')](_0xddb5de[_0x289b('0x44')][_0x289b('0x30')]);_0x50dcdb[_0x289b('0x32')]=qs['offset'](_0xddb5de[_0x289b('0x44')][_0x289b('0x32')]);}_0x50dcdb[_0x289b('0x4a')]=qs[_0x289b('0x4b')](_0xddb5de[_0x289b('0x44')][_0x289b('0x4b')]);_0x50dcdb['where']=qs[_0x289b('0x4e')](_[_0x289b('0x4d')](_0xddb5de['query'],_0x5234f6[_0x289b('0x4e')]));_0x50dcdb[_0x289b('0x4c')][_0x289b('0x66')]=_0x560056['id'];if(_0xddb5de[_0x289b('0x44')]['filter']){_0x50dcdb[_0x289b('0x4c')]=_[_0x289b('0x50')](_0x50dcdb['where'],{'$or':_[_0x289b('0x51')](_0x50dcdb[_0x289b('0x47')],function(_0x52a8bf){var _0x48d129={};_0x48d129[_0x52a8bf]={'$like':'%'+_0xddb5de['query'][_0x289b('0x4f')]+'%'};return _0x48d129;})});}_0x50dcdb=_[_0x289b('0x50')]({},_0x50dcdb,_0xddb5de[_0x289b('0x5a')]);return db[_0x289b('0x67')]['count']({'where':_0x50dcdb[_0x289b('0x4c')]})[_0x289b('0x21')](function(_0x277647){_0x2551f8[_0x289b('0x31')]=_0x277647;if(_0xddb5de[_0x289b('0x44')][_0x289b('0x54')]){_0x50dcdb['include']=[{'all':!![]}];}return db[_0x289b('0x67')][_0x289b('0x6a')](_0x50dcdb);})[_0x289b('0x21')](function(_0x1fa0ec){_0x2551f8[_0x289b('0x56')]=_0x1fa0ec;return _0x2551f8;});}})[_0x289b('0x21')](respondWithFilteredResult(_0x314eca,_0x50dcdb))['catch'](handleError(_0x314eca,null));};exports['removeDispositions']=function(_0x5afc98,_0x466de8,_0x4e5aa9){return db[_0x289b('0x53')][_0x289b('0x5b')]({'where':{'id':_0x5afc98['params']['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x466de8,null))['then'](function(_0x1e5066){if(_0x1e5066){return _0x1e5066[_0x289b('0x6b')](_0x5afc98[_0x289b('0x44')][_0x289b('0x6c')]);}})['then'](respondWithStatusCode(_0x466de8,null))[_0x289b('0x2a')](handleError(_0x466de8,null));};exports['addAnswer']=function(_0x27602a,_0x3ad774,_0x484d70){if(_0x27602a['body']['id']){delete _0x27602a[_0x289b('0x63')]['id'];}return db[_0x289b('0x53')]['find']({'where':{'id':_0x27602a[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x3ad774,null))['then'](function(_0x559c91){if(_0x559c91){_0x27602a[_0x289b('0x63')][_0x289b('0x66')]=_0x559c91['id'];return db[_0x289b('0x6d')][_0x289b('0x5c')](_0x27602a[_0x289b('0x63')]);}})[_0x289b('0x21')](respondWithResult(_0x3ad774,null))[_0x289b('0x2a')](handleError(_0x3ad774,null));};exports['getAnswers']=function(_0x17f15c,_0x1ae101,_0x110bad){var _0x279c90={'raw':![],'where':{}};var _0x42128b={};var _0x4ee7d0={'count':0x0,'rows':[]};return db[_0x289b('0x53')][_0x289b('0x69')]({'where':{'id':_0x17f15c['params']['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x1ae101,null))[_0x289b('0x21')](function(_0x524e8c){if(_0x524e8c){_0x42128b['model']=_[_0x289b('0x45')](db[_0x289b('0x6d')][_0x289b('0x3f')]);_0x42128b['query']=_[_0x289b('0x45')](_0x17f15c[_0x289b('0x44')]);_0x42128b['filters']=_[_0x289b('0x46')](_0x42128b[_0x289b('0x43')],_0x42128b[_0x289b('0x44')]);_0x279c90[_0x289b('0x47')]=_[_0x289b('0x46')](_0x42128b[_0x289b('0x43')],qs['fields'](_0x17f15c['query'][_0x289b('0x48')]));_0x279c90[_0x289b('0x47')]=_0x279c90[_0x289b('0x47')][_0x289b('0x59')]?_0x279c90[_0x289b('0x47')]:_0x42128b['model'];if(!_0x17f15c[_0x289b('0x44')]['hasOwnProperty'](_0x289b('0x6e'))){_0x279c90['limit']=qs[_0x289b('0x30')](_0x17f15c[_0x289b('0x44')][_0x289b('0x30')]);_0x279c90['offset']=qs['offset'](_0x17f15c[_0x289b('0x44')][_0x289b('0x32')]);}_0x279c90[_0x289b('0x4a')]=qs['sort'](_0x17f15c[_0x289b('0x44')][_0x289b('0x4b')]);_0x279c90[_0x289b('0x4c')]=qs[_0x289b('0x4e')](_['pick'](_0x17f15c['query'],_0x42128b['filters']));_0x279c90[_0x289b('0x4c')][_0x289b('0x66')]=_0x524e8c['id'];if(_0x17f15c[_0x289b('0x44')][_0x289b('0x4f')]){_0x279c90['where']=_['merge'](_0x279c90[_0x289b('0x4c')],{'$or':_['map'](_0x279c90[_0x289b('0x47')],function(_0x43514b){var _0x53ff05={};_0x53ff05[_0x43514b]={'$like':'%'+_0x17f15c['query'][_0x289b('0x4f')]+'%'};return _0x53ff05;})});}_0x279c90=_[_0x289b('0x50')]({},_0x279c90,_0x17f15c[_0x289b('0x5a')]);return db[_0x289b('0x6d')][_0x289b('0x31')]({'where':_0x279c90[_0x289b('0x4c')]})['then'](function(_0x18e58d){_0x4ee7d0['count']=_0x18e58d;if(_0x17f15c['query']['includeAll']){_0x279c90['include']=[{'all':!![]}];}return db['CannedAnswer'][_0x289b('0x6a')](_0x279c90);})[_0x289b('0x21')](function(_0xc82e72){_0x4ee7d0[_0x289b('0x56')]=_0xc82e72;return _0x4ee7d0;});}})[_0x289b('0x21')](respondWithFilteredResult(_0x1ae101,_0x279c90))[_0x289b('0x2a')](handleError(_0x1ae101,null));};exports['removeAnswers']=function(_0x1bae6f,_0x4ef426,_0x32c505){return db[_0x289b('0x53')][_0x289b('0x5b')]({'where':{'id':_0x1bae6f[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x4ef426,null))[_0x289b('0x21')](function(_0x44f777){if(_0x44f777){return _0x44f777[_0x289b('0x6f')](_0x1bae6f[_0x289b('0x44')][_0x289b('0x6c')]);}})[_0x289b('0x21')](respondWithStatusCode(_0x4ef426,null))['catch'](handleError(_0x4ef426,null));};exports[_0x289b('0x70')]=function(_0x3d764e,_0x139c4c,_0x3d1eb2){var _0x1b96e5={'body':_0x3d764e['body'],'channel':_0x289b('0x71')};var _0x2a2596=[];var _0x2592a2=[];var _0xa01544={};var _0x5b690f=![];return db[_0x289b('0x72')][_0x289b('0x64')]()['then'](function(_0xe93d96){if(!_0xe93d96){throw new db[(_0x289b('0x73'))][(_0x289b('0x74'))]('no\x20available\x20attributes');}_0x2a2596=_[_0x289b('0x75')](_[_0x289b('0x45')](_0xe93d96),[_0x289b('0x76'),'updatedAt']);_0x2592a2=_[_0x289b('0x75')](_[_0x289b('0x45')](_0xe93d96),['createdAt','updatedAt',_0x289b('0x77'),_0x289b('0x78')]);if(_0x3d764e[_0x289b('0x63')]['id']){delete _0x3d764e[_0x289b('0x63')]['id'];}if(_[_0x289b('0x79')](_0x3d764e['body'][_0x289b('0x7a')])){throw new db['Sequelize'][(_0x289b('0x74'))]('from\x20is\x20mandatory');}if(_[_0x289b('0x79')](_0x3d764e[_0x289b('0x63')][_0x289b('0x63')])||_0x3d764e['body'][_0x289b('0x63')]===''){throw new db[(_0x289b('0x73'))]['ValidationError'](_0x289b('0x7b'));}if(_[_0x289b('0x79')](_0x3d764e[_0x289b('0x63')][_0x289b('0x7c')])){throw new db[(_0x289b('0x73'))]['ValidationError']('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x2592a2);}if(!_[_0x289b('0x7d')](_0x2592a2,_0x3d764e[_0x289b('0x63')]['mapKey'])){throw new db[(_0x289b('0x73'))][(_0x289b('0x74'))](_0x289b('0x7e')+_0x2592a2);}_0xa01544[_0x3d764e[_0x289b('0x63')][_0x289b('0x7c')]]=_0x3d764e['body']['from'];})[_0x289b('0x21')](function(){return db[_0x289b('0x53')]['find']({'where':{'id':_0x3d764e[_0x289b('0x58')]['id']},'include':[{'model':db[_0x289b('0x7f')],'as':_0x289b('0x80'),'include':[{'model':db[_0x289b('0x72')],'as':_0x289b('0x81'),'where':_0xa01544,'limit':0x1,'order':[['updatedAt',_0x289b('0x82')]]}]},{'model':db['OpenchannelApplication'],'as':_0x289b('0x83')}]});})[_0x289b('0x21')](handleEntityNotFound(_0x139c4c,null))[_0x289b('0x21')](function(_0x234ff8){if(_0x234ff8&&_0x234ff8['List']){_0x1b96e5[_0x289b('0x84')]=_0x234ff8;_0x1b96e5[_0x289b('0x85')]=_0x234ff8[_0x289b('0x83')];_0x1b96e5[_0x289b('0x86')]=_0x234ff8[_0x289b('0x80')];_0x1b96e5['applications']=_[_0x289b('0x87')](_0x1b96e5['applications'],[_0x289b('0x88')],[_0x289b('0x89')]);if(_0x1b96e5[_0x289b('0x84')][_0x289b('0x83')]){delete _0x1b96e5[_0x289b('0x84')][_0x289b('0x83')];}if(_0x1b96e5[_0x289b('0x84')][_0x289b('0x80')]&&_0x1b96e5[_0x289b('0x84')][_0x289b('0x80')][_0x289b('0x81')]['length']){return _0x1b96e5[_0x289b('0x84')][_0x289b('0x80')]['Contacts'][0x0];}var _0x159e0c=_[_0x289b('0x17')](_0x3d764e['body'],{'firstName':_0x3d764e['body'][_0x289b('0x7a')],'ListId':_0x234ff8[_0x289b('0x78')]});_0x159e0c[_0x3d764e[_0x289b('0x63')][_0x289b('0x7c')]]=_0x3d764e[_0x289b('0x63')][_0x289b('0x7a')];return db[_0x289b('0x72')][_0x289b('0x5c')](_0x159e0c,{'fields':_0x2a2596,'raw':!![]});}})[_0x289b('0x21')](handleEntityNotFound(_0x139c4c,null))[_0x289b('0x21')](function(_0x107930){_0x1b96e5['contact']=_0x107930;if(_0x107930){var _0x237d43={'ContactId':_0x107930['id'],'OpenchannelAccountId':_0x3d764e[_0x289b('0x58')]['id'],'from':(_0x107930['firstName']||'')+'\x20'+(_0x107930[_0x289b('0x8a')]||'')};var _0x158b71={'OpenchannelAccountId':_0x3d764e[_0x289b('0x58')]['id'],'closed':![]};if(_0x3d764e['body'][_0x289b('0x8b')]){_0x158b71[_0x289b('0x8b')]=_0x3d764e[_0x289b('0x63')]['threadId'];return db[_0x289b('0x8c')][_0x289b('0x5b')]({'where':_0x158b71})[_0x289b('0x21')](function(_0x2017d8){if(_0x2017d8){return[_0x2017d8,![]];}_0x237d43[_0x289b('0x8b')]=_0x3d764e['body'][_0x289b('0x8b')];_0x237d43[_0x289b('0x8d')]=_0x3d764e[_0x289b('0x63')][_0x289b('0x8d')];return db[_0x289b('0x8c')][_0x289b('0x5c')](_0x237d43)['then'](function(_0x15e242){return[_0x15e242,!![]];});});}else{_0x158b71[_0x289b('0x8b')]=null;}_0x158b71[_0x289b('0x8e')]=_0x107930['id'];return db[_0x289b('0x8c')][_0x289b('0x5b')]({'where':_0x158b71})[_0x289b('0x21')](function(_0x38d25b){if(_0x38d25b){return[_0x38d25b,![]];}return db['OpenchannelInteraction']['create'](_0x237d43)[_0x289b('0x21')](function(_0x2872ff){return[_0x2872ff,!![]];});});}})['spread'](function(_0x4cb784,_0x33c7b2){if(_0x4cb784){_0x5b690f=_0x33c7b2;if(!_0x33c7b2){var _0x31ca63={'from':(_0x1b96e5[_0x289b('0x8f')][_0x289b('0x90')]||'')+'\x20'+(_0x1b96e5[_0x289b('0x8f')][_0x289b('0x8a')]||'')};if(_0x3d764e[_0x289b('0x63')][_0x289b('0x8b')]&&_0x3d764e[_0x289b('0x63')][_0x289b('0x91')]&&_0x3d764e[_0x289b('0x63')][_0x289b('0x8b')]!=_0x3d764e['body']['messageId']){_0x31ca63['threadId']=_0x3d764e[_0x289b('0x63')][_0x289b('0x91')];}return _0x4cb784['update'](_0x31ca63);}else{return _0x4cb784;}}})[_0x289b('0x21')](function(_0x2c2913){_0x1b96e5[_0x289b('0x92')]=_0x2c2913[_0x289b('0x39')]({'plain':!![]});_0x1b96e5[_0x289b('0x92')]['created']=_0x5b690f;if(_0x1b96e5[_0x289b('0x92')][_0x289b('0x93')]){if(_0x1b96e5[_0x289b('0x84')]['autoclose']){_0x1b96e5['applications'][_0x289b('0x94')]({'id':0x0,'priority':_0x1b96e5['applications']['length']+0x1,'app':_0x289b('0x95'),'appdata':'unmanaged','interval':_0x289b('0x96')});}}return db[_0x289b('0x97')]['create']({'body':_0x3d764e['body']['body'],'OpenchannelAccountId':_0x3d764e[_0x289b('0x58')]['id'],'OpenchannelInteractionId':_0x2c2913['id'],'direction':'in','ContactId':_0x1b96e5[_0x289b('0x8f')]['id'],'AttachmentId':_0x3d764e[_0x289b('0x63')]['AttachmentId']});})[_0x289b('0x21')](function(_0x1a788c){_0x1b96e5[_0x289b('0x28')]=_0x1a788c;if(_0x1b96e5['interaction']['UserId']){return db[_0x289b('0x98')][_0x289b('0x5b')]({'attributes':['id','name'],'where':{'id':_0x1b96e5['interaction']['UserId']}})[_0x289b('0x21')](function(_0x23a807){if(_0x23a807){_0x1b96e5[_0x289b('0x85')]['unshift']({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x23a807[_0x289b('0x3c')]+','+(_0x1b96e5[_0x289b('0x84')]['waitForTheAssignedAgent']||0xa),'interval':_0x289b('0x96')});_0x1b96e5[_0x289b('0x99')]=![];}return respondWithRpcPromise(_0x289b('0x9a'),'startRouting',_0x1b96e5);});}return respondWithRpcPromise(_0x289b('0x9a'),_0x289b('0x9b'),_0x1b96e5);})[_0x289b('0x21')](function(_0x2e6aaf){respondWithRpcPromise(_0x289b('0x9c'),_0x289b('0x9c'),{'event':'notify','message':_0x2e6aaf},client9002);return _0x2e6aaf;})[_0x289b('0x21')](respondWithResult(_0x139c4c,null))[_0x289b('0x2a')](handleError(_0x139c4c,null));};exports[_0x289b('0x9d')]=function(_0x2078c5,_0x2e446f){var _0xe5fd98=_0x2078c5[_0x289b('0x58')]['id'];var _0x43ccc0=_0x2078c5[_0x289b('0x63')];var _0x2f8537=0xc8;var _0x38eccd=null;return db['sequelize'][_0x289b('0x9e')]({'isolationLevel':db[_0x289b('0x9f')][_0x289b('0xa0')]['ISOLATION_LEVELS']['READ_COMMITTED']},function(_0x4fe7aa){return db[_0x289b('0x53')][_0x289b('0x69')]({'where':{'id':_0xe5fd98},'transaction':_0x4fe7aa})[_0x289b('0x21')](function(_0x103972){if(_0x103972){return db[_0x289b('0xa1')][_0x289b('0x38')]({'where':{'OpenchannelAccountId':_0xe5fd98},'transaction':_0x4fe7aa})['then'](function(){var _0x4133a6=_[_0x289b('0x51')](_0x43ccc0,function(_0x580750){_0x580750[_0x289b('0x66')]=_0xe5fd98;return _0x580750;});return db['OpenchannelApplication']['bulkCreate'](_0x4133a6,{'transaction':_0x4fe7aa});});}else{_0x2f8537=0x194;_0x38eccd=[];}});})[_0x289b('0x21')](function(){if(_0x2f8537!==0x194){return db[_0x289b('0xa1')]['findAndCountAll']({'where':{'OpenchannelAccountId':_0xe5fd98},'order':'priority'})[_0x289b('0x21')](function(_0x2b4ae2){_0x38eccd=_0x2b4ae2;});}})[_0x289b('0x2a')](function(_0x3fdf3d){_0x2f8537=0x1f4;logger['error'](_0x3fdf3d[_0x289b('0x3b')]);if(_0x3fdf3d[_0x289b('0x3c')]){delete _0x3fdf3d[_0x289b('0x3c')];}_0x38eccd=_0x3fdf3d;})[_0x289b('0xa2')](function(){if(_0x38eccd===null){_0x2e446f[_0x289b('0x2b')](_0x2f8537);}else{if(_0x2f8537===0x1f4){_0x2e446f[_0x289b('0x2c')](_0x2f8537)['send'](_0x38eccd);}else{_0x2e446f[_0x289b('0x2c')](_0x2f8537)[_0x289b('0x2e')](_0x38eccd);}}});};exports[_0x289b('0xa3')]=function(_0x14d5b6,_0x309a18,_0x45ad81){var _0x414377={};var _0xfbadfa={};var _0x358f3b;var _0x4f74d8;return db[_0x289b('0x53')][_0x289b('0x69')]({'where':{'id':_0x14d5b6[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x309a18,null))[_0x289b('0x21')](function(_0x4d16ba){if(_0x4d16ba){_0x358f3b=_0x4d16ba;_0xfbadfa[_0x289b('0x43')]=_[_0x289b('0x45')](db[_0x289b('0xa1')]['rawAttributes']);_0xfbadfa[_0x289b('0x44')]=_[_0x289b('0x45')](_0x14d5b6[_0x289b('0x44')]);_0xfbadfa[_0x289b('0x4e')]=_[_0x289b('0x46')](_0xfbadfa[_0x289b('0x43')],_0xfbadfa['query']);_0x414377[_0x289b('0x47')]=_[_0x289b('0x46')](_0xfbadfa[_0x289b('0x43')],qs[_0x289b('0x48')](_0x14d5b6[_0x289b('0x44')][_0x289b('0x48')]));_0x414377['attributes']=_0x414377[_0x289b('0x47')][_0x289b('0x59')]?_0x414377[_0x289b('0x47')]:_0xfbadfa[_0x289b('0x43')];_0x414377[_0x289b('0x4a')]=qs[_0x289b('0x4b')](_0x14d5b6['query'][_0x289b('0x4b')]);_0x414377[_0x289b('0x4c')]=qs['filters'](_[_0x289b('0x4d')](_0x14d5b6['query'],_0xfbadfa[_0x289b('0x4e')]));if(_0x14d5b6[_0x289b('0x44')][_0x289b('0x4f')]){_0x414377['where']=_[_0x289b('0x50')](_0x414377['where'],{'$or':_['map'](_0x414377[_0x289b('0x47')],function(_0x40c601){var _0x6d62e1={};_0x6d62e1[_0x40c601]={'$like':'%'+_0x14d5b6[_0x289b('0x44')][_0x289b('0x4f')]+'%'};return _0x6d62e1;})});}_0x414377=_[_0x289b('0x50')]({},_0x414377,_0x14d5b6[_0x289b('0x5a')]);return _0x358f3b['getApplications'](_0x414377);}})[_0x289b('0x21')](function(_0x28e9dd){if(_0x28e9dd){_0x4f74d8=_0x28e9dd[_0x289b('0x59')];if(!_0x14d5b6[_0x289b('0x44')][_0x289b('0x49')](_0x289b('0x6e'))){_0x414377['limit']=qs[_0x289b('0x30')](_0x14d5b6[_0x289b('0x44')][_0x289b('0x30')]);_0x414377['offset']=qs[_0x289b('0x32')](_0x14d5b6[_0x289b('0x44')][_0x289b('0x32')]);}return _0x358f3b['getApplications'](_0x414377);}})[_0x289b('0x21')](function(_0x4215d1){if(_0x4215d1){return _0x4215d1?{'count':_0x4f74d8,'rows':_0x4215d1}:null;}})['then'](respondWithResult(_0x309a18,null))['catch'](handleError(_0x309a18,null));};exports[_0x289b('0xa4')]=function(_0x3f6f40,_0x51a9b7,_0x2a1dea){var _0x179211={'raw':![],'where':{}};var _0x418d26={};var _0x558d8e={'count':0x0,'rows':[]};return db[_0x289b('0x53')][_0x289b('0x69')]({'where':{'id':_0x3f6f40[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x51a9b7,null))['then'](function(_0x20b339){if(_0x20b339){_0x418d26[_0x289b('0x43')]=_[_0x289b('0x45')](db[_0x289b('0x8c')][_0x289b('0x3f')]);_0x418d26[_0x289b('0x44')]=_[_0x289b('0x45')](_0x3f6f40[_0x289b('0x44')]);_0x418d26[_0x289b('0x4e')]=_['intersection'](_0x418d26[_0x289b('0x43')],_0x418d26[_0x289b('0x44')]);_0x179211['attributes']=_['intersection'](_0x418d26[_0x289b('0x43')],qs['fields'](_0x3f6f40[_0x289b('0x44')][_0x289b('0x48')]));_0x179211[_0x289b('0x47')]=_0x179211[_0x289b('0x47')][_0x289b('0x59')]?_0x179211[_0x289b('0x47')]:_0x418d26[_0x289b('0x43')];if(!_0x3f6f40['query']['hasOwnProperty'](_0x289b('0x6e'))){_0x179211[_0x289b('0x30')]=qs['limit'](_0x3f6f40[_0x289b('0x44')]['limit']);_0x179211[_0x289b('0x32')]=qs['offset'](_0x3f6f40['query'][_0x289b('0x32')]);}_0x179211[_0x289b('0x4a')]=qs[_0x289b('0x4b')](_0x3f6f40['query'][_0x289b('0x4b')]);_0x179211[_0x289b('0x4c')]=qs[_0x289b('0x4e')](_[_0x289b('0x4d')](_0x3f6f40['query'],_0x418d26[_0x289b('0x4e')]));_0x179211[_0x289b('0x4c')][_0x289b('0x66')]=_0x20b339['id'];if(_0x3f6f40[_0x289b('0x44')]['filter']){_0x179211['where']=_[_0x289b('0x50')](_0x179211[_0x289b('0x4c')],{'$or':_[_0x289b('0x51')](_0x179211['attributes'],function(_0x4292fd){var _0x4b0a0b={};_0x4b0a0b[_0x4292fd]={'$like':'%'+_0x3f6f40[_0x289b('0x44')][_0x289b('0x4f')]+'%'};return _0x4b0a0b;})});}_0x179211=_[_0x289b('0x50')]({},_0x179211,_0x3f6f40['options']);return db[_0x289b('0x8c')]['count']({'where':_0x179211[_0x289b('0x4c')]})['then'](function(_0x208d87){_0x558d8e[_0x289b('0x31')]=_0x208d87;if(_0x3f6f40[_0x289b('0x44')][_0x289b('0x54')]){_0x179211[_0x289b('0x55')]=[{'model':db[_0x289b('0x72')],'as':_0x289b('0xa5'),'required':![]},{'model':db[_0x289b('0x98')],'as':'Owner','attributes':[_0x289b('0x3c'),_0x289b('0xa6'),_0x289b('0xa7')],'required':![]},{'model':db[_0x289b('0xa8')],'as':_0x289b('0xa9'),'attributes':['id',_0x289b('0x3c'),_0x289b('0xaa')],'where':_0x3f6f40[_0x289b('0x44')][_0x289b('0xab')]?{'id':_0x3f6f40[_0x289b('0x44')][_0x289b('0xab')]}:undefined,'required':_0x3f6f40['query'][_0x289b('0xab')]?!![]:![]}];}return db[_0x289b('0x8c')][_0x289b('0x6a')](_0x179211);})['then'](function(_0x23ac83){_0x558d8e['rows']=_0x23ac83;return _0x558d8e;});}})['then'](respondWithFilteredResult(_0x51a9b7,_0x179211))[_0x289b('0x2a')](handleError(_0x51a9b7,null));};exports[_0x289b('0xac')]=function(_0x46929f,_0x37683d,_0x2f5677){return db[_0x289b('0x53')][_0x289b('0x5b')]({'where':{'id':_0x46929f[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x37683d,null))[_0x289b('0x21')](function(_0x598a87){if(_0x598a87){return _0x598a87[_0x289b('0xac')](_0x46929f[_0x289b('0x63')][_0x289b('0x6c')],_['omit'](_0x46929f['body'],[_0x289b('0x6c'),'id'])||{})['spread'](function(_0x46789f){for(var _0x2f75f8=0x0;_0x2f75f8<_0x46929f['body'][_0x289b('0x6c')][_0x289b('0x59')];_0x2f75f8+=0x1){socket[_0x289b('0xad')](_0x289b('0xae'),{'UserId':Number(_0x46929f['body']['ids'][_0x2f75f8]),'OpenchannelAccountId':Number(_0x46929f[_0x289b('0x58')]['id'])});}return _0x46789f;});}})[_0x289b('0x21')](respondWithResult(_0x37683d,null))[_0x289b('0x2a')](handleError(_0x37683d,null));};exports[_0x289b('0xaf')]=function(_0x75c67e,_0x1e1a0c,_0x318c1f){return db['OpenchannelAccount'][_0x289b('0x5b')]({'where':{'id':_0x75c67e[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x1e1a0c,null))[_0x289b('0x21')](function(_0x18beee){if(_0x18beee){return _0x18beee[_0x289b('0xaf')](_0x75c67e[_0x289b('0x44')][_0x289b('0x6c')])['then'](function(){if(_['isArray'](_0x75c67e[_0x289b('0x44')][_0x289b('0x6c')])){for(var _0x5e2552=0x0;_0x5e2552<_0x75c67e[_0x289b('0x44')]['ids']['length'];_0x5e2552+=0x1){socket[_0x289b('0xad')]('userOpenchannelAccount:remove',{'UserId':Number(_0x75c67e[_0x289b('0x44')][_0x289b('0x6c')][_0x5e2552]),'OpenchannelAccountId':Number(_0x75c67e[_0x289b('0x58')]['id'])});}}else{socket[_0x289b('0xad')](_0x289b('0xb0'),{'UserId':Number(_0x75c67e[_0x289b('0x44')][_0x289b('0x6c')]),'OpenchannelAccountId':Number(_0x75c67e[_0x289b('0x58')]['id'])});}});}})[_0x289b('0x21')](respondWithStatusCode(_0x1e1a0c,null))[_0x289b('0x2a')](handleError(_0x1e1a0c,null));};exports[_0x289b('0xb1')]=function(_0x3033f1,_0x5d8aeb,_0x49a0dd){var _0x4b9271={};var _0x276e97={};var _0x2d91ed;var _0x3895fe;return db['OpenchannelAccount'][_0x289b('0x69')]({'where':{'id':_0x3033f1['params']['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x5d8aeb,null))[_0x289b('0x21')](function(_0xdcaa40){if(_0xdcaa40){_0x2d91ed=_0xdcaa40;_0x276e97[_0x289b('0x43')]=_[_0x289b('0x45')](db[_0x289b('0x98')]['rawAttributes']);_0x276e97[_0x289b('0x44')]=_[_0x289b('0x45')](_0x3033f1['query']);_0x276e97[_0x289b('0x4e')]=_['intersection'](_0x276e97[_0x289b('0x43')],_0x276e97[_0x289b('0x44')]);_0x4b9271['attributes']=_[_0x289b('0x46')](_0x276e97[_0x289b('0x43')],qs[_0x289b('0x48')](_0x3033f1[_0x289b('0x44')][_0x289b('0x48')]));_0x4b9271[_0x289b('0x47')]=_0x4b9271[_0x289b('0x47')][_0x289b('0x59')]?_0x4b9271[_0x289b('0x47')]:_0x276e97[_0x289b('0x43')];_0x4b9271[_0x289b('0x4a')]=qs['sort'](_0x3033f1['query'][_0x289b('0x4b')]);_0x4b9271[_0x289b('0x4c')]=qs[_0x289b('0x4e')](_['pick'](_0x3033f1['query'],_0x276e97['filters']));if(_0x3033f1[_0x289b('0x44')][_0x289b('0x4f')]){_0x4b9271['where']=_[_0x289b('0x50')](_0x4b9271[_0x289b('0x4c')],{'$or':_['map'](_0x4b9271[_0x289b('0x47')],function(_0x378c94){var _0x40f8a9={};_0x40f8a9[_0x378c94]={'$like':'%'+_0x3033f1['query'][_0x289b('0x4f')]+'%'};return _0x40f8a9;})});}_0x4b9271=_[_0x289b('0x50')]({},_0x4b9271,_0x3033f1['options']);return _0x2d91ed[_0x289b('0xb1')](_0x4b9271);}})[_0x289b('0x21')](function(_0x196c44){if(_0x196c44){_0x3895fe=_0x196c44[_0x289b('0x59')];if(!_0x3033f1['query']['hasOwnProperty'](_0x289b('0x6e'))){_0x4b9271[_0x289b('0x30')]=qs[_0x289b('0x30')](_0x3033f1[_0x289b('0x44')][_0x289b('0x30')]);_0x4b9271[_0x289b('0x32')]=qs[_0x289b('0x32')](_0x3033f1[_0x289b('0x44')][_0x289b('0x32')]);}return _0x2d91ed[_0x289b('0xb1')](_0x4b9271);}})[_0x289b('0x21')](function(_0x55d7bc){if(_0x55d7bc){return _0x55d7bc?{'count':_0x3895fe,'rows':_0x55d7bc}:null;}})['then'](respondWithResult(_0x5d8aeb,null))[_0x289b('0x2a')](handleError(_0x5d8aeb,null));};exports[_0x289b('0xb2')]=function(_0x5ae118,_0x5e9267,_0x37269a){var _0x3db392,_0x450043,_0x3225d9;if(_[_0x289b('0x79')](_0x5ae118[_0x289b('0x63')][_0x289b('0x63')])||_0x5ae118[_0x289b('0x63')][_0x289b('0x63')]===''){throw new db[(_0x289b('0x73'))][(_0x289b('0x74'))](_0x289b('0x7b'));}if(_[_0x289b('0x79')](_0x5ae118['body']['to'])){}_0x3db392=_0x5ae118['body']['to'];return db[_0x289b('0x53')]['findOne']({'where':{'id':_0x5ae118['params']['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x5e9267,null))['then'](function(_0x5b73be){if(_0x5b73be){return db[_0x289b('0x53')][_0x289b('0x5b')]({'where':{'id':_0x5b73be['id']},'include':[{'model':db[_0x289b('0x7f')],'as':_0x289b('0x80'),'include':[{'model':db['CmContact'],'as':_0x289b('0x81'),'where':{[_0x5b73be[_0x289b('0x7c')]]:_0x3db392},'limit':0x1,'order':[[_0x289b('0xb3'),'DESC']]}]}]})['then'](handleEntityNotFound(_0x5e9267,null))[_0x289b('0x21')](function(_0x43981a){if(_0x43981a&&_0x43981a[_0x289b('0x80')]){_0x450043=_0x43981a[_0x289b('0x39')]({'plain':!![]});if(_0x450043[_0x289b('0x80')]&&_0x450043[_0x289b('0x80')][_0x289b('0x81')]['length']){return _0x450043[_0x289b('0x80')][_0x289b('0x81')][0x0];}return db[_0x289b('0x72')][_0x289b('0x5c')](_[_0x289b('0x17')](_0x5ae118[_0x289b('0x63')],{'firstName':_0x3db392,[_0x43981a[_0x289b('0x7c')]]:_0x3db392,'phone':_0x3db392,'ListId':_0x450043[_0x289b('0x78')]}));}})[_0x289b('0x21')](handleEntityNotFound(_0x5e9267,null))[_0x289b('0x21')](function(_0x391b34){if(_0x391b34){_0x3225d9=_0x391b34;return db['OpenchannelInteraction'][_0x289b('0x5b')]({'where':{'ContactId':_0x3225d9['id'],'closed':![],'OpenchannelAccountId':_0x450043['id']}})[_0x289b('0x21')](function(_0x2062aa){if(_0x2062aa){return[_0x2062aa,![]];}return db['OpenchannelInteraction']['create']({'UserId':_0x5ae118[_0x289b('0x5d')]['id'],'ContactId':_0x3225d9['id'],'OpenchannelAccountId':_0x450043['id'],'lastMsgDirection':_0x289b('0xb4'),'firstMsgDirection':_0x289b('0xb4'),'Messages':[_['merge'](_0x5ae118['body'],{'read':![],'body':_0x5ae118['body']['body'],'OpenchannelAccountId':_0x450043['id'],'UserId':_0x5ae118[_0x289b('0x5d')]['id'],'ContactId':_0x3225d9['id']})]},{'include':[{'model':db[_0x289b('0x97')],'as':'Messages'}]})[_0x289b('0x21')](function(_0x5a93d4){return[_0x5a93d4,!![]];});});}})['spread'](function(_0x3bb6dd,_0x303876){if(_0x303876){return _0x3bb6dd;}return db[_0x289b('0x97')][_0x289b('0x5c')](_['merge'](_0x5ae118['body'],{'read':![],'body':_0x5ae118[_0x289b('0x63')][_0x289b('0x63')],'OpenchannelAccountId':_0x450043['id'],'OpenchannelInteractionId':_0x3bb6dd['id'],'UserId':_0x5ae118[_0x289b('0x5d')]['id'],'ContactId':_0x3225d9['id']}))[_0x289b('0x21')](function(_0x190816){_0x3bb6dd[_0x289b('0xb5')][_0x289b('0xb6')]=[];_0x3bb6dd[_0x289b('0xb5')]['Messages']['push'](_0x190816[_0x289b('0xb5')]);return _0x3bb6dd;});});}})[_0x289b('0x21')](respondWithResult(_0x5e9267,null))['catch'](handleError(_0x5e9267,null));};
\ No newline at end of file