Built motion from commit 092f8824.|2.5.49
[motion2.git] / server / api / openchannelMessage / openchannelMessage.controller.js
index 7850523..492cc6d 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf996=['fast-json-patch','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','defaults','redis','localhost','socket.io-emitter','./openchannelMessage.socket','register','jayson/promise','client','http','request','then','info','OpenchannelMessage,\x20%s,\x20%s','debug','request\x20sent','stringify','error','code','message','result','catch','end','status','count','offset','limit','json','apply','reject','update','destroy','sendStatus','name','send','index','map','OpenchannelMessage','rawAttributes','type','model','query','keys','filters','attributes','fields','length','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','include','findAll','rows','show','params','intersection','options','create','body','describe','openchannel-interactions','accept','openchannel','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','find','CmContact','Contact','get','OpenchannelInteraction','read1stAt','interaction','[OPENCHANNELMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','interface','SIP/%s','channel','EventManager','acceptmessage','agent','[OPENCHANNELMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','event','rejectmessage','html-pdf','eml-format','rimraf'];(function(_0x4d613c,_0x55f220){var _0x301fe3=function(_0x5eec0b){while(--_0x5eec0b){_0x4d613c['push'](_0x4d613c['shift']());}};_0x301fe3(++_0x55f220);}(_0xf996,0x74));var _0x6f99=function(_0x1ec73a,_0x491889){_0x1ec73a=_0x1ec73a-0x0;var _0x2dd506=_0xf996[_0x1ec73a];return _0x2dd506;};'use strict';var pdf=require(_0x6f99('0x0'));var emlformat=require(_0x6f99('0x1'));var rimraf=require(_0x6f99('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x6f99('0x3'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x6f99('0x4'));var Mustache=require(_0x6f99('0x5'));var util=require(_0x6f99('0x6'));var path=require(_0x6f99('0x7'));var sox=require(_0x6f99('0x8'));var csv=require(_0x6f99('0x9'));var ejs=require(_0x6f99('0xa'));var fs=require('fs');var _=require(_0x6f99('0xb'));var squel=require(_0x6f99('0xc'));var crypto=require(_0x6f99('0xd'));var jsforce=require('jsforce');var deskjs=require(_0x6f99('0xe'));var toCsv=require('to-csv');var querystring=require(_0x6f99('0xf'));var Papa=require(_0x6f99('0x10'));var Redis=require(_0x6f99('0x11'));var authService=require(_0x6f99('0x12'));var qs=require(_0x6f99('0x13'));var as=require(_0x6f99('0x14'));var hardwareService=require(_0x6f99('0x15'));var logger=require(_0x6f99('0x16'))(_0x6f99('0x17'));var utils=require('../../config/utils');var config=require(_0x6f99('0x18'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];config['redis']=_[_0x6f99('0x19')](config[_0x6f99('0x1a')],{'host':_0x6f99('0x1b'),'port':0x18eb});var socket=require(_0x6f99('0x1c'))(new Redis(config[_0x6f99('0x1a')]));require(_0x6f99('0x1d'))[_0x6f99('0x1e')](socket);var jayson=require(_0x6f99('0x1f'));var client=jayson[_0x6f99('0x20')][_0x6f99('0x21')]({'port':0x232c});var client9002=jayson[_0x6f99('0x20')][_0x6f99('0x21')]({'port':0x232a});function respondWithRpcPromise(_0x537f3d,_0x293937,_0x2256a9,_0x4a7520){return new BPromise(function(_0x48f025,_0x11336b){var _0x5b3638=_0x4a7520||client;return _0x5b3638[_0x6f99('0x22')](_0x537f3d,_0x2256a9)[_0x6f99('0x23')](function(_0x3bed8d){logger[_0x6f99('0x24')](_0x6f99('0x25'),_0x293937,'request\x20sent');logger[_0x6f99('0x26')]('OpenchannelMessage,\x20%s,\x20%s,\x20%s',_0x293937,_0x6f99('0x27'),JSON[_0x6f99('0x28')](_0x3bed8d));if(_0x3bed8d[_0x6f99('0x29')]){if(_0x3bed8d[_0x6f99('0x29')][_0x6f99('0x2a')]===0x1f4){logger[_0x6f99('0x29')]('OpenchannelMessage,\x20%s,\x20%s',_0x293937,_0x3bed8d['error'][_0x6f99('0x2b')]);return _0x11336b(_0x3bed8d[_0x6f99('0x29')]['message']);}logger['error'](_0x6f99('0x25'),_0x293937,_0x3bed8d[_0x6f99('0x29')][_0x6f99('0x2b')]);return _0x48f025(_0x3bed8d[_0x6f99('0x29')][_0x6f99('0x2b')]);}else{logger[_0x6f99('0x24')](_0x6f99('0x25'),_0x293937,_0x6f99('0x27'));_0x48f025(_0x3bed8d[_0x6f99('0x2c')][_0x6f99('0x2b')]);}})[_0x6f99('0x2d')](function(_0x1f8078){logger[_0x6f99('0x29')](_0x6f99('0x25'),_0x293937,_0x1f8078);_0x11336b(_0x1f8078);});});}function respondWithStatusCode(_0x568ecd,_0x1aff24){_0x1aff24=_0x1aff24||0xcc;return function(_0x201070){if(_0x201070){return _0x568ecd['sendStatus'](_0x1aff24);}return _0x568ecd['status'](_0x1aff24)[_0x6f99('0x2e')]();};}function respondWithResult(_0x306ece,_0x53f045){_0x53f045=_0x53f045||0xc8;return function(_0x16da92){if(_0x16da92){return _0x306ece[_0x6f99('0x2f')](_0x53f045)['json'](_0x16da92);}};}function respondWithFilteredResult(_0x45fe22,_0x3c1012){return function(_0x513519){if(_0x513519){var _0x21eb46=_0x513519[_0x6f99('0x30')],_0x3ef6c5=_0x3c1012[_0x6f99('0x31')],_0x5e10e2=_0x3c1012['offset']+_0x3c1012[_0x6f99('0x32')],_0x459601;if(_0x5e10e2>=_0x21eb46){_0x5e10e2=_0x21eb46;_0x459601=0xc8;}else{_0x459601=0xce;}_0x45fe22[_0x6f99('0x2f')](_0x459601);return _0x45fe22['set']('Content-Range',_0x3ef6c5+'-'+_0x5e10e2+'/'+_0x21eb46)[_0x6f99('0x33')](_0x513519);}return null;};}function patchUpdates(_0x33ab31){return function(_0x10a88d){try{jsonpatch[_0x6f99('0x34')](_0x10a88d,_0x33ab31,!![]);}catch(_0x1dea2c){return BPromise[_0x6f99('0x35')](_0x1dea2c);}return _0x10a88d['save']();};}function saveUpdates(_0x499926,_0x269d9b){return function(_0x338606){if(_0x338606){return _0x338606[_0x6f99('0x36')](_0x499926)[_0x6f99('0x23')](function(_0x1ecffc){return _0x1ecffc;});}return null;};}function removeEntity(_0x3723b4,_0x11f2e2){return function(_0x3f4dba){if(_0x3f4dba){return _0x3f4dba[_0x6f99('0x37')]()[_0x6f99('0x23')](function(){_0x3723b4[_0x6f99('0x2f')](0xcc)['end']();});}};}function handleEntityNotFound(_0xb16b1e,_0x398ae6){return function(_0x1a7c53){if(!_0x1a7c53){_0xb16b1e[_0x6f99('0x38')](0x194);}return _0x1a7c53;};}function handleError(_0x350857,_0x48a1b8){_0x48a1b8=_0x48a1b8||0x1f4;return function(_0xde3f68){logger[_0x6f99('0x29')](_0xde3f68['stack']);if(_0xde3f68[_0x6f99('0x39')]){delete _0xde3f68[_0x6f99('0x39')];}_0x350857[_0x6f99('0x2f')](_0x48a1b8)[_0x6f99('0x3a')](_0xde3f68);};}exports[_0x6f99('0x3b')]=function(_0x3c774b,_0x463249){var _0x344f61={},_0x56e206={},_0x304db7={'count':0x0,'rows':[]};var _0x4d87a1=_[_0x6f99('0x3c')](db[_0x6f99('0x3d')][_0x6f99('0x3e')],function(_0x455ffa){return{'name':_0x455ffa['fieldName'],'type':_0x455ffa[_0x6f99('0x3f')]['key']};});_0x56e206[_0x6f99('0x40')]=_[_0x6f99('0x3c')](_0x4d87a1,_0x6f99('0x39'));_0x56e206[_0x6f99('0x41')]=_[_0x6f99('0x42')](_0x3c774b[_0x6f99('0x41')]);_0x56e206[_0x6f99('0x43')]=_['intersection'](_0x56e206[_0x6f99('0x40')],_0x56e206[_0x6f99('0x41')]);_0x344f61[_0x6f99('0x44')]=_['intersection'](_0x56e206[_0x6f99('0x40')],qs[_0x6f99('0x45')](_0x3c774b[_0x6f99('0x41')][_0x6f99('0x45')]));_0x344f61[_0x6f99('0x44')]=_0x344f61[_0x6f99('0x44')][_0x6f99('0x46')]?_0x344f61[_0x6f99('0x44')]:_0x56e206['model'];if(!_0x3c774b[_0x6f99('0x41')]['hasOwnProperty'](_0x6f99('0x47'))){_0x344f61[_0x6f99('0x32')]=qs['limit'](_0x3c774b[_0x6f99('0x41')][_0x6f99('0x32')]);_0x344f61[_0x6f99('0x31')]=qs[_0x6f99('0x31')](_0x3c774b['query'][_0x6f99('0x31')]);}_0x344f61[_0x6f99('0x48')]=qs[_0x6f99('0x49')](_0x3c774b['query'][_0x6f99('0x49')]);_0x344f61[_0x6f99('0x4a')]=qs[_0x6f99('0x43')](_[_0x6f99('0x4b')](_0x3c774b[_0x6f99('0x41')],_0x56e206[_0x6f99('0x43')]),_0x4d87a1);if(_0x3c774b[_0x6f99('0x41')][_0x6f99('0x4c')]){_0x344f61['where']=_[_0x6f99('0x4d')](_0x344f61['where'],{'$or':_[_0x6f99('0x3c')](_0x4d87a1,function(_0x596066){if(_0x596066[_0x6f99('0x3f')]!==_0x6f99('0x4e')){var _0x113890={};_0x113890[_0x596066[_0x6f99('0x39')]]={'$like':'%'+_0x3c774b[_0x6f99('0x41')][_0x6f99('0x4c')]+'%'};return _0x113890;}})});}_0x344f61=_[_0x6f99('0x4d')]({},_0x344f61,_0x3c774b['options']);var _0x224b07={'where':_0x344f61[_0x6f99('0x4a')]};return db['OpenchannelMessage'][_0x6f99('0x30')](_0x224b07)[_0x6f99('0x23')](function(_0x288730){_0x304db7[_0x6f99('0x30')]=_0x288730;if(_0x3c774b[_0x6f99('0x41')]['includeAll']){_0x344f61[_0x6f99('0x4f')]=[{'all':!![]}];}return db[_0x6f99('0x3d')][_0x6f99('0x50')](_0x344f61);})[_0x6f99('0x23')](function(_0x41e37d){_0x304db7[_0x6f99('0x51')]=_0x41e37d;return _0x304db7;})[_0x6f99('0x23')](respondWithFilteredResult(_0x463249,_0x344f61))[_0x6f99('0x2d')](handleError(_0x463249,null));};exports[_0x6f99('0x52')]=function(_0x351c44,_0x3fa3c0){var _0x40d6df={'raw':!![],'where':{'id':_0x351c44[_0x6f99('0x53')]['id']}},_0x5635cd={};_0x5635cd[_0x6f99('0x40')]=_[_0x6f99('0x42')](db[_0x6f99('0x3d')][_0x6f99('0x3e')]);_0x5635cd[_0x6f99('0x41')]=_['keys'](_0x351c44[_0x6f99('0x41')]);_0x5635cd[_0x6f99('0x43')]=_['intersection'](_0x5635cd[_0x6f99('0x40')],_0x5635cd[_0x6f99('0x41')]);_0x40d6df[_0x6f99('0x44')]=_[_0x6f99('0x54')](_0x5635cd[_0x6f99('0x40')],qs['fields'](_0x351c44['query'][_0x6f99('0x45')]));_0x40d6df['attributes']=_0x40d6df[_0x6f99('0x44')][_0x6f99('0x46')]?_0x40d6df[_0x6f99('0x44')]:_0x5635cd[_0x6f99('0x40')];if(_0x351c44[_0x6f99('0x41')]['includeAll']){_0x40d6df[_0x6f99('0x4f')]=[{'all':!![]}];}_0x40d6df=_[_0x6f99('0x4d')]({},_0x40d6df,_0x351c44[_0x6f99('0x55')]);return db[_0x6f99('0x3d')]['find'](_0x40d6df)[_0x6f99('0x23')](handleEntityNotFound(_0x3fa3c0,null))[_0x6f99('0x23')](respondWithResult(_0x3fa3c0,null))[_0x6f99('0x2d')](handleError(_0x3fa3c0,null));};exports[_0x6f99('0x56')]=function(_0x10546a,_0x28e6a0){return db[_0x6f99('0x3d')][_0x6f99('0x56')](_0x10546a['body'],{})[_0x6f99('0x23')](respondWithResult(_0x28e6a0,0xc9))[_0x6f99('0x2d')](handleError(_0x28e6a0,null));};exports[_0x6f99('0x36')]=function(_0x4ac3b3,_0x5e269b){if(_0x4ac3b3[_0x6f99('0x57')]['id']){delete _0x4ac3b3['body']['id'];}return db[_0x6f99('0x3d')]['find']({'where':{'id':_0x4ac3b3[_0x6f99('0x53')]['id']}})[_0x6f99('0x23')](handleEntityNotFound(_0x5e269b,null))[_0x6f99('0x23')](saveUpdates(_0x4ac3b3['body'],null))[_0x6f99('0x23')](respondWithResult(_0x5e269b,null))[_0x6f99('0x2d')](handleError(_0x5e269b,null));};exports[_0x6f99('0x37')]=function(_0x263c02,_0x4e53ee){return db[_0x6f99('0x3d')]['find']({'where':{'id':_0x263c02[_0x6f99('0x53')]['id']}})[_0x6f99('0x23')](handleEntityNotFound(_0x4e53ee,null))[_0x6f99('0x23')](removeEntity(_0x4e53ee,null))[_0x6f99('0x2d')](handleError(_0x4e53ee,null));};exports[_0x6f99('0x58')]=function(_0x5b2990,_0x3c20e1){return db[_0x6f99('0x3d')]['describe']()[_0x6f99('0x23')](respondWithResult(_0x3c20e1,null))['catch'](handleError(_0x3c20e1,null));};var interaction_log=require(_0x6f99('0x16'))(_0x6f99('0x59'));exports[_0x6f99('0x5a')]=function(_0x5436ec,_0x46b223,_0x495776){var _0xf4e118={'channel':_0x6f99('0x5b')};if(_0x5436ec[_0x6f99('0x57')]['id']){delete _0x5436ec[_0x6f99('0x57')]['id'];}_0x5436ec['body'][_0x6f99('0x5c')]=!![];_0x5436ec['body'][_0x6f99('0x5d')]=moment()[_0x6f99('0x5e')](_0x6f99('0x5f'));_0x5436ec[_0x6f99('0x57')][_0x6f99('0x60')]=_0x5436ec[_0x6f99('0x57')][_0x6f99('0x60')]||_0x5436ec[_0x6f99('0x61')]['id'];return db['OpenchannelMessage'][_0x6f99('0x62')]({'where':{'id':_0x5436ec[_0x6f99('0x53')]['id'],'UserId':null},'include':[{'model':db[_0x6f99('0x63')],'as':_0x6f99('0x64')}]})[_0x6f99('0x23')](handleEntityNotFound(_0x46b223,null))['then'](saveUpdates(_0x5436ec[_0x6f99('0x57')],null))[_0x6f99('0x23')](function(_0x225ba8){if(_0x225ba8){_0xf4e118['message']=_0x225ba8[_0x6f99('0x65')]({'plain':!![]});return db[_0x6f99('0x66')][_0x6f99('0x62')]({'where':{'id':_0x225ba8['OpenchannelInteractionId']}});}return null;})['then'](handleEntityNotFound(_0x46b223,null))[_0x6f99('0x23')](function(_0x24a5ad){if(_0x24a5ad){return _0x24a5ad['update']({'UserId':_0x5436ec['body'][_0x6f99('0x60')],'read1stAt':_['isNil'](_0x24a5ad[_0x6f99('0x67')])?moment()['format'](_0x6f99('0x5f')):undefined});}return null;})[_0x6f99('0x23')](function(_0x2df38f){if(_0x2df38f){_0xf4e118[_0x6f99('0x68')]=_0x2df38f[_0x6f99('0x65')]({'plain':!![]});interaction_log[_0x6f99('0x24')](_0x6f99('0x69'),_0x5436ec[_0x6f99('0x61')]['id'],_0x5436ec[_0x6f99('0x61')]['name'],_0x5436ec[_0x6f99('0x61')][_0x6f99('0x6a')],_0xf4e118['interaction']['id'],_0x5436ec[_0x6f99('0x57')]?JSON[_0x6f99('0x28')](_0x5436ec[_0x6f99('0x57')]):_0x6f99('0x6b'));return respondWithRpcPromise('AcceptMessage','acceptMessage',_0xf4e118);}return null;})[_0x6f99('0x23')](function(_0x104941){if(_0x104941){if(_0x5436ec[_0x6f99('0x57')]['manual']){_0xf4e118['message'][_0x6f99('0x6c')]=util[_0x6f99('0x5e')](_0x6f99('0x6d'),_0x5436ec[_0x6f99('0x61')]['name']);_0xf4e118['message'][_0x6f99('0x6e')]=_0xf4e118['channel'];_0xf4e118[_0x6f99('0x2b')]['event']='accept';return respondWithRpcPromise(_0x6f99('0x6f'),_0x6f99('0x6f'),{'event':_0x6f99('0x70'),'message':_0xf4e118[_0x6f99('0x2b')]},client9002)[_0x6f99('0x23')](function(){return _0xf4e118;});}return _0xf4e118;}return null;})['then'](respondWithResult(_0x46b223,null))[_0x6f99('0x2d')](handleError(_0x46b223,null));};var interaction_log=require(_0x6f99('0x16'))(_0x6f99('0x59'));exports[_0x6f99('0x35')]=function(_0x1e24ad,_0x57231b,_0x17ab26){var _0x514013={'agent':{},'channel':'openchannel'};if(_0x1e24ad[_0x6f99('0x57')]['id']){delete _0x1e24ad[_0x6f99('0x57')]['id'];}_0x1e24ad['body'][_0x6f99('0x60')]=_0x1e24ad[_0x6f99('0x57')][_0x6f99('0x60')]||_0x1e24ad[_0x6f99('0x61')]['id'];_0x514013[_0x6f99('0x71')]['id']=_0x1e24ad[_0x6f99('0x57')][_0x6f99('0x60')];return db[_0x6f99('0x3d')]['find']({'where':{'id':_0x1e24ad[_0x6f99('0x53')]['id'],'UserId':null}})[_0x6f99('0x23')](handleEntityNotFound(_0x57231b,null))[_0x6f99('0x23')](function(_0x2f3c42){if(_0x2f3c42){_0x514013[_0x6f99('0x2b')]=_0x2f3c42[_0x6f99('0x65')]({'plain':!![]});return db['OpenchannelInteraction']['find']({'where':{'id':_0x2f3c42['OpenchannelInteractionId']}});}return null;})['then'](handleEntityNotFound(_0x57231b,null))[_0x6f99('0x23')](function(_0x7e4e95){if(_0x7e4e95){_0x514013[_0x6f99('0x68')]=_0x7e4e95[_0x6f99('0x65')]({'plain':!![]});interaction_log[_0x6f99('0x24')](_0x6f99('0x72'),_0x1e24ad[_0x6f99('0x61')]['id'],_0x1e24ad[_0x6f99('0x61')][_0x6f99('0x39')],_0x1e24ad[_0x6f99('0x61')]['role'],_0x514013[_0x6f99('0x68')]['id'],_0x1e24ad[_0x6f99('0x57')]?JSON[_0x6f99('0x28')](_0x1e24ad['body']):_0x6f99('0x6b'));return respondWithRpcPromise(_0x6f99('0x73'),_0x6f99('0x74'),_0x514013);}return null;})[_0x6f99('0x23')](function(_0x5497e7){if(_0x5497e7){_0x5497e7[_0x6f99('0x2b')][_0x6f99('0x6c')]=util[_0x6f99('0x5e')](_0x6f99('0x6d'),_0x1e24ad[_0x6f99('0x61')][_0x6f99('0x39')]);_0x5497e7[_0x6f99('0x2b')][_0x6f99('0x6e')]=_0x514013[_0x6f99('0x6e')];_0x5497e7['message'][_0x6f99('0x75')]='reject';respondWithRpcPromise(_0x6f99('0x6f'),'EventManager',{'event':_0x6f99('0x76'),'message':_0x5497e7[_0x6f99('0x2b')]},client9002);return _0x514013;}return null;})['then'](respondWithResult(_0x57231b,null))[_0x6f99('0x2d')](handleError(_0x57231b,null));};
\ No newline at end of file
+var _0xfa45=['SELECT','contact','User','email','internal','SIP/%s','motionChannel','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','defaults','redis','localhost','socket.io-emitter','register','jayson/promise','http','client','request','then','info','OpenchannelMessage,\x20%s,\x20%s','request\x20sent','debug','OpenchannelMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','status','end','json','offset','undefined','count','limit','set','Content-Range','apply','reject','save','update','stack','name','send','index','map','OpenchannelMessage','type','key','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','VIRTUAL','includeAll','include','findAll','show','params','rawAttributes','options','find','create','body','destroy','openchannel-interactions','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','get','OpenchannelInteraction','OpenchannelInteractionId','isNil','read1stAt','interaction','role','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','Sequelize','QueryTypes','fullname','manual','interface','channel','event','accept','EventManager','acceptmessage','openchannel','[OPENCHANNELMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','null','RejectMessage'];(function(_0x2d6982,_0x10f5bb){var _0x3b28f8=function(_0x1c77ab){while(--_0x1c77ab){_0x2d6982['push'](_0x2d6982['shift']());}};_0x3b28f8(++_0x10f5bb);}(_0xfa45,0x11b));var _0x5fa4=function(_0x46189e,_0x54878f){_0x46189e=_0x46189e-0x0;var _0x41edff=_0xfa45[_0x46189e];return _0x41edff;};'use strict';var emlformat=require(_0x5fa4('0x0'));var rimraf=require(_0x5fa4('0x1'));var zipdir=require(_0x5fa4('0x2'));var jsonpatch=require(_0x5fa4('0x3'));var rp=require(_0x5fa4('0x4'));var moment=require(_0x5fa4('0x5'));var BPromise=require(_0x5fa4('0x6'));var Mustache=require('mustache');var util=require(_0x5fa4('0x7'));var path=require('path');var sox=require(_0x5fa4('0x8'));var csv=require(_0x5fa4('0x9'));var ejs=require(_0x5fa4('0xa'));var fs=require('fs');var fs_extra=require(_0x5fa4('0xb'));var _=require(_0x5fa4('0xc'));var squel=require(_0x5fa4('0xd'));var crypto=require(_0x5fa4('0xe'));var jsforce=require(_0x5fa4('0xf'));var deskjs=require(_0x5fa4('0x10'));var toCsv=require(_0x5fa4('0x9'));var querystring=require('querystring');var Papa=require(_0x5fa4('0x11'));var Redis=require('ioredis');var authService=require(_0x5fa4('0x12'));var qs=require(_0x5fa4('0x13'));var as=require(_0x5fa4('0x14'));var hardwareService=require(_0x5fa4('0x15'));var logger=require(_0x5fa4('0x16'))(_0x5fa4('0x17'));var utils=require(_0x5fa4('0x18'));var config=require(_0x5fa4('0x19'));var licenseUtil=require('../../config/license/util');var db=require(_0x5fa4('0x1a'))['db'];config['redis']=_[_0x5fa4('0x1b')](config[_0x5fa4('0x1c')],{'host':_0x5fa4('0x1d'),'port':0x18eb});var socket=require(_0x5fa4('0x1e'))(new Redis(config[_0x5fa4('0x1c')]));require('./openchannelMessage.socket')[_0x5fa4('0x1f')](socket);var jayson=require(_0x5fa4('0x20'));var client=jayson['client'][_0x5fa4('0x21')]({'port':0x232c});var client9002=jayson[_0x5fa4('0x22')]['http']({'port':0x232a});function respondWithRpcPromise(_0x442064,_0x5cacd7,_0x531e37,_0x5ad60d){return new BPromise(function(_0x1645b1,_0x465c1d){var _0x21d502=_0x5ad60d||client;return _0x21d502[_0x5fa4('0x23')](_0x442064,_0x531e37)[_0x5fa4('0x24')](function(_0x4a3924){logger[_0x5fa4('0x25')](_0x5fa4('0x26'),_0x5cacd7,_0x5fa4('0x27'));logger[_0x5fa4('0x28')](_0x5fa4('0x29'),_0x5cacd7,_0x5fa4('0x27'),JSON[_0x5fa4('0x2a')](_0x4a3924));if(_0x4a3924[_0x5fa4('0x2b')]){if(_0x4a3924[_0x5fa4('0x2b')][_0x5fa4('0x2c')]===0x1f4){logger[_0x5fa4('0x2b')](_0x5fa4('0x26'),_0x5cacd7,_0x4a3924['error']['message']);return _0x465c1d(_0x4a3924[_0x5fa4('0x2b')][_0x5fa4('0x2d')]);}logger[_0x5fa4('0x2b')](_0x5fa4('0x26'),_0x5cacd7,_0x4a3924['error']['message']);return _0x1645b1(_0x4a3924[_0x5fa4('0x2b')]['message']);}else{logger[_0x5fa4('0x25')](_0x5fa4('0x26'),_0x5cacd7,_0x5fa4('0x27'));_0x1645b1(_0x4a3924[_0x5fa4('0x2e')]['message']);}})[_0x5fa4('0x2f')](function(_0x3d2abb){logger[_0x5fa4('0x2b')](_0x5fa4('0x26'),_0x5cacd7,_0x3d2abb);_0x465c1d(_0x3d2abb);});});}function respondWithStatusCode(_0x4dc79a,_0x57996b){_0x57996b=_0x57996b||0xcc;return function(_0x169d61){if(_0x169d61){return _0x4dc79a[_0x5fa4('0x30')](_0x57996b);}return _0x4dc79a[_0x5fa4('0x31')](_0x57996b)[_0x5fa4('0x32')]();};}function respondWithResult(_0x5a7580,_0x34006f){_0x34006f=_0x34006f||0xc8;return function(_0x259be8){if(_0x259be8){return _0x5a7580[_0x5fa4('0x31')](_0x34006f)[_0x5fa4('0x33')](_0x259be8);}};}function respondWithFilteredResult(_0x51833c,_0x49209e){return function(_0x27dcff){if(_0x27dcff){var _0x379fff=typeof _0x49209e[_0x5fa4('0x34')]===_0x5fa4('0x35')&&typeof _0x49209e['limit']===_0x5fa4('0x35');var _0x1c6082=_0x27dcff[_0x5fa4('0x36')];var _0x25ce24=_0x379fff?0x0:_0x49209e[_0x5fa4('0x34')];var _0x1764b6=_0x379fff?_0x27dcff[_0x5fa4('0x36')]:_0x49209e[_0x5fa4('0x34')]+_0x49209e[_0x5fa4('0x37')];var _0x5b79dc;if(_0x1764b6>=_0x1c6082){_0x1764b6=_0x1c6082;_0x5b79dc=0xc8;}else{_0x5b79dc=0xce;}_0x51833c[_0x5fa4('0x31')](_0x5b79dc);return _0x51833c[_0x5fa4('0x38')](_0x5fa4('0x39'),_0x25ce24+'-'+_0x1764b6+'/'+_0x1c6082)['json'](_0x27dcff);}return null;};}function patchUpdates(_0x3b3f52){return function(_0x1fe532){try{jsonpatch[_0x5fa4('0x3a')](_0x1fe532,_0x3b3f52,!![]);}catch(_0x455a35){return BPromise[_0x5fa4('0x3b')](_0x455a35);}return _0x1fe532[_0x5fa4('0x3c')]();};}function saveUpdates(_0x4d6854,_0x2f734f){return function(_0x344482){if(_0x344482){return _0x344482[_0x5fa4('0x3d')](_0x4d6854)[_0x5fa4('0x24')](function(_0x1da509){return _0x1da509;});}return null;};}function removeEntity(_0x58fb50,_0x8e50c1){return function(_0x2c31f8){if(_0x2c31f8){return _0x2c31f8['destroy']()[_0x5fa4('0x24')](function(){_0x58fb50['status'](0xcc)[_0x5fa4('0x32')]();});}};}function handleEntityNotFound(_0x47dbfe,_0xe9e64f){return function(_0x2333ef){if(!_0x2333ef){_0x47dbfe['sendStatus'](0x194);}return _0x2333ef;};}function handleError(_0x4e9df3,_0x5e06c3){_0x5e06c3=_0x5e06c3||0x1f4;return function(_0x226af8){logger[_0x5fa4('0x2b')](_0x226af8[_0x5fa4('0x3e')]);if(_0x226af8[_0x5fa4('0x3f')]){delete _0x226af8['name'];}_0x4e9df3['status'](_0x5e06c3)[_0x5fa4('0x40')](_0x226af8);};}exports[_0x5fa4('0x41')]=function(_0x399601,_0x54f7be){var _0x8bca5f={},_0x1b5df0={},_0x3b1bfa={'count':0x0,'rows':[]};var _0x5062be=_[_0x5fa4('0x42')](db[_0x5fa4('0x43')]['rawAttributes'],function(_0x3d8692){return{'name':_0x3d8692['fieldName'],'type':_0x3d8692[_0x5fa4('0x44')][_0x5fa4('0x45')]};});_0x1b5df0[_0x5fa4('0x46')]=_[_0x5fa4('0x42')](_0x5062be,'name');_0x1b5df0[_0x5fa4('0x47')]=_[_0x5fa4('0x48')](_0x399601[_0x5fa4('0x47')]);_0x1b5df0[_0x5fa4('0x49')]=_['intersection'](_0x1b5df0[_0x5fa4('0x46')],_0x1b5df0[_0x5fa4('0x47')]);_0x8bca5f[_0x5fa4('0x4a')]=_[_0x5fa4('0x4b')](_0x1b5df0[_0x5fa4('0x46')],qs[_0x5fa4('0x4c')](_0x399601[_0x5fa4('0x47')][_0x5fa4('0x4c')]));_0x8bca5f[_0x5fa4('0x4a')]=_0x8bca5f['attributes'][_0x5fa4('0x4d')]?_0x8bca5f[_0x5fa4('0x4a')]:_0x1b5df0[_0x5fa4('0x46')];if(!_0x399601[_0x5fa4('0x47')][_0x5fa4('0x4e')](_0x5fa4('0x4f'))){_0x8bca5f[_0x5fa4('0x37')]=qs[_0x5fa4('0x37')](_0x399601[_0x5fa4('0x47')][_0x5fa4('0x37')]);_0x8bca5f[_0x5fa4('0x34')]=qs[_0x5fa4('0x34')](_0x399601['query'][_0x5fa4('0x34')]);}_0x8bca5f[_0x5fa4('0x50')]=qs[_0x5fa4('0x51')](_0x399601[_0x5fa4('0x47')][_0x5fa4('0x51')]);_0x8bca5f['where']=qs[_0x5fa4('0x49')](_[_0x5fa4('0x52')](_0x399601[_0x5fa4('0x47')],_0x1b5df0[_0x5fa4('0x49')]),_0x5062be);if(_0x399601[_0x5fa4('0x47')][_0x5fa4('0x53')]){_0x8bca5f[_0x5fa4('0x54')]=_[_0x5fa4('0x55')](_0x8bca5f[_0x5fa4('0x54')],{'$or':_[_0x5fa4('0x42')](_0x5062be,function(_0x5ce2fa){if(_0x5ce2fa[_0x5fa4('0x44')]!==_0x5fa4('0x56')){var _0x34fbd2={};_0x34fbd2[_0x5ce2fa[_0x5fa4('0x3f')]]={'$like':'%'+_0x399601[_0x5fa4('0x47')][_0x5fa4('0x53')]+'%'};return _0x34fbd2;}})});}_0x8bca5f=_[_0x5fa4('0x55')]({},_0x8bca5f,_0x399601['options']);var _0x4ae2b3={'where':_0x8bca5f[_0x5fa4('0x54')]};return db['OpenchannelMessage'][_0x5fa4('0x36')](_0x4ae2b3)[_0x5fa4('0x24')](function(_0x3009cb){_0x3b1bfa[_0x5fa4('0x36')]=_0x3009cb;if(_0x399601[_0x5fa4('0x47')][_0x5fa4('0x57')]){_0x8bca5f[_0x5fa4('0x58')]=[{'all':!![]}];}return db['OpenchannelMessage'][_0x5fa4('0x59')](_0x8bca5f);})[_0x5fa4('0x24')](function(_0x3e1713){_0x3b1bfa['rows']=_0x3e1713;return _0x3b1bfa;})[_0x5fa4('0x24')](respondWithFilteredResult(_0x54f7be,_0x8bca5f))['catch'](handleError(_0x54f7be,null));};exports[_0x5fa4('0x5a')]=function(_0x43d95d,_0xd9349e){var _0xecda94={'raw':!![],'where':{'id':_0x43d95d[_0x5fa4('0x5b')]['id']}},_0x418771={};_0x418771[_0x5fa4('0x46')]=_['keys'](db[_0x5fa4('0x43')][_0x5fa4('0x5c')]);_0x418771[_0x5fa4('0x47')]=_[_0x5fa4('0x48')](_0x43d95d[_0x5fa4('0x47')]);_0x418771[_0x5fa4('0x49')]=_[_0x5fa4('0x4b')](_0x418771[_0x5fa4('0x46')],_0x418771[_0x5fa4('0x47')]);_0xecda94[_0x5fa4('0x4a')]=_['intersection'](_0x418771[_0x5fa4('0x46')],qs[_0x5fa4('0x4c')](_0x43d95d['query'][_0x5fa4('0x4c')]));_0xecda94[_0x5fa4('0x4a')]=_0xecda94['attributes'][_0x5fa4('0x4d')]?_0xecda94[_0x5fa4('0x4a')]:_0x418771[_0x5fa4('0x46')];if(_0x43d95d[_0x5fa4('0x47')][_0x5fa4('0x57')]){_0xecda94[_0x5fa4('0x58')]=[{'all':!![]}];}_0xecda94=_[_0x5fa4('0x55')]({},_0xecda94,_0x43d95d[_0x5fa4('0x5d')]);return db[_0x5fa4('0x43')][_0x5fa4('0x5e')](_0xecda94)[_0x5fa4('0x24')](handleEntityNotFound(_0xd9349e,null))['then'](respondWithResult(_0xd9349e,null))[_0x5fa4('0x2f')](handleError(_0xd9349e,null));};exports[_0x5fa4('0x5f')]=function(_0x395d6d,_0x42dda2){return db['OpenchannelMessage'][_0x5fa4('0x5f')](_0x395d6d[_0x5fa4('0x60')],{})[_0x5fa4('0x24')](respondWithResult(_0x42dda2,0xc9))[_0x5fa4('0x2f')](handleError(_0x42dda2,null));};exports[_0x5fa4('0x3d')]=function(_0x2e4c71,_0x583b13){if(_0x2e4c71[_0x5fa4('0x60')]['id']){delete _0x2e4c71['body']['id'];}return db[_0x5fa4('0x43')][_0x5fa4('0x5e')]({'where':{'id':_0x2e4c71[_0x5fa4('0x5b')]['id']}})[_0x5fa4('0x24')](handleEntityNotFound(_0x583b13,null))[_0x5fa4('0x24')](saveUpdates(_0x2e4c71[_0x5fa4('0x60')],null))[_0x5fa4('0x24')](respondWithResult(_0x583b13,null))[_0x5fa4('0x2f')](handleError(_0x583b13,null));};exports[_0x5fa4('0x61')]=function(_0x378eb1,_0x30ab1c){return db['OpenchannelMessage'][_0x5fa4('0x5e')]({'where':{'id':_0x378eb1['params']['id']}})[_0x5fa4('0x24')](handleEntityNotFound(_0x30ab1c,null))[_0x5fa4('0x24')](removeEntity(_0x30ab1c,null))[_0x5fa4('0x2f')](handleError(_0x30ab1c,null));};exports['describe']=function(_0x30618c,_0x2b5758){return db[_0x5fa4('0x43')]['describe']()['then'](respondWithResult(_0x2b5758,null))[_0x5fa4('0x2f')](handleError(_0x2b5758,null));};var interaction_log=require('../../config/logger')(_0x5fa4('0x62'));exports['accept']=function(_0x5a9433,_0x44ac04,_0xcd6cf7){var _0x13cce2={'agent':{},'channel':'openchannel'};if(_0x5a9433[_0x5fa4('0x60')]['id']){delete _0x5a9433['body']['id'];}_0x5a9433['body'][_0x5fa4('0x63')]=!![];_0x5a9433[_0x5fa4('0x60')][_0x5fa4('0x64')]=moment()[_0x5fa4('0x65')](_0x5fa4('0x66'));_0x5a9433[_0x5fa4('0x60')]['UserId']=_0x5a9433[_0x5fa4('0x60')][_0x5fa4('0x67')]||_0x5a9433[_0x5fa4('0x68')]['id'];_0x13cce2[_0x5fa4('0x69')]['id']=_0x5a9433[_0x5fa4('0x60')][_0x5fa4('0x67')];return db[_0x5fa4('0x43')][_0x5fa4('0x5e')]({'where':{'id':_0x5a9433[_0x5fa4('0x5b')]['id'],'UserId':null}})[_0x5fa4('0x24')](handleEntityNotFound(_0x44ac04,null))[_0x5fa4('0x24')](saveUpdates(_0x5a9433[_0x5fa4('0x60')],null))['then'](function(_0xbe67bf){if(_0xbe67bf){_0x13cce2[_0x5fa4('0x2d')]=_0xbe67bf[_0x5fa4('0x6a')]({'plain':!![]});return db[_0x5fa4('0x6b')]['find']({'where':{'id':_0xbe67bf[_0x5fa4('0x6c')]}});}return null;})[_0x5fa4('0x24')](handleEntityNotFound(_0x44ac04,null))['then'](function(_0x7b55d8){if(_0x7b55d8){return _0x7b55d8[_0x5fa4('0x3d')]({'UserId':_0x5a9433[_0x5fa4('0x60')][_0x5fa4('0x67')],'read1stAt':_[_0x5fa4('0x6d')](_0x7b55d8[_0x5fa4('0x6e')])?moment()[_0x5fa4('0x65')]('YYYY-MM-DD\x20HH:mm:ss'):undefined});}return null;})[_0x5fa4('0x24')](function(_0x280c7b){if(_0x280c7b){_0x13cce2[_0x5fa4('0x6f')]=_0x280c7b[_0x5fa4('0x6a')]({'plain':!![]});interaction_log[_0x5fa4('0x25')]('[OPENCHANNELMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x5a9433['user']['id'],_0x5a9433['user']['name'],_0x5a9433['user'][_0x5fa4('0x70')],_0x13cce2['interaction']['id'],_0x5a9433['body']?JSON[_0x5fa4('0x2a')](_0x5a9433[_0x5fa4('0x60')]):'null');return respondWithRpcPromise(_0x5fa4('0x71'),_0x5fa4('0x72'),_0x13cce2);}return null;})[_0x5fa4('0x24')](function(_0x114988){var _0x24a8b8=_0x5fa4('0x73')+_0x114988[_0x5fa4('0x2d')][_0x5fa4('0x74')];return db['sequelize'][_0x5fa4('0x47')](_0x24a8b8,{'type':db[_0x5fa4('0x75')][_0x5fa4('0x76')]['SELECT'],'raw':!![]})[_0x5fa4('0x24')](function(_0x11f92d){return _0x11f92d;});})['then'](function(_0x250285){if(_0x250285){_0x13cce2[_0x5fa4('0x2d')]['contact']=_0x250285[0x0];if(!_0x5a9433[_0x5fa4('0x60')][_0x5fa4('0x67')])return;return db['User']['find']({'where':{'id':_0x5a9433[_0x5fa4('0x60')]['UserId'],'role':'agent'},'attributes':['id',_0x5fa4('0x3f'),_0x5fa4('0x77'),'email','internal'],'raw':!![]});}return null;})[_0x5fa4('0x24')](function(_0x104a91){if(!_0x104a91)return null;_0x13cce2[_0x5fa4('0x2d')][_0x5fa4('0x69')]=_0x104a91;return _0x13cce2;})[_0x5fa4('0x24')](function(_0x58005c){if(_0x58005c){if(_0x5a9433[_0x5fa4('0x60')][_0x5fa4('0x78')]){_0x13cce2[_0x5fa4('0x2d')][_0x5fa4('0x79')]=util[_0x5fa4('0x65')]('SIP/%s',_0x5a9433[_0x5fa4('0x68')][_0x5fa4('0x3f')]);_0x13cce2['message'][_0x5fa4('0x7a')]=_0x13cce2[_0x5fa4('0x7a')];_0x13cce2[_0x5fa4('0x2d')]['motionChannel']=_0x13cce2['channel'];_0x13cce2[_0x5fa4('0x2d')][_0x5fa4('0x7b')]=_0x5fa4('0x7c');return respondWithRpcPromise(_0x5fa4('0x7d'),'EventManager',{'event':_0x5fa4('0x7e'),'message':_0x13cce2[_0x5fa4('0x2d')]},client9002)[_0x5fa4('0x24')](function(){return _0x13cce2;});}return _0x13cce2;}return null;})[_0x5fa4('0x24')](respondWithResult(_0x44ac04,null))[_0x5fa4('0x2f')](handleError(_0x44ac04,null));};var interaction_log=require(_0x5fa4('0x16'))('openchannel-interactions');exports['reject']=function(_0x466827,_0x485aba,_0x407351){var _0x5b724f={'agent':{},'channel':_0x5fa4('0x7f')};if(_0x466827['body']['id']){delete _0x466827[_0x5fa4('0x60')]['id'];}_0x466827['body'][_0x5fa4('0x67')]=_0x466827[_0x5fa4('0x60')][_0x5fa4('0x67')]||_0x466827[_0x5fa4('0x68')]['id'];_0x5b724f[_0x5fa4('0x69')]['id']=_0x466827['body'][_0x5fa4('0x67')];return db[_0x5fa4('0x43')][_0x5fa4('0x5e')]({'where':{'id':_0x466827['params']['id'],'UserId':null}})[_0x5fa4('0x24')](handleEntityNotFound(_0x485aba,null))[_0x5fa4('0x24')](function(_0x565eec){if(_0x565eec){_0x5b724f[_0x5fa4('0x2d')]=_0x565eec[_0x5fa4('0x6a')]({'plain':!![]});return db[_0x5fa4('0x6b')][_0x5fa4('0x5e')]({'where':{'id':_0x565eec[_0x5fa4('0x6c')]}});}return null;})[_0x5fa4('0x24')](handleEntityNotFound(_0x485aba,null))[_0x5fa4('0x24')](function(_0x40c262){if(_0x40c262){_0x5b724f[_0x5fa4('0x6f')]=_0x40c262[_0x5fa4('0x6a')]({'plain':!![]});interaction_log['info'](_0x5fa4('0x80'),_0x466827[_0x5fa4('0x68')]['id'],_0x466827['user'][_0x5fa4('0x3f')],_0x466827[_0x5fa4('0x68')]['role'],_0x5b724f[_0x5fa4('0x6f')]['id'],_0x466827[_0x5fa4('0x60')]?JSON[_0x5fa4('0x2a')](_0x466827[_0x5fa4('0x60')]):_0x5fa4('0x81'));return respondWithRpcPromise(_0x5fa4('0x82'),'rejectMessage',_0x5b724f);}return null;})['then'](function(_0xdd64cf){var _0x57762a=_0x5fa4('0x73')+_0xdd64cf[_0x5fa4('0x2d')][_0x5fa4('0x74')];return db['sequelize'][_0x5fa4('0x47')](_0x57762a,{'type':db[_0x5fa4('0x75')]['QueryTypes'][_0x5fa4('0x83')],'raw':!![]})['then'](function(_0x91e9ef){return _0x91e9ef;});})['then'](function(_0x54810d){if(_0x54810d){_0x5b724f['message'][_0x5fa4('0x84')]=_0x54810d[0x0];if(!_0x466827['body'][_0x5fa4('0x67')])return;return db[_0x5fa4('0x85')]['find']({'where':{'id':_0x466827[_0x5fa4('0x60')][_0x5fa4('0x67')],'role':'agent'},'attributes':['id',_0x5fa4('0x3f'),_0x5fa4('0x77'),_0x5fa4('0x86'),_0x5fa4('0x87')],'raw':!![]});}return null;})[_0x5fa4('0x24')](function(_0x24c9d1){if(!_0x24c9d1)return null;_0x5b724f[_0x5fa4('0x2d')][_0x5fa4('0x69')]=_0x24c9d1;return _0x5b724f;})[_0x5fa4('0x24')](function(_0x177836){if(_0x177836){_0x177836[_0x5fa4('0x2d')]['interface']=util[_0x5fa4('0x65')](_0x5fa4('0x88'),_0x466827[_0x5fa4('0x68')][_0x5fa4('0x3f')]);_0x177836['message'][_0x5fa4('0x7a')]=_0x5b724f['channel'];_0x177836[_0x5fa4('0x2d')][_0x5fa4('0x89')]=_0x5b724f['channel'];_0x177836[_0x5fa4('0x2d')][_0x5fa4('0x7b')]='reject';respondWithRpcPromise(_0x5fa4('0x7d'),_0x5fa4('0x7d'),{'event':'rejectmessage','message':_0x177836[_0x5fa4('0x2d')]},client9002);return _0x5b724f;}return null;})[_0x5fa4('0x24')](respondWithResult(_0x485aba,null))[_0x5fa4('0x2f')](handleError(_0x485aba,null));};
\ No newline at end of file