7db27d3a77843d03350eca4d372d3b0314a98fd0
[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 _0x589f=['map','OpenchannelAccount','fieldName','type','key','model','keys','filters','intersection','query','fields','attributes','order','sort','where','pick','merge','options','includeAll','include','findAll','rows','show','params','rawAttributes','length','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','OpenchannelAccounts','userProfileId','UserProfileResource','describe','OpenchannelAccountId','Disposition','getDispositions','nolimit','filter','removeDispositions','ids','addAnswer','CannedAnswer','findOne','hasOwnProperty','removeAnswers','notify','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','ListId','isNil','from','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','List','Contacts','DESC','OpenchannelApplication','Applications','account','list','applications','orderBy','priority','asc','contact','firstName','threadId','OpenchannelInteraction','ContactId','spread','lastName','messageId','interaction','created','autoclose','push','close','*,*,*,*','OpenchannelMessage','AttachmentId','UserId','User','unshift','agent','waitForTheAssignedAgent','Start','startRouting','EventManager','addApplications','sequelize','transaction','bulkCreate','findAndCountAll','getApplications','Owner','Tag','Tags','tag','addAgents','omit','emit','removeAgents','isArray','userOpenchannelAccount:remove','getAgents','out','Messages','dataValues','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','fs-extra','squel','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','defaults','redis','localhost','socket.io-emitter','client','http','request','then','info','request\x20sent','debug','OpenchannelAccount,\x20%s,\x20%s,\x20%s','error','message','OpenchannelAccount,\x20%s,\x20%s','catch','sendStatus','end','status','undefined','limit','count','offset','set','Content-Range','apply','reject','save','update','get','destroy','stack','name','send','index','Pause','mandatoryDispositionPause'];(function(_0x44bcb0,_0x235aa9){var _0xfaf881=function(_0x25d81d){while(--_0x25d81d){_0x44bcb0['push'](_0x44bcb0['shift']());}};_0xfaf881(++_0x235aa9);}(_0x589f,0x1e6));var _0xf589=function(_0x4131c2,_0x26ccce){_0x4131c2=_0x4131c2-0x0;var _0x1ca43f=_0x589f[_0x4131c2];return _0x1ca43f;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xf589('0x0'));var jsonpatch=require(_0xf589('0x1'));var rp=require(_0xf589('0x2'));var moment=require(_0xf589('0x3'));var BPromise=require(_0xf589('0x4'));var Mustache=require(_0xf589('0x5'));var util=require(_0xf589('0x6'));var path=require(_0xf589('0x7'));var sox=require('sox');var csv=require(_0xf589('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xf589('0x9'));var _=require('lodash');var squel=require(_0xf589('0xa'));var crypto=require('crypto');var jsforce=require(_0xf589('0xb'));var deskjs=require(_0xf589('0xc'));var toCsv=require(_0xf589('0x8'));var querystring=require(_0xf589('0xd'));var Papa=require('papaparse');var Redis=require(_0xf589('0xe'));var authService=require(_0xf589('0xf'));var qs=require(_0xf589('0x10'));var as=require(_0xf589('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf589('0x12'))(_0xf589('0x13'));var utils=require(_0xf589('0x14'));var config=require('../../config/environment');var licenseUtil=require(_0xf589('0x15'));var db=require(_0xf589('0x16'))['db'];config['redis']=_[_0xf589('0x17')](config[_0xf589('0x18')],{'host':_0xf589('0x19'),'port':0x18eb});var socket=require(_0xf589('0x1a'))(new Redis(config['redis']));require('./openchannelAccount.socket')['register'](socket);var jayson=require('jayson/promise');var client=jayson[_0xf589('0x1b')][_0xf589('0x1c')]({'port':0x232c});var client9002=jayson[_0xf589('0x1b')]['http']({'port':0x232a});function respondWithRpcPromise(_0xa1de6b,_0x292b7c,_0x500474,_0x597886){return new BPromise(function(_0x3cd7b6,_0x1d831e){var _0x5f32d3=_0x597886||client;return _0x5f32d3[_0xf589('0x1d')](_0xa1de6b,_0x500474)[_0xf589('0x1e')](function(_0x1681c5){logger[_0xf589('0x1f')]('OpenchannelAccount,\x20%s,\x20%s',_0x292b7c,_0xf589('0x20'));logger[_0xf589('0x21')](_0xf589('0x22'),_0x292b7c,_0xf589('0x20'),JSON['stringify'](_0x1681c5));if(_0x1681c5[_0xf589('0x23')]){if(_0x1681c5[_0xf589('0x23')]['code']===0x1f4){logger[_0xf589('0x23')]('OpenchannelAccount,\x20%s,\x20%s',_0x292b7c,_0x1681c5[_0xf589('0x23')][_0xf589('0x24')]);return _0x1d831e(_0x1681c5[_0xf589('0x23')]['message']);}logger[_0xf589('0x23')](_0xf589('0x25'),_0x292b7c,_0x1681c5[_0xf589('0x23')][_0xf589('0x24')]);return _0x3cd7b6(_0x1681c5[_0xf589('0x23')][_0xf589('0x24')]);}else{logger[_0xf589('0x1f')](_0xf589('0x25'),_0x292b7c,_0xf589('0x20'));_0x3cd7b6(_0x1681c5['result'][_0xf589('0x24')]);}})[_0xf589('0x26')](function(_0x4d2ac7){logger[_0xf589('0x23')](_0xf589('0x25'),_0x292b7c,_0x4d2ac7);_0x1d831e(_0x4d2ac7);});});}function respondWithStatusCode(_0x4ea198,_0x481dd3){_0x481dd3=_0x481dd3||0xcc;return function(_0x4cf6d3){if(_0x4cf6d3){return _0x4ea198[_0xf589('0x27')](_0x481dd3);}return _0x4ea198['status'](_0x481dd3)[_0xf589('0x28')]();};}function respondWithResult(_0x5e4cb2,_0x363eae){_0x363eae=_0x363eae||0xc8;return function(_0x25dcdb){if(_0x25dcdb){return _0x5e4cb2[_0xf589('0x29')](_0x363eae)['json'](_0x25dcdb);}};}function respondWithFilteredResult(_0x285217,_0x12d515){return function(_0x26e509){if(_0x26e509){var _0x5c49a3=typeof _0x12d515['offset']===_0xf589('0x2a')&&typeof _0x12d515[_0xf589('0x2b')]==='undefined';var _0x3617f2=_0x26e509[_0xf589('0x2c')];var _0x5c3721=_0x5c49a3?0x0:_0x12d515[_0xf589('0x2d')];var _0xfd687f=_0x5c49a3?_0x26e509['count']:_0x12d515[_0xf589('0x2d')]+_0x12d515[_0xf589('0x2b')];var _0x2e0684;if(_0xfd687f>=_0x3617f2){_0xfd687f=_0x3617f2;_0x2e0684=0xc8;}else{_0x2e0684=0xce;}_0x285217[_0xf589('0x29')](_0x2e0684);return _0x285217[_0xf589('0x2e')](_0xf589('0x2f'),_0x5c3721+'-'+_0xfd687f+'/'+_0x3617f2)['json'](_0x26e509);}return null;};}function patchUpdates(_0x339cb6){return function(_0xdedcb8){try{jsonpatch[_0xf589('0x30')](_0xdedcb8,_0x339cb6,!![]);}catch(_0x14ffa7){return BPromise[_0xf589('0x31')](_0x14ffa7);}return _0xdedcb8[_0xf589('0x32')]();};}function saveUpdates(_0x275621,_0x52c5bd){return function(_0x12b83e){if(_0x12b83e){return _0x12b83e[_0xf589('0x33')](_0x275621)[_0xf589('0x1e')](function(_0x1d80ff){return _0x1d80ff;});}return null;};}function removeEntity(_0x96deeb,_0x28dfbf){return function(_0x3e846a){if(_0x3e846a){return _0x3e846a['destroy']()[_0xf589('0x1e')](function(){var _0x5b3da5=_0x3e846a[_0xf589('0x34')]({'plain':!![]});var _0x5c41f9='OpenchannelAccounts';return db['UserProfileResource'][_0xf589('0x35')]({'where':{'type':_0x5c41f9,'resourceId':_0x5b3da5['id']}})[_0xf589('0x1e')](function(){return _0x3e846a;});})[_0xf589('0x1e')](function(){_0x96deeb[_0xf589('0x29')](0xcc)[_0xf589('0x28')]();});}};}function handleEntityNotFound(_0x4c6b2b,_0xdc429f){return function(_0x45fb75){if(!_0x45fb75){_0x4c6b2b[_0xf589('0x27')](0x194);}return _0x45fb75;};}function handleError(_0x315177,_0xaa6984){_0xaa6984=_0xaa6984||0x1f4;return function(_0x5befe4){logger[_0xf589('0x23')](_0x5befe4[_0xf589('0x36')]);if(_0x5befe4[_0xf589('0x37')]){delete _0x5befe4[_0xf589('0x37')];}_0x315177[_0xf589('0x29')](_0xaa6984)[_0xf589('0x38')](_0x5befe4);};}exports[_0xf589('0x39')]=function(_0x2e0113,_0x202863){var _0x1f48a3={'include':[{'model':db[_0xf589('0x3a')],'as':_0xf589('0x3b')}]},_0x1e9f18={},_0xb1064f={'count':0x0,'rows':[]};var _0x20ae63=_[_0xf589('0x3c')](db[_0xf589('0x3d')]['rawAttributes'],function(_0x339637){return{'name':_0x339637[_0xf589('0x3e')],'type':_0x339637[_0xf589('0x3f')][_0xf589('0x40')]};});_0x1e9f18[_0xf589('0x41')]=_[_0xf589('0x3c')](_0x20ae63,_0xf589('0x37'));_0x1e9f18['query']=_[_0xf589('0x42')](_0x2e0113['query']);_0x1e9f18[_0xf589('0x43')]=_[_0xf589('0x44')](_0x1e9f18[_0xf589('0x41')],_0x1e9f18[_0xf589('0x45')]);_0x1f48a3['attributes']=_[_0xf589('0x44')](_0x1e9f18[_0xf589('0x41')],qs['fields'](_0x2e0113[_0xf589('0x45')][_0xf589('0x46')]));_0x1f48a3[_0xf589('0x47')]=_0x1f48a3['attributes']['length']?_0x1f48a3[_0xf589('0x47')]:_0x1e9f18['model'];if(!_0x2e0113['query']['hasOwnProperty']('nolimit')){_0x1f48a3['limit']=qs[_0xf589('0x2b')](_0x2e0113[_0xf589('0x45')][_0xf589('0x2b')]);_0x1f48a3[_0xf589('0x2d')]=qs[_0xf589('0x2d')](_0x2e0113[_0xf589('0x45')][_0xf589('0x2d')]);}_0x1f48a3[_0xf589('0x48')]=qs[_0xf589('0x49')](_0x2e0113[_0xf589('0x45')][_0xf589('0x49')]);_0x1f48a3[_0xf589('0x4a')]=qs[_0xf589('0x43')](_[_0xf589('0x4b')](_0x2e0113['query'],_0x1e9f18[_0xf589('0x43')]),_0x20ae63);if(_0x2e0113[_0xf589('0x45')]['filter']){_0x1f48a3[_0xf589('0x4a')]=_['merge'](_0x1f48a3[_0xf589('0x4a')],{'$or':_[_0xf589('0x3c')](_0x20ae63,function(_0x1ed789){if(_0x1ed789['type']!=='VIRTUAL'){var _0x225fa7={};_0x225fa7[_0x1ed789[_0xf589('0x37')]]={'$like':'%'+_0x2e0113[_0xf589('0x45')]['filter']+'%'};return _0x225fa7;}})});}_0x1f48a3=_[_0xf589('0x4c')]({},_0x1f48a3,_0x2e0113[_0xf589('0x4d')]);var _0x4222d9={'where':_0x1f48a3['where']};return db[_0xf589('0x3d')]['count'](_0x4222d9)[_0xf589('0x1e')](function(_0x2d4e5c){_0xb1064f[_0xf589('0x2c')]=_0x2d4e5c;if(_0x2e0113['query'][_0xf589('0x4e')]){_0x1f48a3[_0xf589('0x4f')]=[{'all':!![]}];}return db['OpenchannelAccount'][_0xf589('0x50')](_0x1f48a3);})[_0xf589('0x1e')](function(_0x3f0848){_0xb1064f[_0xf589('0x51')]=_0x3f0848;return _0xb1064f;})[_0xf589('0x1e')](respondWithFilteredResult(_0x202863,_0x1f48a3))['catch'](handleError(_0x202863,null));};exports[_0xf589('0x52')]=function(_0x5133d8,_0x45397b){var _0x1395f3={'raw':![],'where':{'id':_0x5133d8[_0xf589('0x53')]['id']},'include':[{'model':db[_0xf589('0x3a')],'as':_0xf589('0x3b')}]},_0x1d2e9f={};_0x1d2e9f[_0xf589('0x41')]=_['keys'](db['OpenchannelAccount'][_0xf589('0x54')]);_0x1d2e9f[_0xf589('0x45')]=_[_0xf589('0x42')](_0x5133d8['query']);_0x1d2e9f['filters']=_['intersection'](_0x1d2e9f['model'],_0x1d2e9f[_0xf589('0x45')]);_0x1395f3[_0xf589('0x47')]=_['intersection'](_0x1d2e9f['model'],qs[_0xf589('0x46')](_0x5133d8['query'][_0xf589('0x46')]));_0x1395f3[_0xf589('0x47')]=_0x1395f3[_0xf589('0x47')][_0xf589('0x55')]?_0x1395f3['attributes']:_0x1d2e9f[_0xf589('0x41')];if(_0x5133d8['query']['includeAll']){_0x1395f3['include']=[{'all':!![]}];}_0x1395f3=_[_0xf589('0x4c')]({},_0x1395f3,_0x5133d8[_0xf589('0x4d')]);return db['OpenchannelAccount'][_0xf589('0x56')](_0x1395f3)[_0xf589('0x1e')](handleEntityNotFound(_0x45397b,null))[_0xf589('0x1e')](respondWithResult(_0x45397b,null))[_0xf589('0x26')](handleError(_0x45397b,null));};exports[_0xf589('0x57')]=function(_0x4d3df8,_0x406e39){return db['OpenchannelAccount'][_0xf589('0x57')](_0x4d3df8[_0xf589('0x58')],{})[_0xf589('0x1e')](function(_0x1e2ebe){var _0x202ea2=_0x4d3df8[_0xf589('0x59')][_0xf589('0x34')]({'plain':!![]});if(!_0x202ea2)throw new Error(_0xf589('0x5a'));if(_0x202ea2[_0xf589('0x5b')]==='user'){var _0x43e6ad=_0x1e2ebe[_0xf589('0x34')]({'plain':!![]});var _0x231dcb=_0xf589('0x5c');return db['UserProfileSection'][_0xf589('0x56')]({'where':{'name':_0x231dcb,'userProfileId':_0x202ea2[_0xf589('0x5d')]},'raw':!![]})[_0xf589('0x1e')](function(_0x49c728){if(_0x49c728&&_0x49c728['autoAssociation']===0x0){return db[_0xf589('0x5e')]['create']({'name':_0x43e6ad[_0xf589('0x37')],'resourceId':_0x43e6ad['id'],'type':_0x49c728['name'],'sectionId':_0x49c728['id']},{})[_0xf589('0x1e')](function(){return _0x1e2ebe;});}else{return _0x1e2ebe;}})[_0xf589('0x26')](function(_0x373437){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x373437);throw _0x373437;});}return _0x1e2ebe;})['then'](respondWithResult(_0x406e39,0xc9))[_0xf589('0x26')](handleError(_0x406e39,null));};exports[_0xf589('0x33')]=function(_0x142a14,_0x3873a4){if(_0x142a14[_0xf589('0x58')]['id']){delete _0x142a14[_0xf589('0x58')]['id'];}return db[_0xf589('0x3d')][_0xf589('0x56')]({'where':{'id':_0x142a14[_0xf589('0x53')]['id']},'include':[{'model':db['Pause'],'as':_0xf589('0x3b')}]})[_0xf589('0x1e')](handleEntityNotFound(_0x3873a4,null))['then'](saveUpdates(_0x142a14['body'],null))[_0xf589('0x1e')](respondWithResult(_0x3873a4,null))[_0xf589('0x26')](handleError(_0x3873a4,null));};exports['destroy']=function(_0x2842ca,_0x4a3a20){return db[_0xf589('0x3d')][_0xf589('0x56')]({'where':{'id':_0x2842ca[_0xf589('0x53')]['id']}})[_0xf589('0x1e')](handleEntityNotFound(_0x4a3a20,null))[_0xf589('0x1e')](removeEntity(_0x4a3a20,null))[_0xf589('0x26')](handleError(_0x4a3a20,null));};exports['describe']=function(_0xe76edc,_0x5eaef6){return db[_0xf589('0x3d')][_0xf589('0x5f')]()[_0xf589('0x1e')](respondWithResult(_0x5eaef6,null))[_0xf589('0x26')](handleError(_0x5eaef6,null));};exports['addDisposition']=function(_0x21f6cd,_0x391927,_0x242ca0){if(_0x21f6cd[_0xf589('0x58')]['id']){delete _0x21f6cd[_0xf589('0x58')]['id'];}return db['OpenchannelAccount']['find']({'where':{'id':_0x21f6cd[_0xf589('0x53')]['id']}})[_0xf589('0x1e')](handleEntityNotFound(_0x391927,null))['then'](function(_0x2b8134){if(_0x2b8134){_0x21f6cd[_0xf589('0x58')][_0xf589('0x60')]=_0x2b8134['id'];return db[_0xf589('0x61')][_0xf589('0x57')](_0x21f6cd['body']);}})[_0xf589('0x1e')](respondWithResult(_0x391927,null))[_0xf589('0x26')](handleError(_0x391927,null));};exports[_0xf589('0x62')]=function(_0x421eea,_0x153b0e,_0x113345){var _0x3ccc74={'raw':![],'where':{}};var _0x2814cd={};var _0x48e824={'count':0x0,'rows':[]};return db[_0xf589('0x3d')]['findOne']({'where':{'id':_0x421eea[_0xf589('0x53')]['id']}})[_0xf589('0x1e')](handleEntityNotFound(_0x153b0e,null))[_0xf589('0x1e')](function(_0x1aee32){if(_0x1aee32){_0x2814cd[_0xf589('0x41')]=_[_0xf589('0x42')](db[_0xf589('0x61')]['rawAttributes']);_0x2814cd[_0xf589('0x45')]=_[_0xf589('0x42')](_0x421eea[_0xf589('0x45')]);_0x2814cd[_0xf589('0x43')]=_['intersection'](_0x2814cd[_0xf589('0x41')],_0x2814cd[_0xf589('0x45')]);_0x3ccc74['attributes']=_[_0xf589('0x44')](_0x2814cd[_0xf589('0x41')],qs[_0xf589('0x46')](_0x421eea[_0xf589('0x45')]['fields']));_0x3ccc74[_0xf589('0x47')]=_0x3ccc74[_0xf589('0x47')]['length']?_0x3ccc74['attributes']:_0x2814cd[_0xf589('0x41')];if(!_0x421eea[_0xf589('0x45')]['hasOwnProperty'](_0xf589('0x63'))){_0x3ccc74[_0xf589('0x2b')]=qs[_0xf589('0x2b')](_0x421eea['query'][_0xf589('0x2b')]);_0x3ccc74[_0xf589('0x2d')]=qs[_0xf589('0x2d')](_0x421eea[_0xf589('0x45')]['offset']);}_0x3ccc74['order']=qs['sort'](_0x421eea['query'][_0xf589('0x49')]);_0x3ccc74[_0xf589('0x4a')]=qs[_0xf589('0x43')](_[_0xf589('0x4b')](_0x421eea[_0xf589('0x45')],_0x2814cd[_0xf589('0x43')]));_0x3ccc74[_0xf589('0x4a')][_0xf589('0x60')]=_0x1aee32['id'];if(_0x421eea[_0xf589('0x45')][_0xf589('0x64')]){_0x3ccc74[_0xf589('0x4a')]=_['merge'](_0x3ccc74[_0xf589('0x4a')],{'$or':_[_0xf589('0x3c')](_0x3ccc74[_0xf589('0x47')],function(_0x416b66){var _0x400479={};_0x400479[_0x416b66]={'$like':'%'+_0x421eea['query'][_0xf589('0x64')]+'%'};return _0x400479;})});}_0x3ccc74=_[_0xf589('0x4c')]({},_0x3ccc74,_0x421eea['options']);return db[_0xf589('0x61')][_0xf589('0x2c')]({'where':_0x3ccc74[_0xf589('0x4a')]})['then'](function(_0x1743cd){_0x48e824[_0xf589('0x2c')]=_0x1743cd;if(_0x421eea[_0xf589('0x45')]['includeAll']){_0x3ccc74[_0xf589('0x4f')]=[{'all':!![]}];}return db[_0xf589('0x61')][_0xf589('0x50')](_0x3ccc74);})[_0xf589('0x1e')](function(_0x5e9d19){_0x48e824['rows']=_0x5e9d19;return _0x48e824;});}})[_0xf589('0x1e')](respondWithFilteredResult(_0x153b0e,_0x3ccc74))[_0xf589('0x26')](handleError(_0x153b0e,null));};exports['removeDispositions']=function(_0x1bbf4b,_0x244768,_0x227a73){return db[_0xf589('0x3d')][_0xf589('0x56')]({'where':{'id':_0x1bbf4b[_0xf589('0x53')]['id']}})[_0xf589('0x1e')](handleEntityNotFound(_0x244768,null))[_0xf589('0x1e')](function(_0x27af7a){if(_0x27af7a){return _0x27af7a[_0xf589('0x65')](_0x1bbf4b[_0xf589('0x45')][_0xf589('0x66')]);}})[_0xf589('0x1e')](respondWithStatusCode(_0x244768,null))[_0xf589('0x26')](handleError(_0x244768,null));};exports[_0xf589('0x67')]=function(_0x240ecd,_0x258e8c,_0x312e7a){if(_0x240ecd[_0xf589('0x58')]['id']){delete _0x240ecd['body']['id'];}return db[_0xf589('0x3d')][_0xf589('0x56')]({'where':{'id':_0x240ecd['params']['id']}})[_0xf589('0x1e')](handleEntityNotFound(_0x258e8c,null))[_0xf589('0x1e')](function(_0x36c7c5){if(_0x36c7c5){_0x240ecd['body'][_0xf589('0x60')]=_0x36c7c5['id'];return db[_0xf589('0x68')]['create'](_0x240ecd[_0xf589('0x58')]);}})[_0xf589('0x1e')](respondWithResult(_0x258e8c,null))[_0xf589('0x26')](handleError(_0x258e8c,null));};exports['getAnswers']=function(_0x1f7b9a,_0x4b4954,_0x114d81){var _0x1653ab={'raw':![],'where':{}};var _0x11dbad={};var _0x52c6d4={'count':0x0,'rows':[]};return db[_0xf589('0x3d')][_0xf589('0x69')]({'where':{'id':_0x1f7b9a[_0xf589('0x53')]['id']}})[_0xf589('0x1e')](handleEntityNotFound(_0x4b4954,null))[_0xf589('0x1e')](function(_0x6b7864){if(_0x6b7864){_0x11dbad['model']=_[_0xf589('0x42')](db['CannedAnswer'][_0xf589('0x54')]);_0x11dbad[_0xf589('0x45')]=_[_0xf589('0x42')](_0x1f7b9a['query']);_0x11dbad[_0xf589('0x43')]=_[_0xf589('0x44')](_0x11dbad[_0xf589('0x41')],_0x11dbad[_0xf589('0x45')]);_0x1653ab['attributes']=_[_0xf589('0x44')](_0x11dbad[_0xf589('0x41')],qs[_0xf589('0x46')](_0x1f7b9a[_0xf589('0x45')][_0xf589('0x46')]));_0x1653ab[_0xf589('0x47')]=_0x1653ab[_0xf589('0x47')]['length']?_0x1653ab[_0xf589('0x47')]:_0x11dbad[_0xf589('0x41')];if(!_0x1f7b9a[_0xf589('0x45')][_0xf589('0x6a')]('nolimit')){_0x1653ab[_0xf589('0x2b')]=qs[_0xf589('0x2b')](_0x1f7b9a[_0xf589('0x45')][_0xf589('0x2b')]);_0x1653ab[_0xf589('0x2d')]=qs[_0xf589('0x2d')](_0x1f7b9a[_0xf589('0x45')]['offset']);}_0x1653ab[_0xf589('0x48')]=qs[_0xf589('0x49')](_0x1f7b9a[_0xf589('0x45')][_0xf589('0x49')]);_0x1653ab['where']=qs['filters'](_[_0xf589('0x4b')](_0x1f7b9a[_0xf589('0x45')],_0x11dbad[_0xf589('0x43')]));_0x1653ab[_0xf589('0x4a')]['OpenchannelAccountId']=_0x6b7864['id'];if(_0x1f7b9a[_0xf589('0x45')][_0xf589('0x64')]){_0x1653ab[_0xf589('0x4a')]=_[_0xf589('0x4c')](_0x1653ab[_0xf589('0x4a')],{'$or':_[_0xf589('0x3c')](_0x1653ab[_0xf589('0x47')],function(_0x48706c){var _0x23b4bc={};_0x23b4bc[_0x48706c]={'$like':'%'+_0x1f7b9a[_0xf589('0x45')]['filter']+'%'};return _0x23b4bc;})});}_0x1653ab=_[_0xf589('0x4c')]({},_0x1653ab,_0x1f7b9a[_0xf589('0x4d')]);return db[_0xf589('0x68')][_0xf589('0x2c')]({'where':_0x1653ab['where']})[_0xf589('0x1e')](function(_0x4e390f){_0x52c6d4[_0xf589('0x2c')]=_0x4e390f;if(_0x1f7b9a[_0xf589('0x45')][_0xf589('0x4e')]){_0x1653ab[_0xf589('0x4f')]=[{'all':!![]}];}return db[_0xf589('0x68')][_0xf589('0x50')](_0x1653ab);})[_0xf589('0x1e')](function(_0x224e60){_0x52c6d4['rows']=_0x224e60;return _0x52c6d4;});}})[_0xf589('0x1e')](respondWithFilteredResult(_0x4b4954,_0x1653ab))['catch'](handleError(_0x4b4954,null));};exports['removeAnswers']=function(_0x5ceabb,_0x161216,_0x270c92){return db['OpenchannelAccount'][_0xf589('0x56')]({'where':{'id':_0x5ceabb['params']['id']}})[_0xf589('0x1e')](handleEntityNotFound(_0x161216,null))[_0xf589('0x1e')](function(_0x363c4e){if(_0x363c4e){return _0x363c4e[_0xf589('0x6b')](_0x5ceabb[_0xf589('0x45')][_0xf589('0x66')]);}})[_0xf589('0x1e')](respondWithStatusCode(_0x161216,null))['catch'](handleError(_0x161216,null));};exports[_0xf589('0x6c')]=function(_0xa1e9a7,_0x1ee0c9,_0x30a1e1){var _0x320c8e={'body':_0xa1e9a7[_0xf589('0x58')],'channel':'openchannel'};var _0x329b59=[];var _0x48c42f=[];var _0x459f84={};var _0x4e28a2=![];return db[_0xf589('0x6d')][_0xf589('0x5f')]()[_0xf589('0x1e')](function(_0x88244c){if(!_0x88244c){throw new db[(_0xf589('0x6e'))][(_0xf589('0x6f'))](_0xf589('0x70'));}_0x329b59=_[_0xf589('0x71')](_[_0xf589('0x42')](_0x88244c),[_0xf589('0x72'),'updatedAt']);_0x48c42f=_[_0xf589('0x71')](_['keys'](_0x88244c),['createdAt',_0xf589('0x73'),_0xf589('0x74'),_0xf589('0x75')]);if(_0xa1e9a7[_0xf589('0x58')]['id']){delete _0xa1e9a7[_0xf589('0x58')]['id'];}if(_[_0xf589('0x76')](_0xa1e9a7[_0xf589('0x58')][_0xf589('0x77')])){throw new db['Sequelize']['ValidationError'](_0xf589('0x78'));}if(_[_0xf589('0x76')](_0xa1e9a7[_0xf589('0x58')][_0xf589('0x58')])||_0xa1e9a7[_0xf589('0x58')][_0xf589('0x58')]===''){throw new db['Sequelize']['ValidationError'](_0xf589('0x79'));}if(_['isNil'](_0xa1e9a7['body'][_0xf589('0x7a')])){throw new db[(_0xf589('0x6e'))][(_0xf589('0x6f'))](_0xf589('0x7b')+_0x48c42f);}if(!_[_0xf589('0x7c')](_0x48c42f,_0xa1e9a7[_0xf589('0x58')]['mapKey'])){throw new db['Sequelize']['ValidationError'](_0xf589('0x7d')+_0x48c42f);}_0x459f84[_0xa1e9a7[_0xf589('0x58')]['mapKey']]=_0xa1e9a7[_0xf589('0x58')][_0xf589('0x77')];})['then'](function(){return db['OpenchannelAccount'][_0xf589('0x56')]({'where':{'id':_0xa1e9a7[_0xf589('0x53')]['id']},'include':[{'model':db[_0xf589('0x7e')],'as':_0xf589('0x7f'),'include':[{'model':db[_0xf589('0x6d')],'as':_0xf589('0x80'),'where':_0x459f84,'limit':0x1,'order':[[_0xf589('0x73'),_0xf589('0x81')]]}]},{'model':db[_0xf589('0x82')],'as':_0xf589('0x83')}]});})[_0xf589('0x1e')](handleEntityNotFound(_0x1ee0c9,null))[_0xf589('0x1e')](function(_0x9f9753){if(_0x9f9753&&_0x9f9753[_0xf589('0x7f')]){_0x320c8e[_0xf589('0x84')]=_0x9f9753;_0x320c8e['applications']=_0x9f9753[_0xf589('0x83')];_0x320c8e[_0xf589('0x85')]=_0x9f9753[_0xf589('0x7f')];_0x320c8e[_0xf589('0x86')]=_[_0xf589('0x87')](_0x320c8e['applications'],[_0xf589('0x88')],[_0xf589('0x89')]);if(_0x320c8e[_0xf589('0x84')][_0xf589('0x83')]){delete _0x320c8e[_0xf589('0x84')][_0xf589('0x83')];}if(_0x320c8e[_0xf589('0x84')]['List']&&_0x320c8e['account'][_0xf589('0x7f')][_0xf589('0x80')][_0xf589('0x55')]){return _0x320c8e['account'][_0xf589('0x7f')]['Contacts'][0x0];}var _0x43822b=_[_0xf589('0x17')](_0xa1e9a7[_0xf589('0x58')],{'firstName':_0xa1e9a7[_0xf589('0x58')][_0xf589('0x77')],'ListId':_0x9f9753[_0xf589('0x75')]});_0x43822b[_0xa1e9a7[_0xf589('0x58')]['mapKey']]=_0xa1e9a7[_0xf589('0x58')][_0xf589('0x77')];return db['CmContact'][_0xf589('0x57')](_0x43822b,{'fields':_0x329b59,'raw':!![]});}})[_0xf589('0x1e')](handleEntityNotFound(_0x1ee0c9,null))[_0xf589('0x1e')](function(_0x3d6d20){_0x320c8e[_0xf589('0x8a')]=_0x3d6d20;if(_0x3d6d20){var _0xb94dbd={'ContactId':_0x3d6d20['id'],'OpenchannelAccountId':_0xa1e9a7[_0xf589('0x53')]['id'],'from':(_0x3d6d20[_0xf589('0x8b')]||'')+'\x20'+(_0x3d6d20['lastName']||'')};var _0x352d91={'OpenchannelAccountId':_0xa1e9a7['params']['id'],'closed':![]};if(_0xa1e9a7[_0xf589('0x58')][_0xf589('0x8c')]){_0x352d91[_0xf589('0x8c')]=_0xa1e9a7[_0xf589('0x58')][_0xf589('0x8c')];return db[_0xf589('0x8d')][_0xf589('0x56')]({'where':_0x352d91})[_0xf589('0x1e')](function(_0x4b3527){if(_0x4b3527){return[_0x4b3527,![]];}_0xb94dbd[_0xf589('0x8c')]=_0xa1e9a7[_0xf589('0x58')]['threadId'];_0xb94dbd['externalUrl']=_0xa1e9a7[_0xf589('0x58')]['externalUrl'];return db[_0xf589('0x8d')][_0xf589('0x57')](_0xb94dbd)[_0xf589('0x1e')](function(_0x568e3b){return[_0x568e3b,!![]];});});}else{_0x352d91[_0xf589('0x8c')]=null;}_0x352d91[_0xf589('0x8e')]=_0x3d6d20['id'];return db[_0xf589('0x8d')][_0xf589('0x56')]({'where':_0x352d91})[_0xf589('0x1e')](function(_0x22d40a){if(_0x22d40a){return[_0x22d40a,![]];}return db[_0xf589('0x8d')][_0xf589('0x57')](_0xb94dbd)['then'](function(_0xacd68a){return[_0xacd68a,!![]];});});}})[_0xf589('0x8f')](function(_0x536df2,_0x1452d7){if(_0x536df2){_0x4e28a2=_0x1452d7;if(!_0x1452d7){var _0x27d0c3={'from':(_0x320c8e['contact']['firstName']||'')+'\x20'+(_0x320c8e['contact'][_0xf589('0x90')]||'')};if(_0xa1e9a7['body']['threadId']&&_0xa1e9a7[_0xf589('0x58')][_0xf589('0x91')]&&_0xa1e9a7[_0xf589('0x58')][_0xf589('0x8c')]!=_0xa1e9a7[_0xf589('0x58')]['messageId']){_0x27d0c3[_0xf589('0x8c')]=_0xa1e9a7[_0xf589('0x58')][_0xf589('0x91')];}return _0x536df2['update'](_0x27d0c3);}else{return _0x536df2;}}})[_0xf589('0x1e')](function(_0x2d154f){_0x320c8e[_0xf589('0x92')]=_0x2d154f[_0xf589('0x34')]({'plain':!![]});_0x320c8e[_0xf589('0x92')][_0xf589('0x93')]=_0x4e28a2;if(_0x320c8e[_0xf589('0x92')][_0xf589('0x93')]){if(_0x320c8e[_0xf589('0x84')][_0xf589('0x94')]){_0x320c8e[_0xf589('0x86')][_0xf589('0x95')]({'id':0x0,'priority':_0x320c8e[_0xf589('0x86')][_0xf589('0x55')]+0x1,'app':_0xf589('0x96'),'appdata':'unmanaged','interval':_0xf589('0x97')});}}return db[_0xf589('0x98')]['create']({'body':_0xa1e9a7[_0xf589('0x58')][_0xf589('0x58')],'OpenchannelAccountId':_0xa1e9a7[_0xf589('0x53')]['id'],'OpenchannelInteractionId':_0x2d154f['id'],'direction':'in','ContactId':_0x320c8e['contact']['id'],'AttachmentId':_0xa1e9a7[_0xf589('0x58')][_0xf589('0x99')]});})['then'](function(_0x4bffdc){_0x320c8e['message']=_0x4bffdc;if(_0x320c8e[_0xf589('0x92')][_0xf589('0x9a')]){return db[_0xf589('0x9b')]['find']({'attributes':['id',_0xf589('0x37')],'where':{'id':_0x320c8e[_0xf589('0x92')]['UserId']}})[_0xf589('0x1e')](function(_0x482d54){if(_0x482d54){_0x320c8e[_0xf589('0x86')][_0xf589('0x9c')]({'id':0x0,'priority':0x0,'app':_0xf589('0x9d'),'appdata':_0x482d54[_0xf589('0x37')]+','+(_0x320c8e[_0xf589('0x84')][_0xf589('0x9e')]||0xa),'interval':_0xf589('0x97')});_0x320c8e['forcedOwnership']=![];}return respondWithRpcPromise(_0xf589('0x9f'),_0xf589('0xa0'),_0x320c8e);});}return respondWithRpcPromise(_0xf589('0x9f'),_0xf589('0xa0'),_0x320c8e);})[_0xf589('0x1e')](function(_0x50524a){respondWithRpcPromise(_0xf589('0xa1'),'EventManager',{'event':'notify','message':_0x50524a},client9002);return _0x50524a;})[_0xf589('0x1e')](respondWithResult(_0x1ee0c9,null))['catch'](handleError(_0x1ee0c9,null));};exports[_0xf589('0xa2')]=function(_0x397a4f,_0x317773,_0xcdf6a2){return db[_0xf589('0x3d')][_0xf589('0x69')]({'where':{'id':_0x397a4f[_0xf589('0x53')]['id']}})['then'](handleEntityNotFound(_0x317773,null))[_0xf589('0x1e')](function(_0x5c8cba){if(_0x5c8cba){return db[_0xf589('0xa3')][_0xf589('0xa4')](function(_0x47ecaa){return db[_0xf589('0x82')][_0xf589('0x35')]({'where':{'OpenchannelAccountId':_0x397a4f[_0xf589('0x53')]['id']},'transaction':_0x47ecaa})[_0xf589('0x1e')](function(_0x1e2335){var _0x179a63=_[_0xf589('0x3c')](_0x397a4f[_0xf589('0x58')],function(_0x5daa34){_0x5daa34[_0xf589('0x60')]=_0x397a4f[_0xf589('0x53')]['id'];return _0x5daa34;});return db[_0xf589('0x82')][_0xf589('0xa5')](_0x179a63,{'transaction':_0x47ecaa});});})[_0xf589('0x1e')](function(){return db[_0xf589('0x82')][_0xf589('0xa6')]({'where':{'OpenchannelAccountId':_0x397a4f['params']['id']},'order':'priority'});});}})[_0xf589('0x1e')](respondWithResult(_0x317773,null))[_0xf589('0x26')](handleError(_0x317773,null));};exports[_0xf589('0xa7')]=function(_0x1ea4d8,_0x56c920,_0x39e22b){var _0x215d62={};var _0x5a05c4={};var _0x387eb8;var _0x89f6a8;return db['OpenchannelAccount'][_0xf589('0x69')]({'where':{'id':_0x1ea4d8['params']['id']}})[_0xf589('0x1e')](handleEntityNotFound(_0x56c920,null))['then'](function(_0x183431){if(_0x183431){_0x387eb8=_0x183431;_0x5a05c4[_0xf589('0x41')]=_[_0xf589('0x42')](db['OpenchannelApplication'][_0xf589('0x54')]);_0x5a05c4[_0xf589('0x45')]=_[_0xf589('0x42')](_0x1ea4d8['query']);_0x5a05c4[_0xf589('0x43')]=_[_0xf589('0x44')](_0x5a05c4['model'],_0x5a05c4['query']);_0x215d62[_0xf589('0x47')]=_[_0xf589('0x44')](_0x5a05c4[_0xf589('0x41')],qs[_0xf589('0x46')](_0x1ea4d8[_0xf589('0x45')][_0xf589('0x46')]));_0x215d62[_0xf589('0x47')]=_0x215d62[_0xf589('0x47')][_0xf589('0x55')]?_0x215d62[_0xf589('0x47')]:_0x5a05c4[_0xf589('0x41')];_0x215d62[_0xf589('0x48')]=qs[_0xf589('0x49')](_0x1ea4d8[_0xf589('0x45')]['sort']);_0x215d62['where']=qs[_0xf589('0x43')](_[_0xf589('0x4b')](_0x1ea4d8[_0xf589('0x45')],_0x5a05c4['filters']));if(_0x1ea4d8[_0xf589('0x45')][_0xf589('0x64')]){_0x215d62[_0xf589('0x4a')]=_['merge'](_0x215d62[_0xf589('0x4a')],{'$or':_[_0xf589('0x3c')](_0x215d62[_0xf589('0x47')],function(_0x2717c7){var _0x3d2cda={};_0x3d2cda[_0x2717c7]={'$like':'%'+_0x1ea4d8[_0xf589('0x45')][_0xf589('0x64')]+'%'};return _0x3d2cda;})});}_0x215d62=_[_0xf589('0x4c')]({},_0x215d62,_0x1ea4d8[_0xf589('0x4d')]);return _0x387eb8['getApplications'](_0x215d62);}})['then'](function(_0x1e2862){if(_0x1e2862){_0x89f6a8=_0x1e2862[_0xf589('0x55')];if(!_0x1ea4d8[_0xf589('0x45')][_0xf589('0x6a')]('nolimit')){_0x215d62[_0xf589('0x2b')]=qs['limit'](_0x1ea4d8[_0xf589('0x45')][_0xf589('0x2b')]);_0x215d62[_0xf589('0x2d')]=qs['offset'](_0x1ea4d8[_0xf589('0x45')][_0xf589('0x2d')]);}return _0x387eb8[_0xf589('0xa7')](_0x215d62);}})['then'](function(_0x35d99f){if(_0x35d99f){return _0x35d99f?{'count':_0x89f6a8,'rows':_0x35d99f}:null;}})[_0xf589('0x1e')](respondWithResult(_0x56c920,null))[_0xf589('0x26')](handleError(_0x56c920,null));};exports['getInteractions']=function(_0x2c1a96,_0x1cc7df,_0x35f93a){var _0xc4d765={'raw':![],'where':{}};var _0x322c85={};var _0x51325d={'count':0x0,'rows':[]};return db[_0xf589('0x3d')][_0xf589('0x69')]({'where':{'id':_0x2c1a96['params']['id']}})[_0xf589('0x1e')](handleEntityNotFound(_0x1cc7df,null))[_0xf589('0x1e')](function(_0x4d85be){if(_0x4d85be){_0x322c85['model']=_[_0xf589('0x42')](db['OpenchannelInteraction'][_0xf589('0x54')]);_0x322c85[_0xf589('0x45')]=_[_0xf589('0x42')](_0x2c1a96[_0xf589('0x45')]);_0x322c85['filters']=_[_0xf589('0x44')](_0x322c85[_0xf589('0x41')],_0x322c85[_0xf589('0x45')]);_0xc4d765[_0xf589('0x47')]=_[_0xf589('0x44')](_0x322c85[_0xf589('0x41')],qs[_0xf589('0x46')](_0x2c1a96[_0xf589('0x45')]['fields']));_0xc4d765[_0xf589('0x47')]=_0xc4d765[_0xf589('0x47')][_0xf589('0x55')]?_0xc4d765[_0xf589('0x47')]:_0x322c85[_0xf589('0x41')];if(!_0x2c1a96[_0xf589('0x45')][_0xf589('0x6a')](_0xf589('0x63'))){_0xc4d765[_0xf589('0x2b')]=qs[_0xf589('0x2b')](_0x2c1a96[_0xf589('0x45')][_0xf589('0x2b')]);_0xc4d765[_0xf589('0x2d')]=qs[_0xf589('0x2d')](_0x2c1a96[_0xf589('0x45')][_0xf589('0x2d')]);}_0xc4d765[_0xf589('0x48')]=qs['sort'](_0x2c1a96[_0xf589('0x45')][_0xf589('0x49')]);_0xc4d765[_0xf589('0x4a')]=qs[_0xf589('0x43')](_['pick'](_0x2c1a96['query'],_0x322c85[_0xf589('0x43')]));_0xc4d765['where'][_0xf589('0x60')]=_0x4d85be['id'];if(_0x2c1a96['query'][_0xf589('0x64')]){_0xc4d765[_0xf589('0x4a')]=_[_0xf589('0x4c')](_0xc4d765[_0xf589('0x4a')],{'$or':_['map'](_0xc4d765[_0xf589('0x47')],function(_0x32b9f1){var _0xf536f1={};_0xf536f1[_0x32b9f1]={'$like':'%'+_0x2c1a96[_0xf589('0x45')]['filter']+'%'};return _0xf536f1;})});}_0xc4d765=_[_0xf589('0x4c')]({},_0xc4d765,_0x2c1a96['options']);return db[_0xf589('0x8d')]['count']({'where':_0xc4d765['where']})[_0xf589('0x1e')](function(_0x1917fb){_0x51325d['count']=_0x1917fb;if(_0x2c1a96[_0xf589('0x45')][_0xf589('0x4e')]){_0xc4d765[_0xf589('0x4f')]=[{'model':db[_0xf589('0x6d')],'as':'Contact','required':![]},{'model':db[_0xf589('0x9b')],'as':_0xf589('0xa8'),'attributes':[_0xf589('0x37'),'fullname','internal'],'required':![]},{'model':db[_0xf589('0xa9')],'as':_0xf589('0xaa'),'attributes':['id',_0xf589('0x37'),'color'],'where':_0x2c1a96['query'][_0xf589('0xab')]?{'id':_0x2c1a96[_0xf589('0x45')][_0xf589('0xab')]}:undefined,'required':_0x2c1a96[_0xf589('0x45')][_0xf589('0xab')]?!![]:![]}];}return db[_0xf589('0x8d')][_0xf589('0x50')](_0xc4d765);})[_0xf589('0x1e')](function(_0x37a600){_0x51325d['rows']=_0x37a600;return _0x51325d;});}})[_0xf589('0x1e')](respondWithFilteredResult(_0x1cc7df,_0xc4d765))['catch'](handleError(_0x1cc7df,null));};exports['addAgents']=function(_0x5cd2ce,_0x1690eb,_0x4e6398){return db[_0xf589('0x3d')][_0xf589('0x56')]({'where':{'id':_0x5cd2ce['params']['id']}})[_0xf589('0x1e')](handleEntityNotFound(_0x1690eb,null))[_0xf589('0x1e')](function(_0x50f0ab){if(_0x50f0ab){return _0x50f0ab[_0xf589('0xac')](_0x5cd2ce['body']['ids'],_[_0xf589('0xad')](_0x5cd2ce[_0xf589('0x58')],[_0xf589('0x66'),'id'])||{})[_0xf589('0x8f')](function(_0x209ee4){for(var _0x4d7a36=0x0;_0x4d7a36<_0x5cd2ce[_0xf589('0x58')][_0xf589('0x66')][_0xf589('0x55')];_0x4d7a36+=0x1){socket[_0xf589('0xae')]('userOpenchannelAccount:save',{'UserId':_0x5cd2ce[_0xf589('0x58')]['ids'][_0x4d7a36],'OpenchannelAccountId':_0x5cd2ce[_0xf589('0x53')]['id']});}return _0x209ee4;});}})['then'](respondWithResult(_0x1690eb,null))['catch'](handleError(_0x1690eb,null));};exports[_0xf589('0xaf')]=function(_0x39a36b,_0xb76167,_0x37f704){return db[_0xf589('0x3d')]['find']({'where':{'id':_0x39a36b['params']['id']}})[_0xf589('0x1e')](handleEntityNotFound(_0xb76167,null))['then'](function(_0x220cd3){if(_0x220cd3){return _0x220cd3[_0xf589('0xaf')](_0x39a36b[_0xf589('0x45')][_0xf589('0x66')])[_0xf589('0x1e')](function(){if(_[_0xf589('0xb0')](_0x39a36b['query'][_0xf589('0x66')])){for(var _0x5d2bad=0x0;_0x5d2bad<_0x39a36b[_0xf589('0x45')][_0xf589('0x66')]['length'];_0x5d2bad+=0x1){socket[_0xf589('0xae')](_0xf589('0xb1'),{'UserId':Number(_0x39a36b[_0xf589('0x45')][_0xf589('0x66')][_0x5d2bad]),'OpenchannelAccountId':Number(_0x39a36b[_0xf589('0x53')]['id'])});}}else{socket[_0xf589('0xae')]('userOpenchannelAccount:remove',{'UserId':Number(_0x39a36b[_0xf589('0x45')][_0xf589('0x66')]),'OpenchannelAccountId':Number(_0x39a36b[_0xf589('0x53')]['id'])});}});}})[_0xf589('0x1e')](respondWithStatusCode(_0xb76167,null))[_0xf589('0x26')](handleError(_0xb76167,null));};exports['getAgents']=function(_0x905861,_0x10a232,_0x74bb54){var _0x378c8d={};var _0xd15de1={};var _0x354246;var _0x3403ed;return db['OpenchannelAccount'][_0xf589('0x69')]({'where':{'id':_0x905861[_0xf589('0x53')]['id']}})['then'](handleEntityNotFound(_0x10a232,null))[_0xf589('0x1e')](function(_0x36f560){if(_0x36f560){_0x354246=_0x36f560;_0xd15de1[_0xf589('0x41')]=_['keys'](db[_0xf589('0x9b')][_0xf589('0x54')]);_0xd15de1[_0xf589('0x45')]=_[_0xf589('0x42')](_0x905861[_0xf589('0x45')]);_0xd15de1[_0xf589('0x43')]=_[_0xf589('0x44')](_0xd15de1[_0xf589('0x41')],_0xd15de1[_0xf589('0x45')]);_0x378c8d[_0xf589('0x47')]=_[_0xf589('0x44')](_0xd15de1[_0xf589('0x41')],qs['fields'](_0x905861['query'][_0xf589('0x46')]));_0x378c8d[_0xf589('0x47')]=_0x378c8d[_0xf589('0x47')]['length']?_0x378c8d['attributes']:_0xd15de1[_0xf589('0x41')];_0x378c8d[_0xf589('0x48')]=qs['sort'](_0x905861[_0xf589('0x45')][_0xf589('0x49')]);_0x378c8d[_0xf589('0x4a')]=qs['filters'](_[_0xf589('0x4b')](_0x905861[_0xf589('0x45')],_0xd15de1[_0xf589('0x43')]));if(_0x905861['query'][_0xf589('0x64')]){_0x378c8d[_0xf589('0x4a')]=_[_0xf589('0x4c')](_0x378c8d['where'],{'$or':_[_0xf589('0x3c')](_0x378c8d['attributes'],function(_0x519a85){var _0x18a734={};_0x18a734[_0x519a85]={'$like':'%'+_0x905861[_0xf589('0x45')][_0xf589('0x64')]+'%'};return _0x18a734;})});}_0x378c8d=_[_0xf589('0x4c')]({},_0x378c8d,_0x905861['options']);return _0x354246[_0xf589('0xb2')](_0x378c8d);}})['then'](function(_0x523fff){if(_0x523fff){_0x3403ed=_0x523fff[_0xf589('0x55')];if(!_0x905861[_0xf589('0x45')]['hasOwnProperty'](_0xf589('0x63'))){_0x378c8d[_0xf589('0x2b')]=qs[_0xf589('0x2b')](_0x905861[_0xf589('0x45')][_0xf589('0x2b')]);_0x378c8d[_0xf589('0x2d')]=qs[_0xf589('0x2d')](_0x905861[_0xf589('0x45')]['offset']);}return _0x354246[_0xf589('0xb2')](_0x378c8d);}})[_0xf589('0x1e')](function(_0x32e05b){if(_0x32e05b){return _0x32e05b?{'count':_0x3403ed,'rows':_0x32e05b}:null;}})['then'](respondWithResult(_0x10a232,null))[_0xf589('0x26')](handleError(_0x10a232,null));};exports[_0xf589('0x38')]=function(_0x11a3bd,_0x578cd6,_0x1c5731){var _0xfcc735,_0x54e0da,_0x58b850;if(_[_0xf589('0x76')](_0x11a3bd[_0xf589('0x58')][_0xf589('0x58')])||_0x11a3bd[_0xf589('0x58')]['body']===''){throw new db[(_0xf589('0x6e'))][(_0xf589('0x6f'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0xf589('0x76')](_0x11a3bd[_0xf589('0x58')]['to'])){}_0xfcc735=_0x11a3bd[_0xf589('0x58')]['to'];return db[_0xf589('0x3d')][_0xf589('0x69')]({'where':{'id':_0x11a3bd[_0xf589('0x53')]['id']}})['then'](handleEntityNotFound(_0x578cd6,null))['then'](function(_0x179d9c){if(_0x179d9c){return db['OpenchannelAccount']['find']({'where':{'id':_0x179d9c['id']},'include':[{'model':db[_0xf589('0x7e')],'as':_0xf589('0x7f'),'include':[{'model':db[_0xf589('0x6d')],'as':'Contacts','where':{[_0x179d9c[_0xf589('0x7a')]]:_0xfcc735},'limit':0x1,'order':[[_0xf589('0x73'),_0xf589('0x81')]]}]}]})[_0xf589('0x1e')](handleEntityNotFound(_0x578cd6,null))[_0xf589('0x1e')](function(_0x1e2404){if(_0x1e2404&&_0x1e2404[_0xf589('0x7f')]){_0x54e0da=_0x1e2404[_0xf589('0x34')]({'plain':!![]});if(_0x54e0da[_0xf589('0x7f')]&&_0x54e0da[_0xf589('0x7f')][_0xf589('0x80')]['length']){return _0x54e0da[_0xf589('0x7f')][_0xf589('0x80')][0x0];}return db[_0xf589('0x6d')][_0xf589('0x57')](_['defaults'](_0x11a3bd['body'],{'firstName':_0xfcc735,[_0x1e2404[_0xf589('0x7a')]]:_0xfcc735,'phone':_0xfcc735,'ListId':_0x54e0da['ListId']}));}})[_0xf589('0x1e')](handleEntityNotFound(_0x578cd6,null))['then'](function(_0x8709a2){if(_0x8709a2){_0x58b850=_0x8709a2;return db['OpenchannelInteraction']['find']({'where':{'ContactId':_0x58b850['id'],'closed':![],'OpenchannelAccountId':_0x54e0da['id']}})['then'](function(_0x2ea384){if(_0x2ea384){return[_0x2ea384,![]];}return db[_0xf589('0x8d')]['create']({'UserId':_0x11a3bd[_0xf589('0x59')]['id'],'ContactId':_0x58b850['id'],'OpenchannelAccountId':_0x54e0da['id'],'lastMsgDirection':_0xf589('0xb3'),'Messages':[_[_0xf589('0x4c')](_0x11a3bd['body'],{'read':![],'body':_0x11a3bd[_0xf589('0x58')][_0xf589('0x58')],'OpenchannelAccountId':_0x54e0da['id'],'UserId':_0x11a3bd[_0xf589('0x59')]['id'],'ContactId':_0x58b850['id']})]},{'include':[{'model':db['OpenchannelMessage'],'as':_0xf589('0xb4')}]})[_0xf589('0x1e')](function(_0x3de557){return[_0x3de557,!![]];});});}})['spread'](function(_0x49f6da,_0x522056){if(_0x522056){return _0x49f6da;}return db[_0xf589('0x98')][_0xf589('0x57')](_[_0xf589('0x4c')](_0x11a3bd[_0xf589('0x58')],{'read':![],'body':_0x11a3bd[_0xf589('0x58')][_0xf589('0x58')],'OpenchannelAccountId':_0x54e0da['id'],'OpenchannelInteractionId':_0x49f6da['id'],'UserId':_0x11a3bd[_0xf589('0x59')]['id'],'ContactId':_0x58b850['id']}))['then'](function(_0x329665){_0x49f6da['dataValues']['Messages']=[];_0x49f6da[_0xf589('0xb5')][_0xf589('0xb4')][_0xf589('0x95')](_0x329665[_0xf589('0xb5')]);return _0x49f6da;});});}})[_0xf589('0x1e')](respondWithResult(_0x578cd6,null))[_0xf589('0x26')](handleError(_0x578cd6,null));};