c3bbc927188421627332e59161d20d30253ffb58
[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 _0x2b5d=['sort','filters','filter','merge','where','VIRTUAL','options','count','includeAll','findAll','rows','params','find','body','destroy','describe','fax-interactions','accept','fax','read','format','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','sequelize','Sequelize','QueryTypes','SELECT','contact','User','fullname','internal','manual','interface','SIP/%s','channel','motionChannel','event','acceptmessage','agent','role','RejectMessage','rejectMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','email','EventManager','rejectmessage','create','CmContact','findOne','AttachmentId','SendFax','FaxAccountId','/var/opt/motion2/server/files/attachments/%s','basename','download','root','server','attachments','Attachment','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','./faxMessage.socket','register','jayson/promise','http','request','then','info','FaxMessage,\x20%s,\x20%s','debug','FaxMessage,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','result','catch','sendStatus','end','status','undefined','limit','offset','set','json','reject','update','name','send','FaxMessage','rawAttributes','fieldName','type','key','map','query','keys','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order'];(function(_0x5d4607,_0x6b5e7b){var _0x5e4a86=function(_0x46891a){while(--_0x46891a){_0x5d4607['push'](_0x5d4607['shift']());}};_0x5e4a86(++_0x6b5e7b);}(_0x2b5d,0x15f));var _0xd2b5=function(_0x3f6515,_0x18cc88){_0x3f6515=_0x3f6515-0x0;var _0x259183=_0x2b5d[_0x3f6515];return _0x259183;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xd2b5('0x0'));var zipdir=require(_0xd2b5('0x1'));var jsonpatch=require(_0xd2b5('0x2'));var rp=require(_0xd2b5('0x3'));var moment=require(_0xd2b5('0x4'));var BPromise=require(_0xd2b5('0x5'));var Mustache=require('mustache');var util=require(_0xd2b5('0x6'));var path=require(_0xd2b5('0x7'));var sox=require(_0xd2b5('0x8'));var csv=require(_0xd2b5('0x9'));var ejs=require(_0xd2b5('0xa'));var fs=require('fs');var fs_extra=require(_0xd2b5('0xb'));var _=require(_0xd2b5('0xc'));var squel=require(_0xd2b5('0xd'));var crypto=require(_0xd2b5('0xe'));var jsforce=require('jsforce');var deskjs=require(_0xd2b5('0xf'));var toCsv=require(_0xd2b5('0x9'));var querystring=require(_0xd2b5('0x10'));var Papa=require(_0xd2b5('0x11'));var Redis=require(_0xd2b5('0x12'));var authService=require(_0xd2b5('0x13'));var qs=require('../../components/parsers/qs');var as=require(_0xd2b5('0x14'));var hardwareService=require(_0xd2b5('0x15'));var logger=require(_0xd2b5('0x16'))(_0xd2b5('0x17'));var utils=require('../../config/utils');var config=require(_0xd2b5('0x18'));var licenseUtil=require(_0xd2b5('0x19'));var db=require(_0xd2b5('0x1a'))['db'];config[_0xd2b5('0x1b')]=_[_0xd2b5('0x1c')](config[_0xd2b5('0x1b')],{'host':_0xd2b5('0x1d'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xd2b5('0x1b')]));require(_0xd2b5('0x1e'))[_0xd2b5('0x1f')](socket);var jayson=require(_0xd2b5('0x20'));var client=jayson['client'][_0xd2b5('0x21')]({'port':0x232c});var client9002=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x599f67,_0x10852c,_0x820b3c,_0x44d2f7){return new BPromise(function(_0x4bacf3,_0x151e3a){var _0x334eaf=_0x44d2f7||client;return _0x334eaf[_0xd2b5('0x22')](_0x599f67,_0x820b3c)[_0xd2b5('0x23')](function(_0x1d7d9d){logger[_0xd2b5('0x24')](_0xd2b5('0x25'),_0x10852c,'request\x20sent');logger[_0xd2b5('0x26')](_0xd2b5('0x27'),_0x10852c,_0xd2b5('0x28'),JSON[_0xd2b5('0x29')](_0x1d7d9d));if(_0x1d7d9d[_0xd2b5('0x2a')]){if(_0x1d7d9d[_0xd2b5('0x2a')][_0xd2b5('0x2b')]===0x1f4){logger[_0xd2b5('0x2a')]('FaxMessage,\x20%s,\x20%s',_0x10852c,_0x1d7d9d['error']['message']);return _0x151e3a(_0x1d7d9d['error']['message']);}logger[_0xd2b5('0x2a')](_0xd2b5('0x25'),_0x10852c,_0x1d7d9d[_0xd2b5('0x2a')][_0xd2b5('0x2c')]);return _0x4bacf3(_0x1d7d9d[_0xd2b5('0x2a')]['message']);}else{logger[_0xd2b5('0x24')](_0xd2b5('0x25'),_0x10852c,_0xd2b5('0x28'));_0x4bacf3(_0x1d7d9d[_0xd2b5('0x2d')]['message']);}})[_0xd2b5('0x2e')](function(_0xd63f28){logger[_0xd2b5('0x2a')](_0xd2b5('0x25'),_0x10852c,_0xd63f28);_0x151e3a(_0xd63f28);});});}function respondWithStatusCode(_0x139cf3,_0x52df98){_0x52df98=_0x52df98||0xcc;return function(_0x10dc7c){if(_0x10dc7c){return _0x139cf3[_0xd2b5('0x2f')](_0x52df98);}return _0x139cf3['status'](_0x52df98)[_0xd2b5('0x30')]();};}function respondWithResult(_0x2f2eea,_0x3a78f2){_0x3a78f2=_0x3a78f2||0xc8;return function(_0x56637c){if(_0x56637c){return _0x2f2eea[_0xd2b5('0x31')](_0x3a78f2)['json'](_0x56637c);}};}function respondWithFilteredResult(_0x223c05,_0x45979){return function(_0x31baa9){if(_0x31baa9){var _0x50fd31=typeof _0x45979['offset']===_0xd2b5('0x32')&&typeof _0x45979[_0xd2b5('0x33')]==='undefined';var _0x26fe2b=_0x31baa9['count'];var _0x30545b=_0x50fd31?0x0:_0x45979[_0xd2b5('0x34')];var _0x35a456=_0x50fd31?_0x31baa9['count']:_0x45979[_0xd2b5('0x34')]+_0x45979['limit'];var _0x34f86f;if(_0x35a456>=_0x26fe2b){_0x35a456=_0x26fe2b;_0x34f86f=0xc8;}else{_0x34f86f=0xce;}_0x223c05[_0xd2b5('0x31')](_0x34f86f);return _0x223c05[_0xd2b5('0x35')]('Content-Range',_0x30545b+'-'+_0x35a456+'/'+_0x26fe2b)[_0xd2b5('0x36')](_0x31baa9);}return null;};}function patchUpdates(_0x22f0ac){return function(_0x253f50){try{jsonpatch['apply'](_0x253f50,_0x22f0ac,!![]);}catch(_0xa77339){return BPromise[_0xd2b5('0x37')](_0xa77339);}return _0x253f50['save']();};}function saveUpdates(_0x3713d4,_0x298ae4){return function(_0x1a4fc5){if(_0x1a4fc5){return _0x1a4fc5[_0xd2b5('0x38')](_0x3713d4)[_0xd2b5('0x23')](function(_0x1e4dfc){return _0x1e4dfc;});}return null;};}function removeEntity(_0x2d37ee,_0x3ae322){return function(_0x487efb){if(_0x487efb){return _0x487efb['destroy']()[_0xd2b5('0x23')](function(){_0x2d37ee['status'](0xcc)[_0xd2b5('0x30')]();});}};}function handleEntityNotFound(_0x546d22,_0x2294d4){return function(_0x168819){if(!_0x168819){_0x546d22[_0xd2b5('0x2f')](0x194);}return _0x168819;};}function handleError(_0x8f8555,_0x26dfe0){_0x26dfe0=_0x26dfe0||0x1f4;return function(_0x3a2063){logger[_0xd2b5('0x2a')](_0x3a2063['stack']);if(_0x3a2063['name']){delete _0x3a2063[_0xd2b5('0x39')];}_0x8f8555[_0xd2b5('0x31')](_0x26dfe0)[_0xd2b5('0x3a')](_0x3a2063);};}exports['index']=function(_0x2ec822,_0x35e49f){var _0x123657={},_0x98683c={},_0x204220={'count':0x0,'rows':[]};var _0xafcadb=_['map'](db[_0xd2b5('0x3b')][_0xd2b5('0x3c')],function(_0x1f1f18){return{'name':_0x1f1f18[_0xd2b5('0x3d')],'type':_0x1f1f18[_0xd2b5('0x3e')][_0xd2b5('0x3f')]};});_0x98683c['model']=_[_0xd2b5('0x40')](_0xafcadb,_0xd2b5('0x39'));_0x98683c[_0xd2b5('0x41')]=_[_0xd2b5('0x42')](_0x2ec822[_0xd2b5('0x41')]);_0x98683c['filters']=_[_0xd2b5('0x43')](_0x98683c[_0xd2b5('0x44')],_0x98683c[_0xd2b5('0x41')]);_0x123657[_0xd2b5('0x45')]=_[_0xd2b5('0x43')](_0x98683c['model'],qs[_0xd2b5('0x46')](_0x2ec822['query'][_0xd2b5('0x46')]));_0x123657[_0xd2b5('0x45')]=_0x123657['attributes'][_0xd2b5('0x47')]?_0x123657['attributes']:_0x98683c[_0xd2b5('0x44')];if(!_0x2ec822[_0xd2b5('0x41')][_0xd2b5('0x48')](_0xd2b5('0x49'))){_0x123657[_0xd2b5('0x33')]=qs['limit'](_0x2ec822[_0xd2b5('0x41')][_0xd2b5('0x33')]);_0x123657['offset']=qs[_0xd2b5('0x34')](_0x2ec822[_0xd2b5('0x41')][_0xd2b5('0x34')]);}_0x123657[_0xd2b5('0x4a')]=qs[_0xd2b5('0x4b')](_0x2ec822[_0xd2b5('0x41')][_0xd2b5('0x4b')]);_0x123657['where']=qs[_0xd2b5('0x4c')](_['pick'](_0x2ec822[_0xd2b5('0x41')],_0x98683c[_0xd2b5('0x4c')]),_0xafcadb);if(_0x2ec822[_0xd2b5('0x41')][_0xd2b5('0x4d')]){_0x123657['where']=_[_0xd2b5('0x4e')](_0x123657[_0xd2b5('0x4f')],{'$or':_[_0xd2b5('0x40')](_0xafcadb,function(_0x3181fc){if(_0x3181fc['type']!==_0xd2b5('0x50')){var _0x1dbb05={};_0x1dbb05[_0x3181fc[_0xd2b5('0x39')]]={'$like':'%'+_0x2ec822[_0xd2b5('0x41')][_0xd2b5('0x4d')]+'%'};return _0x1dbb05;}})});}_0x123657=_[_0xd2b5('0x4e')]({},_0x123657,_0x2ec822[_0xd2b5('0x51')]);var _0x36059b={'where':_0x123657['where']};return db[_0xd2b5('0x3b')][_0xd2b5('0x52')](_0x36059b)[_0xd2b5('0x23')](function(_0x2ee3e3){_0x204220['count']=_0x2ee3e3;if(_0x2ec822['query'][_0xd2b5('0x53')]){_0x123657['include']=[{'all':!![]}];}return db[_0xd2b5('0x3b')][_0xd2b5('0x54')](_0x123657);})[_0xd2b5('0x23')](function(_0x386e17){_0x204220[_0xd2b5('0x55')]=_0x386e17;return _0x204220;})[_0xd2b5('0x23')](respondWithFilteredResult(_0x35e49f,_0x123657))[_0xd2b5('0x2e')](handleError(_0x35e49f,null));};exports['show']=function(_0x4dee93,_0x4fb0e6){var _0x3ff720={'raw':!![],'where':{'id':_0x4dee93[_0xd2b5('0x56')]['id']}},_0xbd982={};_0xbd982[_0xd2b5('0x44')]=_['keys'](db[_0xd2b5('0x3b')][_0xd2b5('0x3c')]);_0xbd982[_0xd2b5('0x41')]=_[_0xd2b5('0x42')](_0x4dee93[_0xd2b5('0x41')]);_0xbd982[_0xd2b5('0x4c')]=_[_0xd2b5('0x43')](_0xbd982[_0xd2b5('0x44')],_0xbd982[_0xd2b5('0x41')]);_0x3ff720['attributes']=_[_0xd2b5('0x43')](_0xbd982[_0xd2b5('0x44')],qs[_0xd2b5('0x46')](_0x4dee93['query']['fields']));_0x3ff720[_0xd2b5('0x45')]=_0x3ff720[_0xd2b5('0x45')][_0xd2b5('0x47')]?_0x3ff720[_0xd2b5('0x45')]:_0xbd982[_0xd2b5('0x44')];if(_0x4dee93['query'][_0xd2b5('0x53')]){_0x3ff720['include']=[{'all':!![]}];}_0x3ff720=_[_0xd2b5('0x4e')]({},_0x3ff720,_0x4dee93['options']);return db['FaxMessage'][_0xd2b5('0x57')](_0x3ff720)[_0xd2b5('0x23')](handleEntityNotFound(_0x4fb0e6,null))[_0xd2b5('0x23')](respondWithResult(_0x4fb0e6,null))[_0xd2b5('0x2e')](handleError(_0x4fb0e6,null));};exports[_0xd2b5('0x38')]=function(_0x1b89c3,_0x474d7d){if(_0x1b89c3[_0xd2b5('0x58')]['id']){delete _0x1b89c3[_0xd2b5('0x58')]['id'];}return db[_0xd2b5('0x3b')][_0xd2b5('0x57')]({'where':{'id':_0x1b89c3['params']['id']}})[_0xd2b5('0x23')](handleEntityNotFound(_0x474d7d,null))[_0xd2b5('0x23')](saveUpdates(_0x1b89c3[_0xd2b5('0x58')],null))[_0xd2b5('0x23')](respondWithResult(_0x474d7d,null))[_0xd2b5('0x2e')](handleError(_0x474d7d,null));};exports[_0xd2b5('0x59')]=function(_0x283937,_0x27613a){return db[_0xd2b5('0x3b')][_0xd2b5('0x57')]({'where':{'id':_0x283937[_0xd2b5('0x56')]['id']}})['then'](handleEntityNotFound(_0x27613a,null))[_0xd2b5('0x23')](removeEntity(_0x27613a,null))[_0xd2b5('0x2e')](handleError(_0x27613a,null));};exports[_0xd2b5('0x5a')]=function(_0x2a535b,_0xf44d18){return db[_0xd2b5('0x3b')][_0xd2b5('0x5a')]()[_0xd2b5('0x23')](respondWithResult(_0xf44d18,null))['catch'](handleError(_0xf44d18,null));};var interaction_log=require('../../config/logger')(_0xd2b5('0x5b'));exports[_0xd2b5('0x5c')]=function(_0x4df616,_0x2956c6,_0x588a4a){var _0xeaa83b={'agent':{},'channel':_0xd2b5('0x5d')};if(_0x4df616[_0xd2b5('0x58')]['id']){delete _0x4df616[_0xd2b5('0x58')]['id'];}_0x4df616[_0xd2b5('0x58')][_0xd2b5('0x5e')]=!![];_0x4df616[_0xd2b5('0x58')]['readAt']=moment()[_0xd2b5('0x5f')](_0xd2b5('0x60'));_0x4df616[_0xd2b5('0x58')][_0xd2b5('0x61')]=_0x4df616[_0xd2b5('0x58')][_0xd2b5('0x61')]||_0x4df616[_0xd2b5('0x62')]['id'];_0xeaa83b['agent']['id']=_0x4df616[_0xd2b5('0x58')][_0xd2b5('0x61')];return db[_0xd2b5('0x3b')][_0xd2b5('0x57')]({'where':{'id':_0x4df616['params']['id'],'UserId':null}})[_0xd2b5('0x23')](handleEntityNotFound(_0x2956c6,null))['then'](saveUpdates(_0x4df616[_0xd2b5('0x58')],null))['then'](function(_0x1ecb2e){if(_0x1ecb2e){_0xeaa83b['message']=_0x1ecb2e[_0xd2b5('0x63')]({'plain':!![]});return db[_0xd2b5('0x64')][_0xd2b5('0x57')]({'where':{'id':_0x1ecb2e[_0xd2b5('0x65')]}});}return null;})[_0xd2b5('0x23')](handleEntityNotFound(_0x2956c6,null))[_0xd2b5('0x23')](function(_0x685660){if(_0x685660){return _0x685660[_0xd2b5('0x38')]({'UserId':_0x4df616['body']['UserId'],'read1stAt':_[_0xd2b5('0x66')](_0x685660[_0xd2b5('0x67')])?moment()['format'](_0xd2b5('0x60')):undefined});}return null;})[_0xd2b5('0x23')](function(_0x2fd1a3){if(_0x2fd1a3){_0xeaa83b[_0xd2b5('0x68')]=_0x2fd1a3['get']({'plain':!![]});interaction_log[_0xd2b5('0x24')](_0xd2b5('0x69'),_0x4df616['user']['id'],_0x4df616[_0xd2b5('0x62')][_0xd2b5('0x39')],_0x4df616['user']['role'],_0xeaa83b['interaction']['id'],_0x4df616['body']?JSON[_0xd2b5('0x29')](_0x4df616['body']):'null');return respondWithRpcPromise('AcceptMessage','acceptMessage',_0xeaa83b);}return null;})[_0xd2b5('0x23')](function(_0x384e1f){var _0x431a74='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x384e1f[_0xd2b5('0x2c')]['ContactId'];return db[_0xd2b5('0x6a')][_0xd2b5('0x41')](_0x431a74,{'type':db[_0xd2b5('0x6b')][_0xd2b5('0x6c')][_0xd2b5('0x6d')],'raw':!![]})['then'](function(_0x36430b){return _0x36430b;});})[_0xd2b5('0x23')](function(_0x147ef7){if(_0x147ef7){_0xeaa83b[_0xd2b5('0x2c')][_0xd2b5('0x6e')]=_0x147ef7[0x0];if(!_0x4df616[_0xd2b5('0x58')][_0xd2b5('0x61')])return;return db[_0xd2b5('0x6f')][_0xd2b5('0x57')]({'where':{'id':_0x4df616[_0xd2b5('0x58')][_0xd2b5('0x61')],'role':'agent'},'attributes':['id',_0xd2b5('0x39'),_0xd2b5('0x70'),'email',_0xd2b5('0x71')],'raw':!![]});}return null;})['then'](function(_0x48e546){if(!_0x48e546)return null;_0xeaa83b[_0xd2b5('0x2c')]['agent']=_0x48e546;return _0xeaa83b;})['then'](function(_0x4159d3){if(_0x4159d3){if(_0x4df616[_0xd2b5('0x58')][_0xd2b5('0x72')]){_0xeaa83b[_0xd2b5('0x2c')][_0xd2b5('0x73')]=util['format'](_0xd2b5('0x74'),_0x4df616[_0xd2b5('0x62')][_0xd2b5('0x39')]);_0xeaa83b['message']['channel']=_0xeaa83b[_0xd2b5('0x75')];_0xeaa83b['message'][_0xd2b5('0x76')]=_0xeaa83b[_0xd2b5('0x75')];_0xeaa83b['message'][_0xd2b5('0x77')]=_0xd2b5('0x5c');return respondWithRpcPromise('EventManager','EventManager',{'event':_0xd2b5('0x78'),'message':_0xeaa83b[_0xd2b5('0x2c')]},client9002)['then'](function(){return _0xeaa83b;});}return _0xeaa83b;}return null;})[_0xd2b5('0x23')](respondWithResult(_0x2956c6,null))['catch'](handleError(_0x2956c6,null));};var interaction_log=require(_0xd2b5('0x16'))(_0xd2b5('0x5b'));exports['reject']=function(_0x1773b6,_0x4977b8,_0x40df55){var _0x1842b1={'agent':{},'channel':_0xd2b5('0x5d')};if(_0x1773b6['body']['id']){delete _0x1773b6[_0xd2b5('0x58')]['id'];}_0x1773b6[_0xd2b5('0x58')]['UserId']=_0x1773b6[_0xd2b5('0x58')]['UserId']||_0x1773b6[_0xd2b5('0x62')]['id'];_0x1842b1[_0xd2b5('0x79')]['id']=_0x1773b6['body'][_0xd2b5('0x61')];return db[_0xd2b5('0x3b')]['find']({'where':{'id':_0x1773b6[_0xd2b5('0x56')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x4977b8,null))[_0xd2b5('0x23')](function(_0x2aa354){if(_0x2aa354){_0x1842b1['message']=_0x2aa354[_0xd2b5('0x63')]({'plain':!![]});return db[_0xd2b5('0x64')][_0xd2b5('0x57')]({'where':{'id':_0x2aa354[_0xd2b5('0x65')]}});}return null;})[_0xd2b5('0x23')](handleEntityNotFound(_0x4977b8,null))[_0xd2b5('0x23')](function(_0x59057a){if(_0x59057a){_0x1842b1['interaction']=_0x59057a[_0xd2b5('0x63')]({'plain':!![]});interaction_log[_0xd2b5('0x24')]('[FAXMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x1773b6[_0xd2b5('0x62')]['id'],_0x1773b6[_0xd2b5('0x62')][_0xd2b5('0x39')],_0x1773b6[_0xd2b5('0x62')][_0xd2b5('0x7a')],_0x1842b1[_0xd2b5('0x68')]['id'],_0x1773b6[_0xd2b5('0x58')]?JSON[_0xd2b5('0x29')](_0x1773b6[_0xd2b5('0x58')]):'null');return respondWithRpcPromise(_0xd2b5('0x7b'),_0xd2b5('0x7c'),_0x1842b1);}return null;})[_0xd2b5('0x23')](function(_0x4c9c1f){var _0x4fa477=_0xd2b5('0x7d')+_0x4c9c1f[_0xd2b5('0x2c')]['ContactId'];return db[_0xd2b5('0x6a')][_0xd2b5('0x41')](_0x4fa477,{'type':db[_0xd2b5('0x6b')][_0xd2b5('0x6c')][_0xd2b5('0x6d')],'raw':!![]})[_0xd2b5('0x23')](function(_0x392884){return _0x392884;});})[_0xd2b5('0x23')](function(_0x3fd2ad){if(_0x3fd2ad){_0x1842b1['message'][_0xd2b5('0x6e')]=_0x3fd2ad[0x0];if(!_0x1773b6[_0xd2b5('0x58')][_0xd2b5('0x61')])return;return db[_0xd2b5('0x6f')]['find']({'where':{'id':_0x1773b6[_0xd2b5('0x58')][_0xd2b5('0x61')],'role':_0xd2b5('0x79')},'attributes':['id',_0xd2b5('0x39'),_0xd2b5('0x70'),_0xd2b5('0x7e'),_0xd2b5('0x71')],'raw':!![]});}return null;})[_0xd2b5('0x23')](function(_0x174184){if(!_0x174184)return null;_0x1842b1['message'][_0xd2b5('0x79')]=_0x174184;return _0x1842b1;})[_0xd2b5('0x23')](function(_0x5d52e8){if(_0x5d52e8){_0x5d52e8[_0xd2b5('0x2c')][_0xd2b5('0x73')]=util[_0xd2b5('0x5f')](_0xd2b5('0x74'),_0x1773b6[_0xd2b5('0x62')]['name']);_0x5d52e8[_0xd2b5('0x2c')][_0xd2b5('0x75')]=_0x1842b1[_0xd2b5('0x75')];_0x5d52e8['message'][_0xd2b5('0x76')]=_0x1842b1[_0xd2b5('0x75')];_0x5d52e8[_0xd2b5('0x2c')]['event']=_0xd2b5('0x37');respondWithRpcPromise(_0xd2b5('0x7f'),'EventManager',{'event':_0xd2b5('0x80'),'message':_0x5d52e8['message']},client9002);return _0x1842b1;}return null;})['then'](respondWithResult(_0x4977b8,null))['catch'](handleError(_0x4977b8,null));};exports[_0xd2b5('0x81')]=function(_0x3b64ee,_0x176cff){var _0x54a46a;return db['FaxMessage'][_0xd2b5('0x81')](_0x3b64ee[_0xd2b5('0x58')],{})[_0xd2b5('0x23')](function(_0x4f5ede){_0x54a46a=_0x4f5ede;return db[_0xd2b5('0x82')][_0xd2b5('0x83')]({'where':{'id':_0x54a46a['ContactId']}});})[_0xd2b5('0x23')](function(_0x3e435c){if(_[_0xd2b5('0x66')](_0x3e435c)){return;}else{_0x54a46a[_0xd2b5('0x5d')]=_0x3e435c[_0xd2b5('0x5d')];return db['Attachment']['findOne']({'where':{'id':_0x54a46a[_0xd2b5('0x84')]}});}})[_0xd2b5('0x23')](function(_0x31e651){return respondWithRpcPromise(_0xd2b5('0x85'),_0xd2b5('0x85'),{'FaxAccountId':_[_0xd2b5('0x66')](_0x3b64ee[_0xd2b5('0x58')])?undefined:_0x3b64ee['body'][_0xd2b5('0x86')],'path':_[_0xd2b5('0x66')](_0x31e651)?undefined:util[_0xd2b5('0x5f')](_0xd2b5('0x87'),_0x31e651[_0xd2b5('0x88')]),'fax':_[_0xd2b5('0x66')](_0x54a46a[_0xd2b5('0x5d')])?undefined:_0x54a46a['fax'],'AttachmentId':_0x54a46a[_0xd2b5('0x84')]},client9002);})[_0xd2b5('0x23')](respondWithResult(_0x176cff,0xc9))[_0xd2b5('0x2e')](handleError(_0x176cff,null));};exports[_0xd2b5('0x89')]=function(_0x1e2156,_0x171900){var _0xa6229e=path['join'](config[_0xd2b5('0x8a')],_0xd2b5('0x8b'),'files',_0xd2b5('0x8c'));return db[_0xd2b5('0x3b')][_0xd2b5('0x57')]({'where':{'id':_0x1e2156[_0xd2b5('0x56')]['id']},'include':[{'model':db[_0xd2b5('0x8d')],'as':'Attachment'}]})[_0xd2b5('0x23')](handleEntityNotFound(_0x171900,null))[_0xd2b5('0x23')](function(_0x15c3ee){if(_0x15c3ee){return _0x171900[_0xd2b5('0x89')](path['join'](_0xa6229e,_0x15c3ee[_0xd2b5('0x8d')][_0xd2b5('0x88')]));}})['catch'](handleError(_0x171900,null));};