a56c3d32e6cc93c6c2e00409839014ae05c50520
[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 _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));};