Built motion from commit 25580385.|2.6.2
[motion2.git] / server / api / openchannelAccount / openchannelAccount.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x51f4=['getAgents','body\x20is\x20mandatory\x20and\x20not\x20empty','out','OpenchannelMessage','Messages','dataValues','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','util','path','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./openchannelAccount.socket','register','client','http','request','then','info','OpenchannelAccount,\x20%s,\x20%s','debug','OpenchannelAccount,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','result','end','status','json','offset','limit','count','set','Content-Range','apply','reject','save','update','get','OpenchannelAccounts','UserProfileResource','destroy','sendStatus','stack','name','send','index','Pause','mandatoryDispositionPause','OpenchannelAccount','rawAttributes','fieldName','type','map','query','keys','filters','intersection','model','attributes','fields','length','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','findAll','rows','catch','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','describe','addDisposition','OpenchannelAccountId','getDispositions','hasOwnProperty','Disposition','removeDispositions','ids','addAnswer','CannedAnswer','findOne','notify','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','updatedAt','CompanyId','isNil','from\x20is\x20mandatory','mapKey','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','from','CmList','List','Applications','applications','list','orderBy','priority','asc','account','Contacts','ListId','contact','firstName','lastName','OpenchannelInteraction','threadId','externalUrl','ContactId','spread','messageId','interaction','created','autoclose','push','close','unmanaged','*,*,*,*','AttachmentId','UserId','User','unshift','agent','waitForTheAssignedAgent','forcedOwnership','Start','startRouting','EventManager','addApplications','transaction','sequelize','Transaction','ISOLATION_LEVELS','READ_COMMITTED','OpenchannelApplication','findAndCountAll','finally','getApplications','getInteractions','Contact','Owner','fullname','internal','Tag','Tags','color','tag','addAgents','omit','emit'];(function(_0xb03a44,_0x4a835b){var _0x2ebf41=function(_0x3bf587){while(--_0x3bf587){_0xb03a44['push'](_0xb03a44['shift']());}};_0x2ebf41(++_0x4a835b);}(_0x51f4,0x18c));var _0x451f=function(_0x321bb2,_0x202794){_0x321bb2=_0x321bb2-0x0;var _0x9c12ed=_0x51f4[_0x321bb2];return _0x9c12ed;};'use strict';var emlformat=require(_0x451f('0x0'));var rimraf=require(_0x451f('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x451f('0x2'));var rp=require(_0x451f('0x3'));var moment=require(_0x451f('0x4'));var BPromise=require(_0x451f('0x5'));var Mustache=require('mustache');var util=require(_0x451f('0x6'));var path=require(_0x451f('0x7'));var sox=require('sox');var csv=require(_0x451f('0x8'));var ejs=require(_0x451f('0x9'));var fs=require('fs');var fs_extra=require(_0x451f('0xa'));var _=require(_0x451f('0xb'));var squel=require(_0x451f('0xc'));var crypto=require('crypto');var jsforce=require(_0x451f('0xd'));var deskjs=require(_0x451f('0xe'));var toCsv=require('to-csv');var querystring=require(_0x451f('0xf'));var Papa=require(_0x451f('0x10'));var Redis=require('ioredis');var authService=require(_0x451f('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x451f('0x12'));var hardwareService=require(_0x451f('0x13'));var logger=require(_0x451f('0x14'))(_0x451f('0x15'));var utils=require(_0x451f('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0x451f('0x17'));var db=require(_0x451f('0x18'))['db'];config[_0x451f('0x19')]=_[_0x451f('0x1a')](config[_0x451f('0x19')],{'host':_0x451f('0x1b'),'port':0x18eb});var socket=require(_0x451f('0x1c'))(new Redis(config[_0x451f('0x19')]));require(_0x451f('0x1d'))[_0x451f('0x1e')](socket);var jayson=require('jayson/promise');var client=jayson[_0x451f('0x1f')][_0x451f('0x20')]({'port':0x232c});var client9002=jayson[_0x451f('0x1f')][_0x451f('0x20')]({'port':0x232a});function respondWithRpcPromise(_0xbb5d02,_0x4eeecc,_0xe7a416,_0x1aa6a7){return new BPromise(function(_0x10da1d,_0x45ecb3){var _0x48494f=_0x1aa6a7||client;return _0x48494f[_0x451f('0x21')](_0xbb5d02,_0xe7a416)[_0x451f('0x22')](function(_0x2e7549){logger[_0x451f('0x23')](_0x451f('0x24'),_0x4eeecc,'request\x20sent');logger[_0x451f('0x25')](_0x451f('0x26'),_0x4eeecc,_0x451f('0x27'),JSON[_0x451f('0x28')](_0x2e7549));if(_0x2e7549['error']){if(_0x2e7549[_0x451f('0x29')][_0x451f('0x2a')]===0x1f4){logger[_0x451f('0x29')](_0x451f('0x24'),_0x4eeecc,_0x2e7549[_0x451f('0x29')][_0x451f('0x2b')]);return _0x45ecb3(_0x2e7549[_0x451f('0x29')][_0x451f('0x2b')]);}logger[_0x451f('0x29')](_0x451f('0x24'),_0x4eeecc,_0x2e7549['error'][_0x451f('0x2b')]);return _0x10da1d(_0x2e7549[_0x451f('0x29')][_0x451f('0x2b')]);}else{logger['info'](_0x451f('0x24'),_0x4eeecc,_0x451f('0x27'));_0x10da1d(_0x2e7549[_0x451f('0x2c')]['message']);}})['catch'](function(_0x1f1381){logger[_0x451f('0x29')](_0x451f('0x24'),_0x4eeecc,_0x1f1381);_0x45ecb3(_0x1f1381);});});}function respondWithStatusCode(_0xef0bf4,_0xc839b){_0xc839b=_0xc839b||0xcc;return function(_0x16c355){if(_0x16c355){return _0xef0bf4['sendStatus'](_0xc839b);}return _0xef0bf4['status'](_0xc839b)[_0x451f('0x2d')]();};}function respondWithResult(_0x35f5fc,_0x3a81ab){_0x3a81ab=_0x3a81ab||0xc8;return function(_0x458206){if(_0x458206){return _0x35f5fc[_0x451f('0x2e')](_0x3a81ab)[_0x451f('0x2f')](_0x458206);}};}function respondWithFilteredResult(_0x302d98,_0x2d11b1){return function(_0x271049){if(_0x271049){var _0x1c6f91=typeof _0x2d11b1[_0x451f('0x30')]==='undefined'&&typeof _0x2d11b1[_0x451f('0x31')]==='undefined';var _0x236a70=_0x271049[_0x451f('0x32')];var _0x53d15c=_0x1c6f91?0x0:_0x2d11b1[_0x451f('0x30')];var _0x4238b0=_0x1c6f91?_0x271049[_0x451f('0x32')]:_0x2d11b1[_0x451f('0x30')]+_0x2d11b1[_0x451f('0x31')];var _0x3c24b3;if(_0x4238b0>=_0x236a70){_0x4238b0=_0x236a70;_0x3c24b3=0xc8;}else{_0x3c24b3=0xce;}_0x302d98[_0x451f('0x2e')](_0x3c24b3);return _0x302d98[_0x451f('0x33')](_0x451f('0x34'),_0x53d15c+'-'+_0x4238b0+'/'+_0x236a70)[_0x451f('0x2f')](_0x271049);}return null;};}function patchUpdates(_0xc7384d){return function(_0x994b1){try{jsonpatch[_0x451f('0x35')](_0x994b1,_0xc7384d,!![]);}catch(_0x4f0d5a){return BPromise[_0x451f('0x36')](_0x4f0d5a);}return _0x994b1[_0x451f('0x37')]();};}function saveUpdates(_0x4d8cf8,_0x399fa3){return function(_0x4e2164){if(_0x4e2164){return _0x4e2164[_0x451f('0x38')](_0x4d8cf8)[_0x451f('0x22')](function(_0x2cb6c3){return _0x2cb6c3;});}return null;};}function removeEntity(_0x28733c,_0x3de04d){return function(_0x540441){if(_0x540441){return _0x540441['destroy']()[_0x451f('0x22')](function(){var _0x44d3e7=_0x540441[_0x451f('0x39')]({'plain':!![]});var _0x23346c=_0x451f('0x3a');return db[_0x451f('0x3b')][_0x451f('0x3c')]({'where':{'type':_0x23346c,'resourceId':_0x44d3e7['id']}})[_0x451f('0x22')](function(){return _0x540441;});})['then'](function(){_0x28733c[_0x451f('0x2e')](0xcc)[_0x451f('0x2d')]();});}};}function handleEntityNotFound(_0x3e8298,_0x51b7fb){return function(_0x48ad0f){if(!_0x48ad0f){_0x3e8298[_0x451f('0x3d')](0x194);}return _0x48ad0f;};}function handleError(_0x309c72,_0x2351fa){_0x2351fa=_0x2351fa||0x1f4;return function(_0x4d0dfe){logger['error'](_0x4d0dfe[_0x451f('0x3e')]);if(_0x4d0dfe[_0x451f('0x3f')]){delete _0x4d0dfe[_0x451f('0x3f')];}_0x309c72[_0x451f('0x2e')](_0x2351fa)[_0x451f('0x40')](_0x4d0dfe);};}exports[_0x451f('0x41')]=function(_0x5a77fd,_0x429a27){var _0x46e0e9={'include':[{'model':db[_0x451f('0x42')],'as':_0x451f('0x43')}]},_0x1038fd={},_0x4045bc={'count':0x0,'rows':[]};var _0x2ae4f6=_['map'](db[_0x451f('0x44')][_0x451f('0x45')],function(_0x2a3f49){return{'name':_0x2a3f49[_0x451f('0x46')],'type':_0x2a3f49[_0x451f('0x47')]['key']};});_0x1038fd['model']=_[_0x451f('0x48')](_0x2ae4f6,_0x451f('0x3f'));_0x1038fd[_0x451f('0x49')]=_[_0x451f('0x4a')](_0x5a77fd[_0x451f('0x49')]);_0x1038fd[_0x451f('0x4b')]=_[_0x451f('0x4c')](_0x1038fd[_0x451f('0x4d')],_0x1038fd[_0x451f('0x49')]);_0x46e0e9[_0x451f('0x4e')]=_[_0x451f('0x4c')](_0x1038fd[_0x451f('0x4d')],qs[_0x451f('0x4f')](_0x5a77fd[_0x451f('0x49')][_0x451f('0x4f')]));_0x46e0e9[_0x451f('0x4e')]=_0x46e0e9[_0x451f('0x4e')][_0x451f('0x50')]?_0x46e0e9[_0x451f('0x4e')]:_0x1038fd[_0x451f('0x4d')];if(!_0x5a77fd[_0x451f('0x49')]['hasOwnProperty'](_0x451f('0x51'))){_0x46e0e9['limit']=qs['limit'](_0x5a77fd[_0x451f('0x49')][_0x451f('0x31')]);_0x46e0e9[_0x451f('0x30')]=qs['offset'](_0x5a77fd[_0x451f('0x49')][_0x451f('0x30')]);}_0x46e0e9[_0x451f('0x52')]=qs[_0x451f('0x53')](_0x5a77fd['query'][_0x451f('0x53')]);_0x46e0e9[_0x451f('0x54')]=qs['filters'](_[_0x451f('0x55')](_0x5a77fd['query'],_0x1038fd['filters']),_0x2ae4f6);if(_0x5a77fd[_0x451f('0x49')][_0x451f('0x56')]){_0x46e0e9['where']=_[_0x451f('0x57')](_0x46e0e9['where'],{'$or':_[_0x451f('0x48')](_0x2ae4f6,function(_0x57ad00){if(_0x57ad00['type']!==_0x451f('0x58')){var _0xf1d45={};_0xf1d45[_0x57ad00[_0x451f('0x3f')]]={'$like':'%'+_0x5a77fd[_0x451f('0x49')][_0x451f('0x56')]+'%'};return _0xf1d45;}})});}_0x46e0e9=_['merge']({},_0x46e0e9,_0x5a77fd['options']);var _0x565ef9={'where':_0x46e0e9['where']};return db[_0x451f('0x44')][_0x451f('0x32')](_0x565ef9)[_0x451f('0x22')](function(_0x3a2ec6){_0x4045bc['count']=_0x3a2ec6;if(_0x5a77fd[_0x451f('0x49')][_0x451f('0x59')]){_0x46e0e9[_0x451f('0x5a')]=[{'all':!![]}];}return db[_0x451f('0x44')][_0x451f('0x5b')](_0x46e0e9);})[_0x451f('0x22')](function(_0x32750b){_0x4045bc[_0x451f('0x5c')]=_0x32750b;return _0x4045bc;})['then'](respondWithFilteredResult(_0x429a27,_0x46e0e9))[_0x451f('0x5d')](handleError(_0x429a27,null));};exports['show']=function(_0x427bdf,_0x17f7e1){var _0x2e9dd8={'raw':![],'where':{'id':_0x427bdf['params']['id']},'include':[{'model':db[_0x451f('0x42')],'as':_0x451f('0x43')}]},_0x50b42c={};_0x50b42c[_0x451f('0x4d')]=_[_0x451f('0x4a')](db[_0x451f('0x44')][_0x451f('0x45')]);_0x50b42c[_0x451f('0x49')]=_[_0x451f('0x4a')](_0x427bdf[_0x451f('0x49')]);_0x50b42c['filters']=_[_0x451f('0x4c')](_0x50b42c[_0x451f('0x4d')],_0x50b42c['query']);_0x2e9dd8['attributes']=_['intersection'](_0x50b42c[_0x451f('0x4d')],qs[_0x451f('0x4f')](_0x427bdf[_0x451f('0x49')][_0x451f('0x4f')]));_0x2e9dd8[_0x451f('0x4e')]=_0x2e9dd8[_0x451f('0x4e')][_0x451f('0x50')]?_0x2e9dd8['attributes']:_0x50b42c[_0x451f('0x4d')];if(_0x427bdf[_0x451f('0x49')]['includeAll']){_0x2e9dd8[_0x451f('0x5a')]=[{'all':!![]}];}_0x2e9dd8=_['merge']({},_0x2e9dd8,_0x427bdf[_0x451f('0x5e')]);return db[_0x451f('0x44')][_0x451f('0x5f')](_0x2e9dd8)[_0x451f('0x22')](handleEntityNotFound(_0x17f7e1,null))[_0x451f('0x22')](respondWithResult(_0x17f7e1,null))[_0x451f('0x5d')](handleError(_0x17f7e1,null));};exports[_0x451f('0x60')]=function(_0x463e77,_0x3a5488){return db['OpenchannelAccount'][_0x451f('0x60')](_0x463e77[_0x451f('0x61')],{})['then'](function(_0x3662b6){var _0x4018b6=_0x463e77[_0x451f('0x62')][_0x451f('0x39')]({'plain':!![]});if(!_0x4018b6)throw new Error(_0x451f('0x63'));if(_0x4018b6[_0x451f('0x64')]===_0x451f('0x62')){var _0x4a4640=_0x3662b6[_0x451f('0x39')]({'plain':!![]});var _0x19e7c8=_0x451f('0x3a');return db[_0x451f('0x65')]['find']({'where':{'name':_0x19e7c8,'userProfileId':_0x4018b6[_0x451f('0x66')]},'raw':!![]})[_0x451f('0x22')](function(_0x4aee5b){if(_0x4aee5b&&_0x4aee5b[_0x451f('0x67')]===0x0){return db[_0x451f('0x3b')][_0x451f('0x60')]({'name':_0x4a4640[_0x451f('0x3f')],'resourceId':_0x4a4640['id'],'type':_0x4aee5b[_0x451f('0x3f')],'sectionId':_0x4aee5b['id']},{})[_0x451f('0x22')](function(){return _0x3662b6;});}else{return _0x3662b6;}})[_0x451f('0x5d')](function(_0x295c60){logger['error'](_0x451f('0x68'),_0x295c60);throw _0x295c60;});}return _0x3662b6;})[_0x451f('0x22')](respondWithResult(_0x3a5488,0xc9))[_0x451f('0x5d')](handleError(_0x3a5488,null));};exports[_0x451f('0x38')]=function(_0x3c243f,_0xab6aef){if(_0x3c243f['body']['id']){delete _0x3c243f[_0x451f('0x61')]['id'];}return db['OpenchannelAccount'][_0x451f('0x5f')]({'where':{'id':_0x3c243f[_0x451f('0x69')]['id']},'include':[{'model':db['Pause'],'as':_0x451f('0x43')}]})[_0x451f('0x22')](handleEntityNotFound(_0xab6aef,null))[_0x451f('0x22')](saveUpdates(_0x3c243f[_0x451f('0x61')],null))[_0x451f('0x22')](respondWithResult(_0xab6aef,null))[_0x451f('0x5d')](handleError(_0xab6aef,null));};exports[_0x451f('0x3c')]=function(_0x26c46b,_0x14c61c){return db[_0x451f('0x44')][_0x451f('0x5f')]({'where':{'id':_0x26c46b[_0x451f('0x69')]['id']}})[_0x451f('0x22')](handleEntityNotFound(_0x14c61c,null))[_0x451f('0x22')](removeEntity(_0x14c61c,null))[_0x451f('0x5d')](handleError(_0x14c61c,null));};exports[_0x451f('0x6a')]=function(_0x18ef4,_0x124a4a){return db[_0x451f('0x44')][_0x451f('0x6a')]()[_0x451f('0x22')](respondWithResult(_0x124a4a,null))['catch'](handleError(_0x124a4a,null));};exports[_0x451f('0x6b')]=function(_0x4d5fe9,_0x3a1473,_0x4aeb94){if(_0x4d5fe9['body']['id']){delete _0x4d5fe9['body']['id'];}return db[_0x451f('0x44')][_0x451f('0x5f')]({'where':{'id':_0x4d5fe9[_0x451f('0x69')]['id']}})[_0x451f('0x22')](handleEntityNotFound(_0x3a1473,null))[_0x451f('0x22')](function(_0x373fea){if(_0x373fea){_0x4d5fe9[_0x451f('0x61')][_0x451f('0x6c')]=_0x373fea['id'];return db['Disposition'][_0x451f('0x60')](_0x4d5fe9[_0x451f('0x61')]);}})[_0x451f('0x22')](respondWithResult(_0x3a1473,null))[_0x451f('0x5d')](handleError(_0x3a1473,null));};exports[_0x451f('0x6d')]=function(_0x501b5e,_0xe23e34,_0xda18e8){var _0x5752e8={'raw':![],'where':{}};var _0x1a6bce={};var _0x26bcc3={'count':0x0,'rows':[]};return db['OpenchannelAccount']['findOne']({'where':{'id':_0x501b5e[_0x451f('0x69')]['id']}})[_0x451f('0x22')](handleEntityNotFound(_0xe23e34,null))[_0x451f('0x22')](function(_0x2b432e){if(_0x2b432e){_0x1a6bce[_0x451f('0x4d')]=_['keys'](db['Disposition'][_0x451f('0x45')]);_0x1a6bce['query']=_[_0x451f('0x4a')](_0x501b5e['query']);_0x1a6bce['filters']=_[_0x451f('0x4c')](_0x1a6bce['model'],_0x1a6bce[_0x451f('0x49')]);_0x5752e8[_0x451f('0x4e')]=_['intersection'](_0x1a6bce[_0x451f('0x4d')],qs['fields'](_0x501b5e[_0x451f('0x49')][_0x451f('0x4f')]));_0x5752e8[_0x451f('0x4e')]=_0x5752e8[_0x451f('0x4e')]['length']?_0x5752e8[_0x451f('0x4e')]:_0x1a6bce['model'];if(!_0x501b5e[_0x451f('0x49')][_0x451f('0x6e')](_0x451f('0x51'))){_0x5752e8['limit']=qs['limit'](_0x501b5e['query'][_0x451f('0x31')]);_0x5752e8[_0x451f('0x30')]=qs['offset'](_0x501b5e[_0x451f('0x49')][_0x451f('0x30')]);}_0x5752e8[_0x451f('0x52')]=qs[_0x451f('0x53')](_0x501b5e[_0x451f('0x49')][_0x451f('0x53')]);_0x5752e8['where']=qs[_0x451f('0x4b')](_['pick'](_0x501b5e[_0x451f('0x49')],_0x1a6bce[_0x451f('0x4b')]));_0x5752e8[_0x451f('0x54')][_0x451f('0x6c')]=_0x2b432e['id'];if(_0x501b5e[_0x451f('0x49')][_0x451f('0x56')]){_0x5752e8[_0x451f('0x54')]=_[_0x451f('0x57')](_0x5752e8[_0x451f('0x54')],{'$or':_[_0x451f('0x48')](_0x5752e8[_0x451f('0x4e')],function(_0x2ba32b){var _0x255bf0={};_0x255bf0[_0x2ba32b]={'$like':'%'+_0x501b5e[_0x451f('0x49')]['filter']+'%'};return _0x255bf0;})});}_0x5752e8=_[_0x451f('0x57')]({},_0x5752e8,_0x501b5e[_0x451f('0x5e')]);return db[_0x451f('0x6f')][_0x451f('0x32')]({'where':_0x5752e8['where']})[_0x451f('0x22')](function(_0x3473d4){_0x26bcc3[_0x451f('0x32')]=_0x3473d4;if(_0x501b5e[_0x451f('0x49')][_0x451f('0x59')]){_0x5752e8[_0x451f('0x5a')]=[{'all':!![]}];}return db[_0x451f('0x6f')]['findAll'](_0x5752e8);})[_0x451f('0x22')](function(_0x2b04a7){_0x26bcc3[_0x451f('0x5c')]=_0x2b04a7;return _0x26bcc3;});}})[_0x451f('0x22')](respondWithFilteredResult(_0xe23e34,_0x5752e8))[_0x451f('0x5d')](handleError(_0xe23e34,null));};exports[_0x451f('0x70')]=function(_0xbf965d,_0x16085b,_0x1549d0){return db[_0x451f('0x44')][_0x451f('0x5f')]({'where':{'id':_0xbf965d[_0x451f('0x69')]['id']}})[_0x451f('0x22')](handleEntityNotFound(_0x16085b,null))[_0x451f('0x22')](function(_0x240c6d){if(_0x240c6d){return _0x240c6d[_0x451f('0x70')](_0xbf965d[_0x451f('0x49')][_0x451f('0x71')]);}})['then'](respondWithStatusCode(_0x16085b,null))[_0x451f('0x5d')](handleError(_0x16085b,null));};exports[_0x451f('0x72')]=function(_0x537436,_0x3fabb5,_0x48f8bb){if(_0x537436['body']['id']){delete _0x537436['body']['id'];}return db[_0x451f('0x44')]['find']({'where':{'id':_0x537436['params']['id']}})[_0x451f('0x22')](handleEntityNotFound(_0x3fabb5,null))[_0x451f('0x22')](function(_0x8f39ea){if(_0x8f39ea){_0x537436['body'][_0x451f('0x6c')]=_0x8f39ea['id'];return db[_0x451f('0x73')][_0x451f('0x60')](_0x537436[_0x451f('0x61')]);}})[_0x451f('0x22')](respondWithResult(_0x3fabb5,null))['catch'](handleError(_0x3fabb5,null));};exports['getAnswers']=function(_0x2b916b,_0x327b13,_0x459da6){var _0x5cec83={'raw':![],'where':{}};var _0x3bcc5a={};var _0x116be4={'count':0x0,'rows':[]};return db[_0x451f('0x44')][_0x451f('0x74')]({'where':{'id':_0x2b916b[_0x451f('0x69')]['id']}})['then'](handleEntityNotFound(_0x327b13,null))[_0x451f('0x22')](function(_0x54008d){if(_0x54008d){_0x3bcc5a[_0x451f('0x4d')]=_[_0x451f('0x4a')](db['CannedAnswer']['rawAttributes']);_0x3bcc5a[_0x451f('0x49')]=_['keys'](_0x2b916b[_0x451f('0x49')]);_0x3bcc5a[_0x451f('0x4b')]=_['intersection'](_0x3bcc5a[_0x451f('0x4d')],_0x3bcc5a[_0x451f('0x49')]);_0x5cec83[_0x451f('0x4e')]=_[_0x451f('0x4c')](_0x3bcc5a[_0x451f('0x4d')],qs[_0x451f('0x4f')](_0x2b916b['query'][_0x451f('0x4f')]));_0x5cec83[_0x451f('0x4e')]=_0x5cec83['attributes'][_0x451f('0x50')]?_0x5cec83['attributes']:_0x3bcc5a['model'];if(!_0x2b916b[_0x451f('0x49')][_0x451f('0x6e')]('nolimit')){_0x5cec83[_0x451f('0x31')]=qs[_0x451f('0x31')](_0x2b916b[_0x451f('0x49')][_0x451f('0x31')]);_0x5cec83[_0x451f('0x30')]=qs[_0x451f('0x30')](_0x2b916b[_0x451f('0x49')][_0x451f('0x30')]);}_0x5cec83[_0x451f('0x52')]=qs[_0x451f('0x53')](_0x2b916b[_0x451f('0x49')][_0x451f('0x53')]);_0x5cec83['where']=qs[_0x451f('0x4b')](_[_0x451f('0x55')](_0x2b916b[_0x451f('0x49')],_0x3bcc5a[_0x451f('0x4b')]));_0x5cec83['where'][_0x451f('0x6c')]=_0x54008d['id'];if(_0x2b916b[_0x451f('0x49')][_0x451f('0x56')]){_0x5cec83[_0x451f('0x54')]=_[_0x451f('0x57')](_0x5cec83[_0x451f('0x54')],{'$or':_[_0x451f('0x48')](_0x5cec83[_0x451f('0x4e')],function(_0x2d88a2){var _0x59bcdd={};_0x59bcdd[_0x2d88a2]={'$like':'%'+_0x2b916b[_0x451f('0x49')][_0x451f('0x56')]+'%'};return _0x59bcdd;})});}_0x5cec83=_[_0x451f('0x57')]({},_0x5cec83,_0x2b916b[_0x451f('0x5e')]);return db[_0x451f('0x73')][_0x451f('0x32')]({'where':_0x5cec83[_0x451f('0x54')]})[_0x451f('0x22')](function(_0x2ecb77){_0x116be4['count']=_0x2ecb77;if(_0x2b916b[_0x451f('0x49')]['includeAll']){_0x5cec83['include']=[{'all':!![]}];}return db[_0x451f('0x73')]['findAll'](_0x5cec83);})['then'](function(_0x3be339){_0x116be4[_0x451f('0x5c')]=_0x3be339;return _0x116be4;});}})[_0x451f('0x22')](respondWithFilteredResult(_0x327b13,_0x5cec83))[_0x451f('0x5d')](handleError(_0x327b13,null));};exports['removeAnswers']=function(_0x39d831,_0x5590eb,_0x3a4080){return db['OpenchannelAccount'][_0x451f('0x5f')]({'where':{'id':_0x39d831['params']['id']}})[_0x451f('0x22')](handleEntityNotFound(_0x5590eb,null))[_0x451f('0x22')](function(_0x7e9b4c){if(_0x7e9b4c){return _0x7e9b4c['removeAnswers'](_0x39d831[_0x451f('0x49')][_0x451f('0x71')]);}})['then'](respondWithStatusCode(_0x5590eb,null))[_0x451f('0x5d')](handleError(_0x5590eb,null));};exports[_0x451f('0x75')]=function(_0x521b1b,_0x16c990,_0x454d3e){var _0x18da54={'body':_0x521b1b['body'],'channel':'openchannel'};var _0x4facae=[];var _0x4a269c=[];var _0x1131c5={};var _0x245543=![];return db[_0x451f('0x76')][_0x451f('0x6a')]()[_0x451f('0x22')](function(_0x488f98){if(!_0x488f98){throw new db[(_0x451f('0x77'))][(_0x451f('0x78'))](_0x451f('0x79'));}_0x4facae=_[_0x451f('0x7a')](_['keys'](_0x488f98),['createdAt',_0x451f('0x7b')]);_0x4a269c=_[_0x451f('0x7a')](_[_0x451f('0x4a')](_0x488f98),['createdAt','updatedAt',_0x451f('0x7c'),'ListId']);if(_0x521b1b[_0x451f('0x61')]['id']){delete _0x521b1b[_0x451f('0x61')]['id'];}if(_[_0x451f('0x7d')](_0x521b1b[_0x451f('0x61')]['from'])){throw new db[(_0x451f('0x77'))][(_0x451f('0x78'))](_0x451f('0x7e'));}if(_[_0x451f('0x7d')](_0x521b1b['body']['body'])||_0x521b1b[_0x451f('0x61')][_0x451f('0x61')]===''){throw new db[(_0x451f('0x77'))][(_0x451f('0x78'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x451f('0x7d')](_0x521b1b[_0x451f('0x61')]['mapKey'])){throw new db[(_0x451f('0x77'))][(_0x451f('0x78'))]('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x4a269c);}if(!_['includes'](_0x4a269c,_0x521b1b[_0x451f('0x61')][_0x451f('0x7f')])){throw new db['Sequelize'][(_0x451f('0x78'))](_0x451f('0x80')+_0x4a269c);}_0x1131c5[_0x521b1b[_0x451f('0x61')][_0x451f('0x7f')]]=_0x521b1b['body'][_0x451f('0x81')];})[_0x451f('0x22')](function(){return db[_0x451f('0x44')][_0x451f('0x5f')]({'where':{'id':_0x521b1b['params']['id']},'include':[{'model':db[_0x451f('0x82')],'as':_0x451f('0x83'),'include':[{'model':db[_0x451f('0x76')],'as':'Contacts','where':_0x1131c5,'limit':0x1,'order':[[_0x451f('0x7b'),'DESC']]}]},{'model':db['OpenchannelApplication'],'as':_0x451f('0x84')}]});})[_0x451f('0x22')](handleEntityNotFound(_0x16c990,null))[_0x451f('0x22')](function(_0x4b9bc4){if(_0x4b9bc4&&_0x4b9bc4['List']){_0x18da54['account']=_0x4b9bc4;_0x18da54[_0x451f('0x85')]=_0x4b9bc4['Applications'];_0x18da54[_0x451f('0x86')]=_0x4b9bc4[_0x451f('0x83')];_0x18da54[_0x451f('0x85')]=_[_0x451f('0x87')](_0x18da54[_0x451f('0x85')],[_0x451f('0x88')],[_0x451f('0x89')]);if(_0x18da54[_0x451f('0x8a')][_0x451f('0x84')]){delete _0x18da54['account']['Applications'];}if(_0x18da54['account'][_0x451f('0x83')]&&_0x18da54[_0x451f('0x8a')][_0x451f('0x83')][_0x451f('0x8b')][_0x451f('0x50')]){return _0x18da54['account']['List'][_0x451f('0x8b')][0x0];}var _0x15481d=_[_0x451f('0x1a')](_0x521b1b[_0x451f('0x61')],{'firstName':_0x521b1b['body'][_0x451f('0x81')],'ListId':_0x4b9bc4[_0x451f('0x8c')]});_0x15481d[_0x521b1b[_0x451f('0x61')][_0x451f('0x7f')]]=_0x521b1b[_0x451f('0x61')]['from'];return db[_0x451f('0x76')]['create'](_0x15481d,{'fields':_0x4facae,'raw':!![]});}})[_0x451f('0x22')](handleEntityNotFound(_0x16c990,null))[_0x451f('0x22')](function(_0x2b1a9e){_0x18da54[_0x451f('0x8d')]=_0x2b1a9e;if(_0x2b1a9e){var _0x3c4187={'ContactId':_0x2b1a9e['id'],'OpenchannelAccountId':_0x521b1b[_0x451f('0x69')]['id'],'from':(_0x2b1a9e[_0x451f('0x8e')]||'')+'\x20'+(_0x2b1a9e[_0x451f('0x8f')]||'')};var _0x530151={'OpenchannelAccountId':_0x521b1b[_0x451f('0x69')]['id'],'closed':![]};if(_0x521b1b[_0x451f('0x61')]['threadId']){_0x530151['threadId']=_0x521b1b[_0x451f('0x61')]['threadId'];return db[_0x451f('0x90')]['find']({'where':_0x530151})[_0x451f('0x22')](function(_0x310e5c){if(_0x310e5c){return[_0x310e5c,![]];}_0x3c4187[_0x451f('0x91')]=_0x521b1b[_0x451f('0x61')]['threadId'];_0x3c4187[_0x451f('0x92')]=_0x521b1b['body'][_0x451f('0x92')];return db[_0x451f('0x90')]['create'](_0x3c4187)[_0x451f('0x22')](function(_0x50f489){return[_0x50f489,!![]];});});}else{_0x530151[_0x451f('0x91')]=null;}_0x530151[_0x451f('0x93')]=_0x2b1a9e['id'];return db[_0x451f('0x90')]['find']({'where':_0x530151})[_0x451f('0x22')](function(_0x139637){if(_0x139637){return[_0x139637,![]];}return db[_0x451f('0x90')]['create'](_0x3c4187)[_0x451f('0x22')](function(_0x51ec21){return[_0x51ec21,!![]];});});}})[_0x451f('0x94')](function(_0xe6aceb,_0x1303f7){if(_0xe6aceb){_0x245543=_0x1303f7;if(!_0x1303f7){var _0x522032={'from':(_0x18da54['contact'][_0x451f('0x8e')]||'')+'\x20'+(_0x18da54[_0x451f('0x8d')][_0x451f('0x8f')]||'')};if(_0x521b1b[_0x451f('0x61')][_0x451f('0x91')]&&_0x521b1b[_0x451f('0x61')][_0x451f('0x95')]&&_0x521b1b[_0x451f('0x61')]['threadId']!=_0x521b1b[_0x451f('0x61')][_0x451f('0x95')]){_0x522032[_0x451f('0x91')]=_0x521b1b[_0x451f('0x61')]['messageId'];}return _0xe6aceb['update'](_0x522032);}else{return _0xe6aceb;}}})[_0x451f('0x22')](function(_0x1bf365){_0x18da54['interaction']=_0x1bf365[_0x451f('0x39')]({'plain':!![]});_0x18da54[_0x451f('0x96')][_0x451f('0x97')]=_0x245543;if(_0x18da54[_0x451f('0x96')][_0x451f('0x97')]){if(_0x18da54[_0x451f('0x8a')][_0x451f('0x98')]){_0x18da54[_0x451f('0x85')][_0x451f('0x99')]({'id':0x0,'priority':_0x18da54['applications'][_0x451f('0x50')]+0x1,'app':_0x451f('0x9a'),'appdata':_0x451f('0x9b'),'interval':_0x451f('0x9c')});}}return db['OpenchannelMessage'][_0x451f('0x60')]({'body':_0x521b1b[_0x451f('0x61')][_0x451f('0x61')],'OpenchannelAccountId':_0x521b1b[_0x451f('0x69')]['id'],'OpenchannelInteractionId':_0x1bf365['id'],'direction':'in','ContactId':_0x18da54[_0x451f('0x8d')]['id'],'AttachmentId':_0x521b1b['body'][_0x451f('0x9d')]});})[_0x451f('0x22')](function(_0x83f7e2){_0x18da54['message']=_0x83f7e2;if(_0x18da54['interaction'][_0x451f('0x9e')]){return db[_0x451f('0x9f')][_0x451f('0x5f')]({'attributes':['id','name'],'where':{'id':_0x18da54['interaction'][_0x451f('0x9e')]}})['then'](function(_0x3a0e57){if(_0x3a0e57){_0x18da54[_0x451f('0x85')][_0x451f('0xa0')]({'id':0x0,'priority':0x0,'app':_0x451f('0xa1'),'appdata':_0x3a0e57[_0x451f('0x3f')]+','+(_0x18da54[_0x451f('0x8a')][_0x451f('0xa2')]||0xa),'interval':_0x451f('0x9c')});_0x18da54[_0x451f('0xa3')]=![];}return respondWithRpcPromise(_0x451f('0xa4'),_0x451f('0xa5'),_0x18da54);});}return respondWithRpcPromise('Start','startRouting',_0x18da54);})[_0x451f('0x22')](function(_0x412dca){respondWithRpcPromise(_0x451f('0xa6'),'EventManager',{'event':_0x451f('0x75'),'message':_0x412dca},client9002);return _0x412dca;})[_0x451f('0x22')](respondWithResult(_0x16c990,null))[_0x451f('0x5d')](handleError(_0x16c990,null));};exports[_0x451f('0xa7')]=function(_0x51a36c,_0x5a7fda){var _0x107d9b=_0x51a36c[_0x451f('0x69')]['id'];var _0x5e0962=_0x51a36c[_0x451f('0x61')];var _0x54fc22=0xc8;var _0x4e9750=null;return db['sequelize'][_0x451f('0xa8')]({'isolationLevel':db[_0x451f('0xa9')][_0x451f('0xaa')][_0x451f('0xab')][_0x451f('0xac')]},function(_0x481f50){return db[_0x451f('0x44')]['findOne']({'where':{'id':_0x107d9b},'transaction':_0x481f50})[_0x451f('0x22')](function(_0xa0d6b5){if(_0xa0d6b5){return db['OpenchannelApplication']['destroy']({'where':{'OpenchannelAccountId':_0x107d9b},'transaction':_0x481f50})['then'](function(){var _0x2a5ca3=_[_0x451f('0x48')](_0x5e0962,function(_0x5748f8){_0x5748f8[_0x451f('0x6c')]=_0x107d9b;return _0x5748f8;});return db[_0x451f('0xad')]['bulkCreate'](_0x2a5ca3,{'transaction':_0x481f50});});}else{_0x54fc22=0x194;_0x4e9750=[];}});})[_0x451f('0x22')](function(){if(_0x54fc22!==0x194){return db[_0x451f('0xad')][_0x451f('0xae')]({'where':{'OpenchannelAccountId':_0x107d9b},'order':'priority'})[_0x451f('0x22')](function(_0x4301c4){_0x4e9750=_0x4301c4;});}})[_0x451f('0x5d')](function(_0x36049b){_0x54fc22=0x1f4;logger['error'](_0x36049b[_0x451f('0x3e')]);if(_0x36049b[_0x451f('0x3f')]){delete _0x36049b[_0x451f('0x3f')];}_0x4e9750=_0x36049b;})[_0x451f('0xaf')](function(){if(_0x4e9750===null){_0x5a7fda['sendStatus'](_0x54fc22);}else{if(_0x54fc22===0x1f4){_0x5a7fda[_0x451f('0x2e')](_0x54fc22)['send'](_0x4e9750);}else{_0x5a7fda[_0x451f('0x2e')](_0x54fc22)[_0x451f('0x2f')](_0x4e9750);}}});};exports[_0x451f('0xb0')]=function(_0xa79db9,_0x52364d,_0x427712){var _0x4267e4={};var _0x59b9ce={};var _0x43e036;var _0x10ab1a;return db[_0x451f('0x44')][_0x451f('0x74')]({'where':{'id':_0xa79db9[_0x451f('0x69')]['id']}})[_0x451f('0x22')](handleEntityNotFound(_0x52364d,null))[_0x451f('0x22')](function(_0x3b0e35){if(_0x3b0e35){_0x43e036=_0x3b0e35;_0x59b9ce['model']=_[_0x451f('0x4a')](db[_0x451f('0xad')]['rawAttributes']);_0x59b9ce[_0x451f('0x49')]=_[_0x451f('0x4a')](_0xa79db9[_0x451f('0x49')]);_0x59b9ce[_0x451f('0x4b')]=_[_0x451f('0x4c')](_0x59b9ce['model'],_0x59b9ce[_0x451f('0x49')]);_0x4267e4[_0x451f('0x4e')]=_[_0x451f('0x4c')](_0x59b9ce[_0x451f('0x4d')],qs[_0x451f('0x4f')](_0xa79db9['query']['fields']));_0x4267e4[_0x451f('0x4e')]=_0x4267e4[_0x451f('0x4e')][_0x451f('0x50')]?_0x4267e4[_0x451f('0x4e')]:_0x59b9ce[_0x451f('0x4d')];_0x4267e4[_0x451f('0x52')]=qs['sort'](_0xa79db9[_0x451f('0x49')][_0x451f('0x53')]);_0x4267e4[_0x451f('0x54')]=qs[_0x451f('0x4b')](_[_0x451f('0x55')](_0xa79db9[_0x451f('0x49')],_0x59b9ce[_0x451f('0x4b')]));if(_0xa79db9[_0x451f('0x49')]['filter']){_0x4267e4[_0x451f('0x54')]=_[_0x451f('0x57')](_0x4267e4[_0x451f('0x54')],{'$or':_[_0x451f('0x48')](_0x4267e4['attributes'],function(_0x4fb4db){var _0x2ea1d0={};_0x2ea1d0[_0x4fb4db]={'$like':'%'+_0xa79db9[_0x451f('0x49')][_0x451f('0x56')]+'%'};return _0x2ea1d0;})});}_0x4267e4=_[_0x451f('0x57')]({},_0x4267e4,_0xa79db9[_0x451f('0x5e')]);return _0x43e036['getApplications'](_0x4267e4);}})[_0x451f('0x22')](function(_0x1a2569){if(_0x1a2569){_0x10ab1a=_0x1a2569[_0x451f('0x50')];if(!_0xa79db9['query'][_0x451f('0x6e')](_0x451f('0x51'))){_0x4267e4['limit']=qs['limit'](_0xa79db9[_0x451f('0x49')][_0x451f('0x31')]);_0x4267e4[_0x451f('0x30')]=qs['offset'](_0xa79db9[_0x451f('0x49')][_0x451f('0x30')]);}return _0x43e036[_0x451f('0xb0')](_0x4267e4);}})[_0x451f('0x22')](function(_0x3ab6d9){if(_0x3ab6d9){return _0x3ab6d9?{'count':_0x10ab1a,'rows':_0x3ab6d9}:null;}})[_0x451f('0x22')](respondWithResult(_0x52364d,null))[_0x451f('0x5d')](handleError(_0x52364d,null));};exports[_0x451f('0xb1')]=function(_0xfc4656,_0x5d6465,_0x5a18bc){var _0x4a9f2d={'raw':![],'where':{}};var _0x3e1a07={};var _0x1f7a39={'count':0x0,'rows':[]};return db[_0x451f('0x44')]['findOne']({'where':{'id':_0xfc4656[_0x451f('0x69')]['id']}})[_0x451f('0x22')](handleEntityNotFound(_0x5d6465,null))[_0x451f('0x22')](function(_0x1ad5a7){if(_0x1ad5a7){_0x3e1a07['model']=_[_0x451f('0x4a')](db[_0x451f('0x90')][_0x451f('0x45')]);_0x3e1a07[_0x451f('0x49')]=_[_0x451f('0x4a')](_0xfc4656['query']);_0x3e1a07['filters']=_[_0x451f('0x4c')](_0x3e1a07[_0x451f('0x4d')],_0x3e1a07[_0x451f('0x49')]);_0x4a9f2d['attributes']=_['intersection'](_0x3e1a07[_0x451f('0x4d')],qs[_0x451f('0x4f')](_0xfc4656[_0x451f('0x49')]['fields']));_0x4a9f2d[_0x451f('0x4e')]=_0x4a9f2d[_0x451f('0x4e')][_0x451f('0x50')]?_0x4a9f2d[_0x451f('0x4e')]:_0x3e1a07[_0x451f('0x4d')];if(!_0xfc4656[_0x451f('0x49')][_0x451f('0x6e')]('nolimit')){_0x4a9f2d[_0x451f('0x31')]=qs[_0x451f('0x31')](_0xfc4656[_0x451f('0x49')][_0x451f('0x31')]);_0x4a9f2d['offset']=qs[_0x451f('0x30')](_0xfc4656[_0x451f('0x49')]['offset']);}_0x4a9f2d[_0x451f('0x52')]=qs[_0x451f('0x53')](_0xfc4656[_0x451f('0x49')][_0x451f('0x53')]);_0x4a9f2d[_0x451f('0x54')]=qs[_0x451f('0x4b')](_['pick'](_0xfc4656[_0x451f('0x49')],_0x3e1a07[_0x451f('0x4b')]));_0x4a9f2d[_0x451f('0x54')][_0x451f('0x6c')]=_0x1ad5a7['id'];if(_0xfc4656[_0x451f('0x49')][_0x451f('0x56')]){_0x4a9f2d[_0x451f('0x54')]=_[_0x451f('0x57')](_0x4a9f2d['where'],{'$or':_['map'](_0x4a9f2d['attributes'],function(_0x4412f0){var _0x455d58={};_0x455d58[_0x4412f0]={'$like':'%'+_0xfc4656['query']['filter']+'%'};return _0x455d58;})});}_0x4a9f2d=_[_0x451f('0x57')]({},_0x4a9f2d,_0xfc4656['options']);return db[_0x451f('0x90')][_0x451f('0x32')]({'where':_0x4a9f2d[_0x451f('0x54')]})['then'](function(_0x2a2a7a){_0x1f7a39['count']=_0x2a2a7a;if(_0xfc4656[_0x451f('0x49')]['includeAll']){_0x4a9f2d[_0x451f('0x5a')]=[{'model':db['CmContact'],'as':_0x451f('0xb2'),'required':![]},{'model':db['User'],'as':_0x451f('0xb3'),'attributes':[_0x451f('0x3f'),_0x451f('0xb4'),_0x451f('0xb5')],'required':![]},{'model':db[_0x451f('0xb6')],'as':_0x451f('0xb7'),'attributes':['id','name',_0x451f('0xb8')],'where':_0xfc4656[_0x451f('0x49')][_0x451f('0xb9')]?{'id':_0xfc4656[_0x451f('0x49')][_0x451f('0xb9')]}:undefined,'required':_0xfc4656[_0x451f('0x49')][_0x451f('0xb9')]?!![]:![]}];}return db[_0x451f('0x90')][_0x451f('0x5b')](_0x4a9f2d);})[_0x451f('0x22')](function(_0x28aa45){_0x1f7a39[_0x451f('0x5c')]=_0x28aa45;return _0x1f7a39;});}})['then'](respondWithFilteredResult(_0x5d6465,_0x4a9f2d))[_0x451f('0x5d')](handleError(_0x5d6465,null));};exports[_0x451f('0xba')]=function(_0x284143,_0x5a3c2c,_0x3de319){return db['OpenchannelAccount'][_0x451f('0x5f')]({'where':{'id':_0x284143[_0x451f('0x69')]['id']}})[_0x451f('0x22')](handleEntityNotFound(_0x5a3c2c,null))[_0x451f('0x22')](function(_0x53fbb1){if(_0x53fbb1){return _0x53fbb1[_0x451f('0xba')](_0x284143[_0x451f('0x61')][_0x451f('0x71')],_[_0x451f('0xbb')](_0x284143['body'],[_0x451f('0x71'),'id'])||{})[_0x451f('0x94')](function(_0x5eb88b){for(var _0x40d049=0x0;_0x40d049<_0x284143[_0x451f('0x61')]['ids'][_0x451f('0x50')];_0x40d049+=0x1){socket[_0x451f('0xbc')]('userOpenchannelAccount:save',{'UserId':Number(_0x284143[_0x451f('0x61')][_0x451f('0x71')][_0x40d049]),'OpenchannelAccountId':Number(_0x284143[_0x451f('0x69')]['id'])});}return _0x5eb88b;});}})[_0x451f('0x22')](respondWithResult(_0x5a3c2c,null))[_0x451f('0x5d')](handleError(_0x5a3c2c,null));};exports['removeAgents']=function(_0x28ebd4,_0x5bfe21,_0x1de8b8){return db['OpenchannelAccount'][_0x451f('0x5f')]({'where':{'id':_0x28ebd4['params']['id']}})[_0x451f('0x22')](handleEntityNotFound(_0x5bfe21,null))[_0x451f('0x22')](function(_0x509007){if(_0x509007){return _0x509007['removeAgents'](_0x28ebd4[_0x451f('0x49')][_0x451f('0x71')])[_0x451f('0x22')](function(){if(_['isArray'](_0x28ebd4[_0x451f('0x49')][_0x451f('0x71')])){for(var _0x56d39b=0x0;_0x56d39b<_0x28ebd4[_0x451f('0x49')]['ids']['length'];_0x56d39b+=0x1){socket['emit']('userOpenchannelAccount:remove',{'UserId':Number(_0x28ebd4[_0x451f('0x49')]['ids'][_0x56d39b]),'OpenchannelAccountId':Number(_0x28ebd4[_0x451f('0x69')]['id'])});}}else{socket[_0x451f('0xbc')]('userOpenchannelAccount:remove',{'UserId':Number(_0x28ebd4[_0x451f('0x49')][_0x451f('0x71')]),'OpenchannelAccountId':Number(_0x28ebd4[_0x451f('0x69')]['id'])});}});}})[_0x451f('0x22')](respondWithStatusCode(_0x5bfe21,null))[_0x451f('0x5d')](handleError(_0x5bfe21,null));};exports['getAgents']=function(_0x3b57fc,_0x514ce8,_0x4830ad){var _0x13d23c={};var _0x2ed796={};var _0x38e15f;var _0x5be2ba;return db[_0x451f('0x44')][_0x451f('0x74')]({'where':{'id':_0x3b57fc[_0x451f('0x69')]['id']}})[_0x451f('0x22')](handleEntityNotFound(_0x514ce8,null))['then'](function(_0x9ea51c){if(_0x9ea51c){_0x38e15f=_0x9ea51c;_0x2ed796[_0x451f('0x4d')]=_[_0x451f('0x4a')](db[_0x451f('0x9f')][_0x451f('0x45')]);_0x2ed796[_0x451f('0x49')]=_[_0x451f('0x4a')](_0x3b57fc['query']);_0x2ed796[_0x451f('0x4b')]=_[_0x451f('0x4c')](_0x2ed796['model'],_0x2ed796['query']);_0x13d23c['attributes']=_[_0x451f('0x4c')](_0x2ed796[_0x451f('0x4d')],qs['fields'](_0x3b57fc['query']['fields']));_0x13d23c[_0x451f('0x4e')]=_0x13d23c[_0x451f('0x4e')]['length']?_0x13d23c[_0x451f('0x4e')]:_0x2ed796[_0x451f('0x4d')];_0x13d23c[_0x451f('0x52')]=qs[_0x451f('0x53')](_0x3b57fc[_0x451f('0x49')]['sort']);_0x13d23c['where']=qs[_0x451f('0x4b')](_[_0x451f('0x55')](_0x3b57fc[_0x451f('0x49')],_0x2ed796[_0x451f('0x4b')]));if(_0x3b57fc[_0x451f('0x49')][_0x451f('0x56')]){_0x13d23c['where']=_['merge'](_0x13d23c[_0x451f('0x54')],{'$or':_[_0x451f('0x48')](_0x13d23c[_0x451f('0x4e')],function(_0x1052c9){var _0x358b9f={};_0x358b9f[_0x1052c9]={'$like':'%'+_0x3b57fc[_0x451f('0x49')][_0x451f('0x56')]+'%'};return _0x358b9f;})});}_0x13d23c=_[_0x451f('0x57')]({},_0x13d23c,_0x3b57fc[_0x451f('0x5e')]);return _0x38e15f[_0x451f('0xbd')](_0x13d23c);}})['then'](function(_0x39879f){if(_0x39879f){_0x5be2ba=_0x39879f[_0x451f('0x50')];if(!_0x3b57fc[_0x451f('0x49')][_0x451f('0x6e')](_0x451f('0x51'))){_0x13d23c['limit']=qs[_0x451f('0x31')](_0x3b57fc['query'][_0x451f('0x31')]);_0x13d23c['offset']=qs['offset'](_0x3b57fc[_0x451f('0x49')]['offset']);}return _0x38e15f['getAgents'](_0x13d23c);}})[_0x451f('0x22')](function(_0x2ee3c2){if(_0x2ee3c2){return _0x2ee3c2?{'count':_0x5be2ba,'rows':_0x2ee3c2}:null;}})[_0x451f('0x22')](respondWithResult(_0x514ce8,null))[_0x451f('0x5d')](handleError(_0x514ce8,null));};exports[_0x451f('0x40')]=function(_0xa5d76e,_0x59cfd7,_0x2464c0){var _0x3abe61,_0x5705b7,_0x1cca8b;if(_[_0x451f('0x7d')](_0xa5d76e[_0x451f('0x61')][_0x451f('0x61')])||_0xa5d76e[_0x451f('0x61')][_0x451f('0x61')]===''){throw new db[(_0x451f('0x77'))][(_0x451f('0x78'))](_0x451f('0xbe'));}if(_[_0x451f('0x7d')](_0xa5d76e[_0x451f('0x61')]['to'])){}_0x3abe61=_0xa5d76e[_0x451f('0x61')]['to'];return db[_0x451f('0x44')][_0x451f('0x74')]({'where':{'id':_0xa5d76e[_0x451f('0x69')]['id']}})['then'](handleEntityNotFound(_0x59cfd7,null))[_0x451f('0x22')](function(_0x38e215){if(_0x38e215){return db[_0x451f('0x44')][_0x451f('0x5f')]({'where':{'id':_0x38e215['id']},'include':[{'model':db[_0x451f('0x82')],'as':_0x451f('0x83'),'include':[{'model':db['CmContact'],'as':_0x451f('0x8b'),'where':{[_0x38e215[_0x451f('0x7f')]]:_0x3abe61},'limit':0x1,'order':[[_0x451f('0x7b'),'DESC']]}]}]})[_0x451f('0x22')](handleEntityNotFound(_0x59cfd7,null))[_0x451f('0x22')](function(_0x6bc420){if(_0x6bc420&&_0x6bc420[_0x451f('0x83')]){_0x5705b7=_0x6bc420[_0x451f('0x39')]({'plain':!![]});if(_0x5705b7[_0x451f('0x83')]&&_0x5705b7[_0x451f('0x83')][_0x451f('0x8b')][_0x451f('0x50')]){return _0x5705b7['List'][_0x451f('0x8b')][0x0];}return db[_0x451f('0x76')]['create'](_[_0x451f('0x1a')](_0xa5d76e[_0x451f('0x61')],{'firstName':_0x3abe61,[_0x6bc420[_0x451f('0x7f')]]:_0x3abe61,'phone':_0x3abe61,'ListId':_0x5705b7[_0x451f('0x8c')]}));}})['then'](handleEntityNotFound(_0x59cfd7,null))[_0x451f('0x22')](function(_0x328b11){if(_0x328b11){_0x1cca8b=_0x328b11;return db[_0x451f('0x90')]['find']({'where':{'ContactId':_0x1cca8b['id'],'closed':![],'OpenchannelAccountId':_0x5705b7['id']}})['then'](function(_0x15fb1c){if(_0x15fb1c){return[_0x15fb1c,![]];}return db[_0x451f('0x90')][_0x451f('0x60')]({'UserId':_0xa5d76e[_0x451f('0x62')]['id'],'ContactId':_0x1cca8b['id'],'OpenchannelAccountId':_0x5705b7['id'],'lastMsgDirection':_0x451f('0xbf'),'Messages':[_[_0x451f('0x57')](_0xa5d76e[_0x451f('0x61')],{'read':![],'body':_0xa5d76e[_0x451f('0x61')][_0x451f('0x61')],'OpenchannelAccountId':_0x5705b7['id'],'UserId':_0xa5d76e[_0x451f('0x62')]['id'],'ContactId':_0x1cca8b['id']})]},{'include':[{'model':db[_0x451f('0xc0')],'as':_0x451f('0xc1')}]})[_0x451f('0x22')](function(_0x30b0fa){return[_0x30b0fa,!![]];});});}})[_0x451f('0x94')](function(_0x78fc8a,_0x1cb2d4){if(_0x1cb2d4){return _0x78fc8a;}return db[_0x451f('0xc0')][_0x451f('0x60')](_[_0x451f('0x57')](_0xa5d76e[_0x451f('0x61')],{'read':![],'body':_0xa5d76e[_0x451f('0x61')][_0x451f('0x61')],'OpenchannelAccountId':_0x5705b7['id'],'OpenchannelInteractionId':_0x78fc8a['id'],'UserId':_0xa5d76e[_0x451f('0x62')]['id'],'ContactId':_0x1cca8b['id']}))[_0x451f('0x22')](function(_0x371aa5){_0x78fc8a[_0x451f('0xc2')][_0x451f('0xc1')]=[];_0x78fc8a['dataValues'][_0x451f('0xc1')][_0x451f('0x99')](_0x371aa5[_0x451f('0xc2')]);return _0x78fc8a;});});}})[_0x451f('0x22')](respondWithResult(_0x59cfd7,null))[_0x451f('0x5d')](handleError(_0x59cfd7,null));};