Built motion from commit 753c950e.|2.5.42
[motion2.git] / server / api / faxMessage / faxMessage.controller.js
index a56c3d3..062bbd8 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xea05=['desk.js','querystring','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','defaults','redis','localhost','socket.io-emitter','./faxMessage.socket','client','http','request','then','info','FaxMessage,\x20%s,\x20%s','request\x20sent','debug','FaxMessage,\x20%s,\x20%s,\x20%s','stringify','error','message','result','catch','end','status','json','offset','undefined','limit','set','Content-Range','apply','reject','sendStatus','stack','name','map','FaxMessage','rawAttributes','type','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','filter','where','merge','VIRTUAL','options','count','includeAll','include','rows','show','params','find','update','body','destroy','describe','fax-interactions','accept','read','readAt','UserId','user','get','FaxInteraction','FaxInteractionId','read1stAt','format','YYYY-MM-DD\x20HH:mm:ss','interaction','[FAXMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','null','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','Sequelize','contact','User','agent','fullname','email','internal','manual','interface','SIP/%s','channel','motionChannel','event','EventManager','fax','[FAXMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','QueryTypes','SELECT','CmContact','findOne','isNil','Attachment','SendFax','FaxAccountId','/var/opt/motion2/server/files/attachments/%s','basename','download','join','server','files','attachments','fast-json-patch','request-promise','moment','util','squel','crypto'];(function(_0x9c2427,_0x17c865){var _0x51984f=function(_0x177af6){while(--_0x177af6){_0x9c2427['push'](_0x9c2427['shift']());}};_0x51984f(++_0x17c865);}(_0xea05,0x102));var _0x5ea0=function(_0x1a10ef,_0x207697){_0x1a10ef=_0x1a10ef-0x0;var _0x30f444=_0xea05[_0x1a10ef];return _0x30f444;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x5ea0('0x0'));var rp=require(_0x5ea0('0x1'));var moment=require(_0x5ea0('0x2'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x5ea0('0x3'));var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x5ea0('0x4'));var crypto=require(_0x5ea0('0x5'));var jsforce=require('jsforce');var deskjs=require(_0x5ea0('0x6'));var toCsv=require('to-csv');var querystring=require(_0x5ea0('0x7'));var Papa=require('papaparse');var Redis=require(_0x5ea0('0x8'));var authService=require('../../components/auth/service');var qs=require(_0x5ea0('0x9'));var as=require(_0x5ea0('0xa'));var hardwareService=require(_0x5ea0('0xb'));var logger=require(_0x5ea0('0xc'))(_0x5ea0('0xd'));var utils=require(_0x5ea0('0xe'));var config=require('../../config/environment');var licenseUtil=require(_0x5ea0('0xf'));var db=require('../../mysqldb')['db'];config['redis']=_[_0x5ea0('0x10')](config[_0x5ea0('0x11')],{'host':_0x5ea0('0x12'),'port':0x18eb});var socket=require(_0x5ea0('0x13'))(new Redis(config['redis']));require(_0x5ea0('0x14'))['register'](socket);var jayson=require('jayson/promise');var client=jayson[_0x5ea0('0x15')][_0x5ea0('0x16')]({'port':0x232c});var client9002=jayson['client'][_0x5ea0('0x16')]({'port':0x232a});function respondWithRpcPromise(_0x5dee3f,_0x4427dd,_0x22987a,_0x35fcd8){return new BPromise(function(_0x17973d,_0x499a0b){var _0x2269f9=_0x35fcd8||client;return _0x2269f9[_0x5ea0('0x17')](_0x5dee3f,_0x22987a)[_0x5ea0('0x18')](function(_0x5e9302){logger[_0x5ea0('0x19')](_0x5ea0('0x1a'),_0x4427dd,_0x5ea0('0x1b'));logger[_0x5ea0('0x1c')](_0x5ea0('0x1d'),_0x4427dd,_0x5ea0('0x1b'),JSON[_0x5ea0('0x1e')](_0x5e9302));if(_0x5e9302['error']){if(_0x5e9302[_0x5ea0('0x1f')]['code']===0x1f4){logger[_0x5ea0('0x1f')](_0x5ea0('0x1a'),_0x4427dd,_0x5e9302[_0x5ea0('0x1f')][_0x5ea0('0x20')]);return _0x499a0b(_0x5e9302[_0x5ea0('0x1f')][_0x5ea0('0x20')]);}logger[_0x5ea0('0x1f')](_0x5ea0('0x1a'),_0x4427dd,_0x5e9302[_0x5ea0('0x1f')]['message']);return _0x17973d(_0x5e9302[_0x5ea0('0x1f')][_0x5ea0('0x20')]);}else{logger[_0x5ea0('0x19')](_0x5ea0('0x1a'),_0x4427dd,_0x5ea0('0x1b'));_0x17973d(_0x5e9302[_0x5ea0('0x21')][_0x5ea0('0x20')]);}})[_0x5ea0('0x22')](function(_0x51d10e){logger['error'](_0x5ea0('0x1a'),_0x4427dd,_0x51d10e);_0x499a0b(_0x51d10e);});});}function respondWithStatusCode(_0x3536da,_0x330aea){_0x330aea=_0x330aea||0xcc;return function(_0x73a8b){if(_0x73a8b){return _0x3536da['sendStatus'](_0x330aea);}return _0x3536da['status'](_0x330aea)[_0x5ea0('0x23')]();};}function respondWithResult(_0x441727,_0xd30ce1){_0xd30ce1=_0xd30ce1||0xc8;return function(_0x12b878){if(_0x12b878){return _0x441727[_0x5ea0('0x24')](_0xd30ce1)[_0x5ea0('0x25')](_0x12b878);}};}function respondWithFilteredResult(_0x12dbaf,_0x25d7c8){return function(_0x191af4){if(_0x191af4){var _0x54761a=typeof _0x25d7c8[_0x5ea0('0x26')]===_0x5ea0('0x27')&&typeof _0x25d7c8[_0x5ea0('0x28')]===_0x5ea0('0x27');var _0x16a425=_0x191af4['count'];var _0x47f3f1=_0x54761a?0x0:_0x25d7c8['offset'];var _0x1d28c3=_0x54761a?_0x191af4['count']:_0x25d7c8['offset']+_0x25d7c8[_0x5ea0('0x28')];var _0x24e3e4;if(_0x1d28c3>=_0x16a425){_0x1d28c3=_0x16a425;_0x24e3e4=0xc8;}else{_0x24e3e4=0xce;}_0x12dbaf[_0x5ea0('0x24')](_0x24e3e4);return _0x12dbaf[_0x5ea0('0x29')](_0x5ea0('0x2a'),_0x47f3f1+'-'+_0x1d28c3+'/'+_0x16a425)[_0x5ea0('0x25')](_0x191af4);}return null;};}function patchUpdates(_0x327937){return function(_0x2add5e){try{jsonpatch[_0x5ea0('0x2b')](_0x2add5e,_0x327937,!![]);}catch(_0x1b1148){return BPromise[_0x5ea0('0x2c')](_0x1b1148);}return _0x2add5e['save']();};}function saveUpdates(_0x31204c,_0x112ed4){return function(_0x4bc0e){if(_0x4bc0e){return _0x4bc0e['update'](_0x31204c)[_0x5ea0('0x18')](function(_0x165f2c){return _0x165f2c;});}return null;};}function removeEntity(_0x43a3f9,_0x273b6c){return function(_0x7477c7){if(_0x7477c7){return _0x7477c7['destroy']()[_0x5ea0('0x18')](function(){_0x43a3f9[_0x5ea0('0x24')](0xcc)[_0x5ea0('0x23')]();});}};}function handleEntityNotFound(_0xa2dda8,_0x3eaf86){return function(_0x37fa9c){if(!_0x37fa9c){_0xa2dda8[_0x5ea0('0x2d')](0x194);}return _0x37fa9c;};}function handleError(_0x58f02d,_0xed346d){_0xed346d=_0xed346d||0x1f4;return function(_0x29f531){logger[_0x5ea0('0x1f')](_0x29f531[_0x5ea0('0x2e')]);if(_0x29f531['name']){delete _0x29f531[_0x5ea0('0x2f')];}_0x58f02d[_0x5ea0('0x24')](_0xed346d)['send'](_0x29f531);};}exports['index']=function(_0x574f73,_0xbba234){var _0x17b5c5={},_0x4cc98c={},_0x5fe3b0={'count':0x0,'rows':[]};var _0x613c80=_[_0x5ea0('0x30')](db[_0x5ea0('0x31')][_0x5ea0('0x32')],function(_0x22275b){return{'name':_0x22275b['fieldName'],'type':_0x22275b[_0x5ea0('0x33')]['key']};});_0x4cc98c[_0x5ea0('0x34')]=_[_0x5ea0('0x30')](_0x613c80,_0x5ea0('0x2f'));_0x4cc98c[_0x5ea0('0x35')]=_[_0x5ea0('0x36')](_0x574f73['query']);_0x4cc98c[_0x5ea0('0x37')]=_[_0x5ea0('0x38')](_0x4cc98c[_0x5ea0('0x34')],_0x4cc98c['query']);_0x17b5c5[_0x5ea0('0x39')]=_['intersection'](_0x4cc98c[_0x5ea0('0x34')],qs['fields'](_0x574f73[_0x5ea0('0x35')][_0x5ea0('0x3a')]));_0x17b5c5[_0x5ea0('0x39')]=_0x17b5c5[_0x5ea0('0x39')][_0x5ea0('0x3b')]?_0x17b5c5[_0x5ea0('0x39')]:_0x4cc98c[_0x5ea0('0x34')];if(!_0x574f73[_0x5ea0('0x35')][_0x5ea0('0x3c')](_0x5ea0('0x3d'))){_0x17b5c5[_0x5ea0('0x28')]=qs[_0x5ea0('0x28')](_0x574f73[_0x5ea0('0x35')][_0x5ea0('0x28')]);_0x17b5c5[_0x5ea0('0x26')]=qs['offset'](_0x574f73[_0x5ea0('0x35')][_0x5ea0('0x26')]);}_0x17b5c5[_0x5ea0('0x3e')]=qs[_0x5ea0('0x3f')](_0x574f73[_0x5ea0('0x35')]['sort']);_0x17b5c5['where']=qs[_0x5ea0('0x37')](_['pick'](_0x574f73['query'],_0x4cc98c['filters']),_0x613c80);if(_0x574f73[_0x5ea0('0x35')][_0x5ea0('0x40')]){_0x17b5c5[_0x5ea0('0x41')]=_[_0x5ea0('0x42')](_0x17b5c5[_0x5ea0('0x41')],{'$or':_[_0x5ea0('0x30')](_0x613c80,function(_0x6fa18c){if(_0x6fa18c[_0x5ea0('0x33')]!==_0x5ea0('0x43')){var _0x50e9f8={};_0x50e9f8[_0x6fa18c[_0x5ea0('0x2f')]]={'$like':'%'+_0x574f73[_0x5ea0('0x35')][_0x5ea0('0x40')]+'%'};return _0x50e9f8;}})});}_0x17b5c5=_[_0x5ea0('0x42')]({},_0x17b5c5,_0x574f73[_0x5ea0('0x44')]);var _0x8fe6b2={'where':_0x17b5c5[_0x5ea0('0x41')]};return db['FaxMessage']['count'](_0x8fe6b2)[_0x5ea0('0x18')](function(_0x333d57){_0x5fe3b0[_0x5ea0('0x45')]=_0x333d57;if(_0x574f73[_0x5ea0('0x35')][_0x5ea0('0x46')]){_0x17b5c5[_0x5ea0('0x47')]=[{'all':!![]}];}return db[_0x5ea0('0x31')]['findAll'](_0x17b5c5);})['then'](function(_0x4aafc4){_0x5fe3b0[_0x5ea0('0x48')]=_0x4aafc4;return _0x5fe3b0;})[_0x5ea0('0x18')](respondWithFilteredResult(_0xbba234,_0x17b5c5))['catch'](handleError(_0xbba234,null));};exports[_0x5ea0('0x49')]=function(_0xa0610e,_0x4e4c0a){var _0x310e45={'raw':!![],'where':{'id':_0xa0610e[_0x5ea0('0x4a')]['id']}},_0x366119={};_0x366119[_0x5ea0('0x34')]=_[_0x5ea0('0x36')](db[_0x5ea0('0x31')][_0x5ea0('0x32')]);_0x366119[_0x5ea0('0x35')]=_[_0x5ea0('0x36')](_0xa0610e[_0x5ea0('0x35')]);_0x366119[_0x5ea0('0x37')]=_[_0x5ea0('0x38')](_0x366119[_0x5ea0('0x34')],_0x366119[_0x5ea0('0x35')]);_0x310e45['attributes']=_['intersection'](_0x366119['model'],qs[_0x5ea0('0x3a')](_0xa0610e[_0x5ea0('0x35')]['fields']));_0x310e45[_0x5ea0('0x39')]=_0x310e45[_0x5ea0('0x39')]['length']?_0x310e45[_0x5ea0('0x39')]:_0x366119['model'];if(_0xa0610e[_0x5ea0('0x35')][_0x5ea0('0x46')]){_0x310e45[_0x5ea0('0x47')]=[{'all':!![]}];}_0x310e45=_['merge']({},_0x310e45,_0xa0610e[_0x5ea0('0x44')]);return db[_0x5ea0('0x31')][_0x5ea0('0x4b')](_0x310e45)[_0x5ea0('0x18')](handleEntityNotFound(_0x4e4c0a,null))['then'](respondWithResult(_0x4e4c0a,null))[_0x5ea0('0x22')](handleError(_0x4e4c0a,null));};exports[_0x5ea0('0x4c')]=function(_0x15f7d2,_0xab4bf0){if(_0x15f7d2[_0x5ea0('0x4d')]['id']){delete _0x15f7d2[_0x5ea0('0x4d')]['id'];}return db['FaxMessage'][_0x5ea0('0x4b')]({'where':{'id':_0x15f7d2[_0x5ea0('0x4a')]['id']}})[_0x5ea0('0x18')](handleEntityNotFound(_0xab4bf0,null))[_0x5ea0('0x18')](saveUpdates(_0x15f7d2[_0x5ea0('0x4d')],null))[_0x5ea0('0x18')](respondWithResult(_0xab4bf0,null))[_0x5ea0('0x22')](handleError(_0xab4bf0,null));};exports[_0x5ea0('0x4e')]=function(_0x54d231,_0x4a19b5){return db['FaxMessage'][_0x5ea0('0x4b')]({'where':{'id':_0x54d231[_0x5ea0('0x4a')]['id']}})[_0x5ea0('0x18')](handleEntityNotFound(_0x4a19b5,null))[_0x5ea0('0x18')](removeEntity(_0x4a19b5,null))[_0x5ea0('0x22')](handleError(_0x4a19b5,null));};exports[_0x5ea0('0x4f')]=function(_0x531a76,_0x385941){return db[_0x5ea0('0x31')][_0x5ea0('0x4f')]()[_0x5ea0('0x18')](respondWithResult(_0x385941,null))[_0x5ea0('0x22')](handleError(_0x385941,null));};var interaction_log=require(_0x5ea0('0xc'))(_0x5ea0('0x50'));exports[_0x5ea0('0x51')]=function(_0x37d39f,_0xb59e00,_0x18e071){var _0x4a06d6={'agent':{},'channel':'fax'};if(_0x37d39f[_0x5ea0('0x4d')]['id']){delete _0x37d39f[_0x5ea0('0x4d')]['id'];}_0x37d39f[_0x5ea0('0x4d')][_0x5ea0('0x52')]=!![];_0x37d39f[_0x5ea0('0x4d')][_0x5ea0('0x53')]=moment()['format']('YYYY-MM-DD\x20HH:mm:ss');_0x37d39f[_0x5ea0('0x4d')][_0x5ea0('0x54')]=_0x37d39f[_0x5ea0('0x4d')][_0x5ea0('0x54')]||_0x37d39f[_0x5ea0('0x55')]['id'];_0x4a06d6['agent']['id']=_0x37d39f['body']['UserId'];return db[_0x5ea0('0x31')]['find']({'where':{'id':_0x37d39f[_0x5ea0('0x4a')]['id'],'UserId':null}})[_0x5ea0('0x18')](handleEntityNotFound(_0xb59e00,null))['then'](saveUpdates(_0x37d39f[_0x5ea0('0x4d')],null))['then'](function(_0x375bcc){if(_0x375bcc){_0x4a06d6[_0x5ea0('0x20')]=_0x375bcc[_0x5ea0('0x56')]({'plain':!![]});return db[_0x5ea0('0x57')][_0x5ea0('0x4b')]({'where':{'id':_0x375bcc[_0x5ea0('0x58')]}});}return null;})[_0x5ea0('0x18')](handleEntityNotFound(_0xb59e00,null))['then'](function(_0x117546){if(_0x117546){return _0x117546[_0x5ea0('0x4c')]({'UserId':_0x37d39f[_0x5ea0('0x4d')][_0x5ea0('0x54')],'read1stAt':_['isNil'](_0x117546[_0x5ea0('0x59')])?moment()[_0x5ea0('0x5a')](_0x5ea0('0x5b')):undefined});}return null;})[_0x5ea0('0x18')](function(_0x2def41){if(_0x2def41){_0x4a06d6[_0x5ea0('0x5c')]=_0x2def41['get']({'plain':!![]});interaction_log[_0x5ea0('0x19')](_0x5ea0('0x5d'),_0x37d39f[_0x5ea0('0x55')]['id'],_0x37d39f[_0x5ea0('0x55')][_0x5ea0('0x2f')],_0x37d39f[_0x5ea0('0x55')]['role'],_0x4a06d6[_0x5ea0('0x5c')]['id'],_0x37d39f[_0x5ea0('0x4d')]?JSON[_0x5ea0('0x1e')](_0x37d39f[_0x5ea0('0x4d')]):_0x5ea0('0x5e'));return respondWithRpcPromise('AcceptMessage',_0x5ea0('0x5f'),_0x4a06d6);}return null;})[_0x5ea0('0x18')](function(_0x1cd716){var _0x594c46=_0x5ea0('0x60')+_0x1cd716[_0x5ea0('0x20')][_0x5ea0('0x61')];return db[_0x5ea0('0x62')]['query'](_0x594c46,{'type':db[_0x5ea0('0x63')]['QueryTypes']['SELECT'],'raw':!![]})[_0x5ea0('0x18')](function(_0x2d5d3e){return _0x2d5d3e;});})[_0x5ea0('0x18')](function(_0x3c44a2){if(_0x3c44a2){_0x4a06d6[_0x5ea0('0x20')][_0x5ea0('0x64')]=_0x3c44a2[0x0];if(!_0x37d39f[_0x5ea0('0x4d')][_0x5ea0('0x54')])return;return db[_0x5ea0('0x65')][_0x5ea0('0x4b')]({'where':{'id':_0x37d39f['body'][_0x5ea0('0x54')],'role':_0x5ea0('0x66')},'attributes':['id',_0x5ea0('0x2f'),_0x5ea0('0x67'),_0x5ea0('0x68'),_0x5ea0('0x69')],'raw':!![]});}return null;})['then'](function(_0x138990){if(!_0x138990)return null;_0x4a06d6['message'][_0x5ea0('0x66')]=_0x138990;return _0x4a06d6;})[_0x5ea0('0x18')](function(_0x1a16f8){if(_0x1a16f8){if(_0x37d39f[_0x5ea0('0x4d')][_0x5ea0('0x6a')]){_0x4a06d6[_0x5ea0('0x20')][_0x5ea0('0x6b')]=util['format'](_0x5ea0('0x6c'),_0x37d39f[_0x5ea0('0x55')][_0x5ea0('0x2f')]);_0x4a06d6['message'][_0x5ea0('0x6d')]=_0x4a06d6['channel'];_0x4a06d6[_0x5ea0('0x20')][_0x5ea0('0x6e')]=_0x4a06d6[_0x5ea0('0x6d')];_0x4a06d6[_0x5ea0('0x20')][_0x5ea0('0x6f')]=_0x5ea0('0x51');return respondWithRpcPromise(_0x5ea0('0x70'),_0x5ea0('0x70'),{'event':'acceptmessage','message':_0x4a06d6[_0x5ea0('0x20')]},client9002)['then'](function(){return _0x4a06d6;});}return _0x4a06d6;}return null;})[_0x5ea0('0x18')](respondWithResult(_0xb59e00,null))[_0x5ea0('0x22')](handleError(_0xb59e00,null));};var interaction_log=require(_0x5ea0('0xc'))('fax-interactions');exports[_0x5ea0('0x2c')]=function(_0x1322c4,_0x32dfeb,_0x253eb8){var _0x21fa94={'agent':{},'channel':_0x5ea0('0x71')};if(_0x1322c4[_0x5ea0('0x4d')]['id']){delete _0x1322c4[_0x5ea0('0x4d')]['id'];}_0x1322c4[_0x5ea0('0x4d')][_0x5ea0('0x54')]=_0x1322c4[_0x5ea0('0x4d')][_0x5ea0('0x54')]||_0x1322c4[_0x5ea0('0x55')]['id'];_0x21fa94[_0x5ea0('0x66')]['id']=_0x1322c4[_0x5ea0('0x4d')][_0x5ea0('0x54')];return db[_0x5ea0('0x31')]['find']({'where':{'id':_0x1322c4[_0x5ea0('0x4a')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x32dfeb,null))[_0x5ea0('0x18')](function(_0x191a16){if(_0x191a16){_0x21fa94[_0x5ea0('0x20')]=_0x191a16[_0x5ea0('0x56')]({'plain':!![]});return db[_0x5ea0('0x57')]['find']({'where':{'id':_0x191a16[_0x5ea0('0x58')]}});}return null;})[_0x5ea0('0x18')](handleEntityNotFound(_0x32dfeb,null))[_0x5ea0('0x18')](function(_0x25f977){if(_0x25f977){_0x21fa94[_0x5ea0('0x5c')]=_0x25f977[_0x5ea0('0x56')]({'plain':!![]});interaction_log[_0x5ea0('0x19')](_0x5ea0('0x72'),_0x1322c4[_0x5ea0('0x55')]['id'],_0x1322c4[_0x5ea0('0x55')][_0x5ea0('0x2f')],_0x1322c4[_0x5ea0('0x55')]['role'],_0x21fa94['interaction']['id'],_0x1322c4['body']?JSON[_0x5ea0('0x1e')](_0x1322c4[_0x5ea0('0x4d')]):_0x5ea0('0x5e'));return respondWithRpcPromise(_0x5ea0('0x73'),_0x5ea0('0x74'),_0x21fa94);}return null;})[_0x5ea0('0x18')](function(_0xb6a5f2){var _0x377961=_0x5ea0('0x60')+_0xb6a5f2[_0x5ea0('0x20')]['ContactId'];return db[_0x5ea0('0x62')]['query'](_0x377961,{'type':db[_0x5ea0('0x63')][_0x5ea0('0x75')][_0x5ea0('0x76')],'raw':!![]})['then'](function(_0x49f70e){return _0x49f70e;});})[_0x5ea0('0x18')](function(_0x4711bb){if(_0x4711bb){_0x21fa94[_0x5ea0('0x20')]['contact']=_0x4711bb[0x0];if(!_0x1322c4[_0x5ea0('0x4d')][_0x5ea0('0x54')])return;return db[_0x5ea0('0x65')][_0x5ea0('0x4b')]({'where':{'id':_0x1322c4['body'][_0x5ea0('0x54')],'role':_0x5ea0('0x66')},'attributes':['id',_0x5ea0('0x2f'),_0x5ea0('0x67'),_0x5ea0('0x68'),_0x5ea0('0x69')],'raw':!![]});}return null;})[_0x5ea0('0x18')](function(_0x29c2ba){if(!_0x29c2ba)return null;_0x21fa94['message'][_0x5ea0('0x66')]=_0x29c2ba;return _0x21fa94;})['then'](function(_0x17ced9){if(_0x17ced9){_0x17ced9[_0x5ea0('0x20')][_0x5ea0('0x6b')]=util['format'](_0x5ea0('0x6c'),_0x1322c4[_0x5ea0('0x55')][_0x5ea0('0x2f')]);_0x17ced9[_0x5ea0('0x20')][_0x5ea0('0x6d')]=_0x21fa94[_0x5ea0('0x6d')];_0x17ced9[_0x5ea0('0x20')][_0x5ea0('0x6e')]=_0x21fa94[_0x5ea0('0x6d')];_0x17ced9[_0x5ea0('0x20')]['event']='reject';respondWithRpcPromise('EventManager',_0x5ea0('0x70'),{'event':'rejectmessage','message':_0x17ced9[_0x5ea0('0x20')]},client9002);return _0x21fa94;}return null;})[_0x5ea0('0x18')](respondWithResult(_0x32dfeb,null))[_0x5ea0('0x22')](handleError(_0x32dfeb,null));};exports['create']=function(_0x10b38a,_0x233d6e){var _0x46a477;return db[_0x5ea0('0x31')]['create'](_0x10b38a[_0x5ea0('0x4d')],{})[_0x5ea0('0x18')](function(_0x100a83){_0x46a477=_0x100a83;return db[_0x5ea0('0x77')][_0x5ea0('0x78')]({'where':{'id':_0x46a477[_0x5ea0('0x61')]}});})['then'](function(_0x452b30){if(_[_0x5ea0('0x79')](_0x452b30)){return;}else{_0x46a477[_0x5ea0('0x71')]=_0x452b30[_0x5ea0('0x71')];return db[_0x5ea0('0x7a')][_0x5ea0('0x78')]({'where':{'id':_0x46a477['AttachmentId']}});}})[_0x5ea0('0x18')](function(_0x3e79fa){return respondWithRpcPromise(_0x5ea0('0x7b'),_0x5ea0('0x7b'),{'FaxAccountId':_[_0x5ea0('0x79')](_0x10b38a['body'])?undefined:_0x10b38a['body'][_0x5ea0('0x7c')],'path':_[_0x5ea0('0x79')](_0x3e79fa)?undefined:util[_0x5ea0('0x5a')](_0x5ea0('0x7d'),_0x3e79fa[_0x5ea0('0x7e')]),'fax':_[_0x5ea0('0x79')](_0x46a477['fax'])?undefined:_0x46a477[_0x5ea0('0x71')],'AttachmentId':_0x46a477['AttachmentId']},client9002);})[_0x5ea0('0x18')](respondWithResult(_0x233d6e,0xc9))['catch'](handleError(_0x233d6e,null));};exports[_0x5ea0('0x7f')]=function(_0x3ff6c4,_0x4565f5){var _0x59c522=path[_0x5ea0('0x80')](config['root'],_0x5ea0('0x81'),_0x5ea0('0x82'),_0x5ea0('0x83'));return db[_0x5ea0('0x31')][_0x5ea0('0x4b')]({'where':{'id':_0x3ff6c4[_0x5ea0('0x4a')]['id']},'include':[{'model':db['Attachment'],'as':'Attachment'}]})[_0x5ea0('0x18')](handleEntityNotFound(_0x4565f5,null))[_0x5ea0('0x18')](function(_0x2540d5){if(_0x2540d5){return _0x4565f5['download'](path['join'](_0x59c522,_0x2540d5['Attachment'][_0x5ea0('0x7e')]));}})[_0x5ea0('0x22')](handleError(_0x4565f5,null));};
\ No newline at end of file
+var _0xfc50=['Attachment','request-promise','moment','bluebird','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','../../mysqldb','redis','defaults','localhost','jayson/promise','client','http','request','FaxMessage,\x20%s,\x20%s','request\x20sent','debug','error','code','message','info','result','status','end','json','undefined','limit','count','offset','Content-Range','apply','reject','update','then','destroy','sendStatus','stack','name','index','map','FaxMessage','fieldName','type','key','model','query','filters','intersection','attributes','hasOwnProperty','sort','where','filter','merge','VIRTUAL','options','includeAll','include','rows','catch','params','rawAttributes','keys','fields','find','body','describe','fax','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','get','FaxInteraction','FaxInteractionId','isNil','read1stAt','interaction','[FAXMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','user','role','stringify','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','Sequelize','contact','User','fullname','email','internal','SIP/%s','channel','motionChannel','event','accept','EventManager','acceptmessage','agent','RejectMessage','rejectMessage','sequelize','QueryTypes','interface','rejectmessage','create','CmContact','findOne','AttachmentId','SendFax','FaxAccountId','/var/opt/motion2/server/files/attachments/%s','basename','download','join','root','server','files'];(function(_0xedd44e,_0x1f01a4){var _0x4ddcd6=function(_0x41bee2){while(--_0x41bee2){_0xedd44e['push'](_0xedd44e['shift']());}};_0x4ddcd6(++_0x1f01a4);}(_0xfc50,0x85));var _0x0fc5=function(_0x5b644e,_0x2e5e07){_0x5b644e=_0x5b644e-0x0;var _0x49c6bf=_0xfc50[_0x5b644e];return _0x49c6bf;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x0fc5('0x0'));var moment=require(_0x0fc5('0x1'));var BPromise=require(_0x0fc5('0x2'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require('sox');var csv=require(_0x0fc5('0x3'));var ejs=require(_0x0fc5('0x4'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x0fc5('0x5'));var squel=require(_0x0fc5('0x6'));var crypto=require(_0x0fc5('0x7'));var jsforce=require(_0x0fc5('0x8'));var deskjs=require(_0x0fc5('0x9'));var toCsv=require(_0x0fc5('0x3'));var querystring=require('querystring');var Papa=require(_0x0fc5('0xa'));var Redis=require(_0x0fc5('0xb'));var authService=require(_0x0fc5('0xc'));var qs=require(_0x0fc5('0xd'));var as=require(_0x0fc5('0xe'));var hardwareService=require(_0x0fc5('0xf'));var logger=require(_0x0fc5('0x10'))('api');var utils=require('../../config/utils');var config=require(_0x0fc5('0x11'));var licenseUtil=require('../../config/license/util');var db=require(_0x0fc5('0x12'))['db'];config[_0x0fc5('0x13')]=_[_0x0fc5('0x14')](config[_0x0fc5('0x13')],{'host':_0x0fc5('0x15'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require('./faxMessage.socket')['register'](socket);var jayson=require(_0x0fc5('0x16'));var client=jayson[_0x0fc5('0x17')][_0x0fc5('0x18')]({'port':0x232c});var client9002=jayson[_0x0fc5('0x17')][_0x0fc5('0x18')]({'port':0x232a});function respondWithRpcPromise(_0x1b6c80,_0x2d7dad,_0x328eda,_0x4e1ad1){return new BPromise(function(_0x4a6847,_0x3a8c11){var _0x5b3a42=_0x4e1ad1||client;return _0x5b3a42[_0x0fc5('0x19')](_0x1b6c80,_0x328eda)['then'](function(_0x1acff2){logger['info'](_0x0fc5('0x1a'),_0x2d7dad,_0x0fc5('0x1b'));logger[_0x0fc5('0x1c')]('FaxMessage,\x20%s,\x20%s,\x20%s',_0x2d7dad,_0x0fc5('0x1b'),JSON['stringify'](_0x1acff2));if(_0x1acff2[_0x0fc5('0x1d')]){if(_0x1acff2[_0x0fc5('0x1d')][_0x0fc5('0x1e')]===0x1f4){logger[_0x0fc5('0x1d')](_0x0fc5('0x1a'),_0x2d7dad,_0x1acff2[_0x0fc5('0x1d')][_0x0fc5('0x1f')]);return _0x3a8c11(_0x1acff2[_0x0fc5('0x1d')][_0x0fc5('0x1f')]);}logger[_0x0fc5('0x1d')](_0x0fc5('0x1a'),_0x2d7dad,_0x1acff2['error'][_0x0fc5('0x1f')]);return _0x4a6847(_0x1acff2[_0x0fc5('0x1d')][_0x0fc5('0x1f')]);}else{logger[_0x0fc5('0x20')](_0x0fc5('0x1a'),_0x2d7dad,_0x0fc5('0x1b'));_0x4a6847(_0x1acff2[_0x0fc5('0x21')][_0x0fc5('0x1f')]);}})['catch'](function(_0xe41836){logger['error']('FaxMessage,\x20%s,\x20%s',_0x2d7dad,_0xe41836);_0x3a8c11(_0xe41836);});});}function respondWithStatusCode(_0x8004c6,_0x159c4e){_0x159c4e=_0x159c4e||0xcc;return function(_0x593b2e){if(_0x593b2e){return _0x8004c6['sendStatus'](_0x159c4e);}return _0x8004c6[_0x0fc5('0x22')](_0x159c4e)[_0x0fc5('0x23')]();};}function respondWithResult(_0x24a73a,_0x38d1bd){_0x38d1bd=_0x38d1bd||0xc8;return function(_0x2be52a){if(_0x2be52a){return _0x24a73a[_0x0fc5('0x22')](_0x38d1bd)[_0x0fc5('0x24')](_0x2be52a);}};}function respondWithFilteredResult(_0x35729e,_0x5b72e3){return function(_0x5d7bf0){if(_0x5d7bf0){var _0x43ab35=typeof _0x5b72e3['offset']===_0x0fc5('0x25')&&typeof _0x5b72e3[_0x0fc5('0x26')]===_0x0fc5('0x25');var _0x6e74f8=_0x5d7bf0[_0x0fc5('0x27')];var _0x5418ef=_0x43ab35?0x0:_0x5b72e3[_0x0fc5('0x28')];var _0x32f96c=_0x43ab35?_0x5d7bf0[_0x0fc5('0x27')]:_0x5b72e3[_0x0fc5('0x28')]+_0x5b72e3[_0x0fc5('0x26')];var _0xe6b5cd;if(_0x32f96c>=_0x6e74f8){_0x32f96c=_0x6e74f8;_0xe6b5cd=0xc8;}else{_0xe6b5cd=0xce;}_0x35729e[_0x0fc5('0x22')](_0xe6b5cd);return _0x35729e['set'](_0x0fc5('0x29'),_0x5418ef+'-'+_0x32f96c+'/'+_0x6e74f8)[_0x0fc5('0x24')](_0x5d7bf0);}return null;};}function patchUpdates(_0x3194e6){return function(_0x3e5970){try{jsonpatch[_0x0fc5('0x2a')](_0x3e5970,_0x3194e6,!![]);}catch(_0x3e3948){return BPromise[_0x0fc5('0x2b')](_0x3e3948);}return _0x3e5970['save']();};}function saveUpdates(_0x6ee3b4,_0x1ca3da){return function(_0x566288){if(_0x566288){return _0x566288[_0x0fc5('0x2c')](_0x6ee3b4)[_0x0fc5('0x2d')](function(_0x2fe782){return _0x2fe782;});}return null;};}function removeEntity(_0x573211,_0x2184ec){return function(_0x206eb0){if(_0x206eb0){return _0x206eb0[_0x0fc5('0x2e')]()['then'](function(){_0x573211[_0x0fc5('0x22')](0xcc)['end']();});}};}function handleEntityNotFound(_0x251f7a,_0x258598){return function(_0x45fb34){if(!_0x45fb34){_0x251f7a[_0x0fc5('0x2f')](0x194);}return _0x45fb34;};}function handleError(_0xa581f9,_0x4b123a){_0x4b123a=_0x4b123a||0x1f4;return function(_0x3a8b4e){logger[_0x0fc5('0x1d')](_0x3a8b4e[_0x0fc5('0x30')]);if(_0x3a8b4e[_0x0fc5('0x31')]){delete _0x3a8b4e[_0x0fc5('0x31')];}_0xa581f9[_0x0fc5('0x22')](_0x4b123a)['send'](_0x3a8b4e);};}exports[_0x0fc5('0x32')]=function(_0x9d4238,_0x2b38a1){var _0x425b26={},_0x1d15b2={},_0x45a44a={'count':0x0,'rows':[]};var _0x146979=_[_0x0fc5('0x33')](db[_0x0fc5('0x34')]['rawAttributes'],function(_0x590c7a){return{'name':_0x590c7a[_0x0fc5('0x35')],'type':_0x590c7a[_0x0fc5('0x36')][_0x0fc5('0x37')]};});_0x1d15b2[_0x0fc5('0x38')]=_[_0x0fc5('0x33')](_0x146979,_0x0fc5('0x31'));_0x1d15b2[_0x0fc5('0x39')]=_['keys'](_0x9d4238[_0x0fc5('0x39')]);_0x1d15b2[_0x0fc5('0x3a')]=_[_0x0fc5('0x3b')](_0x1d15b2[_0x0fc5('0x38')],_0x1d15b2['query']);_0x425b26[_0x0fc5('0x3c')]=_['intersection'](_0x1d15b2[_0x0fc5('0x38')],qs['fields'](_0x9d4238[_0x0fc5('0x39')]['fields']));_0x425b26[_0x0fc5('0x3c')]=_0x425b26[_0x0fc5('0x3c')]['length']?_0x425b26[_0x0fc5('0x3c')]:_0x1d15b2['model'];if(!_0x9d4238[_0x0fc5('0x39')][_0x0fc5('0x3d')]('nolimit')){_0x425b26['limit']=qs[_0x0fc5('0x26')](_0x9d4238[_0x0fc5('0x39')][_0x0fc5('0x26')]);_0x425b26[_0x0fc5('0x28')]=qs[_0x0fc5('0x28')](_0x9d4238['query'][_0x0fc5('0x28')]);}_0x425b26['order']=qs[_0x0fc5('0x3e')](_0x9d4238[_0x0fc5('0x39')]['sort']);_0x425b26[_0x0fc5('0x3f')]=qs[_0x0fc5('0x3a')](_['pick'](_0x9d4238['query'],_0x1d15b2['filters']),_0x146979);if(_0x9d4238[_0x0fc5('0x39')][_0x0fc5('0x40')]){_0x425b26['where']=_[_0x0fc5('0x41')](_0x425b26[_0x0fc5('0x3f')],{'$or':_[_0x0fc5('0x33')](_0x146979,function(_0x3ed2ea){if(_0x3ed2ea[_0x0fc5('0x36')]!==_0x0fc5('0x42')){var _0x30ef98={};_0x30ef98[_0x3ed2ea[_0x0fc5('0x31')]]={'$like':'%'+_0x9d4238['query'][_0x0fc5('0x40')]+'%'};return _0x30ef98;}})});}_0x425b26=_[_0x0fc5('0x41')]({},_0x425b26,_0x9d4238[_0x0fc5('0x43')]);var _0x16d157={'where':_0x425b26[_0x0fc5('0x3f')]};return db[_0x0fc5('0x34')][_0x0fc5('0x27')](_0x16d157)[_0x0fc5('0x2d')](function(_0x1abca0){_0x45a44a['count']=_0x1abca0;if(_0x9d4238[_0x0fc5('0x39')][_0x0fc5('0x44')]){_0x425b26[_0x0fc5('0x45')]=[{'all':!![]}];}return db[_0x0fc5('0x34')]['findAll'](_0x425b26);})[_0x0fc5('0x2d')](function(_0x5a27aa){_0x45a44a[_0x0fc5('0x46')]=_0x5a27aa;return _0x45a44a;})[_0x0fc5('0x2d')](respondWithFilteredResult(_0x2b38a1,_0x425b26))[_0x0fc5('0x47')](handleError(_0x2b38a1,null));};exports['show']=function(_0x5e7ae4,_0x252314){var _0x523805={'raw':!![],'where':{'id':_0x5e7ae4[_0x0fc5('0x48')]['id']}},_0x3d747d={};_0x3d747d['model']=_['keys'](db['FaxMessage'][_0x0fc5('0x49')]);_0x3d747d[_0x0fc5('0x39')]=_[_0x0fc5('0x4a')](_0x5e7ae4['query']);_0x3d747d[_0x0fc5('0x3a')]=_[_0x0fc5('0x3b')](_0x3d747d['model'],_0x3d747d['query']);_0x523805[_0x0fc5('0x3c')]=_[_0x0fc5('0x3b')](_0x3d747d[_0x0fc5('0x38')],qs[_0x0fc5('0x4b')](_0x5e7ae4[_0x0fc5('0x39')][_0x0fc5('0x4b')]));_0x523805['attributes']=_0x523805[_0x0fc5('0x3c')]['length']?_0x523805[_0x0fc5('0x3c')]:_0x3d747d[_0x0fc5('0x38')];if(_0x5e7ae4[_0x0fc5('0x39')][_0x0fc5('0x44')]){_0x523805['include']=[{'all':!![]}];}_0x523805=_[_0x0fc5('0x41')]({},_0x523805,_0x5e7ae4[_0x0fc5('0x43')]);return db[_0x0fc5('0x34')][_0x0fc5('0x4c')](_0x523805)['then'](handleEntityNotFound(_0x252314,null))[_0x0fc5('0x2d')](respondWithResult(_0x252314,null))[_0x0fc5('0x47')](handleError(_0x252314,null));};exports[_0x0fc5('0x2c')]=function(_0x37f7e6,_0x3aa214){if(_0x37f7e6[_0x0fc5('0x4d')]['id']){delete _0x37f7e6[_0x0fc5('0x4d')]['id'];}return db['FaxMessage'][_0x0fc5('0x4c')]({'where':{'id':_0x37f7e6[_0x0fc5('0x48')]['id']}})[_0x0fc5('0x2d')](handleEntityNotFound(_0x3aa214,null))[_0x0fc5('0x2d')](saveUpdates(_0x37f7e6[_0x0fc5('0x4d')],null))['then'](respondWithResult(_0x3aa214,null))[_0x0fc5('0x47')](handleError(_0x3aa214,null));};exports['destroy']=function(_0x1cb0d2,_0x49ede2){return db['FaxMessage']['find']({'where':{'id':_0x1cb0d2[_0x0fc5('0x48')]['id']}})[_0x0fc5('0x2d')](handleEntityNotFound(_0x49ede2,null))[_0x0fc5('0x2d')](removeEntity(_0x49ede2,null))[_0x0fc5('0x47')](handleError(_0x49ede2,null));};exports[_0x0fc5('0x4e')]=function(_0x473490,_0x4086ea){return db['FaxMessage'][_0x0fc5('0x4e')]()[_0x0fc5('0x2d')](respondWithResult(_0x4086ea,null))['catch'](handleError(_0x4086ea,null));};var interaction_log=require(_0x0fc5('0x10'))('fax-interactions');exports['accept']=function(_0x59f202,_0x200018,_0x1f2847){var _0x332b3f={'agent':{},'channel':_0x0fc5('0x4f')};if(_0x59f202[_0x0fc5('0x4d')]['id']){delete _0x59f202[_0x0fc5('0x4d')]['id'];}_0x59f202[_0x0fc5('0x4d')][_0x0fc5('0x50')]=!![];_0x59f202[_0x0fc5('0x4d')][_0x0fc5('0x51')]=moment()[_0x0fc5('0x52')](_0x0fc5('0x53'));_0x59f202[_0x0fc5('0x4d')]['UserId']=_0x59f202[_0x0fc5('0x4d')][_0x0fc5('0x54')]||_0x59f202['user']['id'];_0x332b3f['agent']['id']=_0x59f202['body'][_0x0fc5('0x54')];return db[_0x0fc5('0x34')][_0x0fc5('0x4c')]({'where':{'id':_0x59f202[_0x0fc5('0x48')]['id'],'UserId':null}})[_0x0fc5('0x2d')](handleEntityNotFound(_0x200018,null))[_0x0fc5('0x2d')](saveUpdates(_0x59f202[_0x0fc5('0x4d')],null))['then'](function(_0xa68ee1){if(_0xa68ee1){_0x332b3f[_0x0fc5('0x1f')]=_0xa68ee1[_0x0fc5('0x55')]({'plain':!![]});return db[_0x0fc5('0x56')][_0x0fc5('0x4c')]({'where':{'id':_0xa68ee1[_0x0fc5('0x57')]}});}return null;})['then'](handleEntityNotFound(_0x200018,null))['then'](function(_0x18f687){if(_0x18f687){return _0x18f687[_0x0fc5('0x2c')]({'UserId':_0x59f202[_0x0fc5('0x4d')]['UserId'],'read1stAt':_[_0x0fc5('0x58')](_0x18f687[_0x0fc5('0x59')])?moment()['format']('YYYY-MM-DD\x20HH:mm:ss'):undefined});}return null;})['then'](function(_0x43eb81){if(_0x43eb81){_0x332b3f[_0x0fc5('0x5a')]=_0x43eb81[_0x0fc5('0x55')]({'plain':!![]});interaction_log['info'](_0x0fc5('0x5b'),_0x59f202[_0x0fc5('0x5c')]['id'],_0x59f202['user'][_0x0fc5('0x31')],_0x59f202[_0x0fc5('0x5c')][_0x0fc5('0x5d')],_0x332b3f[_0x0fc5('0x5a')]['id'],_0x59f202['body']?JSON[_0x0fc5('0x5e')](_0x59f202['body']):'null');return respondWithRpcPromise('AcceptMessage',_0x0fc5('0x5f'),_0x332b3f);}return null;})[_0x0fc5('0x2d')](function(_0xa0c2f6){var _0x1d0f90=_0x0fc5('0x60')+_0xa0c2f6[_0x0fc5('0x1f')][_0x0fc5('0x61')];return db['sequelize'][_0x0fc5('0x39')](_0x1d0f90,{'type':db[_0x0fc5('0x62')]['QueryTypes']['SELECT'],'raw':!![]})[_0x0fc5('0x2d')](function(_0x61e5c7){return _0x61e5c7;});})[_0x0fc5('0x2d')](function(_0x252a4a){if(_0x252a4a){_0x332b3f[_0x0fc5('0x1f')][_0x0fc5('0x63')]=_0x252a4a[0x0];if(!_0x59f202[_0x0fc5('0x4d')][_0x0fc5('0x54')])return;return db[_0x0fc5('0x64')][_0x0fc5('0x4c')]({'where':{'id':_0x59f202['body']['UserId'],'role':'agent'},'attributes':['id',_0x0fc5('0x31'),_0x0fc5('0x65'),_0x0fc5('0x66'),_0x0fc5('0x67')],'raw':!![]});}return null;})[_0x0fc5('0x2d')](function(_0x163e7f){if(!_0x163e7f)return null;_0x332b3f[_0x0fc5('0x1f')]['agent']=_0x163e7f;return _0x332b3f;})[_0x0fc5('0x2d')](function(_0xfb0105){if(_0xfb0105){if(_0x59f202[_0x0fc5('0x4d')]['manual']){_0x332b3f[_0x0fc5('0x1f')]['interface']=util['format'](_0x0fc5('0x68'),_0x59f202[_0x0fc5('0x5c')][_0x0fc5('0x31')]);_0x332b3f[_0x0fc5('0x1f')][_0x0fc5('0x69')]=_0x332b3f['channel'];_0x332b3f['message'][_0x0fc5('0x6a')]=_0x332b3f[_0x0fc5('0x69')];_0x332b3f['message'][_0x0fc5('0x6b')]=_0x0fc5('0x6c');return respondWithRpcPromise('EventManager',_0x0fc5('0x6d'),{'event':_0x0fc5('0x6e'),'message':_0x332b3f[_0x0fc5('0x1f')]},client9002)['then'](function(){return _0x332b3f;});}return _0x332b3f;}return null;})[_0x0fc5('0x2d')](respondWithResult(_0x200018,null))['catch'](handleError(_0x200018,null));};var interaction_log=require(_0x0fc5('0x10'))('fax-interactions');exports[_0x0fc5('0x2b')]=function(_0x205a29,_0xa72d35,_0x43d8c){var _0x126b47={'agent':{},'channel':_0x0fc5('0x4f')};if(_0x205a29[_0x0fc5('0x4d')]['id']){delete _0x205a29[_0x0fc5('0x4d')]['id'];}_0x205a29[_0x0fc5('0x4d')][_0x0fc5('0x54')]=_0x205a29[_0x0fc5('0x4d')][_0x0fc5('0x54')]||_0x205a29[_0x0fc5('0x5c')]['id'];_0x126b47[_0x0fc5('0x6f')]['id']=_0x205a29[_0x0fc5('0x4d')]['UserId'];return db[_0x0fc5('0x34')][_0x0fc5('0x4c')]({'where':{'id':_0x205a29[_0x0fc5('0x48')]['id'],'UserId':null}})[_0x0fc5('0x2d')](handleEntityNotFound(_0xa72d35,null))[_0x0fc5('0x2d')](function(_0x217ce4){if(_0x217ce4){_0x126b47[_0x0fc5('0x1f')]=_0x217ce4[_0x0fc5('0x55')]({'plain':!![]});return db[_0x0fc5('0x56')][_0x0fc5('0x4c')]({'where':{'id':_0x217ce4[_0x0fc5('0x57')]}});}return null;})[_0x0fc5('0x2d')](handleEntityNotFound(_0xa72d35,null))[_0x0fc5('0x2d')](function(_0x54d999){if(_0x54d999){_0x126b47['interaction']=_0x54d999[_0x0fc5('0x55')]({'plain':!![]});interaction_log[_0x0fc5('0x20')]('[FAXMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x205a29['user']['id'],_0x205a29[_0x0fc5('0x5c')]['name'],_0x205a29['user'][_0x0fc5('0x5d')],_0x126b47[_0x0fc5('0x5a')]['id'],_0x205a29['body']?JSON[_0x0fc5('0x5e')](_0x205a29[_0x0fc5('0x4d')]):'null');return respondWithRpcPromise(_0x0fc5('0x70'),_0x0fc5('0x71'),_0x126b47);}return null;})[_0x0fc5('0x2d')](function(_0x16a442){var _0x126780=_0x0fc5('0x60')+_0x16a442[_0x0fc5('0x1f')][_0x0fc5('0x61')];return db[_0x0fc5('0x72')]['query'](_0x126780,{'type':db[_0x0fc5('0x62')][_0x0fc5('0x73')]['SELECT'],'raw':!![]})['then'](function(_0x4ef050){return _0x4ef050;});})[_0x0fc5('0x2d')](function(_0x550716){if(_0x550716){_0x126b47['message'][_0x0fc5('0x63')]=_0x550716[0x0];if(!_0x205a29[_0x0fc5('0x4d')]['UserId'])return;return db[_0x0fc5('0x64')][_0x0fc5('0x4c')]({'where':{'id':_0x205a29[_0x0fc5('0x4d')][_0x0fc5('0x54')],'role':_0x0fc5('0x6f')},'attributes':['id',_0x0fc5('0x31'),_0x0fc5('0x65'),_0x0fc5('0x66'),_0x0fc5('0x67')],'raw':!![]});}return null;})[_0x0fc5('0x2d')](function(_0x801764){if(!_0x801764)return null;_0x126b47[_0x0fc5('0x1f')]['agent']=_0x801764;return _0x126b47;})[_0x0fc5('0x2d')](function(_0x2faf73){if(_0x2faf73){_0x2faf73['message'][_0x0fc5('0x74')]=util['format'](_0x0fc5('0x68'),_0x205a29[_0x0fc5('0x5c')]['name']);_0x2faf73[_0x0fc5('0x1f')][_0x0fc5('0x69')]=_0x126b47[_0x0fc5('0x69')];_0x2faf73[_0x0fc5('0x1f')][_0x0fc5('0x6a')]=_0x126b47['channel'];_0x2faf73[_0x0fc5('0x1f')][_0x0fc5('0x6b')]=_0x0fc5('0x2b');respondWithRpcPromise(_0x0fc5('0x6d'),_0x0fc5('0x6d'),{'event':_0x0fc5('0x75'),'message':_0x2faf73[_0x0fc5('0x1f')]},client9002);return _0x126b47;}return null;})['then'](respondWithResult(_0xa72d35,null))[_0x0fc5('0x47')](handleError(_0xa72d35,null));};exports[_0x0fc5('0x76')]=function(_0x4631eb,_0x3d6b85){var _0x3acf54;return db['FaxMessage'][_0x0fc5('0x76')](_0x4631eb[_0x0fc5('0x4d')],{})[_0x0fc5('0x2d')](function(_0x5e9c0e){_0x3acf54=_0x5e9c0e;return db[_0x0fc5('0x77')]['findOne']({'where':{'id':_0x3acf54[_0x0fc5('0x61')]}});})[_0x0fc5('0x2d')](function(_0x553431){if(_[_0x0fc5('0x58')](_0x553431)){return;}else{_0x3acf54[_0x0fc5('0x4f')]=_0x553431['fax'];return db['Attachment'][_0x0fc5('0x78')]({'where':{'id':_0x3acf54[_0x0fc5('0x79')]}});}})[_0x0fc5('0x2d')](function(_0x23286c){return respondWithRpcPromise(_0x0fc5('0x7a'),_0x0fc5('0x7a'),{'FaxAccountId':_[_0x0fc5('0x58')](_0x4631eb[_0x0fc5('0x4d')])?undefined:_0x4631eb[_0x0fc5('0x4d')][_0x0fc5('0x7b')],'path':_[_0x0fc5('0x58')](_0x23286c)?undefined:util['format'](_0x0fc5('0x7c'),_0x23286c[_0x0fc5('0x7d')]),'fax':_['isNil'](_0x3acf54[_0x0fc5('0x4f')])?undefined:_0x3acf54['fax'],'AttachmentId':_0x3acf54[_0x0fc5('0x79')]},client9002);})[_0x0fc5('0x2d')](respondWithResult(_0x3d6b85,0xc9))[_0x0fc5('0x47')](handleError(_0x3d6b85,null));};exports[_0x0fc5('0x7e')]=function(_0x128b76,_0x2d1870){var _0x4477e7=path[_0x0fc5('0x7f')](config[_0x0fc5('0x80')],_0x0fc5('0x81'),_0x0fc5('0x82'),'attachments');return db[_0x0fc5('0x34')][_0x0fc5('0x4c')]({'where':{'id':_0x128b76[_0x0fc5('0x48')]['id']},'include':[{'model':db[_0x0fc5('0x83')],'as':_0x0fc5('0x83')}]})['then'](handleEntityNotFound(_0x2d1870,null))[_0x0fc5('0x2d')](function(_0x244683){if(_0x244683){return _0x2d1870[_0x0fc5('0x7e')](path[_0x0fc5('0x7f')](_0x4477e7,_0x244683['Attachment'][_0x0fc5('0x7d')]));}})[_0x0fc5('0x47')](handleError(_0x2d1870,null));};
\ No newline at end of file