Built motion from commit (unavailable).|2.5.29
[motion2.git] / server / api / openchannelMessage / openchannelMessage.controller.js
index 7850523..ff86e9c 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 _0x6b59=['user','agent','CmContact','Contact','get','OpenchannelInteraction','OpenchannelInteractionId','isNil','read1stAt','format','[OPENCHANNELMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','interaction','null','AcceptMessage','acceptMessage','manual','SIP/%s','channel','event','accept','EventManager','acceptmessage','[OPENCHANNELMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','interface','reject','eml-format','zip-dir','moment','bluebird','mustache','path','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','redis','localhost','jayson/promise','client','http','then','OpenchannelMessage,\x20%s,\x20%s','request\x20sent','debug','OpenchannelMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','catch','sendStatus','end','offset','undefined','limit','count','set','json','apply','save','update','stack','name','status','send','index','map','OpenchannelMessage','rawAttributes','fieldName','type','key','model','query','keys','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','options','includeAll','include','findAll','rows','show','params','merge','find','create','body','destroy','describe','openchannel-interactions','read','readAt','YYYY-MM-DD\x20HH:mm:ss','UserId'];(function(_0x3bcaa2,_0x37a224){var _0x1c899f=function(_0x53f7d3){while(--_0x53f7d3){_0x3bcaa2['push'](_0x3bcaa2['shift']());}};_0x1c899f(++_0x37a224);}(_0x6b59,0x112));var _0x96b5=function(_0x3eda5d,_0x2320c4){_0x3eda5d=_0x3eda5d-0x0;var _0x5cdebc=_0x6b59[_0x3eda5d];return _0x5cdebc;};'use strict';var emlformat=require(_0x96b5('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x96b5('0x1'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x96b5('0x2'));var BPromise=require(_0x96b5('0x3'));var Mustache=require(_0x96b5('0x4'));var util=require('util');var path=require(_0x96b5('0x5'));var sox=require(_0x96b5('0x6'));var csv=require('to-csv');var ejs=require(_0x96b5('0x7'));var fs=require('fs');var fs_extra=require(_0x96b5('0x8'));var _=require(_0x96b5('0x9'));var squel=require(_0x96b5('0xa'));var crypto=require(_0x96b5('0xb'));var jsforce=require(_0x96b5('0xc'));var deskjs=require(_0x96b5('0xd'));var toCsv=require(_0x96b5('0xe'));var querystring=require('querystring');var Papa=require(_0x96b5('0xf'));var Redis=require(_0x96b5('0x10'));var authService=require(_0x96b5('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x96b5('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x96b5('0x13'))(_0x96b5('0x14'));var utils=require(_0x96b5('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0x96b5('0x16'));var db=require(_0x96b5('0x17'))['db'];config[_0x96b5('0x18')]=_['defaults'](config['redis'],{'host':_0x96b5('0x19'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x96b5('0x18')]));require('./openchannelMessage.socket')['register'](socket);var jayson=require(_0x96b5('0x1a'));var client=jayson[_0x96b5('0x1b')][_0x96b5('0x1c')]({'port':0x232c});var client9002=jayson[_0x96b5('0x1b')][_0x96b5('0x1c')]({'port':0x232a});function respondWithRpcPromise(_0x3e5f01,_0x5e6924,_0x402e00,_0x19e4d8){return new BPromise(function(_0x5496c7,_0x19f690){var _0x4fd441=_0x19e4d8||client;return _0x4fd441['request'](_0x3e5f01,_0x402e00)[_0x96b5('0x1d')](function(_0x3ee42f){logger['info'](_0x96b5('0x1e'),_0x5e6924,_0x96b5('0x1f'));logger[_0x96b5('0x20')](_0x96b5('0x21'),_0x5e6924,_0x96b5('0x1f'),JSON[_0x96b5('0x22')](_0x3ee42f));if(_0x3ee42f[_0x96b5('0x23')]){if(_0x3ee42f[_0x96b5('0x23')][_0x96b5('0x24')]===0x1f4){logger['error']('OpenchannelMessage,\x20%s,\x20%s',_0x5e6924,_0x3ee42f[_0x96b5('0x23')][_0x96b5('0x25')]);return _0x19f690(_0x3ee42f[_0x96b5('0x23')]['message']);}logger[_0x96b5('0x23')](_0x96b5('0x1e'),_0x5e6924,_0x3ee42f[_0x96b5('0x23')][_0x96b5('0x25')]);return _0x5496c7(_0x3ee42f['error'][_0x96b5('0x25')]);}else{logger[_0x96b5('0x26')]('OpenchannelMessage,\x20%s,\x20%s',_0x5e6924,_0x96b5('0x1f'));_0x5496c7(_0x3ee42f['result'][_0x96b5('0x25')]);}})[_0x96b5('0x27')](function(_0x676a25){logger[_0x96b5('0x23')]('OpenchannelMessage,\x20%s,\x20%s',_0x5e6924,_0x676a25);_0x19f690(_0x676a25);});});}function respondWithStatusCode(_0x4e5774,_0x329381){_0x329381=_0x329381||0xcc;return function(_0x4703bc){if(_0x4703bc){return _0x4e5774[_0x96b5('0x28')](_0x329381);}return _0x4e5774['status'](_0x329381)[_0x96b5('0x29')]();};}function respondWithResult(_0x5288c1,_0x2e523f){_0x2e523f=_0x2e523f||0xc8;return function(_0x55831c){if(_0x55831c){return _0x5288c1['status'](_0x2e523f)['json'](_0x55831c);}};}function respondWithFilteredResult(_0x192321,_0x592732){return function(_0x4a12cb){if(_0x4a12cb){var _0x829080=typeof _0x592732[_0x96b5('0x2a')]===_0x96b5('0x2b')&&typeof _0x592732[_0x96b5('0x2c')]===_0x96b5('0x2b');var _0x419537=_0x4a12cb[_0x96b5('0x2d')];var _0x34aeaa=_0x829080?0x0:_0x592732[_0x96b5('0x2a')];var _0x9ccfde=_0x829080?_0x4a12cb[_0x96b5('0x2d')]:_0x592732[_0x96b5('0x2a')]+_0x592732[_0x96b5('0x2c')];var _0x158f0a;if(_0x9ccfde>=_0x419537){_0x9ccfde=_0x419537;_0x158f0a=0xc8;}else{_0x158f0a=0xce;}_0x192321['status'](_0x158f0a);return _0x192321[_0x96b5('0x2e')]('Content-Range',_0x34aeaa+'-'+_0x9ccfde+'/'+_0x419537)[_0x96b5('0x2f')](_0x4a12cb);}return null;};}function patchUpdates(_0x3bc23c){return function(_0x685047){try{jsonpatch[_0x96b5('0x30')](_0x685047,_0x3bc23c,!![]);}catch(_0x47a91c){return BPromise['reject'](_0x47a91c);}return _0x685047[_0x96b5('0x31')]();};}function saveUpdates(_0x4b9947,_0xe03ddd){return function(_0x5110b8){if(_0x5110b8){return _0x5110b8[_0x96b5('0x32')](_0x4b9947)[_0x96b5('0x1d')](function(_0x402056){return _0x402056;});}return null;};}function removeEntity(_0x5668c2,_0x1a9adb){return function(_0x28d243){if(_0x28d243){return _0x28d243['destroy']()[_0x96b5('0x1d')](function(){_0x5668c2['status'](0xcc)[_0x96b5('0x29')]();});}};}function handleEntityNotFound(_0x455b4c,_0x1f749e){return function(_0x316609){if(!_0x316609){_0x455b4c[_0x96b5('0x28')](0x194);}return _0x316609;};}function handleError(_0x315cd7,_0x2356fe){_0x2356fe=_0x2356fe||0x1f4;return function(_0x2ef915){logger[_0x96b5('0x23')](_0x2ef915[_0x96b5('0x33')]);if(_0x2ef915[_0x96b5('0x34')]){delete _0x2ef915[_0x96b5('0x34')];}_0x315cd7[_0x96b5('0x35')](_0x2356fe)[_0x96b5('0x36')](_0x2ef915);};}exports[_0x96b5('0x37')]=function(_0x1af99c,_0x443223){var _0x3d096={},_0x191219={},_0x4679e2={'count':0x0,'rows':[]};var _0x519b2d=_[_0x96b5('0x38')](db[_0x96b5('0x39')][_0x96b5('0x3a')],function(_0xa45930){return{'name':_0xa45930[_0x96b5('0x3b')],'type':_0xa45930[_0x96b5('0x3c')][_0x96b5('0x3d')]};});_0x191219[_0x96b5('0x3e')]=_['map'](_0x519b2d,_0x96b5('0x34'));_0x191219[_0x96b5('0x3f')]=_[_0x96b5('0x40')](_0x1af99c[_0x96b5('0x3f')]);_0x191219['filters']=_[_0x96b5('0x41')](_0x191219[_0x96b5('0x3e')],_0x191219['query']);_0x3d096['attributes']=_[_0x96b5('0x41')](_0x191219[_0x96b5('0x3e')],qs[_0x96b5('0x42')](_0x1af99c['query']['fields']));_0x3d096['attributes']=_0x3d096[_0x96b5('0x43')][_0x96b5('0x44')]?_0x3d096[_0x96b5('0x43')]:_0x191219[_0x96b5('0x3e')];if(!_0x1af99c['query'][_0x96b5('0x45')](_0x96b5('0x46'))){_0x3d096[_0x96b5('0x2c')]=qs['limit'](_0x1af99c['query'][_0x96b5('0x2c')]);_0x3d096[_0x96b5('0x2a')]=qs[_0x96b5('0x2a')](_0x1af99c[_0x96b5('0x3f')][_0x96b5('0x2a')]);}_0x3d096[_0x96b5('0x47')]=qs['sort'](_0x1af99c[_0x96b5('0x3f')][_0x96b5('0x48')]);_0x3d096[_0x96b5('0x49')]=qs[_0x96b5('0x4a')](_[_0x96b5('0x4b')](_0x1af99c[_0x96b5('0x3f')],_0x191219[_0x96b5('0x4a')]),_0x519b2d);if(_0x1af99c[_0x96b5('0x3f')][_0x96b5('0x4c')]){_0x3d096[_0x96b5('0x49')]=_['merge'](_0x3d096['where'],{'$or':_[_0x96b5('0x38')](_0x519b2d,function(_0x173c0f){if(_0x173c0f['type']!=='VIRTUAL'){var _0x5f0c3f={};_0x5f0c3f[_0x173c0f[_0x96b5('0x34')]]={'$like':'%'+_0x1af99c['query'][_0x96b5('0x4c')]+'%'};return _0x5f0c3f;}})});}_0x3d096=_['merge']({},_0x3d096,_0x1af99c[_0x96b5('0x4d')]);var _0x4cfbc1={'where':_0x3d096['where']};return db[_0x96b5('0x39')][_0x96b5('0x2d')](_0x4cfbc1)[_0x96b5('0x1d')](function(_0x2ada3c){_0x4679e2[_0x96b5('0x2d')]=_0x2ada3c;if(_0x1af99c[_0x96b5('0x3f')][_0x96b5('0x4e')]){_0x3d096[_0x96b5('0x4f')]=[{'all':!![]}];}return db[_0x96b5('0x39')][_0x96b5('0x50')](_0x3d096);})[_0x96b5('0x1d')](function(_0x2fa8e1){_0x4679e2[_0x96b5('0x51')]=_0x2fa8e1;return _0x4679e2;})['then'](respondWithFilteredResult(_0x443223,_0x3d096))['catch'](handleError(_0x443223,null));};exports[_0x96b5('0x52')]=function(_0xb1ea6,_0x24160d){var _0x3c223e={'raw':!![],'where':{'id':_0xb1ea6[_0x96b5('0x53')]['id']}},_0x499f82={};_0x499f82[_0x96b5('0x3e')]=_[_0x96b5('0x40')](db['OpenchannelMessage'][_0x96b5('0x3a')]);_0x499f82[_0x96b5('0x3f')]=_['keys'](_0xb1ea6[_0x96b5('0x3f')]);_0x499f82[_0x96b5('0x4a')]=_[_0x96b5('0x41')](_0x499f82['model'],_0x499f82['query']);_0x3c223e['attributes']=_[_0x96b5('0x41')](_0x499f82[_0x96b5('0x3e')],qs[_0x96b5('0x42')](_0xb1ea6[_0x96b5('0x3f')][_0x96b5('0x42')]));_0x3c223e[_0x96b5('0x43')]=_0x3c223e[_0x96b5('0x43')][_0x96b5('0x44')]?_0x3c223e['attributes']:_0x499f82['model'];if(_0xb1ea6[_0x96b5('0x3f')][_0x96b5('0x4e')]){_0x3c223e[_0x96b5('0x4f')]=[{'all':!![]}];}_0x3c223e=_[_0x96b5('0x54')]({},_0x3c223e,_0xb1ea6[_0x96b5('0x4d')]);return db['OpenchannelMessage'][_0x96b5('0x55')](_0x3c223e)['then'](handleEntityNotFound(_0x24160d,null))[_0x96b5('0x1d')](respondWithResult(_0x24160d,null))['catch'](handleError(_0x24160d,null));};exports[_0x96b5('0x56')]=function(_0x274740,_0x3498c0){return db[_0x96b5('0x39')][_0x96b5('0x56')](_0x274740[_0x96b5('0x57')],{})[_0x96b5('0x1d')](respondWithResult(_0x3498c0,0xc9))[_0x96b5('0x27')](handleError(_0x3498c0,null));};exports[_0x96b5('0x32')]=function(_0x1f6269,_0x53f385){if(_0x1f6269[_0x96b5('0x57')]['id']){delete _0x1f6269[_0x96b5('0x57')]['id'];}return db[_0x96b5('0x39')][_0x96b5('0x55')]({'where':{'id':_0x1f6269[_0x96b5('0x53')]['id']}})[_0x96b5('0x1d')](handleEntityNotFound(_0x53f385,null))[_0x96b5('0x1d')](saveUpdates(_0x1f6269[_0x96b5('0x57')],null))['then'](respondWithResult(_0x53f385,null))['catch'](handleError(_0x53f385,null));};exports[_0x96b5('0x58')]=function(_0x57e967,_0x26c09b){return db[_0x96b5('0x39')]['find']({'where':{'id':_0x57e967[_0x96b5('0x53')]['id']}})[_0x96b5('0x1d')](handleEntityNotFound(_0x26c09b,null))[_0x96b5('0x1d')](removeEntity(_0x26c09b,null))[_0x96b5('0x27')](handleError(_0x26c09b,null));};exports[_0x96b5('0x59')]=function(_0x1a85fc,_0x152a9b){return db['OpenchannelMessage']['describe']()[_0x96b5('0x1d')](respondWithResult(_0x152a9b,null))[_0x96b5('0x27')](handleError(_0x152a9b,null));};var interaction_log=require(_0x96b5('0x13'))(_0x96b5('0x5a'));exports['accept']=function(_0x632255,_0x2cab50,_0x48b9c5){var _0x1e9ec5={'agent':{},'channel':'openchannel'};if(_0x632255[_0x96b5('0x57')]['id']){delete _0x632255[_0x96b5('0x57')]['id'];}_0x632255[_0x96b5('0x57')][_0x96b5('0x5b')]=!![];_0x632255['body'][_0x96b5('0x5c')]=moment()['format'](_0x96b5('0x5d'));_0x632255[_0x96b5('0x57')][_0x96b5('0x5e')]=_0x632255[_0x96b5('0x57')][_0x96b5('0x5e')]||_0x632255[_0x96b5('0x5f')]['id'];_0x1e9ec5[_0x96b5('0x60')]['id']=_0x632255[_0x96b5('0x57')][_0x96b5('0x5e')];return db[_0x96b5('0x39')]['find']({'where':{'id':_0x632255['params']['id'],'UserId':null},'include':[{'model':db[_0x96b5('0x61')],'as':_0x96b5('0x62')}]})[_0x96b5('0x1d')](handleEntityNotFound(_0x2cab50,null))[_0x96b5('0x1d')](saveUpdates(_0x632255[_0x96b5('0x57')],null))[_0x96b5('0x1d')](function(_0x11e989){if(_0x11e989){_0x1e9ec5['message']=_0x11e989[_0x96b5('0x63')]({'plain':!![]});return db[_0x96b5('0x64')][_0x96b5('0x55')]({'where':{'id':_0x11e989[_0x96b5('0x65')]}});}return null;})['then'](handleEntityNotFound(_0x2cab50,null))[_0x96b5('0x1d')](function(_0x4f1b90){if(_0x4f1b90){return _0x4f1b90[_0x96b5('0x32')]({'UserId':_0x632255[_0x96b5('0x57')]['UserId'],'read1stAt':_[_0x96b5('0x66')](_0x4f1b90[_0x96b5('0x67')])?moment()[_0x96b5('0x68')](_0x96b5('0x5d')):undefined});}return null;})[_0x96b5('0x1d')](function(_0x510173){if(_0x510173){_0x1e9ec5['interaction']=_0x510173['get']({'plain':!![]});interaction_log[_0x96b5('0x26')](_0x96b5('0x69'),_0x632255[_0x96b5('0x5f')]['id'],_0x632255['user'][_0x96b5('0x34')],_0x632255[_0x96b5('0x5f')][_0x96b5('0x6a')],_0x1e9ec5[_0x96b5('0x6b')]['id'],_0x632255[_0x96b5('0x57')]?JSON[_0x96b5('0x22')](_0x632255[_0x96b5('0x57')]):_0x96b5('0x6c'));return respondWithRpcPromise(_0x96b5('0x6d'),_0x96b5('0x6e'),_0x1e9ec5);}return null;})[_0x96b5('0x1d')](function(_0x1a4aa8){if(_0x1a4aa8){if(_0x632255['body'][_0x96b5('0x6f')]){_0x1e9ec5['message']['interface']=util[_0x96b5('0x68')](_0x96b5('0x70'),_0x632255[_0x96b5('0x5f')][_0x96b5('0x34')]);_0x1e9ec5['message'][_0x96b5('0x71')]=_0x1e9ec5[_0x96b5('0x71')];_0x1e9ec5[_0x96b5('0x25')][_0x96b5('0x72')]=_0x96b5('0x73');return respondWithRpcPromise(_0x96b5('0x74'),'EventManager',{'event':_0x96b5('0x75'),'message':_0x1e9ec5[_0x96b5('0x25')]},client9002)[_0x96b5('0x1d')](function(){return _0x1e9ec5;});}return _0x1e9ec5;}return null;})['then'](respondWithResult(_0x2cab50,null))[_0x96b5('0x27')](handleError(_0x2cab50,null));};var interaction_log=require(_0x96b5('0x13'))('openchannel-interactions');exports['reject']=function(_0x4ffc13,_0x4e2e4d,_0x57e0d0){var _0x2307f8={'agent':{},'channel':'openchannel'};if(_0x4ffc13[_0x96b5('0x57')]['id']){delete _0x4ffc13[_0x96b5('0x57')]['id'];}_0x4ffc13[_0x96b5('0x57')][_0x96b5('0x5e')]=_0x4ffc13[_0x96b5('0x57')][_0x96b5('0x5e')]||_0x4ffc13[_0x96b5('0x5f')]['id'];_0x2307f8['agent']['id']=_0x4ffc13['body'][_0x96b5('0x5e')];return db['OpenchannelMessage'][_0x96b5('0x55')]({'where':{'id':_0x4ffc13['params']['id'],'UserId':null}})['then'](handleEntityNotFound(_0x4e2e4d,null))[_0x96b5('0x1d')](function(_0x47f9ee){if(_0x47f9ee){_0x2307f8[_0x96b5('0x25')]=_0x47f9ee['get']({'plain':!![]});return db[_0x96b5('0x64')]['find']({'where':{'id':_0x47f9ee['OpenchannelInteractionId']}});}return null;})[_0x96b5('0x1d')](handleEntityNotFound(_0x4e2e4d,null))['then'](function(_0x2e343d){if(_0x2e343d){_0x2307f8['interaction']=_0x2e343d['get']({'plain':!![]});interaction_log[_0x96b5('0x26')](_0x96b5('0x76'),_0x4ffc13[_0x96b5('0x5f')]['id'],_0x4ffc13[_0x96b5('0x5f')][_0x96b5('0x34')],_0x4ffc13[_0x96b5('0x5f')][_0x96b5('0x6a')],_0x2307f8[_0x96b5('0x6b')]['id'],_0x4ffc13[_0x96b5('0x57')]?JSON[_0x96b5('0x22')](_0x4ffc13['body']):'null');return respondWithRpcPromise(_0x96b5('0x77'),_0x96b5('0x78'),_0x2307f8);}return null;})[_0x96b5('0x1d')](function(_0x347492){if(_0x347492){_0x347492[_0x96b5('0x25')][_0x96b5('0x79')]=util[_0x96b5('0x68')]('SIP/%s',_0x4ffc13[_0x96b5('0x5f')][_0x96b5('0x34')]);_0x347492[_0x96b5('0x25')][_0x96b5('0x71')]=_0x2307f8[_0x96b5('0x71')];_0x347492[_0x96b5('0x25')][_0x96b5('0x72')]=_0x96b5('0x7a');respondWithRpcPromise('EventManager',_0x96b5('0x74'),{'event':'rejectmessage','message':_0x347492[_0x96b5('0x25')]},client9002);return _0x2307f8;}return null;})[_0x96b5('0x1d')](respondWithResult(_0x4e2e4d,null))[_0x96b5('0x27')](handleError(_0x4e2e4d,null));};
\ No newline at end of file