Built motion from commit ddca4d0d.|2.5.47
[motion2.git] / server / api / openchannelMessage / openchannelMessage.controller.js
index b99dbb8..2e1e2c8 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x75e3=['count','offset','set','json','apply','reject','save','update','then','destroy','stack','name','send','index','map','rawAttributes','fieldName','type','key','query','keys','intersection','model','attributes','length','hasOwnProperty','nolimit','limit','sort','where','pick','filters','filter','merge','VIRTUAL','options','includeAll','include','OpenchannelMessage','findAll','rows','show','params','fields','find','create','body','describe','openchannel-interactions','accept','openchannel','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','agent','CmContact','get','OpenchannelInteraction','isNil','interaction','[OPENCHANNELMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','user','role','null','AcceptMessage','acceptMessage','manual','interface','SIP/%s','event','EventManager','acceptmessage','OpenchannelInteractionId','RejectMessage','rejectMessage','channel','rejectmessage','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/environment','../../config/license/util','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./openchannelMessage.socket','register','client','http','debug','request\x20sent','stringify','error','code','message','OpenchannelMessage,\x20%s,\x20%s','info','catch','sendStatus','end','status'];(function(_0x40d470,_0x430d4a){var _0x161e8a=function(_0x2cda34){while(--_0x2cda34){_0x40d470['push'](_0x40d470['shift']());}};_0x161e8a(++_0x430d4a);}(_0x75e3,0x1c5));var _0x375e=function(_0x430f50,_0x4da5d5){_0x430f50=_0x430f50-0x0;var _0x3f69d0=_0x75e3[_0x430f50];return _0x3f69d0;};'use strict';var pdf=require(_0x375e('0x0'));var emlformat=require(_0x375e('0x1'));var rimraf=require(_0x375e('0x2'));var zipdir=require(_0x375e('0x3'));var jsonpatch=require(_0x375e('0x4'));var rp=require(_0x375e('0x5'));var moment=require(_0x375e('0x6'));var BPromise=require(_0x375e('0x7'));var Mustache=require(_0x375e('0x8'));var util=require(_0x375e('0x9'));var path=require(_0x375e('0xa'));var sox=require(_0x375e('0xb'));var csv=require(_0x375e('0xc'));var ejs=require(_0x375e('0xd'));var fs=require('fs');var _=require(_0x375e('0xe'));var squel=require(_0x375e('0xf'));var crypto=require('crypto');var jsforce=require(_0x375e('0x10'));var deskjs=require(_0x375e('0x11'));var toCsv=require('to-csv');var querystring=require(_0x375e('0x12'));var Papa=require('papaparse');var Redis=require(_0x375e('0x13'));var authService=require(_0x375e('0x14'));var qs=require(_0x375e('0x15'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x375e('0x16'));var logger=require(_0x375e('0x17'))('api');var utils=require('../../config/utils');var config=require(_0x375e('0x18'));var licenseUtil=require(_0x375e('0x19'));var db=require(_0x375e('0x1a'))['db'];config['redis']=_[_0x375e('0x1b')](config[_0x375e('0x1c')],{'host':_0x375e('0x1d'),'port':0x18eb});var socket=require(_0x375e('0x1e'))(new Redis(config[_0x375e('0x1c')]));require(_0x375e('0x1f'))[_0x375e('0x20')](socket);var jayson=require('jayson/promise');var client=jayson[_0x375e('0x21')][_0x375e('0x22')]({'port':0x232c});var client9002=jayson[_0x375e('0x21')][_0x375e('0x22')]({'port':0x232a});function respondWithRpcPromise(_0x58ea02,_0x49677d,_0x5c004d,_0x11e9b5){return new BPromise(function(_0x136d01,_0x4147cb){var _0x5b4dd5=_0x11e9b5||client;return _0x5b4dd5['request'](_0x58ea02,_0x5c004d)['then'](function(_0x41ba36){logger['info']('OpenchannelMessage,\x20%s,\x20%s',_0x49677d,'request\x20sent');logger[_0x375e('0x23')]('OpenchannelMessage,\x20%s,\x20%s,\x20%s',_0x49677d,_0x375e('0x24'),JSON[_0x375e('0x25')](_0x41ba36));if(_0x41ba36['error']){if(_0x41ba36[_0x375e('0x26')][_0x375e('0x27')]===0x1f4){logger[_0x375e('0x26')]('OpenchannelMessage,\x20%s,\x20%s',_0x49677d,_0x41ba36['error'][_0x375e('0x28')]);return _0x4147cb(_0x41ba36[_0x375e('0x26')][_0x375e('0x28')]);}logger[_0x375e('0x26')](_0x375e('0x29'),_0x49677d,_0x41ba36['error'][_0x375e('0x28')]);return _0x136d01(_0x41ba36['error'][_0x375e('0x28')]);}else{logger[_0x375e('0x2a')](_0x375e('0x29'),_0x49677d,'request\x20sent');_0x136d01(_0x41ba36['result'][_0x375e('0x28')]);}})[_0x375e('0x2b')](function(_0x42742b){logger[_0x375e('0x26')](_0x375e('0x29'),_0x49677d,_0x42742b);_0x4147cb(_0x42742b);});});}function respondWithStatusCode(_0x327a35,_0x5c5a61){_0x5c5a61=_0x5c5a61||0xcc;return function(_0x1803cb){if(_0x1803cb){return _0x327a35[_0x375e('0x2c')](_0x5c5a61);}return _0x327a35['status'](_0x5c5a61)[_0x375e('0x2d')]();};}function respondWithResult(_0x3fb032,_0x4d7645){_0x4d7645=_0x4d7645||0xc8;return function(_0x30f2fc){if(_0x30f2fc){return _0x3fb032[_0x375e('0x2e')](_0x4d7645)['json'](_0x30f2fc);}};}function respondWithFilteredResult(_0x107d0f,_0x4d7907){return function(_0x4dbc96){if(_0x4dbc96){var _0x2a39b3=_0x4dbc96[_0x375e('0x2f')],_0x4660e9=_0x4d7907[_0x375e('0x30')],_0x2fe616=_0x4d7907[_0x375e('0x30')]+_0x4d7907['limit'],_0x28ec30;if(_0x2fe616>=_0x2a39b3){_0x2fe616=_0x2a39b3;_0x28ec30=0xc8;}else{_0x28ec30=0xce;}_0x107d0f['status'](_0x28ec30);return _0x107d0f[_0x375e('0x31')]('Content-Range',_0x4660e9+'-'+_0x2fe616+'/'+_0x2a39b3)[_0x375e('0x32')](_0x4dbc96);}return null;};}function patchUpdates(_0x4f9094){return function(_0x2c281d){try{jsonpatch[_0x375e('0x33')](_0x2c281d,_0x4f9094,!![]);}catch(_0x4165d0){return BPromise[_0x375e('0x34')](_0x4165d0);}return _0x2c281d[_0x375e('0x35')]();};}function saveUpdates(_0x247bd1,_0x348839){return function(_0xca17ba){if(_0xca17ba){return _0xca17ba[_0x375e('0x36')](_0x247bd1)[_0x375e('0x37')](function(_0x4847fc){return _0x4847fc;});}return null;};}function removeEntity(_0x1e0be2,_0x170658){return function(_0x2a1ff5){if(_0x2a1ff5){return _0x2a1ff5[_0x375e('0x38')]()[_0x375e('0x37')](function(){_0x1e0be2[_0x375e('0x2e')](0xcc)['end']();});}};}function handleEntityNotFound(_0x32ca7,_0x4ec7db){return function(_0x32e8b9){if(!_0x32e8b9){_0x32ca7['sendStatus'](0x194);}return _0x32e8b9;};}function handleError(_0x4b2c55,_0xe35c98){_0xe35c98=_0xe35c98||0x1f4;return function(_0x717218){logger['error'](_0x717218[_0x375e('0x39')]);if(_0x717218[_0x375e('0x3a')]){delete _0x717218[_0x375e('0x3a')];}_0x4b2c55[_0x375e('0x2e')](_0xe35c98)[_0x375e('0x3b')](_0x717218);};}exports[_0x375e('0x3c')]=function(_0x554ad1,_0x380371){var _0x243cde={},_0x3744bc={},_0x544616={'count':0x0,'rows':[]};var _0x2f2e34=_[_0x375e('0x3d')](db['OpenchannelMessage'][_0x375e('0x3e')],function(_0xc8f6d2){return{'name':_0xc8f6d2[_0x375e('0x3f')],'type':_0xc8f6d2[_0x375e('0x40')][_0x375e('0x41')]};});_0x3744bc['model']=_[_0x375e('0x3d')](_0x2f2e34,_0x375e('0x3a'));_0x3744bc[_0x375e('0x42')]=_[_0x375e('0x43')](_0x554ad1[_0x375e('0x42')]);_0x3744bc['filters']=_[_0x375e('0x44')](_0x3744bc[_0x375e('0x45')],_0x3744bc[_0x375e('0x42')]);_0x243cde[_0x375e('0x46')]=_['intersection'](_0x3744bc[_0x375e('0x45')],qs['fields'](_0x554ad1[_0x375e('0x42')]['fields']));_0x243cde[_0x375e('0x46')]=_0x243cde['attributes'][_0x375e('0x47')]?_0x243cde[_0x375e('0x46')]:_0x3744bc[_0x375e('0x45')];if(!_0x554ad1[_0x375e('0x42')][_0x375e('0x48')](_0x375e('0x49'))){_0x243cde[_0x375e('0x4a')]=qs[_0x375e('0x4a')](_0x554ad1['query'][_0x375e('0x4a')]);_0x243cde[_0x375e('0x30')]=qs[_0x375e('0x30')](_0x554ad1[_0x375e('0x42')][_0x375e('0x30')]);}_0x243cde['order']=qs[_0x375e('0x4b')](_0x554ad1[_0x375e('0x42')][_0x375e('0x4b')]);_0x243cde[_0x375e('0x4c')]=qs['filters'](_[_0x375e('0x4d')](_0x554ad1[_0x375e('0x42')],_0x3744bc[_0x375e('0x4e')]),_0x2f2e34);if(_0x554ad1[_0x375e('0x42')][_0x375e('0x4f')]){_0x243cde[_0x375e('0x4c')]=_[_0x375e('0x50')](_0x243cde[_0x375e('0x4c')],{'$or':_[_0x375e('0x3d')](_0x2f2e34,function(_0xacc604){if(_0xacc604['type']!==_0x375e('0x51')){var _0x47dfd9={};_0x47dfd9[_0xacc604[_0x375e('0x3a')]]={'$like':'%'+_0x554ad1[_0x375e('0x42')][_0x375e('0x4f')]+'%'};return _0x47dfd9;}})});}_0x243cde=_[_0x375e('0x50')]({},_0x243cde,_0x554ad1[_0x375e('0x52')]);var _0x2e275e={'where':_0x243cde[_0x375e('0x4c')]};return db['OpenchannelMessage'][_0x375e('0x2f')](_0x2e275e)[_0x375e('0x37')](function(_0x377117){_0x544616[_0x375e('0x2f')]=_0x377117;if(_0x554ad1['query'][_0x375e('0x53')]){_0x243cde[_0x375e('0x54')]=[{'all':!![]}];}return db[_0x375e('0x55')][_0x375e('0x56')](_0x243cde);})['then'](function(_0x380a64){_0x544616[_0x375e('0x57')]=_0x380a64;return _0x544616;})[_0x375e('0x37')](respondWithFilteredResult(_0x380371,_0x243cde))['catch'](handleError(_0x380371,null));};exports[_0x375e('0x58')]=function(_0x5d769d,_0x559d82){var _0x24d38d={'raw':!![],'where':{'id':_0x5d769d[_0x375e('0x59')]['id']}},_0x37784b={};_0x37784b[_0x375e('0x45')]=_[_0x375e('0x43')](db[_0x375e('0x55')]['rawAttributes']);_0x37784b['query']=_[_0x375e('0x43')](_0x5d769d['query']);_0x37784b['filters']=_['intersection'](_0x37784b[_0x375e('0x45')],_0x37784b[_0x375e('0x42')]);_0x24d38d['attributes']=_[_0x375e('0x44')](_0x37784b['model'],qs[_0x375e('0x5a')](_0x5d769d[_0x375e('0x42')]['fields']));_0x24d38d['attributes']=_0x24d38d[_0x375e('0x46')][_0x375e('0x47')]?_0x24d38d[_0x375e('0x46')]:_0x37784b[_0x375e('0x45')];if(_0x5d769d[_0x375e('0x42')]['includeAll']){_0x24d38d[_0x375e('0x54')]=[{'all':!![]}];}_0x24d38d=_['merge']({},_0x24d38d,_0x5d769d[_0x375e('0x52')]);return db[_0x375e('0x55')][_0x375e('0x5b')](_0x24d38d)[_0x375e('0x37')](handleEntityNotFound(_0x559d82,null))[_0x375e('0x37')](respondWithResult(_0x559d82,null))[_0x375e('0x2b')](handleError(_0x559d82,null));};exports[_0x375e('0x5c')]=function(_0x4fa3d6,_0x5b50ef){return db[_0x375e('0x55')][_0x375e('0x5c')](_0x4fa3d6[_0x375e('0x5d')],{})[_0x375e('0x37')](respondWithResult(_0x5b50ef,0xc9))['catch'](handleError(_0x5b50ef,null));};exports[_0x375e('0x36')]=function(_0x44e8e4,_0xd8fb95){if(_0x44e8e4[_0x375e('0x5d')]['id']){delete _0x44e8e4[_0x375e('0x5d')]['id'];}return db[_0x375e('0x55')][_0x375e('0x5b')]({'where':{'id':_0x44e8e4[_0x375e('0x59')]['id']}})[_0x375e('0x37')](handleEntityNotFound(_0xd8fb95,null))[_0x375e('0x37')](saveUpdates(_0x44e8e4[_0x375e('0x5d')],null))['then'](respondWithResult(_0xd8fb95,null))[_0x375e('0x2b')](handleError(_0xd8fb95,null));};exports[_0x375e('0x38')]=function(_0x1fc947,_0x4a0d97){return db[_0x375e('0x55')][_0x375e('0x5b')]({'where':{'id':_0x1fc947[_0x375e('0x59')]['id']}})[_0x375e('0x37')](handleEntityNotFound(_0x4a0d97,null))['then'](removeEntity(_0x4a0d97,null))[_0x375e('0x2b')](handleError(_0x4a0d97,null));};exports[_0x375e('0x5e')]=function(_0x163bdc,_0x17b65f){return db[_0x375e('0x55')]['describe']()[_0x375e('0x37')](respondWithResult(_0x17b65f,null))[_0x375e('0x2b')](handleError(_0x17b65f,null));};var interaction_log=require('../../config/logger')(_0x375e('0x5f'));exports[_0x375e('0x60')]=function(_0x2956a0,_0x240e37,_0x25597f){var _0x10fdff={'agent':{},'channel':_0x375e('0x61')};if(_0x2956a0[_0x375e('0x5d')]['id']){delete _0x2956a0[_0x375e('0x5d')]['id'];}_0x2956a0[_0x375e('0x5d')]['read']=!![];_0x2956a0['body'][_0x375e('0x62')]=moment()[_0x375e('0x63')](_0x375e('0x64'));_0x2956a0[_0x375e('0x5d')][_0x375e('0x65')]=_0x2956a0['body'][_0x375e('0x65')]||_0x2956a0['user']['id'];_0x10fdff[_0x375e('0x66')]['id']=_0x2956a0['body'][_0x375e('0x65')];return db[_0x375e('0x55')]['find']({'where':{'id':_0x2956a0[_0x375e('0x59')]['id'],'UserId':null},'include':[{'model':db[_0x375e('0x67')],'as':'Contact'}]})[_0x375e('0x37')](handleEntityNotFound(_0x240e37,null))[_0x375e('0x37')](saveUpdates(_0x2956a0['body'],null))[_0x375e('0x37')](function(_0x292c62){if(_0x292c62){_0x10fdff[_0x375e('0x28')]=_0x292c62[_0x375e('0x68')]({'plain':!![]});return db[_0x375e('0x69')][_0x375e('0x5b')]({'where':{'id':_0x292c62['OpenchannelInteractionId']}});}return null;})[_0x375e('0x37')](handleEntityNotFound(_0x240e37,null))[_0x375e('0x37')](function(_0x29b1b3){if(_0x29b1b3){return _0x29b1b3['update']({'UserId':_0x2956a0[_0x375e('0x5d')][_0x375e('0x65')],'read1stAt':_[_0x375e('0x6a')](_0x29b1b3['read1stAt'])?moment()[_0x375e('0x63')](_0x375e('0x64')):undefined});}return null;})[_0x375e('0x37')](function(_0x1bf1a0){if(_0x1bf1a0){_0x10fdff[_0x375e('0x6b')]=_0x1bf1a0[_0x375e('0x68')]({'plain':!![]});interaction_log[_0x375e('0x2a')](_0x375e('0x6c'),_0x2956a0[_0x375e('0x6d')]['id'],_0x2956a0[_0x375e('0x6d')][_0x375e('0x3a')],_0x2956a0[_0x375e('0x6d')][_0x375e('0x6e')],_0x10fdff[_0x375e('0x6b')]['id'],_0x2956a0[_0x375e('0x5d')]?JSON[_0x375e('0x25')](_0x2956a0[_0x375e('0x5d')]):_0x375e('0x6f'));return respondWithRpcPromise(_0x375e('0x70'),_0x375e('0x71'),_0x10fdff);}return null;})[_0x375e('0x37')](function(_0x49f21f){if(_0x49f21f){if(_0x2956a0[_0x375e('0x5d')][_0x375e('0x72')]){_0x10fdff[_0x375e('0x28')][_0x375e('0x73')]=util[_0x375e('0x63')](_0x375e('0x74'),_0x2956a0[_0x375e('0x6d')][_0x375e('0x3a')]);_0x10fdff[_0x375e('0x28')]['channel']=_0x10fdff['channel'];_0x10fdff[_0x375e('0x28')][_0x375e('0x75')]=_0x375e('0x60');return respondWithRpcPromise(_0x375e('0x76'),_0x375e('0x76'),{'event':_0x375e('0x77'),'message':_0x10fdff[_0x375e('0x28')]},client9002)[_0x375e('0x37')](function(){return _0x10fdff;});}return _0x10fdff;}return null;})[_0x375e('0x37')](respondWithResult(_0x240e37,null))[_0x375e('0x2b')](handleError(_0x240e37,null));};var interaction_log=require(_0x375e('0x17'))('openchannel-interactions');exports['reject']=function(_0x276fa8,_0x12926f,_0x42fb0e){var _0x209d72={'agent':{},'channel':_0x375e('0x61')};if(_0x276fa8[_0x375e('0x5d')]['id']){delete _0x276fa8['body']['id'];}_0x276fa8['body'][_0x375e('0x65')]=_0x276fa8[_0x375e('0x5d')][_0x375e('0x65')]||_0x276fa8[_0x375e('0x6d')]['id'];_0x209d72['agent']['id']=_0x276fa8[_0x375e('0x5d')][_0x375e('0x65')];return db[_0x375e('0x55')]['find']({'where':{'id':_0x276fa8['params']['id'],'UserId':null}})['then'](handleEntityNotFound(_0x12926f,null))[_0x375e('0x37')](function(_0x5e40f8){if(_0x5e40f8){_0x209d72[_0x375e('0x28')]=_0x5e40f8[_0x375e('0x68')]({'plain':!![]});return db[_0x375e('0x69')][_0x375e('0x5b')]({'where':{'id':_0x5e40f8[_0x375e('0x78')]}});}return null;})[_0x375e('0x37')](handleEntityNotFound(_0x12926f,null))['then'](function(_0x151a71){if(_0x151a71){_0x209d72[_0x375e('0x6b')]=_0x151a71[_0x375e('0x68')]({'plain':!![]});interaction_log[_0x375e('0x2a')]('[OPENCHANNELMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x276fa8[_0x375e('0x6d')]['id'],_0x276fa8[_0x375e('0x6d')]['name'],_0x276fa8['user'][_0x375e('0x6e')],_0x209d72[_0x375e('0x6b')]['id'],_0x276fa8[_0x375e('0x5d')]?JSON[_0x375e('0x25')](_0x276fa8[_0x375e('0x5d')]):'null');return respondWithRpcPromise(_0x375e('0x79'),_0x375e('0x7a'),_0x209d72);}return null;})[_0x375e('0x37')](function(_0x1c19a8){if(_0x1c19a8){_0x1c19a8[_0x375e('0x28')][_0x375e('0x73')]=util[_0x375e('0x63')](_0x375e('0x74'),_0x276fa8[_0x375e('0x6d')]['name']);_0x1c19a8[_0x375e('0x28')]['channel']=_0x209d72[_0x375e('0x7b')];_0x1c19a8[_0x375e('0x28')][_0x375e('0x75')]=_0x375e('0x34');respondWithRpcPromise(_0x375e('0x76'),_0x375e('0x76'),{'event':_0x375e('0x7c'),'message':_0x1c19a8[_0x375e('0x28')]},client9002);return _0x209d72;}return null;})[_0x375e('0x37')](respondWithResult(_0x12926f,null))[_0x375e('0x2b')](handleError(_0x12926f,null));};
\ No newline at end of file
+var _0x1db0=['save','update','destroy','end','name','send','index','map','OpenchannelMessage','fieldName','type','key','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','sort','where','pick','filter','merge','VIRTUAL','include','findAll','show','params','rawAttributes','includeAll','options','find','create','body','describe','openchannel','read','format','UserId','agent','OpenchannelInteraction','OpenchannelInteractionId','isNil','interaction','[OPENCHANNELMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','user','role','null','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','sequelize','SELECT','fullname','email','internal','manual','interface','SIP/%s','channel','motionChannel','event','accept','EventManager','acceptmessage','reject','get','[OPENCHANNELMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','ContactId','Sequelize','QueryTypes','contact','User','rejectmessage','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./openchannelMessage.socket','jayson/promise','client','http','request','then','info','request\x20sent','OpenchannelMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','OpenchannelMessage,\x20%s,\x20%s','message','result','catch','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range'];(function(_0x19950b,_0x53d0d7){var _0x3c6b41=function(_0x3924ad){while(--_0x3924ad){_0x19950b['push'](_0x19950b['shift']());}};_0x3c6b41(++_0x53d0d7);}(_0x1db0,0x1e8));var _0x01db=function(_0x5ed32c,_0x956025){_0x5ed32c=_0x5ed32c-0x0;var _0x271ea3=_0x1db0[_0x5ed32c];return _0x271ea3;};'use strict';var emlformat=require(_0x01db('0x0'));var rimraf=require(_0x01db('0x1'));var zipdir=require(_0x01db('0x2'));var jsonpatch=require(_0x01db('0x3'));var rp=require(_0x01db('0x4'));var moment=require('moment');var BPromise=require(_0x01db('0x5'));var Mustache=require(_0x01db('0x6'));var util=require(_0x01db('0x7'));var path=require(_0x01db('0x8'));var sox=require(_0x01db('0x9'));var csv=require(_0x01db('0xa'));var ejs=require(_0x01db('0xb'));var fs=require('fs');var fs_extra=require(_0x01db('0xc'));var _=require(_0x01db('0xd'));var squel=require(_0x01db('0xe'));var crypto=require('crypto');var jsforce=require(_0x01db('0xf'));var deskjs=require(_0x01db('0x10'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x01db('0x11'));var Redis=require('ioredis');var authService=require(_0x01db('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0x01db('0x13'));var hardwareService=require(_0x01db('0x14'));var logger=require(_0x01db('0x15'))(_0x01db('0x16'));var utils=require(_0x01db('0x17'));var config=require(_0x01db('0x18'));var licenseUtil=require(_0x01db('0x19'));var db=require(_0x01db('0x1a'))['db'];config[_0x01db('0x1b')]=_[_0x01db('0x1c')](config[_0x01db('0x1b')],{'host':_0x01db('0x1d'),'port':0x18eb});var socket=require(_0x01db('0x1e'))(new Redis(config['redis']));require(_0x01db('0x1f'))['register'](socket);var jayson=require(_0x01db('0x20'));var client=jayson[_0x01db('0x21')][_0x01db('0x22')]({'port':0x232c});var client9002=jayson[_0x01db('0x21')]['http']({'port':0x232a});function respondWithRpcPromise(_0x2f31b0,_0x827f5c,_0x14997d,_0x5c2984){return new BPromise(function(_0x1b7eb3,_0x42c0af){var _0xe742be=_0x5c2984||client;return _0xe742be[_0x01db('0x23')](_0x2f31b0,_0x14997d)[_0x01db('0x24')](function(_0x3a10a6){logger[_0x01db('0x25')]('OpenchannelMessage,\x20%s,\x20%s',_0x827f5c,_0x01db('0x26'));logger['debug'](_0x01db('0x27'),_0x827f5c,_0x01db('0x26'),JSON[_0x01db('0x28')](_0x3a10a6));if(_0x3a10a6[_0x01db('0x29')]){if(_0x3a10a6[_0x01db('0x29')][_0x01db('0x2a')]===0x1f4){logger[_0x01db('0x29')](_0x01db('0x2b'),_0x827f5c,_0x3a10a6[_0x01db('0x29')][_0x01db('0x2c')]);return _0x42c0af(_0x3a10a6['error'][_0x01db('0x2c')]);}logger[_0x01db('0x29')](_0x01db('0x2b'),_0x827f5c,_0x3a10a6['error'][_0x01db('0x2c')]);return _0x1b7eb3(_0x3a10a6['error']['message']);}else{logger[_0x01db('0x25')]('OpenchannelMessage,\x20%s,\x20%s',_0x827f5c,'request\x20sent');_0x1b7eb3(_0x3a10a6[_0x01db('0x2d')][_0x01db('0x2c')]);}})[_0x01db('0x2e')](function(_0xee3e11){logger[_0x01db('0x29')](_0x01db('0x2b'),_0x827f5c,_0xee3e11);_0x42c0af(_0xee3e11);});});}function respondWithStatusCode(_0xc38354,_0x1fccaa){_0x1fccaa=_0x1fccaa||0xcc;return function(_0x262b01){if(_0x262b01){return _0xc38354[_0x01db('0x2f')](_0x1fccaa);}return _0xc38354['status'](_0x1fccaa)['end']();};}function respondWithResult(_0x43a122,_0xb6f086){_0xb6f086=_0xb6f086||0xc8;return function(_0x257687){if(_0x257687){return _0x43a122[_0x01db('0x30')](_0xb6f086)[_0x01db('0x31')](_0x257687);}};}function respondWithFilteredResult(_0x4fa8c7,_0x18ff9a){return function(_0x44eb7d){if(_0x44eb7d){var _0x26733b=typeof _0x18ff9a[_0x01db('0x32')]===_0x01db('0x33')&&typeof _0x18ff9a[_0x01db('0x34')]===_0x01db('0x33');var _0x3267e7=_0x44eb7d[_0x01db('0x35')];var _0x11f351=_0x26733b?0x0:_0x18ff9a[_0x01db('0x32')];var _0x1b7ab6=_0x26733b?_0x44eb7d[_0x01db('0x35')]:_0x18ff9a[_0x01db('0x32')]+_0x18ff9a[_0x01db('0x34')];var _0x5a251c;if(_0x1b7ab6>=_0x3267e7){_0x1b7ab6=_0x3267e7;_0x5a251c=0xc8;}else{_0x5a251c=0xce;}_0x4fa8c7[_0x01db('0x30')](_0x5a251c);return _0x4fa8c7[_0x01db('0x36')](_0x01db('0x37'),_0x11f351+'-'+_0x1b7ab6+'/'+_0x3267e7)[_0x01db('0x31')](_0x44eb7d);}return null;};}function patchUpdates(_0x50c893){return function(_0x16c3f7){try{jsonpatch['apply'](_0x16c3f7,_0x50c893,!![]);}catch(_0x39de93){return BPromise['reject'](_0x39de93);}return _0x16c3f7[_0x01db('0x38')]();};}function saveUpdates(_0x33cb4a,_0x1b1801){return function(_0x3c7a55){if(_0x3c7a55){return _0x3c7a55[_0x01db('0x39')](_0x33cb4a)['then'](function(_0x340bce){return _0x340bce;});}return null;};}function removeEntity(_0x2f33d5,_0x57096f){return function(_0x31a052){if(_0x31a052){return _0x31a052[_0x01db('0x3a')]()[_0x01db('0x24')](function(){_0x2f33d5['status'](0xcc)[_0x01db('0x3b')]();});}};}function handleEntityNotFound(_0x333882,_0x2bd06b){return function(_0x4a42bf){if(!_0x4a42bf){_0x333882[_0x01db('0x2f')](0x194);}return _0x4a42bf;};}function handleError(_0x1102f7,_0x1ad048){_0x1ad048=_0x1ad048||0x1f4;return function(_0x52d304){logger[_0x01db('0x29')](_0x52d304['stack']);if(_0x52d304[_0x01db('0x3c')]){delete _0x52d304[_0x01db('0x3c')];}_0x1102f7[_0x01db('0x30')](_0x1ad048)[_0x01db('0x3d')](_0x52d304);};}exports[_0x01db('0x3e')]=function(_0x47635c,_0x1f5d22){var _0x395df2={},_0x4b2ffe={},_0x1b243d={'count':0x0,'rows':[]};var _0x1c1467=_[_0x01db('0x3f')](db[_0x01db('0x40')]['rawAttributes'],function(_0x45a8cf){return{'name':_0x45a8cf[_0x01db('0x41')],'type':_0x45a8cf[_0x01db('0x42')][_0x01db('0x43')]};});_0x4b2ffe['model']=_[_0x01db('0x3f')](_0x1c1467,_0x01db('0x3c'));_0x4b2ffe[_0x01db('0x44')]=_[_0x01db('0x45')](_0x47635c[_0x01db('0x44')]);_0x4b2ffe[_0x01db('0x46')]=_[_0x01db('0x47')](_0x4b2ffe[_0x01db('0x48')],_0x4b2ffe['query']);_0x395df2[_0x01db('0x49')]=_[_0x01db('0x47')](_0x4b2ffe['model'],qs[_0x01db('0x4a')](_0x47635c['query'][_0x01db('0x4a')]));_0x395df2[_0x01db('0x49')]=_0x395df2[_0x01db('0x49')][_0x01db('0x4b')]?_0x395df2[_0x01db('0x49')]:_0x4b2ffe[_0x01db('0x48')];if(!_0x47635c[_0x01db('0x44')][_0x01db('0x4c')](_0x01db('0x4d'))){_0x395df2[_0x01db('0x34')]=qs[_0x01db('0x34')](_0x47635c[_0x01db('0x44')][_0x01db('0x34')]);_0x395df2['offset']=qs[_0x01db('0x32')](_0x47635c[_0x01db('0x44')][_0x01db('0x32')]);}_0x395df2['order']=qs[_0x01db('0x4e')](_0x47635c[_0x01db('0x44')][_0x01db('0x4e')]);_0x395df2[_0x01db('0x4f')]=qs[_0x01db('0x46')](_[_0x01db('0x50')](_0x47635c['query'],_0x4b2ffe[_0x01db('0x46')]),_0x1c1467);if(_0x47635c[_0x01db('0x44')][_0x01db('0x51')]){_0x395df2['where']=_[_0x01db('0x52')](_0x395df2[_0x01db('0x4f')],{'$or':_['map'](_0x1c1467,function(_0x55ec59){if(_0x55ec59['type']!==_0x01db('0x53')){var _0xf66728={};_0xf66728[_0x55ec59[_0x01db('0x3c')]]={'$like':'%'+_0x47635c['query'][_0x01db('0x51')]+'%'};return _0xf66728;}})});}_0x395df2=_['merge']({},_0x395df2,_0x47635c['options']);var _0x7fb2={'where':_0x395df2['where']};return db[_0x01db('0x40')][_0x01db('0x35')](_0x7fb2)[_0x01db('0x24')](function(_0xd91fd9){_0x1b243d[_0x01db('0x35')]=_0xd91fd9;if(_0x47635c[_0x01db('0x44')]['includeAll']){_0x395df2[_0x01db('0x54')]=[{'all':!![]}];}return db['OpenchannelMessage'][_0x01db('0x55')](_0x395df2);})[_0x01db('0x24')](function(_0x33a748){_0x1b243d['rows']=_0x33a748;return _0x1b243d;})[_0x01db('0x24')](respondWithFilteredResult(_0x1f5d22,_0x395df2))['catch'](handleError(_0x1f5d22,null));};exports[_0x01db('0x56')]=function(_0x3898dc,_0x19e832){var _0x5847fc={'raw':!![],'where':{'id':_0x3898dc[_0x01db('0x57')]['id']}},_0x2b43a2={};_0x2b43a2[_0x01db('0x48')]=_['keys'](db['OpenchannelMessage'][_0x01db('0x58')]);_0x2b43a2[_0x01db('0x44')]=_[_0x01db('0x45')](_0x3898dc[_0x01db('0x44')]);_0x2b43a2[_0x01db('0x46')]=_['intersection'](_0x2b43a2['model'],_0x2b43a2[_0x01db('0x44')]);_0x5847fc[_0x01db('0x49')]=_[_0x01db('0x47')](_0x2b43a2[_0x01db('0x48')],qs[_0x01db('0x4a')](_0x3898dc[_0x01db('0x44')]['fields']));_0x5847fc[_0x01db('0x49')]=_0x5847fc[_0x01db('0x49')][_0x01db('0x4b')]?_0x5847fc['attributes']:_0x2b43a2[_0x01db('0x48')];if(_0x3898dc[_0x01db('0x44')][_0x01db('0x59')]){_0x5847fc['include']=[{'all':!![]}];}_0x5847fc=_[_0x01db('0x52')]({},_0x5847fc,_0x3898dc[_0x01db('0x5a')]);return db[_0x01db('0x40')][_0x01db('0x5b')](_0x5847fc)[_0x01db('0x24')](handleEntityNotFound(_0x19e832,null))[_0x01db('0x24')](respondWithResult(_0x19e832,null))[_0x01db('0x2e')](handleError(_0x19e832,null));};exports[_0x01db('0x5c')]=function(_0x2019aa,_0x2268a6){return db['OpenchannelMessage'][_0x01db('0x5c')](_0x2019aa[_0x01db('0x5d')],{})[_0x01db('0x24')](respondWithResult(_0x2268a6,0xc9))[_0x01db('0x2e')](handleError(_0x2268a6,null));};exports[_0x01db('0x39')]=function(_0x5b4813,_0x205603){if(_0x5b4813[_0x01db('0x5d')]['id']){delete _0x5b4813['body']['id'];}return db[_0x01db('0x40')]['find']({'where':{'id':_0x5b4813[_0x01db('0x57')]['id']}})[_0x01db('0x24')](handleEntityNotFound(_0x205603,null))[_0x01db('0x24')](saveUpdates(_0x5b4813[_0x01db('0x5d')],null))[_0x01db('0x24')](respondWithResult(_0x205603,null))['catch'](handleError(_0x205603,null));};exports[_0x01db('0x3a')]=function(_0x2b7cee,_0x496497){return db[_0x01db('0x40')][_0x01db('0x5b')]({'where':{'id':_0x2b7cee[_0x01db('0x57')]['id']}})['then'](handleEntityNotFound(_0x496497,null))['then'](removeEntity(_0x496497,null))[_0x01db('0x2e')](handleError(_0x496497,null));};exports[_0x01db('0x5e')]=function(_0x375265,_0x5c12d5){return db[_0x01db('0x40')][_0x01db('0x5e')]()[_0x01db('0x24')](respondWithResult(_0x5c12d5,null))[_0x01db('0x2e')](handleError(_0x5c12d5,null));};var interaction_log=require(_0x01db('0x15'))('openchannel-interactions');exports['accept']=function(_0x24edf2,_0x1e996c,_0x44b176){var _0x16120b={'agent':{},'channel':_0x01db('0x5f')};if(_0x24edf2['body']['id']){delete _0x24edf2[_0x01db('0x5d')]['id'];}_0x24edf2['body'][_0x01db('0x60')]=!![];_0x24edf2['body']['readAt']=moment()[_0x01db('0x61')]('YYYY-MM-DD\x20HH:mm:ss');_0x24edf2[_0x01db('0x5d')][_0x01db('0x62')]=_0x24edf2['body'][_0x01db('0x62')]||_0x24edf2['user']['id'];_0x16120b[_0x01db('0x63')]['id']=_0x24edf2[_0x01db('0x5d')][_0x01db('0x62')];return db['OpenchannelMessage'][_0x01db('0x5b')]({'where':{'id':_0x24edf2['params']['id'],'UserId':null}})[_0x01db('0x24')](handleEntityNotFound(_0x1e996c,null))[_0x01db('0x24')](saveUpdates(_0x24edf2[_0x01db('0x5d')],null))['then'](function(_0x208b0c){if(_0x208b0c){_0x16120b[_0x01db('0x2c')]=_0x208b0c['get']({'plain':!![]});return db[_0x01db('0x64')][_0x01db('0x5b')]({'where':{'id':_0x208b0c[_0x01db('0x65')]}});}return null;})['then'](handleEntityNotFound(_0x1e996c,null))[_0x01db('0x24')](function(_0xf91d55){if(_0xf91d55){return _0xf91d55[_0x01db('0x39')]({'UserId':_0x24edf2[_0x01db('0x5d')]['UserId'],'read1stAt':_[_0x01db('0x66')](_0xf91d55['read1stAt'])?moment()[_0x01db('0x61')]('YYYY-MM-DD\x20HH:mm:ss'):undefined});}return null;})['then'](function(_0x4404ec){if(_0x4404ec){_0x16120b[_0x01db('0x67')]=_0x4404ec['get']({'plain':!![]});interaction_log[_0x01db('0x25')](_0x01db('0x68'),_0x24edf2['user']['id'],_0x24edf2[_0x01db('0x69')][_0x01db('0x3c')],_0x24edf2[_0x01db('0x69')][_0x01db('0x6a')],_0x16120b[_0x01db('0x67')]['id'],_0x24edf2['body']?JSON[_0x01db('0x28')](_0x24edf2['body']):_0x01db('0x6b'));return respondWithRpcPromise(_0x01db('0x6c'),_0x01db('0x6d'),_0x16120b);}return null;})[_0x01db('0x24')](function(_0x3b9972){var _0x1c0eca=_0x01db('0x6e')+_0x3b9972[_0x01db('0x2c')]['ContactId'];return db[_0x01db('0x6f')][_0x01db('0x44')](_0x1c0eca,{'type':db['Sequelize']['QueryTypes'][_0x01db('0x70')],'raw':!![]})[_0x01db('0x24')](function(_0x2595e8){return _0x2595e8;});})[_0x01db('0x24')](function(_0x2f1392){if(_0x2f1392){_0x16120b[_0x01db('0x2c')]['contact']=_0x2f1392[0x0];if(!_0x24edf2[_0x01db('0x5d')][_0x01db('0x62')])return;return db['User']['find']({'where':{'id':_0x24edf2[_0x01db('0x5d')][_0x01db('0x62')],'role':_0x01db('0x63')},'attributes':['id',_0x01db('0x3c'),_0x01db('0x71'),_0x01db('0x72'),_0x01db('0x73')],'raw':!![]});}return null;})[_0x01db('0x24')](function(_0x34b068){if(!_0x34b068)return null;_0x16120b[_0x01db('0x2c')][_0x01db('0x63')]=_0x34b068;return _0x16120b;})[_0x01db('0x24')](function(_0x2ff396){if(_0x2ff396){if(_0x24edf2[_0x01db('0x5d')][_0x01db('0x74')]){_0x16120b['message'][_0x01db('0x75')]=util['format'](_0x01db('0x76'),_0x24edf2[_0x01db('0x69')][_0x01db('0x3c')]);_0x16120b[_0x01db('0x2c')][_0x01db('0x77')]=_0x16120b['channel'];_0x16120b[_0x01db('0x2c')][_0x01db('0x78')]=_0x16120b[_0x01db('0x77')];_0x16120b[_0x01db('0x2c')][_0x01db('0x79')]=_0x01db('0x7a');return respondWithRpcPromise(_0x01db('0x7b'),_0x01db('0x7b'),{'event':_0x01db('0x7c'),'message':_0x16120b[_0x01db('0x2c')]},client9002)[_0x01db('0x24')](function(){return _0x16120b;});}return _0x16120b;}return null;})[_0x01db('0x24')](respondWithResult(_0x1e996c,null))[_0x01db('0x2e')](handleError(_0x1e996c,null));};var interaction_log=require(_0x01db('0x15'))('openchannel-interactions');exports[_0x01db('0x7d')]=function(_0x287455,_0x58207b,_0x57b9e9){var _0x7e998b={'agent':{},'channel':_0x01db('0x5f')};if(_0x287455[_0x01db('0x5d')]['id']){delete _0x287455[_0x01db('0x5d')]['id'];}_0x287455['body'][_0x01db('0x62')]=_0x287455[_0x01db('0x5d')][_0x01db('0x62')]||_0x287455[_0x01db('0x69')]['id'];_0x7e998b[_0x01db('0x63')]['id']=_0x287455[_0x01db('0x5d')][_0x01db('0x62')];return db['OpenchannelMessage'][_0x01db('0x5b')]({'where':{'id':_0x287455[_0x01db('0x57')]['id'],'UserId':null}})[_0x01db('0x24')](handleEntityNotFound(_0x58207b,null))['then'](function(_0x885b2){if(_0x885b2){_0x7e998b[_0x01db('0x2c')]=_0x885b2[_0x01db('0x7e')]({'plain':!![]});return db['OpenchannelInteraction']['find']({'where':{'id':_0x885b2[_0x01db('0x65')]}});}return null;})[_0x01db('0x24')](handleEntityNotFound(_0x58207b,null))['then'](function(_0x38a2f7){if(_0x38a2f7){_0x7e998b[_0x01db('0x67')]=_0x38a2f7[_0x01db('0x7e')]({'plain':!![]});interaction_log[_0x01db('0x25')](_0x01db('0x7f'),_0x287455[_0x01db('0x69')]['id'],_0x287455[_0x01db('0x69')][_0x01db('0x3c')],_0x287455[_0x01db('0x69')][_0x01db('0x6a')],_0x7e998b[_0x01db('0x67')]['id'],_0x287455[_0x01db('0x5d')]?JSON[_0x01db('0x28')](_0x287455[_0x01db('0x5d')]):_0x01db('0x6b'));return respondWithRpcPromise(_0x01db('0x80'),_0x01db('0x81'),_0x7e998b);}return null;})[_0x01db('0x24')](function(_0x4a1926){var _0x28633c=_0x01db('0x6e')+_0x4a1926[_0x01db('0x2c')][_0x01db('0x82')];return db[_0x01db('0x6f')][_0x01db('0x44')](_0x28633c,{'type':db[_0x01db('0x83')][_0x01db('0x84')][_0x01db('0x70')],'raw':!![]})[_0x01db('0x24')](function(_0x57cf63){return _0x57cf63;});})[_0x01db('0x24')](function(_0xabd940){if(_0xabd940){_0x7e998b[_0x01db('0x2c')][_0x01db('0x85')]=_0xabd940[0x0];if(!_0x287455['body']['UserId'])return;return db[_0x01db('0x86')][_0x01db('0x5b')]({'where':{'id':_0x287455[_0x01db('0x5d')][_0x01db('0x62')],'role':_0x01db('0x63')},'attributes':['id','name',_0x01db('0x71'),'email',_0x01db('0x73')],'raw':!![]});}return null;})[_0x01db('0x24')](function(_0x5efd5e){if(!_0x5efd5e)return null;_0x7e998b[_0x01db('0x2c')][_0x01db('0x63')]=_0x5efd5e;return _0x7e998b;})['then'](function(_0x3ec194){if(_0x3ec194){_0x3ec194[_0x01db('0x2c')][_0x01db('0x75')]=util[_0x01db('0x61')](_0x01db('0x76'),_0x287455[_0x01db('0x69')][_0x01db('0x3c')]);_0x3ec194['message'][_0x01db('0x77')]=_0x7e998b[_0x01db('0x77')];_0x3ec194[_0x01db('0x2c')][_0x01db('0x78')]=_0x7e998b['channel'];_0x3ec194[_0x01db('0x2c')][_0x01db('0x79')]='reject';respondWithRpcPromise('EventManager',_0x01db('0x7b'),{'event':_0x01db('0x87'),'message':_0x3ec194[_0x01db('0x2c')]},client9002);return _0x7e998b;}return null;})[_0x01db('0x24')](respondWithResult(_0x58207b,null))['catch'](handleError(_0x58207b,null));};
\ No newline at end of file