Built motion from commit (unavailable).|2.5.22
[motion2.git] / server / api / faxMessage / faxMessage.controller.js
index a77fedc..67e3dff 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xa376=['findOne','SendFax','isNil','FaxAccountId','/var/opt/motion2/server/files/attachments/%s','basename','AttachmentId','join','root','attachments','download','rimraf','fast-json-patch','request-promise','mustache','util','path','sox','to-csv','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/parsers/advancedSearch','../../config/environment','../../mysqldb','redis','defaults','localhost','register','client','http','request','then','info','debug','FaxMessage,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','FaxMessage,\x20%s,\x20%s','message','result','catch','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','save','destroy','stack','name','send','index','map','FaxMessage','fieldName','type','key','model','query','filters','intersection','attributes','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','VIRTUAL','options','includeAll','include','findAll','show','params','fields','find','update','body','describe','../../config/logger','fax-interactions','accept','fax','readAt','YYYY-MM-DD\x20HH:mm:ss','UserId','user','CmContact','Contact','get','FaxInteraction','format','interaction','null','acceptMessage','manual','SIP/%s','channel','event','EventManager','acceptmessage','reject','FaxInteractionId','[FAXMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','RejectMessage','interface','create','ContactId','Attachment'];(function(_0x24681d,_0x1a3710){var _0x417eac=function(_0x597477){while(--_0x597477){_0x24681d['push'](_0x24681d['shift']());}};_0x417eac(++_0x1a3710);}(_0xa376,0x88));var _0x6a37=function(_0x315e9c,_0x58e17a){_0x315e9c=_0x315e9c-0x0;var _0x16b2e4=_0xa376[_0x315e9c];return _0x16b2e4;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0x6a37('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x6a37('0x1'));var rp=require(_0x6a37('0x2'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x6a37('0x3'));var util=require(_0x6a37('0x4'));var path=require(_0x6a37('0x5'));var sox=require(_0x6a37('0x6'));var csv=require(_0x6a37('0x7'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x6a37('0x8'));var squel=require(_0x6a37('0x9'));var crypto=require(_0x6a37('0xa'));var jsforce=require(_0x6a37('0xb'));var deskjs=require(_0x6a37('0xc'));var toCsv=require(_0x6a37('0x7'));var querystring=require(_0x6a37('0xd'));var Papa=require('papaparse');var Redis=require(_0x6a37('0xe'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x6a37('0xf'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require(_0x6a37('0x10'));var licenseUtil=require('../../config/license/util');var db=require(_0x6a37('0x11'))['db'];config[_0x6a37('0x12')]=_[_0x6a37('0x13')](config[_0x6a37('0x12')],{'host':_0x6a37('0x14'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x6a37('0x12')]));require('./faxMessage.socket')[_0x6a37('0x15')](socket);var jayson=require('jayson/promise');var client=jayson[_0x6a37('0x16')]['http']({'port':0x232c});var client9002=jayson[_0x6a37('0x16')][_0x6a37('0x17')]({'port':0x232a});function respondWithRpcPromise(_0x5340b1,_0x952417,_0x121f19,_0x14b25b){return new BPromise(function(_0x2f8e0a,_0xba1c2f){var _0x38181a=_0x14b25b||client;return _0x38181a[_0x6a37('0x18')](_0x5340b1,_0x121f19)[_0x6a37('0x19')](function(_0x3ecd35){logger[_0x6a37('0x1a')]('FaxMessage,\x20%s,\x20%s',_0x952417,'request\x20sent');logger[_0x6a37('0x1b')](_0x6a37('0x1c'),_0x952417,_0x6a37('0x1d'),JSON[_0x6a37('0x1e')](_0x3ecd35));if(_0x3ecd35['error']){if(_0x3ecd35[_0x6a37('0x1f')]['code']===0x1f4){logger['error'](_0x6a37('0x20'),_0x952417,_0x3ecd35[_0x6a37('0x1f')][_0x6a37('0x21')]);return _0xba1c2f(_0x3ecd35[_0x6a37('0x1f')][_0x6a37('0x21')]);}logger[_0x6a37('0x1f')](_0x6a37('0x20'),_0x952417,_0x3ecd35['error'][_0x6a37('0x21')]);return _0x2f8e0a(_0x3ecd35[_0x6a37('0x1f')][_0x6a37('0x21')]);}else{logger[_0x6a37('0x1a')](_0x6a37('0x20'),_0x952417,_0x6a37('0x1d'));_0x2f8e0a(_0x3ecd35[_0x6a37('0x22')]['message']);}})[_0x6a37('0x23')](function(_0xf8d82d){logger[_0x6a37('0x1f')](_0x6a37('0x20'),_0x952417,_0xf8d82d);_0xba1c2f(_0xf8d82d);});});}function respondWithStatusCode(_0x46113c,_0x5fc322){_0x5fc322=_0x5fc322||0xcc;return function(_0x33347f){if(_0x33347f){return _0x46113c[_0x6a37('0x24')](_0x5fc322);}return _0x46113c[_0x6a37('0x25')](_0x5fc322)[_0x6a37('0x26')]();};}function respondWithResult(_0x15e6a2,_0x1a45dd){_0x1a45dd=_0x1a45dd||0xc8;return function(_0x46e8db){if(_0x46e8db){return _0x15e6a2[_0x6a37('0x25')](_0x1a45dd)[_0x6a37('0x27')](_0x46e8db);}};}function respondWithFilteredResult(_0x18f076,_0x2398d9){return function(_0x1bf83b){if(_0x1bf83b){var _0x2573e5=_0x1bf83b[_0x6a37('0x28')],_0x5cfa53=_0x2398d9[_0x6a37('0x29')],_0x5be572=_0x2398d9[_0x6a37('0x29')]+_0x2398d9[_0x6a37('0x2a')],_0xe24890;if(_0x5be572>=_0x2573e5){_0x5be572=_0x2573e5;_0xe24890=0xc8;}else{_0xe24890=0xce;}_0x18f076[_0x6a37('0x25')](_0xe24890);return _0x18f076[_0x6a37('0x2b')](_0x6a37('0x2c'),_0x5cfa53+'-'+_0x5be572+'/'+_0x2573e5)[_0x6a37('0x27')](_0x1bf83b);}return null;};}function patchUpdates(_0x390f4c){return function(_0x5484c1){try{jsonpatch[_0x6a37('0x2d')](_0x5484c1,_0x390f4c,!![]);}catch(_0x53ea3c){return BPromise['reject'](_0x53ea3c);}return _0x5484c1[_0x6a37('0x2e')]();};}function saveUpdates(_0x427762,_0x36c4a7){return function(_0x3d225a){if(_0x3d225a){return _0x3d225a['update'](_0x427762)[_0x6a37('0x19')](function(_0x2465d5){return _0x2465d5;});}return null;};}function removeEntity(_0x278f60,_0x511caa){return function(_0x327b41){if(_0x327b41){return _0x327b41[_0x6a37('0x2f')]()[_0x6a37('0x19')](function(){_0x278f60[_0x6a37('0x25')](0xcc)[_0x6a37('0x26')]();});}};}function handleEntityNotFound(_0x1ccb52,_0x33f35d){return function(_0x2fa044){if(!_0x2fa044){_0x1ccb52['sendStatus'](0x194);}return _0x2fa044;};}function handleError(_0x2e2677,_0x1261a7){_0x1261a7=_0x1261a7||0x1f4;return function(_0x227ca0){logger['error'](_0x227ca0[_0x6a37('0x30')]);if(_0x227ca0['name']){delete _0x227ca0[_0x6a37('0x31')];}_0x2e2677[_0x6a37('0x25')](_0x1261a7)[_0x6a37('0x32')](_0x227ca0);};}exports[_0x6a37('0x33')]=function(_0x503135,_0x4cb118){var _0x391713={},_0x4d4f63={},_0x30bb83={'count':0x0,'rows':[]};var _0x546635=_[_0x6a37('0x34')](db[_0x6a37('0x35')]['rawAttributes'],function(_0x470156){return{'name':_0x470156[_0x6a37('0x36')],'type':_0x470156[_0x6a37('0x37')][_0x6a37('0x38')]};});_0x4d4f63[_0x6a37('0x39')]=_[_0x6a37('0x34')](_0x546635,_0x6a37('0x31'));_0x4d4f63['query']=_['keys'](_0x503135[_0x6a37('0x3a')]);_0x4d4f63[_0x6a37('0x3b')]=_[_0x6a37('0x3c')](_0x4d4f63['model'],_0x4d4f63[_0x6a37('0x3a')]);_0x391713['attributes']=_['intersection'](_0x4d4f63['model'],qs['fields'](_0x503135[_0x6a37('0x3a')]['fields']));_0x391713['attributes']=_0x391713[_0x6a37('0x3d')][_0x6a37('0x3e')]?_0x391713[_0x6a37('0x3d')]:_0x4d4f63[_0x6a37('0x39')];if(!_0x503135[_0x6a37('0x3a')][_0x6a37('0x3f')](_0x6a37('0x40'))){_0x391713[_0x6a37('0x2a')]=qs['limit'](_0x503135['query'][_0x6a37('0x2a')]);_0x391713['offset']=qs[_0x6a37('0x29')](_0x503135[_0x6a37('0x3a')][_0x6a37('0x29')]);}_0x391713[_0x6a37('0x41')]=qs[_0x6a37('0x42')](_0x503135['query'][_0x6a37('0x42')]);_0x391713['where']=qs[_0x6a37('0x3b')](_[_0x6a37('0x43')](_0x503135['query'],_0x4d4f63[_0x6a37('0x3b')]),_0x546635);if(_0x503135['query'][_0x6a37('0x44')]){_0x391713[_0x6a37('0x45')]=_[_0x6a37('0x46')](_0x391713[_0x6a37('0x45')],{'$or':_[_0x6a37('0x34')](_0x546635,function(_0x1b927b){if(_0x1b927b[_0x6a37('0x37')]!==_0x6a37('0x47')){var _0x5763cd={};_0x5763cd[_0x1b927b[_0x6a37('0x31')]]={'$like':'%'+_0x503135[_0x6a37('0x3a')][_0x6a37('0x44')]+'%'};return _0x5763cd;}})});}_0x391713=_[_0x6a37('0x46')]({},_0x391713,_0x503135[_0x6a37('0x48')]);var _0x19d522={'where':_0x391713[_0x6a37('0x45')]};return db[_0x6a37('0x35')][_0x6a37('0x28')](_0x19d522)['then'](function(_0x994d8e){_0x30bb83['count']=_0x994d8e;if(_0x503135[_0x6a37('0x3a')][_0x6a37('0x49')]){_0x391713[_0x6a37('0x4a')]=[{'all':!![]}];}return db[_0x6a37('0x35')][_0x6a37('0x4b')](_0x391713);})[_0x6a37('0x19')](function(_0x185155){_0x30bb83['rows']=_0x185155;return _0x30bb83;})[_0x6a37('0x19')](respondWithFilteredResult(_0x4cb118,_0x391713))[_0x6a37('0x23')](handleError(_0x4cb118,null));};exports[_0x6a37('0x4c')]=function(_0x321545,_0x58c63c){var _0x32f0c0={'raw':!![],'where':{'id':_0x321545[_0x6a37('0x4d')]['id']}},_0x4550fa={};_0x4550fa[_0x6a37('0x39')]=_['keys'](db['FaxMessage']['rawAttributes']);_0x4550fa[_0x6a37('0x3a')]=_['keys'](_0x321545[_0x6a37('0x3a')]);_0x4550fa[_0x6a37('0x3b')]=_[_0x6a37('0x3c')](_0x4550fa[_0x6a37('0x39')],_0x4550fa['query']);_0x32f0c0[_0x6a37('0x3d')]=_[_0x6a37('0x3c')](_0x4550fa[_0x6a37('0x39')],qs[_0x6a37('0x4e')](_0x321545[_0x6a37('0x3a')]['fields']));_0x32f0c0[_0x6a37('0x3d')]=_0x32f0c0[_0x6a37('0x3d')]['length']?_0x32f0c0[_0x6a37('0x3d')]:_0x4550fa[_0x6a37('0x39')];if(_0x321545[_0x6a37('0x3a')][_0x6a37('0x49')]){_0x32f0c0['include']=[{'all':!![]}];}_0x32f0c0=_[_0x6a37('0x46')]({},_0x32f0c0,_0x321545['options']);return db[_0x6a37('0x35')][_0x6a37('0x4f')](_0x32f0c0)[_0x6a37('0x19')](handleEntityNotFound(_0x58c63c,null))['then'](respondWithResult(_0x58c63c,null))[_0x6a37('0x23')](handleError(_0x58c63c,null));};exports[_0x6a37('0x50')]=function(_0x5c29be,_0x38849f){if(_0x5c29be[_0x6a37('0x51')]['id']){delete _0x5c29be[_0x6a37('0x51')]['id'];}return db[_0x6a37('0x35')][_0x6a37('0x4f')]({'where':{'id':_0x5c29be['params']['id']}})[_0x6a37('0x19')](handleEntityNotFound(_0x38849f,null))[_0x6a37('0x19')](saveUpdates(_0x5c29be[_0x6a37('0x51')],null))[_0x6a37('0x19')](respondWithResult(_0x38849f,null))[_0x6a37('0x23')](handleError(_0x38849f,null));};exports[_0x6a37('0x2f')]=function(_0x5c88d1,_0x57706d){return db['FaxMessage']['find']({'where':{'id':_0x5c88d1[_0x6a37('0x4d')]['id']}})[_0x6a37('0x19')](handleEntityNotFound(_0x57706d,null))[_0x6a37('0x19')](removeEntity(_0x57706d,null))[_0x6a37('0x23')](handleError(_0x57706d,null));};exports[_0x6a37('0x52')]=function(_0xc5080,_0x7286ba){return db[_0x6a37('0x35')][_0x6a37('0x52')]()[_0x6a37('0x19')](respondWithResult(_0x7286ba,null))[_0x6a37('0x23')](handleError(_0x7286ba,null));};var interaction_log=require(_0x6a37('0x53'))(_0x6a37('0x54'));exports[_0x6a37('0x55')]=function(_0x246a2e,_0x5a7a2b,_0x784f9b){var _0x264557={'channel':_0x6a37('0x56')};if(_0x246a2e[_0x6a37('0x51')]['id']){delete _0x246a2e[_0x6a37('0x51')]['id'];}_0x246a2e[_0x6a37('0x51')]['read']=!![];_0x246a2e[_0x6a37('0x51')][_0x6a37('0x57')]=moment()['format'](_0x6a37('0x58'));_0x246a2e[_0x6a37('0x51')][_0x6a37('0x59')]=_0x246a2e[_0x6a37('0x51')]['UserId']||_0x246a2e[_0x6a37('0x5a')]['id'];return db[_0x6a37('0x35')][_0x6a37('0x4f')]({'where':{'id':_0x246a2e[_0x6a37('0x4d')]['id'],'UserId':null},'include':[{'model':db[_0x6a37('0x5b')],'as':_0x6a37('0x5c')}]})[_0x6a37('0x19')](handleEntityNotFound(_0x5a7a2b,null))[_0x6a37('0x19')](saveUpdates(_0x246a2e[_0x6a37('0x51')],null))['then'](function(_0x499c71){if(_0x499c71){_0x264557[_0x6a37('0x21')]=_0x499c71[_0x6a37('0x5d')]({'plain':!![]});return db[_0x6a37('0x5e')][_0x6a37('0x4f')]({'where':{'id':_0x499c71['FaxInteractionId']}});}return null;})['then'](handleEntityNotFound(_0x5a7a2b,null))[_0x6a37('0x19')](function(_0x2906a4){if(_0x2906a4){return _0x2906a4[_0x6a37('0x50')]({'UserId':_0x246a2e['body']['UserId'],'read1stAt':_['isNil'](_0x2906a4['read1stAt'])?moment()[_0x6a37('0x5f')](_0x6a37('0x58')):undefined});}return null;})['then'](function(_0x175aa4){if(_0x175aa4){_0x264557[_0x6a37('0x60')]=_0x175aa4['get']({'plain':!![]});interaction_log[_0x6a37('0x1a')]('[FAXMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x246a2e[_0x6a37('0x5a')]['id'],_0x246a2e[_0x6a37('0x5a')]['name'],_0x246a2e['user']['role'],_0x264557[_0x6a37('0x60')]['id'],_0x246a2e['body']?JSON[_0x6a37('0x1e')](_0x246a2e[_0x6a37('0x51')]):_0x6a37('0x61'));return respondWithRpcPromise('AcceptMessage',_0x6a37('0x62'),_0x264557);}return null;})['then'](function(_0x50606b){if(_0x50606b){if(_0x246a2e[_0x6a37('0x51')][_0x6a37('0x63')]){_0x264557['message']['interface']=util[_0x6a37('0x5f')](_0x6a37('0x64'),_0x246a2e[_0x6a37('0x5a')]['name']);_0x264557[_0x6a37('0x21')]['channel']=_0x264557[_0x6a37('0x65')];_0x264557[_0x6a37('0x21')][_0x6a37('0x66')]=_0x6a37('0x55');return respondWithRpcPromise(_0x6a37('0x67'),_0x6a37('0x67'),{'event':_0x6a37('0x68'),'message':_0x264557[_0x6a37('0x21')]},client9002)[_0x6a37('0x19')](function(){return _0x264557;});}return _0x264557;}return null;})['then'](respondWithResult(_0x5a7a2b,null))[_0x6a37('0x23')](handleError(_0x5a7a2b,null));};var interaction_log=require(_0x6a37('0x53'))('fax-interactions');exports[_0x6a37('0x69')]=function(_0x475217,_0x252438,_0x4fc2d2){var _0x417207={'agent':{},'channel':'fax'};if(_0x475217[_0x6a37('0x51')]['id']){delete _0x475217['body']['id'];}_0x475217['body']['UserId']=_0x475217[_0x6a37('0x51')][_0x6a37('0x59')]||_0x475217[_0x6a37('0x5a')]['id'];_0x417207['agent']['id']=_0x475217['body'][_0x6a37('0x59')];return db[_0x6a37('0x35')]['find']({'where':{'id':_0x475217[_0x6a37('0x4d')]['id'],'UserId':null}})[_0x6a37('0x19')](handleEntityNotFound(_0x252438,null))[_0x6a37('0x19')](function(_0x55f523){if(_0x55f523){_0x417207['message']=_0x55f523['get']({'plain':!![]});return db[_0x6a37('0x5e')]['find']({'where':{'id':_0x55f523[_0x6a37('0x6a')]}});}return null;})[_0x6a37('0x19')](handleEntityNotFound(_0x252438,null))[_0x6a37('0x19')](function(_0x320447){if(_0x320447){_0x417207[_0x6a37('0x60')]=_0x320447[_0x6a37('0x5d')]({'plain':!![]});interaction_log[_0x6a37('0x1a')](_0x6a37('0x6b'),_0x475217[_0x6a37('0x5a')]['id'],_0x475217[_0x6a37('0x5a')][_0x6a37('0x31')],_0x475217[_0x6a37('0x5a')][_0x6a37('0x6c')],_0x417207[_0x6a37('0x60')]['id'],_0x475217[_0x6a37('0x51')]?JSON['stringify'](_0x475217[_0x6a37('0x51')]):_0x6a37('0x61'));return respondWithRpcPromise(_0x6a37('0x6d'),'rejectMessage',_0x417207);}return null;})[_0x6a37('0x19')](function(_0x54ac1a){if(_0x54ac1a){_0x54ac1a[_0x6a37('0x21')][_0x6a37('0x6e')]=util[_0x6a37('0x5f')](_0x6a37('0x64'),_0x475217[_0x6a37('0x5a')][_0x6a37('0x31')]);_0x54ac1a[_0x6a37('0x21')][_0x6a37('0x65')]=_0x417207['channel'];_0x54ac1a['message']['event']=_0x6a37('0x69');respondWithRpcPromise(_0x6a37('0x67'),_0x6a37('0x67'),{'event':'rejectmessage','message':_0x54ac1a['message']},client9002);return _0x417207;}return null;})[_0x6a37('0x19')](respondWithResult(_0x252438,null))[_0x6a37('0x23')](handleError(_0x252438,null));};exports[_0x6a37('0x6f')]=function(_0x1e93d6,_0xd80f9c){var _0x28a8b5;return db['FaxMessage'][_0x6a37('0x6f')](_0x1e93d6[_0x6a37('0x51')],{})[_0x6a37('0x19')](function(_0x3734fd){_0x28a8b5=_0x3734fd;return db[_0x6a37('0x5b')]['findOne']({'where':{'id':_0x28a8b5[_0x6a37('0x70')]}});})[_0x6a37('0x19')](function(_0x5f2baf){if(_['isNil'](_0x5f2baf)){return;}else{_0x28a8b5['fax']=_0x5f2baf[_0x6a37('0x56')];return db[_0x6a37('0x71')][_0x6a37('0x72')]({'where':{'id':_0x28a8b5['AttachmentId']}});}})[_0x6a37('0x19')](function(_0x35eb52){return respondWithRpcPromise(_0x6a37('0x73'),_0x6a37('0x73'),{'FaxAccountId':_[_0x6a37('0x74')](_0x1e93d6[_0x6a37('0x51')])?undefined:_0x1e93d6[_0x6a37('0x51')][_0x6a37('0x75')],'path':_[_0x6a37('0x74')](_0x35eb52)?undefined:util[_0x6a37('0x5f')](_0x6a37('0x76'),_0x35eb52[_0x6a37('0x77')]),'fax':_[_0x6a37('0x74')](_0x28a8b5['fax'])?undefined:_0x28a8b5[_0x6a37('0x56')],'AttachmentId':_0x28a8b5[_0x6a37('0x78')]},client9002);})[_0x6a37('0x19')](respondWithResult(_0xd80f9c,0xc9))['catch'](handleError(_0xd80f9c,null));};exports['download']=function(_0x58a849,_0x3f435d){var _0x33a511=path[_0x6a37('0x79')](config[_0x6a37('0x7a')],'server','files',_0x6a37('0x7b'));return db[_0x6a37('0x35')][_0x6a37('0x4f')]({'where':{'id':_0x58a849[_0x6a37('0x4d')]['id']},'include':[{'model':db[_0x6a37('0x71')],'as':_0x6a37('0x71')}]})[_0x6a37('0x19')](handleEntityNotFound(_0x3f435d,null))[_0x6a37('0x19')](function(_0x4f031f){if(_0x4f031f){return _0x3f435d[_0x6a37('0x7c')](path[_0x6a37('0x79')](_0x33a511,_0x4f031f[_0x6a37('0x71')][_0x6a37('0x77')]));}})[_0x6a37('0x23')](handleError(_0x3f435d,null));};
\ No newline at end of file
+var _0xe5b5=['FaxInteractionId','read1stAt','interaction','get','[FAXMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','stringify','null','AcceptMessage','acceptMessage','manual','interface','channel','EventManager','agent','FaxInteraction','[FAXMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','SIP/%s','event','rejectmessage','create','findOne','isNil','fax','AttachmentId','SendFax','FaxAccountId','basename','download','join','Attachment','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','redis','defaults','localhost','socket.io-emitter','./faxMessage.socket','jayson/promise','client','request','then','info','FaxMessage,\x20%s,\x20%s','request\x20sent','FaxMessage,\x20%s,\x20%s,\x20%s','error','code','message','result','catch','sendStatus','end','status','json','offset','limit','set','apply','reject','update','destroy','stack','name','send','index','map','FaxMessage','rawAttributes','fieldName','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','type','VIRTUAL','merge','count','includeAll','include','findAll','rows','show','params','find','body','describe','fax-interactions','accept','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','CmContact','Contact'];(function(_0xb65f4e,_0xab08a0){var _0x4c013d=function(_0x94cf6a){while(--_0x94cf6a){_0xb65f4e['push'](_0xb65f4e['shift']());}};_0x4c013d(++_0xab08a0);}(_0xe5b5,0x12b));var _0x5e5b=function(_0x233cb1,_0x8ca9a2){_0x233cb1=_0x233cb1-0x0;var _0x29ee7e=_0xe5b5[_0x233cb1];return _0x29ee7e;};'use strict';var pdf=require(_0x5e5b('0x0'));var emlformat=require(_0x5e5b('0x1'));var rimraf=require(_0x5e5b('0x2'));var zipdir=require(_0x5e5b('0x3'));var jsonpatch=require(_0x5e5b('0x4'));var rp=require(_0x5e5b('0x5'));var moment=require(_0x5e5b('0x6'));var BPromise=require(_0x5e5b('0x7'));var Mustache=require(_0x5e5b('0x8'));var util=require(_0x5e5b('0x9'));var path=require(_0x5e5b('0xa'));var sox=require(_0x5e5b('0xb'));var csv=require(_0x5e5b('0xc'));var ejs=require(_0x5e5b('0xd'));var fs=require('fs');var _=require(_0x5e5b('0xe'));var squel=require(_0x5e5b('0xf'));var crypto=require(_0x5e5b('0x10'));var jsforce=require(_0x5e5b('0x11'));var deskjs=require(_0x5e5b('0x12'));var toCsv=require(_0x5e5b('0xc'));var querystring=require(_0x5e5b('0x13'));var Papa=require(_0x5e5b('0x14'));var Redis=require(_0x5e5b('0x15'));var authService=require('../../components/auth/service');var qs=require(_0x5e5b('0x16'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x5e5b('0x17'));var logger=require(_0x5e5b('0x18'))(_0x5e5b('0x19'));var utils=require(_0x5e5b('0x1a'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];config[_0x5e5b('0x1b')]=_[_0x5e5b('0x1c')](config[_0x5e5b('0x1b')],{'host':_0x5e5b('0x1d'),'port':0x18eb});var socket=require(_0x5e5b('0x1e'))(new Redis(config[_0x5e5b('0x1b')]));require(_0x5e5b('0x1f'))['register'](socket);var jayson=require(_0x5e5b('0x20'));var client=jayson[_0x5e5b('0x21')]['http']({'port':0x232c});var client9002=jayson[_0x5e5b('0x21')]['http']({'port':0x232a});function respondWithRpcPromise(_0x4e9509,_0x13a1cb,_0x444435,_0xaf9ace){return new BPromise(function(_0x5c7148,_0x38fdcc){var _0x4d490c=_0xaf9ace||client;return _0x4d490c[_0x5e5b('0x22')](_0x4e9509,_0x444435)[_0x5e5b('0x23')](function(_0x4c5f9a){logger[_0x5e5b('0x24')](_0x5e5b('0x25'),_0x13a1cb,_0x5e5b('0x26'));logger['debug'](_0x5e5b('0x27'),_0x13a1cb,_0x5e5b('0x26'),JSON['stringify'](_0x4c5f9a));if(_0x4c5f9a[_0x5e5b('0x28')]){if(_0x4c5f9a[_0x5e5b('0x28')][_0x5e5b('0x29')]===0x1f4){logger[_0x5e5b('0x28')](_0x5e5b('0x25'),_0x13a1cb,_0x4c5f9a[_0x5e5b('0x28')][_0x5e5b('0x2a')]);return _0x38fdcc(_0x4c5f9a[_0x5e5b('0x28')]['message']);}logger['error'](_0x5e5b('0x25'),_0x13a1cb,_0x4c5f9a[_0x5e5b('0x28')][_0x5e5b('0x2a')]);return _0x5c7148(_0x4c5f9a[_0x5e5b('0x28')][_0x5e5b('0x2a')]);}else{logger[_0x5e5b('0x24')](_0x5e5b('0x25'),_0x13a1cb,_0x5e5b('0x26'));_0x5c7148(_0x4c5f9a[_0x5e5b('0x2b')][_0x5e5b('0x2a')]);}})[_0x5e5b('0x2c')](function(_0x4da321){logger[_0x5e5b('0x28')](_0x5e5b('0x25'),_0x13a1cb,_0x4da321);_0x38fdcc(_0x4da321);});});}function respondWithStatusCode(_0x3527a8,_0x5a2ba8){_0x5a2ba8=_0x5a2ba8||0xcc;return function(_0x988e5d){if(_0x988e5d){return _0x3527a8[_0x5e5b('0x2d')](_0x5a2ba8);}return _0x3527a8['status'](_0x5a2ba8)[_0x5e5b('0x2e')]();};}function respondWithResult(_0x21c74b,_0x39ce16){_0x39ce16=_0x39ce16||0xc8;return function(_0x36b595){if(_0x36b595){return _0x21c74b[_0x5e5b('0x2f')](_0x39ce16)[_0x5e5b('0x30')](_0x36b595);}};}function respondWithFilteredResult(_0x2cb695,_0x2b4351){return function(_0x3f6b25){if(_0x3f6b25){var _0x42da3b=_0x3f6b25['count'],_0xcb272c=_0x2b4351[_0x5e5b('0x31')],_0x28157a=_0x2b4351[_0x5e5b('0x31')]+_0x2b4351[_0x5e5b('0x32')],_0x4ed688;if(_0x28157a>=_0x42da3b){_0x28157a=_0x42da3b;_0x4ed688=0xc8;}else{_0x4ed688=0xce;}_0x2cb695[_0x5e5b('0x2f')](_0x4ed688);return _0x2cb695[_0x5e5b('0x33')]('Content-Range',_0xcb272c+'-'+_0x28157a+'/'+_0x42da3b)[_0x5e5b('0x30')](_0x3f6b25);}return null;};}function patchUpdates(_0x56f5a9){return function(_0x3f1041){try{jsonpatch[_0x5e5b('0x34')](_0x3f1041,_0x56f5a9,!![]);}catch(_0x11fa95){return BPromise[_0x5e5b('0x35')](_0x11fa95);}return _0x3f1041['save']();};}function saveUpdates(_0x22e906,_0x1bc636){return function(_0x524f74){if(_0x524f74){return _0x524f74[_0x5e5b('0x36')](_0x22e906)[_0x5e5b('0x23')](function(_0x34debb){return _0x34debb;});}return null;};}function removeEntity(_0x356db0,_0x14845d){return function(_0x2296dd){if(_0x2296dd){return _0x2296dd[_0x5e5b('0x37')]()[_0x5e5b('0x23')](function(){_0x356db0['status'](0xcc)[_0x5e5b('0x2e')]();});}};}function handleEntityNotFound(_0x37b5be,_0x1aef4a){return function(_0x34396f){if(!_0x34396f){_0x37b5be[_0x5e5b('0x2d')](0x194);}return _0x34396f;};}function handleError(_0x46cafc,_0x4fec9e){_0x4fec9e=_0x4fec9e||0x1f4;return function(_0x5b2ba5){logger[_0x5e5b('0x28')](_0x5b2ba5[_0x5e5b('0x38')]);if(_0x5b2ba5[_0x5e5b('0x39')]){delete _0x5b2ba5['name'];}_0x46cafc[_0x5e5b('0x2f')](_0x4fec9e)[_0x5e5b('0x3a')](_0x5b2ba5);};}exports[_0x5e5b('0x3b')]=function(_0x470b45,_0x54320f){var _0x5b3e0d={},_0x44c6d2={},_0x4f5b67={'count':0x0,'rows':[]};var _0x5ad9a6=_[_0x5e5b('0x3c')](db[_0x5e5b('0x3d')][_0x5e5b('0x3e')],function(_0x550faf){return{'name':_0x550faf[_0x5e5b('0x3f')],'type':_0x550faf['type']['key']};});_0x44c6d2[_0x5e5b('0x40')]=_[_0x5e5b('0x3c')](_0x5ad9a6,_0x5e5b('0x39'));_0x44c6d2[_0x5e5b('0x41')]=_[_0x5e5b('0x42')](_0x470b45[_0x5e5b('0x41')]);_0x44c6d2[_0x5e5b('0x43')]=_[_0x5e5b('0x44')](_0x44c6d2[_0x5e5b('0x40')],_0x44c6d2['query']);_0x5b3e0d[_0x5e5b('0x45')]=_[_0x5e5b('0x44')](_0x44c6d2['model'],qs[_0x5e5b('0x46')](_0x470b45['query'][_0x5e5b('0x46')]));_0x5b3e0d[_0x5e5b('0x45')]=_0x5b3e0d[_0x5e5b('0x45')][_0x5e5b('0x47')]?_0x5b3e0d[_0x5e5b('0x45')]:_0x44c6d2[_0x5e5b('0x40')];if(!_0x470b45[_0x5e5b('0x41')][_0x5e5b('0x48')](_0x5e5b('0x49'))){_0x5b3e0d[_0x5e5b('0x32')]=qs[_0x5e5b('0x32')](_0x470b45['query'][_0x5e5b('0x32')]);_0x5b3e0d[_0x5e5b('0x31')]=qs[_0x5e5b('0x31')](_0x470b45['query'][_0x5e5b('0x31')]);}_0x5b3e0d[_0x5e5b('0x4a')]=qs['sort'](_0x470b45[_0x5e5b('0x41')][_0x5e5b('0x4b')]);_0x5b3e0d['where']=qs[_0x5e5b('0x43')](_['pick'](_0x470b45['query'],_0x44c6d2['filters']),_0x5ad9a6);if(_0x470b45[_0x5e5b('0x41')]['filter']){_0x5b3e0d[_0x5e5b('0x4c')]=_['merge'](_0x5b3e0d[_0x5e5b('0x4c')],{'$or':_[_0x5e5b('0x3c')](_0x5ad9a6,function(_0x2bc089){if(_0x2bc089[_0x5e5b('0x4d')]!==_0x5e5b('0x4e')){var _0x425531={};_0x425531[_0x2bc089[_0x5e5b('0x39')]]={'$like':'%'+_0x470b45['query']['filter']+'%'};return _0x425531;}})});}_0x5b3e0d=_[_0x5e5b('0x4f')]({},_0x5b3e0d,_0x470b45['options']);var _0x54729b={'where':_0x5b3e0d['where']};return db[_0x5e5b('0x3d')]['count'](_0x54729b)[_0x5e5b('0x23')](function(_0x414dbd){_0x4f5b67[_0x5e5b('0x50')]=_0x414dbd;if(_0x470b45[_0x5e5b('0x41')][_0x5e5b('0x51')]){_0x5b3e0d[_0x5e5b('0x52')]=[{'all':!![]}];}return db['FaxMessage'][_0x5e5b('0x53')](_0x5b3e0d);})[_0x5e5b('0x23')](function(_0x4f110f){_0x4f5b67[_0x5e5b('0x54')]=_0x4f110f;return _0x4f5b67;})['then'](respondWithFilteredResult(_0x54320f,_0x5b3e0d))[_0x5e5b('0x2c')](handleError(_0x54320f,null));};exports[_0x5e5b('0x55')]=function(_0x42ebaf,_0x30de85){var _0x4b2ef6={'raw':!![],'where':{'id':_0x42ebaf[_0x5e5b('0x56')]['id']}},_0x1ae9e4={};_0x1ae9e4['model']=_[_0x5e5b('0x42')](db[_0x5e5b('0x3d')][_0x5e5b('0x3e')]);_0x1ae9e4[_0x5e5b('0x41')]=_[_0x5e5b('0x42')](_0x42ebaf[_0x5e5b('0x41')]);_0x1ae9e4['filters']=_[_0x5e5b('0x44')](_0x1ae9e4[_0x5e5b('0x40')],_0x1ae9e4['query']);_0x4b2ef6[_0x5e5b('0x45')]=_[_0x5e5b('0x44')](_0x1ae9e4[_0x5e5b('0x40')],qs['fields'](_0x42ebaf[_0x5e5b('0x41')][_0x5e5b('0x46')]));_0x4b2ef6[_0x5e5b('0x45')]=_0x4b2ef6['attributes'][_0x5e5b('0x47')]?_0x4b2ef6[_0x5e5b('0x45')]:_0x1ae9e4[_0x5e5b('0x40')];if(_0x42ebaf['query']['includeAll']){_0x4b2ef6[_0x5e5b('0x52')]=[{'all':!![]}];}_0x4b2ef6=_['merge']({},_0x4b2ef6,_0x42ebaf['options']);return db[_0x5e5b('0x3d')][_0x5e5b('0x57')](_0x4b2ef6)[_0x5e5b('0x23')](handleEntityNotFound(_0x30de85,null))['then'](respondWithResult(_0x30de85,null))[_0x5e5b('0x2c')](handleError(_0x30de85,null));};exports[_0x5e5b('0x36')]=function(_0x148032,_0x3c518a){if(_0x148032[_0x5e5b('0x58')]['id']){delete _0x148032[_0x5e5b('0x58')]['id'];}return db['FaxMessage']['find']({'where':{'id':_0x148032[_0x5e5b('0x56')]['id']}})[_0x5e5b('0x23')](handleEntityNotFound(_0x3c518a,null))[_0x5e5b('0x23')](saveUpdates(_0x148032[_0x5e5b('0x58')],null))['then'](respondWithResult(_0x3c518a,null))[_0x5e5b('0x2c')](handleError(_0x3c518a,null));};exports['destroy']=function(_0x325f87,_0x2fdeb5){return db[_0x5e5b('0x3d')][_0x5e5b('0x57')]({'where':{'id':_0x325f87[_0x5e5b('0x56')]['id']}})[_0x5e5b('0x23')](handleEntityNotFound(_0x2fdeb5,null))[_0x5e5b('0x23')](removeEntity(_0x2fdeb5,null))[_0x5e5b('0x2c')](handleError(_0x2fdeb5,null));};exports['describe']=function(_0x3963eb,_0x21b1d5){return db[_0x5e5b('0x3d')][_0x5e5b('0x59')]()[_0x5e5b('0x23')](respondWithResult(_0x21b1d5,null))['catch'](handleError(_0x21b1d5,null));};var interaction_log=require(_0x5e5b('0x18'))(_0x5e5b('0x5a'));exports[_0x5e5b('0x5b')]=function(_0x3fc9b5,_0x27d775,_0x5207e0){var _0x13fb51={'agent':{},'channel':'fax'};if(_0x3fc9b5[_0x5e5b('0x58')]['id']){delete _0x3fc9b5['body']['id'];}_0x3fc9b5[_0x5e5b('0x58')][_0x5e5b('0x5c')]=!![];_0x3fc9b5[_0x5e5b('0x58')][_0x5e5b('0x5d')]=moment()[_0x5e5b('0x5e')](_0x5e5b('0x5f'));_0x3fc9b5['body'][_0x5e5b('0x60')]=_0x3fc9b5[_0x5e5b('0x58')][_0x5e5b('0x60')]||_0x3fc9b5[_0x5e5b('0x61')]['id'];_0x13fb51['agent']['id']=_0x3fc9b5['body'][_0x5e5b('0x60')];return db[_0x5e5b('0x3d')]['find']({'where':{'id':_0x3fc9b5[_0x5e5b('0x56')]['id'],'UserId':null},'include':[{'model':db[_0x5e5b('0x62')],'as':_0x5e5b('0x63')}]})[_0x5e5b('0x23')](handleEntityNotFound(_0x27d775,null))[_0x5e5b('0x23')](saveUpdates(_0x3fc9b5['body'],null))[_0x5e5b('0x23')](function(_0x61faf2){if(_0x61faf2){_0x13fb51['message']=_0x61faf2['get']({'plain':!![]});return db['FaxInteraction'][_0x5e5b('0x57')]({'where':{'id':_0x61faf2[_0x5e5b('0x64')]}});}return null;})[_0x5e5b('0x23')](handleEntityNotFound(_0x27d775,null))[_0x5e5b('0x23')](function(_0xe8327e){if(_0xe8327e){return _0xe8327e['update']({'UserId':_0x3fc9b5[_0x5e5b('0x58')][_0x5e5b('0x60')],'read1stAt':_['isNil'](_0xe8327e[_0x5e5b('0x65')])?moment()['format']('YYYY-MM-DD\x20HH:mm:ss'):undefined});}return null;})[_0x5e5b('0x23')](function(_0x4fa0db){if(_0x4fa0db){_0x13fb51[_0x5e5b('0x66')]=_0x4fa0db[_0x5e5b('0x67')]({'plain':!![]});interaction_log[_0x5e5b('0x24')](_0x5e5b('0x68'),_0x3fc9b5[_0x5e5b('0x61')]['id'],_0x3fc9b5['user'][_0x5e5b('0x39')],_0x3fc9b5[_0x5e5b('0x61')][_0x5e5b('0x69')],_0x13fb51[_0x5e5b('0x66')]['id'],_0x3fc9b5[_0x5e5b('0x58')]?JSON[_0x5e5b('0x6a')](_0x3fc9b5[_0x5e5b('0x58')]):_0x5e5b('0x6b'));return respondWithRpcPromise(_0x5e5b('0x6c'),_0x5e5b('0x6d'),_0x13fb51);}return null;})[_0x5e5b('0x23')](function(_0x526e25){if(_0x526e25){if(_0x3fc9b5[_0x5e5b('0x58')][_0x5e5b('0x6e')]){_0x13fb51[_0x5e5b('0x2a')][_0x5e5b('0x6f')]=util[_0x5e5b('0x5e')]('SIP/%s',_0x3fc9b5[_0x5e5b('0x61')][_0x5e5b('0x39')]);_0x13fb51[_0x5e5b('0x2a')][_0x5e5b('0x70')]=_0x13fb51[_0x5e5b('0x70')];_0x13fb51[_0x5e5b('0x2a')]['event']=_0x5e5b('0x5b');return respondWithRpcPromise(_0x5e5b('0x71'),_0x5e5b('0x71'),{'event':'acceptmessage','message':_0x13fb51[_0x5e5b('0x2a')]},client9002)[_0x5e5b('0x23')](function(){return _0x13fb51;});}return _0x13fb51;}return null;})[_0x5e5b('0x23')](respondWithResult(_0x27d775,null))[_0x5e5b('0x2c')](handleError(_0x27d775,null));};var interaction_log=require(_0x5e5b('0x18'))(_0x5e5b('0x5a'));exports[_0x5e5b('0x35')]=function(_0x19b457,_0x387a44,_0x4fe5fb){var _0x19035d={'agent':{},'channel':'fax'};if(_0x19b457[_0x5e5b('0x58')]['id']){delete _0x19b457[_0x5e5b('0x58')]['id'];}_0x19b457['body']['UserId']=_0x19b457[_0x5e5b('0x58')][_0x5e5b('0x60')]||_0x19b457['user']['id'];_0x19035d[_0x5e5b('0x72')]['id']=_0x19b457['body']['UserId'];return db[_0x5e5b('0x3d')]['find']({'where':{'id':_0x19b457[_0x5e5b('0x56')]['id'],'UserId':null}})[_0x5e5b('0x23')](handleEntityNotFound(_0x387a44,null))[_0x5e5b('0x23')](function(_0x4ff92a){if(_0x4ff92a){_0x19035d[_0x5e5b('0x2a')]=_0x4ff92a[_0x5e5b('0x67')]({'plain':!![]});return db[_0x5e5b('0x73')]['find']({'where':{'id':_0x4ff92a[_0x5e5b('0x64')]}});}return null;})[_0x5e5b('0x23')](handleEntityNotFound(_0x387a44,null))['then'](function(_0x388dbe){if(_0x388dbe){_0x19035d['interaction']=_0x388dbe['get']({'plain':!![]});interaction_log[_0x5e5b('0x24')](_0x5e5b('0x74'),_0x19b457[_0x5e5b('0x61')]['id'],_0x19b457[_0x5e5b('0x61')][_0x5e5b('0x39')],_0x19b457['user'][_0x5e5b('0x69')],_0x19035d[_0x5e5b('0x66')]['id'],_0x19b457['body']?JSON['stringify'](_0x19b457[_0x5e5b('0x58')]):_0x5e5b('0x6b'));return respondWithRpcPromise(_0x5e5b('0x75'),_0x5e5b('0x76'),_0x19035d);}return null;})[_0x5e5b('0x23')](function(_0x1ad8a9){if(_0x1ad8a9){_0x1ad8a9['message'][_0x5e5b('0x6f')]=util[_0x5e5b('0x5e')](_0x5e5b('0x77'),_0x19b457['user']['name']);_0x1ad8a9[_0x5e5b('0x2a')][_0x5e5b('0x70')]=_0x19035d[_0x5e5b('0x70')];_0x1ad8a9['message'][_0x5e5b('0x78')]=_0x5e5b('0x35');respondWithRpcPromise(_0x5e5b('0x71'),'EventManager',{'event':_0x5e5b('0x79'),'message':_0x1ad8a9[_0x5e5b('0x2a')]},client9002);return _0x19035d;}return null;})[_0x5e5b('0x23')](respondWithResult(_0x387a44,null))['catch'](handleError(_0x387a44,null));};exports[_0x5e5b('0x7a')]=function(_0x9574d3,_0x3052d0){var _0x1dc878;return db[_0x5e5b('0x3d')][_0x5e5b('0x7a')](_0x9574d3['body'],{})[_0x5e5b('0x23')](function(_0x2468d5){_0x1dc878=_0x2468d5;return db['CmContact'][_0x5e5b('0x7b')]({'where':{'id':_0x1dc878['ContactId']}});})[_0x5e5b('0x23')](function(_0x263c07){if(_[_0x5e5b('0x7c')](_0x263c07)){return;}else{_0x1dc878[_0x5e5b('0x7d')]=_0x263c07[_0x5e5b('0x7d')];return db['Attachment'][_0x5e5b('0x7b')]({'where':{'id':_0x1dc878[_0x5e5b('0x7e')]}});}})[_0x5e5b('0x23')](function(_0x48d14){return respondWithRpcPromise(_0x5e5b('0x7f'),_0x5e5b('0x7f'),{'FaxAccountId':_['isNil'](_0x9574d3[_0x5e5b('0x58')])?undefined:_0x9574d3['body'][_0x5e5b('0x80')],'path':_[_0x5e5b('0x7c')](_0x48d14)?undefined:util['format']('/var/opt/motion2/server/files/attachments/%s',_0x48d14[_0x5e5b('0x81')]),'fax':_[_0x5e5b('0x7c')](_0x1dc878[_0x5e5b('0x7d')])?undefined:_0x1dc878[_0x5e5b('0x7d')],'AttachmentId':_0x1dc878[_0x5e5b('0x7e')]},client9002);})[_0x5e5b('0x23')](respondWithResult(_0x3052d0,0xc9))[_0x5e5b('0x2c')](handleError(_0x3052d0,null));};exports[_0x5e5b('0x82')]=function(_0xb0bc7,_0x231eff){var _0x4cfdcc=path[_0x5e5b('0x83')](config['root'],'server','files','attachments');return db[_0x5e5b('0x3d')][_0x5e5b('0x57')]({'where':{'id':_0xb0bc7[_0x5e5b('0x56')]['id']},'include':[{'model':db[_0x5e5b('0x84')],'as':_0x5e5b('0x84')}]})['then'](handleEntityNotFound(_0x231eff,null))[_0x5e5b('0x23')](function(_0x41f47c){if(_0x41f47c){return _0x231eff['download'](path[_0x5e5b('0x83')](_0x4cfdcc,_0x41f47c[_0x5e5b('0x84')][_0x5e5b('0x81')]));}})[_0x5e5b('0x2c')](handleError(_0x231eff,null));};
\ No newline at end of file