Built motion from commit (unavailable).|2.5.15
[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 _0xfd7b=['attributes','fields','length','nolimit','order','sort','pick','filter','merge','where','VIRTUAL','options','includeAll','rows','show','params','keys','include','find','create','body','FaxAccounts','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','getDispositions','findOne','Disposition','hasOwnProperty','FaxAccountId','findAll','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','addInteraction','FaxInteraction','CmContact','Contact','User','Owner','fullname','internal','Tag','Tags','color','tag','addApplications','transaction','priority','getApplications','exten','system','description','appdata','push','Answer','CDR(type)=inbound-fax','Set','ecm','gateway','faxdetect','headerinfo','maxrate','minrate','FAXOPT(','/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','ReceiveFax','addAccountApplications','sequelize','bulkCreate','VoiceExtension','omit','TrunkId','ListId','findById','getMessages','FaxMessage','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','CmList','Contacts','updatedAt','attachments','join','root','basename','CheckAfterSend','isNil','\x22%s\x22\x20<%s>','List','Send\x20Fax\x20failed','user','out','filename','Messages','Contact\x20not\x20found','spread','dataValues','SendFax','SendFaxRpc,\x20%s','addAgents','emit','userFaxAccount:save','removeAgents','isArray','userFaxAccount:remove','getAgents','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','squel','jsforce','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','defaults','localhost','./faxAccount.socket','register','jayson/promise','client','request','then','FaxAccount,\x20%s,\x20%s','request\x20sent','error','message','info','catch','sendStatus','status','end','json','count','offset','limit','set','apply','save','update','destroy','get','UserProfileResource','stack','name','Pause','mandatoryDispositionPause','FaxAccount','rawAttributes','fieldName','type','key','model','map','query','filters','intersection'];(function(_0x35d06e,_0x2e3503){var _0x9e9053=function(_0x1546d3){while(--_0x1546d3){_0x35d06e['push'](_0x35d06e['shift']());}};_0x9e9053(++_0x2e3503);}(_0xfd7b,0x1df));var _0xbfd7=function(_0x2bc3f4,_0x470b26){_0x2bc3f4=_0x2bc3f4-0x0;var _0x14ac53=_0xfd7b[_0x2bc3f4];return _0x14ac53;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xbfd7('0x0'));var rimraf=require(_0xbfd7('0x1'));var zipdir=require(_0xbfd7('0x2'));var jsonpatch=require(_0xbfd7('0x3'));var rp=require(_0xbfd7('0x4'));var moment=require(_0xbfd7('0x5'));var BPromise=require(_0xbfd7('0x6'));var Mustache=require(_0xbfd7('0x7'));var util=require(_0xbfd7('0x8'));var path=require(_0xbfd7('0x9'));var sox=require(_0xbfd7('0xa'));var csv=require(_0xbfd7('0xb'));var ejs=require(_0xbfd7('0xc'));var fs=require('fs');var _=require('lodash');var squel=require(_0xbfd7('0xd'));var crypto=require('crypto');var jsforce=require(_0xbfd7('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xbfd7('0xb'));var querystring=require(_0xbfd7('0xf'));var Papa=require(_0xbfd7('0x10'));var Redis=require(_0xbfd7('0x11'));var authService=require('../../components/auth/service');var qs=require(_0xbfd7('0x12'));var as=require(_0xbfd7('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xbfd7('0x14'));var utils=require(_0xbfd7('0x15'));var config=require(_0xbfd7('0x16'));var licenseUtil=require(_0xbfd7('0x17'));var db=require(_0xbfd7('0x18'))['db'];config['redis']=_[_0xbfd7('0x19')](config['redis'],{'host':_0xbfd7('0x1a'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0xbfd7('0x1b'))[_0xbfd7('0x1c')](socket);var jayson=require(_0xbfd7('0x1d'));var client=jayson[_0xbfd7('0x1e')]['http']({'port':0x232c});var client9002=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x37e777,_0x115a34,_0x33d900,_0x3e8754){return new BPromise(function(_0x30c721,_0x4609f2){var _0x137d50=_0x3e8754||client;return _0x137d50[_0xbfd7('0x1f')](_0x37e777,_0x33d900)[_0xbfd7('0x20')](function(_0x514248){logger['info'](_0xbfd7('0x21'),_0x115a34,_0xbfd7('0x22'));logger['debug']('FaxAccount,\x20%s,\x20%s,\x20%s',_0x115a34,_0xbfd7('0x22'),JSON['stringify'](_0x514248));if(_0x514248['error']){if(_0x514248[_0xbfd7('0x23')]['code']===0x1f4){logger[_0xbfd7('0x23')](_0xbfd7('0x21'),_0x115a34,_0x514248[_0xbfd7('0x23')][_0xbfd7('0x24')]);return _0x4609f2(_0x514248['error'][_0xbfd7('0x24')]);}logger[_0xbfd7('0x23')](_0xbfd7('0x21'),_0x115a34,_0x514248[_0xbfd7('0x23')][_0xbfd7('0x24')]);return _0x30c721(_0x514248[_0xbfd7('0x23')]['message']);}else{logger[_0xbfd7('0x25')](_0xbfd7('0x21'),_0x115a34,_0xbfd7('0x22'));_0x30c721(_0x514248['result'][_0xbfd7('0x24')]);}})[_0xbfd7('0x26')](function(_0x18dd74){logger[_0xbfd7('0x23')](_0xbfd7('0x21'),_0x115a34,_0x18dd74);_0x4609f2(_0x18dd74);});});}function respondWithStatusCode(_0x585e60,_0x2a7749){_0x2a7749=_0x2a7749||0xcc;return function(_0x6ef5aa){if(_0x6ef5aa){return _0x585e60[_0xbfd7('0x27')](_0x2a7749);}return _0x585e60[_0xbfd7('0x28')](_0x2a7749)[_0xbfd7('0x29')]();};}function respondWithResult(_0x303060,_0x378428){_0x378428=_0x378428||0xc8;return function(_0x55b2c8){if(_0x55b2c8){return _0x303060[_0xbfd7('0x28')](_0x378428)[_0xbfd7('0x2a')](_0x55b2c8);}};}function respondWithFilteredResult(_0x4d7ef4,_0x2971ea){return function(_0x33583b){if(_0x33583b){var _0x2ec4a5=_0x33583b[_0xbfd7('0x2b')],_0x14c55d=_0x2971ea[_0xbfd7('0x2c')],_0x510506=_0x2971ea['offset']+_0x2971ea[_0xbfd7('0x2d')],_0x3bb808;if(_0x510506>=_0x2ec4a5){_0x510506=_0x2ec4a5;_0x3bb808=0xc8;}else{_0x3bb808=0xce;}_0x4d7ef4['status'](_0x3bb808);return _0x4d7ef4[_0xbfd7('0x2e')]('Content-Range',_0x14c55d+'-'+_0x510506+'/'+_0x2ec4a5)[_0xbfd7('0x2a')](_0x33583b);}return null;};}function patchUpdates(_0x1804a5){return function(_0x532c5f){try{jsonpatch[_0xbfd7('0x2f')](_0x532c5f,_0x1804a5,!![]);}catch(_0xde0053){return BPromise['reject'](_0xde0053);}return _0x532c5f[_0xbfd7('0x30')]();};}function saveUpdates(_0x40fef6,_0x990abe){return function(_0x5d08fe){if(_0x5d08fe){return _0x5d08fe[_0xbfd7('0x31')](_0x40fef6)[_0xbfd7('0x20')](function(_0x267b31){return _0x267b31;});}return null;};}function removeEntity(_0x2a9361,_0x20fc00){return function(_0x3af799){if(_0x3af799){return _0x3af799[_0xbfd7('0x32')]()[_0xbfd7('0x20')](function(){var _0x418994=_0x3af799[_0xbfd7('0x33')]({'plain':!![]});var _0x26802b='FaxAccounts';return db[_0xbfd7('0x34')]['destroy']({'where':{'type':_0x26802b,'resourceId':_0x418994['id']}})['then'](function(){return _0x3af799;});})[_0xbfd7('0x20')](function(){_0x2a9361[_0xbfd7('0x28')](0xcc)[_0xbfd7('0x29')]();});}};}function handleEntityNotFound(_0x6d440c,_0xc51f8b){return function(_0x403bf5){if(!_0x403bf5){_0x6d440c[_0xbfd7('0x27')](0x194);}return _0x403bf5;};}function handleError(_0x373c4a,_0x5d4928){_0x5d4928=_0x5d4928||0x1f4;return function(_0x4b275e){logger[_0xbfd7('0x23')](_0x4b275e[_0xbfd7('0x35')]);if(_0x4b275e['name']){delete _0x4b275e[_0xbfd7('0x36')];}_0x373c4a[_0xbfd7('0x28')](_0x5d4928)['send'](_0x4b275e);};}exports['index']=function(_0x6ec28c,_0x2391b6){var _0x51fce9={'include':[{'model':db[_0xbfd7('0x37')],'as':_0xbfd7('0x38')}]},_0x1d54da={},_0xfee712={'count':0x0,'rows':[]};var _0x68f13=_['map'](db[_0xbfd7('0x39')][_0xbfd7('0x3a')],function(_0x530210){return{'name':_0x530210[_0xbfd7('0x3b')],'type':_0x530210[_0xbfd7('0x3c')][_0xbfd7('0x3d')]};});_0x1d54da[_0xbfd7('0x3e')]=_[_0xbfd7('0x3f')](_0x68f13,'name');_0x1d54da[_0xbfd7('0x40')]=_['keys'](_0x6ec28c['query']);_0x1d54da[_0xbfd7('0x41')]=_[_0xbfd7('0x42')](_0x1d54da[_0xbfd7('0x3e')],_0x1d54da[_0xbfd7('0x40')]);_0x51fce9[_0xbfd7('0x43')]=_[_0xbfd7('0x42')](_0x1d54da['model'],qs[_0xbfd7('0x44')](_0x6ec28c['query'][_0xbfd7('0x44')]));_0x51fce9[_0xbfd7('0x43')]=_0x51fce9[_0xbfd7('0x43')][_0xbfd7('0x45')]?_0x51fce9[_0xbfd7('0x43')]:_0x1d54da[_0xbfd7('0x3e')];if(!_0x6ec28c[_0xbfd7('0x40')]['hasOwnProperty'](_0xbfd7('0x46'))){_0x51fce9[_0xbfd7('0x2d')]=qs[_0xbfd7('0x2d')](_0x6ec28c[_0xbfd7('0x40')][_0xbfd7('0x2d')]);_0x51fce9[_0xbfd7('0x2c')]=qs[_0xbfd7('0x2c')](_0x6ec28c['query'][_0xbfd7('0x2c')]);}_0x51fce9[_0xbfd7('0x47')]=qs[_0xbfd7('0x48')](_0x6ec28c['query']['sort']);_0x51fce9['where']=qs[_0xbfd7('0x41')](_[_0xbfd7('0x49')](_0x6ec28c[_0xbfd7('0x40')],_0x1d54da[_0xbfd7('0x41')]),_0x68f13);if(_0x6ec28c['query'][_0xbfd7('0x4a')]){_0x51fce9['where']=_[_0xbfd7('0x4b')](_0x51fce9[_0xbfd7('0x4c')],{'$or':_['map'](_0x68f13,function(_0x4137aa){if(_0x4137aa['type']!==_0xbfd7('0x4d')){var _0x2e3e1c={};_0x2e3e1c[_0x4137aa[_0xbfd7('0x36')]]={'$like':'%'+_0x6ec28c['query']['filter']+'%'};return _0x2e3e1c;}})});}_0x51fce9=_[_0xbfd7('0x4b')]({},_0x51fce9,_0x6ec28c[_0xbfd7('0x4e')]);var _0x4d700e={'where':_0x51fce9['where']};return db[_0xbfd7('0x39')][_0xbfd7('0x2b')](_0x4d700e)[_0xbfd7('0x20')](function(_0x9279a1){_0xfee712[_0xbfd7('0x2b')]=_0x9279a1;if(_0x6ec28c[_0xbfd7('0x40')][_0xbfd7('0x4f')]){_0x51fce9['include']=[{'all':!![]}];}return db['FaxAccount']['findAll'](_0x51fce9);})[_0xbfd7('0x20')](function(_0x20bd15){_0xfee712[_0xbfd7('0x50')]=_0x20bd15;return _0xfee712;})['then'](respondWithFilteredResult(_0x2391b6,_0x51fce9))[_0xbfd7('0x26')](handleError(_0x2391b6,null));};exports[_0xbfd7('0x51')]=function(_0x4ae9f9,_0x4a7a72){var _0xc89535={'raw':![],'where':{'id':_0x4ae9f9[_0xbfd7('0x52')]['id']},'include':[{'model':db['Pause'],'as':_0xbfd7('0x38')}]},_0x7443a1={};_0x7443a1[_0xbfd7('0x3e')]=_[_0xbfd7('0x53')](db['FaxAccount'][_0xbfd7('0x3a')]);_0x7443a1[_0xbfd7('0x40')]=_[_0xbfd7('0x53')](_0x4ae9f9[_0xbfd7('0x40')]);_0x7443a1['filters']=_[_0xbfd7('0x42')](_0x7443a1[_0xbfd7('0x3e')],_0x7443a1[_0xbfd7('0x40')]);_0xc89535['attributes']=_[_0xbfd7('0x42')](_0x7443a1['model'],qs[_0xbfd7('0x44')](_0x4ae9f9[_0xbfd7('0x40')][_0xbfd7('0x44')]));_0xc89535[_0xbfd7('0x43')]=_0xc89535['attributes'][_0xbfd7('0x45')]?_0xc89535[_0xbfd7('0x43')]:_0x7443a1[_0xbfd7('0x3e')];if(_0x4ae9f9[_0xbfd7('0x40')][_0xbfd7('0x4f')]){_0xc89535[_0xbfd7('0x54')]=[{'all':!![]}];}_0xc89535=_[_0xbfd7('0x4b')]({},_0xc89535,_0x4ae9f9[_0xbfd7('0x4e')]);return db[_0xbfd7('0x39')][_0xbfd7('0x55')](_0xc89535)[_0xbfd7('0x20')](handleEntityNotFound(_0x4a7a72,null))[_0xbfd7('0x20')](respondWithResult(_0x4a7a72,null))[_0xbfd7('0x26')](handleError(_0x4a7a72,null));};exports[_0xbfd7('0x56')]=function(_0x5ad6c8,_0x5a49e7){return db[_0xbfd7('0x39')][_0xbfd7('0x56')](_0x5ad6c8[_0xbfd7('0x57')],{})[_0xbfd7('0x20')](function(_0x3142ba){var _0x3245d8=_0x5ad6c8['user'][_0xbfd7('0x33')]({'plain':!![]});if(!_0x3245d8)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x3245d8['role']==='user'){var _0x2ce454=_0x3142ba[_0xbfd7('0x33')]({'plain':!![]});var _0x5e47c2=_0xbfd7('0x58');return db[_0xbfd7('0x59')][_0xbfd7('0x55')]({'where':{'name':_0x5e47c2,'userProfileId':_0x3245d8[_0xbfd7('0x5a')]},'raw':!![]})[_0xbfd7('0x20')](function(_0x450989){if(_0x450989&&_0x450989[_0xbfd7('0x5b')]===0x0){return db[_0xbfd7('0x34')][_0xbfd7('0x56')]({'name':_0x2ce454['name'],'resourceId':_0x2ce454['id'],'type':_0x450989[_0xbfd7('0x36')],'sectionId':_0x450989['id']},{})[_0xbfd7('0x20')](function(){return _0x3142ba;});}else{return _0x3142ba;}})[_0xbfd7('0x26')](function(_0x531f97){logger['error'](_0xbfd7('0x5c'),_0x531f97);throw _0x531f97;});}return _0x3142ba;})[_0xbfd7('0x20')](respondWithResult(_0x5a49e7,0xc9))[_0xbfd7('0x26')](handleError(_0x5a49e7,null));};exports[_0xbfd7('0x31')]=function(_0x508a8a,_0x41d54c){if(_0x508a8a[_0xbfd7('0x57')]['id']){delete _0x508a8a[_0xbfd7('0x57')]['id'];}return db[_0xbfd7('0x39')][_0xbfd7('0x55')]({'where':{'id':_0x508a8a[_0xbfd7('0x52')]['id']},'include':[{'model':db[_0xbfd7('0x37')],'as':_0xbfd7('0x38')}]})[_0xbfd7('0x20')](handleEntityNotFound(_0x41d54c,null))[_0xbfd7('0x20')](saveUpdates(_0x508a8a[_0xbfd7('0x57')],null))[_0xbfd7('0x20')](respondWithResult(_0x41d54c,null))[_0xbfd7('0x26')](handleError(_0x41d54c,null));};exports['destroy']=function(_0x383241,_0xed99c4){return db[_0xbfd7('0x39')]['find']({'where':{'id':_0x383241[_0xbfd7('0x52')]['id']}})[_0xbfd7('0x20')](handleEntityNotFound(_0xed99c4,null))[_0xbfd7('0x20')](removeEntity(_0xed99c4,null))[_0xbfd7('0x26')](handleError(_0xed99c4,null));};exports[_0xbfd7('0x5d')]=function(_0x569612,_0x3196a7){return db[_0xbfd7('0x39')][_0xbfd7('0x5d')]()[_0xbfd7('0x20')](respondWithResult(_0x3196a7,null))[_0xbfd7('0x26')](handleError(_0x3196a7,null));};exports[_0xbfd7('0x5e')]=function(_0x35b346,_0x476731,_0x460bc7){if(_0x35b346[_0xbfd7('0x57')]['id']){delete _0x35b346[_0xbfd7('0x57')]['id'];}return db[_0xbfd7('0x39')]['find']({'where':{'id':_0x35b346['params']['id']}})[_0xbfd7('0x20')](handleEntityNotFound(_0x476731,null))[_0xbfd7('0x20')](function(_0x13ce36){if(_0x13ce36){_0x35b346[_0xbfd7('0x57')]['FaxAccountId']=_0x13ce36['id'];return db['Disposition'][_0xbfd7('0x56')](_0x35b346[_0xbfd7('0x57')]);}})['then'](respondWithResult(_0x476731,null))[_0xbfd7('0x26')](handleError(_0x476731,null));};exports[_0xbfd7('0x5f')]=function(_0x4c1670,_0x3ca88c,_0x29c568){var _0x11cf3b={'raw':![],'where':{}};var _0x5ad203={};var _0x93f60={'count':0x0,'rows':[]};return db['FaxAccount'][_0xbfd7('0x60')]({'where':{'id':_0x4c1670[_0xbfd7('0x52')]['id']}})[_0xbfd7('0x20')](handleEntityNotFound(_0x3ca88c,null))[_0xbfd7('0x20')](function(_0x320cbf){if(_0x320cbf){_0x5ad203[_0xbfd7('0x3e')]=_[_0xbfd7('0x53')](db[_0xbfd7('0x61')][_0xbfd7('0x3a')]);_0x5ad203['query']=_[_0xbfd7('0x53')](_0x4c1670[_0xbfd7('0x40')]);_0x5ad203[_0xbfd7('0x41')]=_[_0xbfd7('0x42')](_0x5ad203[_0xbfd7('0x3e')],_0x5ad203[_0xbfd7('0x40')]);_0x11cf3b[_0xbfd7('0x43')]=_[_0xbfd7('0x42')](_0x5ad203['model'],qs[_0xbfd7('0x44')](_0x4c1670[_0xbfd7('0x40')]['fields']));_0x11cf3b['attributes']=_0x11cf3b[_0xbfd7('0x43')][_0xbfd7('0x45')]?_0x11cf3b[_0xbfd7('0x43')]:_0x5ad203[_0xbfd7('0x3e')];if(!_0x4c1670[_0xbfd7('0x40')][_0xbfd7('0x62')](_0xbfd7('0x46'))){_0x11cf3b[_0xbfd7('0x2d')]=qs['limit'](_0x4c1670[_0xbfd7('0x40')][_0xbfd7('0x2d')]);_0x11cf3b[_0xbfd7('0x2c')]=qs[_0xbfd7('0x2c')](_0x4c1670[_0xbfd7('0x40')]['offset']);}_0x11cf3b[_0xbfd7('0x47')]=qs['sort'](_0x4c1670['query'][_0xbfd7('0x48')]);_0x11cf3b[_0xbfd7('0x4c')]=qs[_0xbfd7('0x41')](_[_0xbfd7('0x49')](_0x4c1670['query'],_0x5ad203[_0xbfd7('0x41')]));_0x11cf3b[_0xbfd7('0x4c')][_0xbfd7('0x63')]=_0x320cbf['id'];if(_0x4c1670[_0xbfd7('0x40')][_0xbfd7('0x4a')]){_0x11cf3b[_0xbfd7('0x4c')]=_[_0xbfd7('0x4b')](_0x11cf3b[_0xbfd7('0x4c')],{'$or':_[_0xbfd7('0x3f')](_0x11cf3b['attributes'],function(_0x4b3891){var _0x2635a6={};_0x2635a6[_0x4b3891]={'$like':'%'+_0x4c1670[_0xbfd7('0x40')]['filter']+'%'};return _0x2635a6;})});}_0x11cf3b=_[_0xbfd7('0x4b')]({},_0x11cf3b,_0x4c1670[_0xbfd7('0x4e')]);return db[_0xbfd7('0x61')][_0xbfd7('0x2b')]({'where':_0x11cf3b[_0xbfd7('0x4c')]})[_0xbfd7('0x20')](function(_0x11b905){_0x93f60[_0xbfd7('0x2b')]=_0x11b905;if(_0x4c1670[_0xbfd7('0x40')][_0xbfd7('0x4f')]){_0x11cf3b[_0xbfd7('0x54')]=[{'all':!![]}];}return db[_0xbfd7('0x61')][_0xbfd7('0x64')](_0x11cf3b);})['then'](function(_0x39ee78){_0x93f60[_0xbfd7('0x50')]=_0x39ee78;return _0x93f60;});}})[_0xbfd7('0x20')](respondWithFilteredResult(_0x3ca88c,_0x11cf3b))[_0xbfd7('0x26')](handleError(_0x3ca88c,null));};exports[_0xbfd7('0x65')]=function(_0x2520e2,_0x33fd18,_0x57233f){return db[_0xbfd7('0x39')][_0xbfd7('0x55')]({'where':{'id':_0x2520e2['params']['id']}})[_0xbfd7('0x20')](handleEntityNotFound(_0x33fd18,null))[_0xbfd7('0x20')](function(_0x2d3e38){if(_0x2d3e38){return _0x2d3e38['removeDispositions'](_0x2520e2[_0xbfd7('0x40')][_0xbfd7('0x66')]);}})[_0xbfd7('0x20')](respondWithStatusCode(_0x33fd18,null))['catch'](handleError(_0x33fd18,null));};exports[_0xbfd7('0x67')]=function(_0x378dd2,_0x23e9cb,_0x18f6b6){if(_0x378dd2[_0xbfd7('0x57')]['id']){delete _0x378dd2[_0xbfd7('0x57')]['id'];}return db['FaxAccount'][_0xbfd7('0x55')]({'where':{'id':_0x378dd2['params']['id']}})[_0xbfd7('0x20')](handleEntityNotFound(_0x23e9cb,null))[_0xbfd7('0x20')](function(_0x504f27){if(_0x504f27){_0x378dd2[_0xbfd7('0x57')][_0xbfd7('0x63')]=_0x504f27['id'];return db[_0xbfd7('0x68')][_0xbfd7('0x56')](_0x378dd2['body']);}})[_0xbfd7('0x20')](respondWithResult(_0x23e9cb,null))[_0xbfd7('0x26')](handleError(_0x23e9cb,null));};exports[_0xbfd7('0x69')]=function(_0x745d6f,_0x4d6980,_0xbd1ae7){var _0x58ee6e={'raw':![],'where':{}};var _0x90bcc5={};var _0x4df4f7={'count':0x0,'rows':[]};return db['FaxAccount']['findOne']({'where':{'id':_0x745d6f[_0xbfd7('0x52')]['id']}})['then'](handleEntityNotFound(_0x4d6980,null))[_0xbfd7('0x20')](function(_0x36441e){if(_0x36441e){_0x90bcc5[_0xbfd7('0x3e')]=_[_0xbfd7('0x53')](db[_0xbfd7('0x68')][_0xbfd7('0x3a')]);_0x90bcc5[_0xbfd7('0x40')]=_[_0xbfd7('0x53')](_0x745d6f[_0xbfd7('0x40')]);_0x90bcc5[_0xbfd7('0x41')]=_[_0xbfd7('0x42')](_0x90bcc5[_0xbfd7('0x3e')],_0x90bcc5[_0xbfd7('0x40')]);_0x58ee6e['attributes']=_['intersection'](_0x90bcc5[_0xbfd7('0x3e')],qs['fields'](_0x745d6f['query'][_0xbfd7('0x44')]));_0x58ee6e[_0xbfd7('0x43')]=_0x58ee6e['attributes'][_0xbfd7('0x45')]?_0x58ee6e[_0xbfd7('0x43')]:_0x90bcc5[_0xbfd7('0x3e')];if(!_0x745d6f[_0xbfd7('0x40')][_0xbfd7('0x62')](_0xbfd7('0x46'))){_0x58ee6e['limit']=qs['limit'](_0x745d6f[_0xbfd7('0x40')]['limit']);_0x58ee6e[_0xbfd7('0x2c')]=qs[_0xbfd7('0x2c')](_0x745d6f[_0xbfd7('0x40')]['offset']);}_0x58ee6e[_0xbfd7('0x47')]=qs[_0xbfd7('0x48')](_0x745d6f[_0xbfd7('0x40')]['sort']);_0x58ee6e[_0xbfd7('0x4c')]=qs['filters'](_[_0xbfd7('0x49')](_0x745d6f[_0xbfd7('0x40')],_0x90bcc5[_0xbfd7('0x41')]));_0x58ee6e[_0xbfd7('0x4c')][_0xbfd7('0x63')]=_0x36441e['id'];if(_0x745d6f['query'][_0xbfd7('0x4a')]){_0x58ee6e[_0xbfd7('0x4c')]=_['merge'](_0x58ee6e[_0xbfd7('0x4c')],{'$or':_[_0xbfd7('0x3f')](_0x58ee6e['attributes'],function(_0x8492fc){var _0x5d8a43={};_0x5d8a43[_0x8492fc]={'$like':'%'+_0x745d6f['query'][_0xbfd7('0x4a')]+'%'};return _0x5d8a43;})});}_0x58ee6e=_['merge']({},_0x58ee6e,_0x745d6f['options']);return db[_0xbfd7('0x68')][_0xbfd7('0x2b')]({'where':_0x58ee6e[_0xbfd7('0x4c')]})[_0xbfd7('0x20')](function(_0x37dfce){_0x4df4f7[_0xbfd7('0x2b')]=_0x37dfce;if(_0x745d6f[_0xbfd7('0x40')][_0xbfd7('0x4f')]){_0x58ee6e[_0xbfd7('0x54')]=[{'all':!![]}];}return db['CannedAnswer'][_0xbfd7('0x64')](_0x58ee6e);})['then'](function(_0x50f8bf){_0x4df4f7[_0xbfd7('0x50')]=_0x50f8bf;return _0x4df4f7;});}})[_0xbfd7('0x20')](respondWithFilteredResult(_0x4d6980,_0x58ee6e))['catch'](handleError(_0x4d6980,null));};exports[_0xbfd7('0x6a')]=function(_0x589a71,_0x5f1255,_0x5daba9){return db[_0xbfd7('0x39')][_0xbfd7('0x55')]({'where':{'id':_0x589a71['params']['id']}})[_0xbfd7('0x20')](handleEntityNotFound(_0x5f1255,null))[_0xbfd7('0x20')](function(_0x1bf04d){if(_0x1bf04d){return _0x1bf04d[_0xbfd7('0x6a')](_0x589a71[_0xbfd7('0x40')]['ids']);}})[_0xbfd7('0x20')](respondWithStatusCode(_0x5f1255,null))['catch'](handleError(_0x5f1255,null));};exports[_0xbfd7('0x6b')]=function(_0x41147f,_0x1cbe56,_0x32c787){return db[_0xbfd7('0x6c')][_0xbfd7('0x55')]({'where':{'id':_0x41147f['params']['id']}})[_0xbfd7('0x20')](handleEntityNotFound(_0x1cbe56,null))[_0xbfd7('0x20')](function(_0x6f4618){if(_0x6f4618){return _0x6f4618[_0xbfd7('0x6b')](_0x41147f[_0xbfd7('0x57')][_0xbfd7('0x66')],_['omit'](_0x41147f[_0xbfd7('0x57')],['ids','id'])||{});}})[_0xbfd7('0x20')](respondWithResult(_0x1cbe56,null))[_0xbfd7('0x26')](handleError(_0x1cbe56,null));};exports['getInteractions']=function(_0x47f8ff,_0x4017bf,_0xb2f119){var _0xd58d3b={'raw':![],'where':{}};var _0x42bd52={};var _0x7e12d5={'count':0x0,'rows':[]};return db['FaxAccount']['findOne']({'where':{'id':_0x47f8ff[_0xbfd7('0x52')]['id']}})['then'](handleEntityNotFound(_0x4017bf,null))[_0xbfd7('0x20')](function(_0x4a139a){if(_0x4a139a){_0x42bd52['model']=_['keys'](db['FaxInteraction'][_0xbfd7('0x3a')]);_0x42bd52[_0xbfd7('0x40')]=_[_0xbfd7('0x53')](_0x47f8ff['query']);_0x42bd52[_0xbfd7('0x41')]=_[_0xbfd7('0x42')](_0x42bd52[_0xbfd7('0x3e')],_0x42bd52['query']);_0xd58d3b[_0xbfd7('0x43')]=_['intersection'](_0x42bd52['model'],qs[_0xbfd7('0x44')](_0x47f8ff[_0xbfd7('0x40')][_0xbfd7('0x44')]));_0xd58d3b['attributes']=_0xd58d3b[_0xbfd7('0x43')][_0xbfd7('0x45')]?_0xd58d3b[_0xbfd7('0x43')]:_0x42bd52['model'];if(!_0x47f8ff[_0xbfd7('0x40')][_0xbfd7('0x62')](_0xbfd7('0x46'))){_0xd58d3b[_0xbfd7('0x2d')]=qs[_0xbfd7('0x2d')](_0x47f8ff[_0xbfd7('0x40')]['limit']);_0xd58d3b[_0xbfd7('0x2c')]=qs['offset'](_0x47f8ff[_0xbfd7('0x40')][_0xbfd7('0x2c')]);}_0xd58d3b[_0xbfd7('0x47')]=qs['sort'](_0x47f8ff[_0xbfd7('0x40')]['sort']);_0xd58d3b['where']=qs[_0xbfd7('0x41')](_[_0xbfd7('0x49')](_0x47f8ff[_0xbfd7('0x40')],_0x42bd52[_0xbfd7('0x41')]));_0xd58d3b[_0xbfd7('0x4c')][_0xbfd7('0x63')]=_0x4a139a['id'];if(_0x47f8ff['query'][_0xbfd7('0x4a')]){_0xd58d3b[_0xbfd7('0x4c')]=_[_0xbfd7('0x4b')](_0xd58d3b[_0xbfd7('0x4c')],{'$or':_['map'](_0xd58d3b[_0xbfd7('0x43')],function(_0x20fdeb){var _0x3ff80f={};_0x3ff80f[_0x20fdeb]={'$like':'%'+_0x47f8ff[_0xbfd7('0x40')]['filter']+'%'};return _0x3ff80f;})});}_0xd58d3b=_['merge']({},_0xd58d3b,_0x47f8ff[_0xbfd7('0x4e')]);return db[_0xbfd7('0x6c')][_0xbfd7('0x2b')]({'where':_0xd58d3b[_0xbfd7('0x4c')]})[_0xbfd7('0x20')](function(_0xe329c0){_0x7e12d5[_0xbfd7('0x2b')]=_0xe329c0;if(_0x47f8ff[_0xbfd7('0x40')][_0xbfd7('0x4f')]){_0xd58d3b[_0xbfd7('0x54')]=[{'model':db[_0xbfd7('0x6d')],'as':_0xbfd7('0x6e'),'required':![]},{'model':db[_0xbfd7('0x6f')],'as':_0xbfd7('0x70'),'attributes':['name',_0xbfd7('0x71'),_0xbfd7('0x72')],'required':![]},{'model':db[_0xbfd7('0x73')],'as':_0xbfd7('0x74'),'attributes':['id',_0xbfd7('0x36'),_0xbfd7('0x75')],'where':_0x47f8ff[_0xbfd7('0x40')][_0xbfd7('0x76')]?{'id':_0x47f8ff['query']['tag']}:undefined,'required':_0x47f8ff[_0xbfd7('0x40')]['tag']?!![]:![]}];}return db[_0xbfd7('0x6c')][_0xbfd7('0x64')](_0xd58d3b);})[_0xbfd7('0x20')](function(_0x355e9b){_0x7e12d5[_0xbfd7('0x50')]=_0x355e9b;return _0x7e12d5;});}})[_0xbfd7('0x20')](respondWithFilteredResult(_0x4017bf,_0xd58d3b))[_0xbfd7('0x26')](handleError(_0x4017bf,null));};exports[_0xbfd7('0x77')]=function(_0x5412f2,_0x598b04,_0x4175f1){return db[_0xbfd7('0x39')]['findOne']({'where':{'id':_0x5412f2[_0xbfd7('0x52')]['id']}})[_0xbfd7('0x20')](handleEntityNotFound(_0x598b04,null))[_0xbfd7('0x20')](function(_0x5c96af){if(_0x5c96af){return db['sequelize'][_0xbfd7('0x78')](function(_0x1a2d85){return db['FaxApplication']['destroy']({'where':{'FaxAccountId':_0x5412f2[_0xbfd7('0x52')]['id']},'transaction':_0x1a2d85})['then'](function(_0x1498c8){var _0x33f669=_[_0xbfd7('0x3f')](_0x5412f2['body'],function(_0x10f512){_0x10f512[_0xbfd7('0x63')]=_0x5412f2[_0xbfd7('0x52')]['id'];return _0x10f512;});return db['FaxApplication']['bulkCreate'](_0x33f669,{'transaction':_0x1a2d85});});})['then'](function(){return db['FaxApplication']['findAndCountAll']({'where':{'FaxAccountId':_0x5412f2[_0xbfd7('0x52')]['id']},'order':_0xbfd7('0x79')});});}})[_0xbfd7('0x20')](respondWithResult(_0x598b04,null))[_0xbfd7('0x26')](handleError(_0x598b04,null));};exports['getApplications']=function(_0x1e5813,_0x1f362a,_0x20d691){var _0x4e31be={};var _0x549644={};var _0x2830fe;var _0x52346d;return db[_0xbfd7('0x39')]['findOne']({'where':{'id':_0x1e5813[_0xbfd7('0x52')]['id']}})[_0xbfd7('0x20')](handleEntityNotFound(_0x1f362a,null))[_0xbfd7('0x20')](function(_0x51d7df){if(_0x51d7df){_0x2830fe=_0x51d7df;_0x549644[_0xbfd7('0x3e')]=_[_0xbfd7('0x53')](db['FaxApplication'][_0xbfd7('0x3a')]);_0x549644['query']=_['keys'](_0x1e5813['query']);_0x549644[_0xbfd7('0x41')]=_[_0xbfd7('0x42')](_0x549644[_0xbfd7('0x3e')],_0x549644[_0xbfd7('0x40')]);_0x4e31be[_0xbfd7('0x43')]=_[_0xbfd7('0x42')](_0x549644[_0xbfd7('0x3e')],qs[_0xbfd7('0x44')](_0x1e5813[_0xbfd7('0x40')]['fields']));_0x4e31be[_0xbfd7('0x43')]=_0x4e31be['attributes'][_0xbfd7('0x45')]?_0x4e31be[_0xbfd7('0x43')]:_0x549644[_0xbfd7('0x3e')];_0x4e31be['order']=qs[_0xbfd7('0x48')](_0x1e5813[_0xbfd7('0x40')][_0xbfd7('0x48')]);_0x4e31be[_0xbfd7('0x4c')]=qs[_0xbfd7('0x41')](_['pick'](_0x1e5813[_0xbfd7('0x40')],_0x549644[_0xbfd7('0x41')]));if(_0x1e5813[_0xbfd7('0x40')]['filter']){_0x4e31be[_0xbfd7('0x4c')]=_[_0xbfd7('0x4b')](_0x4e31be[_0xbfd7('0x4c')],{'$or':_[_0xbfd7('0x3f')](_0x4e31be[_0xbfd7('0x43')],function(_0x43bed8){var _0x13f40d={};_0x13f40d[_0x43bed8]={'$like':'%'+_0x1e5813[_0xbfd7('0x40')][_0xbfd7('0x4a')]+'%'};return _0x13f40d;})});}_0x4e31be=_[_0xbfd7('0x4b')]({},_0x4e31be,_0x1e5813[_0xbfd7('0x4e')]);return _0x2830fe[_0xbfd7('0x7a')](_0x4e31be);}})[_0xbfd7('0x20')](function(_0x492a1e){if(_0x492a1e){_0x52346d=_0x492a1e[_0xbfd7('0x45')];if(!_0x1e5813[_0xbfd7('0x40')][_0xbfd7('0x62')](_0xbfd7('0x46'))){_0x4e31be[_0xbfd7('0x2d')]=qs[_0xbfd7('0x2d')](_0x1e5813[_0xbfd7('0x40')][_0xbfd7('0x2d')]);_0x4e31be['offset']=qs['offset'](_0x1e5813[_0xbfd7('0x40')][_0xbfd7('0x2c')]);}return _0x2830fe[_0xbfd7('0x7a')](_0x4e31be);}})['then'](function(_0x49693e){if(_0x49693e){return _0x49693e?{'count':_0x52346d,'rows':_0x49693e}:null;}})['then'](respondWithResult(_0x1f362a,null))[_0xbfd7('0x26')](handleError(_0x1f362a,null));};function Extension(_0x54e9a0,_0x1e845e,_0x4aaf4a,_0x4df5b3){this['context']='from-voip-provider';this[_0xbfd7('0x7b')]=_0x54e9a0['localstationid'];this['app']=_0x4df5b3;this['type']=_0xbfd7('0x7c');this[_0xbfd7('0x7d')]='Fax\x20Extension';this['FaxAccountId']=_0x54e9a0['id'];this['priority']=_0x1e845e;this[_0xbfd7('0x7e')]=_0x4aaf4a;}function createExtensionsReciveFax(_0x10b72c){var _0x5d2d6f=0x1;var _0x343953=[];_0x343953[_0xbfd7('0x7f')](new Extension(_0x10b72c,_0x5d2d6f,'',_0xbfd7('0x80')));_0x5d2d6f+=0x1;_0x343953[_0xbfd7('0x7f')](new Extension(_0x10b72c,_0x5d2d6f,_0xbfd7('0x81'),_0xbfd7('0x82')));_0x5d2d6f+=0x1;for(var _0x331ff8 in _0x10b72c){if(_0x10b72c[_0xbfd7('0x62')](_0x331ff8)&&(_0x331ff8===_0xbfd7('0x83')||_0x331ff8==='localstationid'||_0x331ff8===_0xbfd7('0x84')||_0x331ff8===_0xbfd7('0x85')||_0x331ff8===_0xbfd7('0x86')||_0x331ff8===_0xbfd7('0x87')||_0x331ff8===_0xbfd7('0x88')||_0x331ff8==='modem'||_0x331ff8==='t38timeout')){_0x343953[_0xbfd7('0x7f')](new Extension(_0x10b72c,_0x5d2d6f,_0xbfd7('0x89')+_0x331ff8+')='+_0x10b72c[_0x331ff8],_0xbfd7('0x82')));_0x5d2d6f+=0x1;}}_0x343953['push'](new Extension(_0x10b72c,_0x5d2d6f,'6','Wait'));_0x5d2d6f+=0x1;_0x343953[_0xbfd7('0x7f')](new Extension(_0x10b72c,_0x5d2d6f,_0xbfd7('0x8a'),_0xbfd7('0x8b')));_0x5d2d6f=0x0;return _0x343953;}exports[_0xbfd7('0x8c')]=function(_0x4b748b,_0x5be52a,_0x5ea323){var _0x1bceb5;return db[_0xbfd7('0x8d')]['transaction'](function(_0x499dbd){return db['FaxAccount'][_0xbfd7('0x56')](_0x4b748b[_0xbfd7('0x57')],{'transaction':_0x499dbd})[_0xbfd7('0x20')](function(_0x29426c){_0x1bceb5=_0x29426c[_0xbfd7('0x33')]({'plain':!![]});return db['VoiceExtension'][_0xbfd7('0x8e')](createExtensionsReciveFax(_0x1bceb5),{'transaction':_0x499dbd});});})[_0xbfd7('0x20')](function(){return _0x1bceb5;})[_0xbfd7('0x20')](respondWithResult(_0x5be52a,null))['catch'](handleError(_0x5be52a,null));};exports['updateAccountApplications']=function(_0x38eabf,_0x7b5edf,_0x45fc5b){var _0x4949b1;return db['sequelize'][_0xbfd7('0x78')](function(_0x32752b){return db[_0xbfd7('0x39')][_0xbfd7('0x31')](_0x38eabf[_0xbfd7('0x57')],{'where':{'id':_0x38eabf[_0xbfd7('0x57')]['id']},'transaction':_0x32752b})['then'](function(_0x1460b2){return db[_0xbfd7('0x8f')][_0xbfd7('0x32')]({'where':{'FaxAccountId':_0x38eabf[_0xbfd7('0x57')]['id']},'transaction':_0x32752b})[_0xbfd7('0x20')](function(_0x31a152){return db['VoiceExtension']['bulkCreate'](createExtensionsReciveFax(_[_0xbfd7('0x90')](_0x38eabf['body'],['tech',_0xbfd7('0x3d'),'createdAt','updatedAt',_0xbfd7('0x91'),_0xbfd7('0x92')])),{'transaction':_0x32752b});});});})[_0xbfd7('0x20')](function(){return db['FaxAccount'][_0xbfd7('0x93')](_0x38eabf[_0xbfd7('0x57')]['id']);})['then'](respondWithResult(_0x7b5edf,null))[_0xbfd7('0x26')](handleError(_0x7b5edf,null));};exports[_0xbfd7('0x94')]=function(_0x5ac894,_0x23cf5b,_0x49028f){var _0x53d6c6={'raw':!![],'where':{}};var _0x773aa0={};var _0x58c252={'count':0x0,'rows':[]};return db['FaxAccount'][_0xbfd7('0x60')]({'where':{'id':_0x5ac894[_0xbfd7('0x52')]['id']}})[_0xbfd7('0x20')](handleEntityNotFound(_0x23cf5b,null))[_0xbfd7('0x20')](function(_0x24a2c2){if(_0x24a2c2){_0x773aa0[_0xbfd7('0x3e')]=_['keys'](db[_0xbfd7('0x95')][_0xbfd7('0x3a')]);_0x773aa0[_0xbfd7('0x40')]=_[_0xbfd7('0x53')](_0x5ac894[_0xbfd7('0x40')]);_0x773aa0['filters']=_['intersection'](_0x773aa0['model'],_0x773aa0['query']);_0x53d6c6[_0xbfd7('0x43')]=_[_0xbfd7('0x42')](_0x773aa0[_0xbfd7('0x3e')],qs[_0xbfd7('0x44')](_0x5ac894[_0xbfd7('0x40')][_0xbfd7('0x44')]));_0x53d6c6[_0xbfd7('0x43')]=_0x53d6c6[_0xbfd7('0x43')]['length']?_0x53d6c6['attributes']:_0x773aa0[_0xbfd7('0x3e')];if(!_0x5ac894[_0xbfd7('0x40')][_0xbfd7('0x62')](_0xbfd7('0x46'))){_0x53d6c6['limit']=qs['limit'](_0x5ac894['query'][_0xbfd7('0x2d')]);_0x53d6c6[_0xbfd7('0x2c')]=qs[_0xbfd7('0x2c')](_0x5ac894[_0xbfd7('0x40')]['offset']);}_0x53d6c6['order']=qs[_0xbfd7('0x48')](_0x5ac894[_0xbfd7('0x40')][_0xbfd7('0x48')]);_0x53d6c6[_0xbfd7('0x4c')]=qs['filters'](_[_0xbfd7('0x49')](_0x5ac894[_0xbfd7('0x40')],_0x773aa0[_0xbfd7('0x41')]));_0x53d6c6[_0xbfd7('0x4c')][_0xbfd7('0x63')]=_0x24a2c2['id'];if(_0x5ac894[_0xbfd7('0x40')][_0xbfd7('0x4a')]){_0x53d6c6['where']=_[_0xbfd7('0x4b')](_0x53d6c6[_0xbfd7('0x4c')],{'$or':_['map'](_0x53d6c6[_0xbfd7('0x43')],function(_0x1d3f43){var _0x24cf8a={};_0x24cf8a[_0x1d3f43]={'$like':'%'+_0x5ac894[_0xbfd7('0x40')][_0xbfd7('0x4a')]+'%'};return _0x24cf8a;})});}if(_0x5ac894['query'][_0xbfd7('0x96')]){var _0x3d6cc8=_0x5ac894['query'][_0xbfd7('0x96')][_0xbfd7('0x97')](',');var _0x5a6772={};_0x5a6772[_0x3d6cc8[0x0]]={'$gte':moment(_0x3d6cc8[0x1])[_0xbfd7('0x98')](_0xbfd7('0x99'))};_0x53d6c6[_0xbfd7('0x4c')]=_[_0xbfd7('0x4b')](_0x53d6c6['where'],_0x5a6772);}_0x53d6c6=_[_0xbfd7('0x4b')]({},_0x53d6c6,_0x5ac894[_0xbfd7('0x4e')]);return db['FaxMessage']['count']({'where':_0x53d6c6[_0xbfd7('0x4c')]})[_0xbfd7('0x20')](function(_0x2fe887){_0x58c252[_0xbfd7('0x2b')]=_0x2fe887;if(_0x5ac894[_0xbfd7('0x40')]['includeAll']){_0x53d6c6[_0xbfd7('0x54')]=[{'all':!![]}];}return db['FaxMessage'][_0xbfd7('0x64')](_0x53d6c6);})['then'](function(_0x47faa5){_0x58c252['rows']=_0x47faa5;return _0x58c252;});}})[_0xbfd7('0x20')](respondWithFilteredResult(_0x23cf5b,_0x53d6c6))[_0xbfd7('0x26')](handleError(_0x23cf5b,null));};exports['send']=function(_0xfb95f7,_0x432440,_0x37fdb7){var _0x3b61b6,_0xc577fb={},_0x9bc271;if(_0xfb95f7[_0xbfd7('0x57')]['to']){_0x9bc271=_0xfb95f7[_0xbfd7('0x57')]['to'][0x0];}return db[_0xbfd7('0x39')][_0xbfd7('0x55')]({'where':{'id':_0xfb95f7['params']['id']},'include':[{'model':db[_0xbfd7('0x9a')],'as':'List','include':[{'model':db['CmContact'],'as':_0xbfd7('0x9b'),'where':{'fax':_0x9bc271},'limit':0x1,'order':[[_0xbfd7('0x9c'),'DESC']]}]}]})[_0xbfd7('0x20')](handleEntityNotFound(_0x432440,null))[_0xbfd7('0x20')](function(_0x40715c){_0x3b61b6=_0x40715c;if(_0xfb95f7[_0xbfd7('0x57')]['attachments']&&_0xfb95f7[_0xbfd7('0x57')][_0xbfd7('0x9d')][_0xbfd7('0x45')]){for(var _0x12e743=0x0;_0x12e743<_0xfb95f7[_0xbfd7('0x57')]['attachments'][_0xbfd7('0x45')];_0x12e743+=0x1){_0xfb95f7[_0xbfd7('0x57')][_0xbfd7('0x9d')][_0x12e743]={'filename':_0xfb95f7[_0xbfd7('0x57')][_0xbfd7('0x9d')][_0x12e743][_0xbfd7('0x36')],'id':_0xfb95f7[_0xbfd7('0x57')][_0xbfd7('0x9d')][_0x12e743]['id'],'path':path[_0xbfd7('0x9e')](config[_0xbfd7('0x9f')],'server/files/attachments',_0xfb95f7[_0xbfd7('0x57')][_0xbfd7('0x9d')][_0x12e743][_0xbfd7('0xa0')])};}}return respondWithRpcPromise(_0xbfd7('0xa1'),_0xbfd7('0xa1'),{'FaxAccountId':_[_0xbfd7('0xa2')](_0xfb95f7[_0xbfd7('0x52')]['id'])?undefined:_0xfb95f7['params']['id'],'path':_['isNil'](_0xfb95f7[_0xbfd7('0x57')][_0xbfd7('0x9d')][0x0]['path'])?undefined:_0xfb95f7[_0xbfd7('0x57')][_0xbfd7('0x9d')][0x0][_0xbfd7('0x9')],'fax':_[_0xbfd7('0xa2')](_0xfb95f7[_0xbfd7('0x57')]['to'][0x0])?undefined:_0xfb95f7[_0xbfd7('0x57')]['to'][0x0]},client9002);})[_0xbfd7('0x20')](function(){if(_0x3b61b6){if(_[_0xbfd7('0xa2')](_0xfb95f7[_0xbfd7('0x57')]['from'])){_0xfb95f7[_0xbfd7('0x57')]['from']=util[_0xbfd7('0x98')](_0xbfd7('0xa3'),_0x3b61b6['name'],_0x3b61b6['fax']);}if(_0x3b61b6[_0xbfd7('0xa4')]){if(_0x3b61b6['List'][_0xbfd7('0x9b')][_0xbfd7('0x45')]){return _0x3b61b6[_0xbfd7('0xa4')]['Contacts'][0x0];}else{return db[_0xbfd7('0x6d')]['create'](_[_0xbfd7('0x19')](_0xfb95f7[_0xbfd7('0x57')],{'firstName':_0xfb95f7[_0xbfd7('0x57')]['to'][0x0],'phone':_0xfb95f7['body']['to'][0x0],'fax':_0xfb95f7[_0xbfd7('0x57')]['to'][0x0],'ListId':_0x3b61b6['ListId']}));}}else{throw new Error('List\x20not\x20found');}}else{throw new Error(_0xbfd7('0xa5'));}})[_0xbfd7('0x20')](function(_0x2c8996){if(_0x2c8996){return db[_0xbfd7('0x6c')]['find']({'where':{'ContactId':_0x2c8996['id'],'closed':![],'FaxAccountId':_0x3b61b6['id']}})[_0xbfd7('0x20')](function(_0x423c7e){if(_0x423c7e){return[_0x423c7e,![]];}return db[_0xbfd7('0x6c')][_0xbfd7('0x56')]({'UserId':_0xfb95f7[_0xbfd7('0xa6')]['id'],'ContactId':_0x2c8996['id'],'FaxAccountId':_0x3b61b6['id'],'fax':_0xfb95f7[_0xbfd7('0x57')]['to'][0x0],'firstMsgDirection':_0xbfd7('0xa7'),'Messages':[_[_0xbfd7('0x4b')](_0xfb95f7['body'],{'read':![],'body':_0xfb95f7[_0xbfd7('0x57')][_0xbfd7('0x9d')][0x0][_0xbfd7('0xa8')],'FaxAccountId':_0x3b61b6['id'],'UserId':_0xfb95f7[_0xbfd7('0xa6')]['id'],'ContactId':_0x2c8996['id'],'AttachmentId':_0xfb95f7[_0xbfd7('0x57')][_0xbfd7('0x9d')][0x0]['id']})]},{'include':[{'model':db['FaxMessage'],'as':_0xbfd7('0xa9')}]})[_0xbfd7('0x20')](function(_0x8f797){return[_0x8f797,!![]];});});}else{throw new Error(_0xbfd7('0xaa'));}})[_0xbfd7('0xab')](function(_0x443855,_0x4b8e94){if(_0x4b8e94){return _0x443855;}return db[_0xbfd7('0x95')][_0xbfd7('0x56')]({'direction':'out','read':![],'body':_0xfb95f7[_0xbfd7('0x57')][_0xbfd7('0x9d')][0x0][_0xbfd7('0xa8')],'FaxAccountId':_0x3b61b6['id'],'FaxInteractionId':_0x443855['id'],'UserId':_0xfb95f7[_0xbfd7('0xa6')]['id'],'ContactId':_0x443855['ContactId'],'AttachmentId':_0xfb95f7[_0xbfd7('0x57')][_0xbfd7('0x9d')][0x0]['id']})[_0xbfd7('0x20')](function(_0x241b3e){_0x443855['dataValues'][_0xbfd7('0xa9')]=[];_0x443855[_0xbfd7('0xac')][_0xbfd7('0xa9')]['push'](_0x241b3e['dataValues']);return _0x443855;});})[_0xbfd7('0x20')](function(_0x160e05){respondWithRpcPromise(_0xbfd7('0xad'),_0xbfd7('0xad'),{'FaxAccountId':_['isNil'](_0xfb95f7['params']['id'])?undefined:_0xfb95f7['params']['id'],'path':_[_0xbfd7('0xa2')](_0xfb95f7[_0xbfd7('0x57')]['attachments'][0x0][_0xbfd7('0x9')])?undefined:_0xfb95f7[_0xbfd7('0x57')]['attachments'][0x0][_0xbfd7('0x9')],'fax':_[_0xbfd7('0xa2')](_0xfb95f7['body']['to'][0x0])?undefined:_0xfb95f7[_0xbfd7('0x57')]['to'][0x0],'AttachmentId':_0xfb95f7[_0xbfd7('0x57')]['attachments'][0x0]['id']},client9002)[_0xbfd7('0x20')](function(_0x1659aa){logger['info'](_0xbfd7('0xae'),_0x1659aa);})[_0xbfd7('0x26')](function(_0xb0b7c9){logger[_0xbfd7('0x25')](_0xbfd7('0xae'),_0xb0b7c9);});return _0x160e05;})[_0xbfd7('0x20')](respondWithResult(_0x432440,null))['catch'](handleError(_0x432440,null));};exports[_0xbfd7('0xaf')]=function(_0x1e877c,_0x2cabf4,_0x24208a){return db['FaxAccount'][_0xbfd7('0x55')]({'where':{'id':_0x1e877c[_0xbfd7('0x52')]['id']}})[_0xbfd7('0x20')](handleEntityNotFound(_0x2cabf4,null))['then'](function(_0x7db69a){if(_0x7db69a){return _0x7db69a['addAgents'](_0x1e877c[_0xbfd7('0x57')]['ids'],_[_0xbfd7('0x90')](_0x1e877c['body'],[_0xbfd7('0x66'),'id'])||{})[_0xbfd7('0xab')](function(_0x3b050e){for(var _0x5bdebf=0x0;_0x5bdebf<_0x1e877c[_0xbfd7('0x57')]['ids'][_0xbfd7('0x45')];_0x5bdebf+=0x1){socket[_0xbfd7('0xb0')](_0xbfd7('0xb1'),{'UserId':_0x1e877c[_0xbfd7('0x57')][_0xbfd7('0x66')][_0x5bdebf],'FaxAccountId':_0x1e877c[_0xbfd7('0x52')]['id']});}return _0x3b050e;});}})[_0xbfd7('0x20')](respondWithResult(_0x2cabf4,null))[_0xbfd7('0x26')](handleError(_0x2cabf4,null));};exports[_0xbfd7('0xb2')]=function(_0x11b96d,_0x3a0e27,_0x495dbe){return db[_0xbfd7('0x39')][_0xbfd7('0x55')]({'where':{'id':_0x11b96d[_0xbfd7('0x52')]['id']}})['then'](handleEntityNotFound(_0x3a0e27,null))[_0xbfd7('0x20')](function(_0x5d9bee){if(_0x5d9bee){return _0x5d9bee[_0xbfd7('0xb2')](_0x11b96d[_0xbfd7('0x40')][_0xbfd7('0x66')])[_0xbfd7('0x20')](function(){if(_[_0xbfd7('0xb3')](_0x11b96d['query'][_0xbfd7('0x66')])){for(var _0x124c00=0x0;_0x124c00<_0x11b96d['query']['ids'][_0xbfd7('0x45')];_0x124c00+=0x1){socket[_0xbfd7('0xb0')](_0xbfd7('0xb4'),{'UserId':Number(_0x11b96d[_0xbfd7('0x40')][_0xbfd7('0x66')][_0x124c00]),'FaxAccountId':Number(_0x11b96d[_0xbfd7('0x52')]['id'])});}}else{socket[_0xbfd7('0xb0')](_0xbfd7('0xb4'),{'UserId':Number(_0x11b96d[_0xbfd7('0x40')][_0xbfd7('0x66')]),'FaxAccountId':Number(_0x11b96d['params']['id'])});}});}})[_0xbfd7('0x20')](respondWithStatusCode(_0x3a0e27,null))['catch'](handleError(_0x3a0e27,null));};exports[_0xbfd7('0xb5')]=function(_0x1f8dd5,_0x266dd1,_0x2ab0e0){var _0x2ef067={};var _0x191c7b={};var _0x165d23;var _0x24b9c0;return db['FaxAccount'][_0xbfd7('0x60')]({'where':{'id':_0x1f8dd5[_0xbfd7('0x52')]['id']}})['then'](handleEntityNotFound(_0x266dd1,null))[_0xbfd7('0x20')](function(_0xe3cdd2){if(_0xe3cdd2){_0x165d23=_0xe3cdd2;_0x191c7b[_0xbfd7('0x3e')]=_[_0xbfd7('0x53')](db[_0xbfd7('0x6f')][_0xbfd7('0x3a')]);_0x191c7b[_0xbfd7('0x40')]=_[_0xbfd7('0x53')](_0x1f8dd5[_0xbfd7('0x40')]);_0x191c7b[_0xbfd7('0x41')]=_[_0xbfd7('0x42')](_0x191c7b['model'],_0x191c7b[_0xbfd7('0x40')]);_0x2ef067[_0xbfd7('0x43')]=_[_0xbfd7('0x42')](_0x191c7b[_0xbfd7('0x3e')],qs['fields'](_0x1f8dd5[_0xbfd7('0x40')][_0xbfd7('0x44')]));_0x2ef067[_0xbfd7('0x43')]=_0x2ef067['attributes'][_0xbfd7('0x45')]?_0x2ef067[_0xbfd7('0x43')]:_0x191c7b[_0xbfd7('0x3e')];_0x2ef067[_0xbfd7('0x47')]=qs[_0xbfd7('0x48')](_0x1f8dd5[_0xbfd7('0x40')][_0xbfd7('0x48')]);_0x2ef067[_0xbfd7('0x4c')]=qs[_0xbfd7('0x41')](_[_0xbfd7('0x49')](_0x1f8dd5['query'],_0x191c7b[_0xbfd7('0x41')]));if(_0x1f8dd5[_0xbfd7('0x40')][_0xbfd7('0x4a')]){_0x2ef067[_0xbfd7('0x4c')]=_['merge'](_0x2ef067[_0xbfd7('0x4c')],{'$or':_[_0xbfd7('0x3f')](_0x2ef067[_0xbfd7('0x43')],function(_0x8e54e8){var _0x49796c={};_0x49796c[_0x8e54e8]={'$like':'%'+_0x1f8dd5[_0xbfd7('0x40')][_0xbfd7('0x4a')]+'%'};return _0x49796c;})});}_0x2ef067=_[_0xbfd7('0x4b')]({},_0x2ef067,_0x1f8dd5['options']);return _0x165d23[_0xbfd7('0xb5')](_0x2ef067);}})[_0xbfd7('0x20')](function(_0x2a8c5e){if(_0x2a8c5e){_0x24b9c0=_0x2a8c5e[_0xbfd7('0x45')];if(!_0x1f8dd5[_0xbfd7('0x40')]['hasOwnProperty'](_0xbfd7('0x46'))){_0x2ef067[_0xbfd7('0x2d')]=qs[_0xbfd7('0x2d')](_0x1f8dd5[_0xbfd7('0x40')][_0xbfd7('0x2d')]);_0x2ef067['offset']=qs['offset'](_0x1f8dd5[_0xbfd7('0x40')]['offset']);}return _0x165d23['getAgents'](_0x2ef067);}})['then'](function(_0x4e6db8){if(_0x4e6db8){return _0x4e6db8?{'count':_0x24b9c0,'rows':_0x4e6db8}:null;}})[_0xbfd7('0x20')](respondWithResult(_0x266dd1,null))[_0xbfd7('0x26')](handleError(_0x266dd1,null));};