Built motion from commit 25580385.|2.6.2
[motion2.git] / server / api / faxMessage / faxMessage.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 _0x04bb=['redis','defaults','localhost','socket.io-emitter','./faxMessage.socket','register','jayson/promise','client','request','then','request\x20sent','debug','FaxMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','FaxMessage,\x20%s,\x20%s','message','info','catch','sendStatus','status','end','json','undefined','limit','count','offset','set','Content-Range','apply','save','destroy','stack','name','send','map','FaxMessage','type','key','query','keys','model','attributes','intersection','fields','nolimit','order','sort','where','pick','filters','merge','filter','includeAll','findAll','rows','show','params','options','update','body','find','describe','fax-interactions','accept','fax','read','readAt','format','UserId','agent','get','FaxInteraction','read1stAt','YYYY-MM-DD\x20HH:mm:ss','interaction','[FAXMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','user','role','null','AcceptMessage','acceptMessage','sequelize','Sequelize','QueryTypes','SELECT','fullname','internal','manual','interface','SIP/%s','channel','event','EventManager','reject','FaxInteractionId','RejectMessage','rejectMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','motionChannel','rejectmessage','create','findOne','ContactId','isNil','AttachmentId','SendFax','download','join','root','server','files','attachments','Attachment','basename','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','sox','to-csv','ejs','lodash','crypto','jsforce','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/license/util','../../mysqldb'];(function(_0xac800e,_0x54e102){var _0x2f8e19=function(_0x501334){while(--_0x501334){_0xac800e['push'](_0xac800e['shift']());}};_0x2f8e19(++_0x54e102);}(_0x04bb,0x74));var _0xb04b=function(_0xa464c9,_0x7c86d8){_0xa464c9=_0xa464c9-0x0;var _0x3d73c4=_0x04bb[_0xa464c9];return _0x3d73c4;};'use strict';var emlformat=require(_0xb04b('0x0'));var rimraf=require(_0xb04b('0x1'));var zipdir=require(_0xb04b('0x2'));var jsonpatch=require(_0xb04b('0x3'));var rp=require(_0xb04b('0x4'));var moment=require(_0xb04b('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xb04b('0x6'));var util=require(_0xb04b('0x7'));var path=require('path');var sox=require(_0xb04b('0x8'));var csv=require(_0xb04b('0x9'));var ejs=require(_0xb04b('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xb04b('0xb'));var squel=require('squel');var crypto=require(_0xb04b('0xc'));var jsforce=require(_0xb04b('0xd'));var deskjs=require('desk.js');var toCsv=require(_0xb04b('0x9'));var querystring=require('querystring');var Papa=require(_0xb04b('0xe'));var Redis=require(_0xb04b('0xf'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0xb04b('0x10'));var hardwareService=require(_0xb04b('0x11'));var logger=require(_0xb04b('0x12'))(_0xb04b('0x13'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0xb04b('0x14'));var db=require(_0xb04b('0x15'))['db'];config[_0xb04b('0x16')]=_[_0xb04b('0x17')](config[_0xb04b('0x16')],{'host':_0xb04b('0x18'),'port':0x18eb});var socket=require(_0xb04b('0x19'))(new Redis(config[_0xb04b('0x16')]));require(_0xb04b('0x1a'))[_0xb04b('0x1b')](socket);var jayson=require(_0xb04b('0x1c'));var client=jayson['client']['http']({'port':0x232c});var client9002=jayson[_0xb04b('0x1d')]['http']({'port':0x232a});function respondWithRpcPromise(_0x1785ac,_0x657580,_0x46bc43,_0x39d6b8){return new BPromise(function(_0xdc9fa5,_0x298a7a){var _0x26c211=_0x39d6b8||client;return _0x26c211[_0xb04b('0x1e')](_0x1785ac,_0x46bc43)[_0xb04b('0x1f')](function(_0x251604){logger['info']('FaxMessage,\x20%s,\x20%s',_0x657580,_0xb04b('0x20'));logger[_0xb04b('0x21')](_0xb04b('0x22'),_0x657580,'request\x20sent',JSON[_0xb04b('0x23')](_0x251604));if(_0x251604[_0xb04b('0x24')]){if(_0x251604[_0xb04b('0x24')][_0xb04b('0x25')]===0x1f4){logger[_0xb04b('0x24')](_0xb04b('0x26'),_0x657580,_0x251604[_0xb04b('0x24')][_0xb04b('0x27')]);return _0x298a7a(_0x251604[_0xb04b('0x24')][_0xb04b('0x27')]);}logger['error'](_0xb04b('0x26'),_0x657580,_0x251604[_0xb04b('0x24')]['message']);return _0xdc9fa5(_0x251604[_0xb04b('0x24')]['message']);}else{logger[_0xb04b('0x28')](_0xb04b('0x26'),_0x657580,_0xb04b('0x20'));_0xdc9fa5(_0x251604['result'][_0xb04b('0x27')]);}})[_0xb04b('0x29')](function(_0x4db447){logger['error'](_0xb04b('0x26'),_0x657580,_0x4db447);_0x298a7a(_0x4db447);});});}function respondWithStatusCode(_0x22e27d,_0x5d0c11){_0x5d0c11=_0x5d0c11||0xcc;return function(_0x4539de){if(_0x4539de){return _0x22e27d[_0xb04b('0x2a')](_0x5d0c11);}return _0x22e27d[_0xb04b('0x2b')](_0x5d0c11)[_0xb04b('0x2c')]();};}function respondWithResult(_0x306d06,_0x210155){_0x210155=_0x210155||0xc8;return function(_0x4b1156){if(_0x4b1156){return _0x306d06[_0xb04b('0x2b')](_0x210155)[_0xb04b('0x2d')](_0x4b1156);}};}function respondWithFilteredResult(_0x32e319,_0x571527){return function(_0x46a51c){if(_0x46a51c){var _0xb8ceac=typeof _0x571527['offset']===_0xb04b('0x2e')&&typeof _0x571527[_0xb04b('0x2f')]===_0xb04b('0x2e');var _0x4886b4=_0x46a51c[_0xb04b('0x30')];var _0x115e1e=_0xb8ceac?0x0:_0x571527[_0xb04b('0x31')];var _0x389971=_0xb8ceac?_0x46a51c['count']:_0x571527['offset']+_0x571527[_0xb04b('0x2f')];var _0x5408d7;if(_0x389971>=_0x4886b4){_0x389971=_0x4886b4;_0x5408d7=0xc8;}else{_0x5408d7=0xce;}_0x32e319['status'](_0x5408d7);return _0x32e319[_0xb04b('0x32')](_0xb04b('0x33'),_0x115e1e+'-'+_0x389971+'/'+_0x4886b4)[_0xb04b('0x2d')](_0x46a51c);}return null;};}function patchUpdates(_0x388482){return function(_0x4c9fb9){try{jsonpatch[_0xb04b('0x34')](_0x4c9fb9,_0x388482,!![]);}catch(_0x40c58d){return BPromise['reject'](_0x40c58d);}return _0x4c9fb9[_0xb04b('0x35')]();};}function saveUpdates(_0x3ed1b6,_0x3044f7){return function(_0x19c4b5){if(_0x19c4b5){return _0x19c4b5['update'](_0x3ed1b6)['then'](function(_0x1377a7){return _0x1377a7;});}return null;};}function removeEntity(_0x3d6b3d,_0x23b2e0){return function(_0x383090){if(_0x383090){return _0x383090[_0xb04b('0x36')]()[_0xb04b('0x1f')](function(){_0x3d6b3d['status'](0xcc)[_0xb04b('0x2c')]();});}};}function handleEntityNotFound(_0x763a76,_0x1215b7){return function(_0x574d85){if(!_0x574d85){_0x763a76[_0xb04b('0x2a')](0x194);}return _0x574d85;};}function handleError(_0x258cf2,_0x780233){_0x780233=_0x780233||0x1f4;return function(_0x159982){logger['error'](_0x159982[_0xb04b('0x37')]);if(_0x159982[_0xb04b('0x38')]){delete _0x159982['name'];}_0x258cf2[_0xb04b('0x2b')](_0x780233)[_0xb04b('0x39')](_0x159982);};}exports['index']=function(_0x3d8c6f,_0x5b5a1b){var _0x5bb51e={},_0x5a264f={},_0x2fff05={'count':0x0,'rows':[]};var _0x1aa88e=_[_0xb04b('0x3a')](db[_0xb04b('0x3b')]['rawAttributes'],function(_0x12f48b){return{'name':_0x12f48b['fieldName'],'type':_0x12f48b[_0xb04b('0x3c')][_0xb04b('0x3d')]};});_0x5a264f['model']=_[_0xb04b('0x3a')](_0x1aa88e,_0xb04b('0x38'));_0x5a264f[_0xb04b('0x3e')]=_[_0xb04b('0x3f')](_0x3d8c6f['query']);_0x5a264f['filters']=_['intersection'](_0x5a264f[_0xb04b('0x40')],_0x5a264f[_0xb04b('0x3e')]);_0x5bb51e[_0xb04b('0x41')]=_[_0xb04b('0x42')](_0x5a264f[_0xb04b('0x40')],qs[_0xb04b('0x43')](_0x3d8c6f['query'][_0xb04b('0x43')]));_0x5bb51e['attributes']=_0x5bb51e[_0xb04b('0x41')]['length']?_0x5bb51e[_0xb04b('0x41')]:_0x5a264f[_0xb04b('0x40')];if(!_0x3d8c6f[_0xb04b('0x3e')]['hasOwnProperty'](_0xb04b('0x44'))){_0x5bb51e[_0xb04b('0x2f')]=qs[_0xb04b('0x2f')](_0x3d8c6f[_0xb04b('0x3e')][_0xb04b('0x2f')]);_0x5bb51e['offset']=qs[_0xb04b('0x31')](_0x3d8c6f['query'][_0xb04b('0x31')]);}_0x5bb51e[_0xb04b('0x45')]=qs[_0xb04b('0x46')](_0x3d8c6f[_0xb04b('0x3e')]['sort']);_0x5bb51e[_0xb04b('0x47')]=qs['filters'](_[_0xb04b('0x48')](_0x3d8c6f[_0xb04b('0x3e')],_0x5a264f[_0xb04b('0x49')]),_0x1aa88e);if(_0x3d8c6f[_0xb04b('0x3e')]['filter']){_0x5bb51e[_0xb04b('0x47')]=_[_0xb04b('0x4a')](_0x5bb51e[_0xb04b('0x47')],{'$or':_[_0xb04b('0x3a')](_0x1aa88e,function(_0x470d27){if(_0x470d27[_0xb04b('0x3c')]!=='VIRTUAL'){var _0x12f3e6={};_0x12f3e6[_0x470d27[_0xb04b('0x38')]]={'$like':'%'+_0x3d8c6f[_0xb04b('0x3e')][_0xb04b('0x4b')]+'%'};return _0x12f3e6;}})});}_0x5bb51e=_[_0xb04b('0x4a')]({},_0x5bb51e,_0x3d8c6f['options']);var _0x5dfe32={'where':_0x5bb51e[_0xb04b('0x47')]};return db[_0xb04b('0x3b')][_0xb04b('0x30')](_0x5dfe32)[_0xb04b('0x1f')](function(_0x2ceb48){_0x2fff05[_0xb04b('0x30')]=_0x2ceb48;if(_0x3d8c6f['query'][_0xb04b('0x4c')]){_0x5bb51e['include']=[{'all':!![]}];}return db[_0xb04b('0x3b')][_0xb04b('0x4d')](_0x5bb51e);})['then'](function(_0x261958){_0x2fff05[_0xb04b('0x4e')]=_0x261958;return _0x2fff05;})[_0xb04b('0x1f')](respondWithFilteredResult(_0x5b5a1b,_0x5bb51e))['catch'](handleError(_0x5b5a1b,null));};exports[_0xb04b('0x4f')]=function(_0x371da5,_0x2cbec6){var _0x3ea0d4={'raw':!![],'where':{'id':_0x371da5[_0xb04b('0x50')]['id']}},_0x341203={};_0x341203['model']=_[_0xb04b('0x3f')](db['FaxMessage']['rawAttributes']);_0x341203[_0xb04b('0x3e')]=_[_0xb04b('0x3f')](_0x371da5[_0xb04b('0x3e')]);_0x341203[_0xb04b('0x49')]=_[_0xb04b('0x42')](_0x341203[_0xb04b('0x40')],_0x341203[_0xb04b('0x3e')]);_0x3ea0d4[_0xb04b('0x41')]=_[_0xb04b('0x42')](_0x341203[_0xb04b('0x40')],qs['fields'](_0x371da5[_0xb04b('0x3e')][_0xb04b('0x43')]));_0x3ea0d4['attributes']=_0x3ea0d4[_0xb04b('0x41')]['length']?_0x3ea0d4[_0xb04b('0x41')]:_0x341203['model'];if(_0x371da5[_0xb04b('0x3e')]['includeAll']){_0x3ea0d4['include']=[{'all':!![]}];}_0x3ea0d4=_['merge']({},_0x3ea0d4,_0x371da5[_0xb04b('0x51')]);return db['FaxMessage']['find'](_0x3ea0d4)[_0xb04b('0x1f')](handleEntityNotFound(_0x2cbec6,null))[_0xb04b('0x1f')](respondWithResult(_0x2cbec6,null))[_0xb04b('0x29')](handleError(_0x2cbec6,null));};exports[_0xb04b('0x52')]=function(_0x3ccc08,_0x5ae529){if(_0x3ccc08['body']['id']){delete _0x3ccc08[_0xb04b('0x53')]['id'];}return db[_0xb04b('0x3b')][_0xb04b('0x54')]({'where':{'id':_0x3ccc08[_0xb04b('0x50')]['id']}})[_0xb04b('0x1f')](handleEntityNotFound(_0x5ae529,null))['then'](saveUpdates(_0x3ccc08['body'],null))['then'](respondWithResult(_0x5ae529,null))[_0xb04b('0x29')](handleError(_0x5ae529,null));};exports[_0xb04b('0x36')]=function(_0x480958,_0x4953e6){return db[_0xb04b('0x3b')]['find']({'where':{'id':_0x480958[_0xb04b('0x50')]['id']}})[_0xb04b('0x1f')](handleEntityNotFound(_0x4953e6,null))[_0xb04b('0x1f')](removeEntity(_0x4953e6,null))[_0xb04b('0x29')](handleError(_0x4953e6,null));};exports['describe']=function(_0xc2ad8d,_0x594590){return db[_0xb04b('0x3b')][_0xb04b('0x55')]()[_0xb04b('0x1f')](respondWithResult(_0x594590,null))[_0xb04b('0x29')](handleError(_0x594590,null));};var interaction_log=require(_0xb04b('0x12'))(_0xb04b('0x56'));exports[_0xb04b('0x57')]=function(_0x4ef959,_0x430fb2,_0x44caa1){var _0x486823={'agent':{},'channel':_0xb04b('0x58')};if(_0x4ef959[_0xb04b('0x53')]['id']){delete _0x4ef959[_0xb04b('0x53')]['id'];}_0x4ef959[_0xb04b('0x53')][_0xb04b('0x59')]=!![];_0x4ef959[_0xb04b('0x53')][_0xb04b('0x5a')]=moment()[_0xb04b('0x5b')]('YYYY-MM-DD\x20HH:mm:ss');_0x4ef959[_0xb04b('0x53')][_0xb04b('0x5c')]=_0x4ef959[_0xb04b('0x53')][_0xb04b('0x5c')]||_0x4ef959['user']['id'];_0x486823[_0xb04b('0x5d')]['id']=_0x4ef959[_0xb04b('0x53')][_0xb04b('0x5c')];return db[_0xb04b('0x3b')][_0xb04b('0x54')]({'where':{'id':_0x4ef959[_0xb04b('0x50')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x430fb2,null))[_0xb04b('0x1f')](saveUpdates(_0x4ef959[_0xb04b('0x53')],null))[_0xb04b('0x1f')](function(_0x1752c6){if(_0x1752c6){_0x486823[_0xb04b('0x27')]=_0x1752c6[_0xb04b('0x5e')]({'plain':!![]});return db[_0xb04b('0x5f')][_0xb04b('0x54')]({'where':{'id':_0x1752c6['FaxInteractionId']}});}return null;})[_0xb04b('0x1f')](handleEntityNotFound(_0x430fb2,null))[_0xb04b('0x1f')](function(_0x2d18d3){if(_0x2d18d3){return _0x2d18d3[_0xb04b('0x52')]({'UserId':_0x4ef959[_0xb04b('0x53')][_0xb04b('0x5c')],'read1stAt':_['isNil'](_0x2d18d3[_0xb04b('0x60')])?moment()[_0xb04b('0x5b')](_0xb04b('0x61')):undefined});}return null;})['then'](function(_0x87953c){if(_0x87953c){_0x486823[_0xb04b('0x62')]=_0x87953c[_0xb04b('0x5e')]({'plain':!![]});interaction_log[_0xb04b('0x28')](_0xb04b('0x63'),_0x4ef959[_0xb04b('0x64')]['id'],_0x4ef959[_0xb04b('0x64')]['name'],_0x4ef959['user'][_0xb04b('0x65')],_0x486823[_0xb04b('0x62')]['id'],_0x4ef959[_0xb04b('0x53')]?JSON['stringify'](_0x4ef959[_0xb04b('0x53')]):_0xb04b('0x66'));return respondWithRpcPromise(_0xb04b('0x67'),_0xb04b('0x68'),_0x486823);}return null;})[_0xb04b('0x1f')](function(_0x2d55be){var _0x801535='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x2d55be[_0xb04b('0x27')]['ContactId'];return db[_0xb04b('0x69')][_0xb04b('0x3e')](_0x801535,{'type':db[_0xb04b('0x6a')][_0xb04b('0x6b')][_0xb04b('0x6c')],'raw':!![]})['then'](function(_0xb3aab1){return _0xb3aab1;});})[_0xb04b('0x1f')](function(_0x559e7f){if(_0x559e7f){_0x486823[_0xb04b('0x27')]['contact']=_0x559e7f[0x0];if(!_0x4ef959[_0xb04b('0x53')]['UserId'])return;return db['User'][_0xb04b('0x54')]({'where':{'id':_0x4ef959[_0xb04b('0x53')][_0xb04b('0x5c')],'role':_0xb04b('0x5d')},'attributes':['id',_0xb04b('0x38'),_0xb04b('0x6d'),'email',_0xb04b('0x6e')],'raw':!![]});}return null;})[_0xb04b('0x1f')](function(_0x4a4226){if(!_0x4a4226)return null;_0x486823[_0xb04b('0x27')][_0xb04b('0x5d')]=_0x4a4226;return _0x486823;})[_0xb04b('0x1f')](function(_0x22506b){if(_0x22506b){if(_0x4ef959[_0xb04b('0x53')][_0xb04b('0x6f')]){_0x486823[_0xb04b('0x27')][_0xb04b('0x70')]=util[_0xb04b('0x5b')](_0xb04b('0x71'),_0x4ef959[_0xb04b('0x64')][_0xb04b('0x38')]);_0x486823[_0xb04b('0x27')][_0xb04b('0x72')]=_0x486823[_0xb04b('0x72')];_0x486823[_0xb04b('0x27')]['motionChannel']=_0x486823['channel'];_0x486823[_0xb04b('0x27')][_0xb04b('0x73')]=_0xb04b('0x57');return respondWithRpcPromise(_0xb04b('0x74'),'EventManager',{'event':'acceptmessage','message':_0x486823[_0xb04b('0x27')]},client9002)['then'](function(){return _0x486823;});}return _0x486823;}return null;})[_0xb04b('0x1f')](respondWithResult(_0x430fb2,null))[_0xb04b('0x29')](handleError(_0x430fb2,null));};var interaction_log=require(_0xb04b('0x12'))(_0xb04b('0x56'));exports[_0xb04b('0x75')]=function(_0x16432b,_0x5624cf,_0x1a9730){var _0x1c3e46={'agent':{},'channel':_0xb04b('0x58')};if(_0x16432b[_0xb04b('0x53')]['id']){delete _0x16432b['body']['id'];}_0x16432b[_0xb04b('0x53')][_0xb04b('0x5c')]=_0x16432b['body'][_0xb04b('0x5c')]||_0x16432b[_0xb04b('0x64')]['id'];_0x1c3e46['agent']['id']=_0x16432b[_0xb04b('0x53')]['UserId'];return db[_0xb04b('0x3b')][_0xb04b('0x54')]({'where':{'id':_0x16432b[_0xb04b('0x50')]['id'],'UserId':null}})[_0xb04b('0x1f')](handleEntityNotFound(_0x5624cf,null))[_0xb04b('0x1f')](function(_0x470e4b){if(_0x470e4b){_0x1c3e46[_0xb04b('0x27')]=_0x470e4b['get']({'plain':!![]});return db[_0xb04b('0x5f')][_0xb04b('0x54')]({'where':{'id':_0x470e4b[_0xb04b('0x76')]}});}return null;})['then'](handleEntityNotFound(_0x5624cf,null))[_0xb04b('0x1f')](function(_0x312a96){if(_0x312a96){_0x1c3e46['interaction']=_0x312a96[_0xb04b('0x5e')]({'plain':!![]});interaction_log['info']('[FAXMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x16432b['user']['id'],_0x16432b[_0xb04b('0x64')]['name'],_0x16432b['user'][_0xb04b('0x65')],_0x1c3e46[_0xb04b('0x62')]['id'],_0x16432b['body']?JSON[_0xb04b('0x23')](_0x16432b[_0xb04b('0x53')]):'null');return respondWithRpcPromise(_0xb04b('0x77'),_0xb04b('0x78'),_0x1c3e46);}return null;})['then'](function(_0x3c2ae4){var _0x22fb52=_0xb04b('0x79')+_0x3c2ae4['message']['ContactId'];return db[_0xb04b('0x69')]['query'](_0x22fb52,{'type':db[_0xb04b('0x6a')][_0xb04b('0x6b')][_0xb04b('0x6c')],'raw':!![]})[_0xb04b('0x1f')](function(_0xaa1cfb){return _0xaa1cfb;});})['then'](function(_0x3f7bbe){if(_0x3f7bbe){_0x1c3e46[_0xb04b('0x27')]['contact']=_0x3f7bbe[0x0];if(!_0x16432b[_0xb04b('0x53')][_0xb04b('0x5c')])return;return db['User']['find']({'where':{'id':_0x16432b[_0xb04b('0x53')][_0xb04b('0x5c')],'role':_0xb04b('0x5d')},'attributes':['id',_0xb04b('0x38'),'fullname','email',_0xb04b('0x6e')],'raw':!![]});}return null;})[_0xb04b('0x1f')](function(_0x152e84){if(!_0x152e84)return null;_0x1c3e46[_0xb04b('0x27')]['agent']=_0x152e84;return _0x1c3e46;})[_0xb04b('0x1f')](function(_0x4978cf){if(_0x4978cf){_0x4978cf['message'][_0xb04b('0x70')]=util[_0xb04b('0x5b')](_0xb04b('0x71'),_0x16432b[_0xb04b('0x64')][_0xb04b('0x38')]);_0x4978cf[_0xb04b('0x27')][_0xb04b('0x72')]=_0x1c3e46[_0xb04b('0x72')];_0x4978cf['message'][_0xb04b('0x7a')]=_0x1c3e46[_0xb04b('0x72')];_0x4978cf[_0xb04b('0x27')][_0xb04b('0x73')]=_0xb04b('0x75');respondWithRpcPromise(_0xb04b('0x74'),_0xb04b('0x74'),{'event':_0xb04b('0x7b'),'message':_0x4978cf[_0xb04b('0x27')]},client9002);return _0x1c3e46;}return null;})['then'](respondWithResult(_0x5624cf,null))[_0xb04b('0x29')](handleError(_0x5624cf,null));};exports[_0xb04b('0x7c')]=function(_0x3c9bb0,_0x46c2ed){var _0x1d7618;return db[_0xb04b('0x3b')][_0xb04b('0x7c')](_0x3c9bb0['body'],{})[_0xb04b('0x1f')](function(_0x36615d){_0x1d7618=_0x36615d;return db['CmContact'][_0xb04b('0x7d')]({'where':{'id':_0x1d7618[_0xb04b('0x7e')]}});})['then'](function(_0x1d6138){if(_[_0xb04b('0x7f')](_0x1d6138)){return;}else{_0x1d7618[_0xb04b('0x58')]=_0x1d6138[_0xb04b('0x58')];return db['Attachment'][_0xb04b('0x7d')]({'where':{'id':_0x1d7618[_0xb04b('0x80')]}});}})[_0xb04b('0x1f')](function(_0x3abf29){return respondWithRpcPromise(_0xb04b('0x81'),_0xb04b('0x81'),{'FaxAccountId':_[_0xb04b('0x7f')](_0x3c9bb0['body'])?undefined:_0x3c9bb0[_0xb04b('0x53')]['FaxAccountId'],'path':_['isNil'](_0x3abf29)?undefined:util[_0xb04b('0x5b')]('/var/opt/motion2/server/files/attachments/%s',_0x3abf29['basename']),'fax':_[_0xb04b('0x7f')](_0x1d7618[_0xb04b('0x58')])?undefined:_0x1d7618['fax'],'AttachmentId':_0x1d7618[_0xb04b('0x80')]},client9002);})[_0xb04b('0x1f')](respondWithResult(_0x46c2ed,0xc9))[_0xb04b('0x29')](handleError(_0x46c2ed,null));};exports[_0xb04b('0x82')]=function(_0x29501a,_0x111a39){var _0x49888f=path[_0xb04b('0x83')](config[_0xb04b('0x84')],_0xb04b('0x85'),_0xb04b('0x86'),_0xb04b('0x87'));return db['FaxMessage'][_0xb04b('0x54')]({'where':{'id':_0x29501a[_0xb04b('0x50')]['id']},'include':[{'model':db[_0xb04b('0x88')],'as':_0xb04b('0x88')}]})[_0xb04b('0x1f')](handleEntityNotFound(_0x111a39,null))[_0xb04b('0x1f')](function(_0x269fbf){if(_0x269fbf){return _0x111a39[_0xb04b('0x82')](path['join'](_0x49888f,_0x269fbf[_0xb04b('0x88')][_0xb04b('0x89')]));}})[_0xb04b('0x29')](handleError(_0x111a39,null));};