ab0a25da31913056b5167d28ef2d8c38b70fdccf
[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 _0x4ed5=['user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','find','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','Disposition','findOne','nolimit','pick','OpenchannelAccountId','includeAll','findAll','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','notify','openchannel','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','ListId','isNil','from','from\x20is\x20mandatory','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','DESC','Applications','account','list','applications','priority','asc','contact','firstName','lastName','threadId','externalUrl','OpenchannelInteraction','ContactId','spread','messageId','interaction','created','push','OpenchannelMessage','UserId','User','unshift','agent','waitForTheAssignedAgent','*,*,*,*','forcedOwnership','Start','startRouting','EventManager','addApplications','sequelize','transaction','OpenchannelApplication','bulkCreate','findAndCountAll','getApplications','Contact','Owner','fullname','Tag','Tags','color','tag','addAgents','emit','userOpenchannelAccount:save','removeAgents','isArray','userOpenchannelAccount:remove','out','Messages','dataValues','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','defaults','localhost','socket.io-emitter','redis','./openchannelAccount.socket','register','client','http','test','The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.','request','then','info','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','OpenchannelAccount,\x20%s,\x20%s,\x20%s','error','code','message','result','catch','sendStatus','end','status','json','count','offset','limit','set','Content-Range','apply','save','update','destroy','get','UserProfileResource','stack','name','send','index','Pause','mandatoryDispositionPause','OpenchannelAccount','rawAttributes','model','query','keys','filters','attributes','fields','length','hasOwnProperty','order','sort','where','filter','merge','map','key','VIRTUAL','field','include','rows','params','intersection','options','create','body'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x4ed5,0x119));var _0x54ed=function(_0x485a10,_0x17006f){_0x485a10=_0x485a10-0x0;var _0x46e53b=_0x4ed5[_0x485a10];return _0x46e53b;};'use strict';var pdf=require(_0x54ed('0x0'));var emlformat=require(_0x54ed('0x1'));var rimraf=require(_0x54ed('0x2'));var zipdir=require(_0x54ed('0x3'));var jsonpatch=require(_0x54ed('0x4'));var rp=require(_0x54ed('0x5'));var moment=require(_0x54ed('0x6'));var BPromise=require('bluebird');var Mustache=require(_0x54ed('0x7'));var util=require('util');var path=require(_0x54ed('0x8'));var sox=require(_0x54ed('0x9'));var csv=require(_0x54ed('0xa'));var ejs=require(_0x54ed('0xb'));var fs=require('fs');var _=require(_0x54ed('0xc'));var squel=require(_0x54ed('0xd'));var crypto=require(_0x54ed('0xe'));var jsforce=require(_0x54ed('0xf'));var deskjs=require('desk.js');var toCsv=require(_0x54ed('0xa'));var querystring=require(_0x54ed('0x10'));var Papa=require(_0x54ed('0x11'));var Redis=require(_0x54ed('0x12'));var authService=require(_0x54ed('0x13'));var qs=require(_0x54ed('0x14'));var hardwareService=require(_0x54ed('0x15'));var logger=require(_0x54ed('0x16'))(_0x54ed('0x17'));var utils=require(_0x54ed('0x18'));var config=require(_0x54ed('0x19'));var db=require(_0x54ed('0x1a'))['db'];config['redis']=_[_0x54ed('0x1b')](config['redis'],{'host':_0x54ed('0x1c'),'port':0x18eb});var socket=require(_0x54ed('0x1d'))(new Redis(config[_0x54ed('0x1e')]));require(_0x54ed('0x1f'))[_0x54ed('0x20')](socket);var jayson=require('jayson/promise');var client=jayson[_0x54ed('0x21')][_0x54ed('0x22')]({'port':0x232c});var client9002=jayson[_0x54ed('0x21')][_0x54ed('0x22')]({'port':0x232a});function checkPasswordPattern(_0x3760f4,_0x4e514a,_0x18bc70){if(_0x18bc70){var _0x15cac4=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x15cac4[_0x54ed('0x23')](_0x4e514a)){return _0x3760f4;}else{throw new Error(_0x54ed('0x24'));}}else{return _0x3760f4;}}function respondWithRpcPromise(_0x10f1da,_0x523e8f,_0x11fed2,_0x536a03){return new BPromise(function(_0x5a57ce,_0x2a4941){var _0x459a6a=_0x536a03||client;return _0x459a6a[_0x54ed('0x25')](_0x10f1da,_0x11fed2)[_0x54ed('0x26')](function(_0x3569c8){logger[_0x54ed('0x27')](_0x54ed('0x28'),_0x523e8f,_0x54ed('0x29'));logger['debug'](_0x54ed('0x2a'),_0x523e8f,'request\x20sent',JSON['stringify'](_0x3569c8));if(_0x3569c8[_0x54ed('0x2b')]){if(_0x3569c8[_0x54ed('0x2b')][_0x54ed('0x2c')]===0x1f4){logger[_0x54ed('0x2b')](_0x54ed('0x28'),_0x523e8f,_0x3569c8[_0x54ed('0x2b')][_0x54ed('0x2d')]);return _0x2a4941(_0x3569c8['error']['message']);}logger['error'](_0x54ed('0x28'),_0x523e8f,_0x3569c8['error']['message']);return _0x5a57ce(_0x3569c8[_0x54ed('0x2b')]['message']);}else{logger[_0x54ed('0x27')](_0x54ed('0x28'),_0x523e8f,'request\x20sent');_0x5a57ce(_0x3569c8[_0x54ed('0x2e')]['message']);}})[_0x54ed('0x2f')](function(_0x131219){logger[_0x54ed('0x2b')](_0x54ed('0x28'),_0x523e8f,_0x131219);_0x2a4941(_0x131219);});});}function respondWithStatusCode(_0x556230,_0x562f24){_0x562f24=_0x562f24||0xcc;return function(_0x38c646){if(_0x38c646){return _0x556230[_0x54ed('0x30')](_0x562f24);}return _0x556230['status'](_0x562f24)[_0x54ed('0x31')]();};}function respondWithResult(_0x32dc09,_0x1c43b9){_0x1c43b9=_0x1c43b9||0xc8;return function(_0x4d7003){if(_0x4d7003){return _0x32dc09[_0x54ed('0x32')](_0x1c43b9)[_0x54ed('0x33')](_0x4d7003);}};}function respondWithFilteredResult(_0x1c9dc8,_0x23e177){return function(_0x2e43c2){if(_0x2e43c2){var _0x5a5c6d=_0x2e43c2[_0x54ed('0x34')],_0x2c8074=_0x23e177['offset'],_0x5b3cc9=_0x23e177[_0x54ed('0x35')]+_0x23e177[_0x54ed('0x36')],_0x36e6c1;if(_0x5b3cc9>=_0x5a5c6d){_0x5b3cc9=_0x5a5c6d;_0x36e6c1=0xc8;}else{_0x36e6c1=0xce;}_0x1c9dc8[_0x54ed('0x32')](_0x36e6c1);return _0x1c9dc8[_0x54ed('0x37')](_0x54ed('0x38'),_0x2c8074+'-'+_0x5b3cc9+'/'+_0x5a5c6d)[_0x54ed('0x33')](_0x2e43c2);}return null;};}function patchUpdates(_0x4519a0){return function(_0x82f230){try{jsonpatch[_0x54ed('0x39')](_0x82f230,_0x4519a0,!![]);}catch(_0x35343e){return BPromise['reject'](_0x35343e);}return _0x82f230[_0x54ed('0x3a')]();};}function saveUpdates(_0x483581,_0x51b16d){return function(_0x54e0fe){if(_0x54e0fe){return _0x54e0fe[_0x54ed('0x3b')](_0x483581)[_0x54ed('0x26')](function(_0x488ee8){return _0x488ee8;});}return null;};}function removeEntity(_0x36f64a,_0x3ee3af){return function(_0x5eb6a5){if(_0x5eb6a5){return _0x5eb6a5[_0x54ed('0x3c')]()['then'](function(){var _0x168451=_0x5eb6a5[_0x54ed('0x3d')]({'plain':!![]});var _0x3c925d='OpenchannelAccounts';return db[_0x54ed('0x3e')]['destroy']({'where':{'type':_0x3c925d,'resourceId':_0x168451['id']}})[_0x54ed('0x26')](function(){return _0x5eb6a5;});})[_0x54ed('0x26')](function(){_0x36f64a[_0x54ed('0x32')](0xcc)[_0x54ed('0x31')]();});}};}function handleEntityNotFound(_0x10b463,_0x112b80){return function(_0x34d1a7){if(!_0x34d1a7){_0x10b463[_0x54ed('0x30')](0x194);}return _0x34d1a7;};}function handleError(_0x384325,_0x17a4fe){_0x17a4fe=_0x17a4fe||0x1f4;return function(_0x3eb5bf){logger['error'](_0x3eb5bf[_0x54ed('0x3f')]);if(_0x3eb5bf[_0x54ed('0x40')]){delete _0x3eb5bf['name'];}_0x384325['status'](_0x17a4fe)[_0x54ed('0x41')](_0x3eb5bf);};}exports[_0x54ed('0x42')]=function(_0x449e55,_0x3ecd7a){var _0x19cf86={'include':[{'model':db[_0x54ed('0x43')],'as':_0x54ed('0x44')}]},_0x36dd70={},_0x2f1b08={'count':0x0,'rows':[]};var _0x5a4c07=db[_0x54ed('0x45')][_0x54ed('0x46')];_0x36dd70[_0x54ed('0x47')]=_['keys'](_0x5a4c07);_0x36dd70[_0x54ed('0x48')]=_[_0x54ed('0x49')](_0x449e55[_0x54ed('0x48')]);_0x36dd70[_0x54ed('0x4a')]=_['intersection'](_0x36dd70['model'],_0x36dd70[_0x54ed('0x48')]);_0x19cf86[_0x54ed('0x4b')]=_['intersection'](_0x36dd70['model'],qs[_0x54ed('0x4c')](_0x449e55['query'][_0x54ed('0x4c')]));_0x19cf86[_0x54ed('0x4b')]=_0x19cf86['attributes'][_0x54ed('0x4d')]?_0x19cf86[_0x54ed('0x4b')]:_0x36dd70[_0x54ed('0x47')];if(!_0x449e55[_0x54ed('0x48')][_0x54ed('0x4e')]('nolimit')){_0x19cf86['limit']=qs[_0x54ed('0x36')](_0x449e55[_0x54ed('0x48')]['limit']);_0x19cf86[_0x54ed('0x35')]=qs[_0x54ed('0x35')](_0x449e55[_0x54ed('0x48')]['offset']);}_0x19cf86[_0x54ed('0x4f')]=qs[_0x54ed('0x50')](_0x449e55[_0x54ed('0x48')][_0x54ed('0x50')]);_0x19cf86[_0x54ed('0x51')]=qs[_0x54ed('0x4a')](_['pick'](_0x449e55[_0x54ed('0x48')],_0x36dd70[_0x54ed('0x4a')]));if(_0x449e55[_0x54ed('0x48')][_0x54ed('0x52')]){_0x19cf86[_0x54ed('0x51')]=_[_0x54ed('0x53')](_0x19cf86[_0x54ed('0x51')],{'$or':_[_0x54ed('0x54')](_0x5a4c07,function(_0x88cb98){if(_0x88cb98['type'][_0x54ed('0x55')]!==_0x54ed('0x56')){var _0x179f22={};_0x179f22[_0x88cb98[_0x54ed('0x57')]]={'$like':'%'+_0x449e55[_0x54ed('0x48')][_0x54ed('0x52')]+'%'};return _0x179f22;}})});}_0x19cf86=_[_0x54ed('0x53')]({},_0x19cf86,_0x449e55['options']);var _0x3c4cc9={'where':_0x19cf86[_0x54ed('0x51')]};return db[_0x54ed('0x45')]['count'](_0x3c4cc9)['then'](function(_0x29c2fd){_0x2f1b08[_0x54ed('0x34')]=_0x29c2fd;if(_0x449e55[_0x54ed('0x48')]['includeAll']){_0x19cf86[_0x54ed('0x58')]=[{'all':!![]}];}return db[_0x54ed('0x45')]['findAll'](_0x19cf86);})['then'](function(_0x1a2ad9){_0x2f1b08[_0x54ed('0x59')]=_0x1a2ad9;return _0x2f1b08;})[_0x54ed('0x26')](respondWithFilteredResult(_0x3ecd7a,_0x19cf86))[_0x54ed('0x2f')](handleError(_0x3ecd7a,null));};exports['show']=function(_0x4cc0a8,_0x1a30ae){var _0x59073e={'raw':![],'where':{'id':_0x4cc0a8[_0x54ed('0x5a')]['id']},'include':[{'model':db[_0x54ed('0x43')],'as':_0x54ed('0x44')}]},_0x3f117d={};_0x3f117d['model']=_[_0x54ed('0x49')](db['OpenchannelAccount'][_0x54ed('0x46')]);_0x3f117d[_0x54ed('0x48')]=_[_0x54ed('0x49')](_0x4cc0a8['query']);_0x3f117d[_0x54ed('0x4a')]=_[_0x54ed('0x5b')](_0x3f117d['model'],_0x3f117d[_0x54ed('0x48')]);_0x59073e[_0x54ed('0x4b')]=_[_0x54ed('0x5b')](_0x3f117d['model'],qs[_0x54ed('0x4c')](_0x4cc0a8[_0x54ed('0x48')][_0x54ed('0x4c')]));_0x59073e['attributes']=_0x59073e['attributes'][_0x54ed('0x4d')]?_0x59073e[_0x54ed('0x4b')]:_0x3f117d[_0x54ed('0x47')];if(_0x4cc0a8['query']['includeAll']){_0x59073e[_0x54ed('0x58')]=[{'all':!![]}];}_0x59073e=_[_0x54ed('0x53')]({},_0x59073e,_0x4cc0a8[_0x54ed('0x5c')]);return db[_0x54ed('0x45')]['find'](_0x59073e)['then'](handleEntityNotFound(_0x1a30ae,null))[_0x54ed('0x26')](respondWithResult(_0x1a30ae,null))[_0x54ed('0x2f')](handleError(_0x1a30ae,null));};exports[_0x54ed('0x5d')]=function(_0x5b61ae,_0x2d335e){return db[_0x54ed('0x45')][_0x54ed('0x5d')](_0x5b61ae[_0x54ed('0x5e')],{})[_0x54ed('0x26')](function(_0xaad550){var _0x46d9dd=_0x5b61ae[_0x54ed('0x5f')]['get']({'plain':!![]});if(!_0x46d9dd)throw new Error(_0x54ed('0x60'));if(_0x46d9dd[_0x54ed('0x61')]===_0x54ed('0x5f')){var _0x5b9ec0=_0xaad550[_0x54ed('0x3d')]({'plain':!![]});var _0x284143='OpenchannelAccounts';return db['UserProfileSection'][_0x54ed('0x62')]({'where':{'name':_0x284143,'userProfileId':_0x46d9dd['userProfileId']},'raw':!![]})[_0x54ed('0x26')](function(_0x4db237){if(_0x4db237&&_0x4db237['autoAssociation']===0x0){return db[_0x54ed('0x3e')][_0x54ed('0x5d')]({'name':_0x5b9ec0['name'],'resourceId':_0x5b9ec0['id'],'type':_0x4db237[_0x54ed('0x40')],'sectionId':_0x4db237['id']},{})[_0x54ed('0x26')](function(){return _0xaad550;});}else{return _0xaad550;}})[_0x54ed('0x2f')](function(_0x2f17d5){logger['error'](_0x54ed('0x63'),_0x2f17d5);throw _0x2f17d5;});}return _0xaad550;})[_0x54ed('0x26')](respondWithResult(_0x2d335e,0xc9))['catch'](handleError(_0x2d335e,null));};exports['update']=function(_0x256152,_0xe5bf1b){if(_0x256152['body']['id']){delete _0x256152['body']['id'];}return db[_0x54ed('0x45')][_0x54ed('0x62')]({'where':{'id':_0x256152[_0x54ed('0x5a')]['id']},'include':[{'model':db[_0x54ed('0x43')],'as':'mandatoryDispositionPause'}]})[_0x54ed('0x26')](handleEntityNotFound(_0xe5bf1b,null))[_0x54ed('0x26')](saveUpdates(_0x256152[_0x54ed('0x5e')],null))[_0x54ed('0x26')](respondWithResult(_0xe5bf1b,null))['catch'](handleError(_0xe5bf1b,null));};exports[_0x54ed('0x3c')]=function(_0x53354a,_0x1bcf94){return db[_0x54ed('0x45')]['find']({'where':{'id':_0x53354a[_0x54ed('0x5a')]['id']}})['then'](handleEntityNotFound(_0x1bcf94,null))[_0x54ed('0x26')](removeEntity(_0x1bcf94,null))['catch'](handleError(_0x1bcf94,null));};exports[_0x54ed('0x64')]=function(_0x25097e,_0x5b0613){return db[_0x54ed('0x45')][_0x54ed('0x64')]()[_0x54ed('0x26')](respondWithResult(_0x5b0613,null))['catch'](handleError(_0x5b0613,null));};exports['addDisposition']=function(_0x5ec785,_0x3f9205,_0x2c3b02){if(_0x5ec785[_0x54ed('0x5e')]['id']){delete _0x5ec785[_0x54ed('0x5e')]['id'];}return db[_0x54ed('0x45')]['find']({'where':{'id':_0x5ec785[_0x54ed('0x5a')]['id']}})[_0x54ed('0x26')](handleEntityNotFound(_0x3f9205,null))[_0x54ed('0x26')](function(_0x220489){if(_0x220489){_0x5ec785['body']['OpnechannelAccountId']=_0x220489['id'];return db[_0x54ed('0x65')][_0x54ed('0x5d')](_0x5ec785['body']);}})['then'](respondWithResult(_0x3f9205,null))[_0x54ed('0x2f')](handleError(_0x3f9205,null));};exports['getDispositions']=function(_0x4248c9,_0xf94f70,_0x52c5ed){var _0x586323={'raw':![],'where':{}};var _0x4aa1bc={};var _0x37abad={'count':0x0,'rows':[]};return db[_0x54ed('0x45')][_0x54ed('0x66')]({'where':{'id':_0x4248c9[_0x54ed('0x5a')]['id']}})[_0x54ed('0x26')](handleEntityNotFound(_0xf94f70,null))[_0x54ed('0x26')](function(_0x3667fc){if(_0x3667fc){_0x4aa1bc['model']=_['keys'](db[_0x54ed('0x65')][_0x54ed('0x46')]);_0x4aa1bc[_0x54ed('0x48')]=_[_0x54ed('0x49')](_0x4248c9['query']);_0x4aa1bc[_0x54ed('0x4a')]=_[_0x54ed('0x5b')](_0x4aa1bc['model'],_0x4aa1bc['query']);_0x586323[_0x54ed('0x4b')]=_[_0x54ed('0x5b')](_0x4aa1bc[_0x54ed('0x47')],qs[_0x54ed('0x4c')](_0x4248c9[_0x54ed('0x48')]['fields']));_0x586323[_0x54ed('0x4b')]=_0x586323['attributes'][_0x54ed('0x4d')]?_0x586323['attributes']:_0x4aa1bc[_0x54ed('0x47')];if(!_0x4248c9['query'][_0x54ed('0x4e')](_0x54ed('0x67'))){_0x586323[_0x54ed('0x36')]=qs[_0x54ed('0x36')](_0x4248c9['query']['limit']);_0x586323[_0x54ed('0x35')]=qs[_0x54ed('0x35')](_0x4248c9[_0x54ed('0x48')][_0x54ed('0x35')]);}_0x586323[_0x54ed('0x4f')]=qs[_0x54ed('0x50')](_0x4248c9[_0x54ed('0x48')][_0x54ed('0x50')]);_0x586323[_0x54ed('0x51')]=qs[_0x54ed('0x4a')](_[_0x54ed('0x68')](_0x4248c9[_0x54ed('0x48')],_0x4aa1bc[_0x54ed('0x4a')]));_0x586323[_0x54ed('0x51')][_0x54ed('0x69')]=_0x3667fc['id'];if(_0x4248c9[_0x54ed('0x48')][_0x54ed('0x52')]){_0x586323[_0x54ed('0x51')]=_[_0x54ed('0x53')](_0x586323[_0x54ed('0x51')],{'$or':_['map'](_0x586323['attributes'],function(_0x335508){var _0x4c5cc0={};_0x4c5cc0[_0x335508]={'$like':'%'+_0x4248c9[_0x54ed('0x48')][_0x54ed('0x52')]+'%'};return _0x4c5cc0;})});}_0x586323=_['merge']({},_0x586323,_0x4248c9['options']);return db[_0x54ed('0x65')][_0x54ed('0x34')]({'where':_0x586323[_0x54ed('0x51')]})[_0x54ed('0x26')](function(_0x2c60a8){_0x37abad[_0x54ed('0x34')]=_0x2c60a8;if(_0x4248c9[_0x54ed('0x48')][_0x54ed('0x6a')]){_0x586323['include']=[{'all':!![]}];}return db['Disposition'][_0x54ed('0x6b')](_0x586323);})[_0x54ed('0x26')](function(_0x4756cd){_0x37abad[_0x54ed('0x59')]=_0x4756cd;return _0x37abad;});}})[_0x54ed('0x26')](respondWithFilteredResult(_0xf94f70,_0x586323))[_0x54ed('0x2f')](handleError(_0xf94f70,null));};exports[_0x54ed('0x6c')]=function(_0x3952f3,_0x5a416d,_0x393983){return db[_0x54ed('0x45')][_0x54ed('0x62')]({'where':{'id':_0x3952f3[_0x54ed('0x5a')]['id']}})['then'](handleEntityNotFound(_0x5a416d,null))['then'](function(_0x19dc53){if(_0x19dc53){return _0x19dc53[_0x54ed('0x6c')](_0x3952f3[_0x54ed('0x48')][_0x54ed('0x6d')]);}})[_0x54ed('0x26')](respondWithStatusCode(_0x5a416d,null))['catch'](handleError(_0x5a416d,null));};exports[_0x54ed('0x6e')]=function(_0x4b25f3,_0x43a624,_0x2f953b){if(_0x4b25f3[_0x54ed('0x5e')]['id']){delete _0x4b25f3[_0x54ed('0x5e')]['id'];}return db[_0x54ed('0x45')][_0x54ed('0x62')]({'where':{'id':_0x4b25f3[_0x54ed('0x5a')]['id']}})['then'](handleEntityNotFound(_0x43a624,null))[_0x54ed('0x26')](function(_0x293b1e){if(_0x293b1e){_0x4b25f3['body'][_0x54ed('0x69')]=_0x293b1e['id'];return db[_0x54ed('0x6f')][_0x54ed('0x5d')](_0x4b25f3[_0x54ed('0x5e')]);}})[_0x54ed('0x26')](respondWithResult(_0x43a624,null))[_0x54ed('0x2f')](handleError(_0x43a624,null));};exports[_0x54ed('0x70')]=function(_0x513eb1,_0x44f124,_0xdd0d1b){var _0x36c986={'raw':![],'where':{}};var _0x2c54f9={};var _0x553061={'count':0x0,'rows':[]};return db[_0x54ed('0x45')][_0x54ed('0x66')]({'where':{'id':_0x513eb1[_0x54ed('0x5a')]['id']}})['then'](handleEntityNotFound(_0x44f124,null))['then'](function(_0x22e23a){if(_0x22e23a){_0x2c54f9['model']=_[_0x54ed('0x49')](db[_0x54ed('0x6f')][_0x54ed('0x46')]);_0x2c54f9[_0x54ed('0x48')]=_[_0x54ed('0x49')](_0x513eb1[_0x54ed('0x48')]);_0x2c54f9['filters']=_['intersection'](_0x2c54f9[_0x54ed('0x47')],_0x2c54f9[_0x54ed('0x48')]);_0x36c986[_0x54ed('0x4b')]=_[_0x54ed('0x5b')](_0x2c54f9[_0x54ed('0x47')],qs[_0x54ed('0x4c')](_0x513eb1[_0x54ed('0x48')][_0x54ed('0x4c')]));_0x36c986[_0x54ed('0x4b')]=_0x36c986[_0x54ed('0x4b')]['length']?_0x36c986[_0x54ed('0x4b')]:_0x2c54f9[_0x54ed('0x47')];if(!_0x513eb1[_0x54ed('0x48')][_0x54ed('0x4e')](_0x54ed('0x67'))){_0x36c986['limit']=qs[_0x54ed('0x36')](_0x513eb1['query']['limit']);_0x36c986[_0x54ed('0x35')]=qs['offset'](_0x513eb1['query'][_0x54ed('0x35')]);}_0x36c986[_0x54ed('0x4f')]=qs[_0x54ed('0x50')](_0x513eb1[_0x54ed('0x48')][_0x54ed('0x50')]);_0x36c986[_0x54ed('0x51')]=qs[_0x54ed('0x4a')](_[_0x54ed('0x68')](_0x513eb1[_0x54ed('0x48')],_0x2c54f9[_0x54ed('0x4a')]));_0x36c986['where'][_0x54ed('0x69')]=_0x22e23a['id'];if(_0x513eb1[_0x54ed('0x48')][_0x54ed('0x52')]){_0x36c986[_0x54ed('0x51')]=_[_0x54ed('0x53')](_0x36c986['where'],{'$or':_[_0x54ed('0x54')](_0x36c986[_0x54ed('0x4b')],function(_0x3937da){var _0x4d3b5c={};_0x4d3b5c[_0x3937da]={'$like':'%'+_0x513eb1[_0x54ed('0x48')][_0x54ed('0x52')]+'%'};return _0x4d3b5c;})});}_0x36c986=_['merge']({},_0x36c986,_0x513eb1[_0x54ed('0x5c')]);return db[_0x54ed('0x6f')]['count']({'where':_0x36c986[_0x54ed('0x51')]})[_0x54ed('0x26')](function(_0xc0ace2){_0x553061[_0x54ed('0x34')]=_0xc0ace2;if(_0x513eb1['query'][_0x54ed('0x6a')]){_0x36c986[_0x54ed('0x58')]=[{'all':!![]}];}return db[_0x54ed('0x6f')]['findAll'](_0x36c986);})[_0x54ed('0x26')](function(_0x1b9368){_0x553061[_0x54ed('0x59')]=_0x1b9368;return _0x553061;});}})[_0x54ed('0x26')](respondWithFilteredResult(_0x44f124,_0x36c986))[_0x54ed('0x2f')](handleError(_0x44f124,null));};exports[_0x54ed('0x71')]=function(_0x1aaf0f,_0x5e3c15,_0x1ea497){return db[_0x54ed('0x45')][_0x54ed('0x62')]({'where':{'id':_0x1aaf0f[_0x54ed('0x5a')]['id']}})[_0x54ed('0x26')](handleEntityNotFound(_0x5e3c15,null))[_0x54ed('0x26')](function(_0x3e1cf1){if(_0x3e1cf1){return _0x3e1cf1[_0x54ed('0x71')](_0x1aaf0f['query'][_0x54ed('0x6d')]);}})[_0x54ed('0x26')](respondWithStatusCode(_0x5e3c15,null))[_0x54ed('0x2f')](handleError(_0x5e3c15,null));};exports[_0x54ed('0x72')]=function(_0x1382fd,_0x3817a8,_0x19a99b){var _0x1e88e6={'body':_0x1382fd[_0x54ed('0x5e')],'channel':_0x54ed('0x73')};var _0x35c8b5=[];var _0x297350=[];var _0xae95cb={};var _0x3774d4=![];return db[_0x54ed('0x74')][_0x54ed('0x64')]()[_0x54ed('0x26')](function(_0x184045){if(!_0x184045){throw new db[(_0x54ed('0x75'))][(_0x54ed('0x76'))](_0x54ed('0x77'));}_0x35c8b5=_[_0x54ed('0x78')](_['keys'](_0x184045),[_0x54ed('0x79'),_0x54ed('0x7a')]);_0x297350=_[_0x54ed('0x78')](_[_0x54ed('0x49')](_0x184045),['createdAt',_0x54ed('0x7a'),'CompanyId',_0x54ed('0x7b')]);if(_0x1382fd[_0x54ed('0x5e')]['id']){delete _0x1382fd[_0x54ed('0x5e')]['id'];}if(_[_0x54ed('0x7c')](_0x1382fd[_0x54ed('0x5e')][_0x54ed('0x7d')])){throw new db[(_0x54ed('0x75'))][(_0x54ed('0x76'))](_0x54ed('0x7e'));}if(_[_0x54ed('0x7c')](_0x1382fd[_0x54ed('0x5e')]['body'])||_0x1382fd[_0x54ed('0x5e')][_0x54ed('0x5e')]===''){throw new db[(_0x54ed('0x75'))][(_0x54ed('0x76'))](_0x54ed('0x7f'));}if(_[_0x54ed('0x7c')](_0x1382fd[_0x54ed('0x5e')][_0x54ed('0x80')])){throw new db[(_0x54ed('0x75'))][(_0x54ed('0x76'))](_0x54ed('0x81')+_0x297350);}if(!_[_0x54ed('0x82')](_0x297350,_0x1382fd[_0x54ed('0x5e')][_0x54ed('0x80')])){throw new db['Sequelize'][(_0x54ed('0x76'))](_0x54ed('0x83')+_0x297350);}_0xae95cb[_0x1382fd[_0x54ed('0x5e')][_0x54ed('0x80')]]=_0x1382fd[_0x54ed('0x5e')][_0x54ed('0x7d')];})[_0x54ed('0x26')](function(){return db[_0x54ed('0x45')][_0x54ed('0x62')]({'where':{'id':_0x1382fd['params']['id']},'include':[{'model':db[_0x54ed('0x84')],'as':_0x54ed('0x85'),'include':[{'model':db[_0x54ed('0x74')],'as':_0x54ed('0x86'),'where':_0xae95cb,'limit':0x1,'order':[[_0x54ed('0x7a'),_0x54ed('0x87')]]}]},{'model':db['OpenchannelApplication'],'as':_0x54ed('0x88')}]});})[_0x54ed('0x26')](handleEntityNotFound(_0x3817a8,null))[_0x54ed('0x26')](function(_0x1f3cbb){if(_0x1f3cbb&&_0x1f3cbb['List']){_0x1e88e6[_0x54ed('0x89')]=_0x1f3cbb;_0x1e88e6['applications']=_0x1f3cbb['Applications'];_0x1e88e6[_0x54ed('0x8a')]=_0x1f3cbb['List'];_0x1e88e6[_0x54ed('0x8b')]=_['orderBy'](_0x1e88e6[_0x54ed('0x8b')],[_0x54ed('0x8c')],[_0x54ed('0x8d')]);if(_0x1e88e6['account']['Applications']){delete _0x1e88e6['account'][_0x54ed('0x88')];}if(_0x1e88e6[_0x54ed('0x89')][_0x54ed('0x85')]&&_0x1e88e6[_0x54ed('0x89')][_0x54ed('0x85')][_0x54ed('0x86')][_0x54ed('0x4d')]){return _0x1e88e6[_0x54ed('0x89')][_0x54ed('0x85')][_0x54ed('0x86')][0x0];}var _0x2f6bf5=_[_0x54ed('0x1b')](_0x1382fd[_0x54ed('0x5e')],{'firstName':_0x1382fd[_0x54ed('0x5e')]['from'],'ListId':_0x1f3cbb['ListId']});_0x2f6bf5[_0x1382fd[_0x54ed('0x5e')][_0x54ed('0x80')]]=_0x1382fd['body'][_0x54ed('0x7d')];return db[_0x54ed('0x74')][_0x54ed('0x5d')](_0x2f6bf5,{'fields':_0x35c8b5,'raw':!![]});}})[_0x54ed('0x26')](handleEntityNotFound(_0x3817a8,null))[_0x54ed('0x26')](function(_0x128dbc){_0x1e88e6[_0x54ed('0x8e')]=_0x128dbc;if(_0x128dbc){var _0x2dd80c={'ContactId':_0x128dbc['id'],'OpenchannelAccountId':_0x1382fd[_0x54ed('0x5a')]['id'],'from':(_0x128dbc[_0x54ed('0x8f')]||'')+'\x20'+(_0x128dbc[_0x54ed('0x90')]||'')};var _0x473028={'OpenchannelAccountId':_0x1382fd['params']['id'],'closed':![]};if(_0x1382fd[_0x54ed('0x5e')][_0x54ed('0x91')]){_0x473028[_0x54ed('0x91')]=_0x1382fd[_0x54ed('0x5e')]['threadId'];return db['OpenchannelInteraction'][_0x54ed('0x62')]({'where':_0x473028})[_0x54ed('0x26')](function(_0x20eab8){if(_0x20eab8){return[_0x20eab8,![]];}_0x2dd80c[_0x54ed('0x91')]=_0x1382fd[_0x54ed('0x5e')]['threadId'];_0x2dd80c[_0x54ed('0x92')]=_0x1382fd['body'][_0x54ed('0x92')];return db[_0x54ed('0x93')][_0x54ed('0x5d')](_0x2dd80c)[_0x54ed('0x26')](function(_0x392eef){return[_0x392eef,!![]];});});}else{_0x473028[_0x54ed('0x91')]=null;}_0x473028[_0x54ed('0x94')]=_0x128dbc['id'];return db[_0x54ed('0x93')][_0x54ed('0x62')]({'where':_0x473028})[_0x54ed('0x26')](function(_0x266b47){if(_0x266b47){return[_0x266b47,![]];}return db['OpenchannelInteraction'][_0x54ed('0x5d')](_0x2dd80c)[_0x54ed('0x26')](function(_0x4d4f01){return[_0x4d4f01,!![]];});});}})[_0x54ed('0x95')](function(_0x412e49,_0x24d4cc){if(_0x412e49){_0x3774d4=_0x24d4cc;if(!_0x24d4cc){var _0xbfccf0={'from':(_0x1e88e6[_0x54ed('0x8e')][_0x54ed('0x8f')]||'')+'\x20'+(_0x1e88e6['contact'][_0x54ed('0x90')]||'')};if(_0x1382fd[_0x54ed('0x5e')][_0x54ed('0x91')]&&_0x1382fd[_0x54ed('0x5e')][_0x54ed('0x96')]&&_0x1382fd[_0x54ed('0x5e')][_0x54ed('0x91')]!=_0x1382fd[_0x54ed('0x5e')][_0x54ed('0x96')]){_0xbfccf0['threadId']=_0x1382fd[_0x54ed('0x5e')][_0x54ed('0x96')];}return _0x412e49[_0x54ed('0x3b')](_0xbfccf0);}else{return _0x412e49;}}})[_0x54ed('0x26')](function(_0x1149ec){_0x1e88e6[_0x54ed('0x97')]=_0x1149ec[_0x54ed('0x3d')]({'plain':!![]});_0x1e88e6[_0x54ed('0x97')][_0x54ed('0x98')]=_0x3774d4;if(_0x1e88e6[_0x54ed('0x97')][_0x54ed('0x98')]){if(_0x1e88e6[_0x54ed('0x89')]['autoclose']){_0x1e88e6[_0x54ed('0x8b')][_0x54ed('0x99')]({'id':0x0,'priority':_0x1e88e6[_0x54ed('0x8b')][_0x54ed('0x4d')]+0x1,'app':'close','appdata':'unmanaged','interval':'*,*,*,*'});}}return db[_0x54ed('0x9a')][_0x54ed('0x5d')]({'body':_0x1382fd[_0x54ed('0x5e')][_0x54ed('0x5e')],'OpenchannelAccountId':_0x1382fd[_0x54ed('0x5a')]['id'],'OpenchannelInteractionId':_0x1149ec['id'],'direction':'in','ContactId':_0x1e88e6[_0x54ed('0x8e')]['id'],'AttachmentId':_0x1382fd[_0x54ed('0x5e')]['AttachmentId']});})[_0x54ed('0x26')](function(_0x5059e1){_0x1e88e6[_0x54ed('0x2d')]=_0x5059e1;if(_0x1e88e6[_0x54ed('0x97')][_0x54ed('0x9b')]){return db[_0x54ed('0x9c')][_0x54ed('0x62')]({'attributes':['id',_0x54ed('0x40')],'where':{'id':_0x1e88e6[_0x54ed('0x97')][_0x54ed('0x9b')]}})['then'](function(_0x1efd8c){if(_0x1efd8c){_0x1e88e6[_0x54ed('0x8b')][_0x54ed('0x9d')]({'id':0x0,'priority':0x0,'app':_0x54ed('0x9e'),'appdata':_0x1efd8c[_0x54ed('0x40')]+','+(_0x1e88e6[_0x54ed('0x89')][_0x54ed('0x9f')]||0xa),'interval':_0x54ed('0xa0')});_0x1e88e6[_0x54ed('0xa1')]=![];}return respondWithRpcPromise(_0x54ed('0xa2'),_0x54ed('0xa3'),_0x1e88e6);});}return respondWithRpcPromise('Start','startRouting',_0x1e88e6);})[_0x54ed('0x26')](function(_0x4e3eb4){respondWithRpcPromise(_0x54ed('0xa4'),'EventManager',{'event':_0x54ed('0x72'),'message':_0x4e3eb4},client9002);return _0x4e3eb4;})[_0x54ed('0x26')](respondWithResult(_0x3817a8,null))[_0x54ed('0x2f')](handleError(_0x3817a8,null));};exports[_0x54ed('0xa5')]=function(_0x23bca8,_0x2cca5a,_0x497a63){return db[_0x54ed('0x45')][_0x54ed('0x66')]({'where':{'id':_0x23bca8['params']['id']}})[_0x54ed('0x26')](handleEntityNotFound(_0x2cca5a,null))['then'](function(_0x114517){if(_0x114517){return db[_0x54ed('0xa6')][_0x54ed('0xa7')](function(_0x29337e){return db[_0x54ed('0xa8')][_0x54ed('0x3c')]({'where':{'OpenchannelAccountId':_0x23bca8['params']['id']},'transaction':_0x29337e})['then'](function(_0x492ad6){var _0x1b2061=_[_0x54ed('0x54')](_0x23bca8[_0x54ed('0x5e')],function(_0x37eb49){_0x37eb49['OpenchannelAccountId']=_0x23bca8[_0x54ed('0x5a')]['id'];return _0x37eb49;});return db[_0x54ed('0xa8')][_0x54ed('0xa9')](_0x1b2061,{'transaction':_0x29337e});});})[_0x54ed('0x26')](function(){return db['OpenchannelApplication'][_0x54ed('0xaa')]({'where':{'OpenchannelAccountId':_0x23bca8[_0x54ed('0x5a')]['id']},'order':_0x54ed('0x8c')});});}})[_0x54ed('0x26')](respondWithResult(_0x2cca5a,null))[_0x54ed('0x2f')](handleError(_0x2cca5a,null));};exports[_0x54ed('0xab')]=function(_0x27b3f6,_0x54754d,_0x379231){var _0x2fae20={};var _0x3347fe={};var _0xc32cb4;var _0x3b9aec;return db['OpenchannelAccount'][_0x54ed('0x66')]({'where':{'id':_0x27b3f6[_0x54ed('0x5a')]['id']}})['then'](handleEntityNotFound(_0x54754d,null))[_0x54ed('0x26')](function(_0x28240b){if(_0x28240b){_0xc32cb4=_0x28240b;_0x3347fe[_0x54ed('0x47')]=_[_0x54ed('0x49')](db[_0x54ed('0xa8')][_0x54ed('0x46')]);_0x3347fe[_0x54ed('0x48')]=_[_0x54ed('0x49')](_0x27b3f6['query']);_0x3347fe[_0x54ed('0x4a')]=_['intersection'](_0x3347fe[_0x54ed('0x47')],_0x3347fe[_0x54ed('0x48')]);_0x2fae20[_0x54ed('0x4b')]=_[_0x54ed('0x5b')](_0x3347fe['model'],qs['fields'](_0x27b3f6[_0x54ed('0x48')]['fields']));_0x2fae20[_0x54ed('0x4b')]=_0x2fae20[_0x54ed('0x4b')][_0x54ed('0x4d')]?_0x2fae20['attributes']:_0x3347fe[_0x54ed('0x47')];_0x2fae20[_0x54ed('0x4f')]=qs[_0x54ed('0x50')](_0x27b3f6['query']['sort']);_0x2fae20[_0x54ed('0x51')]=qs['filters'](_[_0x54ed('0x68')](_0x27b3f6[_0x54ed('0x48')],_0x3347fe['filters']));if(_0x27b3f6[_0x54ed('0x48')]['filter']){_0x2fae20[_0x54ed('0x51')]=_[_0x54ed('0x53')](_0x2fae20[_0x54ed('0x51')],{'$or':_[_0x54ed('0x54')](_0x2fae20['attributes'],function(_0x3e2354){var _0x46857b={};_0x46857b[_0x3e2354]={'$like':'%'+_0x27b3f6[_0x54ed('0x48')][_0x54ed('0x52')]+'%'};return _0x46857b;})});}_0x2fae20=_[_0x54ed('0x53')]({},_0x2fae20,_0x27b3f6['options']);return _0xc32cb4[_0x54ed('0xab')](_0x2fae20);}})[_0x54ed('0x26')](function(_0x6220e4){if(_0x6220e4){_0x3b9aec=_0x6220e4[_0x54ed('0x4d')];if(!_0x27b3f6[_0x54ed('0x48')][_0x54ed('0x4e')]('nolimit')){_0x2fae20[_0x54ed('0x36')]=qs[_0x54ed('0x36')](_0x27b3f6[_0x54ed('0x48')][_0x54ed('0x36')]);_0x2fae20['offset']=qs[_0x54ed('0x35')](_0x27b3f6[_0x54ed('0x48')][_0x54ed('0x35')]);}return _0xc32cb4['getApplications'](_0x2fae20);}})[_0x54ed('0x26')](function(_0x368ca1){if(_0x368ca1){return _0x368ca1?{'count':_0x3b9aec,'rows':_0x368ca1}:null;}})[_0x54ed('0x26')](respondWithResult(_0x54754d,null))[_0x54ed('0x2f')](handleError(_0x54754d,null));};exports['getInteractions']=function(_0x591c62,_0x476e87,_0x5a03d9){var _0x1e3752={'raw':![],'where':{}};var _0x1e6062={};var _0x41ba59={'count':0x0,'rows':[]};return db[_0x54ed('0x45')][_0x54ed('0x66')]({'where':{'id':_0x591c62[_0x54ed('0x5a')]['id']}})[_0x54ed('0x26')](handleEntityNotFound(_0x476e87,null))[_0x54ed('0x26')](function(_0x1e53ef){if(_0x1e53ef){_0x1e6062[_0x54ed('0x47')]=_[_0x54ed('0x49')](db[_0x54ed('0x93')][_0x54ed('0x46')]);_0x1e6062[_0x54ed('0x48')]=_[_0x54ed('0x49')](_0x591c62[_0x54ed('0x48')]);_0x1e6062[_0x54ed('0x4a')]=_['intersection'](_0x1e6062[_0x54ed('0x47')],_0x1e6062[_0x54ed('0x48')]);_0x1e3752[_0x54ed('0x4b')]=_[_0x54ed('0x5b')](_0x1e6062['model'],qs['fields'](_0x591c62[_0x54ed('0x48')][_0x54ed('0x4c')]));_0x1e3752[_0x54ed('0x4b')]=_0x1e3752[_0x54ed('0x4b')][_0x54ed('0x4d')]?_0x1e3752[_0x54ed('0x4b')]:_0x1e6062[_0x54ed('0x47')];if(!_0x591c62['query'][_0x54ed('0x4e')](_0x54ed('0x67'))){_0x1e3752['limit']=qs[_0x54ed('0x36')](_0x591c62[_0x54ed('0x48')][_0x54ed('0x36')]);_0x1e3752['offset']=qs[_0x54ed('0x35')](_0x591c62[_0x54ed('0x48')][_0x54ed('0x35')]);}_0x1e3752[_0x54ed('0x4f')]=qs[_0x54ed('0x50')](_0x591c62[_0x54ed('0x48')]['sort']);_0x1e3752[_0x54ed('0x51')]=qs['filters'](_['pick'](_0x591c62[_0x54ed('0x48')],_0x1e6062[_0x54ed('0x4a')]));_0x1e3752[_0x54ed('0x51')][_0x54ed('0x69')]=_0x1e53ef['id'];if(_0x591c62[_0x54ed('0x48')][_0x54ed('0x52')]){_0x1e3752['where']=_['merge'](_0x1e3752[_0x54ed('0x51')],{'$or':_[_0x54ed('0x54')](_0x1e3752['attributes'],function(_0x4bebb6){var _0x3c0c82={};_0x3c0c82[_0x4bebb6]={'$like':'%'+_0x591c62[_0x54ed('0x48')]['filter']+'%'};return _0x3c0c82;})});}_0x1e3752=_['merge']({},_0x1e3752,_0x591c62[_0x54ed('0x5c')]);return db[_0x54ed('0x93')][_0x54ed('0x34')]({'where':_0x1e3752[_0x54ed('0x51')]})[_0x54ed('0x26')](function(_0x309ff8){_0x41ba59['count']=_0x309ff8;if(_0x591c62['query'][_0x54ed('0x6a')]){_0x1e3752[_0x54ed('0x58')]=[{'model':db[_0x54ed('0x74')],'as':_0x54ed('0xac'),'required':![]},{'model':db[_0x54ed('0x9c')],'as':_0x54ed('0xad'),'attributes':[_0x54ed('0x40'),_0x54ed('0xae'),'internal'],'required':![]},{'model':db[_0x54ed('0xaf')],'as':_0x54ed('0xb0'),'attributes':['id',_0x54ed('0x40'),_0x54ed('0xb1')],'where':_0x591c62[_0x54ed('0x48')][_0x54ed('0xb2')]?{'id':_0x591c62[_0x54ed('0x48')][_0x54ed('0xb2')]}:undefined,'required':_0x591c62[_0x54ed('0x48')]['tag']?!![]:![]}];}return db[_0x54ed('0x93')][_0x54ed('0x6b')](_0x1e3752);})[_0x54ed('0x26')](function(_0x3848f1){_0x41ba59['rows']=_0x3848f1;return _0x41ba59;});}})['then'](respondWithFilteredResult(_0x476e87,_0x1e3752))[_0x54ed('0x2f')](handleError(_0x476e87,null));};exports[_0x54ed('0xb3')]=function(_0x347a70,_0x17ba7b,_0x5a0c00){return db['OpenchannelAccount'][_0x54ed('0x62')]({'where':{'id':_0x347a70['params']['id']}})['then'](handleEntityNotFound(_0x17ba7b,null))['then'](function(_0x4b9ab7){if(_0x4b9ab7){return _0x4b9ab7[_0x54ed('0xb3')](_0x347a70[_0x54ed('0x5e')][_0x54ed('0x6d')],_['omit'](_0x347a70[_0x54ed('0x5e')],[_0x54ed('0x6d'),'id'])||{})[_0x54ed('0x95')](function(_0x37b4f0){for(var _0x4e0a8f=0x0;_0x4e0a8f<_0x347a70[_0x54ed('0x5e')][_0x54ed('0x6d')][_0x54ed('0x4d')];_0x4e0a8f+=0x1){socket[_0x54ed('0xb4')](_0x54ed('0xb5'),{'UserId':_0x347a70[_0x54ed('0x5e')][_0x54ed('0x6d')][_0x4e0a8f],'OpenchannelAccountId':_0x347a70[_0x54ed('0x5a')]['id']});}return _0x37b4f0;});}})['then'](respondWithResult(_0x17ba7b,null))[_0x54ed('0x2f')](handleError(_0x17ba7b,null));};exports[_0x54ed('0xb6')]=function(_0x12be01,_0x45766d,_0x3247b8){return db[_0x54ed('0x45')][_0x54ed('0x62')]({'where':{'id':_0x12be01[_0x54ed('0x5a')]['id']}})[_0x54ed('0x26')](handleEntityNotFound(_0x45766d,null))[_0x54ed('0x26')](function(_0x1f5cd4){if(_0x1f5cd4){return _0x1f5cd4[_0x54ed('0xb6')](_0x12be01[_0x54ed('0x48')][_0x54ed('0x6d')])[_0x54ed('0x26')](function(){if(_[_0x54ed('0xb7')](_0x12be01[_0x54ed('0x48')][_0x54ed('0x6d')])){for(var _0x1bdb6e=0x0;_0x1bdb6e<_0x12be01[_0x54ed('0x48')]['ids']['length'];_0x1bdb6e+=0x1){socket[_0x54ed('0xb4')](_0x54ed('0xb8'),{'UserId':Number(_0x12be01[_0x54ed('0x48')][_0x54ed('0x6d')][_0x1bdb6e]),'OpenchannelAccountId':Number(_0x12be01[_0x54ed('0x5a')]['id'])});}}else{socket['emit'](_0x54ed('0xb8'),{'UserId':Number(_0x12be01['query'][_0x54ed('0x6d')]),'OpenchannelAccountId':Number(_0x12be01[_0x54ed('0x5a')]['id'])});}});}})[_0x54ed('0x26')](respondWithStatusCode(_0x45766d,null))[_0x54ed('0x2f')](handleError(_0x45766d,null));};exports['getAgents']=function(_0x1d8d16,_0x8e5ac5,_0x5ba7ba){var _0x1f5e98={};var _0x3b355d={};var _0x4caf75;var _0x156377;return db[_0x54ed('0x45')][_0x54ed('0x66')]({'where':{'id':_0x1d8d16[_0x54ed('0x5a')]['id']}})[_0x54ed('0x26')](handleEntityNotFound(_0x8e5ac5,null))[_0x54ed('0x26')](function(_0x50df35){if(_0x50df35){_0x4caf75=_0x50df35;_0x3b355d[_0x54ed('0x47')]=_[_0x54ed('0x49')](db[_0x54ed('0x9c')][_0x54ed('0x46')]);_0x3b355d['query']=_[_0x54ed('0x49')](_0x1d8d16[_0x54ed('0x48')]);_0x3b355d['filters']=_[_0x54ed('0x5b')](_0x3b355d['model'],_0x3b355d[_0x54ed('0x48')]);_0x1f5e98[_0x54ed('0x4b')]=_['intersection'](_0x3b355d[_0x54ed('0x47')],qs[_0x54ed('0x4c')](_0x1d8d16['query'][_0x54ed('0x4c')]));_0x1f5e98[_0x54ed('0x4b')]=_0x1f5e98[_0x54ed('0x4b')][_0x54ed('0x4d')]?_0x1f5e98[_0x54ed('0x4b')]:_0x3b355d[_0x54ed('0x47')];_0x1f5e98[_0x54ed('0x4f')]=qs['sort'](_0x1d8d16[_0x54ed('0x48')][_0x54ed('0x50')]);_0x1f5e98[_0x54ed('0x51')]=qs[_0x54ed('0x4a')](_[_0x54ed('0x68')](_0x1d8d16[_0x54ed('0x48')],_0x3b355d[_0x54ed('0x4a')]));if(_0x1d8d16[_0x54ed('0x48')][_0x54ed('0x52')]){_0x1f5e98[_0x54ed('0x51')]=_[_0x54ed('0x53')](_0x1f5e98[_0x54ed('0x51')],{'$or':_['map'](_0x1f5e98['attributes'],function(_0x49927a){var _0x66153b={};_0x66153b[_0x49927a]={'$like':'%'+_0x1d8d16[_0x54ed('0x48')][_0x54ed('0x52')]+'%'};return _0x66153b;})});}_0x1f5e98=_[_0x54ed('0x53')]({},_0x1f5e98,_0x1d8d16[_0x54ed('0x5c')]);return _0x4caf75['getAgents'](_0x1f5e98);}})['then'](function(_0x4c6817){if(_0x4c6817){_0x156377=_0x4c6817[_0x54ed('0x4d')];if(!_0x1d8d16[_0x54ed('0x48')][_0x54ed('0x4e')]('nolimit')){_0x1f5e98['limit']=qs[_0x54ed('0x36')](_0x1d8d16[_0x54ed('0x48')]['limit']);_0x1f5e98[_0x54ed('0x35')]=qs['offset'](_0x1d8d16[_0x54ed('0x48')][_0x54ed('0x35')]);}return _0x4caf75['getAgents'](_0x1f5e98);}})[_0x54ed('0x26')](function(_0x41cc4e){if(_0x41cc4e){return _0x41cc4e?{'count':_0x156377,'rows':_0x41cc4e}:null;}})[_0x54ed('0x26')](respondWithResult(_0x8e5ac5,null))[_0x54ed('0x2f')](handleError(_0x8e5ac5,null));};exports[_0x54ed('0x41')]=function(_0x8f5073,_0x45976f,_0x2ea82a){var _0x26564b,_0x26bd08,_0x5b16d4;if(_['isNil'](_0x8f5073[_0x54ed('0x5e')][_0x54ed('0x5e')])||_0x8f5073['body'][_0x54ed('0x5e')]===''){throw new db[(_0x54ed('0x75'))][(_0x54ed('0x76'))](_0x54ed('0x7f'));}if(_[_0x54ed('0x7c')](_0x8f5073[_0x54ed('0x5e')]['to'])){}_0x26564b=_0x8f5073[_0x54ed('0x5e')]['to'];return db[_0x54ed('0x45')]['findOne']({'where':{'id':_0x8f5073['params']['id']}})['then'](handleEntityNotFound(_0x45976f,null))[_0x54ed('0x26')](function(_0xcc3b6d){if(_0xcc3b6d){return db[_0x54ed('0x45')]['find']({'where':{'id':_0xcc3b6d['id']},'include':[{'model':db['CmList'],'as':_0x54ed('0x85'),'include':[{'model':db[_0x54ed('0x74')],'as':_0x54ed('0x86'),'where':{[_0xcc3b6d[_0x54ed('0x80')]]:_0x26564b},'limit':0x1,'order':[['updatedAt','DESC']]}]}]})[_0x54ed('0x26')](handleEntityNotFound(_0x45976f,null))['then'](function(_0x12c739){if(_0x12c739&&_0x12c739['List']){_0x26bd08=_0x12c739[_0x54ed('0x3d')]({'plain':!![]});if(_0x26bd08[_0x54ed('0x85')]&&_0x26bd08[_0x54ed('0x85')]['Contacts']['length']){return _0x26bd08['List'][_0x54ed('0x86')][0x0];}return db[_0x54ed('0x74')][_0x54ed('0x5d')](_[_0x54ed('0x1b')](_0x8f5073[_0x54ed('0x5e')],{'firstName':_0x26564b,[_0x12c739[_0x54ed('0x80')]]:_0x26564b,'phone':_0x26564b,'ListId':_0x26bd08['ListId']}));}})[_0x54ed('0x26')](handleEntityNotFound(_0x45976f,null))[_0x54ed('0x26')](function(_0x454416){if(_0x454416){_0x5b16d4=_0x454416;return db[_0x54ed('0x93')][_0x54ed('0x62')]({'where':{'ContactId':_0x5b16d4['id'],'closed':![],'OpenchannelAccountId':_0x26bd08['id']}})[_0x54ed('0x26')](function(_0x486807){if(_0x486807){return[_0x486807,![]];}return db['OpenchannelInteraction'][_0x54ed('0x5d')]({'UserId':_0x8f5073[_0x54ed('0x5f')]['id'],'ContactId':_0x5b16d4['id'],'OpenchannelAccountId':_0x26bd08['id'],'lastMsgDirection':_0x54ed('0xb9'),'Messages':[_[_0x54ed('0x53')](_0x8f5073[_0x54ed('0x5e')],{'read':![],'body':_0x8f5073[_0x54ed('0x5e')][_0x54ed('0x5e')],'OpenchannelAccountId':_0x26bd08['id'],'UserId':_0x8f5073[_0x54ed('0x5f')]['id'],'ContactId':_0x5b16d4['id']})]},{'include':[{'model':db[_0x54ed('0x9a')],'as':_0x54ed('0xba')}]})['then'](function(_0x332a9d){return[_0x332a9d,!![]];});});}})['spread'](function(_0x4d4ab9,_0x368f8a){if(_0x368f8a){return _0x4d4ab9;}return db[_0x54ed('0x9a')]['create'](_['merge'](_0x8f5073['body'],{'read':![],'body':_0x8f5073[_0x54ed('0x5e')][_0x54ed('0x5e')],'OpenchannelAccountId':_0x26bd08['id'],'OpenchannelInteractionId':_0x4d4ab9['id'],'UserId':_0x8f5073['user']['id'],'ContactId':_0x5b16d4['id']}))['then'](function(_0x4b8178){_0x4d4ab9[_0x54ed('0xbb')][_0x54ed('0xba')]=[];_0x4d4ab9[_0x54ed('0xbb')][_0x54ed('0xba')][_0x54ed('0x99')](_0x4b8178[_0x54ed('0xbb')]);return _0x4d4ab9;});});}})[_0x54ed('0x26')](respondWithResult(_0x45976f,null))[_0x54ed('0x2f')](handleError(_0x45976f,null));};