09afb8e5eb7721c88b66689e46cb7cc7d765fc56
[motion2.git] / server / api / faxAccount / faxAccount.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 _0x88f7=['app','system','description','Fax\x20Extension','appdata','Answer','CDR(type)=inbound-fax','ecm','faxdetect','maxrate','modem','t38timeout','push','FAXOPT(','Set','Wait','/var/opt/motion2/server/files/attachments/fax-${CALLERID(num)}-${CUT(UNIQUEID,.,1)}-${CUT(UNIQUEID,.,2)}-${STRFTIME(,,%C%y%m%d%H%M%S)}-rx.tif,d','bulkCreate','updateAccountApplications','VoiceExtension','key','createdAt','updatedAt','TrunkId','ListId','findById','FaxMessage','$gte','format','YYYY-MM-DD\x20HH:mm:ss','CmList','List','Contacts','DESC','attachments','join','server/files/attachments','CheckAfterSend','isNil','from','fax','CmContact','List\x20not\x20found','Send\x20Fax\x20failed','Messages','Contact\x20not\x20found','spread','out','filename','ContactId','dataValues','SendFax','SendFaxRpc,\x20%s','addAgents','removeAgents','userFaxAccount:remove','emit','getAgents','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','./faxAccount.socket','register','client','http','then','info','FaxAccount,\x20%s,\x20%s','debug','FaxAccount,\x20%s,\x20%s,\x20%s','request\x20sent','error','message','result','sendStatus','status','end','limit','offset','set','Content-Range','apply','reject','save','update','destroy','get','FaxAccounts','UserProfileResource','name','send','index','Pause','mandatoryDispositionPause','FaxAccount','rawAttributes','fieldName','type','model','map','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','VIRTUAL','filter','options','count','include','findAll','rows','catch','params','merge','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','FaxAccountId','Disposition','getDispositions','findOne','includeAll','ids','getAnswers','CannedAnswer','removeAnswers','addInteraction','FaxInteraction','omit','Contact','Owner','internal','Tag','Tags','tag','transaction','sequelize','Transaction','READ_COMMITTED','FaxApplication','findAndCountAll','priority','stack','finally','json','getApplications','exten','localstationid'];(function(_0x5959ed,_0x4fbf3c){var _0x47e60e=function(_0x11d482){while(--_0x11d482){_0x5959ed['push'](_0x5959ed['shift']());}};_0x47e60e(++_0x4fbf3c);}(_0x88f7,0xfd));var _0x788f=function(_0x53ccf2,_0x13cb67){_0x53ccf2=_0x53ccf2-0x0;var _0x5a2964=_0x88f7[_0x53ccf2];return _0x5a2964;};'use strict';var emlformat=require(_0x788f('0x0'));var rimraf=require(_0x788f('0x1'));var zipdir=require(_0x788f('0x2'));var jsonpatch=require(_0x788f('0x3'));var rp=require(_0x788f('0x4'));var moment=require(_0x788f('0x5'));var BPromise=require(_0x788f('0x6'));var Mustache=require('mustache');var util=require(_0x788f('0x7'));var path=require(_0x788f('0x8'));var sox=require(_0x788f('0x9'));var csv=require(_0x788f('0xa'));var ejs=require(_0x788f('0xb'));var fs=require('fs');var fs_extra=require(_0x788f('0xc'));var _=require(_0x788f('0xd'));var squel=require(_0x788f('0xe'));var crypto=require(_0x788f('0xf'));var jsforce=require(_0x788f('0x10'));var deskjs=require(_0x788f('0x11'));var toCsv=require(_0x788f('0xa'));var querystring=require(_0x788f('0x12'));var Papa=require(_0x788f('0x13'));var Redis=require(_0x788f('0x14'));var authService=require(_0x788f('0x15'));var qs=require('../../components/parsers/qs');var as=require(_0x788f('0x16'));var hardwareService=require(_0x788f('0x17'));var logger=require(_0x788f('0x18'))(_0x788f('0x19'));var utils=require(_0x788f('0x1a'));var config=require(_0x788f('0x1b'));var licenseUtil=require(_0x788f('0x1c'));var db=require(_0x788f('0x1d'))['db'];config[_0x788f('0x1e')]=_[_0x788f('0x1f')](config['redis'],{'host':_0x788f('0x20'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x788f('0x1e')]));require(_0x788f('0x21'))[_0x788f('0x22')](socket);var jayson=require('jayson/promise');var client=jayson[_0x788f('0x23')][_0x788f('0x24')]({'port':0x232c});var client9002=jayson[_0x788f('0x23')][_0x788f('0x24')]({'port':0x232a});function respondWithRpcPromise(_0x1ea083,_0x48e40c,_0x360ea2,_0x7017d6){return new BPromise(function(_0x7d0370,_0x259860){var _0x4e33a4=_0x7017d6||client;return _0x4e33a4['request'](_0x1ea083,_0x360ea2)[_0x788f('0x25')](function(_0x567bf2){logger[_0x788f('0x26')](_0x788f('0x27'),_0x48e40c,'request\x20sent');logger[_0x788f('0x28')](_0x788f('0x29'),_0x48e40c,_0x788f('0x2a'),JSON['stringify'](_0x567bf2));if(_0x567bf2[_0x788f('0x2b')]){if(_0x567bf2['error']['code']===0x1f4){logger[_0x788f('0x2b')](_0x788f('0x27'),_0x48e40c,_0x567bf2[_0x788f('0x2b')][_0x788f('0x2c')]);return _0x259860(_0x567bf2[_0x788f('0x2b')][_0x788f('0x2c')]);}logger[_0x788f('0x2b')]('FaxAccount,\x20%s,\x20%s',_0x48e40c,_0x567bf2[_0x788f('0x2b')]['message']);return _0x7d0370(_0x567bf2[_0x788f('0x2b')]['message']);}else{logger[_0x788f('0x26')](_0x788f('0x27'),_0x48e40c,'request\x20sent');_0x7d0370(_0x567bf2[_0x788f('0x2d')][_0x788f('0x2c')]);}})['catch'](function(_0x2d565e){logger[_0x788f('0x2b')]('FaxAccount,\x20%s,\x20%s',_0x48e40c,_0x2d565e);_0x259860(_0x2d565e);});});}function respondWithStatusCode(_0x2a6cdf,_0x4e8720){_0x4e8720=_0x4e8720||0xcc;return function(_0x1fcd68){if(_0x1fcd68){return _0x2a6cdf[_0x788f('0x2e')](_0x4e8720);}return _0x2a6cdf[_0x788f('0x2f')](_0x4e8720)[_0x788f('0x30')]();};}function respondWithResult(_0x119852,_0x58dd84){_0x58dd84=_0x58dd84||0xc8;return function(_0x1b05cb){if(_0x1b05cb){return _0x119852[_0x788f('0x2f')](_0x58dd84)['json'](_0x1b05cb);}};}function respondWithFilteredResult(_0x4ca65b,_0x317b72){return function(_0x240dc4){if(_0x240dc4){var _0x4c7fdc=typeof _0x317b72['offset']==='undefined'&&typeof _0x317b72[_0x788f('0x31')]==='undefined';var _0x4a5ebc=_0x240dc4['count'];var _0x365d20=_0x4c7fdc?0x0:_0x317b72[_0x788f('0x32')];var _0x26bcff=_0x4c7fdc?_0x240dc4['count']:_0x317b72[_0x788f('0x32')]+_0x317b72[_0x788f('0x31')];var _0x31f1ff;if(_0x26bcff>=_0x4a5ebc){_0x26bcff=_0x4a5ebc;_0x31f1ff=0xc8;}else{_0x31f1ff=0xce;}_0x4ca65b[_0x788f('0x2f')](_0x31f1ff);return _0x4ca65b[_0x788f('0x33')](_0x788f('0x34'),_0x365d20+'-'+_0x26bcff+'/'+_0x4a5ebc)['json'](_0x240dc4);}return null;};}function patchUpdates(_0x3ed094){return function(_0x49be0d){try{jsonpatch[_0x788f('0x35')](_0x49be0d,_0x3ed094,!![]);}catch(_0x455efb){return BPromise[_0x788f('0x36')](_0x455efb);}return _0x49be0d[_0x788f('0x37')]();};}function saveUpdates(_0x32d6c2,_0x168ea9){return function(_0x52e8e0){if(_0x52e8e0){return _0x52e8e0[_0x788f('0x38')](_0x32d6c2)[_0x788f('0x25')](function(_0x4c3dd9){return _0x4c3dd9;});}return null;};}function removeEntity(_0x4ac008,_0x3818c5){return function(_0x8e8c75){if(_0x8e8c75){return _0x8e8c75[_0x788f('0x39')]()[_0x788f('0x25')](function(){var _0x175faa=_0x8e8c75[_0x788f('0x3a')]({'plain':!![]});var _0x3a6c91=_0x788f('0x3b');return db[_0x788f('0x3c')][_0x788f('0x39')]({'where':{'type':_0x3a6c91,'resourceId':_0x175faa['id']}})['then'](function(){return _0x8e8c75;});})[_0x788f('0x25')](function(){_0x4ac008[_0x788f('0x2f')](0xcc)[_0x788f('0x30')]();});}};}function handleEntityNotFound(_0x5848d0,_0x373686){return function(_0x2fc9ba){if(!_0x2fc9ba){_0x5848d0['sendStatus'](0x194);}return _0x2fc9ba;};}function handleError(_0x15aed8,_0x530ada){_0x530ada=_0x530ada||0x1f4;return function(_0x3510ff){logger[_0x788f('0x2b')](_0x3510ff['stack']);if(_0x3510ff[_0x788f('0x3d')]){delete _0x3510ff[_0x788f('0x3d')];}_0x15aed8['status'](_0x530ada)[_0x788f('0x3e')](_0x3510ff);};}exports[_0x788f('0x3f')]=function(_0x2e6221,_0x27aea8){var _0x4d3e40={'include':[{'model':db[_0x788f('0x40')],'as':_0x788f('0x41')}]},_0x3acf62={},_0x33e547={'count':0x0,'rows':[]};var _0x30db12=_['map'](db[_0x788f('0x42')][_0x788f('0x43')],function(_0x22d34d){return{'name':_0x22d34d[_0x788f('0x44')],'type':_0x22d34d[_0x788f('0x45')]['key']};});_0x3acf62[_0x788f('0x46')]=_[_0x788f('0x47')](_0x30db12,_0x788f('0x3d'));_0x3acf62['query']=_[_0x788f('0x48')](_0x2e6221[_0x788f('0x49')]);_0x3acf62[_0x788f('0x4a')]=_[_0x788f('0x4b')](_0x3acf62[_0x788f('0x46')],_0x3acf62[_0x788f('0x49')]);_0x4d3e40[_0x788f('0x4c')]=_[_0x788f('0x4b')](_0x3acf62[_0x788f('0x46')],qs[_0x788f('0x4d')](_0x2e6221[_0x788f('0x49')][_0x788f('0x4d')]));_0x4d3e40['attributes']=_0x4d3e40[_0x788f('0x4c')][_0x788f('0x4e')]?_0x4d3e40[_0x788f('0x4c')]:_0x3acf62[_0x788f('0x46')];if(!_0x2e6221[_0x788f('0x49')][_0x788f('0x4f')](_0x788f('0x50'))){_0x4d3e40[_0x788f('0x31')]=qs['limit'](_0x2e6221[_0x788f('0x49')][_0x788f('0x31')]);_0x4d3e40[_0x788f('0x32')]=qs[_0x788f('0x32')](_0x2e6221[_0x788f('0x49')][_0x788f('0x32')]);}_0x4d3e40[_0x788f('0x51')]=qs[_0x788f('0x52')](_0x2e6221[_0x788f('0x49')]['sort']);_0x4d3e40[_0x788f('0x53')]=qs[_0x788f('0x4a')](_[_0x788f('0x54')](_0x2e6221[_0x788f('0x49')],_0x3acf62[_0x788f('0x4a')]),_0x30db12);if(_0x2e6221[_0x788f('0x49')]['filter']){_0x4d3e40[_0x788f('0x53')]=_['merge'](_0x4d3e40[_0x788f('0x53')],{'$or':_[_0x788f('0x47')](_0x30db12,function(_0x257b18){if(_0x257b18[_0x788f('0x45')]!==_0x788f('0x55')){var _0x55ecc2={};_0x55ecc2[_0x257b18[_0x788f('0x3d')]]={'$like':'%'+_0x2e6221[_0x788f('0x49')][_0x788f('0x56')]+'%'};return _0x55ecc2;}})});}_0x4d3e40=_['merge']({},_0x4d3e40,_0x2e6221[_0x788f('0x57')]);var _0x4e27df={'where':_0x4d3e40[_0x788f('0x53')]};return db[_0x788f('0x42')][_0x788f('0x58')](_0x4e27df)[_0x788f('0x25')](function(_0x5c9332){_0x33e547[_0x788f('0x58')]=_0x5c9332;if(_0x2e6221[_0x788f('0x49')]['includeAll']){_0x4d3e40[_0x788f('0x59')]=[{'all':!![]}];}return db[_0x788f('0x42')][_0x788f('0x5a')](_0x4d3e40);})['then'](function(_0x399768){_0x33e547[_0x788f('0x5b')]=_0x399768;return _0x33e547;})[_0x788f('0x25')](respondWithFilteredResult(_0x27aea8,_0x4d3e40))[_0x788f('0x5c')](handleError(_0x27aea8,null));};exports['show']=function(_0x6e0c9c,_0x123dc7){var _0x80394c={'raw':![],'where':{'id':_0x6e0c9c[_0x788f('0x5d')]['id']},'include':[{'model':db['Pause'],'as':_0x788f('0x41')}]},_0x5ee639={};_0x5ee639[_0x788f('0x46')]=_['keys'](db[_0x788f('0x42')][_0x788f('0x43')]);_0x5ee639[_0x788f('0x49')]=_[_0x788f('0x48')](_0x6e0c9c[_0x788f('0x49')]);_0x5ee639['filters']=_['intersection'](_0x5ee639[_0x788f('0x46')],_0x5ee639[_0x788f('0x49')]);_0x80394c['attributes']=_['intersection'](_0x5ee639['model'],qs[_0x788f('0x4d')](_0x6e0c9c[_0x788f('0x49')][_0x788f('0x4d')]));_0x80394c[_0x788f('0x4c')]=_0x80394c[_0x788f('0x4c')][_0x788f('0x4e')]?_0x80394c[_0x788f('0x4c')]:_0x5ee639[_0x788f('0x46')];if(_0x6e0c9c[_0x788f('0x49')]['includeAll']){_0x80394c[_0x788f('0x59')]=[{'all':!![]}];}_0x80394c=_[_0x788f('0x5e')]({},_0x80394c,_0x6e0c9c[_0x788f('0x57')]);return db[_0x788f('0x42')][_0x788f('0x5f')](_0x80394c)['then'](handleEntityNotFound(_0x123dc7,null))[_0x788f('0x25')](respondWithResult(_0x123dc7,null))[_0x788f('0x5c')](handleError(_0x123dc7,null));};exports[_0x788f('0x60')]=function(_0x4b71ba,_0x11761b){return db[_0x788f('0x42')][_0x788f('0x60')](_0x4b71ba[_0x788f('0x61')],{})[_0x788f('0x25')](function(_0x1be487){var _0x238078=_0x4b71ba[_0x788f('0x62')][_0x788f('0x3a')]({'plain':!![]});if(!_0x238078)throw new Error(_0x788f('0x63'));if(_0x238078[_0x788f('0x64')]===_0x788f('0x62')){var _0x5cdb07=_0x1be487[_0x788f('0x3a')]({'plain':!![]});var _0x35a398='FaxAccounts';return db[_0x788f('0x65')][_0x788f('0x5f')]({'where':{'name':_0x35a398,'userProfileId':_0x238078[_0x788f('0x66')]},'raw':!![]})[_0x788f('0x25')](function(_0x1a3dc5){if(_0x1a3dc5&&_0x1a3dc5[_0x788f('0x67')]===0x0){return db[_0x788f('0x3c')][_0x788f('0x60')]({'name':_0x5cdb07[_0x788f('0x3d')],'resourceId':_0x5cdb07['id'],'type':_0x1a3dc5[_0x788f('0x3d')],'sectionId':_0x1a3dc5['id']},{})[_0x788f('0x25')](function(){return _0x1be487;});}else{return _0x1be487;}})[_0x788f('0x5c')](function(_0x2095bb){logger[_0x788f('0x2b')](_0x788f('0x68'),_0x2095bb);throw _0x2095bb;});}return _0x1be487;})[_0x788f('0x25')](respondWithResult(_0x11761b,0xc9))[_0x788f('0x5c')](handleError(_0x11761b,null));};exports['update']=function(_0x4efbc6,_0x1c3f7f){if(_0x4efbc6['body']['id']){delete _0x4efbc6[_0x788f('0x61')]['id'];}return db[_0x788f('0x42')]['find']({'where':{'id':_0x4efbc6[_0x788f('0x5d')]['id']},'include':[{'model':db['Pause'],'as':_0x788f('0x41')}]})[_0x788f('0x25')](handleEntityNotFound(_0x1c3f7f,null))['then'](saveUpdates(_0x4efbc6[_0x788f('0x61')],null))['then'](respondWithResult(_0x1c3f7f,null))['catch'](handleError(_0x1c3f7f,null));};exports[_0x788f('0x39')]=function(_0x3edccd,_0x1c61c6){return db[_0x788f('0x42')]['find']({'where':{'id':_0x3edccd[_0x788f('0x5d')]['id']}})[_0x788f('0x25')](handleEntityNotFound(_0x1c61c6,null))[_0x788f('0x25')](removeEntity(_0x1c61c6,null))[_0x788f('0x5c')](handleError(_0x1c61c6,null));};exports[_0x788f('0x69')]=function(_0x2a9279,_0x18f40c){return db['FaxAccount']['describe']()['then'](respondWithResult(_0x18f40c,null))[_0x788f('0x5c')](handleError(_0x18f40c,null));};exports['addDisposition']=function(_0x47bee9,_0x424fa3,_0x32e9e9){if(_0x47bee9['body']['id']){delete _0x47bee9[_0x788f('0x61')]['id'];}return db[_0x788f('0x42')]['find']({'where':{'id':_0x47bee9[_0x788f('0x5d')]['id']}})['then'](handleEntityNotFound(_0x424fa3,null))[_0x788f('0x25')](function(_0x3d12d4){if(_0x3d12d4){_0x47bee9['body'][_0x788f('0x6a')]=_0x3d12d4['id'];return db[_0x788f('0x6b')][_0x788f('0x60')](_0x47bee9[_0x788f('0x61')]);}})[_0x788f('0x25')](respondWithResult(_0x424fa3,null))[_0x788f('0x5c')](handleError(_0x424fa3,null));};exports[_0x788f('0x6c')]=function(_0x19d410,_0x4d27c1,_0x29d355){var _0x756a96={'raw':![],'where':{}};var _0x24b296={};var _0x1fc3d3={'count':0x0,'rows':[]};return db[_0x788f('0x42')][_0x788f('0x6d')]({'where':{'id':_0x19d410[_0x788f('0x5d')]['id']}})[_0x788f('0x25')](handleEntityNotFound(_0x4d27c1,null))[_0x788f('0x25')](function(_0x1ba04b){if(_0x1ba04b){_0x24b296['model']=_[_0x788f('0x48')](db[_0x788f('0x6b')][_0x788f('0x43')]);_0x24b296['query']=_[_0x788f('0x48')](_0x19d410['query']);_0x24b296['filters']=_[_0x788f('0x4b')](_0x24b296[_0x788f('0x46')],_0x24b296[_0x788f('0x49')]);_0x756a96['attributes']=_[_0x788f('0x4b')](_0x24b296['model'],qs[_0x788f('0x4d')](_0x19d410[_0x788f('0x49')][_0x788f('0x4d')]));_0x756a96[_0x788f('0x4c')]=_0x756a96[_0x788f('0x4c')][_0x788f('0x4e')]?_0x756a96[_0x788f('0x4c')]:_0x24b296[_0x788f('0x46')];if(!_0x19d410[_0x788f('0x49')]['hasOwnProperty'](_0x788f('0x50'))){_0x756a96['limit']=qs['limit'](_0x19d410[_0x788f('0x49')]['limit']);_0x756a96[_0x788f('0x32')]=qs[_0x788f('0x32')](_0x19d410['query'][_0x788f('0x32')]);}_0x756a96['order']=qs['sort'](_0x19d410[_0x788f('0x49')][_0x788f('0x52')]);_0x756a96[_0x788f('0x53')]=qs[_0x788f('0x4a')](_['pick'](_0x19d410[_0x788f('0x49')],_0x24b296['filters']));_0x756a96['where'][_0x788f('0x6a')]=_0x1ba04b['id'];if(_0x19d410[_0x788f('0x49')][_0x788f('0x56')]){_0x756a96[_0x788f('0x53')]=_['merge'](_0x756a96[_0x788f('0x53')],{'$or':_[_0x788f('0x47')](_0x756a96[_0x788f('0x4c')],function(_0x2bde6e){var _0x254a4f={};_0x254a4f[_0x2bde6e]={'$like':'%'+_0x19d410[_0x788f('0x49')]['filter']+'%'};return _0x254a4f;})});}_0x756a96=_[_0x788f('0x5e')]({},_0x756a96,_0x19d410[_0x788f('0x57')]);return db[_0x788f('0x6b')][_0x788f('0x58')]({'where':_0x756a96['where']})[_0x788f('0x25')](function(_0x35f35f){_0x1fc3d3[_0x788f('0x58')]=_0x35f35f;if(_0x19d410['query'][_0x788f('0x6e')]){_0x756a96[_0x788f('0x59')]=[{'all':!![]}];}return db[_0x788f('0x6b')][_0x788f('0x5a')](_0x756a96);})[_0x788f('0x25')](function(_0x4e2d93){_0x1fc3d3[_0x788f('0x5b')]=_0x4e2d93;return _0x1fc3d3;});}})['then'](respondWithFilteredResult(_0x4d27c1,_0x756a96))['catch'](handleError(_0x4d27c1,null));};exports['removeDispositions']=function(_0x3b4d82,_0x26ebda,_0x36b0c1){return db[_0x788f('0x42')]['find']({'where':{'id':_0x3b4d82[_0x788f('0x5d')]['id']}})[_0x788f('0x25')](handleEntityNotFound(_0x26ebda,null))[_0x788f('0x25')](function(_0x4c8fab){if(_0x4c8fab){return _0x4c8fab['removeDispositions'](_0x3b4d82[_0x788f('0x49')][_0x788f('0x6f')]);}})[_0x788f('0x25')](respondWithStatusCode(_0x26ebda,null))[_0x788f('0x5c')](handleError(_0x26ebda,null));};exports['addAnswer']=function(_0x125906,_0x2bdddb,_0x506802){if(_0x125906[_0x788f('0x61')]['id']){delete _0x125906['body']['id'];}return db[_0x788f('0x42')][_0x788f('0x5f')]({'where':{'id':_0x125906['params']['id']}})[_0x788f('0x25')](handleEntityNotFound(_0x2bdddb,null))['then'](function(_0x386cdc){if(_0x386cdc){_0x125906[_0x788f('0x61')][_0x788f('0x6a')]=_0x386cdc['id'];return db['CannedAnswer'][_0x788f('0x60')](_0x125906[_0x788f('0x61')]);}})[_0x788f('0x25')](respondWithResult(_0x2bdddb,null))[_0x788f('0x5c')](handleError(_0x2bdddb,null));};exports[_0x788f('0x70')]=function(_0x3ffda7,_0x4e81cf,_0x1f7e56){var _0x26f075={'raw':![],'where':{}};var _0x4fa30a={};var _0x4f8b33={'count':0x0,'rows':[]};return db[_0x788f('0x42')][_0x788f('0x6d')]({'where':{'id':_0x3ffda7['params']['id']}})['then'](handleEntityNotFound(_0x4e81cf,null))[_0x788f('0x25')](function(_0x1690b9){if(_0x1690b9){_0x4fa30a['model']=_[_0x788f('0x48')](db[_0x788f('0x71')][_0x788f('0x43')]);_0x4fa30a['query']=_['keys'](_0x3ffda7[_0x788f('0x49')]);_0x4fa30a[_0x788f('0x4a')]=_['intersection'](_0x4fa30a[_0x788f('0x46')],_0x4fa30a[_0x788f('0x49')]);_0x26f075[_0x788f('0x4c')]=_['intersection'](_0x4fa30a[_0x788f('0x46')],qs['fields'](_0x3ffda7[_0x788f('0x49')][_0x788f('0x4d')]));_0x26f075[_0x788f('0x4c')]=_0x26f075[_0x788f('0x4c')]['length']?_0x26f075['attributes']:_0x4fa30a[_0x788f('0x46')];if(!_0x3ffda7[_0x788f('0x49')]['hasOwnProperty'](_0x788f('0x50'))){_0x26f075['limit']=qs[_0x788f('0x31')](_0x3ffda7[_0x788f('0x49')]['limit']);_0x26f075['offset']=qs[_0x788f('0x32')](_0x3ffda7[_0x788f('0x49')]['offset']);}_0x26f075[_0x788f('0x51')]=qs[_0x788f('0x52')](_0x3ffda7['query'][_0x788f('0x52')]);_0x26f075[_0x788f('0x53')]=qs['filters'](_[_0x788f('0x54')](_0x3ffda7[_0x788f('0x49')],_0x4fa30a[_0x788f('0x4a')]));_0x26f075[_0x788f('0x53')][_0x788f('0x6a')]=_0x1690b9['id'];if(_0x3ffda7[_0x788f('0x49')][_0x788f('0x56')]){_0x26f075[_0x788f('0x53')]=_[_0x788f('0x5e')](_0x26f075[_0x788f('0x53')],{'$or':_['map'](_0x26f075[_0x788f('0x4c')],function(_0xd7341){var _0x20f5fa={};_0x20f5fa[_0xd7341]={'$like':'%'+_0x3ffda7[_0x788f('0x49')][_0x788f('0x56')]+'%'};return _0x20f5fa;})});}_0x26f075=_[_0x788f('0x5e')]({},_0x26f075,_0x3ffda7['options']);return db['CannedAnswer']['count']({'where':_0x26f075[_0x788f('0x53')]})[_0x788f('0x25')](function(_0x2f9c4d){_0x4f8b33[_0x788f('0x58')]=_0x2f9c4d;if(_0x3ffda7['query'][_0x788f('0x6e')]){_0x26f075[_0x788f('0x59')]=[{'all':!![]}];}return db[_0x788f('0x71')]['findAll'](_0x26f075);})['then'](function(_0x3745e3){_0x4f8b33['rows']=_0x3745e3;return _0x4f8b33;});}})[_0x788f('0x25')](respondWithFilteredResult(_0x4e81cf,_0x26f075))[_0x788f('0x5c')](handleError(_0x4e81cf,null));};exports[_0x788f('0x72')]=function(_0x437bbe,_0x4151df,_0x1dc84a){return db['FaxAccount'][_0x788f('0x5f')]({'where':{'id':_0x437bbe[_0x788f('0x5d')]['id']}})['then'](handleEntityNotFound(_0x4151df,null))[_0x788f('0x25')](function(_0x33e09f){if(_0x33e09f){return _0x33e09f['removeAnswers'](_0x437bbe[_0x788f('0x49')][_0x788f('0x6f')]);}})[_0x788f('0x25')](respondWithStatusCode(_0x4151df,null))[_0x788f('0x5c')](handleError(_0x4151df,null));};exports[_0x788f('0x73')]=function(_0x487469,_0x10a499,_0x34e07b){return db[_0x788f('0x74')][_0x788f('0x5f')]({'where':{'id':_0x487469['params']['id']}})[_0x788f('0x25')](handleEntityNotFound(_0x10a499,null))[_0x788f('0x25')](function(_0xd13e57){if(_0xd13e57){return _0xd13e57[_0x788f('0x73')](_0x487469[_0x788f('0x61')][_0x788f('0x6f')],_[_0x788f('0x75')](_0x487469[_0x788f('0x61')],['ids','id'])||{});}})[_0x788f('0x25')](respondWithResult(_0x10a499,null))[_0x788f('0x5c')](handleError(_0x10a499,null));};exports['getInteractions']=function(_0x12f336,_0x283e40,_0x223245){var _0x46c261={'raw':![],'where':{}};var _0x933322={};var _0x22080c={'count':0x0,'rows':[]};return db[_0x788f('0x42')][_0x788f('0x6d')]({'where':{'id':_0x12f336[_0x788f('0x5d')]['id']}})[_0x788f('0x25')](handleEntityNotFound(_0x283e40,null))['then'](function(_0x2c4b91){if(_0x2c4b91){_0x933322[_0x788f('0x46')]=_['keys'](db[_0x788f('0x74')]['rawAttributes']);_0x933322[_0x788f('0x49')]=_[_0x788f('0x48')](_0x12f336['query']);_0x933322[_0x788f('0x4a')]=_['intersection'](_0x933322[_0x788f('0x46')],_0x933322[_0x788f('0x49')]);_0x46c261[_0x788f('0x4c')]=_['intersection'](_0x933322[_0x788f('0x46')],qs['fields'](_0x12f336[_0x788f('0x49')][_0x788f('0x4d')]));_0x46c261[_0x788f('0x4c')]=_0x46c261[_0x788f('0x4c')][_0x788f('0x4e')]?_0x46c261[_0x788f('0x4c')]:_0x933322[_0x788f('0x46')];if(!_0x12f336[_0x788f('0x49')][_0x788f('0x4f')]('nolimit')){_0x46c261[_0x788f('0x31')]=qs[_0x788f('0x31')](_0x12f336[_0x788f('0x49')][_0x788f('0x31')]);_0x46c261['offset']=qs[_0x788f('0x32')](_0x12f336[_0x788f('0x49')]['offset']);}_0x46c261[_0x788f('0x51')]=qs[_0x788f('0x52')](_0x12f336['query'][_0x788f('0x52')]);_0x46c261[_0x788f('0x53')]=qs['filters'](_[_0x788f('0x54')](_0x12f336[_0x788f('0x49')],_0x933322[_0x788f('0x4a')]));_0x46c261['where'][_0x788f('0x6a')]=_0x2c4b91['id'];if(_0x12f336[_0x788f('0x49')][_0x788f('0x56')]){_0x46c261[_0x788f('0x53')]=_[_0x788f('0x5e')](_0x46c261['where'],{'$or':_[_0x788f('0x47')](_0x46c261[_0x788f('0x4c')],function(_0x25d961){var _0x4d42df={};_0x4d42df[_0x25d961]={'$like':'%'+_0x12f336[_0x788f('0x49')]['filter']+'%'};return _0x4d42df;})});}_0x46c261=_[_0x788f('0x5e')]({},_0x46c261,_0x12f336[_0x788f('0x57')]);return db[_0x788f('0x74')]['count']({'where':_0x46c261['where']})[_0x788f('0x25')](function(_0x1cfccf){_0x22080c[_0x788f('0x58')]=_0x1cfccf;if(_0x12f336[_0x788f('0x49')][_0x788f('0x6e')]){_0x46c261[_0x788f('0x59')]=[{'model':db['CmContact'],'as':_0x788f('0x76'),'required':![]},{'model':db['User'],'as':_0x788f('0x77'),'attributes':[_0x788f('0x3d'),'fullname',_0x788f('0x78')],'required':![]},{'model':db[_0x788f('0x79')],'as':_0x788f('0x7a'),'attributes':['id',_0x788f('0x3d'),'color'],'where':_0x12f336[_0x788f('0x49')]['tag']?{'id':_0x12f336['query'][_0x788f('0x7b')]}:undefined,'required':_0x12f336['query'][_0x788f('0x7b')]?!![]:![]}];}return db['FaxInteraction'][_0x788f('0x5a')](_0x46c261);})[_0x788f('0x25')](function(_0x49ea48){_0x22080c[_0x788f('0x5b')]=_0x49ea48;return _0x22080c;});}})[_0x788f('0x25')](respondWithFilteredResult(_0x283e40,_0x46c261))['catch'](handleError(_0x283e40,null));};exports['addApplications']=function(_0x5ee8ee,_0x82c519){var _0x226338=_0x5ee8ee['params']['id'];var _0x4a98db=_0x5ee8ee[_0x788f('0x61')];var _0x4bf09e=0xc8;var _0x41392a=null;return db['sequelize'][_0x788f('0x7c')]({'isolationLevel':db[_0x788f('0x7d')][_0x788f('0x7e')]['ISOLATION_LEVELS'][_0x788f('0x7f')]},function(_0x53f7e2){return db[_0x788f('0x42')][_0x788f('0x6d')]({'where':{'id':_0x226338},'transaction':_0x53f7e2})[_0x788f('0x25')](function(_0x23fb96){if(_0x23fb96){return db['FaxApplication'][_0x788f('0x39')]({'where':{'FaxAccountId':_0x226338},'transaction':_0x53f7e2})[_0x788f('0x25')](function(){var _0xf61270=_['map'](_0x4a98db,function(_0xf80490){_0xf80490['FaxAccountId']=_0x226338;return _0xf80490;});return db[_0x788f('0x80')]['bulkCreate'](_0xf61270,{'transaction':_0x53f7e2});});}else{_0x4bf09e=0x194;_0x41392a=[];}});})[_0x788f('0x25')](function(){if(_0x4bf09e!==0x194){return db['FaxApplication'][_0x788f('0x81')]({'where':{'FaxAccountId':_0x226338},'order':_0x788f('0x82')})['then'](function(_0x2231ce){_0x41392a=_0x2231ce;});}})[_0x788f('0x5c')](function(_0x2a0e58){_0x4bf09e=0x1f4;logger[_0x788f('0x2b')](_0x2a0e58[_0x788f('0x83')]);if(_0x2a0e58[_0x788f('0x3d')]){delete _0x2a0e58[_0x788f('0x3d')];}_0x41392a=_0x2a0e58;})[_0x788f('0x84')](function(){if(_0x41392a===null){_0x82c519[_0x788f('0x2e')](_0x4bf09e);}else{if(_0x4bf09e===0x1f4){_0x82c519[_0x788f('0x2f')](_0x4bf09e)['send'](_0x41392a);}else{_0x82c519[_0x788f('0x2f')](_0x4bf09e)[_0x788f('0x85')](_0x41392a);}}});};exports[_0x788f('0x86')]=function(_0x73240a,_0x4f473d,_0x525b5e){var _0x20e499={};var _0x2d24d3={};var _0x184534;var _0x44e4ab;return db['FaxAccount'][_0x788f('0x6d')]({'where':{'id':_0x73240a['params']['id']}})[_0x788f('0x25')](handleEntityNotFound(_0x4f473d,null))[_0x788f('0x25')](function(_0x244298){if(_0x244298){_0x184534=_0x244298;_0x2d24d3['model']=_[_0x788f('0x48')](db[_0x788f('0x80')][_0x788f('0x43')]);_0x2d24d3[_0x788f('0x49')]=_[_0x788f('0x48')](_0x73240a[_0x788f('0x49')]);_0x2d24d3[_0x788f('0x4a')]=_[_0x788f('0x4b')](_0x2d24d3[_0x788f('0x46')],_0x2d24d3[_0x788f('0x49')]);_0x20e499[_0x788f('0x4c')]=_[_0x788f('0x4b')](_0x2d24d3['model'],qs[_0x788f('0x4d')](_0x73240a[_0x788f('0x49')]['fields']));_0x20e499[_0x788f('0x4c')]=_0x20e499['attributes'][_0x788f('0x4e')]?_0x20e499[_0x788f('0x4c')]:_0x2d24d3[_0x788f('0x46')];_0x20e499[_0x788f('0x51')]=qs[_0x788f('0x52')](_0x73240a[_0x788f('0x49')][_0x788f('0x52')]);_0x20e499[_0x788f('0x53')]=qs[_0x788f('0x4a')](_[_0x788f('0x54')](_0x73240a[_0x788f('0x49')],_0x2d24d3[_0x788f('0x4a')]));if(_0x73240a[_0x788f('0x49')][_0x788f('0x56')]){_0x20e499[_0x788f('0x53')]=_[_0x788f('0x5e')](_0x20e499[_0x788f('0x53')],{'$or':_['map'](_0x20e499[_0x788f('0x4c')],function(_0x4c43be){var _0x4575ad={};_0x4575ad[_0x4c43be]={'$like':'%'+_0x73240a[_0x788f('0x49')][_0x788f('0x56')]+'%'};return _0x4575ad;})});}_0x20e499=_['merge']({},_0x20e499,_0x73240a['options']);return _0x184534['getApplications'](_0x20e499);}})[_0x788f('0x25')](function(_0x1b848b){if(_0x1b848b){_0x44e4ab=_0x1b848b['length'];if(!_0x73240a['query']['hasOwnProperty'](_0x788f('0x50'))){_0x20e499[_0x788f('0x31')]=qs[_0x788f('0x31')](_0x73240a['query'][_0x788f('0x31')]);_0x20e499['offset']=qs[_0x788f('0x32')](_0x73240a[_0x788f('0x49')][_0x788f('0x32')]);}return _0x184534['getApplications'](_0x20e499);}})[_0x788f('0x25')](function(_0x325ae4){if(_0x325ae4){return _0x325ae4?{'count':_0x44e4ab,'rows':_0x325ae4}:null;}})[_0x788f('0x25')](respondWithResult(_0x4f473d,null))[_0x788f('0x5c')](handleError(_0x4f473d,null));};function Extension(_0x242aec,_0x6c3f90,_0x4cf504,_0x261cc7){this['context']='from-voip-provider';this[_0x788f('0x87')]=_0x242aec[_0x788f('0x88')];this[_0x788f('0x89')]=_0x261cc7;this[_0x788f('0x45')]=_0x788f('0x8a');this[_0x788f('0x8b')]=_0x788f('0x8c');this[_0x788f('0x6a')]=_0x242aec['id'];this[_0x788f('0x82')]=_0x6c3f90;this[_0x788f('0x8d')]=_0x4cf504;}function createExtensionsReciveFax(_0x2e90c6){var _0x331c71=0x1;var _0x35d644=[];_0x35d644['push'](new Extension(_0x2e90c6,_0x331c71,'',_0x788f('0x8e')));_0x331c71+=0x1;_0x35d644['push'](new Extension(_0x2e90c6,_0x331c71,_0x788f('0x8f'),'Set'));_0x331c71+=0x1;for(var _0x2bf05d in _0x2e90c6){if(_0x2e90c6['hasOwnProperty'](_0x2bf05d)&&(_0x2bf05d===_0x788f('0x90')||_0x2bf05d===_0x788f('0x88')||_0x2bf05d==='gateway'||_0x2bf05d===_0x788f('0x91')||_0x2bf05d==='headerinfo'||_0x2bf05d===_0x788f('0x92')||_0x2bf05d==='minrate'||_0x2bf05d===_0x788f('0x93')||_0x2bf05d===_0x788f('0x94'))){_0x35d644[_0x788f('0x95')](new Extension(_0x2e90c6,_0x331c71,_0x788f('0x96')+_0x2bf05d+')='+_0x2e90c6[_0x2bf05d],_0x788f('0x97')));_0x331c71+=0x1;}}_0x35d644[_0x788f('0x95')](new Extension(_0x2e90c6,_0x331c71,'6',_0x788f('0x98')));_0x331c71+=0x1;_0x35d644[_0x788f('0x95')](new Extension(_0x2e90c6,_0x331c71,_0x788f('0x99'),'ReceiveFax'));_0x331c71=0x0;return _0x35d644;}exports['addAccountApplications']=function(_0x304fd9,_0x42f946,_0x5ae7eb){var _0x3954da;return db[_0x788f('0x7d')][_0x788f('0x7c')](function(_0x477123){return db['FaxAccount'][_0x788f('0x60')](_0x304fd9[_0x788f('0x61')],{'transaction':_0x477123})[_0x788f('0x25')](function(_0xeca28){_0x3954da=_0xeca28[_0x788f('0x3a')]({'plain':!![]});return db['VoiceExtension'][_0x788f('0x9a')](createExtensionsReciveFax(_0x3954da),{'transaction':_0x477123});});})[_0x788f('0x25')](function(){return _0x3954da;})[_0x788f('0x25')](respondWithResult(_0x42f946,null))[_0x788f('0x5c')](handleError(_0x42f946,null));};exports[_0x788f('0x9b')]=function(_0x55b7fb,_0x4d6e6a,_0x1aa55c){var _0x408591;return db['sequelize']['transaction'](function(_0x26b9e4){return db[_0x788f('0x42')][_0x788f('0x38')](_0x55b7fb[_0x788f('0x61')],{'where':{'id':_0x55b7fb['body']['id']},'transaction':_0x26b9e4})[_0x788f('0x25')](function(_0x1e8edf){return db[_0x788f('0x9c')][_0x788f('0x39')]({'where':{'FaxAccountId':_0x55b7fb['body']['id']},'transaction':_0x26b9e4})[_0x788f('0x25')](function(_0x3084f3){return db['VoiceExtension']['bulkCreate'](createExtensionsReciveFax(_[_0x788f('0x75')](_0x55b7fb[_0x788f('0x61')],['tech',_0x788f('0x9d'),_0x788f('0x9e'),_0x788f('0x9f'),_0x788f('0xa0'),_0x788f('0xa1')])),{'transaction':_0x26b9e4});});});})['then'](function(){return db[_0x788f('0x42')][_0x788f('0xa2')](_0x55b7fb['body']['id']);})[_0x788f('0x25')](respondWithResult(_0x4d6e6a,null))[_0x788f('0x5c')](handleError(_0x4d6e6a,null));};exports['getMessages']=function(_0x50117a,_0x5afb7a,_0x31fb2e){var _0x364728={'raw':!![],'where':{}};var _0x478f8c={};var _0x49bcc6={'count':0x0,'rows':[]};return db[_0x788f('0x42')][_0x788f('0x6d')]({'where':{'id':_0x50117a[_0x788f('0x5d')]['id']}})[_0x788f('0x25')](handleEntityNotFound(_0x5afb7a,null))[_0x788f('0x25')](function(_0x1935e9){if(_0x1935e9){_0x478f8c[_0x788f('0x46')]=_['keys'](db[_0x788f('0xa3')][_0x788f('0x43')]);_0x478f8c[_0x788f('0x49')]=_[_0x788f('0x48')](_0x50117a['query']);_0x478f8c[_0x788f('0x4a')]=_[_0x788f('0x4b')](_0x478f8c['model'],_0x478f8c[_0x788f('0x49')]);_0x364728[_0x788f('0x4c')]=_['intersection'](_0x478f8c[_0x788f('0x46')],qs[_0x788f('0x4d')](_0x50117a[_0x788f('0x49')][_0x788f('0x4d')]));_0x364728[_0x788f('0x4c')]=_0x364728[_0x788f('0x4c')]['length']?_0x364728[_0x788f('0x4c')]:_0x478f8c[_0x788f('0x46')];if(!_0x50117a['query'][_0x788f('0x4f')](_0x788f('0x50'))){_0x364728[_0x788f('0x31')]=qs[_0x788f('0x31')](_0x50117a[_0x788f('0x49')][_0x788f('0x31')]);_0x364728['offset']=qs[_0x788f('0x32')](_0x50117a[_0x788f('0x49')][_0x788f('0x32')]);}_0x364728[_0x788f('0x51')]=qs['sort'](_0x50117a['query']['sort']);_0x364728[_0x788f('0x53')]=qs[_0x788f('0x4a')](_['pick'](_0x50117a[_0x788f('0x49')],_0x478f8c[_0x788f('0x4a')]));_0x364728[_0x788f('0x53')][_0x788f('0x6a')]=_0x1935e9['id'];if(_0x50117a[_0x788f('0x49')][_0x788f('0x56')]){_0x364728[_0x788f('0x53')]=_['merge'](_0x364728['where'],{'$or':_['map'](_0x364728[_0x788f('0x4c')],function(_0x5a0945){var _0x3a3274={};_0x3a3274[_0x5a0945]={'$like':'%'+_0x50117a['query'][_0x788f('0x56')]+'%'};return _0x3a3274;})});}if(_0x50117a[_0x788f('0x49')][_0x788f('0xa4')]){var _0x58ed0d=_0x50117a[_0x788f('0x49')]['$gte']['split'](',');var _0x2175cc={};_0x2175cc[_0x58ed0d[0x0]]={'$gte':moment(_0x58ed0d[0x1])[_0x788f('0xa5')](_0x788f('0xa6'))};_0x364728[_0x788f('0x53')]=_[_0x788f('0x5e')](_0x364728[_0x788f('0x53')],_0x2175cc);}_0x364728=_[_0x788f('0x5e')]({},_0x364728,_0x50117a[_0x788f('0x57')]);return db[_0x788f('0xa3')][_0x788f('0x58')]({'where':_0x364728['where']})[_0x788f('0x25')](function(_0x39da4f){_0x49bcc6[_0x788f('0x58')]=_0x39da4f;if(_0x50117a[_0x788f('0x49')][_0x788f('0x6e')]){_0x364728[_0x788f('0x59')]=[{'all':!![]}];}return db[_0x788f('0xa3')][_0x788f('0x5a')](_0x364728);})[_0x788f('0x25')](function(_0x405488){_0x49bcc6[_0x788f('0x5b')]=_0x405488;return _0x49bcc6;});}})[_0x788f('0x25')](respondWithFilteredResult(_0x5afb7a,_0x364728))[_0x788f('0x5c')](handleError(_0x5afb7a,null));};exports[_0x788f('0x3e')]=function(_0x5c16b4,_0x3d21da,_0x3d51ba){var _0x34a065,_0x3c8550={},_0x302357;if(_0x5c16b4[_0x788f('0x61')]['to']){_0x302357=_0x5c16b4[_0x788f('0x61')]['to'][0x0];}return db[_0x788f('0x42')][_0x788f('0x5f')]({'where':{'id':_0x5c16b4[_0x788f('0x5d')]['id']},'include':[{'model':db[_0x788f('0xa7')],'as':_0x788f('0xa8'),'include':[{'model':db['CmContact'],'as':_0x788f('0xa9'),'where':{'fax':_0x302357},'limit':0x1,'order':[[_0x788f('0x9f'),_0x788f('0xaa')]]}]}]})[_0x788f('0x25')](handleEntityNotFound(_0x3d21da,null))['then'](function(_0x5ac556){_0x34a065=_0x5ac556;if(_0x5c16b4[_0x788f('0x61')]['attachments']&&_0x5c16b4[_0x788f('0x61')][_0x788f('0xab')][_0x788f('0x4e')]){for(var _0x23bafe=0x0;_0x23bafe<_0x5c16b4[_0x788f('0x61')][_0x788f('0xab')][_0x788f('0x4e')];_0x23bafe+=0x1){_0x5c16b4[_0x788f('0x61')][_0x788f('0xab')][_0x23bafe]={'filename':_0x5c16b4['body'][_0x788f('0xab')][_0x23bafe][_0x788f('0x3d')],'id':_0x5c16b4[_0x788f('0x61')][_0x788f('0xab')][_0x23bafe]['id'],'path':path[_0x788f('0xac')](config['root'],_0x788f('0xad'),_0x5c16b4[_0x788f('0x61')][_0x788f('0xab')][_0x23bafe]['basename'])};}}return respondWithRpcPromise('CheckAfterSend',_0x788f('0xae'),{'FaxAccountId':_[_0x788f('0xaf')](_0x5c16b4['params']['id'])?undefined:_0x5c16b4[_0x788f('0x5d')]['id'],'path':_[_0x788f('0xaf')](_0x5c16b4[_0x788f('0x61')]['attachments'][0x0][_0x788f('0x8')])?undefined:_0x5c16b4[_0x788f('0x61')][_0x788f('0xab')][0x0][_0x788f('0x8')],'fax':_[_0x788f('0xaf')](_0x5c16b4[_0x788f('0x61')]['to'][0x0])?undefined:_0x5c16b4['body']['to'][0x0]},client9002);})[_0x788f('0x25')](function(){if(_0x34a065){if(_[_0x788f('0xaf')](_0x5c16b4[_0x788f('0x61')][_0x788f('0xb0')])){_0x5c16b4[_0x788f('0x61')]['from']=util['format']('\x22%s\x22\x20<%s>',_0x34a065[_0x788f('0x3d')],_0x34a065[_0x788f('0xb1')]);}if(_0x34a065[_0x788f('0xa8')]){if(_0x34a065[_0x788f('0xa8')][_0x788f('0xa9')][_0x788f('0x4e')]){return _0x34a065[_0x788f('0xa8')][_0x788f('0xa9')][0x0];}else{return db[_0x788f('0xb2')][_0x788f('0x60')](_['defaults'](_0x5c16b4[_0x788f('0x61')],{'firstName':_0x5c16b4[_0x788f('0x61')]['to'][0x0],'phone':_0x5c16b4[_0x788f('0x61')]['to'][0x0],'fax':_0x5c16b4['body']['to'][0x0],'ListId':_0x34a065[_0x788f('0xa1')]}));}}else{throw new Error(_0x788f('0xb3'));}}else{throw new Error(_0x788f('0xb4'));}})[_0x788f('0x25')](function(_0x386c89){if(_0x386c89){return db[_0x788f('0x74')][_0x788f('0x5f')]({'where':{'ContactId':_0x386c89['id'],'closed':![],'FaxAccountId':_0x34a065['id']}})[_0x788f('0x25')](function(_0x316566){if(_0x316566){return[_0x316566,![]];}return db[_0x788f('0x74')]['create']({'UserId':_0x5c16b4['user']['id'],'ContactId':_0x386c89['id'],'FaxAccountId':_0x34a065['id'],'fax':_0x5c16b4[_0x788f('0x61')]['to'][0x0],'firstMsgDirection':'out','Messages':[_['merge'](_0x5c16b4[_0x788f('0x61')],{'read':![],'body':_0x5c16b4[_0x788f('0x61')][_0x788f('0xab')][0x0]['filename'],'FaxAccountId':_0x34a065['id'],'UserId':_0x5c16b4[_0x788f('0x62')]['id'],'ContactId':_0x386c89['id'],'AttachmentId':_0x5c16b4[_0x788f('0x61')]['attachments'][0x0]['id']})]},{'include':[{'model':db[_0x788f('0xa3')],'as':_0x788f('0xb5')}]})[_0x788f('0x25')](function(_0x16381d){return[_0x16381d,!![]];});});}else{throw new Error(_0x788f('0xb6'));}})[_0x788f('0xb7')](function(_0x33c691,_0x33e48b){if(_0x33e48b){return _0x33c691;}return db['FaxMessage'][_0x788f('0x60')]({'direction':_0x788f('0xb8'),'read':![],'body':_0x5c16b4[_0x788f('0x61')][_0x788f('0xab')][0x0][_0x788f('0xb9')],'FaxAccountId':_0x34a065['id'],'FaxInteractionId':_0x33c691['id'],'UserId':_0x5c16b4[_0x788f('0x62')]['id'],'ContactId':_0x33c691[_0x788f('0xba')],'AttachmentId':_0x5c16b4[_0x788f('0x61')]['attachments'][0x0]['id']})[_0x788f('0x25')](function(_0xb4fb5){_0x33c691[_0x788f('0xbb')][_0x788f('0xb5')]=[];_0x33c691[_0x788f('0xbb')][_0x788f('0xb5')][_0x788f('0x95')](_0xb4fb5[_0x788f('0xbb')]);return _0x33c691;});})[_0x788f('0x25')](function(_0x5a45e2){respondWithRpcPromise('SendFax',_0x788f('0xbc'),{'FaxAccountId':_[_0x788f('0xaf')](_0x5c16b4[_0x788f('0x5d')]['id'])?undefined:_0x5c16b4['params']['id'],'path':_[_0x788f('0xaf')](_0x5c16b4[_0x788f('0x61')][_0x788f('0xab')][0x0]['path'])?undefined:_0x5c16b4[_0x788f('0x61')]['attachments'][0x0]['path'],'fax':_['isNil'](_0x5c16b4[_0x788f('0x61')]['to'][0x0])?undefined:_0x5c16b4[_0x788f('0x61')]['to'][0x0],'AttachmentId':_0x5c16b4[_0x788f('0x61')]['attachments'][0x0]['id']},client9002)['then'](function(_0x3879ba){logger[_0x788f('0x26')](_0x788f('0xbd'),_0x3879ba);})['catch'](function(_0x591b7e){logger['info'](_0x788f('0xbd'),_0x591b7e);});return _0x5a45e2;})[_0x788f('0x25')](respondWithResult(_0x3d21da,null))[_0x788f('0x5c')](handleError(_0x3d21da,null));};exports[_0x788f('0xbe')]=function(_0x4f59d7,_0x16d957,_0x5516c7){return db['FaxAccount']['find']({'where':{'id':_0x4f59d7[_0x788f('0x5d')]['id']}})[_0x788f('0x25')](handleEntityNotFound(_0x16d957,null))[_0x788f('0x25')](function(_0x478b2d){if(_0x478b2d){return _0x478b2d[_0x788f('0xbe')](_0x4f59d7['body'][_0x788f('0x6f')],_[_0x788f('0x75')](_0x4f59d7['body'],['ids','id'])||{})[_0x788f('0xb7')](function(_0x598b69){for(var _0x44a260=0x0;_0x44a260<_0x4f59d7[_0x788f('0x61')][_0x788f('0x6f')]['length'];_0x44a260+=0x1){socket['emit']('userFaxAccount:save',{'UserId':Number(_0x4f59d7[_0x788f('0x61')]['ids'][_0x44a260]),'FaxAccountId':Number(_0x4f59d7['params']['id'])});}return _0x598b69;});}})[_0x788f('0x25')](respondWithResult(_0x16d957,null))[_0x788f('0x5c')](handleError(_0x16d957,null));};exports[_0x788f('0xbf')]=function(_0x54cf7b,_0x350484,_0x4d72b4){return db[_0x788f('0x42')][_0x788f('0x5f')]({'where':{'id':_0x54cf7b[_0x788f('0x5d')]['id']}})[_0x788f('0x25')](handleEntityNotFound(_0x350484,null))[_0x788f('0x25')](function(_0x21f9e8){if(_0x21f9e8){return _0x21f9e8[_0x788f('0xbf')](_0x54cf7b[_0x788f('0x49')][_0x788f('0x6f')])['then'](function(){if(_['isArray'](_0x54cf7b[_0x788f('0x49')][_0x788f('0x6f')])){for(var _0x39d5a8=0x0;_0x39d5a8<_0x54cf7b['query'][_0x788f('0x6f')]['length'];_0x39d5a8+=0x1){socket['emit'](_0x788f('0xc0'),{'UserId':Number(_0x54cf7b[_0x788f('0x49')][_0x788f('0x6f')][_0x39d5a8]),'FaxAccountId':Number(_0x54cf7b[_0x788f('0x5d')]['id'])});}}else{socket[_0x788f('0xc1')]('userFaxAccount:remove',{'UserId':Number(_0x54cf7b[_0x788f('0x49')]['ids']),'FaxAccountId':Number(_0x54cf7b[_0x788f('0x5d')]['id'])});}});}})[_0x788f('0x25')](respondWithStatusCode(_0x350484,null))['catch'](handleError(_0x350484,null));};exports['getAgents']=function(_0x21ccbf,_0xc4b0a5,_0xf27a72){var _0x34a847={};var _0x2533ba={};var _0x309b4c;var _0x1121b6;return db[_0x788f('0x42')]['findOne']({'where':{'id':_0x21ccbf['params']['id']}})['then'](handleEntityNotFound(_0xc4b0a5,null))['then'](function(_0x38dbe0){if(_0x38dbe0){_0x309b4c=_0x38dbe0;_0x2533ba[_0x788f('0x46')]=_[_0x788f('0x48')](db['User']['rawAttributes']);_0x2533ba[_0x788f('0x49')]=_['keys'](_0x21ccbf[_0x788f('0x49')]);_0x2533ba[_0x788f('0x4a')]=_[_0x788f('0x4b')](_0x2533ba[_0x788f('0x46')],_0x2533ba[_0x788f('0x49')]);_0x34a847['attributes']=_['intersection'](_0x2533ba[_0x788f('0x46')],qs['fields'](_0x21ccbf[_0x788f('0x49')][_0x788f('0x4d')]));_0x34a847['attributes']=_0x34a847['attributes'][_0x788f('0x4e')]?_0x34a847['attributes']:_0x2533ba[_0x788f('0x46')];_0x34a847['order']=qs[_0x788f('0x52')](_0x21ccbf[_0x788f('0x49')][_0x788f('0x52')]);_0x34a847[_0x788f('0x53')]=qs[_0x788f('0x4a')](_['pick'](_0x21ccbf[_0x788f('0x49')],_0x2533ba[_0x788f('0x4a')]));if(_0x21ccbf[_0x788f('0x49')][_0x788f('0x56')]){_0x34a847[_0x788f('0x53')]=_[_0x788f('0x5e')](_0x34a847[_0x788f('0x53')],{'$or':_[_0x788f('0x47')](_0x34a847[_0x788f('0x4c')],function(_0x11e3c5){var _0x390d52={};_0x390d52[_0x11e3c5]={'$like':'%'+_0x21ccbf[_0x788f('0x49')][_0x788f('0x56')]+'%'};return _0x390d52;})});}_0x34a847=_[_0x788f('0x5e')]({},_0x34a847,_0x21ccbf[_0x788f('0x57')]);return _0x309b4c[_0x788f('0xc2')](_0x34a847);}})['then'](function(_0x6c9ae5){if(_0x6c9ae5){_0x1121b6=_0x6c9ae5['length'];if(!_0x21ccbf[_0x788f('0x49')][_0x788f('0x4f')]('nolimit')){_0x34a847['limit']=qs['limit'](_0x21ccbf['query'][_0x788f('0x31')]);_0x34a847[_0x788f('0x32')]=qs[_0x788f('0x32')](_0x21ccbf['query'][_0x788f('0x32')]);}return _0x309b4c[_0x788f('0xc2')](_0x34a847);}})[_0x788f('0x25')](function(_0x336b0e){if(_0x336b0e){return _0x336b0e?{'count':_0x1121b6,'rows':_0x336b0e}:null;}})[_0x788f('0x25')](respondWithResult(_0xc4b0a5,null))[_0x788f('0x5c')](handleError(_0xc4b0a5,null));};