7e0cc548f3b88ec50d483ddede8cd050ba925893
[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 _0x6cfa=['request','then','info','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','debug','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','apply','reject','destroy','get','UserProfileResource','end','stack','name','send','mandatoryDispositionPause','map','OpenchannelAccount','rawAttributes','fieldName','type','key','model','keys','query','filters','intersection','attributes','fields','length','nolimit','order','sort','filter','where','merge','VIRTUAL','includeAll','include','findAll','show','params','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','OpenchannelAccounts','UserProfileSection','find','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','Pause','describe','addDisposition','OpenchannelAccountId','Disposition','getDispositions','findOne','options','rows','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','hasOwnProperty','removeAnswers','CmContact','Sequelize','ValidationError','difference','createdAt','updatedAt','CompanyId','ListId','isNil','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','List','Contacts','OpenchannelApplication','Applications','account','applications','list','orderBy','priority','asc','from','lastName','threadId','externalUrl','OpenchannelInteraction','spread','contact','firstName','messageId','update','interaction','created','autoclose','push','close','unmanaged','*,*,*,*','UserId','User','unshift','agent','waitForTheAssignedAgent','queueId','OpenchannelQueue','EventManager','notify','addApplications','sequelize','transaction','Transaction','READ_COMMITTED','findAndCountAll','finally','getApplications','pick','getInteractions','Contact','Owner','fullname','Tag','Tags','color','tag','addAgents','emit','removeAgents','isArray','getAgents','DESC','out','Messages','OpenchannelMessage','dataValues','eml-format','fast-json-patch','moment','bluebird','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','redis','defaults','localhost','socket.io-emitter','./openchannelAccount.socket','client','http'];(function(_0x3ae2b2,_0x2d936f){var _0x1dbf00=function(_0x4072e9){while(--_0x4072e9){_0x3ae2b2['push'](_0x3ae2b2['shift']());}};_0x1dbf00(++_0x2d936f);}(_0x6cfa,0xa1));var _0xa6cf=function(_0x245a93,_0x258504){_0x245a93=_0x245a93-0x0;var _0x38bf51=_0x6cfa[_0x245a93];return _0x38bf51;};'use strict';var emlformat=require(_0xa6cf('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xa6cf('0x1'));var rp=require('request-promise');var moment=require(_0xa6cf('0x2'));var BPromise=require(_0xa6cf('0x3'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require(_0xa6cf('0x4'));var csv=require(_0xa6cf('0x5'));var ejs=require(_0xa6cf('0x6'));var fs=require('fs');var fs_extra=require(_0xa6cf('0x7'));var _=require(_0xa6cf('0x8'));var squel=require(_0xa6cf('0x9'));var crypto=require(_0xa6cf('0xa'));var jsforce=require('jsforce');var deskjs=require(_0xa6cf('0xb'));var toCsv=require('to-csv');var querystring=require(_0xa6cf('0xc'));var Papa=require('papaparse');var Redis=require(_0xa6cf('0xd'));var authService=require(_0xa6cf('0xe'));var qs=require(_0xa6cf('0xf'));var as=require(_0xa6cf('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xa6cf('0x11'))(_0xa6cf('0x12'));var utils=require(_0xa6cf('0x13'));var config=require(_0xa6cf('0x14'));var licenseUtil=require(_0xa6cf('0x15'));var db=require('../../mysqldb')['db'];config[_0xa6cf('0x16')]=_[_0xa6cf('0x17')](config[_0xa6cf('0x16')],{'host':_0xa6cf('0x18'),'port':0x18eb});var socket=require(_0xa6cf('0x19'))(new Redis(config[_0xa6cf('0x16')]));require(_0xa6cf('0x1a'))['register'](socket);var jayson=require('jayson/promise');var client=jayson[_0xa6cf('0x1b')][_0xa6cf('0x1c')]({'port':0x232c});var client9002=jayson['client'][_0xa6cf('0x1c')]({'port':0x232a});function respondWithRpcPromise(_0x2c6d3b,_0x304885,_0x2dab02,_0x428b51){return new BPromise(function(_0x493036,_0xe035fa){var _0x47fe8d=_0x428b51||client;return _0x47fe8d[_0xa6cf('0x1d')](_0x2c6d3b,_0x2dab02)[_0xa6cf('0x1e')](function(_0x2005fb){logger[_0xa6cf('0x1f')](_0xa6cf('0x20'),_0x304885,_0xa6cf('0x21'));logger[_0xa6cf('0x22')](_0xa6cf('0x23'),_0x304885,_0xa6cf('0x21'),JSON[_0xa6cf('0x24')](_0x2005fb));if(_0x2005fb[_0xa6cf('0x25')]){if(_0x2005fb[_0xa6cf('0x25')][_0xa6cf('0x26')]===0x1f4){logger['error'](_0xa6cf('0x20'),_0x304885,_0x2005fb['error'][_0xa6cf('0x27')]);return _0xe035fa(_0x2005fb[_0xa6cf('0x25')][_0xa6cf('0x27')]);}logger['error'](_0xa6cf('0x20'),_0x304885,_0x2005fb[_0xa6cf('0x25')][_0xa6cf('0x27')]);return _0x493036(_0x2005fb[_0xa6cf('0x25')]['message']);}else{logger[_0xa6cf('0x1f')]('OpenchannelAccount,\x20%s,\x20%s',_0x304885,_0xa6cf('0x21'));_0x493036(_0x2005fb[_0xa6cf('0x28')][_0xa6cf('0x27')]);}})[_0xa6cf('0x29')](function(_0x5a5a7d){logger[_0xa6cf('0x25')]('OpenchannelAccount,\x20%s,\x20%s',_0x304885,_0x5a5a7d);_0xe035fa(_0x5a5a7d);});});}function respondWithStatusCode(_0x18a12c,_0x1cd21d){_0x1cd21d=_0x1cd21d||0xcc;return function(_0x241d42){if(_0x241d42){return _0x18a12c[_0xa6cf('0x2a')](_0x1cd21d);}return _0x18a12c[_0xa6cf('0x2b')](_0x1cd21d)['end']();};}function respondWithResult(_0x204039,_0x335ac8){_0x335ac8=_0x335ac8||0xc8;return function(_0x20654b){if(_0x20654b){return _0x204039[_0xa6cf('0x2b')](_0x335ac8)[_0xa6cf('0x2c')](_0x20654b);}};}function respondWithFilteredResult(_0xf975f9,_0x557087){return function(_0xa03b07){if(_0xa03b07){var _0x388096=typeof _0x557087[_0xa6cf('0x2d')]===_0xa6cf('0x2e')&&typeof _0x557087[_0xa6cf('0x2f')]===_0xa6cf('0x2e');var _0x481146=_0xa03b07[_0xa6cf('0x30')];var _0x3f1c9d=_0x388096?0x0:_0x557087[_0xa6cf('0x2d')];var _0x14a059=_0x388096?_0xa03b07['count']:_0x557087['offset']+_0x557087['limit'];var _0x47112e;if(_0x14a059>=_0x481146){_0x14a059=_0x481146;_0x47112e=0xc8;}else{_0x47112e=0xce;}_0xf975f9['status'](_0x47112e);return _0xf975f9[_0xa6cf('0x31')](_0xa6cf('0x32'),_0x3f1c9d+'-'+_0x14a059+'/'+_0x481146)[_0xa6cf('0x2c')](_0xa03b07);}return null;};}function patchUpdates(_0x2c308e){return function(_0x4d7b22){try{jsonpatch[_0xa6cf('0x33')](_0x4d7b22,_0x2c308e,!![]);}catch(_0xb6b5ff){return BPromise[_0xa6cf('0x34')](_0xb6b5ff);}return _0x4d7b22['save']();};}function saveUpdates(_0x105a22,_0x445b75){return function(_0x398815){if(_0x398815){return _0x398815['update'](_0x105a22)['then'](function(_0x422c5b){return _0x422c5b;});}return null;};}function removeEntity(_0x247769,_0x44c60c){return function(_0x270e8b){if(_0x270e8b){return _0x270e8b[_0xa6cf('0x35')]()[_0xa6cf('0x1e')](function(){var _0x2c5ae3=_0x270e8b[_0xa6cf('0x36')]({'plain':!![]});var _0x13383d='OpenchannelAccounts';return db[_0xa6cf('0x37')][_0xa6cf('0x35')]({'where':{'type':_0x13383d,'resourceId':_0x2c5ae3['id']}})[_0xa6cf('0x1e')](function(){return _0x270e8b;});})[_0xa6cf('0x1e')](function(){_0x247769['status'](0xcc)[_0xa6cf('0x38')]();});}};}function handleEntityNotFound(_0x3152e3,_0xc082d7){return function(_0xedf519){if(!_0xedf519){_0x3152e3[_0xa6cf('0x2a')](0x194);}return _0xedf519;};}function handleError(_0x2fcb92,_0x1410fe){_0x1410fe=_0x1410fe||0x1f4;return function(_0x585d7a){logger[_0xa6cf('0x25')](_0x585d7a[_0xa6cf('0x39')]);if(_0x585d7a[_0xa6cf('0x3a')]){delete _0x585d7a['name'];}_0x2fcb92[_0xa6cf('0x2b')](_0x1410fe)[_0xa6cf('0x3b')](_0x585d7a);};}exports['index']=function(_0x168935,_0x1a7171){var _0x3c0ba5={'include':[{'model':db['Pause'],'as':_0xa6cf('0x3c')}]},_0x54d3b3={},_0x50809a={'count':0x0,'rows':[]};var _0x31b7df=_[_0xa6cf('0x3d')](db[_0xa6cf('0x3e')][_0xa6cf('0x3f')],function(_0x23f635){return{'name':_0x23f635[_0xa6cf('0x40')],'type':_0x23f635[_0xa6cf('0x41')][_0xa6cf('0x42')]};});_0x54d3b3[_0xa6cf('0x43')]=_[_0xa6cf('0x3d')](_0x31b7df,_0xa6cf('0x3a'));_0x54d3b3['query']=_[_0xa6cf('0x44')](_0x168935[_0xa6cf('0x45')]);_0x54d3b3[_0xa6cf('0x46')]=_[_0xa6cf('0x47')](_0x54d3b3[_0xa6cf('0x43')],_0x54d3b3[_0xa6cf('0x45')]);_0x3c0ba5[_0xa6cf('0x48')]=_['intersection'](_0x54d3b3[_0xa6cf('0x43')],qs[_0xa6cf('0x49')](_0x168935['query'][_0xa6cf('0x49')]));_0x3c0ba5[_0xa6cf('0x48')]=_0x3c0ba5[_0xa6cf('0x48')][_0xa6cf('0x4a')]?_0x3c0ba5[_0xa6cf('0x48')]:_0x54d3b3[_0xa6cf('0x43')];if(!_0x168935[_0xa6cf('0x45')]['hasOwnProperty'](_0xa6cf('0x4b'))){_0x3c0ba5[_0xa6cf('0x2f')]=qs[_0xa6cf('0x2f')](_0x168935[_0xa6cf('0x45')][_0xa6cf('0x2f')]);_0x3c0ba5[_0xa6cf('0x2d')]=qs[_0xa6cf('0x2d')](_0x168935[_0xa6cf('0x45')][_0xa6cf('0x2d')]);}_0x3c0ba5[_0xa6cf('0x4c')]=qs[_0xa6cf('0x4d')](_0x168935[_0xa6cf('0x45')]['sort']);_0x3c0ba5['where']=qs[_0xa6cf('0x46')](_['pick'](_0x168935[_0xa6cf('0x45')],_0x54d3b3[_0xa6cf('0x46')]),_0x31b7df);if(_0x168935[_0xa6cf('0x45')][_0xa6cf('0x4e')]){_0x3c0ba5[_0xa6cf('0x4f')]=_[_0xa6cf('0x50')](_0x3c0ba5[_0xa6cf('0x4f')],{'$or':_['map'](_0x31b7df,function(_0x6b01cd){if(_0x6b01cd[_0xa6cf('0x41')]!==_0xa6cf('0x51')){var _0x29dd07={};_0x29dd07[_0x6b01cd['name']]={'$like':'%'+_0x168935[_0xa6cf('0x45')][_0xa6cf('0x4e')]+'%'};return _0x29dd07;}})});}_0x3c0ba5=_[_0xa6cf('0x50')]({},_0x3c0ba5,_0x168935['options']);var _0xb3dcef={'where':_0x3c0ba5[_0xa6cf('0x4f')]};return db['OpenchannelAccount']['count'](_0xb3dcef)[_0xa6cf('0x1e')](function(_0x6349aa){_0x50809a['count']=_0x6349aa;if(_0x168935[_0xa6cf('0x45')][_0xa6cf('0x52')]){_0x3c0ba5[_0xa6cf('0x53')]=[{'all':!![]}];}return db[_0xa6cf('0x3e')][_0xa6cf('0x54')](_0x3c0ba5);})[_0xa6cf('0x1e')](function(_0x5ec28f){_0x50809a['rows']=_0x5ec28f;return _0x50809a;})[_0xa6cf('0x1e')](respondWithFilteredResult(_0x1a7171,_0x3c0ba5))[_0xa6cf('0x29')](handleError(_0x1a7171,null));};exports[_0xa6cf('0x55')]=function(_0x3320ac,_0x4a4307){var _0x4b9375={'raw':![],'where':{'id':_0x3320ac[_0xa6cf('0x56')]['id']},'include':[{'model':db['Pause'],'as':'mandatoryDispositionPause'}]},_0x52d9b7={};_0x52d9b7[_0xa6cf('0x43')]=_[_0xa6cf('0x44')](db[_0xa6cf('0x3e')][_0xa6cf('0x3f')]);_0x52d9b7[_0xa6cf('0x45')]=_['keys'](_0x3320ac['query']);_0x52d9b7['filters']=_[_0xa6cf('0x47')](_0x52d9b7[_0xa6cf('0x43')],_0x52d9b7[_0xa6cf('0x45')]);_0x4b9375['attributes']=_[_0xa6cf('0x47')](_0x52d9b7[_0xa6cf('0x43')],qs[_0xa6cf('0x49')](_0x3320ac['query']['fields']));_0x4b9375[_0xa6cf('0x48')]=_0x4b9375[_0xa6cf('0x48')][_0xa6cf('0x4a')]?_0x4b9375[_0xa6cf('0x48')]:_0x52d9b7['model'];if(_0x3320ac['query'][_0xa6cf('0x52')]){_0x4b9375['include']=[{'all':!![]}];}_0x4b9375=_['merge']({},_0x4b9375,_0x3320ac['options']);return db[_0xa6cf('0x3e')]['find'](_0x4b9375)[_0xa6cf('0x1e')](handleEntityNotFound(_0x4a4307,null))[_0xa6cf('0x1e')](respondWithResult(_0x4a4307,null))[_0xa6cf('0x29')](handleError(_0x4a4307,null));};exports[_0xa6cf('0x57')]=function(_0x36833a,_0x249a25){return db[_0xa6cf('0x3e')][_0xa6cf('0x57')](_0x36833a[_0xa6cf('0x58')],{})[_0xa6cf('0x1e')](function(_0x2512d7){var _0x3dc5f9=_0x36833a[_0xa6cf('0x59')][_0xa6cf('0x36')]({'plain':!![]});if(!_0x3dc5f9)throw new Error(_0xa6cf('0x5a'));if(_0x3dc5f9['role']==='user'){var _0x1e2dc9=_0x2512d7['get']({'plain':!![]});var _0x52b479=_0xa6cf('0x5b');return db[_0xa6cf('0x5c')][_0xa6cf('0x5d')]({'where':{'name':_0x52b479,'userProfileId':_0x3dc5f9['userProfileId']},'raw':!![]})[_0xa6cf('0x1e')](function(_0x1cf2df){if(_0x1cf2df&&_0x1cf2df[_0xa6cf('0x5e')]===0x0){return db[_0xa6cf('0x37')][_0xa6cf('0x57')]({'name':_0x1e2dc9['name'],'resourceId':_0x1e2dc9['id'],'type':_0x1cf2df[_0xa6cf('0x3a')],'sectionId':_0x1cf2df['id']},{})[_0xa6cf('0x1e')](function(){return _0x2512d7;});}else{return _0x2512d7;}})[_0xa6cf('0x29')](function(_0xa27cd0){logger[_0xa6cf('0x25')](_0xa6cf('0x5f'),_0xa27cd0);throw _0xa27cd0;});}return _0x2512d7;})[_0xa6cf('0x1e')](respondWithResult(_0x249a25,0xc9))[_0xa6cf('0x29')](handleError(_0x249a25,null));};exports['update']=function(_0x80983a,_0x1d5fa3){if(_0x80983a[_0xa6cf('0x58')]['id']){delete _0x80983a['body']['id'];}return db['OpenchannelAccount']['find']({'where':{'id':_0x80983a[_0xa6cf('0x56')]['id']},'include':[{'model':db[_0xa6cf('0x60')],'as':_0xa6cf('0x3c')}]})[_0xa6cf('0x1e')](handleEntityNotFound(_0x1d5fa3,null))[_0xa6cf('0x1e')](saveUpdates(_0x80983a[_0xa6cf('0x58')],null))['then'](respondWithResult(_0x1d5fa3,null))[_0xa6cf('0x29')](handleError(_0x1d5fa3,null));};exports[_0xa6cf('0x35')]=function(_0x38af8c,_0x451252){return db[_0xa6cf('0x3e')][_0xa6cf('0x5d')]({'where':{'id':_0x38af8c['params']['id']}})[_0xa6cf('0x1e')](handleEntityNotFound(_0x451252,null))[_0xa6cf('0x1e')](removeEntity(_0x451252,null))[_0xa6cf('0x29')](handleError(_0x451252,null));};exports[_0xa6cf('0x61')]=function(_0x297f5d,_0x51677b){return db['OpenchannelAccount']['describe']()[_0xa6cf('0x1e')](respondWithResult(_0x51677b,null))[_0xa6cf('0x29')](handleError(_0x51677b,null));};exports[_0xa6cf('0x62')]=function(_0x57f827,_0x5880c9,_0xfd3af5){if(_0x57f827[_0xa6cf('0x58')]['id']){delete _0x57f827[_0xa6cf('0x58')]['id'];}return db[_0xa6cf('0x3e')]['find']({'where':{'id':_0x57f827[_0xa6cf('0x56')]['id']}})[_0xa6cf('0x1e')](handleEntityNotFound(_0x5880c9,null))[_0xa6cf('0x1e')](function(_0x2d8fc2){if(_0x2d8fc2){_0x57f827[_0xa6cf('0x58')][_0xa6cf('0x63')]=_0x2d8fc2['id'];return db[_0xa6cf('0x64')][_0xa6cf('0x57')](_0x57f827[_0xa6cf('0x58')]);}})[_0xa6cf('0x1e')](respondWithResult(_0x5880c9,null))[_0xa6cf('0x29')](handleError(_0x5880c9,null));};exports[_0xa6cf('0x65')]=function(_0x4d8822,_0x249a46,_0x910087){var _0x4b4828={'raw':![],'where':{}};var _0xfe3b7b={};var _0x1c24bb={'count':0x0,'rows':[]};return db[_0xa6cf('0x3e')][_0xa6cf('0x66')]({'where':{'id':_0x4d8822[_0xa6cf('0x56')]['id']}})[_0xa6cf('0x1e')](handleEntityNotFound(_0x249a46,null))['then'](function(_0x43b689){if(_0x43b689){_0xfe3b7b[_0xa6cf('0x43')]=_[_0xa6cf('0x44')](db['Disposition'][_0xa6cf('0x3f')]);_0xfe3b7b[_0xa6cf('0x45')]=_[_0xa6cf('0x44')](_0x4d8822[_0xa6cf('0x45')]);_0xfe3b7b['filters']=_['intersection'](_0xfe3b7b[_0xa6cf('0x43')],_0xfe3b7b['query']);_0x4b4828[_0xa6cf('0x48')]=_[_0xa6cf('0x47')](_0xfe3b7b['model'],qs[_0xa6cf('0x49')](_0x4d8822[_0xa6cf('0x45')][_0xa6cf('0x49')]));_0x4b4828[_0xa6cf('0x48')]=_0x4b4828[_0xa6cf('0x48')][_0xa6cf('0x4a')]?_0x4b4828[_0xa6cf('0x48')]:_0xfe3b7b[_0xa6cf('0x43')];if(!_0x4d8822[_0xa6cf('0x45')]['hasOwnProperty']('nolimit')){_0x4b4828[_0xa6cf('0x2f')]=qs[_0xa6cf('0x2f')](_0x4d8822[_0xa6cf('0x45')][_0xa6cf('0x2f')]);_0x4b4828[_0xa6cf('0x2d')]=qs[_0xa6cf('0x2d')](_0x4d8822[_0xa6cf('0x45')][_0xa6cf('0x2d')]);}_0x4b4828[_0xa6cf('0x4c')]=qs[_0xa6cf('0x4d')](_0x4d8822[_0xa6cf('0x45')]['sort']);_0x4b4828[_0xa6cf('0x4f')]=qs[_0xa6cf('0x46')](_['pick'](_0x4d8822[_0xa6cf('0x45')],_0xfe3b7b['filters']));_0x4b4828[_0xa6cf('0x4f')]['OpenchannelAccountId']=_0x43b689['id'];if(_0x4d8822[_0xa6cf('0x45')][_0xa6cf('0x4e')]){_0x4b4828[_0xa6cf('0x4f')]=_['merge'](_0x4b4828[_0xa6cf('0x4f')],{'$or':_[_0xa6cf('0x3d')](_0x4b4828[_0xa6cf('0x48')],function(_0x49def4){var _0x22a726={};_0x22a726[_0x49def4]={'$like':'%'+_0x4d8822[_0xa6cf('0x45')][_0xa6cf('0x4e')]+'%'};return _0x22a726;})});}_0x4b4828=_[_0xa6cf('0x50')]({},_0x4b4828,_0x4d8822[_0xa6cf('0x67')]);return db[_0xa6cf('0x64')][_0xa6cf('0x30')]({'where':_0x4b4828[_0xa6cf('0x4f')]})[_0xa6cf('0x1e')](function(_0x3ee76c){_0x1c24bb['count']=_0x3ee76c;if(_0x4d8822[_0xa6cf('0x45')][_0xa6cf('0x52')]){_0x4b4828[_0xa6cf('0x53')]=[{'all':!![]}];}return db[_0xa6cf('0x64')][_0xa6cf('0x54')](_0x4b4828);})[_0xa6cf('0x1e')](function(_0x157a85){_0x1c24bb[_0xa6cf('0x68')]=_0x157a85;return _0x1c24bb;});}})[_0xa6cf('0x1e')](respondWithFilteredResult(_0x249a46,_0x4b4828))['catch'](handleError(_0x249a46,null));};exports[_0xa6cf('0x69')]=function(_0x495834,_0x7fe51b,_0xff57a6){return db[_0xa6cf('0x3e')][_0xa6cf('0x5d')]({'where':{'id':_0x495834['params']['id']}})[_0xa6cf('0x1e')](handleEntityNotFound(_0x7fe51b,null))[_0xa6cf('0x1e')](function(_0x259cde){if(_0x259cde){return _0x259cde[_0xa6cf('0x69')](_0x495834[_0xa6cf('0x45')][_0xa6cf('0x6a')]);}})['then'](respondWithStatusCode(_0x7fe51b,null))['catch'](handleError(_0x7fe51b,null));};exports[_0xa6cf('0x6b')]=function(_0x595855,_0x152461,_0x3f2940){if(_0x595855[_0xa6cf('0x58')]['id']){delete _0x595855[_0xa6cf('0x58')]['id'];}return db[_0xa6cf('0x3e')][_0xa6cf('0x5d')]({'where':{'id':_0x595855['params']['id']}})['then'](handleEntityNotFound(_0x152461,null))[_0xa6cf('0x1e')](function(_0x575b03){if(_0x575b03){_0x595855[_0xa6cf('0x58')]['OpenchannelAccountId']=_0x575b03['id'];return db[_0xa6cf('0x6c')]['create'](_0x595855[_0xa6cf('0x58')]);}})[_0xa6cf('0x1e')](respondWithResult(_0x152461,null))[_0xa6cf('0x29')](handleError(_0x152461,null));};exports[_0xa6cf('0x6d')]=function(_0xe72343,_0x2aa3d9,_0x241e53){var _0x800b1c={'raw':![],'where':{}};var _0x1a642e={};var _0x282150={'count':0x0,'rows':[]};return db['OpenchannelAccount']['findOne']({'where':{'id':_0xe72343[_0xa6cf('0x56')]['id']}})['then'](handleEntityNotFound(_0x2aa3d9,null))[_0xa6cf('0x1e')](function(_0x39ac37){if(_0x39ac37){_0x1a642e[_0xa6cf('0x43')]=_[_0xa6cf('0x44')](db[_0xa6cf('0x6c')]['rawAttributes']);_0x1a642e[_0xa6cf('0x45')]=_[_0xa6cf('0x44')](_0xe72343[_0xa6cf('0x45')]);_0x1a642e['filters']=_[_0xa6cf('0x47')](_0x1a642e['model'],_0x1a642e['query']);_0x800b1c[_0xa6cf('0x48')]=_['intersection'](_0x1a642e[_0xa6cf('0x43')],qs[_0xa6cf('0x49')](_0xe72343[_0xa6cf('0x45')]['fields']));_0x800b1c[_0xa6cf('0x48')]=_0x800b1c[_0xa6cf('0x48')][_0xa6cf('0x4a')]?_0x800b1c[_0xa6cf('0x48')]:_0x1a642e['model'];if(!_0xe72343[_0xa6cf('0x45')][_0xa6cf('0x6e')](_0xa6cf('0x4b'))){_0x800b1c['limit']=qs[_0xa6cf('0x2f')](_0xe72343[_0xa6cf('0x45')][_0xa6cf('0x2f')]);_0x800b1c[_0xa6cf('0x2d')]=qs[_0xa6cf('0x2d')](_0xe72343[_0xa6cf('0x45')][_0xa6cf('0x2d')]);}_0x800b1c[_0xa6cf('0x4c')]=qs[_0xa6cf('0x4d')](_0xe72343['query'][_0xa6cf('0x4d')]);_0x800b1c[_0xa6cf('0x4f')]=qs[_0xa6cf('0x46')](_['pick'](_0xe72343[_0xa6cf('0x45')],_0x1a642e[_0xa6cf('0x46')]));_0x800b1c['where'][_0xa6cf('0x63')]=_0x39ac37['id'];if(_0xe72343[_0xa6cf('0x45')][_0xa6cf('0x4e')]){_0x800b1c[_0xa6cf('0x4f')]=_[_0xa6cf('0x50')](_0x800b1c['where'],{'$or':_['map'](_0x800b1c[_0xa6cf('0x48')],function(_0x1d8796){var _0x4fa99b={};_0x4fa99b[_0x1d8796]={'$like':'%'+_0xe72343['query'][_0xa6cf('0x4e')]+'%'};return _0x4fa99b;})});}_0x800b1c=_[_0xa6cf('0x50')]({},_0x800b1c,_0xe72343['options']);return db['CannedAnswer']['count']({'where':_0x800b1c['where']})[_0xa6cf('0x1e')](function(_0x4ceaff){_0x282150[_0xa6cf('0x30')]=_0x4ceaff;if(_0xe72343[_0xa6cf('0x45')][_0xa6cf('0x52')]){_0x800b1c['include']=[{'all':!![]}];}return db[_0xa6cf('0x6c')]['findAll'](_0x800b1c);})[_0xa6cf('0x1e')](function(_0x75d64){_0x282150[_0xa6cf('0x68')]=_0x75d64;return _0x282150;});}})['then'](respondWithFilteredResult(_0x2aa3d9,_0x800b1c))[_0xa6cf('0x29')](handleError(_0x2aa3d9,null));};exports['removeAnswers']=function(_0x33144f,_0x5a4fb3,_0x15a810){return db[_0xa6cf('0x3e')][_0xa6cf('0x5d')]({'where':{'id':_0x33144f[_0xa6cf('0x56')]['id']}})[_0xa6cf('0x1e')](handleEntityNotFound(_0x5a4fb3,null))[_0xa6cf('0x1e')](function(_0xf85ec0){if(_0xf85ec0){return _0xf85ec0[_0xa6cf('0x6f')](_0x33144f[_0xa6cf('0x45')][_0xa6cf('0x6a')]);}})[_0xa6cf('0x1e')](respondWithStatusCode(_0x5a4fb3,null))[_0xa6cf('0x29')](handleError(_0x5a4fb3,null));};exports['notify']=function(_0x43c89c,_0x3210ff,_0x2d25e8){var _0x1faf18={'body':_0x43c89c[_0xa6cf('0x58')],'channel':'openchannel'};var _0x67f003=[];var _0x2d6ff8=[];var _0x1451ce={};var _0x4b6515=![];return db[_0xa6cf('0x70')][_0xa6cf('0x61')]()[_0xa6cf('0x1e')](function(_0x4564e3){if(!_0x4564e3){throw new db[(_0xa6cf('0x71'))][(_0xa6cf('0x72'))]('no\x20available\x20attributes');}_0x67f003=_[_0xa6cf('0x73')](_[_0xa6cf('0x44')](_0x4564e3),[_0xa6cf('0x74'),_0xa6cf('0x75')]);_0x2d6ff8=_[_0xa6cf('0x73')](_['keys'](_0x4564e3),[_0xa6cf('0x74'),_0xa6cf('0x75'),_0xa6cf('0x76'),_0xa6cf('0x77')]);if(_0x43c89c[_0xa6cf('0x58')]['id']){delete _0x43c89c[_0xa6cf('0x58')]['id'];}if(_[_0xa6cf('0x78')](_0x43c89c[_0xa6cf('0x58')]['from'])){throw new db[(_0xa6cf('0x71'))]['ValidationError']('from\x20is\x20mandatory');}if(_['isNil'](_0x43c89c['body']['body'])||_0x43c89c[_0xa6cf('0x58')][_0xa6cf('0x58')]===''){throw new db[(_0xa6cf('0x71'))][(_0xa6cf('0x72'))](_0xa6cf('0x79'));}if(_[_0xa6cf('0x78')](_0x43c89c[_0xa6cf('0x58')][_0xa6cf('0x7a')])){throw new db[(_0xa6cf('0x71'))][(_0xa6cf('0x72'))](_0xa6cf('0x7b')+_0x2d6ff8);}if(!_[_0xa6cf('0x7c')](_0x2d6ff8,_0x43c89c[_0xa6cf('0x58')]['mapKey'])){throw new db[(_0xa6cf('0x71'))][(_0xa6cf('0x72'))](_0xa6cf('0x7d')+_0x2d6ff8);}_0x1451ce[_0x43c89c[_0xa6cf('0x58')][_0xa6cf('0x7a')]]=_0x43c89c[_0xa6cf('0x58')]['from'];})['then'](function(){return db[_0xa6cf('0x3e')][_0xa6cf('0x5d')]({'where':{'id':_0x43c89c['params']['id']},'include':[{'model':db[_0xa6cf('0x7e')],'as':_0xa6cf('0x7f'),'include':[{'model':db[_0xa6cf('0x70')],'as':_0xa6cf('0x80'),'where':_0x1451ce,'limit':0x1,'order':[[_0xa6cf('0x75'),'DESC']]}]},{'model':db[_0xa6cf('0x81')],'as':_0xa6cf('0x82')}]});})[_0xa6cf('0x1e')](handleEntityNotFound(_0x3210ff,null))[_0xa6cf('0x1e')](function(_0x2ad12b){if(_0x2ad12b&&_0x2ad12b[_0xa6cf('0x7f')]){_0x1faf18[_0xa6cf('0x83')]=_0x2ad12b;_0x1faf18[_0xa6cf('0x84')]=_0x2ad12b[_0xa6cf('0x82')];_0x1faf18[_0xa6cf('0x85')]=_0x2ad12b[_0xa6cf('0x7f')];_0x1faf18[_0xa6cf('0x84')]=_[_0xa6cf('0x86')](_0x1faf18['applications'],[_0xa6cf('0x87')],[_0xa6cf('0x88')]);if(_0x1faf18[_0xa6cf('0x83')]['Applications']){delete _0x1faf18[_0xa6cf('0x83')][_0xa6cf('0x82')];}if(_0x1faf18[_0xa6cf('0x83')][_0xa6cf('0x7f')]&&_0x1faf18[_0xa6cf('0x83')][_0xa6cf('0x7f')]['Contacts'][_0xa6cf('0x4a')]){return _0x1faf18[_0xa6cf('0x83')][_0xa6cf('0x7f')][_0xa6cf('0x80')][0x0];}var _0x39cc8c=_[_0xa6cf('0x17')](_0x43c89c[_0xa6cf('0x58')],{'firstName':_0x43c89c[_0xa6cf('0x58')][_0xa6cf('0x89')],'ListId':_0x2ad12b[_0xa6cf('0x77')]});_0x39cc8c[_0x43c89c[_0xa6cf('0x58')][_0xa6cf('0x7a')]]=_0x43c89c[_0xa6cf('0x58')][_0xa6cf('0x89')];return db[_0xa6cf('0x70')][_0xa6cf('0x57')](_0x39cc8c,{'fields':_0x67f003,'raw':!![]});}})[_0xa6cf('0x1e')](handleEntityNotFound(_0x3210ff,null))[_0xa6cf('0x1e')](function(_0xcaa4a1){_0x1faf18['contact']=_0xcaa4a1;if(_0xcaa4a1){var _0x4a7211={'ContactId':_0xcaa4a1['id'],'OpenchannelAccountId':_0x43c89c[_0xa6cf('0x56')]['id'],'from':(_0xcaa4a1['firstName']||'')+'\x20'+(_0xcaa4a1[_0xa6cf('0x8a')]||'')};var _0x321b6c={'OpenchannelAccountId':_0x43c89c[_0xa6cf('0x56')]['id'],'closed':![]};if(_0x43c89c[_0xa6cf('0x58')][_0xa6cf('0x8b')]){_0x321b6c[_0xa6cf('0x8b')]=_0x43c89c[_0xa6cf('0x58')][_0xa6cf('0x8b')];return db['OpenchannelInteraction']['find']({'where':_0x321b6c})['then'](function(_0x382600){if(_0x382600){return[_0x382600,![]];}_0x4a7211[_0xa6cf('0x8b')]=_0x43c89c[_0xa6cf('0x58')][_0xa6cf('0x8b')];_0x4a7211[_0xa6cf('0x8c')]=_0x43c89c[_0xa6cf('0x58')][_0xa6cf('0x8c')];return db[_0xa6cf('0x8d')][_0xa6cf('0x57')](_0x4a7211)[_0xa6cf('0x1e')](function(_0x1f37a1){return[_0x1f37a1,!![]];});});}else{_0x321b6c[_0xa6cf('0x8b')]=null;}_0x321b6c['ContactId']=_0xcaa4a1['id'];return db[_0xa6cf('0x8d')][_0xa6cf('0x5d')]({'where':_0x321b6c})[_0xa6cf('0x1e')](function(_0x592019){if(_0x592019){return[_0x592019,![]];}return db[_0xa6cf('0x8d')][_0xa6cf('0x57')](_0x4a7211)[_0xa6cf('0x1e')](function(_0x29a93c){return[_0x29a93c,!![]];});});}})[_0xa6cf('0x8e')](function(_0x9ae34d,_0x42c985){if(_0x9ae34d){_0x4b6515=_0x42c985;if(!_0x42c985){var _0x4b8f45={'from':(_0x1faf18[_0xa6cf('0x8f')][_0xa6cf('0x90')]||'')+'\x20'+(_0x1faf18[_0xa6cf('0x8f')][_0xa6cf('0x8a')]||'')};if(_0x43c89c[_0xa6cf('0x58')][_0xa6cf('0x8b')]&&_0x43c89c['body'][_0xa6cf('0x91')]&&_0x43c89c[_0xa6cf('0x58')][_0xa6cf('0x8b')]!=_0x43c89c[_0xa6cf('0x58')]['messageId']){_0x4b8f45['threadId']=_0x43c89c[_0xa6cf('0x58')][_0xa6cf('0x91')];}return _0x9ae34d[_0xa6cf('0x92')](_0x4b8f45);}else{return _0x9ae34d;}}})[_0xa6cf('0x1e')](function(_0x2bb7fa){_0x1faf18['interaction']=_0x2bb7fa['get']({'plain':!![]});_0x1faf18[_0xa6cf('0x93')]['created']=_0x4b6515;if(_0x1faf18[_0xa6cf('0x93')][_0xa6cf('0x94')]){if(_0x1faf18[_0xa6cf('0x83')][_0xa6cf('0x95')]){_0x1faf18[_0xa6cf('0x84')][_0xa6cf('0x96')]({'id':0x0,'priority':_0x1faf18[_0xa6cf('0x84')][_0xa6cf('0x4a')]+0x1,'app':_0xa6cf('0x97'),'appdata':_0xa6cf('0x98'),'interval':_0xa6cf('0x99')});}}return db['OpenchannelMessage'][_0xa6cf('0x57')]({'body':_0x43c89c[_0xa6cf('0x58')][_0xa6cf('0x58')],'OpenchannelAccountId':_0x43c89c[_0xa6cf('0x56')]['id'],'OpenchannelInteractionId':_0x2bb7fa['id'],'direction':'in','ContactId':_0x1faf18[_0xa6cf('0x8f')]['id'],'AttachmentId':_0x43c89c[_0xa6cf('0x58')]['AttachmentId']});})[_0xa6cf('0x1e')](function(_0x41eb29){_0x1faf18[_0xa6cf('0x27')]=_0x41eb29;if(!_0x1faf18[_0xa6cf('0x93')][_0xa6cf('0x9a')])return;return db[_0xa6cf('0x9b')][_0xa6cf('0x5d')]({'attributes':['id','name'],'where':{'id':_0x1faf18[_0xa6cf('0x93')][_0xa6cf('0x9a')]}});})[_0xa6cf('0x1e')](function(_0x2ffbfc){if(_0x2ffbfc){_0x1faf18[_0xa6cf('0x84')][_0xa6cf('0x9c')]({'id':0x0,'priority':0x0,'app':_0xa6cf('0x9d'),'appdata':_0x2ffbfc['name']+','+(_0x1faf18[_0xa6cf('0x83')][_0xa6cf('0x9e')]||0xa),'interval':'*,*,*,*'});}if(!_0x1faf18[_0xa6cf('0x93')][_0xa6cf('0x9f')])return;return db[_0xa6cf('0xa0')][_0xa6cf('0x5d')]({'attributes':['id',_0xa6cf('0x3a')],'where':{'id':_0x1faf18['interaction'][_0xa6cf('0x9f')]}});})[_0xa6cf('0x1e')](function(_0x27d643){if(_0x27d643){_0x1faf18[_0xa6cf('0x84')][_0xa6cf('0x9c')]({'id':0x0,'priority':0x1,'app':'queue','appdata':_0x27d643[_0xa6cf('0x3a')]+','+(_0x1faf18[_0xa6cf('0x83')]['waitForTheAssignedQueue']||0x12c),'interval':'*,*,*,*'});}return respondWithRpcPromise('Start','startRouting',_0x1faf18);})[_0xa6cf('0x1e')](function(_0x4be7f0){respondWithRpcPromise(_0xa6cf('0xa1'),_0xa6cf('0xa1'),{'event':_0xa6cf('0xa2'),'message':_0x4be7f0},client9002);return _0x4be7f0;})[_0xa6cf('0x1e')](respondWithResult(_0x3210ff,null))[_0xa6cf('0x29')](handleError(_0x3210ff,null));};exports[_0xa6cf('0xa3')]=function(_0x286079,_0xeb2e78){var _0x2bedfb=_0x286079['params']['id'];var _0x2fba3a=_0x286079[_0xa6cf('0x58')];var _0x570b1c=0xc8;var _0x30ccd0=null;return db[_0xa6cf('0xa4')][_0xa6cf('0xa5')]({'isolationLevel':db['sequelize'][_0xa6cf('0xa6')]['ISOLATION_LEVELS'][_0xa6cf('0xa7')]},function(_0x100a2d){return db['OpenchannelAccount'][_0xa6cf('0x66')]({'where':{'id':_0x2bedfb},'transaction':_0x100a2d})['then'](function(_0x35fb7f){if(_0x35fb7f){return db[_0xa6cf('0x81')][_0xa6cf('0x35')]({'where':{'OpenchannelAccountId':_0x2bedfb},'transaction':_0x100a2d})[_0xa6cf('0x1e')](function(){var _0x3f0853=_[_0xa6cf('0x3d')](_0x2fba3a,function(_0x2eba2a){_0x2eba2a['OpenchannelAccountId']=_0x2bedfb;return _0x2eba2a;});return db[_0xa6cf('0x81')]['bulkCreate'](_0x3f0853,{'transaction':_0x100a2d});});}else{_0x570b1c=0x194;_0x30ccd0=[];}});})[_0xa6cf('0x1e')](function(){if(_0x570b1c!==0x194){return db[_0xa6cf('0x81')][_0xa6cf('0xa8')]({'where':{'OpenchannelAccountId':_0x2bedfb},'order':_0xa6cf('0x87')})[_0xa6cf('0x1e')](function(_0x7640cb){_0x30ccd0=_0x7640cb;});}})[_0xa6cf('0x29')](function(_0x2b3b29){_0x570b1c=0x1f4;logger[_0xa6cf('0x25')](_0x2b3b29[_0xa6cf('0x39')]);if(_0x2b3b29[_0xa6cf('0x3a')]){delete _0x2b3b29[_0xa6cf('0x3a')];}_0x30ccd0=_0x2b3b29;})[_0xa6cf('0xa9')](function(){if(_0x30ccd0===null){_0xeb2e78['sendStatus'](_0x570b1c);}else{if(_0x570b1c===0x1f4){_0xeb2e78[_0xa6cf('0x2b')](_0x570b1c)[_0xa6cf('0x3b')](_0x30ccd0);}else{_0xeb2e78[_0xa6cf('0x2b')](_0x570b1c)[_0xa6cf('0x2c')](_0x30ccd0);}}});};exports[_0xa6cf('0xaa')]=function(_0x1a39aa,_0x518d28,_0x46786d){var _0x55f79b={};var _0x166b8a={};var _0x16b7b5;var _0xaa11a0;return db[_0xa6cf('0x3e')][_0xa6cf('0x66')]({'where':{'id':_0x1a39aa[_0xa6cf('0x56')]['id']}})[_0xa6cf('0x1e')](handleEntityNotFound(_0x518d28,null))[_0xa6cf('0x1e')](function(_0x2de917){if(_0x2de917){_0x16b7b5=_0x2de917;_0x166b8a['model']=_[_0xa6cf('0x44')](db[_0xa6cf('0x81')]['rawAttributes']);_0x166b8a['query']=_[_0xa6cf('0x44')](_0x1a39aa[_0xa6cf('0x45')]);_0x166b8a['filters']=_[_0xa6cf('0x47')](_0x166b8a['model'],_0x166b8a[_0xa6cf('0x45')]);_0x55f79b[_0xa6cf('0x48')]=_[_0xa6cf('0x47')](_0x166b8a[_0xa6cf('0x43')],qs[_0xa6cf('0x49')](_0x1a39aa['query']['fields']));_0x55f79b['attributes']=_0x55f79b[_0xa6cf('0x48')][_0xa6cf('0x4a')]?_0x55f79b[_0xa6cf('0x48')]:_0x166b8a[_0xa6cf('0x43')];_0x55f79b[_0xa6cf('0x4c')]=qs[_0xa6cf('0x4d')](_0x1a39aa['query'][_0xa6cf('0x4d')]);_0x55f79b[_0xa6cf('0x4f')]=qs[_0xa6cf('0x46')](_[_0xa6cf('0xab')](_0x1a39aa[_0xa6cf('0x45')],_0x166b8a[_0xa6cf('0x46')]));if(_0x1a39aa[_0xa6cf('0x45')]['filter']){_0x55f79b[_0xa6cf('0x4f')]=_[_0xa6cf('0x50')](_0x55f79b['where'],{'$or':_[_0xa6cf('0x3d')](_0x55f79b[_0xa6cf('0x48')],function(_0x1aa145){var _0x2f5cbb={};_0x2f5cbb[_0x1aa145]={'$like':'%'+_0x1a39aa['query']['filter']+'%'};return _0x2f5cbb;})});}_0x55f79b=_[_0xa6cf('0x50')]({},_0x55f79b,_0x1a39aa[_0xa6cf('0x67')]);return _0x16b7b5[_0xa6cf('0xaa')](_0x55f79b);}})[_0xa6cf('0x1e')](function(_0x54cdf3){if(_0x54cdf3){_0xaa11a0=_0x54cdf3[_0xa6cf('0x4a')];if(!_0x1a39aa[_0xa6cf('0x45')]['hasOwnProperty']('nolimit')){_0x55f79b['limit']=qs['limit'](_0x1a39aa['query'][_0xa6cf('0x2f')]);_0x55f79b[_0xa6cf('0x2d')]=qs[_0xa6cf('0x2d')](_0x1a39aa[_0xa6cf('0x45')]['offset']);}return _0x16b7b5[_0xa6cf('0xaa')](_0x55f79b);}})['then'](function(_0x5a3d17){if(_0x5a3d17){return _0x5a3d17?{'count':_0xaa11a0,'rows':_0x5a3d17}:null;}})[_0xa6cf('0x1e')](respondWithResult(_0x518d28,null))['catch'](handleError(_0x518d28,null));};exports[_0xa6cf('0xac')]=function(_0x30a8be,_0x157e1d,_0x245c55){var _0x45557e={'raw':![],'where':{}};var _0x4ac706={};var _0xc45b14={'count':0x0,'rows':[]};return db[_0xa6cf('0x3e')]['findOne']({'where':{'id':_0x30a8be['params']['id']}})[_0xa6cf('0x1e')](handleEntityNotFound(_0x157e1d,null))[_0xa6cf('0x1e')](function(_0x4d70f2){if(_0x4d70f2){_0x4ac706[_0xa6cf('0x43')]=_[_0xa6cf('0x44')](db[_0xa6cf('0x8d')][_0xa6cf('0x3f')]);_0x4ac706[_0xa6cf('0x45')]=_[_0xa6cf('0x44')](_0x30a8be[_0xa6cf('0x45')]);_0x4ac706[_0xa6cf('0x46')]=_[_0xa6cf('0x47')](_0x4ac706['model'],_0x4ac706[_0xa6cf('0x45')]);_0x45557e[_0xa6cf('0x48')]=_[_0xa6cf('0x47')](_0x4ac706[_0xa6cf('0x43')],qs[_0xa6cf('0x49')](_0x30a8be[_0xa6cf('0x45')]['fields']));_0x45557e[_0xa6cf('0x48')]=_0x45557e[_0xa6cf('0x48')]['length']?_0x45557e[_0xa6cf('0x48')]:_0x4ac706[_0xa6cf('0x43')];if(!_0x30a8be[_0xa6cf('0x45')][_0xa6cf('0x6e')]('nolimit')){_0x45557e[_0xa6cf('0x2f')]=qs['limit'](_0x30a8be[_0xa6cf('0x45')][_0xa6cf('0x2f')]);_0x45557e[_0xa6cf('0x2d')]=qs[_0xa6cf('0x2d')](_0x30a8be['query'][_0xa6cf('0x2d')]);}_0x45557e[_0xa6cf('0x4c')]=qs['sort'](_0x30a8be['query'][_0xa6cf('0x4d')]);_0x45557e[_0xa6cf('0x4f')]=qs[_0xa6cf('0x46')](_[_0xa6cf('0xab')](_0x30a8be['query'],_0x4ac706[_0xa6cf('0x46')]));_0x45557e[_0xa6cf('0x4f')][_0xa6cf('0x63')]=_0x4d70f2['id'];if(_0x30a8be[_0xa6cf('0x45')][_0xa6cf('0x4e')]){_0x45557e[_0xa6cf('0x4f')]=_[_0xa6cf('0x50')](_0x45557e[_0xa6cf('0x4f')],{'$or':_['map'](_0x45557e[_0xa6cf('0x48')],function(_0x484bef){var _0x146550={};_0x146550[_0x484bef]={'$like':'%'+_0x30a8be[_0xa6cf('0x45')]['filter']+'%'};return _0x146550;})});}_0x45557e=_['merge']({},_0x45557e,_0x30a8be[_0xa6cf('0x67')]);return db[_0xa6cf('0x8d')][_0xa6cf('0x30')]({'where':_0x45557e[_0xa6cf('0x4f')]})[_0xa6cf('0x1e')](function(_0x52ab7d){_0xc45b14[_0xa6cf('0x30')]=_0x52ab7d;if(_0x30a8be[_0xa6cf('0x45')][_0xa6cf('0x52')]){_0x45557e[_0xa6cf('0x53')]=[{'model':db[_0xa6cf('0x70')],'as':_0xa6cf('0xad'),'required':![]},{'model':db[_0xa6cf('0x9b')],'as':_0xa6cf('0xae'),'attributes':[_0xa6cf('0x3a'),_0xa6cf('0xaf'),'internal'],'required':![]},{'model':db[_0xa6cf('0xb0')],'as':_0xa6cf('0xb1'),'attributes':['id','name',_0xa6cf('0xb2')],'where':_0x30a8be[_0xa6cf('0x45')][_0xa6cf('0xb3')]?{'id':_0x30a8be[_0xa6cf('0x45')][_0xa6cf('0xb3')]}:undefined,'required':_0x30a8be[_0xa6cf('0x45')][_0xa6cf('0xb3')]?!![]:![]}];}return db[_0xa6cf('0x8d')][_0xa6cf('0x54')](_0x45557e);})[_0xa6cf('0x1e')](function(_0x16d4c3){_0xc45b14[_0xa6cf('0x68')]=_0x16d4c3;return _0xc45b14;});}})[_0xa6cf('0x1e')](respondWithFilteredResult(_0x157e1d,_0x45557e))['catch'](handleError(_0x157e1d,null));};exports[_0xa6cf('0xb4')]=function(_0x2222e8,_0x419889,_0x13aec2){return db[_0xa6cf('0x3e')][_0xa6cf('0x5d')]({'where':{'id':_0x2222e8[_0xa6cf('0x56')]['id']}})[_0xa6cf('0x1e')](handleEntityNotFound(_0x419889,null))['then'](function(_0x55d482){if(_0x55d482){return _0x55d482[_0xa6cf('0xb4')](_0x2222e8[_0xa6cf('0x58')][_0xa6cf('0x6a')],_['omit'](_0x2222e8['body'],['ids','id'])||{})[_0xa6cf('0x8e')](function(_0x51099f){for(var _0xa5ca8a=0x0;_0xa5ca8a<_0x2222e8[_0xa6cf('0x58')][_0xa6cf('0x6a')]['length'];_0xa5ca8a+=0x1){socket[_0xa6cf('0xb5')]('userOpenchannelAccount:save',{'UserId':Number(_0x2222e8[_0xa6cf('0x58')][_0xa6cf('0x6a')][_0xa5ca8a]),'OpenchannelAccountId':Number(_0x2222e8[_0xa6cf('0x56')]['id'])});}return _0x51099f;});}})[_0xa6cf('0x1e')](respondWithResult(_0x419889,null))[_0xa6cf('0x29')](handleError(_0x419889,null));};exports[_0xa6cf('0xb6')]=function(_0x566dc6,_0x4f5168,_0x15d95c){return db[_0xa6cf('0x3e')][_0xa6cf('0x5d')]({'where':{'id':_0x566dc6[_0xa6cf('0x56')]['id']}})[_0xa6cf('0x1e')](handleEntityNotFound(_0x4f5168,null))['then'](function(_0x2e5d7a){if(_0x2e5d7a){return _0x2e5d7a[_0xa6cf('0xb6')](_0x566dc6[_0xa6cf('0x45')][_0xa6cf('0x6a')])[_0xa6cf('0x1e')](function(){if(_[_0xa6cf('0xb7')](_0x566dc6[_0xa6cf('0x45')][_0xa6cf('0x6a')])){for(var _0x16d92d=0x0;_0x16d92d<_0x566dc6[_0xa6cf('0x45')][_0xa6cf('0x6a')][_0xa6cf('0x4a')];_0x16d92d+=0x1){socket['emit']('userOpenchannelAccount:remove',{'UserId':Number(_0x566dc6['query']['ids'][_0x16d92d]),'OpenchannelAccountId':Number(_0x566dc6[_0xa6cf('0x56')]['id'])});}}else{socket['emit']('userOpenchannelAccount:remove',{'UserId':Number(_0x566dc6['query'][_0xa6cf('0x6a')]),'OpenchannelAccountId':Number(_0x566dc6[_0xa6cf('0x56')]['id'])});}});}})[_0xa6cf('0x1e')](respondWithStatusCode(_0x4f5168,null))[_0xa6cf('0x29')](handleError(_0x4f5168,null));};exports['getAgents']=function(_0x53450e,_0x21064a,_0x5b2777){var _0x40adfb={};var _0x350bfb={};var _0x2057fc;var _0x4faea7;return db[_0xa6cf('0x3e')][_0xa6cf('0x66')]({'where':{'id':_0x53450e[_0xa6cf('0x56')]['id']}})[_0xa6cf('0x1e')](handleEntityNotFound(_0x21064a,null))['then'](function(_0x301939){if(_0x301939){_0x2057fc=_0x301939;_0x350bfb[_0xa6cf('0x43')]=_[_0xa6cf('0x44')](db['User'][_0xa6cf('0x3f')]);_0x350bfb[_0xa6cf('0x45')]=_['keys'](_0x53450e[_0xa6cf('0x45')]);_0x350bfb['filters']=_['intersection'](_0x350bfb[_0xa6cf('0x43')],_0x350bfb[_0xa6cf('0x45')]);_0x40adfb[_0xa6cf('0x48')]=_['intersection'](_0x350bfb[_0xa6cf('0x43')],qs['fields'](_0x53450e[_0xa6cf('0x45')]['fields']));_0x40adfb[_0xa6cf('0x48')]=_0x40adfb[_0xa6cf('0x48')]['length']?_0x40adfb['attributes']:_0x350bfb[_0xa6cf('0x43')];_0x40adfb[_0xa6cf('0x4c')]=qs[_0xa6cf('0x4d')](_0x53450e[_0xa6cf('0x45')][_0xa6cf('0x4d')]);_0x40adfb['where']=qs[_0xa6cf('0x46')](_['pick'](_0x53450e[_0xa6cf('0x45')],_0x350bfb['filters']));if(_0x53450e[_0xa6cf('0x45')][_0xa6cf('0x4e')]){_0x40adfb[_0xa6cf('0x4f')]=_[_0xa6cf('0x50')](_0x40adfb[_0xa6cf('0x4f')],{'$or':_['map'](_0x40adfb[_0xa6cf('0x48')],function(_0x3d35fd){var _0x11b5d7={};_0x11b5d7[_0x3d35fd]={'$like':'%'+_0x53450e[_0xa6cf('0x45')][_0xa6cf('0x4e')]+'%'};return _0x11b5d7;})});}_0x40adfb=_['merge']({},_0x40adfb,_0x53450e[_0xa6cf('0x67')]);return _0x2057fc[_0xa6cf('0xb8')](_0x40adfb);}})[_0xa6cf('0x1e')](function(_0x2a3c1a){if(_0x2a3c1a){_0x4faea7=_0x2a3c1a[_0xa6cf('0x4a')];if(!_0x53450e[_0xa6cf('0x45')]['hasOwnProperty'](_0xa6cf('0x4b'))){_0x40adfb[_0xa6cf('0x2f')]=qs[_0xa6cf('0x2f')](_0x53450e[_0xa6cf('0x45')][_0xa6cf('0x2f')]);_0x40adfb[_0xa6cf('0x2d')]=qs[_0xa6cf('0x2d')](_0x53450e[_0xa6cf('0x45')]['offset']);}return _0x2057fc[_0xa6cf('0xb8')](_0x40adfb);}})['then'](function(_0x2c052e){if(_0x2c052e){return _0x2c052e?{'count':_0x4faea7,'rows':_0x2c052e}:null;}})[_0xa6cf('0x1e')](respondWithResult(_0x21064a,null))['catch'](handleError(_0x21064a,null));};exports['send']=function(_0x36a1a8,_0x120fd1,_0x1a62ec){var _0x583c61,_0x36eba5,_0x196ca9;if(_[_0xa6cf('0x78')](_0x36a1a8[_0xa6cf('0x58')]['body'])||_0x36a1a8[_0xa6cf('0x58')][_0xa6cf('0x58')]===''){throw new db['Sequelize'][(_0xa6cf('0x72'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0xa6cf('0x78')](_0x36a1a8['body']['to'])){}_0x583c61=_0x36a1a8[_0xa6cf('0x58')]['to'];return db[_0xa6cf('0x3e')][_0xa6cf('0x66')]({'where':{'id':_0x36a1a8[_0xa6cf('0x56')]['id']}})['then'](handleEntityNotFound(_0x120fd1,null))[_0xa6cf('0x1e')](function(_0x5f1d1a){if(_0x5f1d1a){return db[_0xa6cf('0x3e')][_0xa6cf('0x5d')]({'where':{'id':_0x5f1d1a['id']},'include':[{'model':db[_0xa6cf('0x7e')],'as':'List','include':[{'model':db[_0xa6cf('0x70')],'as':_0xa6cf('0x80'),'where':{[_0x5f1d1a['mapKey']]:_0x583c61},'limit':0x1,'order':[[_0xa6cf('0x75'),_0xa6cf('0xb9')]]}]}]})[_0xa6cf('0x1e')](handleEntityNotFound(_0x120fd1,null))[_0xa6cf('0x1e')](function(_0x37bbab){if(_0x37bbab&&_0x37bbab[_0xa6cf('0x7f')]){_0x36eba5=_0x37bbab['get']({'plain':!![]});if(_0x36eba5[_0xa6cf('0x7f')]&&_0x36eba5[_0xa6cf('0x7f')]['Contacts'][_0xa6cf('0x4a')]){return _0x36eba5['List'][_0xa6cf('0x80')][0x0];}return db[_0xa6cf('0x70')][_0xa6cf('0x57')](_[_0xa6cf('0x17')](_0x36a1a8['body'],{'firstName':_0x583c61,[_0x37bbab[_0xa6cf('0x7a')]]:_0x583c61,'phone':_0x583c61,'ListId':_0x36eba5[_0xa6cf('0x77')]}));}})[_0xa6cf('0x1e')](handleEntityNotFound(_0x120fd1,null))[_0xa6cf('0x1e')](function(_0x31729c){if(_0x31729c){_0x196ca9=_0x31729c;return db[_0xa6cf('0x8d')][_0xa6cf('0x5d')]({'where':{'ContactId':_0x196ca9['id'],'closed':![],'OpenchannelAccountId':_0x36eba5['id']}})[_0xa6cf('0x1e')](function(_0x53b4df){if(_0x53b4df){return[_0x53b4df,![]];}return db[_0xa6cf('0x8d')][_0xa6cf('0x57')]({'UserId':_0x36a1a8[_0xa6cf('0x59')]['id'],'ContactId':_0x196ca9['id'],'OpenchannelAccountId':_0x36eba5['id'],'lastMsgDirection':_0xa6cf('0xba'),'firstMsgDirection':'out','Messages':[_[_0xa6cf('0x50')](_0x36a1a8[_0xa6cf('0x58')],{'read':![],'body':_0x36a1a8[_0xa6cf('0x58')][_0xa6cf('0x58')],'OpenchannelAccountId':_0x36eba5['id'],'UserId':_0x36a1a8['user']['id'],'ContactId':_0x196ca9['id']})]},{'include':[{'model':db['OpenchannelMessage'],'as':_0xa6cf('0xbb')}]})[_0xa6cf('0x1e')](function(_0x10bfbf){return[_0x10bfbf,!![]];});});}})[_0xa6cf('0x8e')](function(_0x3572e3,_0x34aba3){if(_0x34aba3){return _0x3572e3;}return db[_0xa6cf('0xbc')][_0xa6cf('0x57')](_['merge'](_0x36a1a8[_0xa6cf('0x58')],{'read':![],'body':_0x36a1a8['body'][_0xa6cf('0x58')],'OpenchannelAccountId':_0x36eba5['id'],'OpenchannelInteractionId':_0x3572e3['id'],'UserId':_0x36a1a8[_0xa6cf('0x59')]['id'],'ContactId':_0x196ca9['id']}))['then'](function(_0x4f506a){_0x3572e3[_0xa6cf('0xbd')][_0xa6cf('0xbb')]=[];_0x3572e3['dataValues'][_0xa6cf('0xbb')][_0xa6cf('0x96')](_0x4f506a[_0xa6cf('0xbd')]);return _0x3572e3;});});}})['then'](respondWithResult(_0x120fd1,null))['catch'](handleError(_0x120fd1,null));};