Built motion from commit 9efc8423.|2.6.31
[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 _0xfc17=['threadId','OpenchannelInteraction','ContactId','spread','contact','messageId','interaction','created','push','close','unmanaged','*,*,*,*','OpenchannelMessage','AttachmentId','UserId','unshift','waitForTheAssignedAgent','OpenchannelQueue','queueId','waitForTheAssignedQueue','startRouting','EventManager','addApplications','sequelize','transaction','Transaction','ISOLATION_LEVELS','READ_COMMITTED','bulkCreate','findAndCountAll','finally','send','getApplications','getInteractions','User','Owner','fullname','Tag','color','tag','addAgents','omit','emit','userOpenchannelAccount:save','removeAgents','isArray','userOpenchannelAccount:remove','getAgents','DESC','out','Messages','dataValues','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','jayson/promise','client','http','then','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','end','json','offset','undefined','count','limit','status','set','Content-Range','apply','reject','update','get','OpenchannelAccounts','stack','name','index','Pause','mandatoryDispositionPause','map','fieldName','type','keys','filters','intersection','query','attributes','model','length','hasOwnProperty','order','sort','where','filter','merge','options','OpenchannelAccount','includeAll','include','findAll','rows','params','fields','find','body','role','user','autoAssociation','UserProfileResource','create','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','destroy','describe','addDisposition','OpenchannelAccountId','Disposition','getDispositions','findOne','rawAttributes','nolimit','removeDispositions','ids','CannedAnswer','getAnswers','pick','removeAnswers','notify','openchannel','CmContact','ValidationError','no\x20available\x20attributes','createdAt','CompanyId','ListId','isNil','Sequelize','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','Contacts','updatedAt','OpenchannelApplication','Applications','List','account','applications','list','orderBy','priority','asc','from','firstName','lastName'];(function(_0x27ae45,_0x6fe56f){var _0x4f8787=function(_0x5c0a60){while(--_0x5c0a60){_0x27ae45['push'](_0x27ae45['shift']());}};_0x4f8787(++_0x6fe56f);}(_0xfc17,0x1b4));var _0x7fc1=function(_0x406047,_0x15ecfc){_0x406047=_0x406047-0x0;var _0x5e5f33=_0xfc17[_0x406047];return _0x5e5f33;};'use strict';var emlformat=require(_0x7fc1('0x0'));var rimraf=require(_0x7fc1('0x1'));var zipdir=require(_0x7fc1('0x2'));var jsonpatch=require(_0x7fc1('0x3'));var rp=require('request-promise');var moment=require(_0x7fc1('0x4'));var BPromise=require(_0x7fc1('0x5'));var Mustache=require(_0x7fc1('0x6'));var util=require(_0x7fc1('0x7'));var path=require(_0x7fc1('0x8'));var sox=require(_0x7fc1('0x9'));var csv=require('to-csv');var ejs=require(_0x7fc1('0xa'));var fs=require('fs');var fs_extra=require(_0x7fc1('0xb'));var _=require(_0x7fc1('0xc'));var squel=require(_0x7fc1('0xd'));var crypto=require(_0x7fc1('0xe'));var jsforce=require(_0x7fc1('0xf'));var deskjs=require(_0x7fc1('0x10'));var toCsv=require('to-csv');var querystring=require(_0x7fc1('0x11'));var Papa=require(_0x7fc1('0x12'));var Redis=require(_0x7fc1('0x13'));var authService=require('../../components/auth/service');var qs=require(_0x7fc1('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x7fc1('0x15'))(_0x7fc1('0x16'));var utils=require(_0x7fc1('0x17'));var config=require(_0x7fc1('0x18'));var licenseUtil=require(_0x7fc1('0x19'));var db=require(_0x7fc1('0x1a'))['db'];config[_0x7fc1('0x1b')]=_[_0x7fc1('0x1c')](config[_0x7fc1('0x1b')],{'host':_0x7fc1('0x1d'),'port':0x18eb});var socket=require(_0x7fc1('0x1e'))(new Redis(config[_0x7fc1('0x1b')]));require('./openchannelAccount.socket')['register'](socket);var jayson=require(_0x7fc1('0x1f'));var client=jayson[_0x7fc1('0x20')][_0x7fc1('0x21')]({'port':0x232c});var client9002=jayson[_0x7fc1('0x20')][_0x7fc1('0x21')]({'port':0x232a});function respondWithRpcPromise(_0x3c4671,_0x3d8e82,_0x37af05,_0x18be8e){return new BPromise(function(_0x442176,_0x5e634a){var _0x419170=_0x18be8e||client;return _0x419170['request'](_0x3c4671,_0x37af05)[_0x7fc1('0x22')](function(_0x88c6e3){logger['info'](_0x7fc1('0x23'),_0x3d8e82,_0x7fc1('0x24'));logger['debug'](_0x7fc1('0x25'),_0x3d8e82,_0x7fc1('0x24'),JSON[_0x7fc1('0x26')](_0x88c6e3));if(_0x88c6e3[_0x7fc1('0x27')]){if(_0x88c6e3[_0x7fc1('0x27')][_0x7fc1('0x28')]===0x1f4){logger[_0x7fc1('0x27')](_0x7fc1('0x23'),_0x3d8e82,_0x88c6e3[_0x7fc1('0x27')][_0x7fc1('0x29')]);return _0x5e634a(_0x88c6e3['error']['message']);}logger[_0x7fc1('0x27')]('OpenchannelAccount,\x20%s,\x20%s',_0x3d8e82,_0x88c6e3[_0x7fc1('0x27')][_0x7fc1('0x29')]);return _0x442176(_0x88c6e3[_0x7fc1('0x27')][_0x7fc1('0x29')]);}else{logger['info'](_0x7fc1('0x23'),_0x3d8e82,_0x7fc1('0x24'));_0x442176(_0x88c6e3[_0x7fc1('0x2a')]['message']);}})[_0x7fc1('0x2b')](function(_0x252b18){logger['error']('OpenchannelAccount,\x20%s,\x20%s',_0x3d8e82,_0x252b18);_0x5e634a(_0x252b18);});});}function respondWithStatusCode(_0x2e4256,_0x293a2a){_0x293a2a=_0x293a2a||0xcc;return function(_0x1f58ca){if(_0x1f58ca){return _0x2e4256[_0x7fc1('0x2c')](_0x293a2a);}return _0x2e4256['status'](_0x293a2a)[_0x7fc1('0x2d')]();};}function respondWithResult(_0x1628fd,_0x378b2f){_0x378b2f=_0x378b2f||0xc8;return function(_0x1fda3f){if(_0x1fda3f){return _0x1628fd['status'](_0x378b2f)[_0x7fc1('0x2e')](_0x1fda3f);}};}function respondWithFilteredResult(_0x583e60,_0x1f7fce){return function(_0x22a3c1){if(_0x22a3c1){var _0x34ec70=typeof _0x1f7fce[_0x7fc1('0x2f')]===_0x7fc1('0x30')&&typeof _0x1f7fce['limit']===_0x7fc1('0x30');var _0x59a89a=_0x22a3c1['count'];var _0x19e79b=_0x34ec70?0x0:_0x1f7fce[_0x7fc1('0x2f')];var _0x3ffd76=_0x34ec70?_0x22a3c1[_0x7fc1('0x31')]:_0x1f7fce[_0x7fc1('0x2f')]+_0x1f7fce[_0x7fc1('0x32')];var _0x28c434;if(_0x3ffd76>=_0x59a89a){_0x3ffd76=_0x59a89a;_0x28c434=0xc8;}else{_0x28c434=0xce;}_0x583e60[_0x7fc1('0x33')](_0x28c434);return _0x583e60[_0x7fc1('0x34')](_0x7fc1('0x35'),_0x19e79b+'-'+_0x3ffd76+'/'+_0x59a89a)[_0x7fc1('0x2e')](_0x22a3c1);}return null;};}function patchUpdates(_0x2c95c8){return function(_0x242fd1){try{jsonpatch[_0x7fc1('0x36')](_0x242fd1,_0x2c95c8,!![]);}catch(_0x211df6){return BPromise[_0x7fc1('0x37')](_0x211df6);}return _0x242fd1['save']();};}function saveUpdates(_0x24904b,_0x2bba7c){return function(_0x4282b5){if(_0x4282b5){return _0x4282b5[_0x7fc1('0x38')](_0x24904b)[_0x7fc1('0x22')](function(_0x2af537){return _0x2af537;});}return null;};}function removeEntity(_0x5b96ea,_0x185d06){return function(_0x3f8961){if(_0x3f8961){return _0x3f8961['destroy']()[_0x7fc1('0x22')](function(){var _0x2b1788=_0x3f8961[_0x7fc1('0x39')]({'plain':!![]});var _0x20f629=_0x7fc1('0x3a');return db['UserProfileResource']['destroy']({'where':{'type':_0x20f629,'resourceId':_0x2b1788['id']}})[_0x7fc1('0x22')](function(){return _0x3f8961;});})[_0x7fc1('0x22')](function(){_0x5b96ea[_0x7fc1('0x33')](0xcc)[_0x7fc1('0x2d')]();});}};}function handleEntityNotFound(_0x12ac96,_0x2474a3){return function(_0x2c8993){if(!_0x2c8993){_0x12ac96[_0x7fc1('0x2c')](0x194);}return _0x2c8993;};}function handleError(_0x53da04,_0x2c1367){_0x2c1367=_0x2c1367||0x1f4;return function(_0x4bf8d6){logger['error'](_0x4bf8d6[_0x7fc1('0x3b')]);if(_0x4bf8d6[_0x7fc1('0x3c')]){delete _0x4bf8d6[_0x7fc1('0x3c')];}_0x53da04['status'](_0x2c1367)['send'](_0x4bf8d6);};}exports[_0x7fc1('0x3d')]=function(_0x459ab0,_0xafc8b0){var _0x564437={'include':[{'model':db[_0x7fc1('0x3e')],'as':_0x7fc1('0x3f')}]},_0x4e640b={},_0x50c728={'count':0x0,'rows':[]};var _0x32607c=_[_0x7fc1('0x40')](db['OpenchannelAccount']['rawAttributes'],function(_0x4115c5){return{'name':_0x4115c5[_0x7fc1('0x41')],'type':_0x4115c5[_0x7fc1('0x42')]['key']};});_0x4e640b['model']=_['map'](_0x32607c,'name');_0x4e640b['query']=_[_0x7fc1('0x43')](_0x459ab0['query']);_0x4e640b[_0x7fc1('0x44')]=_[_0x7fc1('0x45')](_0x4e640b['model'],_0x4e640b[_0x7fc1('0x46')]);_0x564437[_0x7fc1('0x47')]=_[_0x7fc1('0x45')](_0x4e640b[_0x7fc1('0x48')],qs['fields'](_0x459ab0[_0x7fc1('0x46')]['fields']));_0x564437[_0x7fc1('0x47')]=_0x564437[_0x7fc1('0x47')][_0x7fc1('0x49')]?_0x564437[_0x7fc1('0x47')]:_0x4e640b['model'];if(!_0x459ab0[_0x7fc1('0x46')][_0x7fc1('0x4a')]('nolimit')){_0x564437[_0x7fc1('0x32')]=qs[_0x7fc1('0x32')](_0x459ab0['query'][_0x7fc1('0x32')]);_0x564437[_0x7fc1('0x2f')]=qs['offset'](_0x459ab0[_0x7fc1('0x46')][_0x7fc1('0x2f')]);}_0x564437[_0x7fc1('0x4b')]=qs['sort'](_0x459ab0[_0x7fc1('0x46')][_0x7fc1('0x4c')]);_0x564437[_0x7fc1('0x4d')]=qs[_0x7fc1('0x44')](_['pick'](_0x459ab0['query'],_0x4e640b[_0x7fc1('0x44')]),_0x32607c);if(_0x459ab0[_0x7fc1('0x46')][_0x7fc1('0x4e')]){_0x564437[_0x7fc1('0x4d')]=_[_0x7fc1('0x4f')](_0x564437[_0x7fc1('0x4d')],{'$or':_[_0x7fc1('0x40')](_0x32607c,function(_0x40b356){if(_0x40b356[_0x7fc1('0x42')]!=='VIRTUAL'){var _0x518a54={};_0x518a54[_0x40b356['name']]={'$like':'%'+_0x459ab0[_0x7fc1('0x46')][_0x7fc1('0x4e')]+'%'};return _0x518a54;}})});}_0x564437=_[_0x7fc1('0x4f')]({},_0x564437,_0x459ab0[_0x7fc1('0x50')]);var _0x4bcd63={'where':_0x564437[_0x7fc1('0x4d')]};return db[_0x7fc1('0x51')][_0x7fc1('0x31')](_0x4bcd63)[_0x7fc1('0x22')](function(_0x5aee49){_0x50c728[_0x7fc1('0x31')]=_0x5aee49;if(_0x459ab0[_0x7fc1('0x46')][_0x7fc1('0x52')]){_0x564437[_0x7fc1('0x53')]=[{'all':!![]}];}return db[_0x7fc1('0x51')][_0x7fc1('0x54')](_0x564437);})[_0x7fc1('0x22')](function(_0x4d27db){_0x50c728[_0x7fc1('0x55')]=_0x4d27db;return _0x50c728;})['then'](respondWithFilteredResult(_0xafc8b0,_0x564437))[_0x7fc1('0x2b')](handleError(_0xafc8b0,null));};exports['show']=function(_0x10ce10,_0x316ba4){var _0x4dbd61={'raw':![],'where':{'id':_0x10ce10[_0x7fc1('0x56')]['id']},'include':[{'model':db['Pause'],'as':_0x7fc1('0x3f')}]},_0x54f63f={};_0x54f63f[_0x7fc1('0x48')]=_[_0x7fc1('0x43')](db[_0x7fc1('0x51')]['rawAttributes']);_0x54f63f['query']=_[_0x7fc1('0x43')](_0x10ce10['query']);_0x54f63f[_0x7fc1('0x44')]=_[_0x7fc1('0x45')](_0x54f63f[_0x7fc1('0x48')],_0x54f63f[_0x7fc1('0x46')]);_0x4dbd61[_0x7fc1('0x47')]=_[_0x7fc1('0x45')](_0x54f63f[_0x7fc1('0x48')],qs[_0x7fc1('0x57')](_0x10ce10[_0x7fc1('0x46')]['fields']));_0x4dbd61['attributes']=_0x4dbd61[_0x7fc1('0x47')]['length']?_0x4dbd61[_0x7fc1('0x47')]:_0x54f63f['model'];if(_0x10ce10[_0x7fc1('0x46')][_0x7fc1('0x52')]){_0x4dbd61[_0x7fc1('0x53')]=[{'all':!![]}];}_0x4dbd61=_[_0x7fc1('0x4f')]({},_0x4dbd61,_0x10ce10[_0x7fc1('0x50')]);return db[_0x7fc1('0x51')][_0x7fc1('0x58')](_0x4dbd61)[_0x7fc1('0x22')](handleEntityNotFound(_0x316ba4,null))['then'](respondWithResult(_0x316ba4,null))[_0x7fc1('0x2b')](handleError(_0x316ba4,null));};exports['create']=function(_0x1212d4,_0x4a0849){return db[_0x7fc1('0x51')]['create'](_0x1212d4[_0x7fc1('0x59')],{})[_0x7fc1('0x22')](function(_0x382567){var _0x1d471f=_0x1212d4['user'][_0x7fc1('0x39')]({'plain':!![]});if(!_0x1d471f)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x1d471f[_0x7fc1('0x5a')]===_0x7fc1('0x5b')){var _0x1c1d06=_0x382567[_0x7fc1('0x39')]({'plain':!![]});var _0x18cdea=_0x7fc1('0x3a');return db['UserProfileSection']['find']({'where':{'name':_0x18cdea,'userProfileId':_0x1d471f['userProfileId']},'raw':!![]})[_0x7fc1('0x22')](function(_0x30bc86){if(_0x30bc86&&_0x30bc86[_0x7fc1('0x5c')]===0x0){return db[_0x7fc1('0x5d')][_0x7fc1('0x5e')]({'name':_0x1c1d06[_0x7fc1('0x3c')],'resourceId':_0x1c1d06['id'],'type':_0x30bc86[_0x7fc1('0x3c')],'sectionId':_0x30bc86['id']},{})[_0x7fc1('0x22')](function(){return _0x382567;});}else{return _0x382567;}})[_0x7fc1('0x2b')](function(_0x4c524e){logger[_0x7fc1('0x27')](_0x7fc1('0x5f'),_0x4c524e);throw _0x4c524e;});}return _0x382567;})[_0x7fc1('0x22')](respondWithResult(_0x4a0849,0xc9))[_0x7fc1('0x2b')](handleError(_0x4a0849,null));};exports[_0x7fc1('0x38')]=function(_0x543685,_0x54cd5e){if(_0x543685[_0x7fc1('0x59')]['id']){delete _0x543685[_0x7fc1('0x59')]['id'];}return db[_0x7fc1('0x51')][_0x7fc1('0x58')]({'where':{'id':_0x543685[_0x7fc1('0x56')]['id']},'include':[{'model':db[_0x7fc1('0x3e')],'as':'mandatoryDispositionPause'}]})[_0x7fc1('0x22')](handleEntityNotFound(_0x54cd5e,null))[_0x7fc1('0x22')](saveUpdates(_0x543685[_0x7fc1('0x59')],null))[_0x7fc1('0x22')](respondWithResult(_0x54cd5e,null))[_0x7fc1('0x2b')](handleError(_0x54cd5e,null));};exports[_0x7fc1('0x60')]=function(_0x3794ad,_0x14c6d9){return db['OpenchannelAccount'][_0x7fc1('0x58')]({'where':{'id':_0x3794ad['params']['id']}})[_0x7fc1('0x22')](handleEntityNotFound(_0x14c6d9,null))[_0x7fc1('0x22')](removeEntity(_0x14c6d9,null))[_0x7fc1('0x2b')](handleError(_0x14c6d9,null));};exports[_0x7fc1('0x61')]=function(_0x29e2d7,_0x5da55e){return db[_0x7fc1('0x51')][_0x7fc1('0x61')]()[_0x7fc1('0x22')](respondWithResult(_0x5da55e,null))['catch'](handleError(_0x5da55e,null));};exports[_0x7fc1('0x62')]=function(_0x4f2cf0,_0x4269a8,_0x3987b8){if(_0x4f2cf0['body']['id']){delete _0x4f2cf0[_0x7fc1('0x59')]['id'];}return db[_0x7fc1('0x51')][_0x7fc1('0x58')]({'where':{'id':_0x4f2cf0[_0x7fc1('0x56')]['id']}})['then'](handleEntityNotFound(_0x4269a8,null))[_0x7fc1('0x22')](function(_0x264d99){if(_0x264d99){_0x4f2cf0[_0x7fc1('0x59')][_0x7fc1('0x63')]=_0x264d99['id'];return db[_0x7fc1('0x64')][_0x7fc1('0x5e')](_0x4f2cf0[_0x7fc1('0x59')]);}})[_0x7fc1('0x22')](respondWithResult(_0x4269a8,null))[_0x7fc1('0x2b')](handleError(_0x4269a8,null));};exports[_0x7fc1('0x65')]=function(_0xc7629c,_0x135662,_0x372905){var _0x40d32e={'raw':![],'where':{}};var _0x2683ee={};var _0x4a8c11={'count':0x0,'rows':[]};return db[_0x7fc1('0x51')][_0x7fc1('0x66')]({'where':{'id':_0xc7629c[_0x7fc1('0x56')]['id']}})[_0x7fc1('0x22')](handleEntityNotFound(_0x135662,null))[_0x7fc1('0x22')](function(_0x6943b){if(_0x6943b){_0x2683ee['model']=_['keys'](db[_0x7fc1('0x64')][_0x7fc1('0x67')]);_0x2683ee[_0x7fc1('0x46')]=_[_0x7fc1('0x43')](_0xc7629c[_0x7fc1('0x46')]);_0x2683ee[_0x7fc1('0x44')]=_['intersection'](_0x2683ee[_0x7fc1('0x48')],_0x2683ee[_0x7fc1('0x46')]);_0x40d32e['attributes']=_[_0x7fc1('0x45')](_0x2683ee['model'],qs[_0x7fc1('0x57')](_0xc7629c[_0x7fc1('0x46')]['fields']));_0x40d32e['attributes']=_0x40d32e[_0x7fc1('0x47')][_0x7fc1('0x49')]?_0x40d32e[_0x7fc1('0x47')]:_0x2683ee[_0x7fc1('0x48')];if(!_0xc7629c[_0x7fc1('0x46')][_0x7fc1('0x4a')](_0x7fc1('0x68'))){_0x40d32e['limit']=qs[_0x7fc1('0x32')](_0xc7629c[_0x7fc1('0x46')][_0x7fc1('0x32')]);_0x40d32e[_0x7fc1('0x2f')]=qs[_0x7fc1('0x2f')](_0xc7629c[_0x7fc1('0x46')]['offset']);}_0x40d32e[_0x7fc1('0x4b')]=qs[_0x7fc1('0x4c')](_0xc7629c[_0x7fc1('0x46')]['sort']);_0x40d32e[_0x7fc1('0x4d')]=qs['filters'](_['pick'](_0xc7629c['query'],_0x2683ee[_0x7fc1('0x44')]));_0x40d32e[_0x7fc1('0x4d')][_0x7fc1('0x63')]=_0x6943b['id'];if(_0xc7629c[_0x7fc1('0x46')][_0x7fc1('0x4e')]){_0x40d32e[_0x7fc1('0x4d')]=_['merge'](_0x40d32e[_0x7fc1('0x4d')],{'$or':_['map'](_0x40d32e['attributes'],function(_0x4aa587){var _0x43cb18={};_0x43cb18[_0x4aa587]={'$like':'%'+_0xc7629c[_0x7fc1('0x46')][_0x7fc1('0x4e')]+'%'};return _0x43cb18;})});}_0x40d32e=_['merge']({},_0x40d32e,_0xc7629c[_0x7fc1('0x50')]);return db[_0x7fc1('0x64')][_0x7fc1('0x31')]({'where':_0x40d32e[_0x7fc1('0x4d')]})[_0x7fc1('0x22')](function(_0x2f28be){_0x4a8c11['count']=_0x2f28be;if(_0xc7629c[_0x7fc1('0x46')][_0x7fc1('0x52')]){_0x40d32e[_0x7fc1('0x53')]=[{'all':!![]}];}return db[_0x7fc1('0x64')]['findAll'](_0x40d32e);})['then'](function(_0x5b6669){_0x4a8c11[_0x7fc1('0x55')]=_0x5b6669;return _0x4a8c11;});}})[_0x7fc1('0x22')](respondWithFilteredResult(_0x135662,_0x40d32e))[_0x7fc1('0x2b')](handleError(_0x135662,null));};exports[_0x7fc1('0x69')]=function(_0x5a0428,_0x3576aa,_0x771c6a){return db['OpenchannelAccount']['find']({'where':{'id':_0x5a0428[_0x7fc1('0x56')]['id']}})[_0x7fc1('0x22')](handleEntityNotFound(_0x3576aa,null))['then'](function(_0x15899d){if(_0x15899d){return _0x15899d[_0x7fc1('0x69')](_0x5a0428['query'][_0x7fc1('0x6a')]);}})[_0x7fc1('0x22')](respondWithStatusCode(_0x3576aa,null))[_0x7fc1('0x2b')](handleError(_0x3576aa,null));};exports['addAnswer']=function(_0x191e21,_0x357bf1,_0x152a6e){if(_0x191e21[_0x7fc1('0x59')]['id']){delete _0x191e21['body']['id'];}return db['OpenchannelAccount']['find']({'where':{'id':_0x191e21[_0x7fc1('0x56')]['id']}})[_0x7fc1('0x22')](handleEntityNotFound(_0x357bf1,null))['then'](function(_0x474256){if(_0x474256){_0x191e21[_0x7fc1('0x59')][_0x7fc1('0x63')]=_0x474256['id'];return db[_0x7fc1('0x6b')][_0x7fc1('0x5e')](_0x191e21[_0x7fc1('0x59')]);}})[_0x7fc1('0x22')](respondWithResult(_0x357bf1,null))[_0x7fc1('0x2b')](handleError(_0x357bf1,null));};exports[_0x7fc1('0x6c')]=function(_0x38abee,_0xdeea02,_0x565c08){var _0x4581f8={'raw':![],'where':{}};var _0x388817={};var _0x512a31={'count':0x0,'rows':[]};return db[_0x7fc1('0x51')][_0x7fc1('0x66')]({'where':{'id':_0x38abee['params']['id']}})['then'](handleEntityNotFound(_0xdeea02,null))[_0x7fc1('0x22')](function(_0x6b25e5){if(_0x6b25e5){_0x388817[_0x7fc1('0x48')]=_['keys'](db[_0x7fc1('0x6b')][_0x7fc1('0x67')]);_0x388817[_0x7fc1('0x46')]=_[_0x7fc1('0x43')](_0x38abee[_0x7fc1('0x46')]);_0x388817['filters']=_['intersection'](_0x388817[_0x7fc1('0x48')],_0x388817[_0x7fc1('0x46')]);_0x4581f8[_0x7fc1('0x47')]=_[_0x7fc1('0x45')](_0x388817[_0x7fc1('0x48')],qs['fields'](_0x38abee[_0x7fc1('0x46')]['fields']));_0x4581f8[_0x7fc1('0x47')]=_0x4581f8[_0x7fc1('0x47')][_0x7fc1('0x49')]?_0x4581f8['attributes']:_0x388817[_0x7fc1('0x48')];if(!_0x38abee[_0x7fc1('0x46')]['hasOwnProperty'](_0x7fc1('0x68'))){_0x4581f8['limit']=qs['limit'](_0x38abee[_0x7fc1('0x46')]['limit']);_0x4581f8['offset']=qs[_0x7fc1('0x2f')](_0x38abee[_0x7fc1('0x46')]['offset']);}_0x4581f8[_0x7fc1('0x4b')]=qs[_0x7fc1('0x4c')](_0x38abee[_0x7fc1('0x46')]['sort']);_0x4581f8['where']=qs[_0x7fc1('0x44')](_[_0x7fc1('0x6d')](_0x38abee['query'],_0x388817['filters']));_0x4581f8[_0x7fc1('0x4d')][_0x7fc1('0x63')]=_0x6b25e5['id'];if(_0x38abee[_0x7fc1('0x46')][_0x7fc1('0x4e')]){_0x4581f8[_0x7fc1('0x4d')]=_['merge'](_0x4581f8[_0x7fc1('0x4d')],{'$or':_[_0x7fc1('0x40')](_0x4581f8[_0x7fc1('0x47')],function(_0x4c5c84){var _0x48ee2b={};_0x48ee2b[_0x4c5c84]={'$like':'%'+_0x38abee[_0x7fc1('0x46')]['filter']+'%'};return _0x48ee2b;})});}_0x4581f8=_[_0x7fc1('0x4f')]({},_0x4581f8,_0x38abee['options']);return db[_0x7fc1('0x6b')][_0x7fc1('0x31')]({'where':_0x4581f8['where']})[_0x7fc1('0x22')](function(_0x155022){_0x512a31['count']=_0x155022;if(_0x38abee['query'][_0x7fc1('0x52')]){_0x4581f8['include']=[{'all':!![]}];}return db[_0x7fc1('0x6b')][_0x7fc1('0x54')](_0x4581f8);})[_0x7fc1('0x22')](function(_0x401919){_0x512a31[_0x7fc1('0x55')]=_0x401919;return _0x512a31;});}})[_0x7fc1('0x22')](respondWithFilteredResult(_0xdeea02,_0x4581f8))[_0x7fc1('0x2b')](handleError(_0xdeea02,null));};exports[_0x7fc1('0x6e')]=function(_0x4ed9bb,_0x524d5d,_0x203a6e){return db[_0x7fc1('0x51')]['find']({'where':{'id':_0x4ed9bb[_0x7fc1('0x56')]['id']}})['then'](handleEntityNotFound(_0x524d5d,null))['then'](function(_0x2094ab){if(_0x2094ab){return _0x2094ab['removeAnswers'](_0x4ed9bb[_0x7fc1('0x46')][_0x7fc1('0x6a')]);}})['then'](respondWithStatusCode(_0x524d5d,null))[_0x7fc1('0x2b')](handleError(_0x524d5d,null));};exports[_0x7fc1('0x6f')]=function(_0x5275f8,_0x19ead1,_0x5391c2){var _0x87bd80={'body':_0x5275f8[_0x7fc1('0x59')],'channel':_0x7fc1('0x70')};var _0x5f5d56=[];var _0x15a7aa=[];var _0x43e7b8={};var _0x5e42f2=![];return db[_0x7fc1('0x71')][_0x7fc1('0x61')]()[_0x7fc1('0x22')](function(_0x52be0e){if(!_0x52be0e){throw new db['Sequelize'][(_0x7fc1('0x72'))](_0x7fc1('0x73'));}_0x5f5d56=_['difference'](_[_0x7fc1('0x43')](_0x52be0e),[_0x7fc1('0x74'),'updatedAt']);_0x15a7aa=_['difference'](_[_0x7fc1('0x43')](_0x52be0e),[_0x7fc1('0x74'),'updatedAt',_0x7fc1('0x75'),_0x7fc1('0x76')]);if(_0x5275f8['body']['id']){delete _0x5275f8[_0x7fc1('0x59')]['id'];}if(_[_0x7fc1('0x77')](_0x5275f8[_0x7fc1('0x59')]['from'])){throw new db[(_0x7fc1('0x78'))][(_0x7fc1('0x72'))](_0x7fc1('0x79'));}if(_['isNil'](_0x5275f8['body'][_0x7fc1('0x59')])||_0x5275f8['body']['body']===''){throw new db['Sequelize'][(_0x7fc1('0x72'))](_0x7fc1('0x7a'));}if(_[_0x7fc1('0x77')](_0x5275f8['body'][_0x7fc1('0x7b')])){throw new db[(_0x7fc1('0x78'))]['ValidationError'](_0x7fc1('0x7c')+_0x15a7aa);}if(!_['includes'](_0x15a7aa,_0x5275f8[_0x7fc1('0x59')][_0x7fc1('0x7b')])){throw new db[(_0x7fc1('0x78'))][(_0x7fc1('0x72'))](_0x7fc1('0x7d')+_0x15a7aa);}_0x43e7b8[_0x5275f8[_0x7fc1('0x59')][_0x7fc1('0x7b')]]=_0x5275f8[_0x7fc1('0x59')]['from'];})[_0x7fc1('0x22')](function(){return db[_0x7fc1('0x51')][_0x7fc1('0x58')]({'where':{'id':_0x5275f8[_0x7fc1('0x56')]['id']},'include':[{'model':db['CmList'],'as':'List','include':[{'model':db['CmContact'],'as':_0x7fc1('0x7e'),'where':_0x43e7b8,'limit':0x1,'order':[[_0x7fc1('0x7f'),'DESC']]}]},{'model':db[_0x7fc1('0x80')],'as':_0x7fc1('0x81')}]});})[_0x7fc1('0x22')](handleEntityNotFound(_0x19ead1,null))['then'](function(_0x11d81c){if(_0x11d81c&&_0x11d81c[_0x7fc1('0x82')]){_0x87bd80[_0x7fc1('0x83')]=_0x11d81c;_0x87bd80[_0x7fc1('0x84')]=_0x11d81c[_0x7fc1('0x81')];_0x87bd80[_0x7fc1('0x85')]=_0x11d81c[_0x7fc1('0x82')];_0x87bd80[_0x7fc1('0x84')]=_[_0x7fc1('0x86')](_0x87bd80[_0x7fc1('0x84')],[_0x7fc1('0x87')],[_0x7fc1('0x88')]);if(_0x87bd80[_0x7fc1('0x83')][_0x7fc1('0x81')]){delete _0x87bd80[_0x7fc1('0x83')][_0x7fc1('0x81')];}if(_0x87bd80[_0x7fc1('0x83')]['List']&&_0x87bd80[_0x7fc1('0x83')][_0x7fc1('0x82')][_0x7fc1('0x7e')][_0x7fc1('0x49')]){return _0x87bd80['account'][_0x7fc1('0x82')][_0x7fc1('0x7e')][0x0];}var _0x23dea8=_[_0x7fc1('0x1c')](_0x5275f8[_0x7fc1('0x59')],{'firstName':_0x5275f8[_0x7fc1('0x59')][_0x7fc1('0x89')],'ListId':_0x11d81c['ListId']});_0x23dea8[_0x5275f8['body'][_0x7fc1('0x7b')]]=_0x5275f8[_0x7fc1('0x59')][_0x7fc1('0x89')];return db[_0x7fc1('0x71')][_0x7fc1('0x5e')](_0x23dea8,{'fields':_0x5f5d56,'raw':!![]});}})[_0x7fc1('0x22')](handleEntityNotFound(_0x19ead1,null))['then'](function(_0x52a5b4){_0x87bd80['contact']=_0x52a5b4;if(_0x52a5b4){var _0x1e6619={'ContactId':_0x52a5b4['id'],'OpenchannelAccountId':_0x5275f8[_0x7fc1('0x56')]['id'],'from':(_0x52a5b4[_0x7fc1('0x8a')]||'')+'\x20'+(_0x52a5b4[_0x7fc1('0x8b')]||'')};var _0x487bc7={'OpenchannelAccountId':_0x5275f8['params']['id'],'closed':![]};if(_0x5275f8['body'][_0x7fc1('0x8c')]){_0x487bc7[_0x7fc1('0x8c')]=_0x5275f8[_0x7fc1('0x59')][_0x7fc1('0x8c')];return db[_0x7fc1('0x8d')][_0x7fc1('0x58')]({'where':_0x487bc7})[_0x7fc1('0x22')](function(_0x3281c8){if(_0x3281c8){return[_0x3281c8,![]];}_0x1e6619[_0x7fc1('0x8c')]=_0x5275f8[_0x7fc1('0x59')]['threadId'];_0x1e6619['externalUrl']=_0x5275f8[_0x7fc1('0x59')]['externalUrl'];return db[_0x7fc1('0x8d')][_0x7fc1('0x5e')](_0x1e6619)[_0x7fc1('0x22')](function(_0x1aaf75){return[_0x1aaf75,!![]];});});}else{_0x487bc7[_0x7fc1('0x8c')]=null;}_0x487bc7[_0x7fc1('0x8e')]=_0x52a5b4['id'];return db['OpenchannelInteraction'][_0x7fc1('0x58')]({'where':_0x487bc7})[_0x7fc1('0x22')](function(_0x4e370f){if(_0x4e370f){return[_0x4e370f,![]];}return db[_0x7fc1('0x8d')][_0x7fc1('0x5e')](_0x1e6619)[_0x7fc1('0x22')](function(_0x389b69){return[_0x389b69,!![]];});});}})[_0x7fc1('0x8f')](function(_0x98ad70,_0x3bc1d2){if(_0x98ad70){_0x5e42f2=_0x3bc1d2;if(!_0x3bc1d2){var _0x5aeb6c={'from':(_0x87bd80[_0x7fc1('0x90')][_0x7fc1('0x8a')]||'')+'\x20'+(_0x87bd80[_0x7fc1('0x90')][_0x7fc1('0x8b')]||'')};if(_0x5275f8[_0x7fc1('0x59')][_0x7fc1('0x8c')]&&_0x5275f8[_0x7fc1('0x59')][_0x7fc1('0x91')]&&_0x5275f8[_0x7fc1('0x59')]['threadId']!=_0x5275f8[_0x7fc1('0x59')][_0x7fc1('0x91')]){_0x5aeb6c[_0x7fc1('0x8c')]=_0x5275f8[_0x7fc1('0x59')][_0x7fc1('0x91')];}return _0x98ad70[_0x7fc1('0x38')](_0x5aeb6c);}else{return _0x98ad70;}}})[_0x7fc1('0x22')](function(_0x28e9bb){_0x87bd80[_0x7fc1('0x92')]=_0x28e9bb[_0x7fc1('0x39')]({'plain':!![]});_0x87bd80[_0x7fc1('0x92')][_0x7fc1('0x93')]=_0x5e42f2;if(_0x87bd80[_0x7fc1('0x92')]['created']){if(_0x87bd80[_0x7fc1('0x83')]['autoclose']){_0x87bd80[_0x7fc1('0x84')][_0x7fc1('0x94')]({'id':0x0,'priority':_0x87bd80['applications'][_0x7fc1('0x49')]+0x1,'app':_0x7fc1('0x95'),'appdata':_0x7fc1('0x96'),'interval':_0x7fc1('0x97')});}}return db[_0x7fc1('0x98')][_0x7fc1('0x5e')]({'body':_0x5275f8['body']['body'],'OpenchannelAccountId':_0x5275f8[_0x7fc1('0x56')]['id'],'OpenchannelInteractionId':_0x28e9bb['id'],'direction':'in','ContactId':_0x87bd80[_0x7fc1('0x90')]['id'],'AttachmentId':_0x5275f8[_0x7fc1('0x59')][_0x7fc1('0x99')]});})[_0x7fc1('0x22')](function(_0x4f8b2f){_0x87bd80[_0x7fc1('0x29')]=_0x4f8b2f;if(!_0x87bd80[_0x7fc1('0x92')][_0x7fc1('0x9a')])return;return db['User']['find']({'attributes':['id','name'],'where':{'id':_0x87bd80['interaction'][_0x7fc1('0x9a')]}});})[_0x7fc1('0x22')](function(_0x675112){if(_0x675112){_0x87bd80[_0x7fc1('0x84')][_0x7fc1('0x9b')]({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x675112[_0x7fc1('0x3c')]+','+(_0x87bd80[_0x7fc1('0x83')][_0x7fc1('0x9c')]||0xa),'interval':_0x7fc1('0x97')});}if(!_0x87bd80[_0x7fc1('0x92')]['queueId'])return;return db[_0x7fc1('0x9d')][_0x7fc1('0x58')]({'attributes':['id',_0x7fc1('0x3c')],'where':{'id':_0x87bd80[_0x7fc1('0x92')][_0x7fc1('0x9e')]}});})[_0x7fc1('0x22')](function(_0x55cb98){if(_0x55cb98){_0x87bd80[_0x7fc1('0x84')]['unshift']({'id':0x0,'priority':0x1,'app':'queue','appdata':_0x55cb98[_0x7fc1('0x3c')]+','+(_0x87bd80[_0x7fc1('0x83')][_0x7fc1('0x9f')]||0x12c),'interval':_0x7fc1('0x97')});}return respondWithRpcPromise('Start',_0x7fc1('0xa0'),_0x87bd80);})[_0x7fc1('0x22')](function(_0xff6d1a){respondWithRpcPromise(_0x7fc1('0xa1'),'EventManager',{'event':_0x7fc1('0x6f'),'message':_0xff6d1a},client9002);return _0xff6d1a;})['then'](respondWithResult(_0x19ead1,null))[_0x7fc1('0x2b')](handleError(_0x19ead1,null));};exports[_0x7fc1('0xa2')]=function(_0xd79842,_0x21b102){var _0x890dc6=_0xd79842[_0x7fc1('0x56')]['id'];var _0x805f5a=_0xd79842[_0x7fc1('0x59')];var _0x5105f6=0xc8;var _0x47798c=null;return db[_0x7fc1('0xa3')][_0x7fc1('0xa4')]({'isolationLevel':db[_0x7fc1('0xa3')][_0x7fc1('0xa5')][_0x7fc1('0xa6')][_0x7fc1('0xa7')]},function(_0x354508){return db[_0x7fc1('0x51')][_0x7fc1('0x66')]({'where':{'id':_0x890dc6},'transaction':_0x354508})[_0x7fc1('0x22')](function(_0x4aee8a){if(_0x4aee8a){return db[_0x7fc1('0x80')][_0x7fc1('0x60')]({'where':{'OpenchannelAccountId':_0x890dc6},'transaction':_0x354508})[_0x7fc1('0x22')](function(){var _0x293640=_[_0x7fc1('0x40')](_0x805f5a,function(_0x169ed7){_0x169ed7[_0x7fc1('0x63')]=_0x890dc6;return _0x169ed7;});return db[_0x7fc1('0x80')][_0x7fc1('0xa8')](_0x293640,{'transaction':_0x354508});});}else{_0x5105f6=0x194;_0x47798c=[];}});})[_0x7fc1('0x22')](function(){if(_0x5105f6!==0x194){return db[_0x7fc1('0x80')][_0x7fc1('0xa9')]({'where':{'OpenchannelAccountId':_0x890dc6},'order':_0x7fc1('0x87')})['then'](function(_0x4d75fc){_0x47798c=_0x4d75fc;});}})[_0x7fc1('0x2b')](function(_0x16b642){_0x5105f6=0x1f4;logger[_0x7fc1('0x27')](_0x16b642[_0x7fc1('0x3b')]);if(_0x16b642['name']){delete _0x16b642[_0x7fc1('0x3c')];}_0x47798c=_0x16b642;})[_0x7fc1('0xaa')](function(){if(_0x47798c===null){_0x21b102[_0x7fc1('0x2c')](_0x5105f6);}else{if(_0x5105f6===0x1f4){_0x21b102[_0x7fc1('0x33')](_0x5105f6)[_0x7fc1('0xab')](_0x47798c);}else{_0x21b102[_0x7fc1('0x33')](_0x5105f6)['json'](_0x47798c);}}});};exports[_0x7fc1('0xac')]=function(_0x3bff5a,_0x382e02,_0x1d17de){var _0x64762e={};var _0x5c17f1={};var _0x29ee44;var _0x181086;return db['OpenchannelAccount']['findOne']({'where':{'id':_0x3bff5a[_0x7fc1('0x56')]['id']}})[_0x7fc1('0x22')](handleEntityNotFound(_0x382e02,null))[_0x7fc1('0x22')](function(_0x4866b8){if(_0x4866b8){_0x29ee44=_0x4866b8;_0x5c17f1[_0x7fc1('0x48')]=_['keys'](db[_0x7fc1('0x80')][_0x7fc1('0x67')]);_0x5c17f1[_0x7fc1('0x46')]=_[_0x7fc1('0x43')](_0x3bff5a[_0x7fc1('0x46')]);_0x5c17f1[_0x7fc1('0x44')]=_[_0x7fc1('0x45')](_0x5c17f1[_0x7fc1('0x48')],_0x5c17f1[_0x7fc1('0x46')]);_0x64762e[_0x7fc1('0x47')]=_[_0x7fc1('0x45')](_0x5c17f1[_0x7fc1('0x48')],qs[_0x7fc1('0x57')](_0x3bff5a[_0x7fc1('0x46')][_0x7fc1('0x57')]));_0x64762e[_0x7fc1('0x47')]=_0x64762e[_0x7fc1('0x47')][_0x7fc1('0x49')]?_0x64762e[_0x7fc1('0x47')]:_0x5c17f1[_0x7fc1('0x48')];_0x64762e[_0x7fc1('0x4b')]=qs[_0x7fc1('0x4c')](_0x3bff5a['query'][_0x7fc1('0x4c')]);_0x64762e[_0x7fc1('0x4d')]=qs[_0x7fc1('0x44')](_[_0x7fc1('0x6d')](_0x3bff5a[_0x7fc1('0x46')],_0x5c17f1['filters']));if(_0x3bff5a[_0x7fc1('0x46')][_0x7fc1('0x4e')]){_0x64762e['where']=_[_0x7fc1('0x4f')](_0x64762e[_0x7fc1('0x4d')],{'$or':_[_0x7fc1('0x40')](_0x64762e[_0x7fc1('0x47')],function(_0x467293){var _0x59849c={};_0x59849c[_0x467293]={'$like':'%'+_0x3bff5a[_0x7fc1('0x46')][_0x7fc1('0x4e')]+'%'};return _0x59849c;})});}_0x64762e=_[_0x7fc1('0x4f')]({},_0x64762e,_0x3bff5a['options']);return _0x29ee44[_0x7fc1('0xac')](_0x64762e);}})[_0x7fc1('0x22')](function(_0x313ea1){if(_0x313ea1){_0x181086=_0x313ea1[_0x7fc1('0x49')];if(!_0x3bff5a[_0x7fc1('0x46')]['hasOwnProperty'](_0x7fc1('0x68'))){_0x64762e[_0x7fc1('0x32')]=qs[_0x7fc1('0x32')](_0x3bff5a[_0x7fc1('0x46')]['limit']);_0x64762e[_0x7fc1('0x2f')]=qs[_0x7fc1('0x2f')](_0x3bff5a[_0x7fc1('0x46')][_0x7fc1('0x2f')]);}return _0x29ee44[_0x7fc1('0xac')](_0x64762e);}})[_0x7fc1('0x22')](function(_0x4cd0b4){if(_0x4cd0b4){return _0x4cd0b4?{'count':_0x181086,'rows':_0x4cd0b4}:null;}})[_0x7fc1('0x22')](respondWithResult(_0x382e02,null))[_0x7fc1('0x2b')](handleError(_0x382e02,null));};exports[_0x7fc1('0xad')]=function(_0x1e2887,_0x5d2b3a,_0x4bb095){var _0x560fb5={'raw':![],'where':{}};var _0x58c541={};var _0x2d2721={'count':0x0,'rows':[]};return db['OpenchannelAccount']['findOne']({'where':{'id':_0x1e2887[_0x7fc1('0x56')]['id']}})[_0x7fc1('0x22')](handleEntityNotFound(_0x5d2b3a,null))[_0x7fc1('0x22')](function(_0x4b52e7){if(_0x4b52e7){_0x58c541[_0x7fc1('0x48')]=_[_0x7fc1('0x43')](db[_0x7fc1('0x8d')][_0x7fc1('0x67')]);_0x58c541[_0x7fc1('0x46')]=_[_0x7fc1('0x43')](_0x1e2887[_0x7fc1('0x46')]);_0x58c541[_0x7fc1('0x44')]=_[_0x7fc1('0x45')](_0x58c541[_0x7fc1('0x48')],_0x58c541[_0x7fc1('0x46')]);_0x560fb5[_0x7fc1('0x47')]=_['intersection'](_0x58c541[_0x7fc1('0x48')],qs[_0x7fc1('0x57')](_0x1e2887[_0x7fc1('0x46')]['fields']));_0x560fb5[_0x7fc1('0x47')]=_0x560fb5[_0x7fc1('0x47')][_0x7fc1('0x49')]?_0x560fb5[_0x7fc1('0x47')]:_0x58c541[_0x7fc1('0x48')];if(!_0x1e2887[_0x7fc1('0x46')][_0x7fc1('0x4a')]('nolimit')){_0x560fb5[_0x7fc1('0x32')]=qs[_0x7fc1('0x32')](_0x1e2887['query'][_0x7fc1('0x32')]);_0x560fb5[_0x7fc1('0x2f')]=qs[_0x7fc1('0x2f')](_0x1e2887['query'][_0x7fc1('0x2f')]);}_0x560fb5[_0x7fc1('0x4b')]=qs[_0x7fc1('0x4c')](_0x1e2887['query'][_0x7fc1('0x4c')]);_0x560fb5[_0x7fc1('0x4d')]=qs[_0x7fc1('0x44')](_[_0x7fc1('0x6d')](_0x1e2887['query'],_0x58c541['filters']));_0x560fb5[_0x7fc1('0x4d')]['OpenchannelAccountId']=_0x4b52e7['id'];if(_0x1e2887[_0x7fc1('0x46')]['filter']){_0x560fb5[_0x7fc1('0x4d')]=_[_0x7fc1('0x4f')](_0x560fb5[_0x7fc1('0x4d')],{'$or':_[_0x7fc1('0x40')](_0x560fb5[_0x7fc1('0x47')],function(_0xec17a){var _0x5ac685={};_0x5ac685[_0xec17a]={'$like':'%'+_0x1e2887[_0x7fc1('0x46')][_0x7fc1('0x4e')]+'%'};return _0x5ac685;})});}_0x560fb5=_[_0x7fc1('0x4f')]({},_0x560fb5,_0x1e2887[_0x7fc1('0x50')]);return db[_0x7fc1('0x8d')][_0x7fc1('0x31')]({'where':_0x560fb5[_0x7fc1('0x4d')]})[_0x7fc1('0x22')](function(_0x369616){_0x2d2721['count']=_0x369616;if(_0x1e2887['query']['includeAll']){_0x560fb5[_0x7fc1('0x53')]=[{'model':db[_0x7fc1('0x71')],'as':'Contact','required':![]},{'model':db[_0x7fc1('0xae')],'as':_0x7fc1('0xaf'),'attributes':['name',_0x7fc1('0xb0'),'internal'],'required':![]},{'model':db[_0x7fc1('0xb1')],'as':'Tags','attributes':['id',_0x7fc1('0x3c'),_0x7fc1('0xb2')],'where':_0x1e2887['query'][_0x7fc1('0xb3')]?{'id':_0x1e2887[_0x7fc1('0x46')][_0x7fc1('0xb3')]}:undefined,'required':_0x1e2887[_0x7fc1('0x46')][_0x7fc1('0xb3')]?!![]:![]}];}return db[_0x7fc1('0x8d')][_0x7fc1('0x54')](_0x560fb5);})[_0x7fc1('0x22')](function(_0x185df9){_0x2d2721[_0x7fc1('0x55')]=_0x185df9;return _0x2d2721;});}})[_0x7fc1('0x22')](respondWithFilteredResult(_0x5d2b3a,_0x560fb5))[_0x7fc1('0x2b')](handleError(_0x5d2b3a,null));};exports[_0x7fc1('0xb4')]=function(_0xbf3021,_0xb56e6c,_0x5293d8){return db[_0x7fc1('0x51')][_0x7fc1('0x58')]({'where':{'id':_0xbf3021['params']['id']}})[_0x7fc1('0x22')](handleEntityNotFound(_0xb56e6c,null))[_0x7fc1('0x22')](function(_0x5e06ca){if(_0x5e06ca){return _0x5e06ca[_0x7fc1('0xb4')](_0xbf3021[_0x7fc1('0x59')][_0x7fc1('0x6a')],_[_0x7fc1('0xb5')](_0xbf3021[_0x7fc1('0x59')],[_0x7fc1('0x6a'),'id'])||{})[_0x7fc1('0x8f')](function(_0x19e053){for(var _0x3fc359=0x0;_0x3fc359<_0xbf3021[_0x7fc1('0x59')][_0x7fc1('0x6a')][_0x7fc1('0x49')];_0x3fc359+=0x1){socket[_0x7fc1('0xb6')](_0x7fc1('0xb7'),{'UserId':Number(_0xbf3021['body'][_0x7fc1('0x6a')][_0x3fc359]),'OpenchannelAccountId':Number(_0xbf3021[_0x7fc1('0x56')]['id'])});}return _0x19e053;});}})['then'](respondWithResult(_0xb56e6c,null))[_0x7fc1('0x2b')](handleError(_0xb56e6c,null));};exports[_0x7fc1('0xb8')]=function(_0x54342d,_0x2c1766,_0x534604){return db[_0x7fc1('0x51')][_0x7fc1('0x58')]({'where':{'id':_0x54342d['params']['id']}})[_0x7fc1('0x22')](handleEntityNotFound(_0x2c1766,null))[_0x7fc1('0x22')](function(_0xfd967e){if(_0xfd967e){return _0xfd967e[_0x7fc1('0xb8')](_0x54342d[_0x7fc1('0x46')][_0x7fc1('0x6a')])[_0x7fc1('0x22')](function(){if(_[_0x7fc1('0xb9')](_0x54342d['query'][_0x7fc1('0x6a')])){for(var _0x25c72a=0x0;_0x25c72a<_0x54342d[_0x7fc1('0x46')][_0x7fc1('0x6a')][_0x7fc1('0x49')];_0x25c72a+=0x1){socket[_0x7fc1('0xb6')](_0x7fc1('0xba'),{'UserId':Number(_0x54342d['query'][_0x7fc1('0x6a')][_0x25c72a]),'OpenchannelAccountId':Number(_0x54342d[_0x7fc1('0x56')]['id'])});}}else{socket[_0x7fc1('0xb6')](_0x7fc1('0xba'),{'UserId':Number(_0x54342d[_0x7fc1('0x46')][_0x7fc1('0x6a')]),'OpenchannelAccountId':Number(_0x54342d[_0x7fc1('0x56')]['id'])});}});}})['then'](respondWithStatusCode(_0x2c1766,null))['catch'](handleError(_0x2c1766,null));};exports[_0x7fc1('0xbb')]=function(_0x2ce672,_0x5a4127,_0x5a4427){var _0x264dd8={};var _0x503ab7={};var _0x3cbde5;var _0x5eaf65;return db[_0x7fc1('0x51')][_0x7fc1('0x66')]({'where':{'id':_0x2ce672[_0x7fc1('0x56')]['id']}})[_0x7fc1('0x22')](handleEntityNotFound(_0x5a4127,null))[_0x7fc1('0x22')](function(_0x5916e4){if(_0x5916e4){_0x3cbde5=_0x5916e4;_0x503ab7[_0x7fc1('0x48')]=_[_0x7fc1('0x43')](db[_0x7fc1('0xae')][_0x7fc1('0x67')]);_0x503ab7[_0x7fc1('0x46')]=_[_0x7fc1('0x43')](_0x2ce672['query']);_0x503ab7[_0x7fc1('0x44')]=_[_0x7fc1('0x45')](_0x503ab7[_0x7fc1('0x48')],_0x503ab7[_0x7fc1('0x46')]);_0x264dd8[_0x7fc1('0x47')]=_['intersection'](_0x503ab7[_0x7fc1('0x48')],qs['fields'](_0x2ce672[_0x7fc1('0x46')][_0x7fc1('0x57')]));_0x264dd8['attributes']=_0x264dd8[_0x7fc1('0x47')]['length']?_0x264dd8['attributes']:_0x503ab7[_0x7fc1('0x48')];_0x264dd8['order']=qs[_0x7fc1('0x4c')](_0x2ce672[_0x7fc1('0x46')][_0x7fc1('0x4c')]);_0x264dd8[_0x7fc1('0x4d')]=qs[_0x7fc1('0x44')](_['pick'](_0x2ce672[_0x7fc1('0x46')],_0x503ab7[_0x7fc1('0x44')]));if(_0x2ce672[_0x7fc1('0x46')]['filter']){_0x264dd8[_0x7fc1('0x4d')]=_[_0x7fc1('0x4f')](_0x264dd8[_0x7fc1('0x4d')],{'$or':_[_0x7fc1('0x40')](_0x264dd8[_0x7fc1('0x47')],function(_0x5eb79a){var _0x6f3ea9={};_0x6f3ea9[_0x5eb79a]={'$like':'%'+_0x2ce672['query'][_0x7fc1('0x4e')]+'%'};return _0x6f3ea9;})});}_0x264dd8=_[_0x7fc1('0x4f')]({},_0x264dd8,_0x2ce672['options']);return _0x3cbde5[_0x7fc1('0xbb')](_0x264dd8);}})[_0x7fc1('0x22')](function(_0x2a921d){if(_0x2a921d){_0x5eaf65=_0x2a921d[_0x7fc1('0x49')];if(!_0x2ce672['query'][_0x7fc1('0x4a')](_0x7fc1('0x68'))){_0x264dd8[_0x7fc1('0x32')]=qs[_0x7fc1('0x32')](_0x2ce672[_0x7fc1('0x46')][_0x7fc1('0x32')]);_0x264dd8['offset']=qs[_0x7fc1('0x2f')](_0x2ce672[_0x7fc1('0x46')][_0x7fc1('0x2f')]);}return _0x3cbde5[_0x7fc1('0xbb')](_0x264dd8);}})[_0x7fc1('0x22')](function(_0x412c7e){if(_0x412c7e){return _0x412c7e?{'count':_0x5eaf65,'rows':_0x412c7e}:null;}})['then'](respondWithResult(_0x5a4127,null))['catch'](handleError(_0x5a4127,null));};exports[_0x7fc1('0xab')]=function(_0x1d079a,_0x5f12e0,_0x40aad8){var _0x5a774a,_0x5c816c,_0x5b7309;if(_[_0x7fc1('0x77')](_0x1d079a['body'][_0x7fc1('0x59')])||_0x1d079a[_0x7fc1('0x59')][_0x7fc1('0x59')]===''){throw new db['Sequelize'][(_0x7fc1('0x72'))](_0x7fc1('0x7a'));}if(_[_0x7fc1('0x77')](_0x1d079a[_0x7fc1('0x59')]['to'])){}_0x5a774a=_0x1d079a[_0x7fc1('0x59')]['to'];return db[_0x7fc1('0x51')][_0x7fc1('0x66')]({'where':{'id':_0x1d079a[_0x7fc1('0x56')]['id']}})[_0x7fc1('0x22')](handleEntityNotFound(_0x5f12e0,null))[_0x7fc1('0x22')](function(_0x35cf99){if(_0x35cf99){return db['OpenchannelAccount']['find']({'where':{'id':_0x35cf99['id']},'include':[{'model':db['CmList'],'as':_0x7fc1('0x82'),'include':[{'model':db[_0x7fc1('0x71')],'as':_0x7fc1('0x7e'),'where':{[_0x35cf99[_0x7fc1('0x7b')]]:_0x5a774a},'limit':0x1,'order':[[_0x7fc1('0x7f'),_0x7fc1('0xbc')]]}]}]})[_0x7fc1('0x22')](handleEntityNotFound(_0x5f12e0,null))[_0x7fc1('0x22')](function(_0x277fee){if(_0x277fee&&_0x277fee['List']){_0x5c816c=_0x277fee[_0x7fc1('0x39')]({'plain':!![]});if(_0x5c816c[_0x7fc1('0x82')]&&_0x5c816c['List'][_0x7fc1('0x7e')][_0x7fc1('0x49')]){return _0x5c816c[_0x7fc1('0x82')][_0x7fc1('0x7e')][0x0];}return db[_0x7fc1('0x71')][_0x7fc1('0x5e')](_[_0x7fc1('0x1c')](_0x1d079a[_0x7fc1('0x59')],{'firstName':_0x5a774a,[_0x277fee[_0x7fc1('0x7b')]]:_0x5a774a,'phone':_0x5a774a,'ListId':_0x5c816c['ListId']}));}})['then'](handleEntityNotFound(_0x5f12e0,null))[_0x7fc1('0x22')](function(_0x51ab7b){if(_0x51ab7b){_0x5b7309=_0x51ab7b;return db['OpenchannelInteraction'][_0x7fc1('0x58')]({'where':{'ContactId':_0x5b7309['id'],'closed':![],'OpenchannelAccountId':_0x5c816c['id']}})[_0x7fc1('0x22')](function(_0x3ad916){if(_0x3ad916){return[_0x3ad916,![]];}return db[_0x7fc1('0x8d')]['create']({'UserId':_0x1d079a[_0x7fc1('0x5b')]['id'],'ContactId':_0x5b7309['id'],'OpenchannelAccountId':_0x5c816c['id'],'lastMsgDirection':_0x7fc1('0xbd'),'firstMsgDirection':_0x7fc1('0xbd'),'Messages':[_[_0x7fc1('0x4f')](_0x1d079a[_0x7fc1('0x59')],{'read':![],'body':_0x1d079a[_0x7fc1('0x59')][_0x7fc1('0x59')],'OpenchannelAccountId':_0x5c816c['id'],'UserId':_0x1d079a[_0x7fc1('0x5b')]['id'],'ContactId':_0x5b7309['id']})]},{'include':[{'model':db['OpenchannelMessage'],'as':_0x7fc1('0xbe')}]})['then'](function(_0x1ceefd){return[_0x1ceefd,!![]];});});}})['spread'](function(_0xa1e4b6,_0x403bc6){if(_0x403bc6){return _0xa1e4b6;}return db[_0x7fc1('0x98')][_0x7fc1('0x5e')](_[_0x7fc1('0x4f')](_0x1d079a[_0x7fc1('0x59')],{'read':![],'body':_0x1d079a['body']['body'],'OpenchannelAccountId':_0x5c816c['id'],'OpenchannelInteractionId':_0xa1e4b6['id'],'UserId':_0x1d079a['user']['id'],'ContactId':_0x5b7309['id']}))['then'](function(_0x536d10){_0xa1e4b6[_0x7fc1('0xbf')][_0x7fc1('0xbe')]=[];_0xa1e4b6[_0x7fc1('0xbf')]['Messages'][_0x7fc1('0x94')](_0x536d10[_0x7fc1('0xbf')]);return _0xa1e4b6;});});}})[_0x7fc1('0x22')](respondWithResult(_0x5f12e0,null))[_0x7fc1('0x2b')](handleError(_0x5f12e0,null));};