Built motion from commit a679711e.|2.6.15
[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 _0x25d5=['message','OpenchannelAccount,\x20%s,\x20%s','result','sendStatus','status','end','json','offset','undefined','limit','count','set','save','destroy','get','OpenchannelAccounts','UserProfileResource','name','send','index','Pause','map','rawAttributes','fieldName','type','keys','query','filters','intersection','attributes','length','model','nolimit','order','sort','filter','VIRTUAL','options','includeAll','include','OpenchannelAccount','findAll','catch','show','fields','merge','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','find','userProfileId','autoAssociation','update','body','params','mandatoryDispositionPause','describe','addDisposition','OpenchannelAccountId','Disposition','findOne','hasOwnProperty','pick','where','removeDispositions','ids','getAnswers','CannedAnswer','openchannel','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','createdAt','updatedAt','CompanyId','ListId','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','isNil','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','from','List','Contacts','DESC','OpenchannelApplication','Applications','account','applications','list','orderBy','priority','asc','contact','lastName','threadId','OpenchannelInteraction','externalUrl','ContactId','spread','firstName','messageId','created','autoclose','unmanaged','OpenchannelMessage','AttachmentId','interaction','UserId','User','unshift','agent','waitForTheAssignedAgent','*,*,*,*','forcedOwnership','Start','startRouting','EventManager','addApplications','sequelize','READ_COMMITTED','bulkCreate','findAndCountAll','stack','getApplications','getInteractions','Contact','Tag','Tags','tag','rows','addAgents','omit','emit','userOpenchannelAccount:save','removeAgents','isArray','getAgents','out','dataValues','Messages','push','eml-format','zip-dir','request-promise','moment','bluebird','util','path','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/utils','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./openchannelAccount.socket','jayson/promise','client','http','request','then','info','request\x20sent','debug','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','code'];(function(_0x9c5775,_0x5d3504){var _0x5094f7=function(_0x2b3e04){while(--_0x2b3e04){_0x9c5775['push'](_0x9c5775['shift']());}};_0x5094f7(++_0x5d3504);}(_0x25d5,0x91));var _0x525d=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x25d5[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require(_0x525d('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x525d('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x525d('0x2'));var moment=require(_0x525d('0x3'));var BPromise=require(_0x525d('0x4'));var Mustache=require('mustache');var util=require(_0x525d('0x5'));var path=require(_0x525d('0x6'));var sox=require(_0x525d('0x7'));var csv=require(_0x525d('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x525d('0x9'));var _=require(_0x525d('0xa'));var squel=require(_0x525d('0xb'));var crypto=require(_0x525d('0xc'));var jsforce=require(_0x525d('0xd'));var deskjs=require(_0x525d('0xe'));var toCsv=require(_0x525d('0x8'));var querystring=require(_0x525d('0xf'));var Papa=require(_0x525d('0x10'));var Redis=require('ioredis');var authService=require(_0x525d('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x525d('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0x525d('0x13'));var config=require(_0x525d('0x14'));var licenseUtil=require('../../config/license/util');var db=require(_0x525d('0x15'))['db'];config[_0x525d('0x16')]=_[_0x525d('0x17')](config['redis'],{'host':_0x525d('0x18'),'port':0x18eb});var socket=require(_0x525d('0x19'))(new Redis(config[_0x525d('0x16')]));require(_0x525d('0x1a'))['register'](socket);var jayson=require(_0x525d('0x1b'));var client=jayson[_0x525d('0x1c')][_0x525d('0x1d')]({'port':0x232c});var client9002=jayson[_0x525d('0x1c')][_0x525d('0x1d')]({'port':0x232a});function respondWithRpcPromise(_0x31ed21,_0x107dfb,_0x471049,_0x50b4f3){return new BPromise(function(_0x51dfca,_0x38750c){var _0x389565=_0x50b4f3||client;return _0x389565[_0x525d('0x1e')](_0x31ed21,_0x471049)[_0x525d('0x1f')](function(_0x8abf8c){logger[_0x525d('0x20')]('OpenchannelAccount,\x20%s,\x20%s',_0x107dfb,_0x525d('0x21'));logger[_0x525d('0x22')](_0x525d('0x23'),_0x107dfb,_0x525d('0x21'),JSON[_0x525d('0x24')](_0x8abf8c));if(_0x8abf8c[_0x525d('0x25')]){if(_0x8abf8c['error'][_0x525d('0x26')]===0x1f4){logger['error']('OpenchannelAccount,\x20%s,\x20%s',_0x107dfb,_0x8abf8c['error'][_0x525d('0x27')]);return _0x38750c(_0x8abf8c['error'][_0x525d('0x27')]);}logger[_0x525d('0x25')](_0x525d('0x28'),_0x107dfb,_0x8abf8c[_0x525d('0x25')][_0x525d('0x27')]);return _0x51dfca(_0x8abf8c['error'][_0x525d('0x27')]);}else{logger['info']('OpenchannelAccount,\x20%s,\x20%s',_0x107dfb,_0x525d('0x21'));_0x51dfca(_0x8abf8c[_0x525d('0x29')]['message']);}})['catch'](function(_0x3d4a5c){logger['error'](_0x525d('0x28'),_0x107dfb,_0x3d4a5c);_0x38750c(_0x3d4a5c);});});}function respondWithStatusCode(_0x25eeff,_0x190294){_0x190294=_0x190294||0xcc;return function(_0x3dca8a){if(_0x3dca8a){return _0x25eeff[_0x525d('0x2a')](_0x190294);}return _0x25eeff[_0x525d('0x2b')](_0x190294)[_0x525d('0x2c')]();};}function respondWithResult(_0x589e42,_0x3a4886){_0x3a4886=_0x3a4886||0xc8;return function(_0x5b13c2){if(_0x5b13c2){return _0x589e42[_0x525d('0x2b')](_0x3a4886)[_0x525d('0x2d')](_0x5b13c2);}};}function respondWithFilteredResult(_0x512d9f,_0x54856d){return function(_0x86bc45){if(_0x86bc45){var _0x4b9dbb=typeof _0x54856d[_0x525d('0x2e')]===_0x525d('0x2f')&&typeof _0x54856d[_0x525d('0x30')]===_0x525d('0x2f');var _0x497d6e=_0x86bc45['count'];var _0x356a13=_0x4b9dbb?0x0:_0x54856d[_0x525d('0x2e')];var _0x1f10bd=_0x4b9dbb?_0x86bc45[_0x525d('0x31')]:_0x54856d[_0x525d('0x2e')]+_0x54856d[_0x525d('0x30')];var _0x3ff3a4;if(_0x1f10bd>=_0x497d6e){_0x1f10bd=_0x497d6e;_0x3ff3a4=0xc8;}else{_0x3ff3a4=0xce;}_0x512d9f[_0x525d('0x2b')](_0x3ff3a4);return _0x512d9f[_0x525d('0x32')]('Content-Range',_0x356a13+'-'+_0x1f10bd+'/'+_0x497d6e)[_0x525d('0x2d')](_0x86bc45);}return null;};}function patchUpdates(_0x54e610){return function(_0x341d94){try{jsonpatch['apply'](_0x341d94,_0x54e610,!![]);}catch(_0x43447e){return BPromise['reject'](_0x43447e);}return _0x341d94[_0x525d('0x33')]();};}function saveUpdates(_0xef8484,_0x37827c){return function(_0x55c026){if(_0x55c026){return _0x55c026['update'](_0xef8484)[_0x525d('0x1f')](function(_0x2d3178){return _0x2d3178;});}return null;};}function removeEntity(_0x1f7420,_0x75c2fa){return function(_0x382d32){if(_0x382d32){return _0x382d32[_0x525d('0x34')]()['then'](function(){var _0x21afd1=_0x382d32[_0x525d('0x35')]({'plain':!![]});var _0xa6f6c0=_0x525d('0x36');return db[_0x525d('0x37')][_0x525d('0x34')]({'where':{'type':_0xa6f6c0,'resourceId':_0x21afd1['id']}})[_0x525d('0x1f')](function(){return _0x382d32;});})[_0x525d('0x1f')](function(){_0x1f7420[_0x525d('0x2b')](0xcc)[_0x525d('0x2c')]();});}};}function handleEntityNotFound(_0x58377f,_0x261a70){return function(_0x16adaf){if(!_0x16adaf){_0x58377f[_0x525d('0x2a')](0x194);}return _0x16adaf;};}function handleError(_0x45fd5c,_0x13aaea){_0x13aaea=_0x13aaea||0x1f4;return function(_0x341d12){logger[_0x525d('0x25')](_0x341d12['stack']);if(_0x341d12[_0x525d('0x38')]){delete _0x341d12[_0x525d('0x38')];}_0x45fd5c[_0x525d('0x2b')](_0x13aaea)[_0x525d('0x39')](_0x341d12);};}exports[_0x525d('0x3a')]=function(_0x229037,_0x8eadaf){var _0xc011bd={'include':[{'model':db[_0x525d('0x3b')],'as':'mandatoryDispositionPause'}]},_0x332c28={},_0x3e1583={'count':0x0,'rows':[]};var _0x275272=_[_0x525d('0x3c')](db['OpenchannelAccount'][_0x525d('0x3d')],function(_0x241970){return{'name':_0x241970[_0x525d('0x3e')],'type':_0x241970[_0x525d('0x3f')]['key']};});_0x332c28['model']=_[_0x525d('0x3c')](_0x275272,_0x525d('0x38'));_0x332c28['query']=_[_0x525d('0x40')](_0x229037[_0x525d('0x41')]);_0x332c28[_0x525d('0x42')]=_[_0x525d('0x43')](_0x332c28['model'],_0x332c28[_0x525d('0x41')]);_0xc011bd[_0x525d('0x44')]=_[_0x525d('0x43')](_0x332c28['model'],qs['fields'](_0x229037['query']['fields']));_0xc011bd[_0x525d('0x44')]=_0xc011bd[_0x525d('0x44')][_0x525d('0x45')]?_0xc011bd[_0x525d('0x44')]:_0x332c28[_0x525d('0x46')];if(!_0x229037[_0x525d('0x41')]['hasOwnProperty'](_0x525d('0x47'))){_0xc011bd[_0x525d('0x30')]=qs[_0x525d('0x30')](_0x229037[_0x525d('0x41')][_0x525d('0x30')]);_0xc011bd['offset']=qs[_0x525d('0x2e')](_0x229037['query'][_0x525d('0x2e')]);}_0xc011bd[_0x525d('0x48')]=qs[_0x525d('0x49')](_0x229037['query'][_0x525d('0x49')]);_0xc011bd['where']=qs[_0x525d('0x42')](_['pick'](_0x229037[_0x525d('0x41')],_0x332c28[_0x525d('0x42')]),_0x275272);if(_0x229037[_0x525d('0x41')][_0x525d('0x4a')]){_0xc011bd['where']=_['merge'](_0xc011bd['where'],{'$or':_[_0x525d('0x3c')](_0x275272,function(_0x3b82af){if(_0x3b82af[_0x525d('0x3f')]!==_0x525d('0x4b')){var _0x14fc09={};_0x14fc09[_0x3b82af[_0x525d('0x38')]]={'$like':'%'+_0x229037[_0x525d('0x41')]['filter']+'%'};return _0x14fc09;}})});}_0xc011bd=_['merge']({},_0xc011bd,_0x229037[_0x525d('0x4c')]);var _0x2abb17={'where':_0xc011bd['where']};return db['OpenchannelAccount'][_0x525d('0x31')](_0x2abb17)['then'](function(_0x4a7a5b){_0x3e1583[_0x525d('0x31')]=_0x4a7a5b;if(_0x229037[_0x525d('0x41')][_0x525d('0x4d')]){_0xc011bd[_0x525d('0x4e')]=[{'all':!![]}];}return db[_0x525d('0x4f')][_0x525d('0x50')](_0xc011bd);})[_0x525d('0x1f')](function(_0x2df3ca){_0x3e1583['rows']=_0x2df3ca;return _0x3e1583;})[_0x525d('0x1f')](respondWithFilteredResult(_0x8eadaf,_0xc011bd))[_0x525d('0x51')](handleError(_0x8eadaf,null));};exports[_0x525d('0x52')]=function(_0x50accf,_0x556bc8){var _0x16fc6e={'raw':![],'where':{'id':_0x50accf['params']['id']},'include':[{'model':db[_0x525d('0x3b')],'as':'mandatoryDispositionPause'}]},_0x36d5b3={};_0x36d5b3[_0x525d('0x46')]=_[_0x525d('0x40')](db[_0x525d('0x4f')][_0x525d('0x3d')]);_0x36d5b3['query']=_[_0x525d('0x40')](_0x50accf[_0x525d('0x41')]);_0x36d5b3[_0x525d('0x42')]=_[_0x525d('0x43')](_0x36d5b3['model'],_0x36d5b3[_0x525d('0x41')]);_0x16fc6e[_0x525d('0x44')]=_[_0x525d('0x43')](_0x36d5b3[_0x525d('0x46')],qs[_0x525d('0x53')](_0x50accf[_0x525d('0x41')][_0x525d('0x53')]));_0x16fc6e[_0x525d('0x44')]=_0x16fc6e['attributes'][_0x525d('0x45')]?_0x16fc6e[_0x525d('0x44')]:_0x36d5b3['model'];if(_0x50accf['query'][_0x525d('0x4d')]){_0x16fc6e['include']=[{'all':!![]}];}_0x16fc6e=_[_0x525d('0x54')]({},_0x16fc6e,_0x50accf[_0x525d('0x4c')]);return db[_0x525d('0x4f')]['find'](_0x16fc6e)['then'](handleEntityNotFound(_0x556bc8,null))[_0x525d('0x1f')](respondWithResult(_0x556bc8,null))['catch'](handleError(_0x556bc8,null));};exports[_0x525d('0x55')]=function(_0x46cee5,_0x2fae49){return db[_0x525d('0x4f')][_0x525d('0x55')](_0x46cee5['body'],{})[_0x525d('0x1f')](function(_0x25b692){var _0x254110=_0x46cee5[_0x525d('0x56')]['get']({'plain':!![]});if(!_0x254110)throw new Error(_0x525d('0x57'));if(_0x254110[_0x525d('0x58')]===_0x525d('0x56')){var _0x58dff2=_0x25b692[_0x525d('0x35')]({'plain':!![]});var _0x51ef08=_0x525d('0x36');return db[_0x525d('0x59')][_0x525d('0x5a')]({'where':{'name':_0x51ef08,'userProfileId':_0x254110[_0x525d('0x5b')]},'raw':!![]})[_0x525d('0x1f')](function(_0x31b525){if(_0x31b525&&_0x31b525[_0x525d('0x5c')]===0x0){return db['UserProfileResource'][_0x525d('0x55')]({'name':_0x58dff2[_0x525d('0x38')],'resourceId':_0x58dff2['id'],'type':_0x31b525[_0x525d('0x38')],'sectionId':_0x31b525['id']},{})['then'](function(){return _0x25b692;});}else{return _0x25b692;}})[_0x525d('0x51')](function(_0x3ce628){logger[_0x525d('0x25')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x3ce628);throw _0x3ce628;});}return _0x25b692;})['then'](respondWithResult(_0x2fae49,0xc9))[_0x525d('0x51')](handleError(_0x2fae49,null));};exports[_0x525d('0x5d')]=function(_0xbe3f48,_0x47431b){if(_0xbe3f48['body']['id']){delete _0xbe3f48[_0x525d('0x5e')]['id'];}return db['OpenchannelAccount'][_0x525d('0x5a')]({'where':{'id':_0xbe3f48[_0x525d('0x5f')]['id']},'include':[{'model':db['Pause'],'as':_0x525d('0x60')}]})[_0x525d('0x1f')](handleEntityNotFound(_0x47431b,null))[_0x525d('0x1f')](saveUpdates(_0xbe3f48[_0x525d('0x5e')],null))[_0x525d('0x1f')](respondWithResult(_0x47431b,null))[_0x525d('0x51')](handleError(_0x47431b,null));};exports[_0x525d('0x34')]=function(_0x2409c4,_0x5adece){return db['OpenchannelAccount']['find']({'where':{'id':_0x2409c4[_0x525d('0x5f')]['id']}})[_0x525d('0x1f')](handleEntityNotFound(_0x5adece,null))['then'](removeEntity(_0x5adece,null))[_0x525d('0x51')](handleError(_0x5adece,null));};exports['describe']=function(_0x98c1ef,_0x5f609f){return db['OpenchannelAccount'][_0x525d('0x61')]()[_0x525d('0x1f')](respondWithResult(_0x5f609f,null))['catch'](handleError(_0x5f609f,null));};exports[_0x525d('0x62')]=function(_0x492210,_0x208fe4,_0x2bcbbc){if(_0x492210['body']['id']){delete _0x492210[_0x525d('0x5e')]['id'];}return db[_0x525d('0x4f')][_0x525d('0x5a')]({'where':{'id':_0x492210[_0x525d('0x5f')]['id']}})['then'](handleEntityNotFound(_0x208fe4,null))[_0x525d('0x1f')](function(_0x3be484){if(_0x3be484){_0x492210[_0x525d('0x5e')][_0x525d('0x63')]=_0x3be484['id'];return db[_0x525d('0x64')][_0x525d('0x55')](_0x492210[_0x525d('0x5e')]);}})[_0x525d('0x1f')](respondWithResult(_0x208fe4,null))['catch'](handleError(_0x208fe4,null));};exports['getDispositions']=function(_0x149f21,_0x135898,_0x50f789){var _0x5ad7a8={'raw':![],'where':{}};var _0x42e318={};var _0x4d17c3={'count':0x0,'rows':[]};return db['OpenchannelAccount'][_0x525d('0x65')]({'where':{'id':_0x149f21[_0x525d('0x5f')]['id']}})[_0x525d('0x1f')](handleEntityNotFound(_0x135898,null))[_0x525d('0x1f')](function(_0x51164c){if(_0x51164c){_0x42e318[_0x525d('0x46')]=_[_0x525d('0x40')](db['Disposition'][_0x525d('0x3d')]);_0x42e318['query']=_['keys'](_0x149f21['query']);_0x42e318['filters']=_['intersection'](_0x42e318[_0x525d('0x46')],_0x42e318[_0x525d('0x41')]);_0x5ad7a8[_0x525d('0x44')]=_['intersection'](_0x42e318[_0x525d('0x46')],qs[_0x525d('0x53')](_0x149f21[_0x525d('0x41')]['fields']));_0x5ad7a8[_0x525d('0x44')]=_0x5ad7a8[_0x525d('0x44')][_0x525d('0x45')]?_0x5ad7a8[_0x525d('0x44')]:_0x42e318[_0x525d('0x46')];if(!_0x149f21[_0x525d('0x41')][_0x525d('0x66')](_0x525d('0x47'))){_0x5ad7a8[_0x525d('0x30')]=qs[_0x525d('0x30')](_0x149f21['query']['limit']);_0x5ad7a8[_0x525d('0x2e')]=qs[_0x525d('0x2e')](_0x149f21[_0x525d('0x41')][_0x525d('0x2e')]);}_0x5ad7a8[_0x525d('0x48')]=qs[_0x525d('0x49')](_0x149f21['query'][_0x525d('0x49')]);_0x5ad7a8['where']=qs[_0x525d('0x42')](_[_0x525d('0x67')](_0x149f21[_0x525d('0x41')],_0x42e318[_0x525d('0x42')]));_0x5ad7a8[_0x525d('0x68')][_0x525d('0x63')]=_0x51164c['id'];if(_0x149f21['query'][_0x525d('0x4a')]){_0x5ad7a8['where']=_[_0x525d('0x54')](_0x5ad7a8[_0x525d('0x68')],{'$or':_[_0x525d('0x3c')](_0x5ad7a8['attributes'],function(_0x527b9b){var _0x5ad7a0={};_0x5ad7a0[_0x527b9b]={'$like':'%'+_0x149f21[_0x525d('0x41')]['filter']+'%'};return _0x5ad7a0;})});}_0x5ad7a8=_[_0x525d('0x54')]({},_0x5ad7a8,_0x149f21['options']);return db['Disposition'][_0x525d('0x31')]({'where':_0x5ad7a8[_0x525d('0x68')]})[_0x525d('0x1f')](function(_0x23481e){_0x4d17c3[_0x525d('0x31')]=_0x23481e;if(_0x149f21[_0x525d('0x41')][_0x525d('0x4d')]){_0x5ad7a8['include']=[{'all':!![]}];}return db[_0x525d('0x64')][_0x525d('0x50')](_0x5ad7a8);})['then'](function(_0xaaeebe){_0x4d17c3['rows']=_0xaaeebe;return _0x4d17c3;});}})[_0x525d('0x1f')](respondWithFilteredResult(_0x135898,_0x5ad7a8))['catch'](handleError(_0x135898,null));};exports[_0x525d('0x69')]=function(_0x759ba2,_0x42b365,_0x3a626e){return db[_0x525d('0x4f')][_0x525d('0x5a')]({'where':{'id':_0x759ba2['params']['id']}})['then'](handleEntityNotFound(_0x42b365,null))[_0x525d('0x1f')](function(_0x3a8ac1){if(_0x3a8ac1){return _0x3a8ac1['removeDispositions'](_0x759ba2[_0x525d('0x41')][_0x525d('0x6a')]);}})[_0x525d('0x1f')](respondWithStatusCode(_0x42b365,null))[_0x525d('0x51')](handleError(_0x42b365,null));};exports['addAnswer']=function(_0x51218d,_0x18b8a1,_0x3a931b){if(_0x51218d[_0x525d('0x5e')]['id']){delete _0x51218d[_0x525d('0x5e')]['id'];}return db[_0x525d('0x4f')]['find']({'where':{'id':_0x51218d[_0x525d('0x5f')]['id']}})[_0x525d('0x1f')](handleEntityNotFound(_0x18b8a1,null))[_0x525d('0x1f')](function(_0x5b4fd9){if(_0x5b4fd9){_0x51218d[_0x525d('0x5e')][_0x525d('0x63')]=_0x5b4fd9['id'];return db['CannedAnswer'][_0x525d('0x55')](_0x51218d[_0x525d('0x5e')]);}})['then'](respondWithResult(_0x18b8a1,null))[_0x525d('0x51')](handleError(_0x18b8a1,null));};exports[_0x525d('0x6b')]=function(_0x47ed42,_0x16bfe7,_0x583392){var _0x28f6eb={'raw':![],'where':{}};var _0x1815d8={};var _0x35ff12={'count':0x0,'rows':[]};return db[_0x525d('0x4f')][_0x525d('0x65')]({'where':{'id':_0x47ed42[_0x525d('0x5f')]['id']}})[_0x525d('0x1f')](handleEntityNotFound(_0x16bfe7,null))[_0x525d('0x1f')](function(_0x5a6e3f){if(_0x5a6e3f){_0x1815d8[_0x525d('0x46')]=_[_0x525d('0x40')](db[_0x525d('0x6c')][_0x525d('0x3d')]);_0x1815d8[_0x525d('0x41')]=_[_0x525d('0x40')](_0x47ed42['query']);_0x1815d8[_0x525d('0x42')]=_['intersection'](_0x1815d8[_0x525d('0x46')],_0x1815d8[_0x525d('0x41')]);_0x28f6eb[_0x525d('0x44')]=_[_0x525d('0x43')](_0x1815d8[_0x525d('0x46')],qs[_0x525d('0x53')](_0x47ed42['query'][_0x525d('0x53')]));_0x28f6eb[_0x525d('0x44')]=_0x28f6eb[_0x525d('0x44')][_0x525d('0x45')]?_0x28f6eb[_0x525d('0x44')]:_0x1815d8[_0x525d('0x46')];if(!_0x47ed42[_0x525d('0x41')][_0x525d('0x66')](_0x525d('0x47'))){_0x28f6eb['limit']=qs[_0x525d('0x30')](_0x47ed42[_0x525d('0x41')]['limit']);_0x28f6eb[_0x525d('0x2e')]=qs['offset'](_0x47ed42['query'][_0x525d('0x2e')]);}_0x28f6eb['order']=qs['sort'](_0x47ed42[_0x525d('0x41')][_0x525d('0x49')]);_0x28f6eb['where']=qs[_0x525d('0x42')](_[_0x525d('0x67')](_0x47ed42['query'],_0x1815d8[_0x525d('0x42')]));_0x28f6eb['where'][_0x525d('0x63')]=_0x5a6e3f['id'];if(_0x47ed42['query'][_0x525d('0x4a')]){_0x28f6eb[_0x525d('0x68')]=_[_0x525d('0x54')](_0x28f6eb['where'],{'$or':_[_0x525d('0x3c')](_0x28f6eb['attributes'],function(_0x1fd373){var _0x409f04={};_0x409f04[_0x1fd373]={'$like':'%'+_0x47ed42[_0x525d('0x41')][_0x525d('0x4a')]+'%'};return _0x409f04;})});}_0x28f6eb=_[_0x525d('0x54')]({},_0x28f6eb,_0x47ed42['options']);return db[_0x525d('0x6c')]['count']({'where':_0x28f6eb[_0x525d('0x68')]})[_0x525d('0x1f')](function(_0x139a8d){_0x35ff12['count']=_0x139a8d;if(_0x47ed42[_0x525d('0x41')][_0x525d('0x4d')]){_0x28f6eb['include']=[{'all':!![]}];}return db[_0x525d('0x6c')][_0x525d('0x50')](_0x28f6eb);})[_0x525d('0x1f')](function(_0x4768da){_0x35ff12['rows']=_0x4768da;return _0x35ff12;});}})[_0x525d('0x1f')](respondWithFilteredResult(_0x16bfe7,_0x28f6eb))[_0x525d('0x51')](handleError(_0x16bfe7,null));};exports['removeAnswers']=function(_0x4584a9,_0x3d5d80,_0x68213b){return db[_0x525d('0x4f')][_0x525d('0x5a')]({'where':{'id':_0x4584a9['params']['id']}})[_0x525d('0x1f')](handleEntityNotFound(_0x3d5d80,null))[_0x525d('0x1f')](function(_0x49103c){if(_0x49103c){return _0x49103c['removeAnswers'](_0x4584a9[_0x525d('0x41')][_0x525d('0x6a')]);}})[_0x525d('0x1f')](respondWithStatusCode(_0x3d5d80,null))[_0x525d('0x51')](handleError(_0x3d5d80,null));};exports['notify']=function(_0x50825b,_0x160d3a,_0xc194a4){var _0x2f4642={'body':_0x50825b[_0x525d('0x5e')],'channel':_0x525d('0x6d')};var _0x46d6f5=[];var _0xf1c0de=[];var _0x52e1a9={};var _0x1f91d2=![];return db[_0x525d('0x6e')]['describe']()[_0x525d('0x1f')](function(_0x1b1ffc){if(!_0x1b1ffc){throw new db[(_0x525d('0x6f'))][(_0x525d('0x70'))](_0x525d('0x71'));}_0x46d6f5=_['difference'](_[_0x525d('0x40')](_0x1b1ffc),[_0x525d('0x72'),_0x525d('0x73')]);_0xf1c0de=_['difference'](_['keys'](_0x1b1ffc),[_0x525d('0x72'),_0x525d('0x73'),_0x525d('0x74'),_0x525d('0x75')]);if(_0x50825b[_0x525d('0x5e')]['id']){delete _0x50825b[_0x525d('0x5e')]['id'];}if(_['isNil'](_0x50825b['body']['from'])){throw new db['Sequelize'][(_0x525d('0x70'))](_0x525d('0x76'));}if(_['isNil'](_0x50825b['body'][_0x525d('0x5e')])||_0x50825b[_0x525d('0x5e')][_0x525d('0x5e')]===''){throw new db[(_0x525d('0x6f'))]['ValidationError'](_0x525d('0x77'));}if(_[_0x525d('0x78')](_0x50825b[_0x525d('0x5e')][_0x525d('0x79')])){throw new db['Sequelize']['ValidationError'](_0x525d('0x7a')+_0xf1c0de);}if(!_['includes'](_0xf1c0de,_0x50825b[_0x525d('0x5e')][_0x525d('0x79')])){throw new db['Sequelize'][(_0x525d('0x70'))]('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0xf1c0de);}_0x52e1a9[_0x50825b[_0x525d('0x5e')][_0x525d('0x79')]]=_0x50825b['body'][_0x525d('0x7b')];})[_0x525d('0x1f')](function(){return db[_0x525d('0x4f')][_0x525d('0x5a')]({'where':{'id':_0x50825b['params']['id']},'include':[{'model':db['CmList'],'as':_0x525d('0x7c'),'include':[{'model':db[_0x525d('0x6e')],'as':_0x525d('0x7d'),'where':_0x52e1a9,'limit':0x1,'order':[[_0x525d('0x73'),_0x525d('0x7e')]]}]},{'model':db[_0x525d('0x7f')],'as':_0x525d('0x80')}]});})[_0x525d('0x1f')](handleEntityNotFound(_0x160d3a,null))[_0x525d('0x1f')](function(_0x9fc07f){if(_0x9fc07f&&_0x9fc07f[_0x525d('0x7c')]){_0x2f4642[_0x525d('0x81')]=_0x9fc07f;_0x2f4642[_0x525d('0x82')]=_0x9fc07f[_0x525d('0x80')];_0x2f4642[_0x525d('0x83')]=_0x9fc07f[_0x525d('0x7c')];_0x2f4642[_0x525d('0x82')]=_[_0x525d('0x84')](_0x2f4642[_0x525d('0x82')],[_0x525d('0x85')],[_0x525d('0x86')]);if(_0x2f4642['account'][_0x525d('0x80')]){delete _0x2f4642['account'][_0x525d('0x80')];}if(_0x2f4642[_0x525d('0x81')][_0x525d('0x7c')]&&_0x2f4642['account'][_0x525d('0x7c')][_0x525d('0x7d')][_0x525d('0x45')]){return _0x2f4642[_0x525d('0x81')][_0x525d('0x7c')][_0x525d('0x7d')][0x0];}var _0x2ba004=_['defaults'](_0x50825b['body'],{'firstName':_0x50825b[_0x525d('0x5e')][_0x525d('0x7b')],'ListId':_0x9fc07f['ListId']});_0x2ba004[_0x50825b['body']['mapKey']]=_0x50825b[_0x525d('0x5e')]['from'];return db[_0x525d('0x6e')][_0x525d('0x55')](_0x2ba004,{'fields':_0x46d6f5,'raw':!![]});}})['then'](handleEntityNotFound(_0x160d3a,null))[_0x525d('0x1f')](function(_0x54928a){_0x2f4642[_0x525d('0x87')]=_0x54928a;if(_0x54928a){var _0x315f36={'ContactId':_0x54928a['id'],'OpenchannelAccountId':_0x50825b['params']['id'],'from':(_0x54928a['firstName']||'')+'\x20'+(_0x54928a[_0x525d('0x88')]||'')};var _0x7f2b7={'OpenchannelAccountId':_0x50825b[_0x525d('0x5f')]['id'],'closed':![]};if(_0x50825b['body'][_0x525d('0x89')]){_0x7f2b7['threadId']=_0x50825b[_0x525d('0x5e')][_0x525d('0x89')];return db[_0x525d('0x8a')][_0x525d('0x5a')]({'where':_0x7f2b7})[_0x525d('0x1f')](function(_0x171e4b){if(_0x171e4b){return[_0x171e4b,![]];}_0x315f36[_0x525d('0x89')]=_0x50825b[_0x525d('0x5e')][_0x525d('0x89')];_0x315f36[_0x525d('0x8b')]=_0x50825b[_0x525d('0x5e')][_0x525d('0x8b')];return db['OpenchannelInteraction'][_0x525d('0x55')](_0x315f36)['then'](function(_0x35032d){return[_0x35032d,!![]];});});}else{_0x7f2b7[_0x525d('0x89')]=null;}_0x7f2b7[_0x525d('0x8c')]=_0x54928a['id'];return db[_0x525d('0x8a')][_0x525d('0x5a')]({'where':_0x7f2b7})[_0x525d('0x1f')](function(_0x3961b1){if(_0x3961b1){return[_0x3961b1,![]];}return db[_0x525d('0x8a')][_0x525d('0x55')](_0x315f36)['then'](function(_0x269811){return[_0x269811,!![]];});});}})[_0x525d('0x8d')](function(_0x5c03ae,_0x44aa42){if(_0x5c03ae){_0x1f91d2=_0x44aa42;if(!_0x44aa42){var _0x4375ea={'from':(_0x2f4642['contact'][_0x525d('0x8e')]||'')+'\x20'+(_0x2f4642[_0x525d('0x87')][_0x525d('0x88')]||'')};if(_0x50825b[_0x525d('0x5e')]['threadId']&&_0x50825b['body']['messageId']&&_0x50825b[_0x525d('0x5e')][_0x525d('0x89')]!=_0x50825b[_0x525d('0x5e')]['messageId']){_0x4375ea[_0x525d('0x89')]=_0x50825b['body'][_0x525d('0x8f')];}return _0x5c03ae[_0x525d('0x5d')](_0x4375ea);}else{return _0x5c03ae;}}})['then'](function(_0x300adc){_0x2f4642['interaction']=_0x300adc[_0x525d('0x35')]({'plain':!![]});_0x2f4642['interaction'][_0x525d('0x90')]=_0x1f91d2;if(_0x2f4642['interaction'][_0x525d('0x90')]){if(_0x2f4642[_0x525d('0x81')][_0x525d('0x91')]){_0x2f4642[_0x525d('0x82')]['push']({'id':0x0,'priority':_0x2f4642[_0x525d('0x82')][_0x525d('0x45')]+0x1,'app':'close','appdata':_0x525d('0x92'),'interval':'*,*,*,*'});}}return db[_0x525d('0x93')][_0x525d('0x55')]({'body':_0x50825b[_0x525d('0x5e')]['body'],'OpenchannelAccountId':_0x50825b['params']['id'],'OpenchannelInteractionId':_0x300adc['id'],'direction':'in','ContactId':_0x2f4642[_0x525d('0x87')]['id'],'AttachmentId':_0x50825b[_0x525d('0x5e')][_0x525d('0x94')]});})[_0x525d('0x1f')](function(_0x462c9d){_0x2f4642[_0x525d('0x27')]=_0x462c9d;if(_0x2f4642[_0x525d('0x95')][_0x525d('0x96')]){return db[_0x525d('0x97')]['find']({'attributes':['id','name'],'where':{'id':_0x2f4642[_0x525d('0x95')][_0x525d('0x96')]}})[_0x525d('0x1f')](function(_0x2d8906){if(_0x2d8906){_0x2f4642[_0x525d('0x82')][_0x525d('0x98')]({'id':0x0,'priority':0x0,'app':_0x525d('0x99'),'appdata':_0x2d8906[_0x525d('0x38')]+','+(_0x2f4642['account'][_0x525d('0x9a')]||0xa),'interval':_0x525d('0x9b')});_0x2f4642[_0x525d('0x9c')]=![];}return respondWithRpcPromise(_0x525d('0x9d'),_0x525d('0x9e'),_0x2f4642);});}return respondWithRpcPromise(_0x525d('0x9d'),'startRouting',_0x2f4642);})[_0x525d('0x1f')](function(_0x53c1d6){respondWithRpcPromise(_0x525d('0x9f'),_0x525d('0x9f'),{'event':'notify','message':_0x53c1d6},client9002);return _0x53c1d6;})[_0x525d('0x1f')](respondWithResult(_0x160d3a,null))['catch'](handleError(_0x160d3a,null));};exports[_0x525d('0xa0')]=function(_0x9f5866,_0x1089fc){var _0x1c293e=_0x9f5866[_0x525d('0x5f')]['id'];var _0x339fc2=_0x9f5866[_0x525d('0x5e')];var _0x40cf57=0xc8;var _0x1aec4f=null;return db[_0x525d('0xa1')]['transaction']({'isolationLevel':db[_0x525d('0xa1')]['Transaction']['ISOLATION_LEVELS'][_0x525d('0xa2')]},function(_0x36cb48){return db[_0x525d('0x4f')][_0x525d('0x65')]({'where':{'id':_0x1c293e},'transaction':_0x36cb48})[_0x525d('0x1f')](function(_0x107113){if(_0x107113){return db['OpenchannelApplication'][_0x525d('0x34')]({'where':{'OpenchannelAccountId':_0x1c293e},'transaction':_0x36cb48})['then'](function(){var _0x31f430=_[_0x525d('0x3c')](_0x339fc2,function(_0x1b8884){_0x1b8884['OpenchannelAccountId']=_0x1c293e;return _0x1b8884;});return db[_0x525d('0x7f')][_0x525d('0xa3')](_0x31f430,{'transaction':_0x36cb48});});}else{_0x40cf57=0x194;_0x1aec4f=[];}});})[_0x525d('0x1f')](function(){if(_0x40cf57!==0x194){return db['OpenchannelApplication'][_0x525d('0xa4')]({'where':{'OpenchannelAccountId':_0x1c293e},'order':_0x525d('0x85')})[_0x525d('0x1f')](function(_0x3fdccc){_0x1aec4f=_0x3fdccc;});}})[_0x525d('0x51')](function(_0x2e01d0){_0x40cf57=0x1f4;logger['error'](_0x2e01d0[_0x525d('0xa5')]);if(_0x2e01d0[_0x525d('0x38')]){delete _0x2e01d0['name'];}_0x1aec4f=_0x2e01d0;})['finally'](function(){if(_0x1aec4f===null){_0x1089fc[_0x525d('0x2a')](_0x40cf57);}else{if(_0x40cf57===0x1f4){_0x1089fc[_0x525d('0x2b')](_0x40cf57)[_0x525d('0x39')](_0x1aec4f);}else{_0x1089fc[_0x525d('0x2b')](_0x40cf57)['json'](_0x1aec4f);}}});};exports[_0x525d('0xa6')]=function(_0x30ae98,_0x24fafc,_0x2e7ad9){var _0x12d24e={};var _0xd40782={};var _0x56ce16;var _0x29a019;return db[_0x525d('0x4f')][_0x525d('0x65')]({'where':{'id':_0x30ae98[_0x525d('0x5f')]['id']}})[_0x525d('0x1f')](handleEntityNotFound(_0x24fafc,null))[_0x525d('0x1f')](function(_0xa318c9){if(_0xa318c9){_0x56ce16=_0xa318c9;_0xd40782[_0x525d('0x46')]=_[_0x525d('0x40')](db[_0x525d('0x7f')][_0x525d('0x3d')]);_0xd40782[_0x525d('0x41')]=_[_0x525d('0x40')](_0x30ae98[_0x525d('0x41')]);_0xd40782[_0x525d('0x42')]=_['intersection'](_0xd40782[_0x525d('0x46')],_0xd40782[_0x525d('0x41')]);_0x12d24e['attributes']=_[_0x525d('0x43')](_0xd40782[_0x525d('0x46')],qs[_0x525d('0x53')](_0x30ae98[_0x525d('0x41')][_0x525d('0x53')]));_0x12d24e['attributes']=_0x12d24e[_0x525d('0x44')]['length']?_0x12d24e[_0x525d('0x44')]:_0xd40782[_0x525d('0x46')];_0x12d24e['order']=qs[_0x525d('0x49')](_0x30ae98[_0x525d('0x41')][_0x525d('0x49')]);_0x12d24e[_0x525d('0x68')]=qs[_0x525d('0x42')](_['pick'](_0x30ae98[_0x525d('0x41')],_0xd40782[_0x525d('0x42')]));if(_0x30ae98[_0x525d('0x41')][_0x525d('0x4a')]){_0x12d24e[_0x525d('0x68')]=_[_0x525d('0x54')](_0x12d24e['where'],{'$or':_['map'](_0x12d24e[_0x525d('0x44')],function(_0x13a3c5){var _0x2a2391={};_0x2a2391[_0x13a3c5]={'$like':'%'+_0x30ae98['query']['filter']+'%'};return _0x2a2391;})});}_0x12d24e=_['merge']({},_0x12d24e,_0x30ae98['options']);return _0x56ce16[_0x525d('0xa6')](_0x12d24e);}})[_0x525d('0x1f')](function(_0x2206aa){if(_0x2206aa){_0x29a019=_0x2206aa['length'];if(!_0x30ae98[_0x525d('0x41')][_0x525d('0x66')](_0x525d('0x47'))){_0x12d24e[_0x525d('0x30')]=qs['limit'](_0x30ae98[_0x525d('0x41')][_0x525d('0x30')]);_0x12d24e['offset']=qs['offset'](_0x30ae98[_0x525d('0x41')][_0x525d('0x2e')]);}return _0x56ce16[_0x525d('0xa6')](_0x12d24e);}})[_0x525d('0x1f')](function(_0x4ca3d1){if(_0x4ca3d1){return _0x4ca3d1?{'count':_0x29a019,'rows':_0x4ca3d1}:null;}})[_0x525d('0x1f')](respondWithResult(_0x24fafc,null))[_0x525d('0x51')](handleError(_0x24fafc,null));};exports[_0x525d('0xa7')]=function(_0x43deb1,_0x4932cf,_0x3ee185){var _0x33db3e={'raw':![],'where':{}};var _0x52000e={};var _0x5577fe={'count':0x0,'rows':[]};return db[_0x525d('0x4f')][_0x525d('0x65')]({'where':{'id':_0x43deb1[_0x525d('0x5f')]['id']}})['then'](handleEntityNotFound(_0x4932cf,null))[_0x525d('0x1f')](function(_0x45469b){if(_0x45469b){_0x52000e[_0x525d('0x46')]=_[_0x525d('0x40')](db[_0x525d('0x8a')][_0x525d('0x3d')]);_0x52000e[_0x525d('0x41')]=_['keys'](_0x43deb1[_0x525d('0x41')]);_0x52000e[_0x525d('0x42')]=_[_0x525d('0x43')](_0x52000e[_0x525d('0x46')],_0x52000e[_0x525d('0x41')]);_0x33db3e[_0x525d('0x44')]=_[_0x525d('0x43')](_0x52000e['model'],qs[_0x525d('0x53')](_0x43deb1[_0x525d('0x41')][_0x525d('0x53')]));_0x33db3e[_0x525d('0x44')]=_0x33db3e[_0x525d('0x44')][_0x525d('0x45')]?_0x33db3e[_0x525d('0x44')]:_0x52000e[_0x525d('0x46')];if(!_0x43deb1['query']['hasOwnProperty'](_0x525d('0x47'))){_0x33db3e['limit']=qs['limit'](_0x43deb1['query'][_0x525d('0x30')]);_0x33db3e[_0x525d('0x2e')]=qs[_0x525d('0x2e')](_0x43deb1[_0x525d('0x41')]['offset']);}_0x33db3e[_0x525d('0x48')]=qs['sort'](_0x43deb1[_0x525d('0x41')]['sort']);_0x33db3e[_0x525d('0x68')]=qs[_0x525d('0x42')](_['pick'](_0x43deb1[_0x525d('0x41')],_0x52000e[_0x525d('0x42')]));_0x33db3e['where'][_0x525d('0x63')]=_0x45469b['id'];if(_0x43deb1[_0x525d('0x41')]['filter']){_0x33db3e[_0x525d('0x68')]=_[_0x525d('0x54')](_0x33db3e[_0x525d('0x68')],{'$or':_['map'](_0x33db3e['attributes'],function(_0x462a4f){var _0x1b7b60={};_0x1b7b60[_0x462a4f]={'$like':'%'+_0x43deb1['query'][_0x525d('0x4a')]+'%'};return _0x1b7b60;})});}_0x33db3e=_['merge']({},_0x33db3e,_0x43deb1['options']);return db[_0x525d('0x8a')]['count']({'where':_0x33db3e[_0x525d('0x68')]})[_0x525d('0x1f')](function(_0x55c39c){_0x5577fe[_0x525d('0x31')]=_0x55c39c;if(_0x43deb1[_0x525d('0x41')]['includeAll']){_0x33db3e[_0x525d('0x4e')]=[{'model':db[_0x525d('0x6e')],'as':_0x525d('0xa8'),'required':![]},{'model':db[_0x525d('0x97')],'as':'Owner','attributes':[_0x525d('0x38'),'fullname','internal'],'required':![]},{'model':db[_0x525d('0xa9')],'as':_0x525d('0xaa'),'attributes':['id',_0x525d('0x38'),'color'],'where':_0x43deb1[_0x525d('0x41')][_0x525d('0xab')]?{'id':_0x43deb1[_0x525d('0x41')][_0x525d('0xab')]}:undefined,'required':_0x43deb1['query'][_0x525d('0xab')]?!![]:![]}];}return db[_0x525d('0x8a')][_0x525d('0x50')](_0x33db3e);})[_0x525d('0x1f')](function(_0x576521){_0x5577fe[_0x525d('0xac')]=_0x576521;return _0x5577fe;});}})[_0x525d('0x1f')](respondWithFilteredResult(_0x4932cf,_0x33db3e))[_0x525d('0x51')](handleError(_0x4932cf,null));};exports[_0x525d('0xad')]=function(_0x17fb4d,_0x3a39a4,_0x50f273){return db[_0x525d('0x4f')][_0x525d('0x5a')]({'where':{'id':_0x17fb4d['params']['id']}})[_0x525d('0x1f')](handleEntityNotFound(_0x3a39a4,null))[_0x525d('0x1f')](function(_0x2a1e8e){if(_0x2a1e8e){return _0x2a1e8e[_0x525d('0xad')](_0x17fb4d[_0x525d('0x5e')][_0x525d('0x6a')],_[_0x525d('0xae')](_0x17fb4d[_0x525d('0x5e')],['ids','id'])||{})[_0x525d('0x8d')](function(_0x2a9208){for(var _0x241495=0x0;_0x241495<_0x17fb4d['body'][_0x525d('0x6a')][_0x525d('0x45')];_0x241495+=0x1){socket[_0x525d('0xaf')](_0x525d('0xb0'),{'UserId':Number(_0x17fb4d[_0x525d('0x5e')][_0x525d('0x6a')][_0x241495]),'OpenchannelAccountId':Number(_0x17fb4d[_0x525d('0x5f')]['id'])});}return _0x2a9208;});}})['then'](respondWithResult(_0x3a39a4,null))['catch'](handleError(_0x3a39a4,null));};exports['removeAgents']=function(_0x251452,_0x327822,_0x510d4b){return db[_0x525d('0x4f')][_0x525d('0x5a')]({'where':{'id':_0x251452[_0x525d('0x5f')]['id']}})[_0x525d('0x1f')](handleEntityNotFound(_0x327822,null))['then'](function(_0x42aaba){if(_0x42aaba){return _0x42aaba[_0x525d('0xb1')](_0x251452[_0x525d('0x41')]['ids'])[_0x525d('0x1f')](function(){if(_[_0x525d('0xb2')](_0x251452[_0x525d('0x41')][_0x525d('0x6a')])){for(var _0x6920fe=0x0;_0x6920fe<_0x251452[_0x525d('0x41')][_0x525d('0x6a')][_0x525d('0x45')];_0x6920fe+=0x1){socket[_0x525d('0xaf')]('userOpenchannelAccount:remove',{'UserId':Number(_0x251452[_0x525d('0x41')][_0x525d('0x6a')][_0x6920fe]),'OpenchannelAccountId':Number(_0x251452[_0x525d('0x5f')]['id'])});}}else{socket[_0x525d('0xaf')]('userOpenchannelAccount:remove',{'UserId':Number(_0x251452[_0x525d('0x41')][_0x525d('0x6a')]),'OpenchannelAccountId':Number(_0x251452[_0x525d('0x5f')]['id'])});}});}})[_0x525d('0x1f')](respondWithStatusCode(_0x327822,null))[_0x525d('0x51')](handleError(_0x327822,null));};exports[_0x525d('0xb3')]=function(_0x2251b0,_0x1746ba,_0x291ddf){var _0x466ba6={};var _0x6b0cc1={};var _0x4f21bc;var _0x50afff;return db[_0x525d('0x4f')]['findOne']({'where':{'id':_0x2251b0[_0x525d('0x5f')]['id']}})[_0x525d('0x1f')](handleEntityNotFound(_0x1746ba,null))[_0x525d('0x1f')](function(_0x3763f7){if(_0x3763f7){_0x4f21bc=_0x3763f7;_0x6b0cc1[_0x525d('0x46')]=_[_0x525d('0x40')](db[_0x525d('0x97')][_0x525d('0x3d')]);_0x6b0cc1[_0x525d('0x41')]=_[_0x525d('0x40')](_0x2251b0[_0x525d('0x41')]);_0x6b0cc1[_0x525d('0x42')]=_[_0x525d('0x43')](_0x6b0cc1[_0x525d('0x46')],_0x6b0cc1['query']);_0x466ba6['attributes']=_[_0x525d('0x43')](_0x6b0cc1['model'],qs[_0x525d('0x53')](_0x2251b0[_0x525d('0x41')][_0x525d('0x53')]));_0x466ba6[_0x525d('0x44')]=_0x466ba6['attributes'][_0x525d('0x45')]?_0x466ba6[_0x525d('0x44')]:_0x6b0cc1[_0x525d('0x46')];_0x466ba6[_0x525d('0x48')]=qs[_0x525d('0x49')](_0x2251b0[_0x525d('0x41')][_0x525d('0x49')]);_0x466ba6[_0x525d('0x68')]=qs[_0x525d('0x42')](_[_0x525d('0x67')](_0x2251b0['query'],_0x6b0cc1[_0x525d('0x42')]));if(_0x2251b0[_0x525d('0x41')][_0x525d('0x4a')]){_0x466ba6[_0x525d('0x68')]=_[_0x525d('0x54')](_0x466ba6['where'],{'$or':_[_0x525d('0x3c')](_0x466ba6[_0x525d('0x44')],function(_0x48d566){var _0x6ae73c={};_0x6ae73c[_0x48d566]={'$like':'%'+_0x2251b0[_0x525d('0x41')][_0x525d('0x4a')]+'%'};return _0x6ae73c;})});}_0x466ba6=_[_0x525d('0x54')]({},_0x466ba6,_0x2251b0[_0x525d('0x4c')]);return _0x4f21bc['getAgents'](_0x466ba6);}})[_0x525d('0x1f')](function(_0x4f2fa6){if(_0x4f2fa6){_0x50afff=_0x4f2fa6[_0x525d('0x45')];if(!_0x2251b0[_0x525d('0x41')][_0x525d('0x66')](_0x525d('0x47'))){_0x466ba6[_0x525d('0x30')]=qs[_0x525d('0x30')](_0x2251b0['query'][_0x525d('0x30')]);_0x466ba6[_0x525d('0x2e')]=qs[_0x525d('0x2e')](_0x2251b0[_0x525d('0x41')][_0x525d('0x2e')]);}return _0x4f21bc[_0x525d('0xb3')](_0x466ba6);}})[_0x525d('0x1f')](function(_0x23bcc0){if(_0x23bcc0){return _0x23bcc0?{'count':_0x50afff,'rows':_0x23bcc0}:null;}})[_0x525d('0x1f')](respondWithResult(_0x1746ba,null))[_0x525d('0x51')](handleError(_0x1746ba,null));};exports[_0x525d('0x39')]=function(_0x2af6d1,_0x3bf1fb,_0x1ae876){var _0x167347,_0x32d207,_0x3a0e79;if(_[_0x525d('0x78')](_0x2af6d1[_0x525d('0x5e')][_0x525d('0x5e')])||_0x2af6d1['body'][_0x525d('0x5e')]===''){throw new db[(_0x525d('0x6f'))][(_0x525d('0x70'))](_0x525d('0x77'));}if(_[_0x525d('0x78')](_0x2af6d1[_0x525d('0x5e')]['to'])){}_0x167347=_0x2af6d1[_0x525d('0x5e')]['to'];return db[_0x525d('0x4f')]['findOne']({'where':{'id':_0x2af6d1[_0x525d('0x5f')]['id']}})[_0x525d('0x1f')](handleEntityNotFound(_0x3bf1fb,null))[_0x525d('0x1f')](function(_0x4c4bdd){if(_0x4c4bdd){return db[_0x525d('0x4f')]['find']({'where':{'id':_0x4c4bdd['id']},'include':[{'model':db['CmList'],'as':'List','include':[{'model':db[_0x525d('0x6e')],'as':_0x525d('0x7d'),'where':{[_0x4c4bdd[_0x525d('0x79')]]:_0x167347},'limit':0x1,'order':[[_0x525d('0x73'),_0x525d('0x7e')]]}]}]})[_0x525d('0x1f')](handleEntityNotFound(_0x3bf1fb,null))[_0x525d('0x1f')](function(_0x55da49){if(_0x55da49&&_0x55da49[_0x525d('0x7c')]){_0x32d207=_0x55da49[_0x525d('0x35')]({'plain':!![]});if(_0x32d207[_0x525d('0x7c')]&&_0x32d207['List'][_0x525d('0x7d')][_0x525d('0x45')]){return _0x32d207[_0x525d('0x7c')]['Contacts'][0x0];}return db[_0x525d('0x6e')][_0x525d('0x55')](_[_0x525d('0x17')](_0x2af6d1['body'],{'firstName':_0x167347,[_0x55da49[_0x525d('0x79')]]:_0x167347,'phone':_0x167347,'ListId':_0x32d207['ListId']}));}})[_0x525d('0x1f')](handleEntityNotFound(_0x3bf1fb,null))['then'](function(_0x29bb29){if(_0x29bb29){_0x3a0e79=_0x29bb29;return db[_0x525d('0x8a')]['find']({'where':{'ContactId':_0x3a0e79['id'],'closed':![],'OpenchannelAccountId':_0x32d207['id']}})[_0x525d('0x1f')](function(_0x54a5d3){if(_0x54a5d3){return[_0x54a5d3,![]];}return db[_0x525d('0x8a')][_0x525d('0x55')]({'UserId':_0x2af6d1[_0x525d('0x56')]['id'],'ContactId':_0x3a0e79['id'],'OpenchannelAccountId':_0x32d207['id'],'lastMsgDirection':_0x525d('0xb4'),'firstMsgDirection':_0x525d('0xb4'),'Messages':[_['merge'](_0x2af6d1[_0x525d('0x5e')],{'read':![],'body':_0x2af6d1[_0x525d('0x5e')]['body'],'OpenchannelAccountId':_0x32d207['id'],'UserId':_0x2af6d1[_0x525d('0x56')]['id'],'ContactId':_0x3a0e79['id']})]},{'include':[{'model':db[_0x525d('0x93')],'as':'Messages'}]})['then'](function(_0x162cb1){return[_0x162cb1,!![]];});});}})[_0x525d('0x8d')](function(_0x196046,_0x4b48b9){if(_0x4b48b9){return _0x196046;}return db[_0x525d('0x93')][_0x525d('0x55')](_[_0x525d('0x54')](_0x2af6d1[_0x525d('0x5e')],{'read':![],'body':_0x2af6d1[_0x525d('0x5e')]['body'],'OpenchannelAccountId':_0x32d207['id'],'OpenchannelInteractionId':_0x196046['id'],'UserId':_0x2af6d1[_0x525d('0x56')]['id'],'ContactId':_0x3a0e79['id']}))['then'](function(_0x5c0f6f){_0x196046[_0x525d('0xb5')][_0x525d('0xb6')]=[];_0x196046[_0x525d('0xb5')][_0x525d('0xb6')][_0x525d('0xb7')](_0x5c0f6f[_0x525d('0xb5')]);return _0x196046;});});}})['then'](respondWithResult(_0x3bf1fb,null))['catch'](handleError(_0x3bf1fb,null));};