b7ffd7e371746a86d7161b3d8c45f38dc6f1069e
[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 _0x06b1=['OpenchannelAccountId','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','notify','openchannel','CmContact','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','ListId','isNil','Sequelize','from\x20is\x20mandatory','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','DESC','OpenchannelApplication','List','Applications','list','orderBy','applications','priority','asc','account','Contacts','from','contact','firstName','lastName','threadId','externalUrl','OpenchannelInteraction','ContactId','spread','messageId','interaction','created','autoclose','close','unmanaged','OpenchannelMessage','UserId','waitForTheAssignedAgent','forcedOwnership','Start','startRouting','EventManager','addApplications','sequelize','transaction','bulkCreate','findAndCountAll','getApplications','getInteractions','Contact','User','fullname','internal','Tag','color','tag','addAgents','omit','userOpenchannelAccount:save','emit','userOpenchannelAccount:remove','getAgents','body\x20is\x20mandatory\x20and\x20not\x20empty','out','Messages','push','dataValues','rimraf','request-promise','bluebird','mustache','util','path','sox','ejs','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','socket.io-emitter','jayson/promise','client','http','request','then','info','OpenchannelAccount,\x20%s,\x20%s','debug','OpenchannelAccount,\x20%s,\x20%s,\x20%s','request\x20sent','error','code','message','result','catch','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','destroy','get','OpenchannelAccounts','UserProfileResource','name','send','mandatoryDispositionPause','map','OpenchannelAccount','rawAttributes','fieldName','type','query','keys','intersection','model','fields','attributes','length','nolimit','sort','where','filters','pick','filter','VIRTUAL','merge','options','include','findAll','rows','show','Pause','includeAll','find','create','user','role','UserProfileSection','userProfileId','autoAssociation','body','params','describe','addDisposition','getDispositions','findOne','Disposition','hasOwnProperty','order'];(function(_0x2dafbe,_0x5d04de){var _0x58a45a=function(_0x50ac96){while(--_0x50ac96){_0x2dafbe['push'](_0x2dafbe['shift']());}};_0x58a45a(++_0x5d04de);}(_0x06b1,0x10d));var _0x106b=function(_0x32d4b9,_0x33df83){_0x32d4b9=_0x32d4b9-0x0;var _0x2ab656=_0x06b1[_0x32d4b9];return _0x2ab656;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x106b('0x0'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x106b('0x1'));var moment=require('moment');var BPromise=require(_0x106b('0x2'));var Mustache=require(_0x106b('0x3'));var util=require(_0x106b('0x4'));var path=require(_0x106b('0x5'));var sox=require(_0x106b('0x6'));var csv=require('to-csv');var ejs=require(_0x106b('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x106b('0x8'));var crypto=require(_0x106b('0x9'));var jsforce=require(_0x106b('0xa'));var deskjs=require(_0x106b('0xb'));var toCsv=require(_0x106b('0xc'));var querystring=require(_0x106b('0xd'));var Papa=require(_0x106b('0xe'));var Redis=require(_0x106b('0xf'));var authService=require('../../components/auth/service');var qs=require(_0x106b('0x10'));var as=require(_0x106b('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x106b('0x12'))('api');var utils=require(_0x106b('0x13'));var config=require(_0x106b('0x14'));var licenseUtil=require(_0x106b('0x15'));var db=require(_0x106b('0x16'))['db'];config[_0x106b('0x17')]=_[_0x106b('0x18')](config[_0x106b('0x17')],{'host':'localhost','port':0x18eb});var socket=require(_0x106b('0x19'))(new Redis(config[_0x106b('0x17')]));require('./openchannelAccount.socket')['register'](socket);var jayson=require(_0x106b('0x1a'));var client=jayson[_0x106b('0x1b')]['http']({'port':0x232c});var client9002=jayson['client'][_0x106b('0x1c')]({'port':0x232a});function respondWithRpcPromise(_0x45675f,_0x28c4e3,_0x333c01,_0x550e27){return new BPromise(function(_0x5b9983,_0x56228a){var _0x4525a0=_0x550e27||client;return _0x4525a0[_0x106b('0x1d')](_0x45675f,_0x333c01)[_0x106b('0x1e')](function(_0x87dfa3){logger[_0x106b('0x1f')](_0x106b('0x20'),_0x28c4e3,'request\x20sent');logger[_0x106b('0x21')](_0x106b('0x22'),_0x28c4e3,_0x106b('0x23'),JSON['stringify'](_0x87dfa3));if(_0x87dfa3[_0x106b('0x24')]){if(_0x87dfa3[_0x106b('0x24')][_0x106b('0x25')]===0x1f4){logger[_0x106b('0x24')](_0x106b('0x20'),_0x28c4e3,_0x87dfa3[_0x106b('0x24')][_0x106b('0x26')]);return _0x56228a(_0x87dfa3[_0x106b('0x24')][_0x106b('0x26')]);}logger['error'](_0x106b('0x20'),_0x28c4e3,_0x87dfa3[_0x106b('0x24')]['message']);return _0x5b9983(_0x87dfa3['error']['message']);}else{logger[_0x106b('0x1f')](_0x106b('0x20'),_0x28c4e3,_0x106b('0x23'));_0x5b9983(_0x87dfa3[_0x106b('0x27')][_0x106b('0x26')]);}})[_0x106b('0x28')](function(_0x16504e){logger[_0x106b('0x24')](_0x106b('0x20'),_0x28c4e3,_0x16504e);_0x56228a(_0x16504e);});});}function respondWithStatusCode(_0x8c102a,_0x89b119){_0x89b119=_0x89b119||0xcc;return function(_0x5f368f){if(_0x5f368f){return _0x8c102a[_0x106b('0x29')](_0x89b119);}return _0x8c102a[_0x106b('0x2a')](_0x89b119)[_0x106b('0x2b')]();};}function respondWithResult(_0x4368c0,_0x3f2482){_0x3f2482=_0x3f2482||0xc8;return function(_0x448b3c){if(_0x448b3c){return _0x4368c0[_0x106b('0x2a')](_0x3f2482)[_0x106b('0x2c')](_0x448b3c);}};}function respondWithFilteredResult(_0x19c172,_0x2bdaff){return function(_0x454fca){if(_0x454fca){var _0x11921b=typeof _0x2bdaff[_0x106b('0x2d')]===_0x106b('0x2e')&&typeof _0x2bdaff[_0x106b('0x2f')]===_0x106b('0x2e');var _0x207605=_0x454fca[_0x106b('0x30')];var _0xf73ca5=_0x11921b?0x0:_0x2bdaff[_0x106b('0x2d')];var _0x21d300=_0x11921b?_0x454fca[_0x106b('0x30')]:_0x2bdaff[_0x106b('0x2d')]+_0x2bdaff[_0x106b('0x2f')];var _0x3c372b;if(_0x21d300>=_0x207605){_0x21d300=_0x207605;_0x3c372b=0xc8;}else{_0x3c372b=0xce;}_0x19c172[_0x106b('0x2a')](_0x3c372b);return _0x19c172[_0x106b('0x31')](_0x106b('0x32'),_0xf73ca5+'-'+_0x21d300+'/'+_0x207605)['json'](_0x454fca);}return null;};}function patchUpdates(_0x448090){return function(_0x2598b6){try{jsonpatch[_0x106b('0x33')](_0x2598b6,_0x448090,!![]);}catch(_0x4cf62e){return BPromise[_0x106b('0x34')](_0x4cf62e);}return _0x2598b6[_0x106b('0x35')]();};}function saveUpdates(_0x454dae,_0x556d83){return function(_0x1c8aa4){if(_0x1c8aa4){return _0x1c8aa4[_0x106b('0x36')](_0x454dae)[_0x106b('0x1e')](function(_0x5f49b1){return _0x5f49b1;});}return null;};}function removeEntity(_0x5e65c1,_0x14ca28){return function(_0x2ac9e2){if(_0x2ac9e2){return _0x2ac9e2[_0x106b('0x37')]()[_0x106b('0x1e')](function(){var _0x1ebd87=_0x2ac9e2[_0x106b('0x38')]({'plain':!![]});var _0x3a73a7=_0x106b('0x39');return db[_0x106b('0x3a')][_0x106b('0x37')]({'where':{'type':_0x3a73a7,'resourceId':_0x1ebd87['id']}})['then'](function(){return _0x2ac9e2;});})[_0x106b('0x1e')](function(){_0x5e65c1[_0x106b('0x2a')](0xcc)[_0x106b('0x2b')]();});}};}function handleEntityNotFound(_0x50c607,_0x148163){return function(_0x32cf6c){if(!_0x32cf6c){_0x50c607[_0x106b('0x29')](0x194);}return _0x32cf6c;};}function handleError(_0x477be7,_0x386a02){_0x386a02=_0x386a02||0x1f4;return function(_0x3a449a){logger[_0x106b('0x24')](_0x3a449a['stack']);if(_0x3a449a[_0x106b('0x3b')]){delete _0x3a449a['name'];}_0x477be7['status'](_0x386a02)[_0x106b('0x3c')](_0x3a449a);};}exports['index']=function(_0xf5f90d,_0x19a71e){var _0x4d4811={'include':[{'model':db['Pause'],'as':_0x106b('0x3d')}]},_0x1dddd1={},_0xbc1f25={'count':0x0,'rows':[]};var _0x571089=_[_0x106b('0x3e')](db[_0x106b('0x3f')][_0x106b('0x40')],function(_0x317da7){return{'name':_0x317da7[_0x106b('0x41')],'type':_0x317da7[_0x106b('0x42')]['key']};});_0x1dddd1['model']=_[_0x106b('0x3e')](_0x571089,_0x106b('0x3b'));_0x1dddd1[_0x106b('0x43')]=_[_0x106b('0x44')](_0xf5f90d[_0x106b('0x43')]);_0x1dddd1['filters']=_[_0x106b('0x45')](_0x1dddd1[_0x106b('0x46')],_0x1dddd1['query']);_0x4d4811['attributes']=_['intersection'](_0x1dddd1['model'],qs[_0x106b('0x47')](_0xf5f90d[_0x106b('0x43')]['fields']));_0x4d4811[_0x106b('0x48')]=_0x4d4811[_0x106b('0x48')][_0x106b('0x49')]?_0x4d4811['attributes']:_0x1dddd1[_0x106b('0x46')];if(!_0xf5f90d[_0x106b('0x43')]['hasOwnProperty'](_0x106b('0x4a'))){_0x4d4811[_0x106b('0x2f')]=qs[_0x106b('0x2f')](_0xf5f90d['query']['limit']);_0x4d4811[_0x106b('0x2d')]=qs[_0x106b('0x2d')](_0xf5f90d['query'][_0x106b('0x2d')]);}_0x4d4811['order']=qs['sort'](_0xf5f90d[_0x106b('0x43')][_0x106b('0x4b')]);_0x4d4811[_0x106b('0x4c')]=qs[_0x106b('0x4d')](_[_0x106b('0x4e')](_0xf5f90d[_0x106b('0x43')],_0x1dddd1[_0x106b('0x4d')]),_0x571089);if(_0xf5f90d[_0x106b('0x43')][_0x106b('0x4f')]){_0x4d4811[_0x106b('0x4c')]=_['merge'](_0x4d4811['where'],{'$or':_[_0x106b('0x3e')](_0x571089,function(_0x2da1b6){if(_0x2da1b6[_0x106b('0x42')]!==_0x106b('0x50')){var _0x17d66b={};_0x17d66b[_0x2da1b6['name']]={'$like':'%'+_0xf5f90d['query'][_0x106b('0x4f')]+'%'};return _0x17d66b;}})});}_0x4d4811=_[_0x106b('0x51')]({},_0x4d4811,_0xf5f90d[_0x106b('0x52')]);var _0x55b651={'where':_0x4d4811['where']};return db[_0x106b('0x3f')][_0x106b('0x30')](_0x55b651)['then'](function(_0x2e7421){_0xbc1f25['count']=_0x2e7421;if(_0xf5f90d['query']['includeAll']){_0x4d4811[_0x106b('0x53')]=[{'all':!![]}];}return db[_0x106b('0x3f')][_0x106b('0x54')](_0x4d4811);})[_0x106b('0x1e')](function(_0x25ac1b){_0xbc1f25[_0x106b('0x55')]=_0x25ac1b;return _0xbc1f25;})[_0x106b('0x1e')](respondWithFilteredResult(_0x19a71e,_0x4d4811))[_0x106b('0x28')](handleError(_0x19a71e,null));};exports[_0x106b('0x56')]=function(_0x3ba6ef,_0x3c850c){var _0x910561={'raw':![],'where':{'id':_0x3ba6ef['params']['id']},'include':[{'model':db[_0x106b('0x57')],'as':'mandatoryDispositionPause'}]},_0x2387a1={};_0x2387a1[_0x106b('0x46')]=_[_0x106b('0x44')](db['OpenchannelAccount'][_0x106b('0x40')]);_0x2387a1[_0x106b('0x43')]=_['keys'](_0x3ba6ef[_0x106b('0x43')]);_0x2387a1[_0x106b('0x4d')]=_[_0x106b('0x45')](_0x2387a1[_0x106b('0x46')],_0x2387a1[_0x106b('0x43')]);_0x910561[_0x106b('0x48')]=_[_0x106b('0x45')](_0x2387a1['model'],qs[_0x106b('0x47')](_0x3ba6ef['query'][_0x106b('0x47')]));_0x910561[_0x106b('0x48')]=_0x910561[_0x106b('0x48')][_0x106b('0x49')]?_0x910561[_0x106b('0x48')]:_0x2387a1[_0x106b('0x46')];if(_0x3ba6ef['query'][_0x106b('0x58')]){_0x910561['include']=[{'all':!![]}];}_0x910561=_['merge']({},_0x910561,_0x3ba6ef[_0x106b('0x52')]);return db['OpenchannelAccount'][_0x106b('0x59')](_0x910561)[_0x106b('0x1e')](handleEntityNotFound(_0x3c850c,null))[_0x106b('0x1e')](respondWithResult(_0x3c850c,null))[_0x106b('0x28')](handleError(_0x3c850c,null));};exports[_0x106b('0x5a')]=function(_0x35e9fa,_0x1d59fb){return db[_0x106b('0x3f')][_0x106b('0x5a')](_0x35e9fa['body'],{})[_0x106b('0x1e')](function(_0x6b63a7){var _0x5a1f22=_0x35e9fa[_0x106b('0x5b')][_0x106b('0x38')]({'plain':!![]});if(!_0x5a1f22)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x5a1f22[_0x106b('0x5c')]==='user'){var _0x2a030c=_0x6b63a7[_0x106b('0x38')]({'plain':!![]});var _0x402567=_0x106b('0x39');return db[_0x106b('0x5d')]['find']({'where':{'name':_0x402567,'userProfileId':_0x5a1f22[_0x106b('0x5e')]},'raw':!![]})['then'](function(_0x41aa5b){if(_0x41aa5b&&_0x41aa5b[_0x106b('0x5f')]===0x0){return db[_0x106b('0x3a')][_0x106b('0x5a')]({'name':_0x2a030c['name'],'resourceId':_0x2a030c['id'],'type':_0x41aa5b['name'],'sectionId':_0x41aa5b['id']},{})[_0x106b('0x1e')](function(){return _0x6b63a7;});}else{return _0x6b63a7;}})[_0x106b('0x28')](function(_0x43abd4){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x43abd4);throw _0x43abd4;});}return _0x6b63a7;})[_0x106b('0x1e')](respondWithResult(_0x1d59fb,0xc9))[_0x106b('0x28')](handleError(_0x1d59fb,null));};exports[_0x106b('0x36')]=function(_0x32dc5b,_0x3a94de){if(_0x32dc5b['body']['id']){delete _0x32dc5b[_0x106b('0x60')]['id'];}return db[_0x106b('0x3f')][_0x106b('0x59')]({'where':{'id':_0x32dc5b['params']['id']},'include':[{'model':db[_0x106b('0x57')],'as':_0x106b('0x3d')}]})[_0x106b('0x1e')](handleEntityNotFound(_0x3a94de,null))[_0x106b('0x1e')](saveUpdates(_0x32dc5b[_0x106b('0x60')],null))['then'](respondWithResult(_0x3a94de,null))['catch'](handleError(_0x3a94de,null));};exports[_0x106b('0x37')]=function(_0x564b09,_0x53b33f){return db[_0x106b('0x3f')][_0x106b('0x59')]({'where':{'id':_0x564b09[_0x106b('0x61')]['id']}})[_0x106b('0x1e')](handleEntityNotFound(_0x53b33f,null))[_0x106b('0x1e')](removeEntity(_0x53b33f,null))[_0x106b('0x28')](handleError(_0x53b33f,null));};exports[_0x106b('0x62')]=function(_0xfd9eb,_0x242354){return db[_0x106b('0x3f')][_0x106b('0x62')]()['then'](respondWithResult(_0x242354,null))['catch'](handleError(_0x242354,null));};exports[_0x106b('0x63')]=function(_0x3ae3ea,_0x5c21e5,_0x4efcec){if(_0x3ae3ea['body']['id']){delete _0x3ae3ea[_0x106b('0x60')]['id'];}return db[_0x106b('0x3f')][_0x106b('0x59')]({'where':{'id':_0x3ae3ea[_0x106b('0x61')]['id']}})[_0x106b('0x1e')](handleEntityNotFound(_0x5c21e5,null))[_0x106b('0x1e')](function(_0x3ce105){if(_0x3ce105){_0x3ae3ea[_0x106b('0x60')]['OpenchannelAccountId']=_0x3ce105['id'];return db['Disposition']['create'](_0x3ae3ea[_0x106b('0x60')]);}})['then'](respondWithResult(_0x5c21e5,null))['catch'](handleError(_0x5c21e5,null));};exports[_0x106b('0x64')]=function(_0x58705a,_0x443664,_0x2b5304){var _0x2e0f0e={'raw':![],'where':{}};var _0x2cf81d={};var _0x537e32={'count':0x0,'rows':[]};return db['OpenchannelAccount'][_0x106b('0x65')]({'where':{'id':_0x58705a[_0x106b('0x61')]['id']}})[_0x106b('0x1e')](handleEntityNotFound(_0x443664,null))[_0x106b('0x1e')](function(_0x4febb2){if(_0x4febb2){_0x2cf81d['model']=_[_0x106b('0x44')](db[_0x106b('0x66')][_0x106b('0x40')]);_0x2cf81d[_0x106b('0x43')]=_[_0x106b('0x44')](_0x58705a[_0x106b('0x43')]);_0x2cf81d[_0x106b('0x4d')]=_[_0x106b('0x45')](_0x2cf81d[_0x106b('0x46')],_0x2cf81d[_0x106b('0x43')]);_0x2e0f0e[_0x106b('0x48')]=_[_0x106b('0x45')](_0x2cf81d['model'],qs['fields'](_0x58705a[_0x106b('0x43')]['fields']));_0x2e0f0e['attributes']=_0x2e0f0e[_0x106b('0x48')][_0x106b('0x49')]?_0x2e0f0e[_0x106b('0x48')]:_0x2cf81d[_0x106b('0x46')];if(!_0x58705a[_0x106b('0x43')][_0x106b('0x67')](_0x106b('0x4a'))){_0x2e0f0e[_0x106b('0x2f')]=qs[_0x106b('0x2f')](_0x58705a[_0x106b('0x43')][_0x106b('0x2f')]);_0x2e0f0e[_0x106b('0x2d')]=qs[_0x106b('0x2d')](_0x58705a['query']['offset']);}_0x2e0f0e[_0x106b('0x68')]=qs[_0x106b('0x4b')](_0x58705a[_0x106b('0x43')][_0x106b('0x4b')]);_0x2e0f0e[_0x106b('0x4c')]=qs[_0x106b('0x4d')](_[_0x106b('0x4e')](_0x58705a[_0x106b('0x43')],_0x2cf81d[_0x106b('0x4d')]));_0x2e0f0e[_0x106b('0x4c')][_0x106b('0x69')]=_0x4febb2['id'];if(_0x58705a[_0x106b('0x43')][_0x106b('0x4f')]){_0x2e0f0e[_0x106b('0x4c')]=_[_0x106b('0x51')](_0x2e0f0e[_0x106b('0x4c')],{'$or':_[_0x106b('0x3e')](_0x2e0f0e[_0x106b('0x48')],function(_0xee1058){var _0x37200e={};_0x37200e[_0xee1058]={'$like':'%'+_0x58705a[_0x106b('0x43')][_0x106b('0x4f')]+'%'};return _0x37200e;})});}_0x2e0f0e=_[_0x106b('0x51')]({},_0x2e0f0e,_0x58705a['options']);return db['Disposition']['count']({'where':_0x2e0f0e[_0x106b('0x4c')]})[_0x106b('0x1e')](function(_0x214ae3){_0x537e32[_0x106b('0x30')]=_0x214ae3;if(_0x58705a[_0x106b('0x43')][_0x106b('0x58')]){_0x2e0f0e['include']=[{'all':!![]}];}return db['Disposition']['findAll'](_0x2e0f0e);})['then'](function(_0x2c2539){_0x537e32['rows']=_0x2c2539;return _0x537e32;});}})['then'](respondWithFilteredResult(_0x443664,_0x2e0f0e))[_0x106b('0x28')](handleError(_0x443664,null));};exports[_0x106b('0x6a')]=function(_0x5dc54f,_0x347c1f,_0x3da88f){return db[_0x106b('0x3f')][_0x106b('0x59')]({'where':{'id':_0x5dc54f[_0x106b('0x61')]['id']}})['then'](handleEntityNotFound(_0x347c1f,null))[_0x106b('0x1e')](function(_0x213dd8){if(_0x213dd8){return _0x213dd8[_0x106b('0x6a')](_0x5dc54f[_0x106b('0x43')][_0x106b('0x6b')]);}})[_0x106b('0x1e')](respondWithStatusCode(_0x347c1f,null))[_0x106b('0x28')](handleError(_0x347c1f,null));};exports[_0x106b('0x6c')]=function(_0x8e70af,_0x166180,_0x40994c){if(_0x8e70af[_0x106b('0x60')]['id']){delete _0x8e70af[_0x106b('0x60')]['id'];}return db[_0x106b('0x3f')][_0x106b('0x59')]({'where':{'id':_0x8e70af[_0x106b('0x61')]['id']}})[_0x106b('0x1e')](handleEntityNotFound(_0x166180,null))[_0x106b('0x1e')](function(_0x4f5703){if(_0x4f5703){_0x8e70af['body']['OpenchannelAccountId']=_0x4f5703['id'];return db[_0x106b('0x6d')][_0x106b('0x5a')](_0x8e70af[_0x106b('0x60')]);}})[_0x106b('0x1e')](respondWithResult(_0x166180,null))[_0x106b('0x28')](handleError(_0x166180,null));};exports[_0x106b('0x6e')]=function(_0x4f2b2d,_0x448759,_0x122663){var _0x2ada4e={'raw':![],'where':{}};var _0x367c30={};var _0x59dc88={'count':0x0,'rows':[]};return db[_0x106b('0x3f')][_0x106b('0x65')]({'where':{'id':_0x4f2b2d['params']['id']}})[_0x106b('0x1e')](handleEntityNotFound(_0x448759,null))[_0x106b('0x1e')](function(_0x13a10d){if(_0x13a10d){_0x367c30[_0x106b('0x46')]=_[_0x106b('0x44')](db[_0x106b('0x6d')][_0x106b('0x40')]);_0x367c30[_0x106b('0x43')]=_[_0x106b('0x44')](_0x4f2b2d['query']);_0x367c30[_0x106b('0x4d')]=_[_0x106b('0x45')](_0x367c30[_0x106b('0x46')],_0x367c30[_0x106b('0x43')]);_0x2ada4e[_0x106b('0x48')]=_[_0x106b('0x45')](_0x367c30['model'],qs[_0x106b('0x47')](_0x4f2b2d[_0x106b('0x43')][_0x106b('0x47')]));_0x2ada4e[_0x106b('0x48')]=_0x2ada4e[_0x106b('0x48')][_0x106b('0x49')]?_0x2ada4e[_0x106b('0x48')]:_0x367c30[_0x106b('0x46')];if(!_0x4f2b2d['query']['hasOwnProperty'](_0x106b('0x4a'))){_0x2ada4e[_0x106b('0x2f')]=qs[_0x106b('0x2f')](_0x4f2b2d[_0x106b('0x43')][_0x106b('0x2f')]);_0x2ada4e[_0x106b('0x2d')]=qs[_0x106b('0x2d')](_0x4f2b2d[_0x106b('0x43')][_0x106b('0x2d')]);}_0x2ada4e[_0x106b('0x68')]=qs[_0x106b('0x4b')](_0x4f2b2d['query']['sort']);_0x2ada4e['where']=qs['filters'](_[_0x106b('0x4e')](_0x4f2b2d[_0x106b('0x43')],_0x367c30[_0x106b('0x4d')]));_0x2ada4e[_0x106b('0x4c')][_0x106b('0x69')]=_0x13a10d['id'];if(_0x4f2b2d['query'][_0x106b('0x4f')]){_0x2ada4e['where']=_[_0x106b('0x51')](_0x2ada4e[_0x106b('0x4c')],{'$or':_[_0x106b('0x3e')](_0x2ada4e[_0x106b('0x48')],function(_0x3b84c3){var _0x456c71={};_0x456c71[_0x3b84c3]={'$like':'%'+_0x4f2b2d['query'][_0x106b('0x4f')]+'%'};return _0x456c71;})});}_0x2ada4e=_[_0x106b('0x51')]({},_0x2ada4e,_0x4f2b2d[_0x106b('0x52')]);return db[_0x106b('0x6d')][_0x106b('0x30')]({'where':_0x2ada4e[_0x106b('0x4c')]})['then'](function(_0x1f0822){_0x59dc88['count']=_0x1f0822;if(_0x4f2b2d[_0x106b('0x43')][_0x106b('0x58')]){_0x2ada4e[_0x106b('0x53')]=[{'all':!![]}];}return db[_0x106b('0x6d')][_0x106b('0x54')](_0x2ada4e);})[_0x106b('0x1e')](function(_0x25549e){_0x59dc88[_0x106b('0x55')]=_0x25549e;return _0x59dc88;});}})['then'](respondWithFilteredResult(_0x448759,_0x2ada4e))[_0x106b('0x28')](handleError(_0x448759,null));};exports[_0x106b('0x6f')]=function(_0x4b0753,_0x5c14b2,_0x3c9e19){return db[_0x106b('0x3f')][_0x106b('0x59')]({'where':{'id':_0x4b0753['params']['id']}})[_0x106b('0x1e')](handleEntityNotFound(_0x5c14b2,null))['then'](function(_0x2968ee){if(_0x2968ee){return _0x2968ee[_0x106b('0x6f')](_0x4b0753[_0x106b('0x43')][_0x106b('0x6b')]);}})[_0x106b('0x1e')](respondWithStatusCode(_0x5c14b2,null))[_0x106b('0x28')](handleError(_0x5c14b2,null));};exports[_0x106b('0x70')]=function(_0x5496c4,_0x294c3d,_0x3b4dfb){var _0xa7adae={'body':_0x5496c4['body'],'channel':_0x106b('0x71')};var _0x290d52=[];var _0x24c144=[];var _0x402b27={};var _0x27082=![];return db[_0x106b('0x72')]['describe']()['then'](function(_0x371765){if(!_0x371765){throw new db['Sequelize'][(_0x106b('0x73'))](_0x106b('0x74'));}_0x290d52=_[_0x106b('0x75')](_[_0x106b('0x44')](_0x371765),[_0x106b('0x76'),_0x106b('0x77')]);_0x24c144=_[_0x106b('0x75')](_[_0x106b('0x44')](_0x371765),[_0x106b('0x76'),_0x106b('0x77'),_0x106b('0x78'),_0x106b('0x79')]);if(_0x5496c4[_0x106b('0x60')]['id']){delete _0x5496c4['body']['id'];}if(_[_0x106b('0x7a')](_0x5496c4[_0x106b('0x60')]['from'])){throw new db[(_0x106b('0x7b'))][(_0x106b('0x73'))](_0x106b('0x7c'));}if(_[_0x106b('0x7a')](_0x5496c4['body']['body'])||_0x5496c4[_0x106b('0x60')][_0x106b('0x60')]===''){throw new db['Sequelize'][(_0x106b('0x73'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x106b('0x7a')](_0x5496c4[_0x106b('0x60')][_0x106b('0x7d')])){throw new db[(_0x106b('0x7b'))][(_0x106b('0x73'))](_0x106b('0x7e')+_0x24c144);}if(!_['includes'](_0x24c144,_0x5496c4[_0x106b('0x60')]['mapKey'])){throw new db[(_0x106b('0x7b'))]['ValidationError'](_0x106b('0x7f')+_0x24c144);}_0x402b27[_0x5496c4[_0x106b('0x60')][_0x106b('0x7d')]]=_0x5496c4[_0x106b('0x60')]['from'];})[_0x106b('0x1e')](function(){return db[_0x106b('0x3f')][_0x106b('0x59')]({'where':{'id':_0x5496c4[_0x106b('0x61')]['id']},'include':[{'model':db[_0x106b('0x80')],'as':'List','include':[{'model':db[_0x106b('0x72')],'as':'Contacts','where':_0x402b27,'limit':0x1,'order':[['updatedAt',_0x106b('0x81')]]}]},{'model':db[_0x106b('0x82')],'as':'Applications'}]});})[_0x106b('0x1e')](handleEntityNotFound(_0x294c3d,null))['then'](function(_0x3f370f){if(_0x3f370f&&_0x3f370f[_0x106b('0x83')]){_0xa7adae['account']=_0x3f370f;_0xa7adae['applications']=_0x3f370f[_0x106b('0x84')];_0xa7adae[_0x106b('0x85')]=_0x3f370f[_0x106b('0x83')];_0xa7adae['applications']=_[_0x106b('0x86')](_0xa7adae[_0x106b('0x87')],[_0x106b('0x88')],[_0x106b('0x89')]);if(_0xa7adae[_0x106b('0x8a')][_0x106b('0x84')]){delete _0xa7adae[_0x106b('0x8a')][_0x106b('0x84')];}if(_0xa7adae[_0x106b('0x8a')][_0x106b('0x83')]&&_0xa7adae[_0x106b('0x8a')][_0x106b('0x83')][_0x106b('0x8b')][_0x106b('0x49')]){return _0xa7adae[_0x106b('0x8a')][_0x106b('0x83')][_0x106b('0x8b')][0x0];}var _0x1c7c4f=_[_0x106b('0x18')](_0x5496c4[_0x106b('0x60')],{'firstName':_0x5496c4[_0x106b('0x60')][_0x106b('0x8c')],'ListId':_0x3f370f[_0x106b('0x79')]});_0x1c7c4f[_0x5496c4[_0x106b('0x60')][_0x106b('0x7d')]]=_0x5496c4[_0x106b('0x60')][_0x106b('0x8c')];return db[_0x106b('0x72')]['create'](_0x1c7c4f,{'fields':_0x290d52,'raw':!![]});}})[_0x106b('0x1e')](handleEntityNotFound(_0x294c3d,null))[_0x106b('0x1e')](function(_0x65c472){_0xa7adae[_0x106b('0x8d')]=_0x65c472;if(_0x65c472){var _0x3b69b9={'ContactId':_0x65c472['id'],'OpenchannelAccountId':_0x5496c4[_0x106b('0x61')]['id'],'from':(_0x65c472[_0x106b('0x8e')]||'')+'\x20'+(_0x65c472[_0x106b('0x8f')]||'')};var _0x5a7534={'OpenchannelAccountId':_0x5496c4[_0x106b('0x61')]['id'],'closed':![]};if(_0x5496c4[_0x106b('0x60')]['threadId']){_0x5a7534[_0x106b('0x90')]=_0x5496c4['body'][_0x106b('0x90')];return db['OpenchannelInteraction'][_0x106b('0x59')]({'where':_0x5a7534})[_0x106b('0x1e')](function(_0x5bde58){if(_0x5bde58){return[_0x5bde58,![]];}_0x3b69b9[_0x106b('0x90')]=_0x5496c4[_0x106b('0x60')][_0x106b('0x90')];_0x3b69b9[_0x106b('0x91')]=_0x5496c4[_0x106b('0x60')][_0x106b('0x91')];return db[_0x106b('0x92')][_0x106b('0x5a')](_0x3b69b9)[_0x106b('0x1e')](function(_0x92af18){return[_0x92af18,!![]];});});}else{_0x5a7534[_0x106b('0x90')]=null;}_0x5a7534[_0x106b('0x93')]=_0x65c472['id'];return db[_0x106b('0x92')]['find']({'where':_0x5a7534})[_0x106b('0x1e')](function(_0x1e8fed){if(_0x1e8fed){return[_0x1e8fed,![]];}return db['OpenchannelInteraction'][_0x106b('0x5a')](_0x3b69b9)['then'](function(_0x18546a){return[_0x18546a,!![]];});});}})[_0x106b('0x94')](function(_0x377f24,_0x93c63f){if(_0x377f24){_0x27082=_0x93c63f;if(!_0x93c63f){var _0x4fd66c={'from':(_0xa7adae['contact'][_0x106b('0x8e')]||'')+'\x20'+(_0xa7adae[_0x106b('0x8d')]['lastName']||'')};if(_0x5496c4['body'][_0x106b('0x90')]&&_0x5496c4[_0x106b('0x60')]['messageId']&&_0x5496c4[_0x106b('0x60')]['threadId']!=_0x5496c4['body'][_0x106b('0x95')]){_0x4fd66c[_0x106b('0x90')]=_0x5496c4[_0x106b('0x60')]['messageId'];}return _0x377f24['update'](_0x4fd66c);}else{return _0x377f24;}}})[_0x106b('0x1e')](function(_0x3f9979){_0xa7adae['interaction']=_0x3f9979[_0x106b('0x38')]({'plain':!![]});_0xa7adae[_0x106b('0x96')]['created']=_0x27082;if(_0xa7adae['interaction'][_0x106b('0x97')]){if(_0xa7adae[_0x106b('0x8a')][_0x106b('0x98')]){_0xa7adae['applications']['push']({'id':0x0,'priority':_0xa7adae['applications'][_0x106b('0x49')]+0x1,'app':_0x106b('0x99'),'appdata':_0x106b('0x9a'),'interval':'*,*,*,*'});}}return db[_0x106b('0x9b')][_0x106b('0x5a')]({'body':_0x5496c4['body'][_0x106b('0x60')],'OpenchannelAccountId':_0x5496c4[_0x106b('0x61')]['id'],'OpenchannelInteractionId':_0x3f9979['id'],'direction':'in','ContactId':_0xa7adae[_0x106b('0x8d')]['id'],'AttachmentId':_0x5496c4[_0x106b('0x60')]['AttachmentId']});})[_0x106b('0x1e')](function(_0x2d0853){_0xa7adae['message']=_0x2d0853;if(_0xa7adae[_0x106b('0x96')]['UserId']){return db['User'][_0x106b('0x59')]({'attributes':['id','name'],'where':{'id':_0xa7adae[_0x106b('0x96')][_0x106b('0x9c')]}})[_0x106b('0x1e')](function(_0x56cd41){if(_0x56cd41){_0xa7adae[_0x106b('0x87')]['unshift']({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x56cd41[_0x106b('0x3b')]+','+(_0xa7adae[_0x106b('0x8a')][_0x106b('0x9d')]||0xa),'interval':'*,*,*,*'});_0xa7adae[_0x106b('0x9e')]=![];}return respondWithRpcPromise(_0x106b('0x9f'),_0x106b('0xa0'),_0xa7adae);});}return respondWithRpcPromise(_0x106b('0x9f'),_0x106b('0xa0'),_0xa7adae);})[_0x106b('0x1e')](function(_0x102330){respondWithRpcPromise(_0x106b('0xa1'),'EventManager',{'event':_0x106b('0x70'),'message':_0x102330},client9002);return _0x102330;})[_0x106b('0x1e')](respondWithResult(_0x294c3d,null))[_0x106b('0x28')](handleError(_0x294c3d,null));};exports[_0x106b('0xa2')]=function(_0x597347,_0x5eaffb,_0x2a7a68){return db[_0x106b('0x3f')][_0x106b('0x65')]({'where':{'id':_0x597347[_0x106b('0x61')]['id']}})[_0x106b('0x1e')](handleEntityNotFound(_0x5eaffb,null))[_0x106b('0x1e')](function(_0x3a2745){if(_0x3a2745){return db[_0x106b('0xa3')][_0x106b('0xa4')](function(_0x231a59){return db[_0x106b('0x82')][_0x106b('0x37')]({'where':{'OpenchannelAccountId':_0x597347[_0x106b('0x61')]['id']},'transaction':_0x231a59})['then'](function(_0x443ff4){var _0xed01d9=_[_0x106b('0x3e')](_0x597347[_0x106b('0x60')],function(_0x55d3a5){_0x55d3a5['OpenchannelAccountId']=_0x597347[_0x106b('0x61')]['id'];return _0x55d3a5;});return db['OpenchannelApplication'][_0x106b('0xa5')](_0xed01d9,{'transaction':_0x231a59});});})[_0x106b('0x1e')](function(){return db[_0x106b('0x82')][_0x106b('0xa6')]({'where':{'OpenchannelAccountId':_0x597347[_0x106b('0x61')]['id']},'order':_0x106b('0x88')});});}})[_0x106b('0x1e')](respondWithResult(_0x5eaffb,null))[_0x106b('0x28')](handleError(_0x5eaffb,null));};exports[_0x106b('0xa7')]=function(_0x56862f,_0x427ef9,_0x13dfe4){var _0x11d272={};var _0x424a0c={};var _0x42cd5d;var _0x2a5c8a;return db[_0x106b('0x3f')][_0x106b('0x65')]({'where':{'id':_0x56862f[_0x106b('0x61')]['id']}})['then'](handleEntityNotFound(_0x427ef9,null))[_0x106b('0x1e')](function(_0x1921bd){if(_0x1921bd){_0x42cd5d=_0x1921bd;_0x424a0c[_0x106b('0x46')]=_['keys'](db[_0x106b('0x82')][_0x106b('0x40')]);_0x424a0c[_0x106b('0x43')]=_['keys'](_0x56862f['query']);_0x424a0c[_0x106b('0x4d')]=_[_0x106b('0x45')](_0x424a0c[_0x106b('0x46')],_0x424a0c[_0x106b('0x43')]);_0x11d272['attributes']=_['intersection'](_0x424a0c[_0x106b('0x46')],qs[_0x106b('0x47')](_0x56862f[_0x106b('0x43')][_0x106b('0x47')]));_0x11d272[_0x106b('0x48')]=_0x11d272[_0x106b('0x48')][_0x106b('0x49')]?_0x11d272[_0x106b('0x48')]:_0x424a0c[_0x106b('0x46')];_0x11d272['order']=qs[_0x106b('0x4b')](_0x56862f[_0x106b('0x43')][_0x106b('0x4b')]);_0x11d272[_0x106b('0x4c')]=qs[_0x106b('0x4d')](_[_0x106b('0x4e')](_0x56862f['query'],_0x424a0c[_0x106b('0x4d')]));if(_0x56862f[_0x106b('0x43')][_0x106b('0x4f')]){_0x11d272['where']=_[_0x106b('0x51')](_0x11d272['where'],{'$or':_[_0x106b('0x3e')](_0x11d272['attributes'],function(_0x58cbbe){var _0x94fc5b={};_0x94fc5b[_0x58cbbe]={'$like':'%'+_0x56862f[_0x106b('0x43')][_0x106b('0x4f')]+'%'};return _0x94fc5b;})});}_0x11d272=_['merge']({},_0x11d272,_0x56862f['options']);return _0x42cd5d[_0x106b('0xa7')](_0x11d272);}})[_0x106b('0x1e')](function(_0x23fa9){if(_0x23fa9){_0x2a5c8a=_0x23fa9[_0x106b('0x49')];if(!_0x56862f[_0x106b('0x43')][_0x106b('0x67')](_0x106b('0x4a'))){_0x11d272[_0x106b('0x2f')]=qs['limit'](_0x56862f[_0x106b('0x43')][_0x106b('0x2f')]);_0x11d272[_0x106b('0x2d')]=qs[_0x106b('0x2d')](_0x56862f[_0x106b('0x43')][_0x106b('0x2d')]);}return _0x42cd5d[_0x106b('0xa7')](_0x11d272);}})['then'](function(_0x4a0ea4){if(_0x4a0ea4){return _0x4a0ea4?{'count':_0x2a5c8a,'rows':_0x4a0ea4}:null;}})['then'](respondWithResult(_0x427ef9,null))[_0x106b('0x28')](handleError(_0x427ef9,null));};exports[_0x106b('0xa8')]=function(_0x3a9179,_0x1d469a,_0x4bfb0a){var _0x32b49c={'raw':![],'where':{}};var _0x43cafc={};var _0x40cf4a={'count':0x0,'rows':[]};return db[_0x106b('0x3f')][_0x106b('0x65')]({'where':{'id':_0x3a9179[_0x106b('0x61')]['id']}})[_0x106b('0x1e')](handleEntityNotFound(_0x1d469a,null))['then'](function(_0x293c90){if(_0x293c90){_0x43cafc['model']=_[_0x106b('0x44')](db[_0x106b('0x92')][_0x106b('0x40')]);_0x43cafc['query']=_[_0x106b('0x44')](_0x3a9179['query']);_0x43cafc[_0x106b('0x4d')]=_[_0x106b('0x45')](_0x43cafc[_0x106b('0x46')],_0x43cafc[_0x106b('0x43')]);_0x32b49c[_0x106b('0x48')]=_[_0x106b('0x45')](_0x43cafc[_0x106b('0x46')],qs[_0x106b('0x47')](_0x3a9179[_0x106b('0x43')]['fields']));_0x32b49c[_0x106b('0x48')]=_0x32b49c['attributes'][_0x106b('0x49')]?_0x32b49c[_0x106b('0x48')]:_0x43cafc['model'];if(!_0x3a9179[_0x106b('0x43')][_0x106b('0x67')]('nolimit')){_0x32b49c[_0x106b('0x2f')]=qs[_0x106b('0x2f')](_0x3a9179[_0x106b('0x43')]['limit']);_0x32b49c[_0x106b('0x2d')]=qs['offset'](_0x3a9179[_0x106b('0x43')][_0x106b('0x2d')]);}_0x32b49c[_0x106b('0x68')]=qs['sort'](_0x3a9179['query'][_0x106b('0x4b')]);_0x32b49c[_0x106b('0x4c')]=qs[_0x106b('0x4d')](_[_0x106b('0x4e')](_0x3a9179['query'],_0x43cafc[_0x106b('0x4d')]));_0x32b49c[_0x106b('0x4c')][_0x106b('0x69')]=_0x293c90['id'];if(_0x3a9179[_0x106b('0x43')][_0x106b('0x4f')]){_0x32b49c[_0x106b('0x4c')]=_['merge'](_0x32b49c[_0x106b('0x4c')],{'$or':_['map'](_0x32b49c[_0x106b('0x48')],function(_0x9976f3){var _0x53fa82={};_0x53fa82[_0x9976f3]={'$like':'%'+_0x3a9179[_0x106b('0x43')][_0x106b('0x4f')]+'%'};return _0x53fa82;})});}_0x32b49c=_[_0x106b('0x51')]({},_0x32b49c,_0x3a9179[_0x106b('0x52')]);return db['OpenchannelInteraction'][_0x106b('0x30')]({'where':_0x32b49c['where']})[_0x106b('0x1e')](function(_0x1e6e30){_0x40cf4a[_0x106b('0x30')]=_0x1e6e30;if(_0x3a9179[_0x106b('0x43')]['includeAll']){_0x32b49c[_0x106b('0x53')]=[{'model':db[_0x106b('0x72')],'as':_0x106b('0xa9'),'required':![]},{'model':db[_0x106b('0xaa')],'as':'Owner','attributes':['name',_0x106b('0xab'),_0x106b('0xac')],'required':![]},{'model':db[_0x106b('0xad')],'as':'Tags','attributes':['id',_0x106b('0x3b'),_0x106b('0xae')],'where':_0x3a9179[_0x106b('0x43')][_0x106b('0xaf')]?{'id':_0x3a9179[_0x106b('0x43')][_0x106b('0xaf')]}:undefined,'required':_0x3a9179[_0x106b('0x43')][_0x106b('0xaf')]?!![]:![]}];}return db[_0x106b('0x92')][_0x106b('0x54')](_0x32b49c);})[_0x106b('0x1e')](function(_0x4c7f5e){_0x40cf4a[_0x106b('0x55')]=_0x4c7f5e;return _0x40cf4a;});}})['then'](respondWithFilteredResult(_0x1d469a,_0x32b49c))['catch'](handleError(_0x1d469a,null));};exports[_0x106b('0xb0')]=function(_0xe87e41,_0x4ada85,_0x54f4b6){return db[_0x106b('0x3f')][_0x106b('0x59')]({'where':{'id':_0xe87e41[_0x106b('0x61')]['id']}})[_0x106b('0x1e')](handleEntityNotFound(_0x4ada85,null))['then'](function(_0x3b54c9){if(_0x3b54c9){return _0x3b54c9[_0x106b('0xb0')](_0xe87e41[_0x106b('0x60')]['ids'],_[_0x106b('0xb1')](_0xe87e41[_0x106b('0x60')],['ids','id'])||{})[_0x106b('0x94')](function(_0x2aa241){for(var _0x44c88d=0x0;_0x44c88d<_0xe87e41[_0x106b('0x60')][_0x106b('0x6b')][_0x106b('0x49')];_0x44c88d+=0x1){socket['emit'](_0x106b('0xb2'),{'UserId':Number(_0xe87e41[_0x106b('0x60')][_0x106b('0x6b')][_0x44c88d]),'OpenchannelAccountId':Number(_0xe87e41['params']['id'])});}return _0x2aa241;});}})[_0x106b('0x1e')](respondWithResult(_0x4ada85,null))[_0x106b('0x28')](handleError(_0x4ada85,null));};exports['removeAgents']=function(_0x3f4450,_0x11744d,_0x360e22){return db[_0x106b('0x3f')][_0x106b('0x59')]({'where':{'id':_0x3f4450['params']['id']}})[_0x106b('0x1e')](handleEntityNotFound(_0x11744d,null))['then'](function(_0x411bb8){if(_0x411bb8){return _0x411bb8['removeAgents'](_0x3f4450['query']['ids'])[_0x106b('0x1e')](function(){if(_['isArray'](_0x3f4450[_0x106b('0x43')]['ids'])){for(var _0x4753c6=0x0;_0x4753c6<_0x3f4450['query'][_0x106b('0x6b')]['length'];_0x4753c6+=0x1){socket[_0x106b('0xb3')](_0x106b('0xb4'),{'UserId':Number(_0x3f4450[_0x106b('0x43')]['ids'][_0x4753c6]),'OpenchannelAccountId':Number(_0x3f4450[_0x106b('0x61')]['id'])});}}else{socket[_0x106b('0xb3')](_0x106b('0xb4'),{'UserId':Number(_0x3f4450[_0x106b('0x43')]['ids']),'OpenchannelAccountId':Number(_0x3f4450[_0x106b('0x61')]['id'])});}});}})[_0x106b('0x1e')](respondWithStatusCode(_0x11744d,null))[_0x106b('0x28')](handleError(_0x11744d,null));};exports['getAgents']=function(_0x514f50,_0x528b6d,_0x297246){var _0x1a4450={};var _0x3ed108={};var _0x59209e;var _0x2a60ce;return db[_0x106b('0x3f')][_0x106b('0x65')]({'where':{'id':_0x514f50[_0x106b('0x61')]['id']}})[_0x106b('0x1e')](handleEntityNotFound(_0x528b6d,null))[_0x106b('0x1e')](function(_0x351060){if(_0x351060){_0x59209e=_0x351060;_0x3ed108['model']=_['keys'](db[_0x106b('0xaa')]['rawAttributes']);_0x3ed108[_0x106b('0x43')]=_[_0x106b('0x44')](_0x514f50['query']);_0x3ed108[_0x106b('0x4d')]=_[_0x106b('0x45')](_0x3ed108[_0x106b('0x46')],_0x3ed108[_0x106b('0x43')]);_0x1a4450[_0x106b('0x48')]=_[_0x106b('0x45')](_0x3ed108[_0x106b('0x46')],qs[_0x106b('0x47')](_0x514f50[_0x106b('0x43')]['fields']));_0x1a4450[_0x106b('0x48')]=_0x1a4450[_0x106b('0x48')][_0x106b('0x49')]?_0x1a4450[_0x106b('0x48')]:_0x3ed108[_0x106b('0x46')];_0x1a4450[_0x106b('0x68')]=qs[_0x106b('0x4b')](_0x514f50[_0x106b('0x43')][_0x106b('0x4b')]);_0x1a4450[_0x106b('0x4c')]=qs[_0x106b('0x4d')](_[_0x106b('0x4e')](_0x514f50[_0x106b('0x43')],_0x3ed108[_0x106b('0x4d')]));if(_0x514f50[_0x106b('0x43')][_0x106b('0x4f')]){_0x1a4450[_0x106b('0x4c')]=_[_0x106b('0x51')](_0x1a4450[_0x106b('0x4c')],{'$or':_[_0x106b('0x3e')](_0x1a4450[_0x106b('0x48')],function(_0x288110){var _0x164eb3={};_0x164eb3[_0x288110]={'$like':'%'+_0x514f50['query'][_0x106b('0x4f')]+'%'};return _0x164eb3;})});}_0x1a4450=_[_0x106b('0x51')]({},_0x1a4450,_0x514f50[_0x106b('0x52')]);return _0x59209e[_0x106b('0xb5')](_0x1a4450);}})[_0x106b('0x1e')](function(_0x57f4c0){if(_0x57f4c0){_0x2a60ce=_0x57f4c0['length'];if(!_0x514f50[_0x106b('0x43')][_0x106b('0x67')](_0x106b('0x4a'))){_0x1a4450['limit']=qs[_0x106b('0x2f')](_0x514f50['query'][_0x106b('0x2f')]);_0x1a4450[_0x106b('0x2d')]=qs[_0x106b('0x2d')](_0x514f50[_0x106b('0x43')][_0x106b('0x2d')]);}return _0x59209e['getAgents'](_0x1a4450);}})[_0x106b('0x1e')](function(_0xa1641b){if(_0xa1641b){return _0xa1641b?{'count':_0x2a60ce,'rows':_0xa1641b}:null;}})[_0x106b('0x1e')](respondWithResult(_0x528b6d,null))[_0x106b('0x28')](handleError(_0x528b6d,null));};exports['send']=function(_0x46df6a,_0x3f0a8a,_0x16f012){var _0x256fd0,_0x13c130,_0x2d4058;if(_['isNil'](_0x46df6a[_0x106b('0x60')][_0x106b('0x60')])||_0x46df6a[_0x106b('0x60')][_0x106b('0x60')]===''){throw new db[(_0x106b('0x7b'))][(_0x106b('0x73'))](_0x106b('0xb6'));}if(_[_0x106b('0x7a')](_0x46df6a[_0x106b('0x60')]['to'])){}_0x256fd0=_0x46df6a[_0x106b('0x60')]['to'];return db[_0x106b('0x3f')]['findOne']({'where':{'id':_0x46df6a[_0x106b('0x61')]['id']}})[_0x106b('0x1e')](handleEntityNotFound(_0x3f0a8a,null))['then'](function(_0x44a375){if(_0x44a375){return db['OpenchannelAccount']['find']({'where':{'id':_0x44a375['id']},'include':[{'model':db[_0x106b('0x80')],'as':'List','include':[{'model':db[_0x106b('0x72')],'as':_0x106b('0x8b'),'where':{[_0x44a375[_0x106b('0x7d')]]:_0x256fd0},'limit':0x1,'order':[[_0x106b('0x77'),'DESC']]}]}]})['then'](handleEntityNotFound(_0x3f0a8a,null))[_0x106b('0x1e')](function(_0x632b16){if(_0x632b16&&_0x632b16[_0x106b('0x83')]){_0x13c130=_0x632b16['get']({'plain':!![]});if(_0x13c130[_0x106b('0x83')]&&_0x13c130['List'][_0x106b('0x8b')][_0x106b('0x49')]){return _0x13c130[_0x106b('0x83')]['Contacts'][0x0];}return db['CmContact'][_0x106b('0x5a')](_[_0x106b('0x18')](_0x46df6a[_0x106b('0x60')],{'firstName':_0x256fd0,[_0x632b16[_0x106b('0x7d')]]:_0x256fd0,'phone':_0x256fd0,'ListId':_0x13c130['ListId']}));}})[_0x106b('0x1e')](handleEntityNotFound(_0x3f0a8a,null))['then'](function(_0x9046e6){if(_0x9046e6){_0x2d4058=_0x9046e6;return db[_0x106b('0x92')][_0x106b('0x59')]({'where':{'ContactId':_0x2d4058['id'],'closed':![],'OpenchannelAccountId':_0x13c130['id']}})['then'](function(_0x35ac5e){if(_0x35ac5e){return[_0x35ac5e,![]];}return db[_0x106b('0x92')][_0x106b('0x5a')]({'UserId':_0x46df6a['user']['id'],'ContactId':_0x2d4058['id'],'OpenchannelAccountId':_0x13c130['id'],'lastMsgDirection':_0x106b('0xb7'),'Messages':[_[_0x106b('0x51')](_0x46df6a[_0x106b('0x60')],{'read':![],'body':_0x46df6a[_0x106b('0x60')]['body'],'OpenchannelAccountId':_0x13c130['id'],'UserId':_0x46df6a[_0x106b('0x5b')]['id'],'ContactId':_0x2d4058['id']})]},{'include':[{'model':db[_0x106b('0x9b')],'as':_0x106b('0xb8')}]})[_0x106b('0x1e')](function(_0x1f92b1){return[_0x1f92b1,!![]];});});}})[_0x106b('0x94')](function(_0x1e3927,_0x1f8a64){if(_0x1f8a64){return _0x1e3927;}return db[_0x106b('0x9b')][_0x106b('0x5a')](_['merge'](_0x46df6a[_0x106b('0x60')],{'read':![],'body':_0x46df6a['body'][_0x106b('0x60')],'OpenchannelAccountId':_0x13c130['id'],'OpenchannelInteractionId':_0x1e3927['id'],'UserId':_0x46df6a[_0x106b('0x5b')]['id'],'ContactId':_0x2d4058['id']}))['then'](function(_0x251bfa){_0x1e3927['dataValues'][_0x106b('0xb8')]=[];_0x1e3927['dataValues'][_0x106b('0xb8')][_0x106b('0xb9')](_0x251bfa[_0x106b('0xba')]);return _0x1e3927;});});}})[_0x106b('0x1e')](respondWithResult(_0x3f0a8a,null))['catch'](handleError(_0x3f0a8a,null));};