Built motion from commit d1eab355.|2.6.28
[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 _0xf0c2=['show','rawAttributes','length','includeAll','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','destroy','describe','addDisposition','findOne','Disposition','OpenchannelAccountId','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','order','removeAnswers','notify','openchannel','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','updatedAt','difference','createdAt','CompanyId','ListId','isNil','from','from\x20is\x20mandatory','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','List','DESC','OpenchannelApplication','account','Applications','list','applications','orderBy','priority','asc','Contacts','contact','firstName','lastName','threadId','OpenchannelInteraction','externalUrl','ContactId','spread','messageId','interaction','created','autoclose','push','close','unmanaged','*,*,*,*','OpenchannelMessage','AttachmentId','User','UserId','unshift','waitForTheAssignedAgent','queueId','queue','waitForTheAssignedQueue','Start','startRouting','EventManager','sequelize','transaction','Transaction','ISOLATION_LEVELS','bulkCreate','findAndCountAll','getApplications','getInteractions','Owner','fullname','internal','Tag','Tags','tag','addAgents','omit','userOpenchannelAccount:save','removeAgents','isArray','emit','userOpenchannelAccount:remove','getAgents','Messages','dataValues','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','./openchannelAccount.socket','register','jayson/promise','client','http','request','then','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','debug','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','result','status','end','json','offset','undefined','count','set','Content-Range','apply','reject','save','update','get','OpenchannelAccounts','sendStatus','stack','name','send','Pause','mandatoryDispositionPause','OpenchannelAccount','fieldName','type','key','map','query','keys','filters','model','attributes','intersection','fields','hasOwnProperty','nolimit','limit','sort','where','pick','merge','VIRTUAL','filter','include','findAll','rows','catch'];(function(_0x559cca,_0x477765){var _0x228ba1=function(_0x1e2aea){while(--_0x1e2aea){_0x559cca['push'](_0x559cca['shift']());}};_0x228ba1(++_0x477765);}(_0xf0c2,0x6e));var _0x2f0c=function(_0x156d15,_0x2c22b4){_0x156d15=_0x156d15-0x0;var _0x6fe3fb=_0xf0c2[_0x156d15];return _0x6fe3fb;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x2f0c('0x0'));var zipdir=require(_0x2f0c('0x1'));var jsonpatch=require(_0x2f0c('0x2'));var rp=require(_0x2f0c('0x3'));var moment=require(_0x2f0c('0x4'));var BPromise=require(_0x2f0c('0x5'));var Mustache=require(_0x2f0c('0x6'));var util=require(_0x2f0c('0x7'));var path=require(_0x2f0c('0x8'));var sox=require(_0x2f0c('0x9'));var csv=require(_0x2f0c('0xa'));var ejs=require(_0x2f0c('0xb'));var fs=require('fs');var fs_extra=require(_0x2f0c('0xc'));var _=require('lodash');var squel=require(_0x2f0c('0xd'));var crypto=require(_0x2f0c('0xe'));var jsforce=require('jsforce');var deskjs=require(_0x2f0c('0xf'));var toCsv=require(_0x2f0c('0xa'));var querystring=require(_0x2f0c('0x10'));var Papa=require(_0x2f0c('0x11'));var Redis=require(_0x2f0c('0x12'));var authService=require('../../components/auth/service');var qs=require(_0x2f0c('0x13'));var as=require(_0x2f0c('0x14'));var hardwareService=require(_0x2f0c('0x15'));var logger=require(_0x2f0c('0x16'))(_0x2f0c('0x17'));var utils=require(_0x2f0c('0x18'));var config=require(_0x2f0c('0x19'));var licenseUtil=require(_0x2f0c('0x1a'));var db=require(_0x2f0c('0x1b'))['db'];config[_0x2f0c('0x1c')]=_[_0x2f0c('0x1d')](config[_0x2f0c('0x1c')],{'host':_0x2f0c('0x1e'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x2f0c('0x1f'))[_0x2f0c('0x20')](socket);var jayson=require(_0x2f0c('0x21'));var client=jayson[_0x2f0c('0x22')]['http']({'port':0x232c});var client9002=jayson[_0x2f0c('0x22')][_0x2f0c('0x23')]({'port':0x232a});function respondWithRpcPromise(_0xa3f8e2,_0x31ab32,_0xd8f935,_0x4976e4){return new BPromise(function(_0x3612bb,_0xa16ab){var _0x5dad52=_0x4976e4||client;return _0x5dad52[_0x2f0c('0x24')](_0xa3f8e2,_0xd8f935)[_0x2f0c('0x25')](function(_0x5219e9){logger['info'](_0x2f0c('0x26'),_0x31ab32,_0x2f0c('0x27'));logger[_0x2f0c('0x28')](_0x2f0c('0x29'),_0x31ab32,_0x2f0c('0x27'),JSON[_0x2f0c('0x2a')](_0x5219e9));if(_0x5219e9[_0x2f0c('0x2b')]){if(_0x5219e9[_0x2f0c('0x2b')][_0x2f0c('0x2c')]===0x1f4){logger[_0x2f0c('0x2b')](_0x2f0c('0x26'),_0x31ab32,_0x5219e9[_0x2f0c('0x2b')][_0x2f0c('0x2d')]);return _0xa16ab(_0x5219e9['error'][_0x2f0c('0x2d')]);}logger[_0x2f0c('0x2b')]('OpenchannelAccount,\x20%s,\x20%s',_0x31ab32,_0x5219e9['error'][_0x2f0c('0x2d')]);return _0x3612bb(_0x5219e9[_0x2f0c('0x2b')][_0x2f0c('0x2d')]);}else{logger[_0x2f0c('0x2e')](_0x2f0c('0x26'),_0x31ab32,_0x2f0c('0x27'));_0x3612bb(_0x5219e9[_0x2f0c('0x2f')][_0x2f0c('0x2d')]);}})['catch'](function(_0x2d9053){logger['error'](_0x2f0c('0x26'),_0x31ab32,_0x2d9053);_0xa16ab(_0x2d9053);});});}function respondWithStatusCode(_0x3b48b7,_0x337f8e){_0x337f8e=_0x337f8e||0xcc;return function(_0x3b8e02){if(_0x3b8e02){return _0x3b48b7['sendStatus'](_0x337f8e);}return _0x3b48b7[_0x2f0c('0x30')](_0x337f8e)[_0x2f0c('0x31')]();};}function respondWithResult(_0x9b9273,_0x3edbc2){_0x3edbc2=_0x3edbc2||0xc8;return function(_0x5a11f2){if(_0x5a11f2){return _0x9b9273['status'](_0x3edbc2)[_0x2f0c('0x32')](_0x5a11f2);}};}function respondWithFilteredResult(_0x415c7a,_0x41a4f1){return function(_0x25c683){if(_0x25c683){var _0x1c5638=typeof _0x41a4f1[_0x2f0c('0x33')]===_0x2f0c('0x34')&&typeof _0x41a4f1['limit']===_0x2f0c('0x34');var _0x145441=_0x25c683[_0x2f0c('0x35')];var _0x4f3a99=_0x1c5638?0x0:_0x41a4f1[_0x2f0c('0x33')];var _0xaa2b97=_0x1c5638?_0x25c683[_0x2f0c('0x35')]:_0x41a4f1[_0x2f0c('0x33')]+_0x41a4f1['limit'];var _0x1cea58;if(_0xaa2b97>=_0x145441){_0xaa2b97=_0x145441;_0x1cea58=0xc8;}else{_0x1cea58=0xce;}_0x415c7a['status'](_0x1cea58);return _0x415c7a[_0x2f0c('0x36')](_0x2f0c('0x37'),_0x4f3a99+'-'+_0xaa2b97+'/'+_0x145441)[_0x2f0c('0x32')](_0x25c683);}return null;};}function patchUpdates(_0x219374){return function(_0x179906){try{jsonpatch[_0x2f0c('0x38')](_0x179906,_0x219374,!![]);}catch(_0x56a77e){return BPromise[_0x2f0c('0x39')](_0x56a77e);}return _0x179906[_0x2f0c('0x3a')]();};}function saveUpdates(_0x46ecba,_0x249cad){return function(_0x5d061f){if(_0x5d061f){return _0x5d061f[_0x2f0c('0x3b')](_0x46ecba)[_0x2f0c('0x25')](function(_0x4a4411){return _0x4a4411;});}return null;};}function removeEntity(_0x198e7f,_0x333561){return function(_0xf9dab8){if(_0xf9dab8){return _0xf9dab8['destroy']()[_0x2f0c('0x25')](function(){var _0x32db77=_0xf9dab8[_0x2f0c('0x3c')]({'plain':!![]});var _0x505936=_0x2f0c('0x3d');return db['UserProfileResource']['destroy']({'where':{'type':_0x505936,'resourceId':_0x32db77['id']}})['then'](function(){return _0xf9dab8;});})[_0x2f0c('0x25')](function(){_0x198e7f['status'](0xcc)[_0x2f0c('0x31')]();});}};}function handleEntityNotFound(_0x5d5fd9,_0x364f90){return function(_0x437816){if(!_0x437816){_0x5d5fd9[_0x2f0c('0x3e')](0x194);}return _0x437816;};}function handleError(_0x52f223,_0x2105ad){_0x2105ad=_0x2105ad||0x1f4;return function(_0x1d3600){logger[_0x2f0c('0x2b')](_0x1d3600[_0x2f0c('0x3f')]);if(_0x1d3600['name']){delete _0x1d3600[_0x2f0c('0x40')];}_0x52f223[_0x2f0c('0x30')](_0x2105ad)[_0x2f0c('0x41')](_0x1d3600);};}exports['index']=function(_0x43e5d8,_0x59cd57){var _0x268de4={'include':[{'model':db[_0x2f0c('0x42')],'as':_0x2f0c('0x43')}]},_0x7235bd={},_0x2854d8={'count':0x0,'rows':[]};var _0x41010d=_['map'](db[_0x2f0c('0x44')]['rawAttributes'],function(_0x1fd4da){return{'name':_0x1fd4da[_0x2f0c('0x45')],'type':_0x1fd4da[_0x2f0c('0x46')][_0x2f0c('0x47')]};});_0x7235bd['model']=_[_0x2f0c('0x48')](_0x41010d,_0x2f0c('0x40'));_0x7235bd[_0x2f0c('0x49')]=_[_0x2f0c('0x4a')](_0x43e5d8[_0x2f0c('0x49')]);_0x7235bd[_0x2f0c('0x4b')]=_['intersection'](_0x7235bd[_0x2f0c('0x4c')],_0x7235bd[_0x2f0c('0x49')]);_0x268de4[_0x2f0c('0x4d')]=_[_0x2f0c('0x4e')](_0x7235bd[_0x2f0c('0x4c')],qs[_0x2f0c('0x4f')](_0x43e5d8[_0x2f0c('0x49')][_0x2f0c('0x4f')]));_0x268de4[_0x2f0c('0x4d')]=_0x268de4[_0x2f0c('0x4d')]['length']?_0x268de4[_0x2f0c('0x4d')]:_0x7235bd['model'];if(!_0x43e5d8[_0x2f0c('0x49')][_0x2f0c('0x50')](_0x2f0c('0x51'))){_0x268de4['limit']=qs['limit'](_0x43e5d8['query'][_0x2f0c('0x52')]);_0x268de4[_0x2f0c('0x33')]=qs[_0x2f0c('0x33')](_0x43e5d8[_0x2f0c('0x49')][_0x2f0c('0x33')]);}_0x268de4['order']=qs[_0x2f0c('0x53')](_0x43e5d8[_0x2f0c('0x49')][_0x2f0c('0x53')]);_0x268de4[_0x2f0c('0x54')]=qs[_0x2f0c('0x4b')](_[_0x2f0c('0x55')](_0x43e5d8['query'],_0x7235bd['filters']),_0x41010d);if(_0x43e5d8[_0x2f0c('0x49')]['filter']){_0x268de4[_0x2f0c('0x54')]=_[_0x2f0c('0x56')](_0x268de4[_0x2f0c('0x54')],{'$or':_[_0x2f0c('0x48')](_0x41010d,function(_0x4bbec7){if(_0x4bbec7[_0x2f0c('0x46')]!==_0x2f0c('0x57')){var _0x476c47={};_0x476c47[_0x4bbec7['name']]={'$like':'%'+_0x43e5d8[_0x2f0c('0x49')][_0x2f0c('0x58')]+'%'};return _0x476c47;}})});}_0x268de4=_[_0x2f0c('0x56')]({},_0x268de4,_0x43e5d8['options']);var _0xf344db={'where':_0x268de4[_0x2f0c('0x54')]};return db[_0x2f0c('0x44')][_0x2f0c('0x35')](_0xf344db)['then'](function(_0x192398){_0x2854d8[_0x2f0c('0x35')]=_0x192398;if(_0x43e5d8[_0x2f0c('0x49')]['includeAll']){_0x268de4[_0x2f0c('0x59')]=[{'all':!![]}];}return db[_0x2f0c('0x44')][_0x2f0c('0x5a')](_0x268de4);})[_0x2f0c('0x25')](function(_0x23456a){_0x2854d8[_0x2f0c('0x5b')]=_0x23456a;return _0x2854d8;})[_0x2f0c('0x25')](respondWithFilteredResult(_0x59cd57,_0x268de4))[_0x2f0c('0x5c')](handleError(_0x59cd57,null));};exports[_0x2f0c('0x5d')]=function(_0x307db2,_0x426937){var _0x56224d={'raw':![],'where':{'id':_0x307db2['params']['id']},'include':[{'model':db['Pause'],'as':_0x2f0c('0x43')}]},_0x3bb5e8={};_0x3bb5e8['model']=_[_0x2f0c('0x4a')](db[_0x2f0c('0x44')][_0x2f0c('0x5e')]);_0x3bb5e8[_0x2f0c('0x49')]=_[_0x2f0c('0x4a')](_0x307db2[_0x2f0c('0x49')]);_0x3bb5e8[_0x2f0c('0x4b')]=_['intersection'](_0x3bb5e8['model'],_0x3bb5e8[_0x2f0c('0x49')]);_0x56224d[_0x2f0c('0x4d')]=_[_0x2f0c('0x4e')](_0x3bb5e8[_0x2f0c('0x4c')],qs[_0x2f0c('0x4f')](_0x307db2[_0x2f0c('0x49')][_0x2f0c('0x4f')]));_0x56224d[_0x2f0c('0x4d')]=_0x56224d['attributes'][_0x2f0c('0x5f')]?_0x56224d['attributes']:_0x3bb5e8[_0x2f0c('0x4c')];if(_0x307db2[_0x2f0c('0x49')][_0x2f0c('0x60')]){_0x56224d[_0x2f0c('0x59')]=[{'all':!![]}];}_0x56224d=_[_0x2f0c('0x56')]({},_0x56224d,_0x307db2[_0x2f0c('0x61')]);return db[_0x2f0c('0x44')][_0x2f0c('0x62')](_0x56224d)[_0x2f0c('0x25')](handleEntityNotFound(_0x426937,null))[_0x2f0c('0x25')](respondWithResult(_0x426937,null))['catch'](handleError(_0x426937,null));};exports[_0x2f0c('0x63')]=function(_0x265990,_0x2a642f){return db['OpenchannelAccount'][_0x2f0c('0x63')](_0x265990[_0x2f0c('0x64')],{})[_0x2f0c('0x25')](function(_0x5172ce){var _0x2fb525=_0x265990[_0x2f0c('0x65')][_0x2f0c('0x3c')]({'plain':!![]});if(!_0x2fb525)throw new Error(_0x2f0c('0x66'));if(_0x2fb525[_0x2f0c('0x67')]==='user'){var _0x11ac63=_0x5172ce['get']({'plain':!![]});var _0x4cf475=_0x2f0c('0x3d');return db[_0x2f0c('0x68')][_0x2f0c('0x62')]({'where':{'name':_0x4cf475,'userProfileId':_0x2fb525['userProfileId']},'raw':!![]})[_0x2f0c('0x25')](function(_0x2e6592){if(_0x2e6592&&_0x2e6592[_0x2f0c('0x69')]===0x0){return db['UserProfileResource']['create']({'name':_0x11ac63[_0x2f0c('0x40')],'resourceId':_0x11ac63['id'],'type':_0x2e6592[_0x2f0c('0x40')],'sectionId':_0x2e6592['id']},{})['then'](function(){return _0x5172ce;});}else{return _0x5172ce;}})[_0x2f0c('0x5c')](function(_0x292755){logger['error'](_0x2f0c('0x6a'),_0x292755);throw _0x292755;});}return _0x5172ce;})['then'](respondWithResult(_0x2a642f,0xc9))[_0x2f0c('0x5c')](handleError(_0x2a642f,null));};exports[_0x2f0c('0x3b')]=function(_0x5a5cd8,_0x124e8d){if(_0x5a5cd8[_0x2f0c('0x64')]['id']){delete _0x5a5cd8[_0x2f0c('0x64')]['id'];}return db['OpenchannelAccount'][_0x2f0c('0x62')]({'where':{'id':_0x5a5cd8[_0x2f0c('0x6b')]['id']},'include':[{'model':db['Pause'],'as':_0x2f0c('0x43')}]})[_0x2f0c('0x25')](handleEntityNotFound(_0x124e8d,null))[_0x2f0c('0x25')](saveUpdates(_0x5a5cd8[_0x2f0c('0x64')],null))[_0x2f0c('0x25')](respondWithResult(_0x124e8d,null))[_0x2f0c('0x5c')](handleError(_0x124e8d,null));};exports[_0x2f0c('0x6c')]=function(_0x54394b,_0x207028){return db[_0x2f0c('0x44')][_0x2f0c('0x62')]({'where':{'id':_0x54394b['params']['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x207028,null))['then'](removeEntity(_0x207028,null))[_0x2f0c('0x5c')](handleError(_0x207028,null));};exports['describe']=function(_0x39f479,_0x38f855){return db[_0x2f0c('0x44')][_0x2f0c('0x6d')]()[_0x2f0c('0x25')](respondWithResult(_0x38f855,null))['catch'](handleError(_0x38f855,null));};exports[_0x2f0c('0x6e')]=function(_0x56b5e6,_0x5dde71,_0x1cbafc){if(_0x56b5e6[_0x2f0c('0x64')]['id']){delete _0x56b5e6[_0x2f0c('0x64')]['id'];}return db[_0x2f0c('0x44')][_0x2f0c('0x62')]({'where':{'id':_0x56b5e6[_0x2f0c('0x6b')]['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x5dde71,null))['then'](function(_0x54b213){if(_0x54b213){_0x56b5e6[_0x2f0c('0x64')]['OpenchannelAccountId']=_0x54b213['id'];return db['Disposition'][_0x2f0c('0x63')](_0x56b5e6[_0x2f0c('0x64')]);}})[_0x2f0c('0x25')](respondWithResult(_0x5dde71,null))[_0x2f0c('0x5c')](handleError(_0x5dde71,null));};exports['getDispositions']=function(_0x2edf98,_0x4bb7b0,_0x5669e5){var _0x411077={'raw':![],'where':{}};var _0x451ea9={};var _0x34e03d={'count':0x0,'rows':[]};return db[_0x2f0c('0x44')][_0x2f0c('0x6f')]({'where':{'id':_0x2edf98[_0x2f0c('0x6b')]['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x4bb7b0,null))[_0x2f0c('0x25')](function(_0x4a5488){if(_0x4a5488){_0x451ea9[_0x2f0c('0x4c')]=_['keys'](db[_0x2f0c('0x70')][_0x2f0c('0x5e')]);_0x451ea9[_0x2f0c('0x49')]=_[_0x2f0c('0x4a')](_0x2edf98[_0x2f0c('0x49')]);_0x451ea9[_0x2f0c('0x4b')]=_[_0x2f0c('0x4e')](_0x451ea9[_0x2f0c('0x4c')],_0x451ea9['query']);_0x411077['attributes']=_[_0x2f0c('0x4e')](_0x451ea9[_0x2f0c('0x4c')],qs['fields'](_0x2edf98['query'][_0x2f0c('0x4f')]));_0x411077['attributes']=_0x411077[_0x2f0c('0x4d')]['length']?_0x411077[_0x2f0c('0x4d')]:_0x451ea9[_0x2f0c('0x4c')];if(!_0x2edf98[_0x2f0c('0x49')]['hasOwnProperty']('nolimit')){_0x411077['limit']=qs[_0x2f0c('0x52')](_0x2edf98[_0x2f0c('0x49')][_0x2f0c('0x52')]);_0x411077['offset']=qs['offset'](_0x2edf98[_0x2f0c('0x49')][_0x2f0c('0x33')]);}_0x411077['order']=qs[_0x2f0c('0x53')](_0x2edf98['query'][_0x2f0c('0x53')]);_0x411077[_0x2f0c('0x54')]=qs[_0x2f0c('0x4b')](_[_0x2f0c('0x55')](_0x2edf98['query'],_0x451ea9[_0x2f0c('0x4b')]));_0x411077['where'][_0x2f0c('0x71')]=_0x4a5488['id'];if(_0x2edf98[_0x2f0c('0x49')][_0x2f0c('0x58')]){_0x411077[_0x2f0c('0x54')]=_['merge'](_0x411077['where'],{'$or':_['map'](_0x411077['attributes'],function(_0xb016bb){var _0x33e6bf={};_0x33e6bf[_0xb016bb]={'$like':'%'+_0x2edf98['query'][_0x2f0c('0x58')]+'%'};return _0x33e6bf;})});}_0x411077=_[_0x2f0c('0x56')]({},_0x411077,_0x2edf98[_0x2f0c('0x61')]);return db[_0x2f0c('0x70')][_0x2f0c('0x35')]({'where':_0x411077[_0x2f0c('0x54')]})[_0x2f0c('0x25')](function(_0x1d3734){_0x34e03d[_0x2f0c('0x35')]=_0x1d3734;if(_0x2edf98[_0x2f0c('0x49')][_0x2f0c('0x60')]){_0x411077[_0x2f0c('0x59')]=[{'all':!![]}];}return db[_0x2f0c('0x70')][_0x2f0c('0x5a')](_0x411077);})[_0x2f0c('0x25')](function(_0x1747f5){_0x34e03d[_0x2f0c('0x5b')]=_0x1747f5;return _0x34e03d;});}})['then'](respondWithFilteredResult(_0x4bb7b0,_0x411077))[_0x2f0c('0x5c')](handleError(_0x4bb7b0,null));};exports[_0x2f0c('0x72')]=function(_0x286b79,_0x4668d9,_0x672730){return db[_0x2f0c('0x44')]['find']({'where':{'id':_0x286b79[_0x2f0c('0x6b')]['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x4668d9,null))[_0x2f0c('0x25')](function(_0x568f28){if(_0x568f28){return _0x568f28[_0x2f0c('0x72')](_0x286b79[_0x2f0c('0x49')][_0x2f0c('0x73')]);}})[_0x2f0c('0x25')](respondWithStatusCode(_0x4668d9,null))['catch'](handleError(_0x4668d9,null));};exports[_0x2f0c('0x74')]=function(_0x298f10,_0x146db1,_0x26d8e9){if(_0x298f10[_0x2f0c('0x64')]['id']){delete _0x298f10[_0x2f0c('0x64')]['id'];}return db[_0x2f0c('0x44')]['find']({'where':{'id':_0x298f10[_0x2f0c('0x6b')]['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x146db1,null))[_0x2f0c('0x25')](function(_0x3420d5){if(_0x3420d5){_0x298f10[_0x2f0c('0x64')][_0x2f0c('0x71')]=_0x3420d5['id'];return db[_0x2f0c('0x75')][_0x2f0c('0x63')](_0x298f10[_0x2f0c('0x64')]);}})[_0x2f0c('0x25')](respondWithResult(_0x146db1,null))[_0x2f0c('0x5c')](handleError(_0x146db1,null));};exports[_0x2f0c('0x76')]=function(_0x3c7018,_0x42d367,_0x57aad0){var _0x18f7e0={'raw':![],'where':{}};var _0xe8a96c={};var _0x524d5f={'count':0x0,'rows':[]};return db[_0x2f0c('0x44')][_0x2f0c('0x6f')]({'where':{'id':_0x3c7018[_0x2f0c('0x6b')]['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x42d367,null))[_0x2f0c('0x25')](function(_0x2e1efb){if(_0x2e1efb){_0xe8a96c[_0x2f0c('0x4c')]=_[_0x2f0c('0x4a')](db[_0x2f0c('0x75')]['rawAttributes']);_0xe8a96c[_0x2f0c('0x49')]=_['keys'](_0x3c7018[_0x2f0c('0x49')]);_0xe8a96c[_0x2f0c('0x4b')]=_[_0x2f0c('0x4e')](_0xe8a96c[_0x2f0c('0x4c')],_0xe8a96c[_0x2f0c('0x49')]);_0x18f7e0['attributes']=_['intersection'](_0xe8a96c[_0x2f0c('0x4c')],qs[_0x2f0c('0x4f')](_0x3c7018[_0x2f0c('0x49')][_0x2f0c('0x4f')]));_0x18f7e0[_0x2f0c('0x4d')]=_0x18f7e0[_0x2f0c('0x4d')]['length']?_0x18f7e0[_0x2f0c('0x4d')]:_0xe8a96c[_0x2f0c('0x4c')];if(!_0x3c7018['query'][_0x2f0c('0x50')](_0x2f0c('0x51'))){_0x18f7e0['limit']=qs[_0x2f0c('0x52')](_0x3c7018[_0x2f0c('0x49')]['limit']);_0x18f7e0['offset']=qs[_0x2f0c('0x33')](_0x3c7018[_0x2f0c('0x49')][_0x2f0c('0x33')]);}_0x18f7e0[_0x2f0c('0x77')]=qs[_0x2f0c('0x53')](_0x3c7018[_0x2f0c('0x49')][_0x2f0c('0x53')]);_0x18f7e0['where']=qs[_0x2f0c('0x4b')](_[_0x2f0c('0x55')](_0x3c7018[_0x2f0c('0x49')],_0xe8a96c[_0x2f0c('0x4b')]));_0x18f7e0[_0x2f0c('0x54')]['OpenchannelAccountId']=_0x2e1efb['id'];if(_0x3c7018[_0x2f0c('0x49')]['filter']){_0x18f7e0[_0x2f0c('0x54')]=_[_0x2f0c('0x56')](_0x18f7e0[_0x2f0c('0x54')],{'$or':_[_0x2f0c('0x48')](_0x18f7e0[_0x2f0c('0x4d')],function(_0x5772e){var _0x22a1bc={};_0x22a1bc[_0x5772e]={'$like':'%'+_0x3c7018[_0x2f0c('0x49')][_0x2f0c('0x58')]+'%'};return _0x22a1bc;})});}_0x18f7e0=_[_0x2f0c('0x56')]({},_0x18f7e0,_0x3c7018[_0x2f0c('0x61')]);return db['CannedAnswer']['count']({'where':_0x18f7e0[_0x2f0c('0x54')]})[_0x2f0c('0x25')](function(_0x1c673f){_0x524d5f[_0x2f0c('0x35')]=_0x1c673f;if(_0x3c7018[_0x2f0c('0x49')][_0x2f0c('0x60')]){_0x18f7e0[_0x2f0c('0x59')]=[{'all':!![]}];}return db[_0x2f0c('0x75')]['findAll'](_0x18f7e0);})[_0x2f0c('0x25')](function(_0x3e0952){_0x524d5f[_0x2f0c('0x5b')]=_0x3e0952;return _0x524d5f;});}})[_0x2f0c('0x25')](respondWithFilteredResult(_0x42d367,_0x18f7e0))['catch'](handleError(_0x42d367,null));};exports[_0x2f0c('0x78')]=function(_0x585f39,_0x3e3363,_0x2a84ab){return db[_0x2f0c('0x44')]['find']({'where':{'id':_0x585f39[_0x2f0c('0x6b')]['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x3e3363,null))[_0x2f0c('0x25')](function(_0x4e2a56){if(_0x4e2a56){return _0x4e2a56[_0x2f0c('0x78')](_0x585f39[_0x2f0c('0x49')][_0x2f0c('0x73')]);}})[_0x2f0c('0x25')](respondWithStatusCode(_0x3e3363,null))[_0x2f0c('0x5c')](handleError(_0x3e3363,null));};exports[_0x2f0c('0x79')]=function(_0x5611ae,_0x50b430,_0x5a00e9){var _0x4f99d4={'body':_0x5611ae[_0x2f0c('0x64')],'channel':_0x2f0c('0x7a')};var _0x31e28e=[];var _0xefd0bd=[];var _0x521d5d={};var _0x2d814a=![];return db[_0x2f0c('0x7b')][_0x2f0c('0x6d')]()['then'](function(_0x505616){if(!_0x505616){throw new db[(_0x2f0c('0x7c'))][(_0x2f0c('0x7d'))](_0x2f0c('0x7e'));}_0x31e28e=_['difference'](_['keys'](_0x505616),['createdAt',_0x2f0c('0x7f')]);_0xefd0bd=_[_0x2f0c('0x80')](_[_0x2f0c('0x4a')](_0x505616),[_0x2f0c('0x81'),_0x2f0c('0x7f'),_0x2f0c('0x82'),_0x2f0c('0x83')]);if(_0x5611ae[_0x2f0c('0x64')]['id']){delete _0x5611ae[_0x2f0c('0x64')]['id'];}if(_[_0x2f0c('0x84')](_0x5611ae['body'][_0x2f0c('0x85')])){throw new db[(_0x2f0c('0x7c'))]['ValidationError'](_0x2f0c('0x86'));}if(_[_0x2f0c('0x84')](_0x5611ae['body'][_0x2f0c('0x64')])||_0x5611ae[_0x2f0c('0x64')][_0x2f0c('0x64')]===''){throw new db[(_0x2f0c('0x7c'))][(_0x2f0c('0x7d'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x2f0c('0x84')](_0x5611ae[_0x2f0c('0x64')][_0x2f0c('0x87')])){throw new db[(_0x2f0c('0x7c'))][(_0x2f0c('0x7d'))](_0x2f0c('0x88')+_0xefd0bd);}if(!_[_0x2f0c('0x89')](_0xefd0bd,_0x5611ae[_0x2f0c('0x64')]['mapKey'])){throw new db[(_0x2f0c('0x7c'))][(_0x2f0c('0x7d'))](_0x2f0c('0x8a')+_0xefd0bd);}_0x521d5d[_0x5611ae[_0x2f0c('0x64')][_0x2f0c('0x87')]]=_0x5611ae[_0x2f0c('0x64')][_0x2f0c('0x85')];})['then'](function(){return db[_0x2f0c('0x44')][_0x2f0c('0x62')]({'where':{'id':_0x5611ae[_0x2f0c('0x6b')]['id']},'include':[{'model':db[_0x2f0c('0x8b')],'as':_0x2f0c('0x8c'),'include':[{'model':db[_0x2f0c('0x7b')],'as':'Contacts','where':_0x521d5d,'limit':0x1,'order':[[_0x2f0c('0x7f'),_0x2f0c('0x8d')]]}]},{'model':db[_0x2f0c('0x8e')],'as':'Applications'}]});})[_0x2f0c('0x25')](handleEntityNotFound(_0x50b430,null))[_0x2f0c('0x25')](function(_0x46f88d){if(_0x46f88d&&_0x46f88d['List']){_0x4f99d4[_0x2f0c('0x8f')]=_0x46f88d;_0x4f99d4['applications']=_0x46f88d[_0x2f0c('0x90')];_0x4f99d4[_0x2f0c('0x91')]=_0x46f88d['List'];_0x4f99d4[_0x2f0c('0x92')]=_[_0x2f0c('0x93')](_0x4f99d4[_0x2f0c('0x92')],[_0x2f0c('0x94')],[_0x2f0c('0x95')]);if(_0x4f99d4[_0x2f0c('0x8f')][_0x2f0c('0x90')]){delete _0x4f99d4[_0x2f0c('0x8f')][_0x2f0c('0x90')];}if(_0x4f99d4['account'][_0x2f0c('0x8c')]&&_0x4f99d4[_0x2f0c('0x8f')][_0x2f0c('0x8c')][_0x2f0c('0x96')][_0x2f0c('0x5f')]){return _0x4f99d4[_0x2f0c('0x8f')][_0x2f0c('0x8c')][_0x2f0c('0x96')][0x0];}var _0x1cd5cd=_[_0x2f0c('0x1d')](_0x5611ae[_0x2f0c('0x64')],{'firstName':_0x5611ae['body'][_0x2f0c('0x85')],'ListId':_0x46f88d[_0x2f0c('0x83')]});_0x1cd5cd[_0x5611ae[_0x2f0c('0x64')]['mapKey']]=_0x5611ae['body'][_0x2f0c('0x85')];return db[_0x2f0c('0x7b')][_0x2f0c('0x63')](_0x1cd5cd,{'fields':_0x31e28e,'raw':!![]});}})['then'](handleEntityNotFound(_0x50b430,null))['then'](function(_0xc523f2){_0x4f99d4[_0x2f0c('0x97')]=_0xc523f2;if(_0xc523f2){var _0x52d8d2={'ContactId':_0xc523f2['id'],'OpenchannelAccountId':_0x5611ae['params']['id'],'from':(_0xc523f2[_0x2f0c('0x98')]||'')+'\x20'+(_0xc523f2[_0x2f0c('0x99')]||'')};var _0x2781dd={'OpenchannelAccountId':_0x5611ae['params']['id'],'closed':![]};if(_0x5611ae[_0x2f0c('0x64')][_0x2f0c('0x9a')]){_0x2781dd[_0x2f0c('0x9a')]=_0x5611ae['body'][_0x2f0c('0x9a')];return db[_0x2f0c('0x9b')][_0x2f0c('0x62')]({'where':_0x2781dd})['then'](function(_0x552a66){if(_0x552a66){return[_0x552a66,![]];}_0x52d8d2['threadId']=_0x5611ae[_0x2f0c('0x64')]['threadId'];_0x52d8d2[_0x2f0c('0x9c')]=_0x5611ae[_0x2f0c('0x64')][_0x2f0c('0x9c')];return db[_0x2f0c('0x9b')][_0x2f0c('0x63')](_0x52d8d2)[_0x2f0c('0x25')](function(_0x1bbcdb){return[_0x1bbcdb,!![]];});});}else{_0x2781dd[_0x2f0c('0x9a')]=null;}_0x2781dd[_0x2f0c('0x9d')]=_0xc523f2['id'];return db['OpenchannelInteraction']['find']({'where':_0x2781dd})[_0x2f0c('0x25')](function(_0x561527){if(_0x561527){return[_0x561527,![]];}return db[_0x2f0c('0x9b')]['create'](_0x52d8d2)[_0x2f0c('0x25')](function(_0x24b3a3){return[_0x24b3a3,!![]];});});}})[_0x2f0c('0x9e')](function(_0x3234c5,_0x444c69){if(_0x3234c5){_0x2d814a=_0x444c69;if(!_0x444c69){var _0x2148f5={'from':(_0x4f99d4[_0x2f0c('0x97')][_0x2f0c('0x98')]||'')+'\x20'+(_0x4f99d4['contact'][_0x2f0c('0x99')]||'')};if(_0x5611ae['body']['threadId']&&_0x5611ae[_0x2f0c('0x64')][_0x2f0c('0x9f')]&&_0x5611ae['body'][_0x2f0c('0x9a')]!=_0x5611ae[_0x2f0c('0x64')][_0x2f0c('0x9f')]){_0x2148f5['threadId']=_0x5611ae[_0x2f0c('0x64')][_0x2f0c('0x9f')];}return _0x3234c5[_0x2f0c('0x3b')](_0x2148f5);}else{return _0x3234c5;}}})[_0x2f0c('0x25')](function(_0x209dce){_0x4f99d4[_0x2f0c('0xa0')]=_0x209dce[_0x2f0c('0x3c')]({'plain':!![]});_0x4f99d4['interaction']['created']=_0x2d814a;if(_0x4f99d4[_0x2f0c('0xa0')][_0x2f0c('0xa1')]){if(_0x4f99d4[_0x2f0c('0x8f')][_0x2f0c('0xa2')]){_0x4f99d4[_0x2f0c('0x92')][_0x2f0c('0xa3')]({'id':0x0,'priority':_0x4f99d4[_0x2f0c('0x92')][_0x2f0c('0x5f')]+0x1,'app':_0x2f0c('0xa4'),'appdata':_0x2f0c('0xa5'),'interval':_0x2f0c('0xa6')});}}return db[_0x2f0c('0xa7')][_0x2f0c('0x63')]({'body':_0x5611ae[_0x2f0c('0x64')][_0x2f0c('0x64')],'OpenchannelAccountId':_0x5611ae[_0x2f0c('0x6b')]['id'],'OpenchannelInteractionId':_0x209dce['id'],'direction':'in','ContactId':_0x4f99d4[_0x2f0c('0x97')]['id'],'AttachmentId':_0x5611ae[_0x2f0c('0x64')][_0x2f0c('0xa8')]});})[_0x2f0c('0x25')](function(_0x3d3a23){_0x4f99d4[_0x2f0c('0x2d')]=_0x3d3a23;if(!_0x4f99d4['interaction']['UserId'])return;return db[_0x2f0c('0xa9')][_0x2f0c('0x62')]({'attributes':['id','name'],'where':{'id':_0x4f99d4['interaction'][_0x2f0c('0xaa')]}});})['then'](function(_0x2a1c60){if(_0x2a1c60){_0x4f99d4[_0x2f0c('0x92')][_0x2f0c('0xab')]({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x2a1c60[_0x2f0c('0x40')]+','+(_0x4f99d4[_0x2f0c('0x8f')][_0x2f0c('0xac')]||0xa),'interval':_0x2f0c('0xa6')});}if(!_0x4f99d4[_0x2f0c('0xa0')][_0x2f0c('0xad')])return;return db['OpenchannelQueue'][_0x2f0c('0x62')]({'attributes':['id','name'],'where':{'id':_0x4f99d4[_0x2f0c('0xa0')][_0x2f0c('0xad')]}});})[_0x2f0c('0x25')](function(_0x25b94c){if(_0x25b94c){_0x4f99d4['applications'][_0x2f0c('0xab')]({'id':0x0,'priority':0x1,'app':_0x2f0c('0xae'),'appdata':_0x25b94c['name']+','+(_0x4f99d4[_0x2f0c('0x8f')][_0x2f0c('0xaf')]||0x12c),'interval':_0x2f0c('0xa6')});}return respondWithRpcPromise(_0x2f0c('0xb0'),_0x2f0c('0xb1'),_0x4f99d4);})[_0x2f0c('0x25')](function(_0x207693){respondWithRpcPromise(_0x2f0c('0xb2'),'EventManager',{'event':_0x2f0c('0x79'),'message':_0x207693},client9002);return _0x207693;})[_0x2f0c('0x25')](respondWithResult(_0x50b430,null))['catch'](handleError(_0x50b430,null));};exports['addApplications']=function(_0x42d40b,_0x21d932){var _0x4a36fd=_0x42d40b[_0x2f0c('0x6b')]['id'];var _0x3cf2cf=_0x42d40b[_0x2f0c('0x64')];var _0x4f85d4=0xc8;var _0x24e669=null;return db[_0x2f0c('0xb3')][_0x2f0c('0xb4')]({'isolationLevel':db[_0x2f0c('0xb3')][_0x2f0c('0xb5')][_0x2f0c('0xb6')]['READ_COMMITTED']},function(_0x3f1cd8){return db[_0x2f0c('0x44')][_0x2f0c('0x6f')]({'where':{'id':_0x4a36fd},'transaction':_0x3f1cd8})[_0x2f0c('0x25')](function(_0x244acc){if(_0x244acc){return db['OpenchannelApplication'][_0x2f0c('0x6c')]({'where':{'OpenchannelAccountId':_0x4a36fd},'transaction':_0x3f1cd8})[_0x2f0c('0x25')](function(){var _0x4780c3=_[_0x2f0c('0x48')](_0x3cf2cf,function(_0xa4f7f7){_0xa4f7f7[_0x2f0c('0x71')]=_0x4a36fd;return _0xa4f7f7;});return db['OpenchannelApplication'][_0x2f0c('0xb7')](_0x4780c3,{'transaction':_0x3f1cd8});});}else{_0x4f85d4=0x194;_0x24e669=[];}});})[_0x2f0c('0x25')](function(){if(_0x4f85d4!==0x194){return db[_0x2f0c('0x8e')][_0x2f0c('0xb8')]({'where':{'OpenchannelAccountId':_0x4a36fd},'order':'priority'})['then'](function(_0x19afdc){_0x24e669=_0x19afdc;});}})[_0x2f0c('0x5c')](function(_0xfae729){_0x4f85d4=0x1f4;logger[_0x2f0c('0x2b')](_0xfae729['stack']);if(_0xfae729[_0x2f0c('0x40')]){delete _0xfae729['name'];}_0x24e669=_0xfae729;})['finally'](function(){if(_0x24e669===null){_0x21d932[_0x2f0c('0x3e')](_0x4f85d4);}else{if(_0x4f85d4===0x1f4){_0x21d932[_0x2f0c('0x30')](_0x4f85d4)['send'](_0x24e669);}else{_0x21d932[_0x2f0c('0x30')](_0x4f85d4)[_0x2f0c('0x32')](_0x24e669);}}});};exports[_0x2f0c('0xb9')]=function(_0x60ee6b,_0x1a6851,_0x26e582){var _0x1c50f9={};var _0x54eef7={};var _0x314d93;var _0x32c46a;return db[_0x2f0c('0x44')][_0x2f0c('0x6f')]({'where':{'id':_0x60ee6b['params']['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x1a6851,null))[_0x2f0c('0x25')](function(_0x3e5f6b){if(_0x3e5f6b){_0x314d93=_0x3e5f6b;_0x54eef7[_0x2f0c('0x4c')]=_['keys'](db['OpenchannelApplication'][_0x2f0c('0x5e')]);_0x54eef7[_0x2f0c('0x49')]=_[_0x2f0c('0x4a')](_0x60ee6b[_0x2f0c('0x49')]);_0x54eef7[_0x2f0c('0x4b')]=_[_0x2f0c('0x4e')](_0x54eef7['model'],_0x54eef7[_0x2f0c('0x49')]);_0x1c50f9[_0x2f0c('0x4d')]=_['intersection'](_0x54eef7[_0x2f0c('0x4c')],qs['fields'](_0x60ee6b[_0x2f0c('0x49')][_0x2f0c('0x4f')]));_0x1c50f9[_0x2f0c('0x4d')]=_0x1c50f9[_0x2f0c('0x4d')][_0x2f0c('0x5f')]?_0x1c50f9[_0x2f0c('0x4d')]:_0x54eef7[_0x2f0c('0x4c')];_0x1c50f9[_0x2f0c('0x77')]=qs['sort'](_0x60ee6b[_0x2f0c('0x49')][_0x2f0c('0x53')]);_0x1c50f9[_0x2f0c('0x54')]=qs['filters'](_[_0x2f0c('0x55')](_0x60ee6b[_0x2f0c('0x49')],_0x54eef7[_0x2f0c('0x4b')]));if(_0x60ee6b[_0x2f0c('0x49')][_0x2f0c('0x58')]){_0x1c50f9[_0x2f0c('0x54')]=_['merge'](_0x1c50f9['where'],{'$or':_[_0x2f0c('0x48')](_0x1c50f9[_0x2f0c('0x4d')],function(_0x1f58e5){var _0x3b0f47={};_0x3b0f47[_0x1f58e5]={'$like':'%'+_0x60ee6b[_0x2f0c('0x49')]['filter']+'%'};return _0x3b0f47;})});}_0x1c50f9=_[_0x2f0c('0x56')]({},_0x1c50f9,_0x60ee6b[_0x2f0c('0x61')]);return _0x314d93[_0x2f0c('0xb9')](_0x1c50f9);}})[_0x2f0c('0x25')](function(_0x22fed0){if(_0x22fed0){_0x32c46a=_0x22fed0[_0x2f0c('0x5f')];if(!_0x60ee6b[_0x2f0c('0x49')][_0x2f0c('0x50')](_0x2f0c('0x51'))){_0x1c50f9[_0x2f0c('0x52')]=qs[_0x2f0c('0x52')](_0x60ee6b[_0x2f0c('0x49')][_0x2f0c('0x52')]);_0x1c50f9[_0x2f0c('0x33')]=qs['offset'](_0x60ee6b[_0x2f0c('0x49')][_0x2f0c('0x33')]);}return _0x314d93[_0x2f0c('0xb9')](_0x1c50f9);}})[_0x2f0c('0x25')](function(_0x518a3d){if(_0x518a3d){return _0x518a3d?{'count':_0x32c46a,'rows':_0x518a3d}:null;}})[_0x2f0c('0x25')](respondWithResult(_0x1a6851,null))[_0x2f0c('0x5c')](handleError(_0x1a6851,null));};exports[_0x2f0c('0xba')]=function(_0x19bef0,_0x2bae4,_0x4ee084){var _0x13af5e={'raw':![],'where':{}};var _0x15c533={};var _0xda0725={'count':0x0,'rows':[]};return db[_0x2f0c('0x44')][_0x2f0c('0x6f')]({'where':{'id':_0x19bef0['params']['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x2bae4,null))[_0x2f0c('0x25')](function(_0x3ece57){if(_0x3ece57){_0x15c533['model']=_['keys'](db[_0x2f0c('0x9b')]['rawAttributes']);_0x15c533[_0x2f0c('0x49')]=_[_0x2f0c('0x4a')](_0x19bef0[_0x2f0c('0x49')]);_0x15c533[_0x2f0c('0x4b')]=_[_0x2f0c('0x4e')](_0x15c533[_0x2f0c('0x4c')],_0x15c533[_0x2f0c('0x49')]);_0x13af5e[_0x2f0c('0x4d')]=_[_0x2f0c('0x4e')](_0x15c533['model'],qs[_0x2f0c('0x4f')](_0x19bef0[_0x2f0c('0x49')][_0x2f0c('0x4f')]));_0x13af5e['attributes']=_0x13af5e[_0x2f0c('0x4d')]['length']?_0x13af5e['attributes']:_0x15c533['model'];if(!_0x19bef0[_0x2f0c('0x49')][_0x2f0c('0x50')]('nolimit')){_0x13af5e[_0x2f0c('0x52')]=qs['limit'](_0x19bef0[_0x2f0c('0x49')][_0x2f0c('0x52')]);_0x13af5e[_0x2f0c('0x33')]=qs[_0x2f0c('0x33')](_0x19bef0[_0x2f0c('0x49')][_0x2f0c('0x33')]);}_0x13af5e['order']=qs[_0x2f0c('0x53')](_0x19bef0[_0x2f0c('0x49')][_0x2f0c('0x53')]);_0x13af5e['where']=qs[_0x2f0c('0x4b')](_[_0x2f0c('0x55')](_0x19bef0[_0x2f0c('0x49')],_0x15c533[_0x2f0c('0x4b')]));_0x13af5e[_0x2f0c('0x54')]['OpenchannelAccountId']=_0x3ece57['id'];if(_0x19bef0[_0x2f0c('0x49')][_0x2f0c('0x58')]){_0x13af5e[_0x2f0c('0x54')]=_[_0x2f0c('0x56')](_0x13af5e[_0x2f0c('0x54')],{'$or':_[_0x2f0c('0x48')](_0x13af5e[_0x2f0c('0x4d')],function(_0x2c65cc){var _0x579a33={};_0x579a33[_0x2c65cc]={'$like':'%'+_0x19bef0[_0x2f0c('0x49')]['filter']+'%'};return _0x579a33;})});}_0x13af5e=_['merge']({},_0x13af5e,_0x19bef0[_0x2f0c('0x61')]);return db['OpenchannelInteraction'][_0x2f0c('0x35')]({'where':_0x13af5e[_0x2f0c('0x54')]})[_0x2f0c('0x25')](function(_0x41e0ed){_0xda0725[_0x2f0c('0x35')]=_0x41e0ed;if(_0x19bef0[_0x2f0c('0x49')][_0x2f0c('0x60')]){_0x13af5e[_0x2f0c('0x59')]=[{'model':db[_0x2f0c('0x7b')],'as':'Contact','required':![]},{'model':db[_0x2f0c('0xa9')],'as':_0x2f0c('0xbb'),'attributes':[_0x2f0c('0x40'),_0x2f0c('0xbc'),_0x2f0c('0xbd')],'required':![]},{'model':db[_0x2f0c('0xbe')],'as':_0x2f0c('0xbf'),'attributes':['id',_0x2f0c('0x40'),'color'],'where':_0x19bef0['query'][_0x2f0c('0xc0')]?{'id':_0x19bef0[_0x2f0c('0x49')][_0x2f0c('0xc0')]}:undefined,'required':_0x19bef0[_0x2f0c('0x49')][_0x2f0c('0xc0')]?!![]:![]}];}return db[_0x2f0c('0x9b')][_0x2f0c('0x5a')](_0x13af5e);})['then'](function(_0x3aec14){_0xda0725[_0x2f0c('0x5b')]=_0x3aec14;return _0xda0725;});}})[_0x2f0c('0x25')](respondWithFilteredResult(_0x2bae4,_0x13af5e))[_0x2f0c('0x5c')](handleError(_0x2bae4,null));};exports[_0x2f0c('0xc1')]=function(_0x3faf73,_0x3e6d77,_0x63b9d1){return db['OpenchannelAccount'][_0x2f0c('0x62')]({'where':{'id':_0x3faf73[_0x2f0c('0x6b')]['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x3e6d77,null))[_0x2f0c('0x25')](function(_0x4314d9){if(_0x4314d9){return _0x4314d9[_0x2f0c('0xc1')](_0x3faf73[_0x2f0c('0x64')]['ids'],_[_0x2f0c('0xc2')](_0x3faf73[_0x2f0c('0x64')],['ids','id'])||{})['spread'](function(_0x386860){for(var _0x3681b7=0x0;_0x3681b7<_0x3faf73[_0x2f0c('0x64')]['ids']['length'];_0x3681b7+=0x1){socket['emit'](_0x2f0c('0xc3'),{'UserId':Number(_0x3faf73[_0x2f0c('0x64')]['ids'][_0x3681b7]),'OpenchannelAccountId':Number(_0x3faf73[_0x2f0c('0x6b')]['id'])});}return _0x386860;});}})['then'](respondWithResult(_0x3e6d77,null))[_0x2f0c('0x5c')](handleError(_0x3e6d77,null));};exports['removeAgents']=function(_0x3513f1,_0x103b29,_0x194e42){return db[_0x2f0c('0x44')][_0x2f0c('0x62')]({'where':{'id':_0x3513f1[_0x2f0c('0x6b')]['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x103b29,null))[_0x2f0c('0x25')](function(_0x28e1dc){if(_0x28e1dc){return _0x28e1dc[_0x2f0c('0xc4')](_0x3513f1['query'][_0x2f0c('0x73')])[_0x2f0c('0x25')](function(){if(_[_0x2f0c('0xc5')](_0x3513f1[_0x2f0c('0x49')]['ids'])){for(var _0x4b725d=0x0;_0x4b725d<_0x3513f1[_0x2f0c('0x49')][_0x2f0c('0x73')][_0x2f0c('0x5f')];_0x4b725d+=0x1){socket[_0x2f0c('0xc6')](_0x2f0c('0xc7'),{'UserId':Number(_0x3513f1[_0x2f0c('0x49')][_0x2f0c('0x73')][_0x4b725d]),'OpenchannelAccountId':Number(_0x3513f1[_0x2f0c('0x6b')]['id'])});}}else{socket['emit'](_0x2f0c('0xc7'),{'UserId':Number(_0x3513f1[_0x2f0c('0x49')][_0x2f0c('0x73')]),'OpenchannelAccountId':Number(_0x3513f1[_0x2f0c('0x6b')]['id'])});}});}})[_0x2f0c('0x25')](respondWithStatusCode(_0x103b29,null))[_0x2f0c('0x5c')](handleError(_0x103b29,null));};exports[_0x2f0c('0xc8')]=function(_0x490294,_0x15e876,_0xa14ba0){var _0x3057c5={};var _0x29a38c={};var _0xd08acf;var _0x2b7608;return db['OpenchannelAccount'][_0x2f0c('0x6f')]({'where':{'id':_0x490294['params']['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x15e876,null))[_0x2f0c('0x25')](function(_0x2aa0aa){if(_0x2aa0aa){_0xd08acf=_0x2aa0aa;_0x29a38c[_0x2f0c('0x4c')]=_[_0x2f0c('0x4a')](db[_0x2f0c('0xa9')]['rawAttributes']);_0x29a38c[_0x2f0c('0x49')]=_[_0x2f0c('0x4a')](_0x490294[_0x2f0c('0x49')]);_0x29a38c[_0x2f0c('0x4b')]=_['intersection'](_0x29a38c['model'],_0x29a38c[_0x2f0c('0x49')]);_0x3057c5[_0x2f0c('0x4d')]=_[_0x2f0c('0x4e')](_0x29a38c[_0x2f0c('0x4c')],qs[_0x2f0c('0x4f')](_0x490294['query'][_0x2f0c('0x4f')]));_0x3057c5[_0x2f0c('0x4d')]=_0x3057c5[_0x2f0c('0x4d')][_0x2f0c('0x5f')]?_0x3057c5[_0x2f0c('0x4d')]:_0x29a38c[_0x2f0c('0x4c')];_0x3057c5[_0x2f0c('0x77')]=qs['sort'](_0x490294['query'][_0x2f0c('0x53')]);_0x3057c5[_0x2f0c('0x54')]=qs[_0x2f0c('0x4b')](_['pick'](_0x490294['query'],_0x29a38c[_0x2f0c('0x4b')]));if(_0x490294[_0x2f0c('0x49')][_0x2f0c('0x58')]){_0x3057c5[_0x2f0c('0x54')]=_[_0x2f0c('0x56')](_0x3057c5[_0x2f0c('0x54')],{'$or':_[_0x2f0c('0x48')](_0x3057c5[_0x2f0c('0x4d')],function(_0x5dca15){var _0x471da9={};_0x471da9[_0x5dca15]={'$like':'%'+_0x490294['query'][_0x2f0c('0x58')]+'%'};return _0x471da9;})});}_0x3057c5=_[_0x2f0c('0x56')]({},_0x3057c5,_0x490294[_0x2f0c('0x61')]);return _0xd08acf[_0x2f0c('0xc8')](_0x3057c5);}})['then'](function(_0x9711c0){if(_0x9711c0){_0x2b7608=_0x9711c0['length'];if(!_0x490294['query'][_0x2f0c('0x50')](_0x2f0c('0x51'))){_0x3057c5[_0x2f0c('0x52')]=qs[_0x2f0c('0x52')](_0x490294['query']['limit']);_0x3057c5[_0x2f0c('0x33')]=qs[_0x2f0c('0x33')](_0x490294[_0x2f0c('0x49')][_0x2f0c('0x33')]);}return _0xd08acf[_0x2f0c('0xc8')](_0x3057c5);}})[_0x2f0c('0x25')](function(_0x20a836){if(_0x20a836){return _0x20a836?{'count':_0x2b7608,'rows':_0x20a836}:null;}})[_0x2f0c('0x25')](respondWithResult(_0x15e876,null))['catch'](handleError(_0x15e876,null));};exports['send']=function(_0x4547bb,_0x41e150,_0x2de7ab){var _0x37d41d,_0x4e0229,_0x3eef81;if(_['isNil'](_0x4547bb[_0x2f0c('0x64')][_0x2f0c('0x64')])||_0x4547bb[_0x2f0c('0x64')][_0x2f0c('0x64')]===''){throw new db[(_0x2f0c('0x7c'))][(_0x2f0c('0x7d'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x2f0c('0x84')](_0x4547bb[_0x2f0c('0x64')]['to'])){}_0x37d41d=_0x4547bb[_0x2f0c('0x64')]['to'];return db['OpenchannelAccount'][_0x2f0c('0x6f')]({'where':{'id':_0x4547bb[_0x2f0c('0x6b')]['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x41e150,null))[_0x2f0c('0x25')](function(_0x2e3ce4){if(_0x2e3ce4){return db[_0x2f0c('0x44')][_0x2f0c('0x62')]({'where':{'id':_0x2e3ce4['id']},'include':[{'model':db[_0x2f0c('0x8b')],'as':_0x2f0c('0x8c'),'include':[{'model':db[_0x2f0c('0x7b')],'as':_0x2f0c('0x96'),'where':{[_0x2e3ce4[_0x2f0c('0x87')]]:_0x37d41d},'limit':0x1,'order':[[_0x2f0c('0x7f'),'DESC']]}]}]})[_0x2f0c('0x25')](handleEntityNotFound(_0x41e150,null))['then'](function(_0x5c1b0c){if(_0x5c1b0c&&_0x5c1b0c[_0x2f0c('0x8c')]){_0x4e0229=_0x5c1b0c[_0x2f0c('0x3c')]({'plain':!![]});if(_0x4e0229[_0x2f0c('0x8c')]&&_0x4e0229[_0x2f0c('0x8c')][_0x2f0c('0x96')][_0x2f0c('0x5f')]){return _0x4e0229[_0x2f0c('0x8c')][_0x2f0c('0x96')][0x0];}return db[_0x2f0c('0x7b')][_0x2f0c('0x63')](_[_0x2f0c('0x1d')](_0x4547bb[_0x2f0c('0x64')],{'firstName':_0x37d41d,[_0x5c1b0c['mapKey']]:_0x37d41d,'phone':_0x37d41d,'ListId':_0x4e0229[_0x2f0c('0x83')]}));}})[_0x2f0c('0x25')](handleEntityNotFound(_0x41e150,null))['then'](function(_0x4e3988){if(_0x4e3988){_0x3eef81=_0x4e3988;return db[_0x2f0c('0x9b')][_0x2f0c('0x62')]({'where':{'ContactId':_0x3eef81['id'],'closed':![],'OpenchannelAccountId':_0x4e0229['id']}})['then'](function(_0x4f9657){if(_0x4f9657){return[_0x4f9657,![]];}return db[_0x2f0c('0x9b')]['create']({'UserId':_0x4547bb[_0x2f0c('0x65')]['id'],'ContactId':_0x3eef81['id'],'OpenchannelAccountId':_0x4e0229['id'],'lastMsgDirection':'out','firstMsgDirection':'out','Messages':[_[_0x2f0c('0x56')](_0x4547bb['body'],{'read':![],'body':_0x4547bb[_0x2f0c('0x64')][_0x2f0c('0x64')],'OpenchannelAccountId':_0x4e0229['id'],'UserId':_0x4547bb['user']['id'],'ContactId':_0x3eef81['id']})]},{'include':[{'model':db['OpenchannelMessage'],'as':_0x2f0c('0xc9')}]})[_0x2f0c('0x25')](function(_0x19ab23){return[_0x19ab23,!![]];});});}})[_0x2f0c('0x9e')](function(_0x102c0d,_0x378723){if(_0x378723){return _0x102c0d;}return db[_0x2f0c('0xa7')][_0x2f0c('0x63')](_['merge'](_0x4547bb[_0x2f0c('0x64')],{'read':![],'body':_0x4547bb[_0x2f0c('0x64')][_0x2f0c('0x64')],'OpenchannelAccountId':_0x4e0229['id'],'OpenchannelInteractionId':_0x102c0d['id'],'UserId':_0x4547bb[_0x2f0c('0x65')]['id'],'ContactId':_0x3eef81['id']}))[_0x2f0c('0x25')](function(_0x3e8d32){_0x102c0d[_0x2f0c('0xca')]['Messages']=[];_0x102c0d['dataValues'][_0x2f0c('0xc9')][_0x2f0c('0xa3')](_0x3e8d32[_0x2f0c('0xca')]);return _0x102c0d;});});}})[_0x2f0c('0x25')](respondWithResult(_0x41e150,null))[_0x2f0c('0x5c')](handleError(_0x41e150,null));};