Built motion from commit b5413ace.|2.6.9
[motion2.git] / server / api / faxMessage / faxMessage.controller.js
index aec2dc9..b541b3e 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x84cb=['user','agent','get','FaxInteraction','isNil','read1stAt','YYYY-MM-DD\x20HH:mm:ss','interaction','null','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','sequelize','contact','User','email','internal','manual','channel','event','EventManager','acceptmessage','reject','FaxInteractionId','[FAXMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','ContactId','Sequelize','QueryTypes','SELECT','fullname','SIP/%s','rejectmessage','CmContact','findOne','Attachment','SendFax','FaxAccountId','/var/opt/motion2/server/files/attachments/%s','basename','AttachmentId','download','root','files','attachments','join','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','path','sox','to-csv','ejs','lodash','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','jayson/promise','client','http','request','then','FaxMessage,\x20%s,\x20%s','request\x20sent','debug','stringify','code','error','message','info','result','catch','status','json','offset','undefined','limit','count','set','Content-Range','apply','save','destroy','end','sendStatus','name','send','FaxMessage','rawAttributes','fieldName','type','key','query','keys','filters','model','attributes','fields','length','hasOwnProperty','nolimit','sort','pick','filter','where','merge','map','VIRTUAL','options','includeAll','include','findAll','rows','show','intersection','update','body','find','params','describe','fax-interactions','accept','fax','format','UserId'];(function(_0x2e7087,_0x112eec){var _0xb5b3a6=function(_0x296310){while(--_0x296310){_0x2e7087['push'](_0x2e7087['shift']());}};_0xb5b3a6(++_0x112eec);}(_0x84cb,0x153));var _0xb84c=function(_0xb4ea77,_0x392f42){_0xb4ea77=_0xb4ea77-0x0;var _0x2075c6=_0x84cb[_0xb4ea77];return _0x2075c6;};'use strict';var emlformat=require(_0xb84c('0x0'));var rimraf=require(_0xb84c('0x1'));var zipdir=require(_0xb84c('0x2'));var jsonpatch=require(_0xb84c('0x3'));var rp=require(_0xb84c('0x4'));var moment=require(_0xb84c('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xb84c('0x6'));var util=require('util');var path=require(_0xb84c('0x7'));var sox=require(_0xb84c('0x8'));var csv=require(_0xb84c('0x9'));var ejs=require(_0xb84c('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xb84c('0xb'));var squel=require('squel');var crypto=require(_0xb84c('0xc'));var jsforce=require('jsforce');var deskjs=require(_0xb84c('0xd'));var toCsv=require(_0xb84c('0x9'));var querystring=require(_0xb84c('0xe'));var Papa=require(_0xb84c('0xf'));var Redis=require(_0xb84c('0x10'));var authService=require(_0xb84c('0x11'));var qs=require(_0xb84c('0x12'));var as=require(_0xb84c('0x13'));var hardwareService=require(_0xb84c('0x14'));var logger=require(_0xb84c('0x15'))(_0xb84c('0x16'));var utils=require(_0xb84c('0x17'));var config=require(_0xb84c('0x18'));var licenseUtil=require(_0xb84c('0x19'));var db=require(_0xb84c('0x1a'))['db'];config[_0xb84c('0x1b')]=_[_0xb84c('0x1c')](config[_0xb84c('0x1b')],{'host':_0xb84c('0x1d'),'port':0x18eb});var socket=require(_0xb84c('0x1e'))(new Redis(config[_0xb84c('0x1b')]));require('./faxMessage.socket')['register'](socket);var jayson=require(_0xb84c('0x1f'));var client=jayson[_0xb84c('0x20')][_0xb84c('0x21')]({'port':0x232c});var client9002=jayson[_0xb84c('0x20')][_0xb84c('0x21')]({'port':0x232a});function respondWithRpcPromise(_0x57e4af,_0x52fa2c,_0x3e6ebc,_0x5d1540){return new BPromise(function(_0x2b2c2f,_0x15f1a2){var _0x285d67=_0x5d1540||client;return _0x285d67[_0xb84c('0x22')](_0x57e4af,_0x3e6ebc)[_0xb84c('0x23')](function(_0x5bae59){logger['info'](_0xb84c('0x24'),_0x52fa2c,_0xb84c('0x25'));logger[_0xb84c('0x26')]('FaxMessage,\x20%s,\x20%s,\x20%s',_0x52fa2c,_0xb84c('0x25'),JSON[_0xb84c('0x27')](_0x5bae59));if(_0x5bae59['error']){if(_0x5bae59['error'][_0xb84c('0x28')]===0x1f4){logger[_0xb84c('0x29')]('FaxMessage,\x20%s,\x20%s',_0x52fa2c,_0x5bae59['error']['message']);return _0x15f1a2(_0x5bae59['error']['message']);}logger[_0xb84c('0x29')](_0xb84c('0x24'),_0x52fa2c,_0x5bae59[_0xb84c('0x29')][_0xb84c('0x2a')]);return _0x2b2c2f(_0x5bae59[_0xb84c('0x29')][_0xb84c('0x2a')]);}else{logger[_0xb84c('0x2b')](_0xb84c('0x24'),_0x52fa2c,_0xb84c('0x25'));_0x2b2c2f(_0x5bae59[_0xb84c('0x2c')][_0xb84c('0x2a')]);}})[_0xb84c('0x2d')](function(_0x47548b){logger[_0xb84c('0x29')](_0xb84c('0x24'),_0x52fa2c,_0x47548b);_0x15f1a2(_0x47548b);});});}function respondWithStatusCode(_0x5a614b,_0x183e78){_0x183e78=_0x183e78||0xcc;return function(_0x4a1e4c){if(_0x4a1e4c){return _0x5a614b['sendStatus'](_0x183e78);}return _0x5a614b['status'](_0x183e78)['end']();};}function respondWithResult(_0x54b346,_0x12d8f5){_0x12d8f5=_0x12d8f5||0xc8;return function(_0x61fbcc){if(_0x61fbcc){return _0x54b346[_0xb84c('0x2e')](_0x12d8f5)[_0xb84c('0x2f')](_0x61fbcc);}};}function respondWithFilteredResult(_0x2514b5,_0x2e8aec){return function(_0x49a16a){if(_0x49a16a){var _0x5c6fa1=typeof _0x2e8aec[_0xb84c('0x30')]===_0xb84c('0x31')&&typeof _0x2e8aec[_0xb84c('0x32')]==='undefined';var _0x2bc19e=_0x49a16a[_0xb84c('0x33')];var _0x2c04eb=_0x5c6fa1?0x0:_0x2e8aec[_0xb84c('0x30')];var _0x701fff=_0x5c6fa1?_0x49a16a[_0xb84c('0x33')]:_0x2e8aec[_0xb84c('0x30')]+_0x2e8aec['limit'];var _0x26080f;if(_0x701fff>=_0x2bc19e){_0x701fff=_0x2bc19e;_0x26080f=0xc8;}else{_0x26080f=0xce;}_0x2514b5[_0xb84c('0x2e')](_0x26080f);return _0x2514b5[_0xb84c('0x34')](_0xb84c('0x35'),_0x2c04eb+'-'+_0x701fff+'/'+_0x2bc19e)[_0xb84c('0x2f')](_0x49a16a);}return null;};}function patchUpdates(_0x423be4){return function(_0x1a5998){try{jsonpatch[_0xb84c('0x36')](_0x1a5998,_0x423be4,!![]);}catch(_0x562508){return BPromise['reject'](_0x562508);}return _0x1a5998[_0xb84c('0x37')]();};}function saveUpdates(_0x392e86,_0x4dd854){return function(_0x4fe276){if(_0x4fe276){return _0x4fe276['update'](_0x392e86)[_0xb84c('0x23')](function(_0x8423ca){return _0x8423ca;});}return null;};}function removeEntity(_0x1f37d7,_0x103d46){return function(_0x3f9b24){if(_0x3f9b24){return _0x3f9b24[_0xb84c('0x38')]()[_0xb84c('0x23')](function(){_0x1f37d7[_0xb84c('0x2e')](0xcc)[_0xb84c('0x39')]();});}};}function handleEntityNotFound(_0x5b5248,_0x25bee0){return function(_0x4554b3){if(!_0x4554b3){_0x5b5248[_0xb84c('0x3a')](0x194);}return _0x4554b3;};}function handleError(_0x12f945,_0x450cbe){_0x450cbe=_0x450cbe||0x1f4;return function(_0x2e4227){logger['error'](_0x2e4227['stack']);if(_0x2e4227[_0xb84c('0x3b')]){delete _0x2e4227[_0xb84c('0x3b')];}_0x12f945['status'](_0x450cbe)[_0xb84c('0x3c')](_0x2e4227);};}exports['index']=function(_0x1bfd76,_0x2ccc3a){var _0x474455={},_0x17723c={},_0x3d8373={'count':0x0,'rows':[]};var _0x38dab9=_['map'](db[_0xb84c('0x3d')][_0xb84c('0x3e')],function(_0x9b019d){return{'name':_0x9b019d[_0xb84c('0x3f')],'type':_0x9b019d[_0xb84c('0x40')][_0xb84c('0x41')]};});_0x17723c['model']=_['map'](_0x38dab9,_0xb84c('0x3b'));_0x17723c[_0xb84c('0x42')]=_[_0xb84c('0x43')](_0x1bfd76[_0xb84c('0x42')]);_0x17723c[_0xb84c('0x44')]=_['intersection'](_0x17723c[_0xb84c('0x45')],_0x17723c[_0xb84c('0x42')]);_0x474455[_0xb84c('0x46')]=_['intersection'](_0x17723c[_0xb84c('0x45')],qs[_0xb84c('0x47')](_0x1bfd76['query']['fields']));_0x474455[_0xb84c('0x46')]=_0x474455[_0xb84c('0x46')][_0xb84c('0x48')]?_0x474455[_0xb84c('0x46')]:_0x17723c['model'];if(!_0x1bfd76[_0xb84c('0x42')][_0xb84c('0x49')](_0xb84c('0x4a'))){_0x474455['limit']=qs[_0xb84c('0x32')](_0x1bfd76[_0xb84c('0x42')][_0xb84c('0x32')]);_0x474455[_0xb84c('0x30')]=qs[_0xb84c('0x30')](_0x1bfd76[_0xb84c('0x42')]['offset']);}_0x474455['order']=qs[_0xb84c('0x4b')](_0x1bfd76[_0xb84c('0x42')][_0xb84c('0x4b')]);_0x474455['where']=qs['filters'](_[_0xb84c('0x4c')](_0x1bfd76[_0xb84c('0x42')],_0x17723c['filters']),_0x38dab9);if(_0x1bfd76[_0xb84c('0x42')][_0xb84c('0x4d')]){_0x474455[_0xb84c('0x4e')]=_[_0xb84c('0x4f')](_0x474455[_0xb84c('0x4e')],{'$or':_[_0xb84c('0x50')](_0x38dab9,function(_0x3dff05){if(_0x3dff05[_0xb84c('0x40')]!==_0xb84c('0x51')){var _0x4d5fb0={};_0x4d5fb0[_0x3dff05[_0xb84c('0x3b')]]={'$like':'%'+_0x1bfd76[_0xb84c('0x42')][_0xb84c('0x4d')]+'%'};return _0x4d5fb0;}})});}_0x474455=_[_0xb84c('0x4f')]({},_0x474455,_0x1bfd76[_0xb84c('0x52')]);var _0x40f5b7={'where':_0x474455[_0xb84c('0x4e')]};return db['FaxMessage'][_0xb84c('0x33')](_0x40f5b7)[_0xb84c('0x23')](function(_0x24b169){_0x3d8373[_0xb84c('0x33')]=_0x24b169;if(_0x1bfd76[_0xb84c('0x42')][_0xb84c('0x53')]){_0x474455[_0xb84c('0x54')]=[{'all':!![]}];}return db['FaxMessage'][_0xb84c('0x55')](_0x474455);})[_0xb84c('0x23')](function(_0x11a928){_0x3d8373[_0xb84c('0x56')]=_0x11a928;return _0x3d8373;})[_0xb84c('0x23')](respondWithFilteredResult(_0x2ccc3a,_0x474455))[_0xb84c('0x2d')](handleError(_0x2ccc3a,null));};exports[_0xb84c('0x57')]=function(_0x4c0abb,_0xdfbf13){var _0x5b641f={'raw':!![],'where':{'id':_0x4c0abb['params']['id']}},_0x1f761a={};_0x1f761a[_0xb84c('0x45')]=_[_0xb84c('0x43')](db[_0xb84c('0x3d')][_0xb84c('0x3e')]);_0x1f761a[_0xb84c('0x42')]=_[_0xb84c('0x43')](_0x4c0abb[_0xb84c('0x42')]);_0x1f761a[_0xb84c('0x44')]=_[_0xb84c('0x58')](_0x1f761a[_0xb84c('0x45')],_0x1f761a[_0xb84c('0x42')]);_0x5b641f[_0xb84c('0x46')]=_[_0xb84c('0x58')](_0x1f761a[_0xb84c('0x45')],qs[_0xb84c('0x47')](_0x4c0abb[_0xb84c('0x42')][_0xb84c('0x47')]));_0x5b641f[_0xb84c('0x46')]=_0x5b641f[_0xb84c('0x46')][_0xb84c('0x48')]?_0x5b641f[_0xb84c('0x46')]:_0x1f761a[_0xb84c('0x45')];if(_0x4c0abb[_0xb84c('0x42')][_0xb84c('0x53')]){_0x5b641f[_0xb84c('0x54')]=[{'all':!![]}];}_0x5b641f=_[_0xb84c('0x4f')]({},_0x5b641f,_0x4c0abb[_0xb84c('0x52')]);return db[_0xb84c('0x3d')]['find'](_0x5b641f)[_0xb84c('0x23')](handleEntityNotFound(_0xdfbf13,null))[_0xb84c('0x23')](respondWithResult(_0xdfbf13,null))[_0xb84c('0x2d')](handleError(_0xdfbf13,null));};exports[_0xb84c('0x59')]=function(_0x41c6c7,_0x37efa9){if(_0x41c6c7[_0xb84c('0x5a')]['id']){delete _0x41c6c7[_0xb84c('0x5a')]['id'];}return db[_0xb84c('0x3d')][_0xb84c('0x5b')]({'where':{'id':_0x41c6c7[_0xb84c('0x5c')]['id']}})[_0xb84c('0x23')](handleEntityNotFound(_0x37efa9,null))[_0xb84c('0x23')](saveUpdates(_0x41c6c7['body'],null))[_0xb84c('0x23')](respondWithResult(_0x37efa9,null))[_0xb84c('0x2d')](handleError(_0x37efa9,null));};exports['destroy']=function(_0x40b784,_0x4455ed){return db[_0xb84c('0x3d')][_0xb84c('0x5b')]({'where':{'id':_0x40b784['params']['id']}})['then'](handleEntityNotFound(_0x4455ed,null))[_0xb84c('0x23')](removeEntity(_0x4455ed,null))[_0xb84c('0x2d')](handleError(_0x4455ed,null));};exports['describe']=function(_0x5b361d,_0x1f8bee){return db[_0xb84c('0x3d')][_0xb84c('0x5d')]()[_0xb84c('0x23')](respondWithResult(_0x1f8bee,null))[_0xb84c('0x2d')](handleError(_0x1f8bee,null));};var interaction_log=require(_0xb84c('0x15'))(_0xb84c('0x5e'));exports[_0xb84c('0x5f')]=function(_0x18b51f,_0xe502bb,_0x22629c){var _0x2dda7c={'agent':{},'channel':_0xb84c('0x60')};if(_0x18b51f[_0xb84c('0x5a')]['id']){delete _0x18b51f['body']['id'];}_0x18b51f[_0xb84c('0x5a')]['read']=!![];_0x18b51f['body']['readAt']=moment()[_0xb84c('0x61')]('YYYY-MM-DD\x20HH:mm:ss');_0x18b51f[_0xb84c('0x5a')][_0xb84c('0x62')]=_0x18b51f['body'][_0xb84c('0x62')]||_0x18b51f[_0xb84c('0x63')]['id'];_0x2dda7c[_0xb84c('0x64')]['id']=_0x18b51f['body'][_0xb84c('0x62')];return db[_0xb84c('0x3d')][_0xb84c('0x5b')]({'where':{'id':_0x18b51f[_0xb84c('0x5c')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0xe502bb,null))[_0xb84c('0x23')](saveUpdates(_0x18b51f[_0xb84c('0x5a')],null))[_0xb84c('0x23')](function(_0x4ecb79){if(_0x4ecb79){_0x2dda7c[_0xb84c('0x2a')]=_0x4ecb79[_0xb84c('0x65')]({'plain':!![]});return db[_0xb84c('0x66')][_0xb84c('0x5b')]({'where':{'id':_0x4ecb79['FaxInteractionId']}});}return null;})[_0xb84c('0x23')](handleEntityNotFound(_0xe502bb,null))[_0xb84c('0x23')](function(_0x5676f9){if(_0x5676f9){return _0x5676f9['update']({'UserId':_0x18b51f[_0xb84c('0x5a')][_0xb84c('0x62')],'read1stAt':_[_0xb84c('0x67')](_0x5676f9[_0xb84c('0x68')])?moment()[_0xb84c('0x61')](_0xb84c('0x69')):undefined});}return null;})['then'](function(_0x19a6ec){if(_0x19a6ec){_0x2dda7c[_0xb84c('0x6a')]=_0x19a6ec['get']({'plain':!![]});interaction_log[_0xb84c('0x2b')]('[FAXMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x18b51f[_0xb84c('0x63')]['id'],_0x18b51f[_0xb84c('0x63')]['name'],_0x18b51f[_0xb84c('0x63')]['role'],_0x2dda7c[_0xb84c('0x6a')]['id'],_0x18b51f[_0xb84c('0x5a')]?JSON[_0xb84c('0x27')](_0x18b51f[_0xb84c('0x5a')]):_0xb84c('0x6b'));return respondWithRpcPromise(_0xb84c('0x6c'),_0xb84c('0x6d'),_0x2dda7c);}return null;})[_0xb84c('0x23')](function(_0x206660){var _0x124353=_0xb84c('0x6e')+_0x206660[_0xb84c('0x2a')]['ContactId'];return db[_0xb84c('0x6f')]['query'](_0x124353,{'type':db['Sequelize']['QueryTypes']['SELECT'],'raw':!![]})[_0xb84c('0x23')](function(_0x28062c){return _0x28062c;});})['then'](function(_0x1ea291){if(_0x1ea291){_0x2dda7c[_0xb84c('0x2a')][_0xb84c('0x70')]=_0x1ea291[0x0];if(!_0x18b51f[_0xb84c('0x5a')][_0xb84c('0x62')])return;return db[_0xb84c('0x71')][_0xb84c('0x5b')]({'where':{'id':_0x18b51f['body'][_0xb84c('0x62')],'role':_0xb84c('0x64')},'attributes':['id',_0xb84c('0x3b'),'fullname',_0xb84c('0x72'),_0xb84c('0x73')],'raw':!![]});}return null;})[_0xb84c('0x23')](function(_0x3b3249){if(!_0x3b3249)return null;_0x2dda7c[_0xb84c('0x2a')][_0xb84c('0x64')]=_0x3b3249;return _0x2dda7c;})[_0xb84c('0x23')](function(_0x17adeb){if(_0x17adeb){if(_0x18b51f[_0xb84c('0x5a')][_0xb84c('0x74')]){_0x2dda7c[_0xb84c('0x2a')]['interface']=util[_0xb84c('0x61')]('SIP/%s',_0x18b51f['user'][_0xb84c('0x3b')]);_0x2dda7c[_0xb84c('0x2a')]['channel']=_0x2dda7c[_0xb84c('0x75')];_0x2dda7c[_0xb84c('0x2a')]['motionChannel']=_0x2dda7c['channel'];_0x2dda7c[_0xb84c('0x2a')][_0xb84c('0x76')]=_0xb84c('0x5f');return respondWithRpcPromise(_0xb84c('0x77'),_0xb84c('0x77'),{'event':_0xb84c('0x78'),'message':_0x2dda7c['message']},client9002)[_0xb84c('0x23')](function(){return _0x2dda7c;});}return _0x2dda7c;}return null;})['then'](respondWithResult(_0xe502bb,null))[_0xb84c('0x2d')](handleError(_0xe502bb,null));};var interaction_log=require('../../config/logger')('fax-interactions');exports[_0xb84c('0x79')]=function(_0x3ae5e4,_0x35f175,_0x8e573d){var _0x45d2ae={'agent':{},'channel':_0xb84c('0x60')};if(_0x3ae5e4[_0xb84c('0x5a')]['id']){delete _0x3ae5e4[_0xb84c('0x5a')]['id'];}_0x3ae5e4[_0xb84c('0x5a')]['UserId']=_0x3ae5e4[_0xb84c('0x5a')][_0xb84c('0x62')]||_0x3ae5e4[_0xb84c('0x63')]['id'];_0x45d2ae[_0xb84c('0x64')]['id']=_0x3ae5e4[_0xb84c('0x5a')][_0xb84c('0x62')];return db['FaxMessage'][_0xb84c('0x5b')]({'where':{'id':_0x3ae5e4[_0xb84c('0x5c')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x35f175,null))[_0xb84c('0x23')](function(_0x134ecb){if(_0x134ecb){_0x45d2ae[_0xb84c('0x2a')]=_0x134ecb[_0xb84c('0x65')]({'plain':!![]});return db[_0xb84c('0x66')][_0xb84c('0x5b')]({'where':{'id':_0x134ecb[_0xb84c('0x7a')]}});}return null;})['then'](handleEntityNotFound(_0x35f175,null))[_0xb84c('0x23')](function(_0x3165c1){if(_0x3165c1){_0x45d2ae[_0xb84c('0x6a')]=_0x3165c1[_0xb84c('0x65')]({'plain':!![]});interaction_log[_0xb84c('0x2b')](_0xb84c('0x7b'),_0x3ae5e4[_0xb84c('0x63')]['id'],_0x3ae5e4[_0xb84c('0x63')][_0xb84c('0x3b')],_0x3ae5e4[_0xb84c('0x63')]['role'],_0x45d2ae[_0xb84c('0x6a')]['id'],_0x3ae5e4[_0xb84c('0x5a')]?JSON['stringify'](_0x3ae5e4[_0xb84c('0x5a')]):_0xb84c('0x6b'));return respondWithRpcPromise(_0xb84c('0x7c'),_0xb84c('0x7d'),_0x45d2ae);}return null;})[_0xb84c('0x23')](function(_0x4f0819){var _0x1a0028='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x4f0819['message'][_0xb84c('0x7e')];return db[_0xb84c('0x6f')][_0xb84c('0x42')](_0x1a0028,{'type':db[_0xb84c('0x7f')][_0xb84c('0x80')][_0xb84c('0x81')],'raw':!![]})[_0xb84c('0x23')](function(_0x1456ef){return _0x1456ef;});})[_0xb84c('0x23')](function(_0x2b3cb9){if(_0x2b3cb9){_0x45d2ae[_0xb84c('0x2a')][_0xb84c('0x70')]=_0x2b3cb9[0x0];if(!_0x3ae5e4[_0xb84c('0x5a')][_0xb84c('0x62')])return;return db['User'][_0xb84c('0x5b')]({'where':{'id':_0x3ae5e4['body'][_0xb84c('0x62')],'role':_0xb84c('0x64')},'attributes':['id',_0xb84c('0x3b'),_0xb84c('0x82'),_0xb84c('0x72'),_0xb84c('0x73')],'raw':!![]});}return null;})[_0xb84c('0x23')](function(_0x23d9c9){if(!_0x23d9c9)return null;_0x45d2ae[_0xb84c('0x2a')][_0xb84c('0x64')]=_0x23d9c9;return _0x45d2ae;})[_0xb84c('0x23')](function(_0x5b3e7c){if(_0x5b3e7c){_0x5b3e7c[_0xb84c('0x2a')]['interface']=util[_0xb84c('0x61')](_0xb84c('0x83'),_0x3ae5e4[_0xb84c('0x63')][_0xb84c('0x3b')]);_0x5b3e7c[_0xb84c('0x2a')]['channel']=_0x45d2ae['channel'];_0x5b3e7c[_0xb84c('0x2a')]['motionChannel']=_0x45d2ae[_0xb84c('0x75')];_0x5b3e7c[_0xb84c('0x2a')]['event']='reject';respondWithRpcPromise('EventManager','EventManager',{'event':_0xb84c('0x84'),'message':_0x5b3e7c['message']},client9002);return _0x45d2ae;}return null;})['then'](respondWithResult(_0x35f175,null))[_0xb84c('0x2d')](handleError(_0x35f175,null));};exports['create']=function(_0x17a8be,_0x337749){var _0x23b4d6;return db[_0xb84c('0x3d')]['create'](_0x17a8be['body'],{})[_0xb84c('0x23')](function(_0x530370){_0x23b4d6=_0x530370;return db[_0xb84c('0x85')][_0xb84c('0x86')]({'where':{'id':_0x23b4d6[_0xb84c('0x7e')]}});})['then'](function(_0x2c072a){if(_[_0xb84c('0x67')](_0x2c072a)){return;}else{_0x23b4d6[_0xb84c('0x60')]=_0x2c072a[_0xb84c('0x60')];return db[_0xb84c('0x87')][_0xb84c('0x86')]({'where':{'id':_0x23b4d6['AttachmentId']}});}})['then'](function(_0x41de4b){return respondWithRpcPromise(_0xb84c('0x88'),_0xb84c('0x88'),{'FaxAccountId':_['isNil'](_0x17a8be[_0xb84c('0x5a')])?undefined:_0x17a8be['body'][_0xb84c('0x89')],'path':_[_0xb84c('0x67')](_0x41de4b)?undefined:util[_0xb84c('0x61')](_0xb84c('0x8a'),_0x41de4b[_0xb84c('0x8b')]),'fax':_[_0xb84c('0x67')](_0x23b4d6[_0xb84c('0x60')])?undefined:_0x23b4d6[_0xb84c('0x60')],'AttachmentId':_0x23b4d6[_0xb84c('0x8c')]},client9002);})['then'](respondWithResult(_0x337749,0xc9))[_0xb84c('0x2d')](handleError(_0x337749,null));};exports[_0xb84c('0x8d')]=function(_0x577cb3,_0x4b975c){var _0x387b0b=path['join'](config[_0xb84c('0x8e')],'server',_0xb84c('0x8f'),_0xb84c('0x90'));return db[_0xb84c('0x3d')][_0xb84c('0x5b')]({'where':{'id':_0x577cb3[_0xb84c('0x5c')]['id']},'include':[{'model':db['Attachment'],'as':'Attachment'}]})['then'](handleEntityNotFound(_0x4b975c,null))[_0xb84c('0x23')](function(_0xe1d414){if(_0xe1d414){return _0x4b975c['download'](path[_0xb84c('0x91')](_0x387b0b,_0xe1d414['Attachment'][_0xb84c('0x8b')]));}})[_0xb84c('0x2d')](handleError(_0x4b975c,null));};
\ No newline at end of file
+var _0x8f55=['fax-interactions','accept','fax','read','format','user','get','FaxInteractionId','update','UserId','isNil','read1stAt','YYYY-MM-DD\x20HH:mm:ss','interaction','role','null','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','Sequelize','QueryTypes','SELECT','User','agent','fullname','email','internal','manual','interface','SIP/%s','channel','event','EventManager','acceptmessage','FaxInteraction','[FAXMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','sequelize','contact','motionChannel','rejectmessage','create','findOne','AttachmentId','SendFax','FaxAccountId','/var/opt/motion2/server/files/attachments/%s','basename','download','join','server','attachments','Attachment','eml-format','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','fs-extra','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','defaults','redis','localhost','socket.io-emitter','./faxMessage.socket','register','jayson/promise','client','request','then','request\x20sent','debug','FaxMessage,\x20%s,\x20%s,\x20%s','stringify','error','message','FaxMessage,\x20%s,\x20%s','info','result','catch','sendStatus','status','json','offset','undefined','limit','set','apply','reject','save','end','stack','name','send','index','map','FaxMessage','rawAttributes','fieldName','keys','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','type','VIRTUAL','filter','merge','count','includeAll','findAll','rows','show','params','include','options','find','body','destroy','describe'];(function(_0x3ad818,_0x3dea92){var _0x4762ca=function(_0x25a988){while(--_0x25a988){_0x3ad818['push'](_0x3ad818['shift']());}};_0x4762ca(++_0x3dea92);}(_0x8f55,0x1f2));var _0x58f5=function(_0x20a584,_0xe384a5){_0x20a584=_0x20a584-0x0;var _0x4b41a8=_0x8f55[_0x20a584];return _0x4b41a8;};'use strict';var emlformat=require(_0x58f5('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x58f5('0x1'));var rp=require(_0x58f5('0x2'));var moment=require(_0x58f5('0x3'));var BPromise=require(_0x58f5('0x4'));var Mustache=require(_0x58f5('0x5'));var util=require(_0x58f5('0x6'));var path=require(_0x58f5('0x7'));var sox=require(_0x58f5('0x8'));var csv=require('to-csv');var ejs=require(_0x58f5('0x9'));var fs=require('fs');var fs_extra=require(_0x58f5('0xa'));var _=require('lodash');var squel=require(_0x58f5('0xb'));var crypto=require(_0x58f5('0xc'));var jsforce=require(_0x58f5('0xd'));var deskjs=require(_0x58f5('0xe'));var toCsv=require(_0x58f5('0xf'));var querystring=require(_0x58f5('0x10'));var Papa=require(_0x58f5('0x11'));var Redis=require(_0x58f5('0x12'));var authService=require(_0x58f5('0x13'));var qs=require(_0x58f5('0x14'));var as=require(_0x58f5('0x15'));var hardwareService=require(_0x58f5('0x16'));var logger=require(_0x58f5('0x17'))('api');var utils=require(_0x58f5('0x18'));var config=require(_0x58f5('0x19'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];config['redis']=_[_0x58f5('0x1a')](config[_0x58f5('0x1b')],{'host':_0x58f5('0x1c'),'port':0x18eb});var socket=require(_0x58f5('0x1d'))(new Redis(config['redis']));require(_0x58f5('0x1e'))[_0x58f5('0x1f')](socket);var jayson=require(_0x58f5('0x20'));var client=jayson[_0x58f5('0x21')]['http']({'port':0x232c});var client9002=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x1d8e57,_0x227ae3,_0x811812,_0x52ccab){return new BPromise(function(_0x2aa508,_0x10a890){var _0x2cb5af=_0x52ccab||client;return _0x2cb5af[_0x58f5('0x22')](_0x1d8e57,_0x811812)[_0x58f5('0x23')](function(_0x4d8e91){logger['info']('FaxMessage,\x20%s,\x20%s',_0x227ae3,_0x58f5('0x24'));logger[_0x58f5('0x25')](_0x58f5('0x26'),_0x227ae3,'request\x20sent',JSON[_0x58f5('0x27')](_0x4d8e91));if(_0x4d8e91['error']){if(_0x4d8e91[_0x58f5('0x28')]['code']===0x1f4){logger[_0x58f5('0x28')]('FaxMessage,\x20%s,\x20%s',_0x227ae3,_0x4d8e91[_0x58f5('0x28')][_0x58f5('0x29')]);return _0x10a890(_0x4d8e91['error'][_0x58f5('0x29')]);}logger[_0x58f5('0x28')](_0x58f5('0x2a'),_0x227ae3,_0x4d8e91['error'][_0x58f5('0x29')]);return _0x2aa508(_0x4d8e91[_0x58f5('0x28')][_0x58f5('0x29')]);}else{logger[_0x58f5('0x2b')](_0x58f5('0x2a'),_0x227ae3,_0x58f5('0x24'));_0x2aa508(_0x4d8e91[_0x58f5('0x2c')][_0x58f5('0x29')]);}})[_0x58f5('0x2d')](function(_0x24c0af){logger[_0x58f5('0x28')](_0x58f5('0x2a'),_0x227ae3,_0x24c0af);_0x10a890(_0x24c0af);});});}function respondWithStatusCode(_0x435c93,_0x3c04ed){_0x3c04ed=_0x3c04ed||0xcc;return function(_0x4d37ef){if(_0x4d37ef){return _0x435c93[_0x58f5('0x2e')](_0x3c04ed);}return _0x435c93['status'](_0x3c04ed)['end']();};}function respondWithResult(_0x5bac79,_0x265c6e){_0x265c6e=_0x265c6e||0xc8;return function(_0x2ea4d2){if(_0x2ea4d2){return _0x5bac79[_0x58f5('0x2f')](_0x265c6e)[_0x58f5('0x30')](_0x2ea4d2);}};}function respondWithFilteredResult(_0x1aa853,_0x1e20d3){return function(_0x5548b3){if(_0x5548b3){var _0x342f81=typeof _0x1e20d3[_0x58f5('0x31')]===_0x58f5('0x32')&&typeof _0x1e20d3[_0x58f5('0x33')]===_0x58f5('0x32');var _0x394024=_0x5548b3['count'];var _0x1d3c56=_0x342f81?0x0:_0x1e20d3[_0x58f5('0x31')];var _0x5ea31c=_0x342f81?_0x5548b3['count']:_0x1e20d3[_0x58f5('0x31')]+_0x1e20d3[_0x58f5('0x33')];var _0x3224d1;if(_0x5ea31c>=_0x394024){_0x5ea31c=_0x394024;_0x3224d1=0xc8;}else{_0x3224d1=0xce;}_0x1aa853[_0x58f5('0x2f')](_0x3224d1);return _0x1aa853[_0x58f5('0x34')]('Content-Range',_0x1d3c56+'-'+_0x5ea31c+'/'+_0x394024)['json'](_0x5548b3);}return null;};}function patchUpdates(_0x1964d9){return function(_0xf2a9ac){try{jsonpatch[_0x58f5('0x35')](_0xf2a9ac,_0x1964d9,!![]);}catch(_0x3a4b56){return BPromise[_0x58f5('0x36')](_0x3a4b56);}return _0xf2a9ac[_0x58f5('0x37')]();};}function saveUpdates(_0xa34382,_0x1072dc){return function(_0x340415){if(_0x340415){return _0x340415['update'](_0xa34382)['then'](function(_0x34ebf5){return _0x34ebf5;});}return null;};}function removeEntity(_0x32cb34,_0x415217){return function(_0x33ab2a){if(_0x33ab2a){return _0x33ab2a['destroy']()['then'](function(){_0x32cb34[_0x58f5('0x2f')](0xcc)[_0x58f5('0x38')]();});}};}function handleEntityNotFound(_0x9152af,_0x4ae66b){return function(_0x4c64c2){if(!_0x4c64c2){_0x9152af['sendStatus'](0x194);}return _0x4c64c2;};}function handleError(_0x16e778,_0x4f9b3a){_0x4f9b3a=_0x4f9b3a||0x1f4;return function(_0x541b11){logger[_0x58f5('0x28')](_0x541b11[_0x58f5('0x39')]);if(_0x541b11[_0x58f5('0x3a')]){delete _0x541b11[_0x58f5('0x3a')];}_0x16e778['status'](_0x4f9b3a)[_0x58f5('0x3b')](_0x541b11);};}exports[_0x58f5('0x3c')]=function(_0x3a746c,_0x5559b3){var _0x5ccc24={},_0xc38960={},_0x116f40={'count':0x0,'rows':[]};var _0x2e51e9=_[_0x58f5('0x3d')](db[_0x58f5('0x3e')][_0x58f5('0x3f')],function(_0x3316e7){return{'name':_0x3316e7[_0x58f5('0x40')],'type':_0x3316e7['type']['key']};});_0xc38960['model']=_[_0x58f5('0x3d')](_0x2e51e9,'name');_0xc38960['query']=_[_0x58f5('0x41')](_0x3a746c[_0x58f5('0x42')]);_0xc38960[_0x58f5('0x43')]=_[_0x58f5('0x44')](_0xc38960[_0x58f5('0x45')],_0xc38960[_0x58f5('0x42')]);_0x5ccc24[_0x58f5('0x46')]=_['intersection'](_0xc38960[_0x58f5('0x45')],qs[_0x58f5('0x47')](_0x3a746c[_0x58f5('0x42')][_0x58f5('0x47')]));_0x5ccc24[_0x58f5('0x46')]=_0x5ccc24[_0x58f5('0x46')][_0x58f5('0x48')]?_0x5ccc24[_0x58f5('0x46')]:_0xc38960[_0x58f5('0x45')];if(!_0x3a746c[_0x58f5('0x42')][_0x58f5('0x49')](_0x58f5('0x4a'))){_0x5ccc24[_0x58f5('0x33')]=qs['limit'](_0x3a746c[_0x58f5('0x42')][_0x58f5('0x33')]);_0x5ccc24[_0x58f5('0x31')]=qs[_0x58f5('0x31')](_0x3a746c[_0x58f5('0x42')][_0x58f5('0x31')]);}_0x5ccc24[_0x58f5('0x4b')]=qs[_0x58f5('0x4c')](_0x3a746c['query']['sort']);_0x5ccc24[_0x58f5('0x4d')]=qs[_0x58f5('0x43')](_['pick'](_0x3a746c[_0x58f5('0x42')],_0xc38960[_0x58f5('0x43')]),_0x2e51e9);if(_0x3a746c[_0x58f5('0x42')]['filter']){_0x5ccc24[_0x58f5('0x4d')]=_['merge'](_0x5ccc24[_0x58f5('0x4d')],{'$or':_['map'](_0x2e51e9,function(_0x5c0330){if(_0x5c0330[_0x58f5('0x4e')]!==_0x58f5('0x4f')){var _0x5b86ed={};_0x5b86ed[_0x5c0330[_0x58f5('0x3a')]]={'$like':'%'+_0x3a746c[_0x58f5('0x42')][_0x58f5('0x50')]+'%'};return _0x5b86ed;}})});}_0x5ccc24=_[_0x58f5('0x51')]({},_0x5ccc24,_0x3a746c['options']);var _0x6d5d17={'where':_0x5ccc24['where']};return db['FaxMessage'][_0x58f5('0x52')](_0x6d5d17)[_0x58f5('0x23')](function(_0x15d486){_0x116f40[_0x58f5('0x52')]=_0x15d486;if(_0x3a746c[_0x58f5('0x42')][_0x58f5('0x53')]){_0x5ccc24['include']=[{'all':!![]}];}return db[_0x58f5('0x3e')][_0x58f5('0x54')](_0x5ccc24);})[_0x58f5('0x23')](function(_0x493a7f){_0x116f40[_0x58f5('0x55')]=_0x493a7f;return _0x116f40;})[_0x58f5('0x23')](respondWithFilteredResult(_0x5559b3,_0x5ccc24))[_0x58f5('0x2d')](handleError(_0x5559b3,null));};exports[_0x58f5('0x56')]=function(_0x3a2150,_0x1c8871){var _0x19a41e={'raw':!![],'where':{'id':_0x3a2150[_0x58f5('0x57')]['id']}},_0x2083e8={};_0x2083e8[_0x58f5('0x45')]=_[_0x58f5('0x41')](db['FaxMessage'][_0x58f5('0x3f')]);_0x2083e8[_0x58f5('0x42')]=_[_0x58f5('0x41')](_0x3a2150['query']);_0x2083e8[_0x58f5('0x43')]=_['intersection'](_0x2083e8['model'],_0x2083e8[_0x58f5('0x42')]);_0x19a41e[_0x58f5('0x46')]=_[_0x58f5('0x44')](_0x2083e8[_0x58f5('0x45')],qs[_0x58f5('0x47')](_0x3a2150[_0x58f5('0x42')][_0x58f5('0x47')]));_0x19a41e[_0x58f5('0x46')]=_0x19a41e[_0x58f5('0x46')][_0x58f5('0x48')]?_0x19a41e[_0x58f5('0x46')]:_0x2083e8[_0x58f5('0x45')];if(_0x3a2150[_0x58f5('0x42')]['includeAll']){_0x19a41e[_0x58f5('0x58')]=[{'all':!![]}];}_0x19a41e=_['merge']({},_0x19a41e,_0x3a2150[_0x58f5('0x59')]);return db[_0x58f5('0x3e')][_0x58f5('0x5a')](_0x19a41e)['then'](handleEntityNotFound(_0x1c8871,null))[_0x58f5('0x23')](respondWithResult(_0x1c8871,null))[_0x58f5('0x2d')](handleError(_0x1c8871,null));};exports['update']=function(_0x4b0c89,_0x4bdf2d){if(_0x4b0c89[_0x58f5('0x5b')]['id']){delete _0x4b0c89['body']['id'];}return db['FaxMessage'][_0x58f5('0x5a')]({'where':{'id':_0x4b0c89[_0x58f5('0x57')]['id']}})[_0x58f5('0x23')](handleEntityNotFound(_0x4bdf2d,null))[_0x58f5('0x23')](saveUpdates(_0x4b0c89['body'],null))['then'](respondWithResult(_0x4bdf2d,null))[_0x58f5('0x2d')](handleError(_0x4bdf2d,null));};exports[_0x58f5('0x5c')]=function(_0x2896e8,_0x4d6ceb){return db[_0x58f5('0x3e')][_0x58f5('0x5a')]({'where':{'id':_0x2896e8['params']['id']}})[_0x58f5('0x23')](handleEntityNotFound(_0x4d6ceb,null))['then'](removeEntity(_0x4d6ceb,null))[_0x58f5('0x2d')](handleError(_0x4d6ceb,null));};exports[_0x58f5('0x5d')]=function(_0x446ea6,_0x5cc949){return db['FaxMessage'][_0x58f5('0x5d')]()[_0x58f5('0x23')](respondWithResult(_0x5cc949,null))[_0x58f5('0x2d')](handleError(_0x5cc949,null));};var interaction_log=require(_0x58f5('0x17'))(_0x58f5('0x5e'));exports[_0x58f5('0x5f')]=function(_0xdd9965,_0xfcda5a,_0x4ee10c){var _0x4bde33={'agent':{},'channel':_0x58f5('0x60')};if(_0xdd9965[_0x58f5('0x5b')]['id']){delete _0xdd9965[_0x58f5('0x5b')]['id'];}_0xdd9965[_0x58f5('0x5b')][_0x58f5('0x61')]=!![];_0xdd9965[_0x58f5('0x5b')]['readAt']=moment()[_0x58f5('0x62')]('YYYY-MM-DD\x20HH:mm:ss');_0xdd9965[_0x58f5('0x5b')]['UserId']=_0xdd9965[_0x58f5('0x5b')]['UserId']||_0xdd9965[_0x58f5('0x63')]['id'];_0x4bde33['agent']['id']=_0xdd9965[_0x58f5('0x5b')]['UserId'];return db[_0x58f5('0x3e')][_0x58f5('0x5a')]({'where':{'id':_0xdd9965['params']['id'],'UserId':null}})[_0x58f5('0x23')](handleEntityNotFound(_0xfcda5a,null))[_0x58f5('0x23')](saveUpdates(_0xdd9965[_0x58f5('0x5b')],null))[_0x58f5('0x23')](function(_0x16da85){if(_0x16da85){_0x4bde33[_0x58f5('0x29')]=_0x16da85[_0x58f5('0x64')]({'plain':!![]});return db['FaxInteraction'][_0x58f5('0x5a')]({'where':{'id':_0x16da85[_0x58f5('0x65')]}});}return null;})[_0x58f5('0x23')](handleEntityNotFound(_0xfcda5a,null))[_0x58f5('0x23')](function(_0x1b3494){if(_0x1b3494){return _0x1b3494[_0x58f5('0x66')]({'UserId':_0xdd9965[_0x58f5('0x5b')][_0x58f5('0x67')],'read1stAt':_[_0x58f5('0x68')](_0x1b3494[_0x58f5('0x69')])?moment()[_0x58f5('0x62')](_0x58f5('0x6a')):undefined});}return null;})[_0x58f5('0x23')](function(_0xbaf42b){if(_0xbaf42b){_0x4bde33[_0x58f5('0x6b')]=_0xbaf42b[_0x58f5('0x64')]({'plain':!![]});interaction_log[_0x58f5('0x2b')]('[FAXMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0xdd9965[_0x58f5('0x63')]['id'],_0xdd9965[_0x58f5('0x63')]['name'],_0xdd9965[_0x58f5('0x63')][_0x58f5('0x6c')],_0x4bde33[_0x58f5('0x6b')]['id'],_0xdd9965[_0x58f5('0x5b')]?JSON[_0x58f5('0x27')](_0xdd9965[_0x58f5('0x5b')]):_0x58f5('0x6d'));return respondWithRpcPromise('AcceptMessage',_0x58f5('0x6e'),_0x4bde33);}return null;})[_0x58f5('0x23')](function(_0x5e8c6c){var _0x157c47=_0x58f5('0x6f')+_0x5e8c6c[_0x58f5('0x29')][_0x58f5('0x70')];return db['sequelize'][_0x58f5('0x42')](_0x157c47,{'type':db[_0x58f5('0x71')][_0x58f5('0x72')][_0x58f5('0x73')],'raw':!![]})[_0x58f5('0x23')](function(_0x11a673){return _0x11a673;});})[_0x58f5('0x23')](function(_0x810988){if(_0x810988){_0x4bde33['message']['contact']=_0x810988[0x0];if(!_0xdd9965[_0x58f5('0x5b')][_0x58f5('0x67')])return;return db[_0x58f5('0x74')][_0x58f5('0x5a')]({'where':{'id':_0xdd9965[_0x58f5('0x5b')][_0x58f5('0x67')],'role':_0x58f5('0x75')},'attributes':['id',_0x58f5('0x3a'),_0x58f5('0x76'),_0x58f5('0x77'),_0x58f5('0x78')],'raw':!![]});}return null;})['then'](function(_0x51bf4a){if(!_0x51bf4a)return null;_0x4bde33[_0x58f5('0x29')]['agent']=_0x51bf4a;return _0x4bde33;})[_0x58f5('0x23')](function(_0x3beb5b){if(_0x3beb5b){if(_0xdd9965[_0x58f5('0x5b')][_0x58f5('0x79')]){_0x4bde33[_0x58f5('0x29')][_0x58f5('0x7a')]=util[_0x58f5('0x62')](_0x58f5('0x7b'),_0xdd9965['user'][_0x58f5('0x3a')]);_0x4bde33[_0x58f5('0x29')][_0x58f5('0x7c')]=_0x4bde33['channel'];_0x4bde33[_0x58f5('0x29')]['motionChannel']=_0x4bde33[_0x58f5('0x7c')];_0x4bde33['message'][_0x58f5('0x7d')]=_0x58f5('0x5f');return respondWithRpcPromise('EventManager',_0x58f5('0x7e'),{'event':_0x58f5('0x7f'),'message':_0x4bde33[_0x58f5('0x29')]},client9002)[_0x58f5('0x23')](function(){return _0x4bde33;});}return _0x4bde33;}return null;})[_0x58f5('0x23')](respondWithResult(_0xfcda5a,null))['catch'](handleError(_0xfcda5a,null));};var interaction_log=require(_0x58f5('0x17'))('fax-interactions');exports[_0x58f5('0x36')]=function(_0x36d5b3,_0x34320b,_0x4720de){var _0x573156={'agent':{},'channel':_0x58f5('0x60')};if(_0x36d5b3[_0x58f5('0x5b')]['id']){delete _0x36d5b3['body']['id'];}_0x36d5b3[_0x58f5('0x5b')][_0x58f5('0x67')]=_0x36d5b3[_0x58f5('0x5b')][_0x58f5('0x67')]||_0x36d5b3['user']['id'];_0x573156[_0x58f5('0x75')]['id']=_0x36d5b3[_0x58f5('0x5b')]['UserId'];return db[_0x58f5('0x3e')][_0x58f5('0x5a')]({'where':{'id':_0x36d5b3[_0x58f5('0x57')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x34320b,null))['then'](function(_0x32e828){if(_0x32e828){_0x573156[_0x58f5('0x29')]=_0x32e828[_0x58f5('0x64')]({'plain':!![]});return db[_0x58f5('0x80')][_0x58f5('0x5a')]({'where':{'id':_0x32e828['FaxInteractionId']}});}return null;})[_0x58f5('0x23')](handleEntityNotFound(_0x34320b,null))[_0x58f5('0x23')](function(_0x22ef7b){if(_0x22ef7b){_0x573156[_0x58f5('0x6b')]=_0x22ef7b[_0x58f5('0x64')]({'plain':!![]});interaction_log[_0x58f5('0x2b')](_0x58f5('0x81'),_0x36d5b3[_0x58f5('0x63')]['id'],_0x36d5b3[_0x58f5('0x63')][_0x58f5('0x3a')],_0x36d5b3['user']['role'],_0x573156[_0x58f5('0x6b')]['id'],_0x36d5b3[_0x58f5('0x5b')]?JSON['stringify'](_0x36d5b3['body']):_0x58f5('0x6d'));return respondWithRpcPromise(_0x58f5('0x82'),_0x58f5('0x83'),_0x573156);}return null;})[_0x58f5('0x23')](function(_0x1161a0){var _0x1718e9='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x1161a0[_0x58f5('0x29')][_0x58f5('0x70')];return db[_0x58f5('0x84')][_0x58f5('0x42')](_0x1718e9,{'type':db[_0x58f5('0x71')]['QueryTypes'][_0x58f5('0x73')],'raw':!![]})[_0x58f5('0x23')](function(_0x433a94){return _0x433a94;});})['then'](function(_0x54b86c){if(_0x54b86c){_0x573156[_0x58f5('0x29')][_0x58f5('0x85')]=_0x54b86c[0x0];if(!_0x36d5b3[_0x58f5('0x5b')][_0x58f5('0x67')])return;return db[_0x58f5('0x74')]['find']({'where':{'id':_0x36d5b3[_0x58f5('0x5b')][_0x58f5('0x67')],'role':_0x58f5('0x75')},'attributes':['id',_0x58f5('0x3a'),_0x58f5('0x76'),_0x58f5('0x77'),'internal'],'raw':!![]});}return null;})['then'](function(_0x391d17){if(!_0x391d17)return null;_0x573156[_0x58f5('0x29')][_0x58f5('0x75')]=_0x391d17;return _0x573156;})[_0x58f5('0x23')](function(_0x3c160f){if(_0x3c160f){_0x3c160f[_0x58f5('0x29')][_0x58f5('0x7a')]=util[_0x58f5('0x62')](_0x58f5('0x7b'),_0x36d5b3[_0x58f5('0x63')][_0x58f5('0x3a')]);_0x3c160f[_0x58f5('0x29')][_0x58f5('0x7c')]=_0x573156['channel'];_0x3c160f['message'][_0x58f5('0x86')]=_0x573156['channel'];_0x3c160f[_0x58f5('0x29')]['event']='reject';respondWithRpcPromise('EventManager','EventManager',{'event':_0x58f5('0x87'),'message':_0x3c160f['message']},client9002);return _0x573156;}return null;})['then'](respondWithResult(_0x34320b,null))[_0x58f5('0x2d')](handleError(_0x34320b,null));};exports[_0x58f5('0x88')]=function(_0x29313e,_0x23c3e5){var _0x378485;return db['FaxMessage'][_0x58f5('0x88')](_0x29313e[_0x58f5('0x5b')],{})[_0x58f5('0x23')](function(_0x2cb91e){_0x378485=_0x2cb91e;return db['CmContact'][_0x58f5('0x89')]({'where':{'id':_0x378485['ContactId']}});})[_0x58f5('0x23')](function(_0x431f89){if(_[_0x58f5('0x68')](_0x431f89)){return;}else{_0x378485[_0x58f5('0x60')]=_0x431f89[_0x58f5('0x60')];return db['Attachment'][_0x58f5('0x89')]({'where':{'id':_0x378485[_0x58f5('0x8a')]}});}})[_0x58f5('0x23')](function(_0x1f11e6){return respondWithRpcPromise(_0x58f5('0x8b'),_0x58f5('0x8b'),{'FaxAccountId':_[_0x58f5('0x68')](_0x29313e[_0x58f5('0x5b')])?undefined:_0x29313e[_0x58f5('0x5b')][_0x58f5('0x8c')],'path':_[_0x58f5('0x68')](_0x1f11e6)?undefined:util[_0x58f5('0x62')](_0x58f5('0x8d'),_0x1f11e6[_0x58f5('0x8e')]),'fax':_['isNil'](_0x378485[_0x58f5('0x60')])?undefined:_0x378485[_0x58f5('0x60')],'AttachmentId':_0x378485[_0x58f5('0x8a')]},client9002);})[_0x58f5('0x23')](respondWithResult(_0x23c3e5,0xc9))['catch'](handleError(_0x23c3e5,null));};exports[_0x58f5('0x8f')]=function(_0x4f66b6,_0x487ac7){var _0x3c0f1e=path[_0x58f5('0x90')](config['root'],_0x58f5('0x91'),'files',_0x58f5('0x92'));return db[_0x58f5('0x3e')]['find']({'where':{'id':_0x4f66b6['params']['id']},'include':[{'model':db[_0x58f5('0x93')],'as':'Attachment'}]})[_0x58f5('0x23')](handleEntityNotFound(_0x487ac7,null))[_0x58f5('0x23')](function(_0x4b398a){if(_0x4b398a){return _0x487ac7[_0x58f5('0x8f')](path[_0x58f5('0x90')](_0x3c0f1e,_0x4b398a[_0x58f5('0x93')][_0x58f5('0x8e')]));}})['catch'](handleError(_0x487ac7,null));};
\ No newline at end of file