Built motion from commit da617fac.|2.6.6
[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 _0x71ff=['attributes','fields','hasOwnProperty','nolimit','sort','where','pick','filter','merge','options','include','findAll','rows','show','length','includeAll','find','update','body','params','describe','fax-interactions','accept','fax','read','YYYY-MM-DD\x20HH:mm:ss','UserId','user','get','FaxInteraction','FaxInteractionId','isNil','read1stAt','interaction','[FAXMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','Sequelize','QueryTypes','SELECT','contact','email','internal','agent','SIP/%s','channel','event','EventManager','acceptmessage','reject','[FAXMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','User','interface','motionChannel','create','CmContact','findOne','Attachment','SendFax','FaxAccountId','format','/var/opt/motion2/server/files/attachments/%s','basename','download','join','root','server','attachments','eml-format','request-promise','moment','bluebird','util','sox','ejs','fs-extra','lodash','squel','jsforce','desk.js','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','socket.io-emitter','./faxMessage.socket','jayson/promise','client','http','request','then','info','request\x20sent','debug','FaxMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','FaxMessage,\x20%s,\x20%s','message','result','catch','sendStatus','end','json','offset','undefined','count','limit','status','set','Content-Range','apply','destroy','stack','name','index','FaxMessage','rawAttributes','fieldName','type','model','map','keys','query','filters','intersection'];(function(_0x352041,_0x170746){var _0x38be0b=function(_0x5b5e00){while(--_0x5b5e00){_0x352041['push'](_0x352041['shift']());}};_0x38be0b(++_0x170746);}(_0x71ff,0x1f4));var _0xf71f=function(_0x2cae8e,_0x32a809){_0x2cae8e=_0x2cae8e-0x0;var _0x59fd42=_0x71ff[_0x2cae8e];return _0x59fd42;};'use strict';var emlformat=require(_0xf71f('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xf71f('0x1'));var moment=require(_0xf71f('0x2'));var BPromise=require(_0xf71f('0x3'));var Mustache=require('mustache');var util=require(_0xf71f('0x4'));var path=require('path');var sox=require(_0xf71f('0x5'));var csv=require('to-csv');var ejs=require(_0xf71f('0x6'));var fs=require('fs');var fs_extra=require(_0xf71f('0x7'));var _=require(_0xf71f('0x8'));var squel=require(_0xf71f('0x9'));var crypto=require('crypto');var jsforce=require(_0xf71f('0xa'));var deskjs=require(_0xf71f('0xb'));var toCsv=require(_0xf71f('0xc'));var querystring=require('querystring');var Papa=require(_0xf71f('0xd'));var Redis=require(_0xf71f('0xe'));var authService=require(_0xf71f('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0xf71f('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf71f('0x11'))(_0xf71f('0x12'));var utils=require(_0xf71f('0x13'));var config=require(_0xf71f('0x14'));var licenseUtil=require(_0xf71f('0x15'));var db=require(_0xf71f('0x16'))['db'];config[_0xf71f('0x17')]=_[_0xf71f('0x18')](config[_0xf71f('0x17')],{'host':'localhost','port':0x18eb});var socket=require(_0xf71f('0x19'))(new Redis(config['redis']));require(_0xf71f('0x1a'))['register'](socket);var jayson=require(_0xf71f('0x1b'));var client=jayson[_0xf71f('0x1c')][_0xf71f('0x1d')]({'port':0x232c});var client9002=jayson[_0xf71f('0x1c')][_0xf71f('0x1d')]({'port':0x232a});function respondWithRpcPromise(_0x331b04,_0x32bbe9,_0x5aeb92,_0x29d3ad){return new BPromise(function(_0x424b0a,_0x3c0a5c){var _0x53bb93=_0x29d3ad||client;return _0x53bb93[_0xf71f('0x1e')](_0x331b04,_0x5aeb92)[_0xf71f('0x1f')](function(_0x2b9944){logger[_0xf71f('0x20')]('FaxMessage,\x20%s,\x20%s',_0x32bbe9,_0xf71f('0x21'));logger[_0xf71f('0x22')](_0xf71f('0x23'),_0x32bbe9,_0xf71f('0x21'),JSON[_0xf71f('0x24')](_0x2b9944));if(_0x2b9944['error']){if(_0x2b9944[_0xf71f('0x25')][_0xf71f('0x26')]===0x1f4){logger['error'](_0xf71f('0x27'),_0x32bbe9,_0x2b9944['error'][_0xf71f('0x28')]);return _0x3c0a5c(_0x2b9944[_0xf71f('0x25')][_0xf71f('0x28')]);}logger[_0xf71f('0x25')](_0xf71f('0x27'),_0x32bbe9,_0x2b9944[_0xf71f('0x25')]['message']);return _0x424b0a(_0x2b9944[_0xf71f('0x25')][_0xf71f('0x28')]);}else{logger[_0xf71f('0x20')](_0xf71f('0x27'),_0x32bbe9,_0xf71f('0x21'));_0x424b0a(_0x2b9944[_0xf71f('0x29')][_0xf71f('0x28')]);}})[_0xf71f('0x2a')](function(_0x35896e){logger[_0xf71f('0x25')](_0xf71f('0x27'),_0x32bbe9,_0x35896e);_0x3c0a5c(_0x35896e);});});}function respondWithStatusCode(_0x1a37ab,_0x5dc1b0){_0x5dc1b0=_0x5dc1b0||0xcc;return function(_0x31d272){if(_0x31d272){return _0x1a37ab[_0xf71f('0x2b')](_0x5dc1b0);}return _0x1a37ab['status'](_0x5dc1b0)[_0xf71f('0x2c')]();};}function respondWithResult(_0x1968af,_0x3eb8c0){_0x3eb8c0=_0x3eb8c0||0xc8;return function(_0x526e21){if(_0x526e21){return _0x1968af['status'](_0x3eb8c0)[_0xf71f('0x2d')](_0x526e21);}};}function respondWithFilteredResult(_0x3a7c0f,_0x47ccf9){return function(_0x3441eb){if(_0x3441eb){var _0x2f67c7=typeof _0x47ccf9[_0xf71f('0x2e')]==='undefined'&&typeof _0x47ccf9['limit']===_0xf71f('0x2f');var _0x19c8e2=_0x3441eb[_0xf71f('0x30')];var _0x258509=_0x2f67c7?0x0:_0x47ccf9[_0xf71f('0x2e')];var _0x26f3aa=_0x2f67c7?_0x3441eb['count']:_0x47ccf9[_0xf71f('0x2e')]+_0x47ccf9[_0xf71f('0x31')];var _0x25b3e4;if(_0x26f3aa>=_0x19c8e2){_0x26f3aa=_0x19c8e2;_0x25b3e4=0xc8;}else{_0x25b3e4=0xce;}_0x3a7c0f[_0xf71f('0x32')](_0x25b3e4);return _0x3a7c0f[_0xf71f('0x33')](_0xf71f('0x34'),_0x258509+'-'+_0x26f3aa+'/'+_0x19c8e2)[_0xf71f('0x2d')](_0x3441eb);}return null;};}function patchUpdates(_0x1d191e){return function(_0x551a55){try{jsonpatch[_0xf71f('0x35')](_0x551a55,_0x1d191e,!![]);}catch(_0x23819b){return BPromise['reject'](_0x23819b);}return _0x551a55['save']();};}function saveUpdates(_0x39768b,_0x40a3d8){return function(_0x398b8e){if(_0x398b8e){return _0x398b8e['update'](_0x39768b)['then'](function(_0x2c7d76){return _0x2c7d76;});}return null;};}function removeEntity(_0x56329a,_0x5d36d4){return function(_0x58d89c){if(_0x58d89c){return _0x58d89c[_0xf71f('0x36')]()['then'](function(){_0x56329a[_0xf71f('0x32')](0xcc)[_0xf71f('0x2c')]();});}};}function handleEntityNotFound(_0x1d3bb2,_0xb174be){return function(_0x11d963){if(!_0x11d963){_0x1d3bb2['sendStatus'](0x194);}return _0x11d963;};}function handleError(_0x174ff1,_0x58fef1){_0x58fef1=_0x58fef1||0x1f4;return function(_0x1da1b2){logger[_0xf71f('0x25')](_0x1da1b2[_0xf71f('0x37')]);if(_0x1da1b2[_0xf71f('0x38')]){delete _0x1da1b2[_0xf71f('0x38')];}_0x174ff1[_0xf71f('0x32')](_0x58fef1)['send'](_0x1da1b2);};}exports[_0xf71f('0x39')]=function(_0x9b1e69,_0x264f7c){var _0x56672e={},_0x47d493={},_0x24d911={'count':0x0,'rows':[]};var _0x4eaa29=_['map'](db[_0xf71f('0x3a')][_0xf71f('0x3b')],function(_0x1d6922){return{'name':_0x1d6922[_0xf71f('0x3c')],'type':_0x1d6922[_0xf71f('0x3d')]['key']};});_0x47d493[_0xf71f('0x3e')]=_[_0xf71f('0x3f')](_0x4eaa29,_0xf71f('0x38'));_0x47d493['query']=_[_0xf71f('0x40')](_0x9b1e69[_0xf71f('0x41')]);_0x47d493[_0xf71f('0x42')]=_[_0xf71f('0x43')](_0x47d493[_0xf71f('0x3e')],_0x47d493[_0xf71f('0x41')]);_0x56672e[_0xf71f('0x44')]=_[_0xf71f('0x43')](_0x47d493['model'],qs[_0xf71f('0x45')](_0x9b1e69[_0xf71f('0x41')][_0xf71f('0x45')]));_0x56672e[_0xf71f('0x44')]=_0x56672e[_0xf71f('0x44')]['length']?_0x56672e[_0xf71f('0x44')]:_0x47d493[_0xf71f('0x3e')];if(!_0x9b1e69[_0xf71f('0x41')][_0xf71f('0x46')](_0xf71f('0x47'))){_0x56672e[_0xf71f('0x31')]=qs[_0xf71f('0x31')](_0x9b1e69[_0xf71f('0x41')][_0xf71f('0x31')]);_0x56672e[_0xf71f('0x2e')]=qs[_0xf71f('0x2e')](_0x9b1e69[_0xf71f('0x41')][_0xf71f('0x2e')]);}_0x56672e['order']=qs['sort'](_0x9b1e69['query'][_0xf71f('0x48')]);_0x56672e[_0xf71f('0x49')]=qs[_0xf71f('0x42')](_[_0xf71f('0x4a')](_0x9b1e69[_0xf71f('0x41')],_0x47d493[_0xf71f('0x42')]),_0x4eaa29);if(_0x9b1e69[_0xf71f('0x41')][_0xf71f('0x4b')]){_0x56672e['where']=_[_0xf71f('0x4c')](_0x56672e[_0xf71f('0x49')],{'$or':_[_0xf71f('0x3f')](_0x4eaa29,function(_0x32dcf6){if(_0x32dcf6[_0xf71f('0x3d')]!=='VIRTUAL'){var _0x43c5ea={};_0x43c5ea[_0x32dcf6[_0xf71f('0x38')]]={'$like':'%'+_0x9b1e69[_0xf71f('0x41')][_0xf71f('0x4b')]+'%'};return _0x43c5ea;}})});}_0x56672e=_[_0xf71f('0x4c')]({},_0x56672e,_0x9b1e69[_0xf71f('0x4d')]);var _0x504a64={'where':_0x56672e[_0xf71f('0x49')]};return db[_0xf71f('0x3a')][_0xf71f('0x30')](_0x504a64)['then'](function(_0x51c7e0){_0x24d911['count']=_0x51c7e0;if(_0x9b1e69[_0xf71f('0x41')]['includeAll']){_0x56672e[_0xf71f('0x4e')]=[{'all':!![]}];}return db[_0xf71f('0x3a')][_0xf71f('0x4f')](_0x56672e);})[_0xf71f('0x1f')](function(_0x5bcccd){_0x24d911[_0xf71f('0x50')]=_0x5bcccd;return _0x24d911;})[_0xf71f('0x1f')](respondWithFilteredResult(_0x264f7c,_0x56672e))[_0xf71f('0x2a')](handleError(_0x264f7c,null));};exports[_0xf71f('0x51')]=function(_0x50ae20,_0xb13352){var _0x106dd0={'raw':!![],'where':{'id':_0x50ae20['params']['id']}},_0x1af481={};_0x1af481[_0xf71f('0x3e')]=_[_0xf71f('0x40')](db['FaxMessage'][_0xf71f('0x3b')]);_0x1af481[_0xf71f('0x41')]=_[_0xf71f('0x40')](_0x50ae20[_0xf71f('0x41')]);_0x1af481[_0xf71f('0x42')]=_[_0xf71f('0x43')](_0x1af481[_0xf71f('0x3e')],_0x1af481['query']);_0x106dd0[_0xf71f('0x44')]=_[_0xf71f('0x43')](_0x1af481[_0xf71f('0x3e')],qs[_0xf71f('0x45')](_0x50ae20[_0xf71f('0x41')][_0xf71f('0x45')]));_0x106dd0[_0xf71f('0x44')]=_0x106dd0['attributes'][_0xf71f('0x52')]?_0x106dd0[_0xf71f('0x44')]:_0x1af481[_0xf71f('0x3e')];if(_0x50ae20[_0xf71f('0x41')][_0xf71f('0x53')]){_0x106dd0['include']=[{'all':!![]}];}_0x106dd0=_[_0xf71f('0x4c')]({},_0x106dd0,_0x50ae20[_0xf71f('0x4d')]);return db[_0xf71f('0x3a')][_0xf71f('0x54')](_0x106dd0)[_0xf71f('0x1f')](handleEntityNotFound(_0xb13352,null))[_0xf71f('0x1f')](respondWithResult(_0xb13352,null))[_0xf71f('0x2a')](handleError(_0xb13352,null));};exports[_0xf71f('0x55')]=function(_0x18bad8,_0x584582){if(_0x18bad8['body']['id']){delete _0x18bad8[_0xf71f('0x56')]['id'];}return db['FaxMessage'][_0xf71f('0x54')]({'where':{'id':_0x18bad8['params']['id']}})[_0xf71f('0x1f')](handleEntityNotFound(_0x584582,null))[_0xf71f('0x1f')](saveUpdates(_0x18bad8[_0xf71f('0x56')],null))[_0xf71f('0x1f')](respondWithResult(_0x584582,null))[_0xf71f('0x2a')](handleError(_0x584582,null));};exports[_0xf71f('0x36')]=function(_0x79808e,_0x2ffcc8){return db[_0xf71f('0x3a')][_0xf71f('0x54')]({'where':{'id':_0x79808e[_0xf71f('0x57')]['id']}})[_0xf71f('0x1f')](handleEntityNotFound(_0x2ffcc8,null))['then'](removeEntity(_0x2ffcc8,null))[_0xf71f('0x2a')](handleError(_0x2ffcc8,null));};exports[_0xf71f('0x58')]=function(_0x1b096c,_0x86293a){return db[_0xf71f('0x3a')][_0xf71f('0x58')]()['then'](respondWithResult(_0x86293a,null))['catch'](handleError(_0x86293a,null));};var interaction_log=require(_0xf71f('0x11'))(_0xf71f('0x59'));exports[_0xf71f('0x5a')]=function(_0x4d33cf,_0x2d1ab8,_0x229b1f){var _0x173e57={'agent':{},'channel':_0xf71f('0x5b')};if(_0x4d33cf[_0xf71f('0x56')]['id']){delete _0x4d33cf[_0xf71f('0x56')]['id'];}_0x4d33cf[_0xf71f('0x56')][_0xf71f('0x5c')]=!![];_0x4d33cf[_0xf71f('0x56')]['readAt']=moment()['format'](_0xf71f('0x5d'));_0x4d33cf[_0xf71f('0x56')][_0xf71f('0x5e')]=_0x4d33cf[_0xf71f('0x56')][_0xf71f('0x5e')]||_0x4d33cf[_0xf71f('0x5f')]['id'];_0x173e57['agent']['id']=_0x4d33cf[_0xf71f('0x56')][_0xf71f('0x5e')];return db[_0xf71f('0x3a')][_0xf71f('0x54')]({'where':{'id':_0x4d33cf[_0xf71f('0x57')]['id'],'UserId':null}})[_0xf71f('0x1f')](handleEntityNotFound(_0x2d1ab8,null))[_0xf71f('0x1f')](saveUpdates(_0x4d33cf[_0xf71f('0x56')],null))[_0xf71f('0x1f')](function(_0x3f233f){if(_0x3f233f){_0x173e57[_0xf71f('0x28')]=_0x3f233f[_0xf71f('0x60')]({'plain':!![]});return db[_0xf71f('0x61')][_0xf71f('0x54')]({'where':{'id':_0x3f233f[_0xf71f('0x62')]}});}return null;})['then'](handleEntityNotFound(_0x2d1ab8,null))['then'](function(_0x4f9c89){if(_0x4f9c89){return _0x4f9c89['update']({'UserId':_0x4d33cf['body']['UserId'],'read1stAt':_[_0xf71f('0x63')](_0x4f9c89[_0xf71f('0x64')])?moment()['format'](_0xf71f('0x5d')):undefined});}return null;})['then'](function(_0x210d7a){if(_0x210d7a){_0x173e57[_0xf71f('0x65')]=_0x210d7a['get']({'plain':!![]});interaction_log[_0xf71f('0x20')](_0xf71f('0x66'),_0x4d33cf[_0xf71f('0x5f')]['id'],_0x4d33cf[_0xf71f('0x5f')]['name'],_0x4d33cf['user'][_0xf71f('0x67')],_0x173e57[_0xf71f('0x65')]['id'],_0x4d33cf[_0xf71f('0x56')]?JSON[_0xf71f('0x24')](_0x4d33cf['body']):_0xf71f('0x68'));return respondWithRpcPromise(_0xf71f('0x69'),_0xf71f('0x6a'),_0x173e57);}return null;})[_0xf71f('0x1f')](function(_0xff666e){var _0x1310ae=_0xf71f('0x6b')+_0xff666e[_0xf71f('0x28')][_0xf71f('0x6c')];return db[_0xf71f('0x6d')][_0xf71f('0x41')](_0x1310ae,{'type':db[_0xf71f('0x6e')][_0xf71f('0x6f')][_0xf71f('0x70')],'raw':!![]})[_0xf71f('0x1f')](function(_0x494857){return _0x494857;});})[_0xf71f('0x1f')](function(_0x8be0a3){if(_0x8be0a3){_0x173e57[_0xf71f('0x28')][_0xf71f('0x71')]=_0x8be0a3[0x0];if(!_0x4d33cf[_0xf71f('0x56')][_0xf71f('0x5e')])return;return db['User'][_0xf71f('0x54')]({'where':{'id':_0x4d33cf['body'][_0xf71f('0x5e')],'role':'agent'},'attributes':['id',_0xf71f('0x38'),'fullname',_0xf71f('0x72'),_0xf71f('0x73')],'raw':!![]});}return null;})[_0xf71f('0x1f')](function(_0x3e68db){if(!_0x3e68db)return null;_0x173e57[_0xf71f('0x28')][_0xf71f('0x74')]=_0x3e68db;return _0x173e57;})[_0xf71f('0x1f')](function(_0x513759){if(_0x513759){if(_0x4d33cf[_0xf71f('0x56')]['manual']){_0x173e57[_0xf71f('0x28')]['interface']=util['format'](_0xf71f('0x75'),_0x4d33cf[_0xf71f('0x5f')][_0xf71f('0x38')]);_0x173e57['message'][_0xf71f('0x76')]=_0x173e57[_0xf71f('0x76')];_0x173e57[_0xf71f('0x28')]['motionChannel']=_0x173e57[_0xf71f('0x76')];_0x173e57['message'][_0xf71f('0x77')]=_0xf71f('0x5a');return respondWithRpcPromise(_0xf71f('0x78'),_0xf71f('0x78'),{'event':_0xf71f('0x79'),'message':_0x173e57[_0xf71f('0x28')]},client9002)[_0xf71f('0x1f')](function(){return _0x173e57;});}return _0x173e57;}return null;})[_0xf71f('0x1f')](respondWithResult(_0x2d1ab8,null))[_0xf71f('0x2a')](handleError(_0x2d1ab8,null));};var interaction_log=require(_0xf71f('0x11'))(_0xf71f('0x59'));exports[_0xf71f('0x7a')]=function(_0x403148,_0x271bac,_0x33e64a){var _0x29cf85={'agent':{},'channel':'fax'};if(_0x403148['body']['id']){delete _0x403148[_0xf71f('0x56')]['id'];}_0x403148[_0xf71f('0x56')][_0xf71f('0x5e')]=_0x403148[_0xf71f('0x56')]['UserId']||_0x403148[_0xf71f('0x5f')]['id'];_0x29cf85[_0xf71f('0x74')]['id']=_0x403148[_0xf71f('0x56')]['UserId'];return db[_0xf71f('0x3a')]['find']({'where':{'id':_0x403148[_0xf71f('0x57')]['id'],'UserId':null}})[_0xf71f('0x1f')](handleEntityNotFound(_0x271bac,null))[_0xf71f('0x1f')](function(_0x3c4f4e){if(_0x3c4f4e){_0x29cf85['message']=_0x3c4f4e['get']({'plain':!![]});return db['FaxInteraction'][_0xf71f('0x54')]({'where':{'id':_0x3c4f4e[_0xf71f('0x62')]}});}return null;})[_0xf71f('0x1f')](handleEntityNotFound(_0x271bac,null))[_0xf71f('0x1f')](function(_0xf68073){if(_0xf68073){_0x29cf85['interaction']=_0xf68073['get']({'plain':!![]});interaction_log[_0xf71f('0x20')](_0xf71f('0x7b'),_0x403148[_0xf71f('0x5f')]['id'],_0x403148[_0xf71f('0x5f')][_0xf71f('0x38')],_0x403148[_0xf71f('0x5f')][_0xf71f('0x67')],_0x29cf85['interaction']['id'],_0x403148[_0xf71f('0x56')]?JSON[_0xf71f('0x24')](_0x403148[_0xf71f('0x56')]):_0xf71f('0x68'));return respondWithRpcPromise(_0xf71f('0x7c'),'rejectMessage',_0x29cf85);}return null;})[_0xf71f('0x1f')](function(_0x2a4282){var _0x52ccbb=_0xf71f('0x6b')+_0x2a4282[_0xf71f('0x28')][_0xf71f('0x6c')];return db[_0xf71f('0x6d')][_0xf71f('0x41')](_0x52ccbb,{'type':db['Sequelize'][_0xf71f('0x6f')][_0xf71f('0x70')],'raw':!![]})['then'](function(_0x2abe35){return _0x2abe35;});})[_0xf71f('0x1f')](function(_0x1c023a){if(_0x1c023a){_0x29cf85[_0xf71f('0x28')]['contact']=_0x1c023a[0x0];if(!_0x403148['body'][_0xf71f('0x5e')])return;return db[_0xf71f('0x7d')]['find']({'where':{'id':_0x403148[_0xf71f('0x56')][_0xf71f('0x5e')],'role':_0xf71f('0x74')},'attributes':['id',_0xf71f('0x38'),'fullname',_0xf71f('0x72'),_0xf71f('0x73')],'raw':!![]});}return null;})[_0xf71f('0x1f')](function(_0x2db7be){if(!_0x2db7be)return null;_0x29cf85['message'][_0xf71f('0x74')]=_0x2db7be;return _0x29cf85;})['then'](function(_0x574db7){if(_0x574db7){_0x574db7[_0xf71f('0x28')][_0xf71f('0x7e')]=util['format'](_0xf71f('0x75'),_0x403148[_0xf71f('0x5f')][_0xf71f('0x38')]);_0x574db7[_0xf71f('0x28')][_0xf71f('0x76')]=_0x29cf85['channel'];_0x574db7[_0xf71f('0x28')][_0xf71f('0x7f')]=_0x29cf85[_0xf71f('0x76')];_0x574db7['message'][_0xf71f('0x77')]=_0xf71f('0x7a');respondWithRpcPromise(_0xf71f('0x78'),_0xf71f('0x78'),{'event':'rejectmessage','message':_0x574db7[_0xf71f('0x28')]},client9002);return _0x29cf85;}return null;})[_0xf71f('0x1f')](respondWithResult(_0x271bac,null))['catch'](handleError(_0x271bac,null));};exports[_0xf71f('0x80')]=function(_0x2d0f77,_0x59c197){var _0x3bcc33;return db[_0xf71f('0x3a')]['create'](_0x2d0f77[_0xf71f('0x56')],{})['then'](function(_0x3d21f7){_0x3bcc33=_0x3d21f7;return db[_0xf71f('0x81')][_0xf71f('0x82')]({'where':{'id':_0x3bcc33[_0xf71f('0x6c')]}});})[_0xf71f('0x1f')](function(_0x178da8){if(_[_0xf71f('0x63')](_0x178da8)){return;}else{_0x3bcc33[_0xf71f('0x5b')]=_0x178da8['fax'];return db[_0xf71f('0x83')][_0xf71f('0x82')]({'where':{'id':_0x3bcc33['AttachmentId']}});}})[_0xf71f('0x1f')](function(_0x625632){return respondWithRpcPromise('SendFax',_0xf71f('0x84'),{'FaxAccountId':_[_0xf71f('0x63')](_0x2d0f77[_0xf71f('0x56')])?undefined:_0x2d0f77[_0xf71f('0x56')][_0xf71f('0x85')],'path':_['isNil'](_0x625632)?undefined:util[_0xf71f('0x86')](_0xf71f('0x87'),_0x625632[_0xf71f('0x88')]),'fax':_[_0xf71f('0x63')](_0x3bcc33[_0xf71f('0x5b')])?undefined:_0x3bcc33[_0xf71f('0x5b')],'AttachmentId':_0x3bcc33['AttachmentId']},client9002);})[_0xf71f('0x1f')](respondWithResult(_0x59c197,0xc9))[_0xf71f('0x2a')](handleError(_0x59c197,null));};exports[_0xf71f('0x89')]=function(_0xc3d6df,_0x79989){var _0xbbd56c=path[_0xf71f('0x8a')](config[_0xf71f('0x8b')],_0xf71f('0x8c'),'files',_0xf71f('0x8d'));return db[_0xf71f('0x3a')]['find']({'where':{'id':_0xc3d6df['params']['id']},'include':[{'model':db['Attachment'],'as':'Attachment'}]})[_0xf71f('0x1f')](handleEntityNotFound(_0x79989,null))[_0xf71f('0x1f')](function(_0xcc9482){if(_0xcc9482){return _0x79989['download'](path[_0xf71f('0x8a')](_0xbbd56c,_0xcc9482[_0xf71f('0x83')][_0xf71f('0x88')]));}})[_0xf71f('0x2a')](handleError(_0x79989,null));};