Built motion from commit 3c2ce842.|2.6.31
[motion2.git] / server / api / faxMessage / faxMessage.controller.js
index 9b55ef6..7771fea 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x48db=['pick','filter','merge','where','options','FaxMessage','count','includeAll','include','rows','catch','show','find','update','body','params','destroy','describe','fax','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','CmContact','Contact','get','FaxInteractionId','read1stAt','interaction','[FAXMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','null','AcceptMessage','manual','interface','SIP/%s','channel','event','accept','EventManager','acceptmessage','../../config/logger','fax-interactions','agent','FaxInteraction','[FAXMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','RejectMessage','rejectMessage','create','findOne','ContactId','Attachment','SendFax','isNil','FaxAccountId','/var/opt/motion2/server/files/attachments/%s','basename','AttachmentId','download','join','files','attachments','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','to-csv','ejs','lodash','squel','crypto','jsforce','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','./faxMessage.socket','register','http','request','info','FaxMessage,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','result','sendStatus','status','offset','limit','set','Content-Range','json','apply','reject','save','then','end','stack','index','map','rawAttributes','fieldName','type','key','model','name','keys','query','filters','attributes','intersection','fields','length','nolimit','order','sort'];(function(_0x13f0b4,_0x3713f0){var _0x31f462=function(_0x58c586){while(--_0x58c586){_0x13f0b4['push'](_0x13f0b4['shift']());}};_0x31f462(++_0x3713f0);}(_0x48db,0x1cf));var _0xb48d=function(_0x15b84a,_0x24fdc2){_0x15b84a=_0x15b84a-0x0;var _0x2e05bd=_0x48db[_0x15b84a];return _0x2e05bd;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0xb48d('0x0'));var zipdir=require(_0xb48d('0x1'));var jsonpatch=require(_0xb48d('0x2'));var rp=require(_0xb48d('0x3'));var moment=require(_0xb48d('0x4'));var BPromise=require(_0xb48d('0x5'));var Mustache=require('mustache');var util=require(_0xb48d('0x6'));var path=require(_0xb48d('0x7'));var sox=require('sox');var csv=require(_0xb48d('0x8'));var ejs=require(_0xb48d('0x9'));var fs=require('fs');var _=require(_0xb48d('0xa'));var squel=require(_0xb48d('0xb'));var crypto=require(_0xb48d('0xc'));var jsforce=require(_0xb48d('0xd'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0xb48d('0xe'));var Papa=require('papaparse');var Redis=require(_0xb48d('0xf'));var authService=require(_0xb48d('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0xb48d('0x11'));var hardwareService=require(_0xb48d('0x12'));var logger=require('../../config/logger')(_0xb48d('0x13'));var utils=require(_0xb48d('0x14'));var config=require(_0xb48d('0x15'));var licenseUtil=require(_0xb48d('0x16'));var db=require(_0xb48d('0x17'))['db'];config[_0xb48d('0x18')]=_[_0xb48d('0x19')](config[_0xb48d('0x18')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xb48d('0x18')]));require(_0xb48d('0x1a'))[_0xb48d('0x1b')](socket);var jayson=require('jayson/promise');var client=jayson['client'][_0xb48d('0x1c')]({'port':0x232c});var client9002=jayson['client'][_0xb48d('0x1c')]({'port':0x232a});function respondWithRpcPromise(_0x405f7a,_0x41b6e9,_0x1e8b03,_0x312f1c){return new BPromise(function(_0x2e4b0b,_0xdebfc){var _0x5374f9=_0x312f1c||client;return _0x5374f9[_0xb48d('0x1d')](_0x405f7a,_0x1e8b03)['then'](function(_0x39f234){logger[_0xb48d('0x1e')](_0xb48d('0x1f'),_0x41b6e9,_0xb48d('0x20'));logger['debug']('FaxMessage,\x20%s,\x20%s,\x20%s',_0x41b6e9,'request\x20sent',JSON[_0xb48d('0x21')](_0x39f234));if(_0x39f234[_0xb48d('0x22')]){if(_0x39f234[_0xb48d('0x22')][_0xb48d('0x23')]===0x1f4){logger[_0xb48d('0x22')](_0xb48d('0x1f'),_0x41b6e9,_0x39f234['error'][_0xb48d('0x24')]);return _0xdebfc(_0x39f234['error'][_0xb48d('0x24')]);}logger[_0xb48d('0x22')](_0xb48d('0x1f'),_0x41b6e9,_0x39f234[_0xb48d('0x22')][_0xb48d('0x24')]);return _0x2e4b0b(_0x39f234[_0xb48d('0x22')][_0xb48d('0x24')]);}else{logger[_0xb48d('0x1e')](_0xb48d('0x1f'),_0x41b6e9,_0xb48d('0x20'));_0x2e4b0b(_0x39f234[_0xb48d('0x25')]['message']);}})['catch'](function(_0x15af9f){logger[_0xb48d('0x22')](_0xb48d('0x1f'),_0x41b6e9,_0x15af9f);_0xdebfc(_0x15af9f);});});}function respondWithStatusCode(_0x21c0dc,_0x4e93ee){_0x4e93ee=_0x4e93ee||0xcc;return function(_0x2b6400){if(_0x2b6400){return _0x21c0dc[_0xb48d('0x26')](_0x4e93ee);}return _0x21c0dc[_0xb48d('0x27')](_0x4e93ee)['end']();};}function respondWithResult(_0x1b59a7,_0x35582a){_0x35582a=_0x35582a||0xc8;return function(_0x105aa8){if(_0x105aa8){return _0x1b59a7[_0xb48d('0x27')](_0x35582a)['json'](_0x105aa8);}};}function respondWithFilteredResult(_0x51bc3a,_0x16ac74){return function(_0x7e665d){if(_0x7e665d){var _0x471e55=_0x7e665d['count'],_0x482d7d=_0x16ac74[_0xb48d('0x28')],_0x3dd734=_0x16ac74['offset']+_0x16ac74[_0xb48d('0x29')],_0x532a61;if(_0x3dd734>=_0x471e55){_0x3dd734=_0x471e55;_0x532a61=0xc8;}else{_0x532a61=0xce;}_0x51bc3a[_0xb48d('0x27')](_0x532a61);return _0x51bc3a[_0xb48d('0x2a')](_0xb48d('0x2b'),_0x482d7d+'-'+_0x3dd734+'/'+_0x471e55)[_0xb48d('0x2c')](_0x7e665d);}return null;};}function patchUpdates(_0x4ded46){return function(_0x2f93a5){try{jsonpatch[_0xb48d('0x2d')](_0x2f93a5,_0x4ded46,!![]);}catch(_0x412b0a){return BPromise[_0xb48d('0x2e')](_0x412b0a);}return _0x2f93a5[_0xb48d('0x2f')]();};}function saveUpdates(_0x44cea8,_0x3ca942){return function(_0x1c8d5c){if(_0x1c8d5c){return _0x1c8d5c['update'](_0x44cea8)[_0xb48d('0x30')](function(_0x5ddb92){return _0x5ddb92;});}return null;};}function removeEntity(_0x1919d6,_0x4239e6){return function(_0x987e53){if(_0x987e53){return _0x987e53['destroy']()[_0xb48d('0x30')](function(){_0x1919d6['status'](0xcc)[_0xb48d('0x31')]();});}};}function handleEntityNotFound(_0x28435f,_0x44c7e7){return function(_0x151374){if(!_0x151374){_0x28435f[_0xb48d('0x26')](0x194);}return _0x151374;};}function handleError(_0x4e6e0b,_0x5a68a9){_0x5a68a9=_0x5a68a9||0x1f4;return function(_0x298e28){logger[_0xb48d('0x22')](_0x298e28[_0xb48d('0x32')]);if(_0x298e28['name']){delete _0x298e28['name'];}_0x4e6e0b[_0xb48d('0x27')](_0x5a68a9)['send'](_0x298e28);};}exports[_0xb48d('0x33')]=function(_0x3f6a7f,_0x48c8b4){var _0x1f5a44={},_0x2ec08c={},_0x15a79d={'count':0x0,'rows':[]};var _0x1d1322=_[_0xb48d('0x34')](db['FaxMessage'][_0xb48d('0x35')],function(_0x35f3bc){return{'name':_0x35f3bc[_0xb48d('0x36')],'type':_0x35f3bc[_0xb48d('0x37')][_0xb48d('0x38')]};});_0x2ec08c[_0xb48d('0x39')]=_[_0xb48d('0x34')](_0x1d1322,_0xb48d('0x3a'));_0x2ec08c['query']=_[_0xb48d('0x3b')](_0x3f6a7f[_0xb48d('0x3c')]);_0x2ec08c[_0xb48d('0x3d')]=_['intersection'](_0x2ec08c['model'],_0x2ec08c[_0xb48d('0x3c')]);_0x1f5a44[_0xb48d('0x3e')]=_[_0xb48d('0x3f')](_0x2ec08c[_0xb48d('0x39')],qs[_0xb48d('0x40')](_0x3f6a7f[_0xb48d('0x3c')]['fields']));_0x1f5a44[_0xb48d('0x3e')]=_0x1f5a44[_0xb48d('0x3e')][_0xb48d('0x41')]?_0x1f5a44[_0xb48d('0x3e')]:_0x2ec08c[_0xb48d('0x39')];if(!_0x3f6a7f['query']['hasOwnProperty'](_0xb48d('0x42'))){_0x1f5a44[_0xb48d('0x29')]=qs['limit'](_0x3f6a7f['query'][_0xb48d('0x29')]);_0x1f5a44[_0xb48d('0x28')]=qs[_0xb48d('0x28')](_0x3f6a7f[_0xb48d('0x3c')][_0xb48d('0x28')]);}_0x1f5a44[_0xb48d('0x43')]=qs[_0xb48d('0x44')](_0x3f6a7f[_0xb48d('0x3c')]['sort']);_0x1f5a44['where']=qs[_0xb48d('0x3d')](_[_0xb48d('0x45')](_0x3f6a7f[_0xb48d('0x3c')],_0x2ec08c['filters']),_0x1d1322);if(_0x3f6a7f[_0xb48d('0x3c')][_0xb48d('0x46')]){_0x1f5a44['where']=_[_0xb48d('0x47')](_0x1f5a44[_0xb48d('0x48')],{'$or':_[_0xb48d('0x34')](_0x1d1322,function(_0x162c97){if(_0x162c97[_0xb48d('0x37')]!=='VIRTUAL'){var _0x432fa3={};_0x432fa3[_0x162c97[_0xb48d('0x3a')]]={'$like':'%'+_0x3f6a7f[_0xb48d('0x3c')][_0xb48d('0x46')]+'%'};return _0x432fa3;}})});}_0x1f5a44=_[_0xb48d('0x47')]({},_0x1f5a44,_0x3f6a7f[_0xb48d('0x49')]);var _0x402f23={'where':_0x1f5a44[_0xb48d('0x48')]};return db[_0xb48d('0x4a')][_0xb48d('0x4b')](_0x402f23)[_0xb48d('0x30')](function(_0x9a5a69){_0x15a79d[_0xb48d('0x4b')]=_0x9a5a69;if(_0x3f6a7f['query'][_0xb48d('0x4c')]){_0x1f5a44[_0xb48d('0x4d')]=[{'all':!![]}];}return db[_0xb48d('0x4a')]['findAll'](_0x1f5a44);})[_0xb48d('0x30')](function(_0x26bb98){_0x15a79d[_0xb48d('0x4e')]=_0x26bb98;return _0x15a79d;})[_0xb48d('0x30')](respondWithFilteredResult(_0x48c8b4,_0x1f5a44))[_0xb48d('0x4f')](handleError(_0x48c8b4,null));};exports[_0xb48d('0x50')]=function(_0x4d71c1,_0x466ef5){var _0x265e4e={'raw':!![],'where':{'id':_0x4d71c1['params']['id']}},_0x503b78={};_0x503b78['model']=_['keys'](db[_0xb48d('0x4a')][_0xb48d('0x35')]);_0x503b78[_0xb48d('0x3c')]=_[_0xb48d('0x3b')](_0x4d71c1['query']);_0x503b78[_0xb48d('0x3d')]=_[_0xb48d('0x3f')](_0x503b78[_0xb48d('0x39')],_0x503b78['query']);_0x265e4e[_0xb48d('0x3e')]=_[_0xb48d('0x3f')](_0x503b78[_0xb48d('0x39')],qs['fields'](_0x4d71c1['query'][_0xb48d('0x40')]));_0x265e4e[_0xb48d('0x3e')]=_0x265e4e[_0xb48d('0x3e')][_0xb48d('0x41')]?_0x265e4e[_0xb48d('0x3e')]:_0x503b78['model'];if(_0x4d71c1[_0xb48d('0x3c')][_0xb48d('0x4c')]){_0x265e4e[_0xb48d('0x4d')]=[{'all':!![]}];}_0x265e4e=_[_0xb48d('0x47')]({},_0x265e4e,_0x4d71c1[_0xb48d('0x49')]);return db[_0xb48d('0x4a')][_0xb48d('0x51')](_0x265e4e)['then'](handleEntityNotFound(_0x466ef5,null))['then'](respondWithResult(_0x466ef5,null))[_0xb48d('0x4f')](handleError(_0x466ef5,null));};exports[_0xb48d('0x52')]=function(_0x3052c8,_0x4e23e8){if(_0x3052c8[_0xb48d('0x53')]['id']){delete _0x3052c8['body']['id'];}return db[_0xb48d('0x4a')][_0xb48d('0x51')]({'where':{'id':_0x3052c8[_0xb48d('0x54')]['id']}})['then'](handleEntityNotFound(_0x4e23e8,null))[_0xb48d('0x30')](saveUpdates(_0x3052c8['body'],null))[_0xb48d('0x30')](respondWithResult(_0x4e23e8,null))[_0xb48d('0x4f')](handleError(_0x4e23e8,null));};exports[_0xb48d('0x55')]=function(_0x9feea7,_0x488ef5){return db[_0xb48d('0x4a')][_0xb48d('0x51')]({'where':{'id':_0x9feea7[_0xb48d('0x54')]['id']}})[_0xb48d('0x30')](handleEntityNotFound(_0x488ef5,null))[_0xb48d('0x30')](removeEntity(_0x488ef5,null))['catch'](handleError(_0x488ef5,null));};exports[_0xb48d('0x56')]=function(_0x1a9597,_0x406cef){return db[_0xb48d('0x4a')][_0xb48d('0x56')]()[_0xb48d('0x30')](respondWithResult(_0x406cef,null))[_0xb48d('0x4f')](handleError(_0x406cef,null));};var interaction_log=require('../../config/logger')('fax-interactions');exports['accept']=function(_0x3f9262,_0x158f56,_0x18f2e5){var _0x13868b={'channel':_0xb48d('0x57')};if(_0x3f9262['body']['id']){delete _0x3f9262[_0xb48d('0x53')]['id'];}_0x3f9262['body'][_0xb48d('0x58')]=!![];_0x3f9262[_0xb48d('0x53')][_0xb48d('0x59')]=moment()[_0xb48d('0x5a')](_0xb48d('0x5b'));_0x3f9262[_0xb48d('0x53')][_0xb48d('0x5c')]=_0x3f9262[_0xb48d('0x53')][_0xb48d('0x5c')]||_0x3f9262[_0xb48d('0x5d')]['id'];return db[_0xb48d('0x4a')]['find']({'where':{'id':_0x3f9262[_0xb48d('0x54')]['id'],'UserId':null},'include':[{'model':db[_0xb48d('0x5e')],'as':_0xb48d('0x5f')}]})[_0xb48d('0x30')](handleEntityNotFound(_0x158f56,null))[_0xb48d('0x30')](saveUpdates(_0x3f9262[_0xb48d('0x53')],null))[_0xb48d('0x30')](function(_0x1ca2a3){if(_0x1ca2a3){_0x13868b['message']=_0x1ca2a3[_0xb48d('0x60')]({'plain':!![]});return db['FaxInteraction'][_0xb48d('0x51')]({'where':{'id':_0x1ca2a3[_0xb48d('0x61')]}});}return null;})[_0xb48d('0x30')](handleEntityNotFound(_0x158f56,null))[_0xb48d('0x30')](function(_0x406300){if(_0x406300){return _0x406300[_0xb48d('0x52')]({'UserId':_0x3f9262[_0xb48d('0x53')]['UserId'],'read1stAt':_['isNil'](_0x406300[_0xb48d('0x62')])?moment()[_0xb48d('0x5a')](_0xb48d('0x5b')):undefined});}return null;})[_0xb48d('0x30')](function(_0xb0bf83){if(_0xb0bf83){_0x13868b[_0xb48d('0x63')]=_0xb0bf83[_0xb48d('0x60')]({'plain':!![]});interaction_log[_0xb48d('0x1e')](_0xb48d('0x64'),_0x3f9262[_0xb48d('0x5d')]['id'],_0x3f9262[_0xb48d('0x5d')][_0xb48d('0x3a')],_0x3f9262[_0xb48d('0x5d')]['role'],_0x13868b['interaction']['id'],_0x3f9262[_0xb48d('0x53')]?JSON[_0xb48d('0x21')](_0x3f9262[_0xb48d('0x53')]):_0xb48d('0x65'));return respondWithRpcPromise(_0xb48d('0x66'),'acceptMessage',_0x13868b);}return null;})[_0xb48d('0x30')](function(_0x37055a){if(_0x37055a){if(_0x3f9262[_0xb48d('0x53')][_0xb48d('0x67')]){_0x13868b[_0xb48d('0x24')][_0xb48d('0x68')]=util[_0xb48d('0x5a')](_0xb48d('0x69'),_0x3f9262['user'][_0xb48d('0x3a')]);_0x13868b['message'][_0xb48d('0x6a')]=_0x13868b[_0xb48d('0x6a')];_0x13868b[_0xb48d('0x24')][_0xb48d('0x6b')]=_0xb48d('0x6c');return respondWithRpcPromise(_0xb48d('0x6d'),'EventManager',{'event':_0xb48d('0x6e'),'message':_0x13868b[_0xb48d('0x24')]},client9002)[_0xb48d('0x30')](function(){return _0x13868b;});}return _0x13868b;}return null;})['then'](respondWithResult(_0x158f56,null))[_0xb48d('0x4f')](handleError(_0x158f56,null));};var interaction_log=require(_0xb48d('0x6f'))(_0xb48d('0x70'));exports[_0xb48d('0x2e')]=function(_0x327643,_0x25e711,_0x48fe3c){var _0x50a2fa={'agent':{},'channel':'fax'};if(_0x327643[_0xb48d('0x53')]['id']){delete _0x327643[_0xb48d('0x53')]['id'];}_0x327643[_0xb48d('0x53')][_0xb48d('0x5c')]=_0x327643[_0xb48d('0x53')][_0xb48d('0x5c')]||_0x327643[_0xb48d('0x5d')]['id'];_0x50a2fa[_0xb48d('0x71')]['id']=_0x327643['body'][_0xb48d('0x5c')];return db[_0xb48d('0x4a')][_0xb48d('0x51')]({'where':{'id':_0x327643[_0xb48d('0x54')]['id'],'UserId':null}})[_0xb48d('0x30')](handleEntityNotFound(_0x25e711,null))[_0xb48d('0x30')](function(_0x579a5d){if(_0x579a5d){_0x50a2fa[_0xb48d('0x24')]=_0x579a5d[_0xb48d('0x60')]({'plain':!![]});return db[_0xb48d('0x72')][_0xb48d('0x51')]({'where':{'id':_0x579a5d[_0xb48d('0x61')]}});}return null;})['then'](handleEntityNotFound(_0x25e711,null))[_0xb48d('0x30')](function(_0x4572e7){if(_0x4572e7){_0x50a2fa['interaction']=_0x4572e7['get']({'plain':!![]});interaction_log[_0xb48d('0x1e')](_0xb48d('0x73'),_0x327643[_0xb48d('0x5d')]['id'],_0x327643[_0xb48d('0x5d')][_0xb48d('0x3a')],_0x327643[_0xb48d('0x5d')][_0xb48d('0x74')],_0x50a2fa[_0xb48d('0x63')]['id'],_0x327643['body']?JSON['stringify'](_0x327643[_0xb48d('0x53')]):_0xb48d('0x65'));return respondWithRpcPromise(_0xb48d('0x75'),_0xb48d('0x76'),_0x50a2fa);}return null;})[_0xb48d('0x30')](function(_0x4586b5){if(_0x4586b5){_0x4586b5[_0xb48d('0x24')]['interface']=util[_0xb48d('0x5a')]('SIP/%s',_0x327643['user']['name']);_0x4586b5[_0xb48d('0x24')][_0xb48d('0x6a')]=_0x50a2fa[_0xb48d('0x6a')];_0x4586b5[_0xb48d('0x24')][_0xb48d('0x6b')]=_0xb48d('0x2e');respondWithRpcPromise(_0xb48d('0x6d'),_0xb48d('0x6d'),{'event':'rejectmessage','message':_0x4586b5[_0xb48d('0x24')]},client9002);return _0x50a2fa;}return null;})[_0xb48d('0x30')](respondWithResult(_0x25e711,null))['catch'](handleError(_0x25e711,null));};exports[_0xb48d('0x77')]=function(_0x4d6d2d,_0x46154a){var _0x4021be;return db[_0xb48d('0x4a')][_0xb48d('0x77')](_0x4d6d2d[_0xb48d('0x53')],{})[_0xb48d('0x30')](function(_0x3853a6){_0x4021be=_0x3853a6;return db[_0xb48d('0x5e')][_0xb48d('0x78')]({'where':{'id':_0x4021be[_0xb48d('0x79')]}});})[_0xb48d('0x30')](function(_0x2191c2){if(_['isNil'](_0x2191c2)){return;}else{_0x4021be[_0xb48d('0x57')]=_0x2191c2[_0xb48d('0x57')];return db[_0xb48d('0x7a')][_0xb48d('0x78')]({'where':{'id':_0x4021be['AttachmentId']}});}})[_0xb48d('0x30')](function(_0x44e18c){return respondWithRpcPromise(_0xb48d('0x7b'),_0xb48d('0x7b'),{'FaxAccountId':_[_0xb48d('0x7c')](_0x4d6d2d[_0xb48d('0x53')])?undefined:_0x4d6d2d[_0xb48d('0x53')][_0xb48d('0x7d')],'path':_['isNil'](_0x44e18c)?undefined:util[_0xb48d('0x5a')](_0xb48d('0x7e'),_0x44e18c[_0xb48d('0x7f')]),'fax':_[_0xb48d('0x7c')](_0x4021be[_0xb48d('0x57')])?undefined:_0x4021be[_0xb48d('0x57')],'AttachmentId':_0x4021be[_0xb48d('0x80')]},client9002);})[_0xb48d('0x30')](respondWithResult(_0x46154a,0xc9))[_0xb48d('0x4f')](handleError(_0x46154a,null));};exports[_0xb48d('0x81')]=function(_0x47fbee,_0x13863f){var _0x42e777=path[_0xb48d('0x82')](config['root'],'server',_0xb48d('0x83'),_0xb48d('0x84'));return db[_0xb48d('0x4a')][_0xb48d('0x51')]({'where':{'id':_0x47fbee[_0xb48d('0x54')]['id']},'include':[{'model':db['Attachment'],'as':_0xb48d('0x7a')}]})['then'](handleEntityNotFound(_0x13863f,null))[_0xb48d('0x30')](function(_0x46588e){if(_0x46588e){return _0x13863f['download'](path[_0xb48d('0x82')](_0x42e777,_0x46588e[_0xb48d('0x7a')][_0xb48d('0x7f')]));}})['catch'](handleError(_0x13863f,null));};
\ No newline at end of file
+var _0xf0c9=['download','root','files','attachments','Attachment','join','util','path','ioredis','../../components/parsers/qs','../../config/logger','../../config/environment','redis','defaults','localhost','register','jayson/promise','client','http','fax-interactions','then','info','FaxMessage,\x20%s,\x20%s','debug','FaxMessage,\x20%s,\x20%s,\x20%s','request\x20sent','error','code','message','catch','json','undefined','count','offset','status','set','Content-Range','update','end','sendStatus','stack','name','send','FaxMessage','fieldName','type','key','model','query','filters','intersection','attributes','fields','hasOwnProperty','limit','order','sort','filter','where','merge','map','VIRTUAL','options','includeAll','include','findAll','show','params','keys','rawAttributes','length','find','body','destroy','describe','sms','acceptMessage','fax','reject','UserId','user','agent','get','FaxInteraction','[FAXMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','stringify','null','RejectMessage','rejectMessage','ContactId','sequelize','QueryTypes','SELECT','contact','User','fullname','email','internal','interface','format','SIP/%s','channel','motionChannel','EventManager','rejectmessage','create','CmContact','findOne','isNil','AttachmentId','SendFax','FaxAccountId','/var/opt/motion2/server/files/attachments/%s','basename'];(function(_0x596284,_0x1cd02b){var _0x5313c6=function(_0x77db49){while(--_0x77db49){_0x596284['push'](_0x596284['shift']());}};_0x5313c6(++_0x1cd02b);}(_0xf0c9,0x15f));var _0x9f0c=function(_0x317c38,_0x9d154d){_0x317c38=_0x317c38-0x0;var _0x304c05=_0xf0c9[_0x317c38];return _0x304c05;};'use strict';var util=require(_0x9f0c('0x0'));var path=require(_0x9f0c('0x1'));var _=require('lodash');var Redis=require(_0x9f0c('0x2'));var interactionService=require('../../components/interaction/service');var qs=require(_0x9f0c('0x3'));var logger=require(_0x9f0c('0x4'))('api');var config=require(_0x9f0c('0x5'));var db=require('../../mysqldb')['db'];config[_0x9f0c('0x6')]=_[_0x9f0c('0x7')](config[_0x9f0c('0x6')],{'host':_0x9f0c('0x8'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x9f0c('0x6')]));require('./faxMessage.socket')[_0x9f0c('0x9')](socket);var jayson=require(_0x9f0c('0xa'));var client=jayson[_0x9f0c('0xb')]['http']({'port':0x232c});var client9002=jayson['client'][_0x9f0c('0xc')]({'port':0x232a});var interaction_log=require(_0x9f0c('0x4'))(_0x9f0c('0xd'));function respondWithRpcPromise(_0x3fa6cb,_0x3e87f0,_0x353d84,_0x26a9a6){return new Promise(function(_0x1e8a02,_0x3694a9){var _0x1694b1=_0x26a9a6||client;return _0x1694b1['request'](_0x3fa6cb,_0x353d84)[_0x9f0c('0xe')](function(_0x471d91){logger[_0x9f0c('0xf')](_0x9f0c('0x10'),_0x3e87f0,'request\x20sent');logger[_0x9f0c('0x11')](_0x9f0c('0x12'),_0x3e87f0,_0x9f0c('0x13'),JSON['stringify'](_0x471d91));if(_0x471d91['error']){if(_0x471d91[_0x9f0c('0x14')][_0x9f0c('0x15')]===0x1f4){logger[_0x9f0c('0x14')](_0x9f0c('0x10'),_0x3e87f0,_0x471d91[_0x9f0c('0x14')][_0x9f0c('0x16')]);return _0x3694a9(_0x471d91[_0x9f0c('0x14')][_0x9f0c('0x16')]);}logger[_0x9f0c('0x14')](_0x9f0c('0x10'),_0x3e87f0,_0x471d91[_0x9f0c('0x14')][_0x9f0c('0x16')]);return _0x1e8a02(_0x471d91[_0x9f0c('0x14')][_0x9f0c('0x16')]);}else{logger[_0x9f0c('0xf')](_0x9f0c('0x10'),_0x3e87f0,_0x9f0c('0x13'));_0x1e8a02(_0x471d91['result'][_0x9f0c('0x16')]);}})[_0x9f0c('0x17')](function(_0x473795){logger['error'](_0x9f0c('0x10'),_0x3e87f0,_0x473795);_0x3694a9(_0x473795);});});}function respondWithResult(_0x8d0a5a,_0x589793){_0x589793=_0x589793||0xc8;return function(_0x4e2974){if(_0x4e2974){return _0x8d0a5a['status'](_0x589793)[_0x9f0c('0x18')](_0x4e2974);}};}function respondWithFilteredResult(_0x125265,_0x597b86){return function(_0x4f1eec){if(_0x4f1eec){var _0x218256=typeof _0x597b86['offset']===_0x9f0c('0x19')&&typeof _0x597b86['limit']===_0x9f0c('0x19');var _0x5a8a5d=_0x4f1eec[_0x9f0c('0x1a')];var _0x3509d4=_0x218256?0x0:_0x597b86[_0x9f0c('0x1b')];var _0x4b51df=_0x218256?_0x4f1eec[_0x9f0c('0x1a')]:_0x597b86['offset']+_0x597b86['limit'];var _0x27ac6e;if(_0x4b51df>=_0x5a8a5d){_0x4b51df=_0x5a8a5d;_0x27ac6e=0xc8;}else{_0x27ac6e=0xce;}_0x125265[_0x9f0c('0x1c')](_0x27ac6e);return _0x125265[_0x9f0c('0x1d')](_0x9f0c('0x1e'),_0x3509d4+'-'+_0x4b51df+'/'+_0x5a8a5d)[_0x9f0c('0x18')](_0x4f1eec);}return null;};}function saveUpdates(_0x3a44c2){return function(_0x2e80e4){if(_0x2e80e4){return _0x2e80e4[_0x9f0c('0x1f')](_0x3a44c2)[_0x9f0c('0xe')](function(_0x986138){return _0x986138;});}return null;};}function removeEntity(_0x5221ce){return function(_0x22772f){if(_0x22772f){return _0x22772f['destroy']()[_0x9f0c('0xe')](function(){_0x5221ce['status'](0xcc)[_0x9f0c('0x20')]();});}};}function handleEntityNotFound(_0x515065){return function(_0x327f13){if(!_0x327f13){_0x515065[_0x9f0c('0x21')](0x194);}return _0x327f13;};}function handleError(_0x3db569,_0x20b5e8){_0x20b5e8=_0x20b5e8||0x1f4;return function(_0x5635e2){logger[_0x9f0c('0x14')](_0x5635e2[_0x9f0c('0x22')]);if(_0x5635e2[_0x9f0c('0x23')]){delete _0x5635e2[_0x9f0c('0x23')];}_0x3db569[_0x9f0c('0x1c')](_0x20b5e8)[_0x9f0c('0x24')](_0x5635e2);};}exports['index']=function(_0x49ed54,_0x5cb4f9){var _0x4484a4={},_0x590ae9={},_0x5c77bb={'count':0x0,'rows':[]};var _0x33beb7=_['map'](db[_0x9f0c('0x25')]['rawAttributes'],function(_0x10d378){return{'name':_0x10d378[_0x9f0c('0x26')],'type':_0x10d378[_0x9f0c('0x27')][_0x9f0c('0x28')]};});_0x590ae9[_0x9f0c('0x29')]=_['map'](_0x33beb7,_0x9f0c('0x23'));_0x590ae9[_0x9f0c('0x2a')]=_['keys'](_0x49ed54[_0x9f0c('0x2a')]);_0x590ae9[_0x9f0c('0x2b')]=_[_0x9f0c('0x2c')](_0x590ae9[_0x9f0c('0x29')],_0x590ae9[_0x9f0c('0x2a')]);_0x4484a4[_0x9f0c('0x2d')]=_[_0x9f0c('0x2c')](_0x590ae9['model'],qs[_0x9f0c('0x2e')](_0x49ed54[_0x9f0c('0x2a')][_0x9f0c('0x2e')]));_0x4484a4[_0x9f0c('0x2d')]=_0x4484a4['attributes']['length']?_0x4484a4[_0x9f0c('0x2d')]:_0x590ae9[_0x9f0c('0x29')];if(!_0x49ed54['query'][_0x9f0c('0x2f')]('nolimit')){_0x4484a4[_0x9f0c('0x30')]=qs[_0x9f0c('0x30')](_0x49ed54['query'][_0x9f0c('0x30')]);_0x4484a4[_0x9f0c('0x1b')]=qs['offset'](_0x49ed54[_0x9f0c('0x2a')][_0x9f0c('0x1b')]);}_0x4484a4[_0x9f0c('0x31')]=qs[_0x9f0c('0x32')](_0x49ed54[_0x9f0c('0x2a')][_0x9f0c('0x32')]);_0x4484a4['where']=qs['filters'](_['pick'](_0x49ed54[_0x9f0c('0x2a')],_0x590ae9[_0x9f0c('0x2b')]),_0x33beb7);if(_0x49ed54[_0x9f0c('0x2a')][_0x9f0c('0x33')]){_0x4484a4[_0x9f0c('0x34')]=_[_0x9f0c('0x35')](_0x4484a4[_0x9f0c('0x34')],{'$or':_[_0x9f0c('0x36')](_0x33beb7,function(_0x32d8f8){if(_0x32d8f8[_0x9f0c('0x27')]!==_0x9f0c('0x37')){var _0x5d74c0={};_0x5d74c0[_0x32d8f8['name']]={'$like':'%'+_0x49ed54[_0x9f0c('0x2a')][_0x9f0c('0x33')]+'%'};return _0x5d74c0;}})});}_0x4484a4=_[_0x9f0c('0x35')]({},_0x4484a4,_0x49ed54[_0x9f0c('0x38')]);var _0x10ebe3={'where':_0x4484a4[_0x9f0c('0x34')]};return db[_0x9f0c('0x25')][_0x9f0c('0x1a')](_0x10ebe3)['then'](function(_0x459214){_0x5c77bb['count']=_0x459214;if(_0x49ed54[_0x9f0c('0x2a')][_0x9f0c('0x39')]){_0x4484a4[_0x9f0c('0x3a')]=[{'all':!![]}];}return db['FaxMessage'][_0x9f0c('0x3b')](_0x4484a4);})[_0x9f0c('0xe')](function(_0x12a939){_0x5c77bb['rows']=_0x12a939;return _0x5c77bb;})[_0x9f0c('0xe')](respondWithFilteredResult(_0x5cb4f9,_0x4484a4))['catch'](handleError(_0x5cb4f9,null));};exports[_0x9f0c('0x3c')]=function(_0x2f0f88,_0x242cf7){var _0xfe3c00={'raw':!![],'where':{'id':_0x2f0f88[_0x9f0c('0x3d')]['id']}},_0x38b8f7={};_0x38b8f7[_0x9f0c('0x29')]=_[_0x9f0c('0x3e')](db['FaxMessage'][_0x9f0c('0x3f')]);_0x38b8f7['query']=_[_0x9f0c('0x3e')](_0x2f0f88[_0x9f0c('0x2a')]);_0x38b8f7[_0x9f0c('0x2b')]=_[_0x9f0c('0x2c')](_0x38b8f7[_0x9f0c('0x29')],_0x38b8f7[_0x9f0c('0x2a')]);_0xfe3c00[_0x9f0c('0x2d')]=_[_0x9f0c('0x2c')](_0x38b8f7['model'],qs['fields'](_0x2f0f88[_0x9f0c('0x2a')]['fields']));_0xfe3c00[_0x9f0c('0x2d')]=_0xfe3c00[_0x9f0c('0x2d')][_0x9f0c('0x40')]?_0xfe3c00[_0x9f0c('0x2d')]:_0x38b8f7[_0x9f0c('0x29')];if(_0x2f0f88[_0x9f0c('0x2a')][_0x9f0c('0x39')]){_0xfe3c00[_0x9f0c('0x3a')]=[{'all':!![]}];}_0xfe3c00=_[_0x9f0c('0x35')]({},_0xfe3c00,_0x2f0f88[_0x9f0c('0x38')]);return db[_0x9f0c('0x25')][_0x9f0c('0x41')](_0xfe3c00)[_0x9f0c('0xe')](handleEntityNotFound(_0x242cf7,null))['then'](respondWithResult(_0x242cf7,null))[_0x9f0c('0x17')](handleError(_0x242cf7,null));};exports['update']=function(_0x26a95a,_0x20cf3d){if(_0x26a95a[_0x9f0c('0x42')]['id']){delete _0x26a95a['body']['id'];}return db[_0x9f0c('0x25')][_0x9f0c('0x41')]({'where':{'id':_0x26a95a['params']['id']}})[_0x9f0c('0xe')](handleEntityNotFound(_0x20cf3d,null))['then'](saveUpdates(_0x26a95a[_0x9f0c('0x42')],null))[_0x9f0c('0xe')](respondWithResult(_0x20cf3d,null))[_0x9f0c('0x17')](handleError(_0x20cf3d,null));};exports[_0x9f0c('0x43')]=function(_0x5efc5c,_0x21e4ce){return db[_0x9f0c('0x25')][_0x9f0c('0x41')]({'where':{'id':_0x5efc5c[_0x9f0c('0x3d')]['id']}})[_0x9f0c('0xe')](handleEntityNotFound(_0x21e4ce,null))[_0x9f0c('0xe')](removeEntity(_0x21e4ce,null))[_0x9f0c('0x17')](handleError(_0x21e4ce,null));};exports[_0x9f0c('0x44')]=function(_0x3a4a3a,_0x41cf25){return db[_0x9f0c('0x25')]['describe']()[_0x9f0c('0xe')](respondWithResult(_0x41cf25,null))[_0x9f0c('0x17')](handleError(_0x41cf25,null));};exports['accept']=function(_0x43161c,_0x2f575b){var _0x3cd93a=_0x9f0c('0x45');return interactionService[_0x9f0c('0x46')](_0x43161c,_0x3cd93a)[_0x9f0c('0xe')](respondWithResult(_0x2f575b,null))[_0x9f0c('0x17')](handleError(_0x2f575b,null));};exports['accept']=function(_0x4389ed,_0x2a8659){var _0x4efd2d=_0x9f0c('0x47');return interactionService['acceptMessage'](_0x4389ed,_0x4efd2d)[_0x9f0c('0xe')](respondWithResult(_0x2a8659,null))[_0x9f0c('0x17')](handleError(_0x2a8659,null));};exports[_0x9f0c('0x48')]=function(_0xdff421,_0x21df33){var _0x348bb8={'agent':{},'channel':_0x9f0c('0x47')};if(_0xdff421[_0x9f0c('0x42')]['id']){delete _0xdff421['body']['id'];}_0xdff421[_0x9f0c('0x42')][_0x9f0c('0x49')]=_0xdff421[_0x9f0c('0x42')]['UserId']||_0xdff421[_0x9f0c('0x4a')]['id'];_0x348bb8[_0x9f0c('0x4b')]['id']=_0xdff421[_0x9f0c('0x42')][_0x9f0c('0x49')];return db[_0x9f0c('0x25')][_0x9f0c('0x41')]({'where':{'id':_0xdff421[_0x9f0c('0x3d')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x21df33,null))['then'](function(_0x17a738){if(_0x17a738){_0x348bb8[_0x9f0c('0x16')]=_0x17a738[_0x9f0c('0x4c')]({'plain':!![]});return db[_0x9f0c('0x4d')][_0x9f0c('0x41')]({'where':{'id':_0x17a738['FaxInteractionId']}});}return null;})[_0x9f0c('0xe')](handleEntityNotFound(_0x21df33,null))[_0x9f0c('0xe')](function(_0x435c03){if(_0x435c03){_0x348bb8['interaction']=_0x435c03[_0x9f0c('0x4c')]({'plain':!![]});interaction_log[_0x9f0c('0xf')](_0x9f0c('0x4e'),_0xdff421[_0x9f0c('0x4a')]['id'],_0xdff421[_0x9f0c('0x4a')][_0x9f0c('0x23')],_0xdff421['user'][_0x9f0c('0x4f')],_0x348bb8['interaction']['id'],_0xdff421[_0x9f0c('0x42')]?JSON[_0x9f0c('0x50')](_0xdff421['body']):_0x9f0c('0x51'));return respondWithRpcPromise(_0x9f0c('0x52'),_0x9f0c('0x53'),_0x348bb8);}return null;})[_0x9f0c('0xe')](function(_0x2d8e52){var _0x4a4637='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x2d8e52[_0x9f0c('0x16')][_0x9f0c('0x54')];return db[_0x9f0c('0x55')]['query'](_0x4a4637,{'type':db['Sequelize'][_0x9f0c('0x56')][_0x9f0c('0x57')],'raw':!![]})[_0x9f0c('0xe')](function(_0x4394eb){return _0x4394eb;});})[_0x9f0c('0xe')](function(_0x192e0e){if(_0x192e0e){_0x348bb8['message'][_0x9f0c('0x58')]=_0x192e0e[0x0];if(!_0xdff421[_0x9f0c('0x42')][_0x9f0c('0x49')])return;return db[_0x9f0c('0x59')][_0x9f0c('0x41')]({'where':{'id':_0xdff421[_0x9f0c('0x42')][_0x9f0c('0x49')],'role':_0x9f0c('0x4b')},'attributes':['id',_0x9f0c('0x23'),_0x9f0c('0x5a'),_0x9f0c('0x5b'),_0x9f0c('0x5c')],'raw':!![]});}return null;})[_0x9f0c('0xe')](function(_0x142db4){if(!_0x142db4)return null;_0x348bb8['message']['agent']=_0x142db4;return _0x348bb8;})[_0x9f0c('0xe')](function(_0x45ac82){if(_0x45ac82){_0x45ac82[_0x9f0c('0x16')][_0x9f0c('0x5d')]=util[_0x9f0c('0x5e')](_0x9f0c('0x5f'),_0xdff421[_0x9f0c('0x4a')][_0x9f0c('0x23')]);_0x45ac82['message'][_0x9f0c('0x60')]=_0x348bb8['channel'];_0x45ac82[_0x9f0c('0x16')][_0x9f0c('0x61')]=_0x348bb8['channel'];_0x45ac82['message']['event']=_0x9f0c('0x48');respondWithRpcPromise(_0x9f0c('0x62'),'EventManager',{'event':_0x9f0c('0x63'),'message':_0x45ac82[_0x9f0c('0x16')]},client9002);return _0x348bb8;}return null;})['then'](respondWithResult(_0x21df33,null))['catch'](handleError(_0x21df33,null));};exports[_0x9f0c('0x64')]=function(_0xc06307,_0x5cf07e){var _0x222525;return db[_0x9f0c('0x25')]['create'](_0xc06307[_0x9f0c('0x42')],{})[_0x9f0c('0xe')](function(_0x45d208){_0x222525=_0x45d208;return db[_0x9f0c('0x65')][_0x9f0c('0x66')]({'where':{'id':_0x222525['ContactId']}});})['then'](function(_0xbc0f5b){if(_[_0x9f0c('0x67')](_0xbc0f5b)){return;}else{_0x222525[_0x9f0c('0x47')]=_0xbc0f5b[_0x9f0c('0x47')];return db['Attachment'][_0x9f0c('0x66')]({'where':{'id':_0x222525[_0x9f0c('0x68')]}});}})[_0x9f0c('0xe')](function(_0x477889){return respondWithRpcPromise('SendFax',_0x9f0c('0x69'),{'FaxAccountId':_[_0x9f0c('0x67')](_0xc06307[_0x9f0c('0x42')])?undefined:_0xc06307[_0x9f0c('0x42')][_0x9f0c('0x6a')],'path':_[_0x9f0c('0x67')](_0x477889)?undefined:util[_0x9f0c('0x5e')](_0x9f0c('0x6b'),_0x477889[_0x9f0c('0x6c')]),'fax':_[_0x9f0c('0x67')](_0x222525[_0x9f0c('0x47')])?undefined:_0x222525[_0x9f0c('0x47')],'AttachmentId':_0x222525[_0x9f0c('0x68')]},client9002);})[_0x9f0c('0xe')](respondWithResult(_0x5cf07e,0xc9))[_0x9f0c('0x17')](handleError(_0x5cf07e,null));};exports[_0x9f0c('0x6d')]=function(_0x16ef9d,_0x11bad7){var _0x4eb1f5=path['join'](config[_0x9f0c('0x6e')],'server',_0x9f0c('0x6f'),_0x9f0c('0x70'));return db['FaxMessage'][_0x9f0c('0x41')]({'where':{'id':_0x16ef9d[_0x9f0c('0x3d')]['id']},'include':[{'model':db[_0x9f0c('0x71')],'as':_0x9f0c('0x71')}]})[_0x9f0c('0xe')](handleEntityNotFound(_0x11bad7,null))['then'](function(_0x5e6f27){if(_0x5e6f27){return _0x11bad7['download'](path[_0x9f0c('0x72')](_0x4eb1f5,_0x5e6f27[_0x9f0c('0x71')][_0x9f0c('0x6c')]));}})[_0x9f0c('0x17')](handleError(_0x11bad7,null));};
\ No newline at end of file