Built motion from commit 47436d59.|2.6.7
[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 _0xb439=['map','OpenchannelAccount','rawAttributes','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','sort','where','pick','filter','type','VIRTUAL','merge','includeAll','include','rows','catch','show','options','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','addDisposition','OpenchannelAccountId','Disposition','getDispositions','nolimit','findAll','removeDispositions','addAnswer','findOne','CannedAnswer','order','removeAnswers','ids','notify','openchannel','describe','Sequelize','ValidationError','no\x20available\x20attributes','createdAt','updatedAt','difference','ListId','isNil','from','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','List','CmContact','Contacts','DESC','OpenchannelApplication','Applications','applications','list','orderBy','asc','account','contact','firstName','lastName','threadId','OpenchannelInteraction','externalUrl','ContactId','spread','messageId','interaction','created','autoclose','push','close','unmanaged','AttachmentId','UserId','User','unshift','waitForTheAssignedAgent','*,*,*,*','forcedOwnership','Start','startRouting','EventManager','addApplications','transaction','sequelize','Transaction','ISOLATION_LEVELS','findAndCountAll','priority','stack','finally','send','getApplications','getInteractions','Contact','Owner','fullname','internal','Tag','Tags','color','tag','addAgents','omit','userOpenchannelAccount:save','removeAgents','isArray','userOpenchannelAccount:remove','emit','getAgents','out','OpenchannelMessage','Messages','dataValues','eml-format','rimraf','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','defaults','redis','localhost','./openchannelAccount.socket','register','jayson/promise','client','http','request','then','info','OpenchannelAccount,\x20%s,\x20%s','debug','OpenchannelAccount,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','result','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','update','get','OpenchannelAccounts','UserProfileResource','destroy','name','index','Pause','mandatoryDispositionPause'];(function(_0x214511,_0x5d5d40){var _0xd3665f=function(_0x22d6c7){while(--_0x22d6c7){_0x214511['push'](_0x214511['shift']());}};_0xd3665f(++_0x5d5d40);}(_0xb439,0x87));var _0x9b43=function(_0x4b055c,_0x4b870b){_0x4b055c=_0x4b055c-0x0;var _0x4b62bb=_0xb439[_0x4b055c];return _0x4b62bb;};'use strict';var emlformat=require(_0x9b43('0x0'));var rimraf=require(_0x9b43('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x9b43('0x2'));var moment=require(_0x9b43('0x3'));var BPromise=require(_0x9b43('0x4'));var Mustache=require('mustache');var util=require(_0x9b43('0x5'));var path=require(_0x9b43('0x6'));var sox=require(_0x9b43('0x7'));var csv=require(_0x9b43('0x8'));var ejs=require(_0x9b43('0x9'));var fs=require('fs');var fs_extra=require(_0x9b43('0xa'));var _=require(_0x9b43('0xb'));var squel=require(_0x9b43('0xc'));var crypto=require(_0x9b43('0xd'));var jsforce=require(_0x9b43('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x9b43('0x8'));var querystring=require(_0x9b43('0xf'));var Papa=require(_0x9b43('0x10'));var Redis=require('ioredis');var authService=require(_0x9b43('0x11'));var qs=require(_0x9b43('0x12'));var as=require(_0x9b43('0x13'));var hardwareService=require(_0x9b43('0x14'));var logger=require(_0x9b43('0x15'))(_0x9b43('0x16'));var utils=require(_0x9b43('0x17'));var config=require(_0x9b43('0x18'));var licenseUtil=require('../../config/license/util');var db=require(_0x9b43('0x19'))['db'];config['redis']=_[_0x9b43('0x1a')](config[_0x9b43('0x1b')],{'host':_0x9b43('0x1c'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x9b43('0x1b')]));require(_0x9b43('0x1d'))[_0x9b43('0x1e')](socket);var jayson=require(_0x9b43('0x1f'));var client=jayson[_0x9b43('0x20')][_0x9b43('0x21')]({'port':0x232c});var client9002=jayson[_0x9b43('0x20')][_0x9b43('0x21')]({'port':0x232a});function respondWithRpcPromise(_0x203a84,_0x211ac1,_0x3370c2,_0x2a3e17){return new BPromise(function(_0x432f1e,_0x577b17){var _0x4d749c=_0x2a3e17||client;return _0x4d749c[_0x9b43('0x22')](_0x203a84,_0x3370c2)[_0x9b43('0x23')](function(_0x364e39){logger[_0x9b43('0x24')](_0x9b43('0x25'),_0x211ac1,'request\x20sent');logger[_0x9b43('0x26')](_0x9b43('0x27'),_0x211ac1,_0x9b43('0x28'),JSON[_0x9b43('0x29')](_0x364e39));if(_0x364e39[_0x9b43('0x2a')]){if(_0x364e39[_0x9b43('0x2a')][_0x9b43('0x2b')]===0x1f4){logger['error'](_0x9b43('0x25'),_0x211ac1,_0x364e39['error'][_0x9b43('0x2c')]);return _0x577b17(_0x364e39[_0x9b43('0x2a')][_0x9b43('0x2c')]);}logger[_0x9b43('0x2a')](_0x9b43('0x25'),_0x211ac1,_0x364e39[_0x9b43('0x2a')]['message']);return _0x432f1e(_0x364e39[_0x9b43('0x2a')][_0x9b43('0x2c')]);}else{logger[_0x9b43('0x24')](_0x9b43('0x25'),_0x211ac1,_0x9b43('0x28'));_0x432f1e(_0x364e39[_0x9b43('0x2d')][_0x9b43('0x2c')]);}})['catch'](function(_0x2ec822){logger['error'](_0x9b43('0x25'),_0x211ac1,_0x2ec822);_0x577b17(_0x2ec822);});});}function respondWithStatusCode(_0x4b2c17,_0x2dd36e){_0x2dd36e=_0x2dd36e||0xcc;return function(_0x55d1e9){if(_0x55d1e9){return _0x4b2c17[_0x9b43('0x2e')](_0x2dd36e);}return _0x4b2c17[_0x9b43('0x2f')](_0x2dd36e)[_0x9b43('0x30')]();};}function respondWithResult(_0x360cbd,_0x25a9b0){_0x25a9b0=_0x25a9b0||0xc8;return function(_0x37bf05){if(_0x37bf05){return _0x360cbd[_0x9b43('0x2f')](_0x25a9b0)[_0x9b43('0x31')](_0x37bf05);}};}function respondWithFilteredResult(_0x5033aa,_0x1deda6){return function(_0x9c9eb4){if(_0x9c9eb4){var _0x3ceb71=typeof _0x1deda6[_0x9b43('0x32')]===_0x9b43('0x33')&&typeof _0x1deda6[_0x9b43('0x34')]==='undefined';var _0x3aa42a=_0x9c9eb4[_0x9b43('0x35')];var _0x3c3b90=_0x3ceb71?0x0:_0x1deda6[_0x9b43('0x32')];var _0x595681=_0x3ceb71?_0x9c9eb4[_0x9b43('0x35')]:_0x1deda6[_0x9b43('0x32')]+_0x1deda6[_0x9b43('0x34')];var _0x4b746a;if(_0x595681>=_0x3aa42a){_0x595681=_0x3aa42a;_0x4b746a=0xc8;}else{_0x4b746a=0xce;}_0x5033aa['status'](_0x4b746a);return _0x5033aa[_0x9b43('0x36')](_0x9b43('0x37'),_0x3c3b90+'-'+_0x595681+'/'+_0x3aa42a)[_0x9b43('0x31')](_0x9c9eb4);}return null;};}function patchUpdates(_0x1eae2a){return function(_0x3f7652){try{jsonpatch[_0x9b43('0x38')](_0x3f7652,_0x1eae2a,!![]);}catch(_0x12dc90){return BPromise[_0x9b43('0x39')](_0x12dc90);}return _0x3f7652['save']();};}function saveUpdates(_0x1f8ce8,_0x5dacab){return function(_0x2a61d0){if(_0x2a61d0){return _0x2a61d0[_0x9b43('0x3a')](_0x1f8ce8)[_0x9b43('0x23')](function(_0x532cde){return _0x532cde;});}return null;};}function removeEntity(_0x11c20e,_0x423cb7){return function(_0x133555){if(_0x133555){return _0x133555['destroy']()[_0x9b43('0x23')](function(){var _0x2a1701=_0x133555[_0x9b43('0x3b')]({'plain':!![]});var _0x4edd44=_0x9b43('0x3c');return db[_0x9b43('0x3d')][_0x9b43('0x3e')]({'where':{'type':_0x4edd44,'resourceId':_0x2a1701['id']}})[_0x9b43('0x23')](function(){return _0x133555;});})['then'](function(){_0x11c20e[_0x9b43('0x2f')](0xcc)['end']();});}};}function handleEntityNotFound(_0x9f80a5,_0x3413d9){return function(_0x5838c0){if(!_0x5838c0){_0x9f80a5[_0x9b43('0x2e')](0x194);}return _0x5838c0;};}function handleError(_0x5e6568,_0x88a4f0){_0x88a4f0=_0x88a4f0||0x1f4;return function(_0x398895){logger[_0x9b43('0x2a')](_0x398895['stack']);if(_0x398895[_0x9b43('0x3f')]){delete _0x398895[_0x9b43('0x3f')];}_0x5e6568[_0x9b43('0x2f')](_0x88a4f0)['send'](_0x398895);};}exports[_0x9b43('0x40')]=function(_0x4cdd30,_0x4db2b9){var _0x35c859={'include':[{'model':db[_0x9b43('0x41')],'as':_0x9b43('0x42')}]},_0x15c09a={},_0xf02096={'count':0x0,'rows':[]};var _0x58923c=_[_0x9b43('0x43')](db[_0x9b43('0x44')][_0x9b43('0x45')],function(_0x412257){return{'name':_0x412257['fieldName'],'type':_0x412257['type'][_0x9b43('0x46')]};});_0x15c09a[_0x9b43('0x47')]=_[_0x9b43('0x43')](_0x58923c,_0x9b43('0x3f'));_0x15c09a[_0x9b43('0x48')]=_[_0x9b43('0x49')](_0x4cdd30[_0x9b43('0x48')]);_0x15c09a[_0x9b43('0x4a')]=_[_0x9b43('0x4b')](_0x15c09a[_0x9b43('0x47')],_0x15c09a['query']);_0x35c859[_0x9b43('0x4c')]=_[_0x9b43('0x4b')](_0x15c09a['model'],qs['fields'](_0x4cdd30[_0x9b43('0x48')][_0x9b43('0x4d')]));_0x35c859['attributes']=_0x35c859[_0x9b43('0x4c')][_0x9b43('0x4e')]?_0x35c859['attributes']:_0x15c09a['model'];if(!_0x4cdd30[_0x9b43('0x48')][_0x9b43('0x4f')]('nolimit')){_0x35c859[_0x9b43('0x34')]=qs[_0x9b43('0x34')](_0x4cdd30[_0x9b43('0x48')][_0x9b43('0x34')]);_0x35c859['offset']=qs['offset'](_0x4cdd30['query'][_0x9b43('0x32')]);}_0x35c859['order']=qs[_0x9b43('0x50')](_0x4cdd30[_0x9b43('0x48')][_0x9b43('0x50')]);_0x35c859[_0x9b43('0x51')]=qs['filters'](_[_0x9b43('0x52')](_0x4cdd30[_0x9b43('0x48')],_0x15c09a[_0x9b43('0x4a')]),_0x58923c);if(_0x4cdd30[_0x9b43('0x48')][_0x9b43('0x53')]){_0x35c859['where']=_['merge'](_0x35c859['where'],{'$or':_[_0x9b43('0x43')](_0x58923c,function(_0x29c6c0){if(_0x29c6c0[_0x9b43('0x54')]!==_0x9b43('0x55')){var _0x18c66e={};_0x18c66e[_0x29c6c0[_0x9b43('0x3f')]]={'$like':'%'+_0x4cdd30['query']['filter']+'%'};return _0x18c66e;}})});}_0x35c859=_[_0x9b43('0x56')]({},_0x35c859,_0x4cdd30['options']);var _0x52587f={'where':_0x35c859['where']};return db[_0x9b43('0x44')][_0x9b43('0x35')](_0x52587f)[_0x9b43('0x23')](function(_0x43a68d){_0xf02096[_0x9b43('0x35')]=_0x43a68d;if(_0x4cdd30[_0x9b43('0x48')][_0x9b43('0x57')]){_0x35c859[_0x9b43('0x58')]=[{'all':!![]}];}return db['OpenchannelAccount']['findAll'](_0x35c859);})[_0x9b43('0x23')](function(_0x4c1c23){_0xf02096[_0x9b43('0x59')]=_0x4c1c23;return _0xf02096;})[_0x9b43('0x23')](respondWithFilteredResult(_0x4db2b9,_0x35c859))[_0x9b43('0x5a')](handleError(_0x4db2b9,null));};exports[_0x9b43('0x5b')]=function(_0x30f2e8,_0x208a6d){var _0xa5797={'raw':![],'where':{'id':_0x30f2e8['params']['id']},'include':[{'model':db[_0x9b43('0x41')],'as':_0x9b43('0x42')}]},_0x258c4={};_0x258c4[_0x9b43('0x47')]=_[_0x9b43('0x49')](db[_0x9b43('0x44')]['rawAttributes']);_0x258c4[_0x9b43('0x48')]=_['keys'](_0x30f2e8[_0x9b43('0x48')]);_0x258c4[_0x9b43('0x4a')]=_[_0x9b43('0x4b')](_0x258c4[_0x9b43('0x47')],_0x258c4[_0x9b43('0x48')]);_0xa5797[_0x9b43('0x4c')]=_[_0x9b43('0x4b')](_0x258c4[_0x9b43('0x47')],qs[_0x9b43('0x4d')](_0x30f2e8[_0x9b43('0x48')][_0x9b43('0x4d')]));_0xa5797[_0x9b43('0x4c')]=_0xa5797['attributes']['length']?_0xa5797[_0x9b43('0x4c')]:_0x258c4['model'];if(_0x30f2e8[_0x9b43('0x48')]['includeAll']){_0xa5797['include']=[{'all':!![]}];}_0xa5797=_[_0x9b43('0x56')]({},_0xa5797,_0x30f2e8[_0x9b43('0x5c')]);return db[_0x9b43('0x44')][_0x9b43('0x5d')](_0xa5797)[_0x9b43('0x23')](handleEntityNotFound(_0x208a6d,null))['then'](respondWithResult(_0x208a6d,null))['catch'](handleError(_0x208a6d,null));};exports[_0x9b43('0x5e')]=function(_0x2b2938,_0x9e339f){return db[_0x9b43('0x44')][_0x9b43('0x5e')](_0x2b2938[_0x9b43('0x5f')],{})['then'](function(_0x1c8161){var _0x141f87=_0x2b2938['user']['get']({'plain':!![]});if(!_0x141f87)throw new Error(_0x9b43('0x60'));if(_0x141f87[_0x9b43('0x61')]===_0x9b43('0x62')){var _0x389273=_0x1c8161[_0x9b43('0x3b')]({'plain':!![]});var _0x14eb0d='OpenchannelAccounts';return db[_0x9b43('0x63')][_0x9b43('0x5d')]({'where':{'name':_0x14eb0d,'userProfileId':_0x141f87['userProfileId']},'raw':!![]})[_0x9b43('0x23')](function(_0x21a553){if(_0x21a553&&_0x21a553[_0x9b43('0x64')]===0x0){return db[_0x9b43('0x3d')][_0x9b43('0x5e')]({'name':_0x389273['name'],'resourceId':_0x389273['id'],'type':_0x21a553[_0x9b43('0x3f')],'sectionId':_0x21a553['id']},{})[_0x9b43('0x23')](function(){return _0x1c8161;});}else{return _0x1c8161;}})['catch'](function(_0x10f344){logger[_0x9b43('0x2a')](_0x9b43('0x65'),_0x10f344);throw _0x10f344;});}return _0x1c8161;})['then'](respondWithResult(_0x9e339f,0xc9))[_0x9b43('0x5a')](handleError(_0x9e339f,null));};exports[_0x9b43('0x3a')]=function(_0x59ca81,_0x1caa93){if(_0x59ca81[_0x9b43('0x5f')]['id']){delete _0x59ca81[_0x9b43('0x5f')]['id'];}return db['OpenchannelAccount'][_0x9b43('0x5d')]({'where':{'id':_0x59ca81['params']['id']},'include':[{'model':db[_0x9b43('0x41')],'as':_0x9b43('0x42')}]})[_0x9b43('0x23')](handleEntityNotFound(_0x1caa93,null))[_0x9b43('0x23')](saveUpdates(_0x59ca81[_0x9b43('0x5f')],null))[_0x9b43('0x23')](respondWithResult(_0x1caa93,null))['catch'](handleError(_0x1caa93,null));};exports[_0x9b43('0x3e')]=function(_0x2aca28,_0x515a82){return db[_0x9b43('0x44')]['find']({'where':{'id':_0x2aca28[_0x9b43('0x66')]['id']}})[_0x9b43('0x23')](handleEntityNotFound(_0x515a82,null))[_0x9b43('0x23')](removeEntity(_0x515a82,null))[_0x9b43('0x5a')](handleError(_0x515a82,null));};exports['describe']=function(_0x2a6f51,_0x3c19a0){return db['OpenchannelAccount']['describe']()[_0x9b43('0x23')](respondWithResult(_0x3c19a0,null))[_0x9b43('0x5a')](handleError(_0x3c19a0,null));};exports[_0x9b43('0x67')]=function(_0x3f928a,_0x30dc8a,_0x329e14){if(_0x3f928a[_0x9b43('0x5f')]['id']){delete _0x3f928a['body']['id'];}return db[_0x9b43('0x44')][_0x9b43('0x5d')]({'where':{'id':_0x3f928a[_0x9b43('0x66')]['id']}})[_0x9b43('0x23')](handleEntityNotFound(_0x30dc8a,null))[_0x9b43('0x23')](function(_0x5da005){if(_0x5da005){_0x3f928a[_0x9b43('0x5f')][_0x9b43('0x68')]=_0x5da005['id'];return db[_0x9b43('0x69')][_0x9b43('0x5e')](_0x3f928a[_0x9b43('0x5f')]);}})[_0x9b43('0x23')](respondWithResult(_0x30dc8a,null))[_0x9b43('0x5a')](handleError(_0x30dc8a,null));};exports[_0x9b43('0x6a')]=function(_0x5689c2,_0x4fe8f1,_0x26dd65){var _0x23e6ac={'raw':![],'where':{}};var _0x39c9ff={};var _0x3e8ebe={'count':0x0,'rows':[]};return db[_0x9b43('0x44')]['findOne']({'where':{'id':_0x5689c2[_0x9b43('0x66')]['id']}})[_0x9b43('0x23')](handleEntityNotFound(_0x4fe8f1,null))[_0x9b43('0x23')](function(_0x2184e5){if(_0x2184e5){_0x39c9ff[_0x9b43('0x47')]=_['keys'](db[_0x9b43('0x69')][_0x9b43('0x45')]);_0x39c9ff['query']=_[_0x9b43('0x49')](_0x5689c2[_0x9b43('0x48')]);_0x39c9ff[_0x9b43('0x4a')]=_[_0x9b43('0x4b')](_0x39c9ff[_0x9b43('0x47')],_0x39c9ff[_0x9b43('0x48')]);_0x23e6ac[_0x9b43('0x4c')]=_[_0x9b43('0x4b')](_0x39c9ff[_0x9b43('0x47')],qs[_0x9b43('0x4d')](_0x5689c2[_0x9b43('0x48')][_0x9b43('0x4d')]));_0x23e6ac['attributes']=_0x23e6ac[_0x9b43('0x4c')]['length']?_0x23e6ac['attributes']:_0x39c9ff[_0x9b43('0x47')];if(!_0x5689c2[_0x9b43('0x48')][_0x9b43('0x4f')](_0x9b43('0x6b'))){_0x23e6ac[_0x9b43('0x34')]=qs[_0x9b43('0x34')](_0x5689c2[_0x9b43('0x48')][_0x9b43('0x34')]);_0x23e6ac[_0x9b43('0x32')]=qs[_0x9b43('0x32')](_0x5689c2['query']['offset']);}_0x23e6ac['order']=qs['sort'](_0x5689c2[_0x9b43('0x48')][_0x9b43('0x50')]);_0x23e6ac[_0x9b43('0x51')]=qs[_0x9b43('0x4a')](_[_0x9b43('0x52')](_0x5689c2[_0x9b43('0x48')],_0x39c9ff['filters']));_0x23e6ac[_0x9b43('0x51')][_0x9b43('0x68')]=_0x2184e5['id'];if(_0x5689c2[_0x9b43('0x48')][_0x9b43('0x53')]){_0x23e6ac['where']=_[_0x9b43('0x56')](_0x23e6ac[_0x9b43('0x51')],{'$or':_[_0x9b43('0x43')](_0x23e6ac[_0x9b43('0x4c')],function(_0x3ec669){var _0x3339c0={};_0x3339c0[_0x3ec669]={'$like':'%'+_0x5689c2[_0x9b43('0x48')][_0x9b43('0x53')]+'%'};return _0x3339c0;})});}_0x23e6ac=_['merge']({},_0x23e6ac,_0x5689c2[_0x9b43('0x5c')]);return db[_0x9b43('0x69')][_0x9b43('0x35')]({'where':_0x23e6ac[_0x9b43('0x51')]})[_0x9b43('0x23')](function(_0x3fce14){_0x3e8ebe[_0x9b43('0x35')]=_0x3fce14;if(_0x5689c2[_0x9b43('0x48')][_0x9b43('0x57')]){_0x23e6ac['include']=[{'all':!![]}];}return db['Disposition'][_0x9b43('0x6c')](_0x23e6ac);})['then'](function(_0x1f1a7a){_0x3e8ebe[_0x9b43('0x59')]=_0x1f1a7a;return _0x3e8ebe;});}})[_0x9b43('0x23')](respondWithFilteredResult(_0x4fe8f1,_0x23e6ac))[_0x9b43('0x5a')](handleError(_0x4fe8f1,null));};exports[_0x9b43('0x6d')]=function(_0x39b8fe,_0x41b438,_0x44be7b){return db['OpenchannelAccount'][_0x9b43('0x5d')]({'where':{'id':_0x39b8fe[_0x9b43('0x66')]['id']}})[_0x9b43('0x23')](handleEntityNotFound(_0x41b438,null))[_0x9b43('0x23')](function(_0x39dbfd){if(_0x39dbfd){return _0x39dbfd['removeDispositions'](_0x39b8fe['query']['ids']);}})[_0x9b43('0x23')](respondWithStatusCode(_0x41b438,null))[_0x9b43('0x5a')](handleError(_0x41b438,null));};exports[_0x9b43('0x6e')]=function(_0x2185e4,_0x13ece9,_0x2f2af7){if(_0x2185e4[_0x9b43('0x5f')]['id']){delete _0x2185e4[_0x9b43('0x5f')]['id'];}return db['OpenchannelAccount']['find']({'where':{'id':_0x2185e4[_0x9b43('0x66')]['id']}})[_0x9b43('0x23')](handleEntityNotFound(_0x13ece9,null))[_0x9b43('0x23')](function(_0xea2bf0){if(_0xea2bf0){_0x2185e4['body']['OpenchannelAccountId']=_0xea2bf0['id'];return db['CannedAnswer'][_0x9b43('0x5e')](_0x2185e4[_0x9b43('0x5f')]);}})['then'](respondWithResult(_0x13ece9,null))[_0x9b43('0x5a')](handleError(_0x13ece9,null));};exports['getAnswers']=function(_0x3d4479,_0x44e1d4,_0x3a282c){var _0x2b4125={'raw':![],'where':{}};var _0x517e2c={};var _0xc1984a={'count':0x0,'rows':[]};return db[_0x9b43('0x44')][_0x9b43('0x6f')]({'where':{'id':_0x3d4479[_0x9b43('0x66')]['id']}})[_0x9b43('0x23')](handleEntityNotFound(_0x44e1d4,null))[_0x9b43('0x23')](function(_0x32777a){if(_0x32777a){_0x517e2c[_0x9b43('0x47')]=_[_0x9b43('0x49')](db[_0x9b43('0x70')]['rawAttributes']);_0x517e2c[_0x9b43('0x48')]=_[_0x9b43('0x49')](_0x3d4479[_0x9b43('0x48')]);_0x517e2c[_0x9b43('0x4a')]=_[_0x9b43('0x4b')](_0x517e2c[_0x9b43('0x47')],_0x517e2c['query']);_0x2b4125['attributes']=_[_0x9b43('0x4b')](_0x517e2c['model'],qs[_0x9b43('0x4d')](_0x3d4479[_0x9b43('0x48')][_0x9b43('0x4d')]));_0x2b4125[_0x9b43('0x4c')]=_0x2b4125['attributes'][_0x9b43('0x4e')]?_0x2b4125['attributes']:_0x517e2c[_0x9b43('0x47')];if(!_0x3d4479[_0x9b43('0x48')][_0x9b43('0x4f')]('nolimit')){_0x2b4125[_0x9b43('0x34')]=qs[_0x9b43('0x34')](_0x3d4479['query'][_0x9b43('0x34')]);_0x2b4125['offset']=qs[_0x9b43('0x32')](_0x3d4479['query'][_0x9b43('0x32')]);}_0x2b4125[_0x9b43('0x71')]=qs[_0x9b43('0x50')](_0x3d4479[_0x9b43('0x48')]['sort']);_0x2b4125[_0x9b43('0x51')]=qs[_0x9b43('0x4a')](_[_0x9b43('0x52')](_0x3d4479[_0x9b43('0x48')],_0x517e2c[_0x9b43('0x4a')]));_0x2b4125[_0x9b43('0x51')][_0x9b43('0x68')]=_0x32777a['id'];if(_0x3d4479[_0x9b43('0x48')][_0x9b43('0x53')]){_0x2b4125['where']=_[_0x9b43('0x56')](_0x2b4125[_0x9b43('0x51')],{'$or':_[_0x9b43('0x43')](_0x2b4125[_0x9b43('0x4c')],function(_0x37ab25){var _0x29dd58={};_0x29dd58[_0x37ab25]={'$like':'%'+_0x3d4479[_0x9b43('0x48')][_0x9b43('0x53')]+'%'};return _0x29dd58;})});}_0x2b4125=_[_0x9b43('0x56')]({},_0x2b4125,_0x3d4479['options']);return db[_0x9b43('0x70')][_0x9b43('0x35')]({'where':_0x2b4125['where']})[_0x9b43('0x23')](function(_0x10d7c1){_0xc1984a[_0x9b43('0x35')]=_0x10d7c1;if(_0x3d4479[_0x9b43('0x48')]['includeAll']){_0x2b4125['include']=[{'all':!![]}];}return db[_0x9b43('0x70')][_0x9b43('0x6c')](_0x2b4125);})[_0x9b43('0x23')](function(_0x41cffb){_0xc1984a['rows']=_0x41cffb;return _0xc1984a;});}})[_0x9b43('0x23')](respondWithFilteredResult(_0x44e1d4,_0x2b4125))['catch'](handleError(_0x44e1d4,null));};exports[_0x9b43('0x72')]=function(_0x5a29ec,_0x557b1c,_0x133fa5){return db['OpenchannelAccount']['find']({'where':{'id':_0x5a29ec[_0x9b43('0x66')]['id']}})[_0x9b43('0x23')](handleEntityNotFound(_0x557b1c,null))[_0x9b43('0x23')](function(_0x5b205d){if(_0x5b205d){return _0x5b205d[_0x9b43('0x72')](_0x5a29ec[_0x9b43('0x48')][_0x9b43('0x73')]);}})[_0x9b43('0x23')](respondWithStatusCode(_0x557b1c,null))[_0x9b43('0x5a')](handleError(_0x557b1c,null));};exports[_0x9b43('0x74')]=function(_0x5a4ab2,_0x1c72d2,_0x2f8d6d){var _0x382e87={'body':_0x5a4ab2[_0x9b43('0x5f')],'channel':_0x9b43('0x75')};var _0x3ba60f=[];var _0x556901=[];var _0xfcbbc2={};var _0x50a2ea=![];return db['CmContact'][_0x9b43('0x76')]()[_0x9b43('0x23')](function(_0x290061){if(!_0x290061){throw new db[(_0x9b43('0x77'))][(_0x9b43('0x78'))](_0x9b43('0x79'));}_0x3ba60f=_['difference'](_['keys'](_0x290061),[_0x9b43('0x7a'),_0x9b43('0x7b')]);_0x556901=_[_0x9b43('0x7c')](_['keys'](_0x290061),[_0x9b43('0x7a'),_0x9b43('0x7b'),'CompanyId',_0x9b43('0x7d')]);if(_0x5a4ab2[_0x9b43('0x5f')]['id']){delete _0x5a4ab2[_0x9b43('0x5f')]['id'];}if(_[_0x9b43('0x7e')](_0x5a4ab2[_0x9b43('0x5f')][_0x9b43('0x7f')])){throw new db['Sequelize'][(_0x9b43('0x78'))](_0x9b43('0x80'));}if(_[_0x9b43('0x7e')](_0x5a4ab2['body']['body'])||_0x5a4ab2[_0x9b43('0x5f')][_0x9b43('0x5f')]===''){throw new db['Sequelize'][(_0x9b43('0x78'))](_0x9b43('0x81'));}if(_[_0x9b43('0x7e')](_0x5a4ab2[_0x9b43('0x5f')][_0x9b43('0x82')])){throw new db[(_0x9b43('0x77'))][(_0x9b43('0x78'))](_0x9b43('0x83')+_0x556901);}if(!_['includes'](_0x556901,_0x5a4ab2[_0x9b43('0x5f')][_0x9b43('0x82')])){throw new db[(_0x9b43('0x77'))]['ValidationError'](_0x9b43('0x84')+_0x556901);}_0xfcbbc2[_0x5a4ab2[_0x9b43('0x5f')]['mapKey']]=_0x5a4ab2[_0x9b43('0x5f')][_0x9b43('0x7f')];})[_0x9b43('0x23')](function(){return db['OpenchannelAccount']['find']({'where':{'id':_0x5a4ab2[_0x9b43('0x66')]['id']},'include':[{'model':db[_0x9b43('0x85')],'as':_0x9b43('0x86'),'include':[{'model':db[_0x9b43('0x87')],'as':_0x9b43('0x88'),'where':_0xfcbbc2,'limit':0x1,'order':[[_0x9b43('0x7b'),_0x9b43('0x89')]]}]},{'model':db[_0x9b43('0x8a')],'as':_0x9b43('0x8b')}]});})[_0x9b43('0x23')](handleEntityNotFound(_0x1c72d2,null))[_0x9b43('0x23')](function(_0x323713){if(_0x323713&&_0x323713['List']){_0x382e87['account']=_0x323713;_0x382e87[_0x9b43('0x8c')]=_0x323713[_0x9b43('0x8b')];_0x382e87[_0x9b43('0x8d')]=_0x323713[_0x9b43('0x86')];_0x382e87[_0x9b43('0x8c')]=_[_0x9b43('0x8e')](_0x382e87[_0x9b43('0x8c')],['priority'],[_0x9b43('0x8f')]);if(_0x382e87[_0x9b43('0x90')][_0x9b43('0x8b')]){delete _0x382e87[_0x9b43('0x90')][_0x9b43('0x8b')];}if(_0x382e87['account'][_0x9b43('0x86')]&&_0x382e87['account'][_0x9b43('0x86')][_0x9b43('0x88')][_0x9b43('0x4e')]){return _0x382e87['account']['List'][_0x9b43('0x88')][0x0];}var _0x49cd45=_[_0x9b43('0x1a')](_0x5a4ab2[_0x9b43('0x5f')],{'firstName':_0x5a4ab2[_0x9b43('0x5f')][_0x9b43('0x7f')],'ListId':_0x323713['ListId']});_0x49cd45[_0x5a4ab2[_0x9b43('0x5f')]['mapKey']]=_0x5a4ab2[_0x9b43('0x5f')]['from'];return db[_0x9b43('0x87')][_0x9b43('0x5e')](_0x49cd45,{'fields':_0x3ba60f,'raw':!![]});}})[_0x9b43('0x23')](handleEntityNotFound(_0x1c72d2,null))[_0x9b43('0x23')](function(_0x55e474){_0x382e87[_0x9b43('0x91')]=_0x55e474;if(_0x55e474){var _0x87dc11={'ContactId':_0x55e474['id'],'OpenchannelAccountId':_0x5a4ab2[_0x9b43('0x66')]['id'],'from':(_0x55e474[_0x9b43('0x92')]||'')+'\x20'+(_0x55e474[_0x9b43('0x93')]||'')};var _0x2dc1be={'OpenchannelAccountId':_0x5a4ab2[_0x9b43('0x66')]['id'],'closed':![]};if(_0x5a4ab2[_0x9b43('0x5f')][_0x9b43('0x94')]){_0x2dc1be[_0x9b43('0x94')]=_0x5a4ab2[_0x9b43('0x5f')][_0x9b43('0x94')];return db[_0x9b43('0x95')][_0x9b43('0x5d')]({'where':_0x2dc1be})['then'](function(_0x89f344){if(_0x89f344){return[_0x89f344,![]];}_0x87dc11[_0x9b43('0x94')]=_0x5a4ab2[_0x9b43('0x5f')][_0x9b43('0x94')];_0x87dc11[_0x9b43('0x96')]=_0x5a4ab2[_0x9b43('0x5f')][_0x9b43('0x96')];return db[_0x9b43('0x95')]['create'](_0x87dc11)[_0x9b43('0x23')](function(_0x4da76b){return[_0x4da76b,!![]];});});}else{_0x2dc1be[_0x9b43('0x94')]=null;}_0x2dc1be[_0x9b43('0x97')]=_0x55e474['id'];return db[_0x9b43('0x95')][_0x9b43('0x5d')]({'where':_0x2dc1be})[_0x9b43('0x23')](function(_0x5d2d53){if(_0x5d2d53){return[_0x5d2d53,![]];}return db[_0x9b43('0x95')][_0x9b43('0x5e')](_0x87dc11)[_0x9b43('0x23')](function(_0x3b168a){return[_0x3b168a,!![]];});});}})[_0x9b43('0x98')](function(_0x4d9df5,_0x50ed89){if(_0x4d9df5){_0x50a2ea=_0x50ed89;if(!_0x50ed89){var _0x52bf6e={'from':(_0x382e87['contact'][_0x9b43('0x92')]||'')+'\x20'+(_0x382e87[_0x9b43('0x91')]['lastName']||'')};if(_0x5a4ab2[_0x9b43('0x5f')][_0x9b43('0x94')]&&_0x5a4ab2['body'][_0x9b43('0x99')]&&_0x5a4ab2[_0x9b43('0x5f')]['threadId']!=_0x5a4ab2[_0x9b43('0x5f')]['messageId']){_0x52bf6e[_0x9b43('0x94')]=_0x5a4ab2['body'][_0x9b43('0x99')];}return _0x4d9df5['update'](_0x52bf6e);}else{return _0x4d9df5;}}})['then'](function(_0x2359ba){_0x382e87[_0x9b43('0x9a')]=_0x2359ba['get']({'plain':!![]});_0x382e87[_0x9b43('0x9a')][_0x9b43('0x9b')]=_0x50a2ea;if(_0x382e87[_0x9b43('0x9a')]['created']){if(_0x382e87['account'][_0x9b43('0x9c')]){_0x382e87['applications'][_0x9b43('0x9d')]({'id':0x0,'priority':_0x382e87['applications'][_0x9b43('0x4e')]+0x1,'app':_0x9b43('0x9e'),'appdata':_0x9b43('0x9f'),'interval':'*,*,*,*'});}}return db['OpenchannelMessage']['create']({'body':_0x5a4ab2[_0x9b43('0x5f')]['body'],'OpenchannelAccountId':_0x5a4ab2['params']['id'],'OpenchannelInteractionId':_0x2359ba['id'],'direction':'in','ContactId':_0x382e87['contact']['id'],'AttachmentId':_0x5a4ab2[_0x9b43('0x5f')][_0x9b43('0xa0')]});})[_0x9b43('0x23')](function(_0x5944c4){_0x382e87[_0x9b43('0x2c')]=_0x5944c4;if(_0x382e87['interaction'][_0x9b43('0xa1')]){return db[_0x9b43('0xa2')][_0x9b43('0x5d')]({'attributes':['id',_0x9b43('0x3f')],'where':{'id':_0x382e87[_0x9b43('0x9a')]['UserId']}})[_0x9b43('0x23')](function(_0x31aaed){if(_0x31aaed){_0x382e87[_0x9b43('0x8c')][_0x9b43('0xa3')]({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x31aaed[_0x9b43('0x3f')]+','+(_0x382e87[_0x9b43('0x90')][_0x9b43('0xa4')]||0xa),'interval':_0x9b43('0xa5')});_0x382e87[_0x9b43('0xa6')]=![];}return respondWithRpcPromise(_0x9b43('0xa7'),_0x9b43('0xa8'),_0x382e87);});}return respondWithRpcPromise('Start',_0x9b43('0xa8'),_0x382e87);})[_0x9b43('0x23')](function(_0x594b88){respondWithRpcPromise(_0x9b43('0xa9'),'EventManager',{'event':_0x9b43('0x74'),'message':_0x594b88},client9002);return _0x594b88;})[_0x9b43('0x23')](respondWithResult(_0x1c72d2,null))[_0x9b43('0x5a')](handleError(_0x1c72d2,null));};exports[_0x9b43('0xaa')]=function(_0x4fb65c,_0x162694){var _0x548fe3=_0x4fb65c[_0x9b43('0x66')]['id'];var _0x39d9b6=_0x4fb65c[_0x9b43('0x5f')];var _0x52ab70=0xc8;var _0x3e08a7=null;return db['sequelize'][_0x9b43('0xab')]({'isolationLevel':db[_0x9b43('0xac')][_0x9b43('0xad')][_0x9b43('0xae')]['READ_COMMITTED']},function(_0x18aef2){return db[_0x9b43('0x44')]['findOne']({'where':{'id':_0x548fe3},'transaction':_0x18aef2})[_0x9b43('0x23')](function(_0x171e25){if(_0x171e25){return db[_0x9b43('0x8a')][_0x9b43('0x3e')]({'where':{'OpenchannelAccountId':_0x548fe3},'transaction':_0x18aef2})['then'](function(){var _0x7aa6aa=_[_0x9b43('0x43')](_0x39d9b6,function(_0x2e768f){_0x2e768f['OpenchannelAccountId']=_0x548fe3;return _0x2e768f;});return db[_0x9b43('0x8a')]['bulkCreate'](_0x7aa6aa,{'transaction':_0x18aef2});});}else{_0x52ab70=0x194;_0x3e08a7=[];}});})[_0x9b43('0x23')](function(){if(_0x52ab70!==0x194){return db[_0x9b43('0x8a')][_0x9b43('0xaf')]({'where':{'OpenchannelAccountId':_0x548fe3},'order':_0x9b43('0xb0')})[_0x9b43('0x23')](function(_0x5305e6){_0x3e08a7=_0x5305e6;});}})[_0x9b43('0x5a')](function(_0x5bf72a){_0x52ab70=0x1f4;logger['error'](_0x5bf72a[_0x9b43('0xb1')]);if(_0x5bf72a[_0x9b43('0x3f')]){delete _0x5bf72a[_0x9b43('0x3f')];}_0x3e08a7=_0x5bf72a;})[_0x9b43('0xb2')](function(){if(_0x3e08a7===null){_0x162694[_0x9b43('0x2e')](_0x52ab70);}else{if(_0x52ab70===0x1f4){_0x162694['status'](_0x52ab70)[_0x9b43('0xb3')](_0x3e08a7);}else{_0x162694[_0x9b43('0x2f')](_0x52ab70)[_0x9b43('0x31')](_0x3e08a7);}}});};exports[_0x9b43('0xb4')]=function(_0x4084e4,_0x24118a,_0x41f9b6){var _0x4fd651={};var _0x1b2bd2={};var _0x1dd316;var _0x287141;return db['OpenchannelAccount'][_0x9b43('0x6f')]({'where':{'id':_0x4084e4[_0x9b43('0x66')]['id']}})[_0x9b43('0x23')](handleEntityNotFound(_0x24118a,null))[_0x9b43('0x23')](function(_0x19fbd9){if(_0x19fbd9){_0x1dd316=_0x19fbd9;_0x1b2bd2['model']=_[_0x9b43('0x49')](db[_0x9b43('0x8a')][_0x9b43('0x45')]);_0x1b2bd2[_0x9b43('0x48')]=_[_0x9b43('0x49')](_0x4084e4['query']);_0x1b2bd2[_0x9b43('0x4a')]=_[_0x9b43('0x4b')](_0x1b2bd2[_0x9b43('0x47')],_0x1b2bd2[_0x9b43('0x48')]);_0x4fd651[_0x9b43('0x4c')]=_['intersection'](_0x1b2bd2[_0x9b43('0x47')],qs[_0x9b43('0x4d')](_0x4084e4[_0x9b43('0x48')][_0x9b43('0x4d')]));_0x4fd651['attributes']=_0x4fd651['attributes']['length']?_0x4fd651['attributes']:_0x1b2bd2[_0x9b43('0x47')];_0x4fd651[_0x9b43('0x71')]=qs[_0x9b43('0x50')](_0x4084e4[_0x9b43('0x48')]['sort']);_0x4fd651[_0x9b43('0x51')]=qs['filters'](_[_0x9b43('0x52')](_0x4084e4[_0x9b43('0x48')],_0x1b2bd2[_0x9b43('0x4a')]));if(_0x4084e4[_0x9b43('0x48')][_0x9b43('0x53')]){_0x4fd651[_0x9b43('0x51')]=_[_0x9b43('0x56')](_0x4fd651[_0x9b43('0x51')],{'$or':_[_0x9b43('0x43')](_0x4fd651[_0x9b43('0x4c')],function(_0x125ae9){var _0x52f53e={};_0x52f53e[_0x125ae9]={'$like':'%'+_0x4084e4[_0x9b43('0x48')]['filter']+'%'};return _0x52f53e;})});}_0x4fd651=_[_0x9b43('0x56')]({},_0x4fd651,_0x4084e4[_0x9b43('0x5c')]);return _0x1dd316[_0x9b43('0xb4')](_0x4fd651);}})['then'](function(_0x7a9c1e){if(_0x7a9c1e){_0x287141=_0x7a9c1e[_0x9b43('0x4e')];if(!_0x4084e4[_0x9b43('0x48')][_0x9b43('0x4f')]('nolimit')){_0x4fd651[_0x9b43('0x34')]=qs['limit'](_0x4084e4[_0x9b43('0x48')][_0x9b43('0x34')]);_0x4fd651[_0x9b43('0x32')]=qs['offset'](_0x4084e4[_0x9b43('0x48')][_0x9b43('0x32')]);}return _0x1dd316[_0x9b43('0xb4')](_0x4fd651);}})[_0x9b43('0x23')](function(_0xc82750){if(_0xc82750){return _0xc82750?{'count':_0x287141,'rows':_0xc82750}:null;}})[_0x9b43('0x23')](respondWithResult(_0x24118a,null))[_0x9b43('0x5a')](handleError(_0x24118a,null));};exports[_0x9b43('0xb5')]=function(_0x4040f7,_0x57b608,_0x42b2b1){var _0x17e4e6={'raw':![],'where':{}};var _0x309663={};var _0x4f76d1={'count':0x0,'rows':[]};return db[_0x9b43('0x44')][_0x9b43('0x6f')]({'where':{'id':_0x4040f7[_0x9b43('0x66')]['id']}})['then'](handleEntityNotFound(_0x57b608,null))[_0x9b43('0x23')](function(_0x500fe8){if(_0x500fe8){_0x309663[_0x9b43('0x47')]=_[_0x9b43('0x49')](db[_0x9b43('0x95')][_0x9b43('0x45')]);_0x309663[_0x9b43('0x48')]=_['keys'](_0x4040f7[_0x9b43('0x48')]);_0x309663[_0x9b43('0x4a')]=_[_0x9b43('0x4b')](_0x309663['model'],_0x309663[_0x9b43('0x48')]);_0x17e4e6[_0x9b43('0x4c')]=_[_0x9b43('0x4b')](_0x309663['model'],qs[_0x9b43('0x4d')](_0x4040f7[_0x9b43('0x48')]['fields']));_0x17e4e6[_0x9b43('0x4c')]=_0x17e4e6['attributes'][_0x9b43('0x4e')]?_0x17e4e6['attributes']:_0x309663[_0x9b43('0x47')];if(!_0x4040f7[_0x9b43('0x48')][_0x9b43('0x4f')](_0x9b43('0x6b'))){_0x17e4e6['limit']=qs['limit'](_0x4040f7['query'][_0x9b43('0x34')]);_0x17e4e6['offset']=qs[_0x9b43('0x32')](_0x4040f7['query']['offset']);}_0x17e4e6[_0x9b43('0x71')]=qs['sort'](_0x4040f7[_0x9b43('0x48')][_0x9b43('0x50')]);_0x17e4e6[_0x9b43('0x51')]=qs['filters'](_[_0x9b43('0x52')](_0x4040f7[_0x9b43('0x48')],_0x309663[_0x9b43('0x4a')]));_0x17e4e6['where'][_0x9b43('0x68')]=_0x500fe8['id'];if(_0x4040f7[_0x9b43('0x48')][_0x9b43('0x53')]){_0x17e4e6[_0x9b43('0x51')]=_[_0x9b43('0x56')](_0x17e4e6[_0x9b43('0x51')],{'$or':_[_0x9b43('0x43')](_0x17e4e6[_0x9b43('0x4c')],function(_0x91ef16){var _0x3a0070={};_0x3a0070[_0x91ef16]={'$like':'%'+_0x4040f7[_0x9b43('0x48')][_0x9b43('0x53')]+'%'};return _0x3a0070;})});}_0x17e4e6=_[_0x9b43('0x56')]({},_0x17e4e6,_0x4040f7[_0x9b43('0x5c')]);return db['OpenchannelInteraction'][_0x9b43('0x35')]({'where':_0x17e4e6[_0x9b43('0x51')]})[_0x9b43('0x23')](function(_0x1e16a9){_0x4f76d1[_0x9b43('0x35')]=_0x1e16a9;if(_0x4040f7[_0x9b43('0x48')]['includeAll']){_0x17e4e6['include']=[{'model':db[_0x9b43('0x87')],'as':_0x9b43('0xb6'),'required':![]},{'model':db[_0x9b43('0xa2')],'as':_0x9b43('0xb7'),'attributes':[_0x9b43('0x3f'),_0x9b43('0xb8'),_0x9b43('0xb9')],'required':![]},{'model':db[_0x9b43('0xba')],'as':_0x9b43('0xbb'),'attributes':['id',_0x9b43('0x3f'),_0x9b43('0xbc')],'where':_0x4040f7[_0x9b43('0x48')]['tag']?{'id':_0x4040f7[_0x9b43('0x48')][_0x9b43('0xbd')]}:undefined,'required':_0x4040f7[_0x9b43('0x48')][_0x9b43('0xbd')]?!![]:![]}];}return db[_0x9b43('0x95')][_0x9b43('0x6c')](_0x17e4e6);})['then'](function(_0x5e8747){_0x4f76d1[_0x9b43('0x59')]=_0x5e8747;return _0x4f76d1;});}})[_0x9b43('0x23')](respondWithFilteredResult(_0x57b608,_0x17e4e6))[_0x9b43('0x5a')](handleError(_0x57b608,null));};exports['addAgents']=function(_0xc3c0d1,_0x5a8597,_0x4fba93){return db[_0x9b43('0x44')][_0x9b43('0x5d')]({'where':{'id':_0xc3c0d1[_0x9b43('0x66')]['id']}})[_0x9b43('0x23')](handleEntityNotFound(_0x5a8597,null))[_0x9b43('0x23')](function(_0x87fff8){if(_0x87fff8){return _0x87fff8[_0x9b43('0xbe')](_0xc3c0d1[_0x9b43('0x5f')][_0x9b43('0x73')],_[_0x9b43('0xbf')](_0xc3c0d1[_0x9b43('0x5f')],[_0x9b43('0x73'),'id'])||{})[_0x9b43('0x98')](function(_0x2d8b2b){for(var _0x1fba6c=0x0;_0x1fba6c<_0xc3c0d1[_0x9b43('0x5f')]['ids'][_0x9b43('0x4e')];_0x1fba6c+=0x1){socket['emit'](_0x9b43('0xc0'),{'UserId':Number(_0xc3c0d1['body']['ids'][_0x1fba6c]),'OpenchannelAccountId':Number(_0xc3c0d1[_0x9b43('0x66')]['id'])});}return _0x2d8b2b;});}})[_0x9b43('0x23')](respondWithResult(_0x5a8597,null))[_0x9b43('0x5a')](handleError(_0x5a8597,null));};exports[_0x9b43('0xc1')]=function(_0x4a90a0,_0x14c01d,_0x8154b7){return db[_0x9b43('0x44')]['find']({'where':{'id':_0x4a90a0[_0x9b43('0x66')]['id']}})[_0x9b43('0x23')](handleEntityNotFound(_0x14c01d,null))[_0x9b43('0x23')](function(_0x45046b){if(_0x45046b){return _0x45046b[_0x9b43('0xc1')](_0x4a90a0[_0x9b43('0x48')][_0x9b43('0x73')])[_0x9b43('0x23')](function(){if(_[_0x9b43('0xc2')](_0x4a90a0[_0x9b43('0x48')][_0x9b43('0x73')])){for(var _0x336748=0x0;_0x336748<_0x4a90a0[_0x9b43('0x48')][_0x9b43('0x73')][_0x9b43('0x4e')];_0x336748+=0x1){socket['emit'](_0x9b43('0xc3'),{'UserId':Number(_0x4a90a0[_0x9b43('0x48')][_0x9b43('0x73')][_0x336748]),'OpenchannelAccountId':Number(_0x4a90a0[_0x9b43('0x66')]['id'])});}}else{socket[_0x9b43('0xc4')](_0x9b43('0xc3'),{'UserId':Number(_0x4a90a0['query'][_0x9b43('0x73')]),'OpenchannelAccountId':Number(_0x4a90a0[_0x9b43('0x66')]['id'])});}});}})[_0x9b43('0x23')](respondWithStatusCode(_0x14c01d,null))[_0x9b43('0x5a')](handleError(_0x14c01d,null));};exports[_0x9b43('0xc5')]=function(_0x54a74b,_0xaa9adc,_0x38a738){var _0x5c206f={};var _0x54f1eb={};var _0x3b65f5;var _0x552888;return db[_0x9b43('0x44')][_0x9b43('0x6f')]({'where':{'id':_0x54a74b[_0x9b43('0x66')]['id']}})['then'](handleEntityNotFound(_0xaa9adc,null))[_0x9b43('0x23')](function(_0x423df7){if(_0x423df7){_0x3b65f5=_0x423df7;_0x54f1eb[_0x9b43('0x47')]=_[_0x9b43('0x49')](db[_0x9b43('0xa2')][_0x9b43('0x45')]);_0x54f1eb[_0x9b43('0x48')]=_[_0x9b43('0x49')](_0x54a74b['query']);_0x54f1eb[_0x9b43('0x4a')]=_[_0x9b43('0x4b')](_0x54f1eb['model'],_0x54f1eb['query']);_0x5c206f[_0x9b43('0x4c')]=_[_0x9b43('0x4b')](_0x54f1eb['model'],qs[_0x9b43('0x4d')](_0x54a74b[_0x9b43('0x48')][_0x9b43('0x4d')]));_0x5c206f[_0x9b43('0x4c')]=_0x5c206f[_0x9b43('0x4c')][_0x9b43('0x4e')]?_0x5c206f[_0x9b43('0x4c')]:_0x54f1eb['model'];_0x5c206f['order']=qs[_0x9b43('0x50')](_0x54a74b['query']['sort']);_0x5c206f[_0x9b43('0x51')]=qs[_0x9b43('0x4a')](_[_0x9b43('0x52')](_0x54a74b[_0x9b43('0x48')],_0x54f1eb[_0x9b43('0x4a')]));if(_0x54a74b[_0x9b43('0x48')]['filter']){_0x5c206f['where']=_[_0x9b43('0x56')](_0x5c206f[_0x9b43('0x51')],{'$or':_[_0x9b43('0x43')](_0x5c206f[_0x9b43('0x4c')],function(_0x10338c){var _0x2b7847={};_0x2b7847[_0x10338c]={'$like':'%'+_0x54a74b[_0x9b43('0x48')][_0x9b43('0x53')]+'%'};return _0x2b7847;})});}_0x5c206f=_[_0x9b43('0x56')]({},_0x5c206f,_0x54a74b[_0x9b43('0x5c')]);return _0x3b65f5[_0x9b43('0xc5')](_0x5c206f);}})['then'](function(_0xe994d4){if(_0xe994d4){_0x552888=_0xe994d4['length'];if(!_0x54a74b[_0x9b43('0x48')][_0x9b43('0x4f')]('nolimit')){_0x5c206f[_0x9b43('0x34')]=qs[_0x9b43('0x34')](_0x54a74b[_0x9b43('0x48')][_0x9b43('0x34')]);_0x5c206f[_0x9b43('0x32')]=qs[_0x9b43('0x32')](_0x54a74b[_0x9b43('0x48')]['offset']);}return _0x3b65f5[_0x9b43('0xc5')](_0x5c206f);}})[_0x9b43('0x23')](function(_0xf19a39){if(_0xf19a39){return _0xf19a39?{'count':_0x552888,'rows':_0xf19a39}:null;}})[_0x9b43('0x23')](respondWithResult(_0xaa9adc,null))[_0x9b43('0x5a')](handleError(_0xaa9adc,null));};exports['send']=function(_0x55cdad,_0x5a11e5,_0x51d7c1){var _0x237dbb,_0x53b5f7,_0x1ab663;if(_[_0x9b43('0x7e')](_0x55cdad[_0x9b43('0x5f')][_0x9b43('0x5f')])||_0x55cdad['body'][_0x9b43('0x5f')]===''){throw new db[(_0x9b43('0x77'))][(_0x9b43('0x78'))](_0x9b43('0x81'));}if(_[_0x9b43('0x7e')](_0x55cdad[_0x9b43('0x5f')]['to'])){}_0x237dbb=_0x55cdad[_0x9b43('0x5f')]['to'];return db[_0x9b43('0x44')]['findOne']({'where':{'id':_0x55cdad['params']['id']}})[_0x9b43('0x23')](handleEntityNotFound(_0x5a11e5,null))[_0x9b43('0x23')](function(_0x44b05b){if(_0x44b05b){return db[_0x9b43('0x44')]['find']({'where':{'id':_0x44b05b['id']},'include':[{'model':db['CmList'],'as':_0x9b43('0x86'),'include':[{'model':db[_0x9b43('0x87')],'as':_0x9b43('0x88'),'where':{[_0x44b05b[_0x9b43('0x82')]]:_0x237dbb},'limit':0x1,'order':[[_0x9b43('0x7b'),_0x9b43('0x89')]]}]}]})[_0x9b43('0x23')](handleEntityNotFound(_0x5a11e5,null))[_0x9b43('0x23')](function(_0x446be1){if(_0x446be1&&_0x446be1[_0x9b43('0x86')]){_0x53b5f7=_0x446be1[_0x9b43('0x3b')]({'plain':!![]});if(_0x53b5f7['List']&&_0x53b5f7[_0x9b43('0x86')][_0x9b43('0x88')][_0x9b43('0x4e')]){return _0x53b5f7[_0x9b43('0x86')][_0x9b43('0x88')][0x0];}return db['CmContact'][_0x9b43('0x5e')](_['defaults'](_0x55cdad[_0x9b43('0x5f')],{'firstName':_0x237dbb,[_0x446be1[_0x9b43('0x82')]]:_0x237dbb,'phone':_0x237dbb,'ListId':_0x53b5f7[_0x9b43('0x7d')]}));}})['then'](handleEntityNotFound(_0x5a11e5,null))[_0x9b43('0x23')](function(_0x479944){if(_0x479944){_0x1ab663=_0x479944;return db[_0x9b43('0x95')][_0x9b43('0x5d')]({'where':{'ContactId':_0x1ab663['id'],'closed':![],'OpenchannelAccountId':_0x53b5f7['id']}})['then'](function(_0x1e5539){if(_0x1e5539){return[_0x1e5539,![]];}return db[_0x9b43('0x95')]['create']({'UserId':_0x55cdad[_0x9b43('0x62')]['id'],'ContactId':_0x1ab663['id'],'OpenchannelAccountId':_0x53b5f7['id'],'lastMsgDirection':_0x9b43('0xc6'),'firstMsgDirection':_0x9b43('0xc6'),'Messages':[_[_0x9b43('0x56')](_0x55cdad[_0x9b43('0x5f')],{'read':![],'body':_0x55cdad[_0x9b43('0x5f')]['body'],'OpenchannelAccountId':_0x53b5f7['id'],'UserId':_0x55cdad[_0x9b43('0x62')]['id'],'ContactId':_0x1ab663['id']})]},{'include':[{'model':db[_0x9b43('0xc7')],'as':_0x9b43('0xc8')}]})['then'](function(_0x4c9318){return[_0x4c9318,!![]];});});}})[_0x9b43('0x98')](function(_0x2dabe1,_0x2364ba){if(_0x2364ba){return _0x2dabe1;}return db[_0x9b43('0xc7')][_0x9b43('0x5e')](_['merge'](_0x55cdad[_0x9b43('0x5f')],{'read':![],'body':_0x55cdad['body'][_0x9b43('0x5f')],'OpenchannelAccountId':_0x53b5f7['id'],'OpenchannelInteractionId':_0x2dabe1['id'],'UserId':_0x55cdad[_0x9b43('0x62')]['id'],'ContactId':_0x1ab663['id']}))['then'](function(_0x3ba8fb){_0x2dabe1[_0x9b43('0xc9')][_0x9b43('0xc8')]=[];_0x2dabe1['dataValues']['Messages'][_0x9b43('0x9d')](_0x3ba8fb[_0x9b43('0xc9')]);return _0x2dabe1;});});}})[_0x9b43('0x23')](respondWithResult(_0x5a11e5,null))['catch'](handleError(_0x5a11e5,null));};