Built motion from commit b4f7ded2.|2.0.69
[motion2.git] / server / api / faxMessage / faxMessage.controller.js
index 66161fb..24e386a 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xae33=['intersection','model','attributes','fields','length','hasOwnProperty','nolimit','sort','pick','dateStart','add','day','where','merge','map','filter','options','FaxMessage','includeAll','include','findAll','show','params','find','body','describe','fax','readAt','YYYY-MM-DD\x20HH:mm:ss','UserId','user','Contact','FaxInteraction','FaxInteractionId','isNil','read1stAt','format','interaction','[FAXMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','AcceptMessage','manual','interface','SIP/%s','channel','accept','EventManager','acceptmessage','agent','get','[FAXMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','event','rejectmessage','create','findOne','ContactId','Attachment','AttachmentId','SendFax','/var/opt/motion2/server/files/attachments/%s','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','ejs','lodash','crypto','jsforce','desk.js','querystring','papaparse','../../config/logger','api','../../config/utils','../../mysqldb','./faxMessage.socket','register','jayson/promise','client','http','request','info','FaxMessage,\x20%s,\x20%s','request\x20sent','FaxMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','status','json','count','offset','limit','set','reject','save','update','then','destroy','end','stack','name','send','keys','rawAttributes','query','dateEnd','filters'];(function(_0x5afcbb,_0x12ed6f){var _0x19ddce=function(_0x3a17aa){while(--_0x3a17aa){_0x5afcbb['push'](_0x5afcbb['shift']());}};_0x19ddce(++_0x12ed6f);}(_0xae33,0x1a0));var _0x3ae3=function(_0x14dae1,_0x280f7f){_0x14dae1=_0x14dae1-0x0;var _0x4f207b=_0xae33[_0x14dae1];return _0x4f207b;};'use strict';var jsonpatch=require(_0x3ae3('0x0'));var rp=require(_0x3ae3('0x1'));var moment=require(_0x3ae3('0x2'));var BPromise=require('bluebird');var Mustache=require(_0x3ae3('0x3'));var util=require(_0x3ae3('0x4'));var path=require(_0x3ae3('0x5'));var sox=require(_0x3ae3('0x6'));var csv=require(_0x3ae3('0x7'));var ejs=require(_0x3ae3('0x8'));var fs=require('fs');var _=require(_0x3ae3('0x9'));var squel=require('squel');var crypto=require(_0x3ae3('0xa'));var jsforce=require(_0x3ae3('0xb'));var deskjs=require(_0x3ae3('0xc'));var toCsv=require('to-csv');var querystring=require(_0x3ae3('0xd'));var Papa=require(_0x3ae3('0xe'));var qs=require('../../components/parsers/qs');var logger=require(_0x3ae3('0xf'))(_0x3ae3('0x10'));var utils=require(_0x3ae3('0x11'));var config=require('../../config/environment');var db=require(_0x3ae3('0x12'))['db'];var socket=require('socket.io-emitter')({'host':'localhost','port':0x18eb});require(_0x3ae3('0x13'))[_0x3ae3('0x14')](socket);var jayson=require(_0x3ae3('0x15'));var client=jayson[_0x3ae3('0x16')][_0x3ae3('0x17')]({'port':0x232c});var client9002=jayson[_0x3ae3('0x16')][_0x3ae3('0x17')]({'port':0x232a});function respondWithRpcPromise(_0x9c9df4,_0x1e94be,_0x49ecd7,_0x4fcc48){return new BPromise(function(_0x2e5c5d,_0x4a106e){var _0x4cc656=_0x4fcc48||client;return _0x4cc656[_0x3ae3('0x18')](_0x9c9df4,_0x49ecd7)['then'](function(_0x59494e){logger[_0x3ae3('0x19')](_0x3ae3('0x1a'),_0x1e94be,_0x3ae3('0x1b'));logger['debug'](_0x3ae3('0x1c'),_0x1e94be,_0x3ae3('0x1b'),JSON[_0x3ae3('0x1d')](_0x59494e));if(_0x59494e[_0x3ae3('0x1e')]){if(_0x59494e[_0x3ae3('0x1e')][_0x3ae3('0x1f')]===0x1f4){logger['error'](_0x3ae3('0x1a'),_0x1e94be,_0x59494e[_0x3ae3('0x1e')][_0x3ae3('0x20')]);return _0x4a106e(_0x59494e[_0x3ae3('0x1e')][_0x3ae3('0x20')]);}logger[_0x3ae3('0x1e')]('FaxMessage,\x20%s,\x20%s',_0x1e94be,_0x59494e[_0x3ae3('0x1e')][_0x3ae3('0x20')]);return _0x2e5c5d(_0x59494e[_0x3ae3('0x1e')][_0x3ae3('0x20')]);}else{logger[_0x3ae3('0x19')](_0x3ae3('0x1a'),_0x1e94be,'request\x20sent');_0x2e5c5d(_0x59494e[_0x3ae3('0x21')]['message']);}})[_0x3ae3('0x22')](function(_0x1ad7a6){logger[_0x3ae3('0x1e')](_0x3ae3('0x1a'),_0x1e94be,_0x1ad7a6);_0x4a106e(_0x1ad7a6);});});}function respondWithStatusCode(_0x20c2ba,_0x13d851){_0x13d851=_0x13d851||0xcc;return function(_0x35741e){if(_0x35741e){return _0x20c2ba[_0x3ae3('0x23')](_0x13d851);}return _0x20c2ba[_0x3ae3('0x24')](_0x13d851)['end']();};}function respondWithResult(_0x2f1848,_0x512d7f){_0x512d7f=_0x512d7f||0xc8;return function(_0x4aa3f8){if(_0x4aa3f8){return _0x2f1848['status'](_0x512d7f)[_0x3ae3('0x25')](_0x4aa3f8);}};}function respondWithFilteredResult(_0x302370,_0x33bfab){return function(_0x1f61ff){if(_0x1f61ff){var _0x3c3e39=_0x1f61ff[_0x3ae3('0x26')],_0x1b93ac=_0x33bfab[_0x3ae3('0x27')],_0x212e89=_0x33bfab[_0x3ae3('0x27')]+_0x33bfab[_0x3ae3('0x28')],_0x4822bb;if(_0x212e89>=_0x3c3e39){_0x212e89=_0x3c3e39;_0x4822bb=0xc8;}else{_0x4822bb=0xce;}_0x302370['status'](_0x4822bb);return _0x302370[_0x3ae3('0x29')]('Content-Range',_0x1b93ac+'-'+_0x212e89+'/'+_0x3c3e39)[_0x3ae3('0x25')](_0x1f61ff);}return null;};}function patchUpdates(_0x5aab59){return function(_0x1d9ec4){try{jsonpatch['apply'](_0x1d9ec4,_0x5aab59,!![]);}catch(_0x25417e){return BPromise[_0x3ae3('0x2a')](_0x25417e);}return _0x1d9ec4[_0x3ae3('0x2b')]();};}function saveUpdates(_0x41802d,_0x587f95){return function(_0xdbcfe7){if(_0xdbcfe7){return _0xdbcfe7[_0x3ae3('0x2c')](_0x41802d)[_0x3ae3('0x2d')](function(_0xcf9e71){return _0xcf9e71;});}return null;};}function removeEntity(_0x3721d5,_0x431d9d){return function(_0x387e44){if(_0x387e44){return _0x387e44[_0x3ae3('0x2e')]()[_0x3ae3('0x2d')](function(){_0x3721d5['status'](0xcc)[_0x3ae3('0x2f')]();});}};}function handleEntityNotFound(_0x4b6cff,_0xa3212c){return function(_0x44ecb2){if(!_0x44ecb2){_0x4b6cff[_0x3ae3('0x23')](0x194);}return _0x44ecb2;};}function handleError(_0x564fa4,_0x1cb078){_0x1cb078=_0x1cb078||0x1f4;return function(_0x2c6f8e){logger[_0x3ae3('0x1e')](_0x2c6f8e[_0x3ae3('0x30')]);if(_0x2c6f8e[_0x3ae3('0x31')]){delete _0x2c6f8e[_0x3ae3('0x31')];}_0x564fa4[_0x3ae3('0x24')](_0x1cb078)[_0x3ae3('0x32')](_0x2c6f8e);};}exports['index']=function(_0x46d200,_0xb4cccb){var _0x6d2db1={},_0x36898c={},_0x4276d1={'count':0x0,'rows':[]};_0x36898c['model']=_[_0x3ae3('0x33')](db['FaxMessage'][_0x3ae3('0x34')]);var _0x7f68d0={'dateStart':_0x46d200[_0x3ae3('0x35')]['dateStart'],'dateEnd':_0x46d200[_0x3ae3('0x35')][_0x3ae3('0x36')]};delete _0x46d200['query']['dateStart'];delete _0x46d200[_0x3ae3('0x35')][_0x3ae3('0x36')];_0x36898c[_0x3ae3('0x35')]=_['keys'](_0x46d200[_0x3ae3('0x35')]);_0x36898c[_0x3ae3('0x37')]=_[_0x3ae3('0x38')](_0x36898c[_0x3ae3('0x39')],_0x36898c[_0x3ae3('0x35')]);_0x6d2db1[_0x3ae3('0x3a')]=_[_0x3ae3('0x38')](_0x36898c[_0x3ae3('0x39')],qs[_0x3ae3('0x3b')](_0x46d200[_0x3ae3('0x35')][_0x3ae3('0x3b')]));_0x6d2db1['attributes']=_0x6d2db1['attributes'][_0x3ae3('0x3c')]?_0x6d2db1[_0x3ae3('0x3a')]:_0x36898c[_0x3ae3('0x39')];if(!_0x46d200['query'][_0x3ae3('0x3d')](_0x3ae3('0x3e'))){_0x6d2db1[_0x3ae3('0x28')]=qs['limit'](_0x46d200[_0x3ae3('0x35')][_0x3ae3('0x28')]);_0x6d2db1['offset']=qs['offset'](_0x46d200['query'][_0x3ae3('0x27')]);}_0x6d2db1['order']=qs['sort'](_0x46d200[_0x3ae3('0x35')][_0x3ae3('0x3f')]);_0x6d2db1['where']=qs[_0x3ae3('0x37')](_[_0x3ae3('0x40')](_0x46d200['query'],_0x36898c['filters']));if(_0x7f68d0[_0x3ae3('0x41')]){if(_0x7f68d0['dateEnd']){_0x7f68d0[_0x3ae3('0x36')]=moment(_0x7f68d0[_0x3ae3('0x36')])[_0x3ae3('0x42')](0x1,'day');}else{_0x7f68d0['dateEnd']=moment(_0x7f68d0['dateStart'])[_0x3ae3('0x42')](0x1,_0x3ae3('0x43'));}_['merge'](_0x6d2db1[_0x3ae3('0x44')],{'createdAt':{'$gte':_0x7f68d0[_0x3ae3('0x41')],'$lte':_0x7f68d0[_0x3ae3('0x36')]}});}if(_0x46d200['query']['filter']){_0x6d2db1[_0x3ae3('0x44')]=_[_0x3ae3('0x45')](_0x6d2db1['where'],{'$or':_[_0x3ae3('0x46')](_0x6d2db1[_0x3ae3('0x3a')],function(_0x51ad43){var _0xccde68={};_0xccde68[_0x51ad43]={'$like':'%'+_0x46d200[_0x3ae3('0x35')][_0x3ae3('0x47')]+'%'};return _0xccde68;})});}_0x6d2db1=_[_0x3ae3('0x45')]({},_0x6d2db1,_0x46d200[_0x3ae3('0x48')]);var _0x37a08a={'where':_0x6d2db1[_0x3ae3('0x44')]};return db[_0x3ae3('0x49')][_0x3ae3('0x26')](_0x37a08a)[_0x3ae3('0x2d')](function(_0x2f76b4){_0x4276d1[_0x3ae3('0x26')]=_0x2f76b4;if(_0x46d200['query'][_0x3ae3('0x4a')]){_0x6d2db1[_0x3ae3('0x4b')]=[{'all':!![]}];}return db[_0x3ae3('0x49')][_0x3ae3('0x4c')](_0x6d2db1);})['then'](function(_0x55084c){_0x4276d1['rows']=_0x55084c;return _0x4276d1;})[_0x3ae3('0x2d')](respondWithFilteredResult(_0xb4cccb,_0x6d2db1))[_0x3ae3('0x22')](handleError(_0xb4cccb,null));};exports[_0x3ae3('0x4d')]=function(_0x3f54f5,_0x165d38){var _0x360d84={'raw':!![],'where':{'id':_0x3f54f5[_0x3ae3('0x4e')]['id']}},_0x1a8429={};_0x1a8429[_0x3ae3('0x39')]=_['keys'](db[_0x3ae3('0x49')][_0x3ae3('0x34')]);_0x1a8429[_0x3ae3('0x35')]=_[_0x3ae3('0x33')](_0x3f54f5[_0x3ae3('0x35')]);_0x1a8429[_0x3ae3('0x37')]=_[_0x3ae3('0x38')](_0x1a8429[_0x3ae3('0x39')],_0x1a8429['query']);_0x360d84[_0x3ae3('0x3a')]=_[_0x3ae3('0x38')](_0x1a8429[_0x3ae3('0x39')],qs['fields'](_0x3f54f5[_0x3ae3('0x35')][_0x3ae3('0x3b')]));_0x360d84['attributes']=_0x360d84[_0x3ae3('0x3a')][_0x3ae3('0x3c')]?_0x360d84[_0x3ae3('0x3a')]:_0x1a8429['model'];if(_0x3f54f5[_0x3ae3('0x35')][_0x3ae3('0x4a')]){_0x360d84[_0x3ae3('0x4b')]=[{'all':!![]}];}_0x360d84=_[_0x3ae3('0x45')]({},_0x360d84,_0x3f54f5[_0x3ae3('0x48')]);return db[_0x3ae3('0x49')][_0x3ae3('0x4f')](_0x360d84)[_0x3ae3('0x2d')](handleEntityNotFound(_0x165d38,null))[_0x3ae3('0x2d')](respondWithResult(_0x165d38,null))[_0x3ae3('0x22')](handleError(_0x165d38,null));};exports['update']=function(_0x4640ac,_0x48e7f5){if(_0x4640ac[_0x3ae3('0x50')]['id']){delete _0x4640ac[_0x3ae3('0x50')]['id'];}return db[_0x3ae3('0x49')][_0x3ae3('0x4f')]({'where':{'id':_0x4640ac[_0x3ae3('0x4e')]['id']}})['then'](handleEntityNotFound(_0x48e7f5,null))[_0x3ae3('0x2d')](saveUpdates(_0x4640ac[_0x3ae3('0x50')],null))['then'](respondWithResult(_0x48e7f5,null))[_0x3ae3('0x22')](handleError(_0x48e7f5,null));};exports[_0x3ae3('0x2e')]=function(_0x101dee,_0x54fdbd){return db[_0x3ae3('0x49')][_0x3ae3('0x4f')]({'where':{'id':_0x101dee['params']['id']}})['then'](handleEntityNotFound(_0x54fdbd,null))[_0x3ae3('0x2d')](removeEntity(_0x54fdbd,null))[_0x3ae3('0x22')](handleError(_0x54fdbd,null));};exports[_0x3ae3('0x51')]=function(_0x47b561,_0x49cab9){return db['FaxMessage'][_0x3ae3('0x51')]()['then'](respondWithResult(_0x49cab9,null))['catch'](handleError(_0x49cab9,null));};var interaction_log=require(_0x3ae3('0xf'))('fax-interactions');exports['accept']=function(_0x26a1c3,_0x23d5b5,_0x4004e4){var _0x5e6f82={'channel':_0x3ae3('0x52')};if(_0x26a1c3['body']['id']){delete _0x26a1c3[_0x3ae3('0x50')]['id'];}_0x26a1c3[_0x3ae3('0x50')]['read']=!![];_0x26a1c3[_0x3ae3('0x50')][_0x3ae3('0x53')]=moment()['format'](_0x3ae3('0x54'));_0x26a1c3[_0x3ae3('0x50')][_0x3ae3('0x55')]=_0x26a1c3[_0x3ae3('0x50')][_0x3ae3('0x55')]||_0x26a1c3[_0x3ae3('0x56')]['id'];return db[_0x3ae3('0x49')][_0x3ae3('0x4f')]({'where':{'id':_0x26a1c3[_0x3ae3('0x4e')]['id'],'UserId':null},'include':[{'model':db['CmContact'],'as':_0x3ae3('0x57')}]})[_0x3ae3('0x2d')](handleEntityNotFound(_0x23d5b5,null))[_0x3ae3('0x2d')](saveUpdates(_0x26a1c3[_0x3ae3('0x50')],null))[_0x3ae3('0x2d')](function(_0x4b1f41){if(_0x4b1f41){_0x5e6f82[_0x3ae3('0x20')]=_0x4b1f41['get']({'plain':!![]});return db[_0x3ae3('0x58')]['find']({'where':{'id':_0x4b1f41[_0x3ae3('0x59')]}});}return null;})['then'](handleEntityNotFound(_0x23d5b5,null))[_0x3ae3('0x2d')](function(_0x352bc5){if(_0x352bc5){return _0x352bc5[_0x3ae3('0x2c')]({'UserId':_0x26a1c3[_0x3ae3('0x50')]['UserId'],'read1stAt':_[_0x3ae3('0x5a')](_0x352bc5[_0x3ae3('0x5b')])?moment()[_0x3ae3('0x5c')](_0x3ae3('0x54')):undefined});}return null;})[_0x3ae3('0x2d')](function(_0x38684c){if(_0x38684c){_0x5e6f82[_0x3ae3('0x5d')]=_0x38684c['get']({'plain':!![]});interaction_log[_0x3ae3('0x19')](_0x3ae3('0x5e'),_0x26a1c3[_0x3ae3('0x56')]['id'],_0x26a1c3[_0x3ae3('0x56')][_0x3ae3('0x31')],_0x26a1c3[_0x3ae3('0x56')][_0x3ae3('0x5f')],_0x5e6f82[_0x3ae3('0x5d')]['id'],_0x26a1c3[_0x3ae3('0x50')]?JSON['stringify'](_0x26a1c3[_0x3ae3('0x50')]):_0x3ae3('0x60'));return respondWithRpcPromise(_0x3ae3('0x61'),'acceptMessage',_0x5e6f82);}return null;})[_0x3ae3('0x2d')](function(_0x51158f){if(_0x51158f){if(_0x26a1c3[_0x3ae3('0x50')][_0x3ae3('0x62')]){_0x5e6f82[_0x3ae3('0x20')][_0x3ae3('0x63')]=util[_0x3ae3('0x5c')](_0x3ae3('0x64'),_0x26a1c3[_0x3ae3('0x56')][_0x3ae3('0x31')]);_0x5e6f82[_0x3ae3('0x20')][_0x3ae3('0x65')]=_0x5e6f82['channel'];_0x5e6f82['message']['event']=_0x3ae3('0x66');return respondWithRpcPromise(_0x3ae3('0x67'),_0x3ae3('0x67'),{'event':_0x3ae3('0x68'),'message':_0x5e6f82['message']},client9002)['then'](function(){return _0x5e6f82;});}return _0x5e6f82;}return null;})['then'](respondWithResult(_0x23d5b5,null))[_0x3ae3('0x22')](handleError(_0x23d5b5,null));};var interaction_log=require(_0x3ae3('0xf'))('fax-interactions');exports['reject']=function(_0x150869,_0x94cf5c,_0x463222){var _0x4ac7b3={'agent':{},'channel':_0x3ae3('0x52')};if(_0x150869[_0x3ae3('0x50')]['id']){delete _0x150869[_0x3ae3('0x50')]['id'];}_0x150869[_0x3ae3('0x50')][_0x3ae3('0x55')]=_0x150869[_0x3ae3('0x50')]['UserId']||_0x150869['user']['id'];_0x4ac7b3[_0x3ae3('0x69')]['id']=_0x150869[_0x3ae3('0x50')][_0x3ae3('0x55')];return db[_0x3ae3('0x49')]['find']({'where':{'id':_0x150869[_0x3ae3('0x4e')]['id'],'UserId':null}})[_0x3ae3('0x2d')](handleEntityNotFound(_0x94cf5c,null))[_0x3ae3('0x2d')](function(_0x30ee57){if(_0x30ee57){_0x4ac7b3[_0x3ae3('0x20')]=_0x30ee57[_0x3ae3('0x6a')]({'plain':!![]});return db[_0x3ae3('0x58')][_0x3ae3('0x4f')]({'where':{'id':_0x30ee57['FaxInteractionId']}});}return null;})[_0x3ae3('0x2d')](handleEntityNotFound(_0x94cf5c,null))[_0x3ae3('0x2d')](function(_0x15dbcb){if(_0x15dbcb){_0x4ac7b3[_0x3ae3('0x5d')]=_0x15dbcb[_0x3ae3('0x6a')]({'plain':!![]});interaction_log[_0x3ae3('0x19')](_0x3ae3('0x6b'),_0x150869[_0x3ae3('0x56')]['id'],_0x150869[_0x3ae3('0x56')]['name'],_0x150869[_0x3ae3('0x56')][_0x3ae3('0x5f')],_0x4ac7b3[_0x3ae3('0x5d')]['id'],_0x150869[_0x3ae3('0x50')]?JSON[_0x3ae3('0x1d')](_0x150869[_0x3ae3('0x50')]):_0x3ae3('0x60'));return respondWithRpcPromise(_0x3ae3('0x6c'),'rejectMessage',_0x4ac7b3);}return null;})[_0x3ae3('0x2d')](function(_0x59ea3a){if(_0x59ea3a){_0x59ea3a[_0x3ae3('0x20')]['interface']=util[_0x3ae3('0x5c')](_0x3ae3('0x64'),_0x150869[_0x3ae3('0x56')][_0x3ae3('0x31')]);_0x59ea3a[_0x3ae3('0x20')][_0x3ae3('0x65')]=_0x4ac7b3['channel'];_0x59ea3a[_0x3ae3('0x20')][_0x3ae3('0x6d')]=_0x3ae3('0x2a');respondWithRpcPromise(_0x3ae3('0x67'),_0x3ae3('0x67'),{'event':_0x3ae3('0x6e'),'message':_0x59ea3a[_0x3ae3('0x20')]},client9002);return _0x4ac7b3;}return null;})[_0x3ae3('0x2d')](respondWithResult(_0x94cf5c,null))[_0x3ae3('0x22')](handleError(_0x94cf5c,null));};exports[_0x3ae3('0x6f')]=function(_0x46866f,_0x9b0c0e){var _0xb9c30;return db['FaxMessage'][_0x3ae3('0x6f')](_0x46866f[_0x3ae3('0x50')],{})[_0x3ae3('0x2d')](function(_0x4461a4){_0xb9c30=_0x4461a4;return db['CmContact'][_0x3ae3('0x70')]({'where':{'id':_0xb9c30[_0x3ae3('0x71')]}});})['then'](function(_0x4c4907){if(_[_0x3ae3('0x5a')](_0x4c4907)){return;}else{_0xb9c30[_0x3ae3('0x52')]=_0x4c4907[_0x3ae3('0x52')];return db[_0x3ae3('0x72')]['findOne']({'where':{'id':_0xb9c30[_0x3ae3('0x73')]}});}})['then'](function(_0x2d95b3){return respondWithRpcPromise(_0x3ae3('0x74'),_0x3ae3('0x74'),{'FaxAccountId':_[_0x3ae3('0x5a')](_0x46866f[_0x3ae3('0x50')])?undefined:_0x46866f[_0x3ae3('0x50')]['FaxAccountId'],'path':_[_0x3ae3('0x5a')](_0x2d95b3)?undefined:util[_0x3ae3('0x5c')](_0x3ae3('0x75'),_0x2d95b3['basename']),'fax':_['isNil'](_0xb9c30[_0x3ae3('0x52')])?undefined:_0xb9c30[_0x3ae3('0x52')],'AttachmentId':_0xb9c30[_0x3ae3('0x73')]},client9002);})[_0x3ae3('0x2d')](respondWithResult(_0x9b0c0e,0xc9))[_0x3ae3('0x22')](handleError(_0x9b0c0e,null));};
\ No newline at end of file
+var _0xb2f3=['create','CmContact','findOne','ContactId','SendFax','FaxAccountId','/var/opt/motion2/server/files/attachments/%s','basename','AttachmentId','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','../../components/parsers/qs','../../config/logger','api','../../config/utils','socket.io-emitter','localhost','./faxMessage.socket','register','jayson/promise','client','http','request','info','request\x20sent','FaxMessage,\x20%s,\x20%s,\x20%s','stringify','error','FaxMessage,\x20%s,\x20%s','message','result','catch','status','end','json','offset','limit','Content-Range','apply','reject','save','destroy','then','sendStatus','stack','name','send','index','FaxMessage','rawAttributes','query','dateStart','dateEnd','keys','intersection','attributes','fields','length','model','hasOwnProperty','nolimit','order','sort','where','pick','filters','add','day','merge','options','count','includeAll','include','findAll','rows','show','params','update','body','find','describe','fax-interactions','accept','fax','read','readAt','UserId','get','FaxInteraction','FaxInteractionId','isNil','read1stAt','format','YYYY-MM-DD\x20HH:mm:ss','interaction','[FAXMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','user','role','null','AcceptMessage','manual','SIP/%s','channel','EventManager','acceptmessage','agent','[FAXMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','interface','rejectmessage'];(function(_0x37c22c,_0x28a70d){var _0x119d79=function(_0x243a13){while(--_0x243a13){_0x37c22c['push'](_0x37c22c['shift']());}};_0x119d79(++_0x28a70d);}(_0xb2f3,0xfd));var _0x3b2f=function(_0x59ee6f,_0x450239){_0x59ee6f=_0x59ee6f-0x0;var _0x4c0979=_0xb2f3[_0x59ee6f];return _0x4c0979;};'use strict';var jsonpatch=require(_0x3b2f('0x0'));var rp=require(_0x3b2f('0x1'));var moment=require(_0x3b2f('0x2'));var BPromise=require(_0x3b2f('0x3'));var Mustache=require(_0x3b2f('0x4'));var util=require(_0x3b2f('0x5'));var path=require(_0x3b2f('0x6'));var sox=require('sox');var csv=require(_0x3b2f('0x7'));var ejs=require(_0x3b2f('0x8'));var fs=require('fs');var _=require(_0x3b2f('0x9'));var squel=require(_0x3b2f('0xa'));var crypto=require(_0x3b2f('0xb'));var jsforce=require(_0x3b2f('0xc'));var deskjs=require(_0x3b2f('0xd'));var toCsv=require('to-csv');var querystring=require(_0x3b2f('0xe'));var Papa=require('papaparse');var qs=require(_0x3b2f('0xf'));var logger=require(_0x3b2f('0x10'))(_0x3b2f('0x11'));var utils=require(_0x3b2f('0x12'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];var socket=require(_0x3b2f('0x13'))({'host':_0x3b2f('0x14'),'port':0x18eb});require(_0x3b2f('0x15'))[_0x3b2f('0x16')](socket);var jayson=require(_0x3b2f('0x17'));var client=jayson[_0x3b2f('0x18')][_0x3b2f('0x19')]({'port':0x232c});var client9002=jayson[_0x3b2f('0x18')][_0x3b2f('0x19')]({'port':0x232a});function respondWithRpcPromise(_0x322dda,_0x458f93,_0x2a9d0e,_0x1f509a){return new BPromise(function(_0x1319b4,_0x37e53d){var _0x4fb033=_0x1f509a||client;return _0x4fb033[_0x3b2f('0x1a')](_0x322dda,_0x2a9d0e)['then'](function(_0x2ef8ca){logger[_0x3b2f('0x1b')]('FaxMessage,\x20%s,\x20%s',_0x458f93,_0x3b2f('0x1c'));logger['debug'](_0x3b2f('0x1d'),_0x458f93,_0x3b2f('0x1c'),JSON[_0x3b2f('0x1e')](_0x2ef8ca));if(_0x2ef8ca[_0x3b2f('0x1f')]){if(_0x2ef8ca['error']['code']===0x1f4){logger[_0x3b2f('0x1f')](_0x3b2f('0x20'),_0x458f93,_0x2ef8ca[_0x3b2f('0x1f')][_0x3b2f('0x21')]);return _0x37e53d(_0x2ef8ca[_0x3b2f('0x1f')][_0x3b2f('0x21')]);}logger[_0x3b2f('0x1f')](_0x3b2f('0x20'),_0x458f93,_0x2ef8ca[_0x3b2f('0x1f')][_0x3b2f('0x21')]);return _0x1319b4(_0x2ef8ca[_0x3b2f('0x1f')][_0x3b2f('0x21')]);}else{logger[_0x3b2f('0x1b')](_0x3b2f('0x20'),_0x458f93,'request\x20sent');_0x1319b4(_0x2ef8ca[_0x3b2f('0x22')][_0x3b2f('0x21')]);}})[_0x3b2f('0x23')](function(_0xef73a0){logger['error'](_0x3b2f('0x20'),_0x458f93,_0xef73a0);_0x37e53d(_0xef73a0);});});}function respondWithStatusCode(_0x3d270b,_0x5ed7bd){_0x5ed7bd=_0x5ed7bd||0xcc;return function(_0x429649){if(_0x429649){return _0x3d270b['sendStatus'](_0x5ed7bd);}return _0x3d270b[_0x3b2f('0x24')](_0x5ed7bd)[_0x3b2f('0x25')]();};}function respondWithResult(_0x267fa5,_0x409401){_0x409401=_0x409401||0xc8;return function(_0x51c00a){if(_0x51c00a){return _0x267fa5[_0x3b2f('0x24')](_0x409401)[_0x3b2f('0x26')](_0x51c00a);}};}function respondWithFilteredResult(_0x48592c,_0x4db72f){return function(_0x11e9e7){if(_0x11e9e7){var _0x44fa57=_0x11e9e7['count'],_0x9cf807=_0x4db72f[_0x3b2f('0x27')],_0x2ca527=_0x4db72f[_0x3b2f('0x27')]+_0x4db72f[_0x3b2f('0x28')],_0x4a8aa7;if(_0x2ca527>=_0x44fa57){_0x2ca527=_0x44fa57;_0x4a8aa7=0xc8;}else{_0x4a8aa7=0xce;}_0x48592c[_0x3b2f('0x24')](_0x4a8aa7);return _0x48592c['set'](_0x3b2f('0x29'),_0x9cf807+'-'+_0x2ca527+'/'+_0x44fa57)['json'](_0x11e9e7);}return null;};}function patchUpdates(_0x30d504){return function(_0x21c8a4){try{jsonpatch[_0x3b2f('0x2a')](_0x21c8a4,_0x30d504,!![]);}catch(_0x469fc9){return BPromise[_0x3b2f('0x2b')](_0x469fc9);}return _0x21c8a4[_0x3b2f('0x2c')]();};}function saveUpdates(_0x593f3d,_0x1fbcb6){return function(_0x335e75){if(_0x335e75){return _0x335e75['update'](_0x593f3d)['then'](function(_0x450080){return _0x450080;});}return null;};}function removeEntity(_0x3380d4,_0x5de7f2){return function(_0x4a0d14){if(_0x4a0d14){return _0x4a0d14[_0x3b2f('0x2d')]()[_0x3b2f('0x2e')](function(){_0x3380d4[_0x3b2f('0x24')](0xcc)[_0x3b2f('0x25')]();});}};}function handleEntityNotFound(_0x309099,_0x2b0cc0){return function(_0x5bfa76){if(!_0x5bfa76){_0x309099[_0x3b2f('0x2f')](0x194);}return _0x5bfa76;};}function handleError(_0x104f1f,_0x5029cf){_0x5029cf=_0x5029cf||0x1f4;return function(_0x2fb736){logger[_0x3b2f('0x1f')](_0x2fb736[_0x3b2f('0x30')]);if(_0x2fb736[_0x3b2f('0x31')]){delete _0x2fb736['name'];}_0x104f1f[_0x3b2f('0x24')](_0x5029cf)[_0x3b2f('0x32')](_0x2fb736);};}exports[_0x3b2f('0x33')]=function(_0x2d8a6b,_0x500b73){var _0x4fa6e9={},_0x2421ce={},_0x30214f={'count':0x0,'rows':[]};var _0x445dc9=db[_0x3b2f('0x34')][_0x3b2f('0x35')];_0x2421ce['model']=_['keys'](_0x445dc9);var _0xf7fb3={'dateStart':_0x2d8a6b[_0x3b2f('0x36')][_0x3b2f('0x37')],'dateEnd':_0x2d8a6b['query'][_0x3b2f('0x38')]};delete _0x2d8a6b[_0x3b2f('0x36')][_0x3b2f('0x37')];delete _0x2d8a6b['query'][_0x3b2f('0x38')];_0x2421ce[_0x3b2f('0x36')]=_[_0x3b2f('0x39')](_0x2d8a6b['query']);_0x2421ce['filters']=_[_0x3b2f('0x3a')](_0x2421ce['model'],_0x2421ce['query']);_0x4fa6e9[_0x3b2f('0x3b')]=_[_0x3b2f('0x3a')](_0x2421ce['model'],qs[_0x3b2f('0x3c')](_0x2d8a6b[_0x3b2f('0x36')][_0x3b2f('0x3c')]));_0x4fa6e9[_0x3b2f('0x3b')]=_0x4fa6e9[_0x3b2f('0x3b')][_0x3b2f('0x3d')]?_0x4fa6e9[_0x3b2f('0x3b')]:_0x2421ce[_0x3b2f('0x3e')];if(!_0x2d8a6b['query'][_0x3b2f('0x3f')](_0x3b2f('0x40'))){_0x4fa6e9[_0x3b2f('0x28')]=qs[_0x3b2f('0x28')](_0x2d8a6b[_0x3b2f('0x36')][_0x3b2f('0x28')]);_0x4fa6e9[_0x3b2f('0x27')]=qs[_0x3b2f('0x27')](_0x2d8a6b[_0x3b2f('0x36')]['offset']);}_0x4fa6e9[_0x3b2f('0x41')]=qs[_0x3b2f('0x42')](_0x2d8a6b[_0x3b2f('0x36')]['sort']);_0x4fa6e9[_0x3b2f('0x43')]=qs['filters'](_[_0x3b2f('0x44')](_0x2d8a6b[_0x3b2f('0x36')],_0x2421ce[_0x3b2f('0x45')]));if(_0xf7fb3[_0x3b2f('0x37')]){if(_0xf7fb3[_0x3b2f('0x38')]){_0xf7fb3[_0x3b2f('0x38')]=moment(_0xf7fb3['dateEnd'])[_0x3b2f('0x46')](0x1,'day');}else{_0xf7fb3[_0x3b2f('0x38')]=moment(_0xf7fb3[_0x3b2f('0x37')])['add'](0x1,_0x3b2f('0x47'));}_[_0x3b2f('0x48')](_0x4fa6e9[_0x3b2f('0x43')],{'createdAt':{'$gte':_0xf7fb3[_0x3b2f('0x37')],'$lte':_0xf7fb3[_0x3b2f('0x38')]}});}if(_0x2d8a6b['query']['filter']){_0x4fa6e9[_0x3b2f('0x43')]=_['merge'](_0x4fa6e9[_0x3b2f('0x43')],{'$or':_['map'](_0x4fa6e9[_0x3b2f('0x3b')],function(_0xadb569){var _0x39f2c6={};_0x39f2c6[_0xadb569]={'$like':'%'+_0x2d8a6b[_0x3b2f('0x36')]['filter']+'%'};return _0x39f2c6;})});}_0x4fa6e9=_[_0x3b2f('0x48')]({},_0x4fa6e9,_0x2d8a6b[_0x3b2f('0x49')]);var _0x346912={'where':_0x4fa6e9['where']};return db[_0x3b2f('0x34')][_0x3b2f('0x4a')](_0x346912)[_0x3b2f('0x2e')](function(_0x26f92f){_0x30214f['count']=_0x26f92f;if(_0x2d8a6b[_0x3b2f('0x36')][_0x3b2f('0x4b')]){_0x4fa6e9[_0x3b2f('0x4c')]=[{'all':!![]}];}return db[_0x3b2f('0x34')][_0x3b2f('0x4d')](_0x4fa6e9);})[_0x3b2f('0x2e')](function(_0x381140){_0x30214f[_0x3b2f('0x4e')]=_0x381140;return _0x30214f;})['then'](respondWithFilteredResult(_0x500b73,_0x4fa6e9))[_0x3b2f('0x23')](handleError(_0x500b73,null));};exports[_0x3b2f('0x4f')]=function(_0x5d2acf,_0x484f8d){var _0x590922={'raw':!![],'where':{'id':_0x5d2acf[_0x3b2f('0x50')]['id']}},_0x41cee8={};_0x41cee8[_0x3b2f('0x3e')]=_[_0x3b2f('0x39')](db['FaxMessage'][_0x3b2f('0x35')]);_0x41cee8[_0x3b2f('0x36')]=_['keys'](_0x5d2acf['query']);_0x41cee8['filters']=_[_0x3b2f('0x3a')](_0x41cee8[_0x3b2f('0x3e')],_0x41cee8['query']);_0x590922['attributes']=_['intersection'](_0x41cee8['model'],qs[_0x3b2f('0x3c')](_0x5d2acf[_0x3b2f('0x36')][_0x3b2f('0x3c')]));_0x590922[_0x3b2f('0x3b')]=_0x590922['attributes'][_0x3b2f('0x3d')]?_0x590922['attributes']:_0x41cee8[_0x3b2f('0x3e')];if(_0x5d2acf[_0x3b2f('0x36')][_0x3b2f('0x4b')]){_0x590922[_0x3b2f('0x4c')]=[{'all':!![]}];}_0x590922=_['merge']({},_0x590922,_0x5d2acf['options']);return db['FaxMessage']['find'](_0x590922)[_0x3b2f('0x2e')](handleEntityNotFound(_0x484f8d,null))['then'](respondWithResult(_0x484f8d,null))[_0x3b2f('0x23')](handleError(_0x484f8d,null));};exports[_0x3b2f('0x51')]=function(_0x4eb3b3,_0xbee5fa){if(_0x4eb3b3[_0x3b2f('0x52')]['id']){delete _0x4eb3b3[_0x3b2f('0x52')]['id'];}return db['FaxMessage'][_0x3b2f('0x53')]({'where':{'id':_0x4eb3b3[_0x3b2f('0x50')]['id']}})['then'](handleEntityNotFound(_0xbee5fa,null))['then'](saveUpdates(_0x4eb3b3[_0x3b2f('0x52')],null))[_0x3b2f('0x2e')](respondWithResult(_0xbee5fa,null))[_0x3b2f('0x23')](handleError(_0xbee5fa,null));};exports[_0x3b2f('0x2d')]=function(_0x5db85c,_0x3438fd){return db['FaxMessage'][_0x3b2f('0x53')]({'where':{'id':_0x5db85c['params']['id']}})[_0x3b2f('0x2e')](handleEntityNotFound(_0x3438fd,null))[_0x3b2f('0x2e')](removeEntity(_0x3438fd,null))['catch'](handleError(_0x3438fd,null));};exports[_0x3b2f('0x54')]=function(_0x1a58da,_0x167e05){return db['FaxMessage']['describe']()[_0x3b2f('0x2e')](respondWithResult(_0x167e05,null))[_0x3b2f('0x23')](handleError(_0x167e05,null));};var interaction_log=require(_0x3b2f('0x10'))(_0x3b2f('0x55'));exports[_0x3b2f('0x56')]=function(_0x537ed8,_0x230cb5,_0x1e45e4){var _0x300975={'channel':_0x3b2f('0x57')};if(_0x537ed8[_0x3b2f('0x52')]['id']){delete _0x537ed8[_0x3b2f('0x52')]['id'];}_0x537ed8['body'][_0x3b2f('0x58')]=!![];_0x537ed8['body'][_0x3b2f('0x59')]=moment()['format']('YYYY-MM-DD\x20HH:mm:ss');_0x537ed8['body']['UserId']=_0x537ed8[_0x3b2f('0x52')][_0x3b2f('0x5a')]||_0x537ed8['user']['id'];return db[_0x3b2f('0x34')][_0x3b2f('0x53')]({'where':{'id':_0x537ed8[_0x3b2f('0x50')]['id'],'UserId':null},'include':[{'model':db['CmContact'],'as':'Contact'}]})[_0x3b2f('0x2e')](handleEntityNotFound(_0x230cb5,null))[_0x3b2f('0x2e')](saveUpdates(_0x537ed8[_0x3b2f('0x52')],null))[_0x3b2f('0x2e')](function(_0x2338a4){if(_0x2338a4){_0x300975['message']=_0x2338a4[_0x3b2f('0x5b')]({'plain':!![]});return db[_0x3b2f('0x5c')][_0x3b2f('0x53')]({'where':{'id':_0x2338a4[_0x3b2f('0x5d')]}});}return null;})[_0x3b2f('0x2e')](handleEntityNotFound(_0x230cb5,null))[_0x3b2f('0x2e')](function(_0x3df98d){if(_0x3df98d){return _0x3df98d[_0x3b2f('0x51')]({'UserId':_0x537ed8[_0x3b2f('0x52')][_0x3b2f('0x5a')],'read1stAt':_[_0x3b2f('0x5e')](_0x3df98d[_0x3b2f('0x5f')])?moment()[_0x3b2f('0x60')](_0x3b2f('0x61')):undefined});}return null;})['then'](function(_0x55bc41){if(_0x55bc41){_0x300975[_0x3b2f('0x62')]=_0x55bc41[_0x3b2f('0x5b')]({'plain':!![]});interaction_log['info'](_0x3b2f('0x63'),_0x537ed8[_0x3b2f('0x64')]['id'],_0x537ed8[_0x3b2f('0x64')][_0x3b2f('0x31')],_0x537ed8[_0x3b2f('0x64')][_0x3b2f('0x65')],_0x300975[_0x3b2f('0x62')]['id'],_0x537ed8[_0x3b2f('0x52')]?JSON[_0x3b2f('0x1e')](_0x537ed8['body']):_0x3b2f('0x66'));return respondWithRpcPromise(_0x3b2f('0x67'),'acceptMessage',_0x300975);}return null;})[_0x3b2f('0x2e')](function(_0x3399e7){if(_0x3399e7){if(_0x537ed8[_0x3b2f('0x52')][_0x3b2f('0x68')]){_0x300975[_0x3b2f('0x21')]['interface']=util['format'](_0x3b2f('0x69'),_0x537ed8[_0x3b2f('0x64')]['name']);_0x300975[_0x3b2f('0x21')][_0x3b2f('0x6a')]=_0x300975[_0x3b2f('0x6a')];_0x300975[_0x3b2f('0x21')]['event']=_0x3b2f('0x56');return respondWithRpcPromise(_0x3b2f('0x6b'),_0x3b2f('0x6b'),{'event':_0x3b2f('0x6c'),'message':_0x300975[_0x3b2f('0x21')]},client9002)['then'](function(){return _0x300975;});}return _0x300975;}return null;})['then'](respondWithResult(_0x230cb5,null))[_0x3b2f('0x23')](handleError(_0x230cb5,null));};var interaction_log=require(_0x3b2f('0x10'))(_0x3b2f('0x55'));exports[_0x3b2f('0x2b')]=function(_0x171ba4,_0x2c0a17,_0x5e413c){var _0x1426e9={'agent':{},'channel':_0x3b2f('0x57')};if(_0x171ba4['body']['id']){delete _0x171ba4['body']['id'];}_0x171ba4['body'][_0x3b2f('0x5a')]=_0x171ba4['body']['UserId']||_0x171ba4[_0x3b2f('0x64')]['id'];_0x1426e9[_0x3b2f('0x6d')]['id']=_0x171ba4[_0x3b2f('0x52')][_0x3b2f('0x5a')];return db[_0x3b2f('0x34')][_0x3b2f('0x53')]({'where':{'id':_0x171ba4[_0x3b2f('0x50')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x2c0a17,null))[_0x3b2f('0x2e')](function(_0xdc9470){if(_0xdc9470){_0x1426e9['message']=_0xdc9470[_0x3b2f('0x5b')]({'plain':!![]});return db['FaxInteraction']['find']({'where':{'id':_0xdc9470['FaxInteractionId']}});}return null;})['then'](handleEntityNotFound(_0x2c0a17,null))[_0x3b2f('0x2e')](function(_0x5d5ea1){if(_0x5d5ea1){_0x1426e9[_0x3b2f('0x62')]=_0x5d5ea1[_0x3b2f('0x5b')]({'plain':!![]});interaction_log['info'](_0x3b2f('0x6e'),_0x171ba4[_0x3b2f('0x64')]['id'],_0x171ba4[_0x3b2f('0x64')][_0x3b2f('0x31')],_0x171ba4[_0x3b2f('0x64')][_0x3b2f('0x65')],_0x1426e9[_0x3b2f('0x62')]['id'],_0x171ba4['body']?JSON['stringify'](_0x171ba4[_0x3b2f('0x52')]):_0x3b2f('0x66'));return respondWithRpcPromise('RejectMessage','rejectMessage',_0x1426e9);}return null;})[_0x3b2f('0x2e')](function(_0x281dab){if(_0x281dab){_0x281dab[_0x3b2f('0x21')][_0x3b2f('0x6f')]=util[_0x3b2f('0x60')](_0x3b2f('0x69'),_0x171ba4[_0x3b2f('0x64')][_0x3b2f('0x31')]);_0x281dab[_0x3b2f('0x21')][_0x3b2f('0x6a')]=_0x1426e9[_0x3b2f('0x6a')];_0x281dab[_0x3b2f('0x21')]['event']=_0x3b2f('0x2b');respondWithRpcPromise('EventManager',_0x3b2f('0x6b'),{'event':_0x3b2f('0x70'),'message':_0x281dab['message']},client9002);return _0x1426e9;}return null;})[_0x3b2f('0x2e')](respondWithResult(_0x2c0a17,null))['catch'](handleError(_0x2c0a17,null));};exports[_0x3b2f('0x71')]=function(_0x1dd448,_0x37e8cd){var _0x483f8f;return db['FaxMessage']['create'](_0x1dd448[_0x3b2f('0x52')],{})['then'](function(_0x277ff5){_0x483f8f=_0x277ff5;return db[_0x3b2f('0x72')][_0x3b2f('0x73')]({'where':{'id':_0x483f8f[_0x3b2f('0x74')]}});})[_0x3b2f('0x2e')](function(_0x16bcb8){if(_[_0x3b2f('0x5e')](_0x16bcb8)){return;}else{_0x483f8f['fax']=_0x16bcb8[_0x3b2f('0x57')];return db['Attachment'][_0x3b2f('0x73')]({'where':{'id':_0x483f8f['AttachmentId']}});}})['then'](function(_0x35232d){return respondWithRpcPromise(_0x3b2f('0x75'),_0x3b2f('0x75'),{'FaxAccountId':_['isNil'](_0x1dd448['body'])?undefined:_0x1dd448['body'][_0x3b2f('0x76')],'path':_[_0x3b2f('0x5e')](_0x35232d)?undefined:util[_0x3b2f('0x60')](_0x3b2f('0x77'),_0x35232d[_0x3b2f('0x78')]),'fax':_[_0x3b2f('0x5e')](_0x483f8f['fax'])?undefined:_0x483f8f['fax'],'AttachmentId':_0x483f8f[_0x3b2f('0x79')]},client9002);})['then'](respondWithResult(_0x37e8cd,0xc9))[_0x3b2f('0x23')](handleError(_0x37e8cd,null));};
\ No newline at end of file