Built motion from commit (unavailable).|2.5.15
[motion2.git] / server / api / openchannelMessage / openchannelMessage.controller.js
index 4e713b9..5d03460 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x9d02=['includeAll','findAll','rows','show','params','rawAttributes','keys','include','find','create','body','describe','accept','openchannel','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','CmContact','Contact','get','OpenchannelInteractionId','isNil','read1stAt','user','interaction','null','AcceptMessage','acceptMessage','manual','interface','channel','event','EventManager','acceptmessage','openchannel-interactions','agent','OpenchannelInteraction','[OPENCHANNELMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','rejectMessage','html-pdf','rimraf','fast-json-patch','moment','bluebird','util','path','sox','squel','crypto','desk.js','to-csv','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','register','jayson/promise','client','http','request','then','info','request\x20sent','debug','OpenchannelMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','OpenchannelMessage,\x20%s,\x20%s','message','result','catch','sendStatus','status','json','count','offset','set','Content-Range','apply','reject','update','destroy','stack','name','map','OpenchannelMessage','fieldName','type','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','where','pick','filter','merge','VIRTUAL','options'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x9d02,0x118));var _0x29d0=function(_0x1a0c8c,_0x531752){_0x1a0c8c=_0x1a0c8c-0x0;var _0x1fb71a=_0x9d02[_0x1a0c8c];return _0x1fb71a;};'use strict';var pdf=require(_0x29d0('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x29d0('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x29d0('0x2'));var rp=require('request-promise');var moment=require(_0x29d0('0x3'));var BPromise=require(_0x29d0('0x4'));var Mustache=require('mustache');var util=require(_0x29d0('0x5'));var path=require(_0x29d0('0x6'));var sox=require(_0x29d0('0x7'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0x29d0('0x8'));var crypto=require(_0x29d0('0x9'));var jsforce=require('jsforce');var deskjs=require(_0x29d0('0xa'));var toCsv=require(_0x29d0('0xb'));var querystring=require('querystring');var Papa=require(_0x29d0('0xc'));var Redis=require(_0x29d0('0xd'));var authService=require('../../components/auth/service');var qs=require(_0x29d0('0xe'));var as=require(_0x29d0('0xf'));var hardwareService=require(_0x29d0('0x10'));var logger=require(_0x29d0('0x11'))('api');var utils=require('../../config/utils');var config=require(_0x29d0('0x12'));var licenseUtil=require(_0x29d0('0x13'));var db=require(_0x29d0('0x14'))['db'];config[_0x29d0('0x15')]=_[_0x29d0('0x16')](config[_0x29d0('0x15')],{'host':_0x29d0('0x17'),'port':0x18eb});var socket=require(_0x29d0('0x18'))(new Redis(config[_0x29d0('0x15')]));require('./openchannelMessage.socket')[_0x29d0('0x19')](socket);var jayson=require(_0x29d0('0x1a'));var client=jayson[_0x29d0('0x1b')][_0x29d0('0x1c')]({'port':0x232c});var client9002=jayson[_0x29d0('0x1b')][_0x29d0('0x1c')]({'port':0x232a});function respondWithRpcPromise(_0x55ba12,_0x24562f,_0x1826d0,_0x75a016){return new BPromise(function(_0x49e919,_0x2f30a5){var _0x6964fa=_0x75a016||client;return _0x6964fa[_0x29d0('0x1d')](_0x55ba12,_0x1826d0)[_0x29d0('0x1e')](function(_0x2b83e7){logger[_0x29d0('0x1f')]('OpenchannelMessage,\x20%s,\x20%s',_0x24562f,_0x29d0('0x20'));logger[_0x29d0('0x21')](_0x29d0('0x22'),_0x24562f,_0x29d0('0x20'),JSON[_0x29d0('0x23')](_0x2b83e7));if(_0x2b83e7[_0x29d0('0x24')]){if(_0x2b83e7['error'][_0x29d0('0x25')]===0x1f4){logger[_0x29d0('0x24')](_0x29d0('0x26'),_0x24562f,_0x2b83e7['error'][_0x29d0('0x27')]);return _0x2f30a5(_0x2b83e7[_0x29d0('0x24')][_0x29d0('0x27')]);}logger[_0x29d0('0x24')]('OpenchannelMessage,\x20%s,\x20%s',_0x24562f,_0x2b83e7[_0x29d0('0x24')][_0x29d0('0x27')]);return _0x49e919(_0x2b83e7[_0x29d0('0x24')]['message']);}else{logger[_0x29d0('0x1f')](_0x29d0('0x26'),_0x24562f,_0x29d0('0x20'));_0x49e919(_0x2b83e7[_0x29d0('0x28')][_0x29d0('0x27')]);}})[_0x29d0('0x29')](function(_0x39037a){logger['error'](_0x29d0('0x26'),_0x24562f,_0x39037a);_0x2f30a5(_0x39037a);});});}function respondWithStatusCode(_0x109b77,_0x15b166){_0x15b166=_0x15b166||0xcc;return function(_0x110472){if(_0x110472){return _0x109b77[_0x29d0('0x2a')](_0x15b166);}return _0x109b77[_0x29d0('0x2b')](_0x15b166)['end']();};}function respondWithResult(_0x342a0d,_0x4b6012){_0x4b6012=_0x4b6012||0xc8;return function(_0x435918){if(_0x435918){return _0x342a0d['status'](_0x4b6012)[_0x29d0('0x2c')](_0x435918);}};}function respondWithFilteredResult(_0x275f80,_0x3b5174){return function(_0x27de66){if(_0x27de66){var _0x9573ff=_0x27de66[_0x29d0('0x2d')],_0x2732da=_0x3b5174[_0x29d0('0x2e')],_0x43f981=_0x3b5174[_0x29d0('0x2e')]+_0x3b5174['limit'],_0x1d2735;if(_0x43f981>=_0x9573ff){_0x43f981=_0x9573ff;_0x1d2735=0xc8;}else{_0x1d2735=0xce;}_0x275f80[_0x29d0('0x2b')](_0x1d2735);return _0x275f80[_0x29d0('0x2f')](_0x29d0('0x30'),_0x2732da+'-'+_0x43f981+'/'+_0x9573ff)['json'](_0x27de66);}return null;};}function patchUpdates(_0x340a8e){return function(_0x557be7){try{jsonpatch[_0x29d0('0x31')](_0x557be7,_0x340a8e,!![]);}catch(_0x52619a){return BPromise[_0x29d0('0x32')](_0x52619a);}return _0x557be7['save']();};}function saveUpdates(_0x3be5dd,_0x5cd7a3){return function(_0x370d0f){if(_0x370d0f){return _0x370d0f[_0x29d0('0x33')](_0x3be5dd)[_0x29d0('0x1e')](function(_0x321771){return _0x321771;});}return null;};}function removeEntity(_0x3cfbe4,_0x5054d4){return function(_0x266701){if(_0x266701){return _0x266701[_0x29d0('0x34')]()['then'](function(){_0x3cfbe4['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x57f049,_0x3c126a){return function(_0x50f98e){if(!_0x50f98e){_0x57f049[_0x29d0('0x2a')](0x194);}return _0x50f98e;};}function handleError(_0x279264,_0x2f992c){_0x2f992c=_0x2f992c||0x1f4;return function(_0x3f4305){logger['error'](_0x3f4305[_0x29d0('0x35')]);if(_0x3f4305[_0x29d0('0x36')]){delete _0x3f4305[_0x29d0('0x36')];}_0x279264['status'](_0x2f992c)['send'](_0x3f4305);};}exports['index']=function(_0x4bd1cf,_0x4576a8){var _0x26d731={},_0xa5ee11={},_0x44c558={'count':0x0,'rows':[]};var _0x13f8dd=_[_0x29d0('0x37')](db[_0x29d0('0x38')]['rawAttributes'],function(_0x3e7198){return{'name':_0x3e7198[_0x29d0('0x39')],'type':_0x3e7198[_0x29d0('0x3a')]['key']};});_0xa5ee11[_0x29d0('0x3b')]=_['map'](_0x13f8dd,_0x29d0('0x36'));_0xa5ee11['query']=_['keys'](_0x4bd1cf[_0x29d0('0x3c')]);_0xa5ee11[_0x29d0('0x3d')]=_[_0x29d0('0x3e')](_0xa5ee11['model'],_0xa5ee11[_0x29d0('0x3c')]);_0x26d731[_0x29d0('0x3f')]=_[_0x29d0('0x3e')](_0xa5ee11[_0x29d0('0x3b')],qs[_0x29d0('0x40')](_0x4bd1cf[_0x29d0('0x3c')][_0x29d0('0x40')]));_0x26d731['attributes']=_0x26d731['attributes'][_0x29d0('0x41')]?_0x26d731['attributes']:_0xa5ee11[_0x29d0('0x3b')];if(!_0x4bd1cf[_0x29d0('0x3c')][_0x29d0('0x42')](_0x29d0('0x43'))){_0x26d731[_0x29d0('0x44')]=qs['limit'](_0x4bd1cf[_0x29d0('0x3c')][_0x29d0('0x44')]);_0x26d731[_0x29d0('0x2e')]=qs[_0x29d0('0x2e')](_0x4bd1cf['query'][_0x29d0('0x2e')]);}_0x26d731[_0x29d0('0x45')]=qs[_0x29d0('0x46')](_0x4bd1cf[_0x29d0('0x3c')][_0x29d0('0x46')]);_0x26d731[_0x29d0('0x47')]=qs[_0x29d0('0x3d')](_[_0x29d0('0x48')](_0x4bd1cf[_0x29d0('0x3c')],_0xa5ee11[_0x29d0('0x3d')]),_0x13f8dd);if(_0x4bd1cf[_0x29d0('0x3c')][_0x29d0('0x49')]){_0x26d731[_0x29d0('0x47')]=_[_0x29d0('0x4a')](_0x26d731['where'],{'$or':_[_0x29d0('0x37')](_0x13f8dd,function(_0x51c475){if(_0x51c475[_0x29d0('0x3a')]!==_0x29d0('0x4b')){var _0x2c9fc0={};_0x2c9fc0[_0x51c475['name']]={'$like':'%'+_0x4bd1cf['query'][_0x29d0('0x49')]+'%'};return _0x2c9fc0;}})});}_0x26d731=_[_0x29d0('0x4a')]({},_0x26d731,_0x4bd1cf[_0x29d0('0x4c')]);var _0xef5756={'where':_0x26d731['where']};return db[_0x29d0('0x38')][_0x29d0('0x2d')](_0xef5756)[_0x29d0('0x1e')](function(_0x1b7a59){_0x44c558[_0x29d0('0x2d')]=_0x1b7a59;if(_0x4bd1cf[_0x29d0('0x3c')][_0x29d0('0x4d')]){_0x26d731['include']=[{'all':!![]}];}return db['OpenchannelMessage'][_0x29d0('0x4e')](_0x26d731);})[_0x29d0('0x1e')](function(_0x53af44){_0x44c558[_0x29d0('0x4f')]=_0x53af44;return _0x44c558;})['then'](respondWithFilteredResult(_0x4576a8,_0x26d731))[_0x29d0('0x29')](handleError(_0x4576a8,null));};exports[_0x29d0('0x50')]=function(_0x387c66,_0x47d66d){var _0x4dab1e={'raw':!![],'where':{'id':_0x387c66[_0x29d0('0x51')]['id']}},_0x355890={};_0x355890[_0x29d0('0x3b')]=_['keys'](db['OpenchannelMessage'][_0x29d0('0x52')]);_0x355890['query']=_[_0x29d0('0x53')](_0x387c66[_0x29d0('0x3c')]);_0x355890['filters']=_[_0x29d0('0x3e')](_0x355890[_0x29d0('0x3b')],_0x355890[_0x29d0('0x3c')]);_0x4dab1e[_0x29d0('0x3f')]=_['intersection'](_0x355890[_0x29d0('0x3b')],qs[_0x29d0('0x40')](_0x387c66[_0x29d0('0x3c')][_0x29d0('0x40')]));_0x4dab1e['attributes']=_0x4dab1e['attributes'][_0x29d0('0x41')]?_0x4dab1e[_0x29d0('0x3f')]:_0x355890[_0x29d0('0x3b')];if(_0x387c66[_0x29d0('0x3c')][_0x29d0('0x4d')]){_0x4dab1e[_0x29d0('0x54')]=[{'all':!![]}];}_0x4dab1e=_[_0x29d0('0x4a')]({},_0x4dab1e,_0x387c66[_0x29d0('0x4c')]);return db['OpenchannelMessage'][_0x29d0('0x55')](_0x4dab1e)[_0x29d0('0x1e')](handleEntityNotFound(_0x47d66d,null))['then'](respondWithResult(_0x47d66d,null))[_0x29d0('0x29')](handleError(_0x47d66d,null));};exports[_0x29d0('0x56')]=function(_0x344891,_0x4f2605){return db['OpenchannelMessage'][_0x29d0('0x56')](_0x344891[_0x29d0('0x57')],{})[_0x29d0('0x1e')](respondWithResult(_0x4f2605,0xc9))[_0x29d0('0x29')](handleError(_0x4f2605,null));};exports['update']=function(_0x2f3566,_0x31b1b8){if(_0x2f3566[_0x29d0('0x57')]['id']){delete _0x2f3566['body']['id'];}return db[_0x29d0('0x38')][_0x29d0('0x55')]({'where':{'id':_0x2f3566['params']['id']}})[_0x29d0('0x1e')](handleEntityNotFound(_0x31b1b8,null))[_0x29d0('0x1e')](saveUpdates(_0x2f3566[_0x29d0('0x57')],null))['then'](respondWithResult(_0x31b1b8,null))['catch'](handleError(_0x31b1b8,null));};exports[_0x29d0('0x34')]=function(_0x2afdf3,_0x4b73a2){return db[_0x29d0('0x38')][_0x29d0('0x55')]({'where':{'id':_0x2afdf3[_0x29d0('0x51')]['id']}})[_0x29d0('0x1e')](handleEntityNotFound(_0x4b73a2,null))['then'](removeEntity(_0x4b73a2,null))[_0x29d0('0x29')](handleError(_0x4b73a2,null));};exports[_0x29d0('0x58')]=function(_0x483571,_0x2ba1ce){return db[_0x29d0('0x38')][_0x29d0('0x58')]()['then'](respondWithResult(_0x2ba1ce,null))['catch'](handleError(_0x2ba1ce,null));};var interaction_log=require('../../config/logger')('openchannel-interactions');exports[_0x29d0('0x59')]=function(_0x5c94dc,_0x1980cc,_0x3a583a){var _0x27874f={'channel':_0x29d0('0x5a')};if(_0x5c94dc[_0x29d0('0x57')]['id']){delete _0x5c94dc[_0x29d0('0x57')]['id'];}_0x5c94dc[_0x29d0('0x57')][_0x29d0('0x5b')]=!![];_0x5c94dc[_0x29d0('0x57')][_0x29d0('0x5c')]=moment()[_0x29d0('0x5d')](_0x29d0('0x5e'));_0x5c94dc['body'][_0x29d0('0x5f')]=_0x5c94dc[_0x29d0('0x57')][_0x29d0('0x5f')]||_0x5c94dc['user']['id'];return db[_0x29d0('0x38')]['find']({'where':{'id':_0x5c94dc[_0x29d0('0x51')]['id'],'UserId':null},'include':[{'model':db[_0x29d0('0x60')],'as':_0x29d0('0x61')}]})[_0x29d0('0x1e')](handleEntityNotFound(_0x1980cc,null))['then'](saveUpdates(_0x5c94dc[_0x29d0('0x57')],null))['then'](function(_0x524918){if(_0x524918){_0x27874f['message']=_0x524918[_0x29d0('0x62')]({'plain':!![]});return db['OpenchannelInteraction'][_0x29d0('0x55')]({'where':{'id':_0x524918[_0x29d0('0x63')]}});}return null;})['then'](handleEntityNotFound(_0x1980cc,null))[_0x29d0('0x1e')](function(_0x164e19){if(_0x164e19){return _0x164e19[_0x29d0('0x33')]({'UserId':_0x5c94dc[_0x29d0('0x57')][_0x29d0('0x5f')],'read1stAt':_[_0x29d0('0x64')](_0x164e19[_0x29d0('0x65')])?moment()[_0x29d0('0x5d')](_0x29d0('0x5e')):undefined});}return null;})[_0x29d0('0x1e')](function(_0x205874){if(_0x205874){_0x27874f['interaction']=_0x205874[_0x29d0('0x62')]({'plain':!![]});interaction_log[_0x29d0('0x1f')]('[OPENCHANNELMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x5c94dc[_0x29d0('0x66')]['id'],_0x5c94dc['user'][_0x29d0('0x36')],_0x5c94dc['user']['role'],_0x27874f[_0x29d0('0x67')]['id'],_0x5c94dc[_0x29d0('0x57')]?JSON[_0x29d0('0x23')](_0x5c94dc[_0x29d0('0x57')]):_0x29d0('0x68'));return respondWithRpcPromise(_0x29d0('0x69'),_0x29d0('0x6a'),_0x27874f);}return null;})[_0x29d0('0x1e')](function(_0x17564d){if(_0x17564d){if(_0x5c94dc[_0x29d0('0x57')][_0x29d0('0x6b')]){_0x27874f[_0x29d0('0x27')][_0x29d0('0x6c')]=util[_0x29d0('0x5d')]('SIP/%s',_0x5c94dc[_0x29d0('0x66')]['name']);_0x27874f[_0x29d0('0x27')][_0x29d0('0x6d')]=_0x27874f['channel'];_0x27874f[_0x29d0('0x27')][_0x29d0('0x6e')]='accept';return respondWithRpcPromise(_0x29d0('0x6f'),_0x29d0('0x6f'),{'event':_0x29d0('0x70'),'message':_0x27874f[_0x29d0('0x27')]},client9002)[_0x29d0('0x1e')](function(){return _0x27874f;});}return _0x27874f;}return null;})[_0x29d0('0x1e')](respondWithResult(_0x1980cc,null))[_0x29d0('0x29')](handleError(_0x1980cc,null));};var interaction_log=require(_0x29d0('0x11'))(_0x29d0('0x71'));exports[_0x29d0('0x32')]=function(_0x4868d5,_0x186034,_0x3122cd){var _0x531fe7={'agent':{},'channel':_0x29d0('0x5a')};if(_0x4868d5['body']['id']){delete _0x4868d5['body']['id'];}_0x4868d5[_0x29d0('0x57')][_0x29d0('0x5f')]=_0x4868d5[_0x29d0('0x57')][_0x29d0('0x5f')]||_0x4868d5[_0x29d0('0x66')]['id'];_0x531fe7[_0x29d0('0x72')]['id']=_0x4868d5['body'][_0x29d0('0x5f')];return db[_0x29d0('0x38')]['find']({'where':{'id':_0x4868d5[_0x29d0('0x51')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x186034,null))[_0x29d0('0x1e')](function(_0x24bc33){if(_0x24bc33){_0x531fe7[_0x29d0('0x27')]=_0x24bc33[_0x29d0('0x62')]({'plain':!![]});return db[_0x29d0('0x73')][_0x29d0('0x55')]({'where':{'id':_0x24bc33[_0x29d0('0x63')]}});}return null;})[_0x29d0('0x1e')](handleEntityNotFound(_0x186034,null))[_0x29d0('0x1e')](function(_0x5f44fd){if(_0x5f44fd){_0x531fe7[_0x29d0('0x67')]=_0x5f44fd['get']({'plain':!![]});interaction_log['info'](_0x29d0('0x74'),_0x4868d5[_0x29d0('0x66')]['id'],_0x4868d5[_0x29d0('0x66')][_0x29d0('0x36')],_0x4868d5[_0x29d0('0x66')][_0x29d0('0x75')],_0x531fe7[_0x29d0('0x67')]['id'],_0x4868d5[_0x29d0('0x57')]?JSON[_0x29d0('0x23')](_0x4868d5['body']):_0x29d0('0x68'));return respondWithRpcPromise('RejectMessage',_0x29d0('0x76'),_0x531fe7);}return null;})['then'](function(_0x575927){if(_0x575927){_0x575927[_0x29d0('0x27')][_0x29d0('0x6c')]=util[_0x29d0('0x5d')]('SIP/%s',_0x4868d5[_0x29d0('0x66')][_0x29d0('0x36')]);_0x575927[_0x29d0('0x27')][_0x29d0('0x6d')]=_0x531fe7['channel'];_0x575927['message']['event']=_0x29d0('0x32');respondWithRpcPromise(_0x29d0('0x6f'),_0x29d0('0x6f'),{'event':'rejectmessage','message':_0x575927[_0x29d0('0x27')]},client9002);return _0x531fe7;}return null;})[_0x29d0('0x1e')](respondWithResult(_0x186034,null))['catch'](handleError(_0x186034,null));};
\ No newline at end of file
+var _0xf151=['sort','where','pick','filter','merge','type','options','includeAll','include','findAll','rows','show','params','rawAttributes','find','create','body','describe','../../config/logger','accept','read','readAt','format','UserId','user','CmContact','Contact','get','OpenchannelInteraction','OpenchannelInteractionId','isNil','read1stAt','YYYY-MM-DD\x20HH:mm:ss','[OPENCHANNELMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','interaction','stringify','AcceptMessage','acceptMessage','manual','interface','channel','EventManager','acceptmessage','openchannel-interactions','agent','RejectMessage','rejectMessage','event','reject','rejectmessage','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','squel','crypto','jsforce','to-csv','querystring','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','defaults','redis','localhost','socket.io-emitter','./openchannelMessage.socket','jayson/promise','client','http','request','then','OpenchannelMessage,\x20%s,\x20%s','debug','OpenchannelMessage,\x20%s,\x20%s,\x20%s','error','code','message','info','request\x20sent','catch','sendStatus','end','json','count','offset','status','set','Content-Range','apply','update','destroy','name','send','index','map','OpenchannelMessage','fieldName','model','query','keys','filters','intersection','fields','attributes','length','nolimit','limit','order'];(function(_0x39484e,_0x489629){var _0x592b70=function(_0x2ab75a){while(--_0x2ab75a){_0x39484e['push'](_0x39484e['shift']());}};_0x592b70(++_0x489629);}(_0xf151,0xab));var _0x1f15=function(_0x436110,_0x6c3bc3){_0x436110=_0x436110-0x0;var _0x264d3b=_0xf151[_0x436110];return _0x264d3b;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0x1f15('0x0'));var zipdir=require(_0x1f15('0x1'));var jsonpatch=require(_0x1f15('0x2'));var rp=require(_0x1f15('0x3'));var moment=require(_0x1f15('0x4'));var BPromise=require(_0x1f15('0x5'));var Mustache=require(_0x1f15('0x6'));var util=require(_0x1f15('0x7'));var path=require('path');var sox=require(_0x1f15('0x8'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0x1f15('0x9'));var crypto=require(_0x1f15('0xa'));var jsforce=require(_0x1f15('0xb'));var deskjs=require('desk.js');var toCsv=require(_0x1f15('0xc'));var querystring=require(_0x1f15('0xd'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x1f15('0xe'));var qs=require(_0x1f15('0xf'));var as=require(_0x1f15('0x10'));var hardwareService=require(_0x1f15('0x11'));var logger=require('../../config/logger')(_0x1f15('0x12'));var utils=require(_0x1f15('0x13'));var config=require(_0x1f15('0x14'));var licenseUtil=require(_0x1f15('0x15'));var db=require('../../mysqldb')['db'];config['redis']=_[_0x1f15('0x16')](config[_0x1f15('0x17')],{'host':_0x1f15('0x18'),'port':0x18eb});var socket=require(_0x1f15('0x19'))(new Redis(config[_0x1f15('0x17')]));require(_0x1f15('0x1a'))['register'](socket);var jayson=require(_0x1f15('0x1b'));var client=jayson[_0x1f15('0x1c')][_0x1f15('0x1d')]({'port':0x232c});var client9002=jayson[_0x1f15('0x1c')]['http']({'port':0x232a});function respondWithRpcPromise(_0x428133,_0x5baa48,_0x19f7a2,_0xd021d0){return new BPromise(function(_0x2960d2,_0x4ae66f){var _0x586a7d=_0xd021d0||client;return _0x586a7d[_0x1f15('0x1e')](_0x428133,_0x19f7a2)[_0x1f15('0x1f')](function(_0x448725){logger['info'](_0x1f15('0x20'),_0x5baa48,'request\x20sent');logger[_0x1f15('0x21')](_0x1f15('0x22'),_0x5baa48,'request\x20sent',JSON['stringify'](_0x448725));if(_0x448725[_0x1f15('0x23')]){if(_0x448725['error'][_0x1f15('0x24')]===0x1f4){logger[_0x1f15('0x23')](_0x1f15('0x20'),_0x5baa48,_0x448725[_0x1f15('0x23')][_0x1f15('0x25')]);return _0x4ae66f(_0x448725[_0x1f15('0x23')][_0x1f15('0x25')]);}logger['error']('OpenchannelMessage,\x20%s,\x20%s',_0x5baa48,_0x448725[_0x1f15('0x23')][_0x1f15('0x25')]);return _0x2960d2(_0x448725['error']['message']);}else{logger[_0x1f15('0x26')](_0x1f15('0x20'),_0x5baa48,_0x1f15('0x27'));_0x2960d2(_0x448725['result'][_0x1f15('0x25')]);}})[_0x1f15('0x28')](function(_0x41559e){logger[_0x1f15('0x23')](_0x1f15('0x20'),_0x5baa48,_0x41559e);_0x4ae66f(_0x41559e);});});}function respondWithStatusCode(_0xdca8f4,_0x4305c0){_0x4305c0=_0x4305c0||0xcc;return function(_0x317bfc){if(_0x317bfc){return _0xdca8f4[_0x1f15('0x29')](_0x4305c0);}return _0xdca8f4['status'](_0x4305c0)[_0x1f15('0x2a')]();};}function respondWithResult(_0x4893d4,_0x1e81ca){_0x1e81ca=_0x1e81ca||0xc8;return function(_0xe42369){if(_0xe42369){return _0x4893d4['status'](_0x1e81ca)[_0x1f15('0x2b')](_0xe42369);}};}function respondWithFilteredResult(_0x610939,_0x1a5a14){return function(_0x4be862){if(_0x4be862){var _0x38ce55=_0x4be862[_0x1f15('0x2c')],_0x14f9f4=_0x1a5a14['offset'],_0x15b68f=_0x1a5a14[_0x1f15('0x2d')]+_0x1a5a14['limit'],_0x51b054;if(_0x15b68f>=_0x38ce55){_0x15b68f=_0x38ce55;_0x51b054=0xc8;}else{_0x51b054=0xce;}_0x610939[_0x1f15('0x2e')](_0x51b054);return _0x610939[_0x1f15('0x2f')](_0x1f15('0x30'),_0x14f9f4+'-'+_0x15b68f+'/'+_0x38ce55)[_0x1f15('0x2b')](_0x4be862);}return null;};}function patchUpdates(_0x22fe81){return function(_0x152644){try{jsonpatch[_0x1f15('0x31')](_0x152644,_0x22fe81,!![]);}catch(_0x4343e7){return BPromise['reject'](_0x4343e7);}return _0x152644['save']();};}function saveUpdates(_0x3847b4,_0x438f12){return function(_0x416ee9){if(_0x416ee9){return _0x416ee9[_0x1f15('0x32')](_0x3847b4)[_0x1f15('0x1f')](function(_0x43a02d){return _0x43a02d;});}return null;};}function removeEntity(_0x5ba734,_0x473f65){return function(_0x85eb87){if(_0x85eb87){return _0x85eb87[_0x1f15('0x33')]()[_0x1f15('0x1f')](function(){_0x5ba734['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x544e4e,_0x5b1dee){return function(_0x344ff5){if(!_0x344ff5){_0x544e4e[_0x1f15('0x29')](0x194);}return _0x344ff5;};}function handleError(_0x33ba93,_0x23c1d9){_0x23c1d9=_0x23c1d9||0x1f4;return function(_0x568413){logger[_0x1f15('0x23')](_0x568413['stack']);if(_0x568413[_0x1f15('0x34')]){delete _0x568413[_0x1f15('0x34')];}_0x33ba93[_0x1f15('0x2e')](_0x23c1d9)[_0x1f15('0x35')](_0x568413);};}exports[_0x1f15('0x36')]=function(_0x25a9c4,_0x56fc97){var _0x1d2256={},_0x24ea8f={},_0x5a61a7={'count':0x0,'rows':[]};var _0x140326=_[_0x1f15('0x37')](db[_0x1f15('0x38')]['rawAttributes'],function(_0x371478){return{'name':_0x371478[_0x1f15('0x39')],'type':_0x371478['type']['key']};});_0x24ea8f[_0x1f15('0x3a')]=_[_0x1f15('0x37')](_0x140326,'name');_0x24ea8f[_0x1f15('0x3b')]=_[_0x1f15('0x3c')](_0x25a9c4['query']);_0x24ea8f[_0x1f15('0x3d')]=_[_0x1f15('0x3e')](_0x24ea8f['model'],_0x24ea8f[_0x1f15('0x3b')]);_0x1d2256['attributes']=_['intersection'](_0x24ea8f['model'],qs['fields'](_0x25a9c4[_0x1f15('0x3b')][_0x1f15('0x3f')]));_0x1d2256[_0x1f15('0x40')]=_0x1d2256[_0x1f15('0x40')][_0x1f15('0x41')]?_0x1d2256['attributes']:_0x24ea8f['model'];if(!_0x25a9c4[_0x1f15('0x3b')]['hasOwnProperty'](_0x1f15('0x42'))){_0x1d2256['limit']=qs[_0x1f15('0x43')](_0x25a9c4[_0x1f15('0x3b')][_0x1f15('0x43')]);_0x1d2256[_0x1f15('0x2d')]=qs['offset'](_0x25a9c4[_0x1f15('0x3b')][_0x1f15('0x2d')]);}_0x1d2256[_0x1f15('0x44')]=qs[_0x1f15('0x45')](_0x25a9c4['query'][_0x1f15('0x45')]);_0x1d2256[_0x1f15('0x46')]=qs['filters'](_[_0x1f15('0x47')](_0x25a9c4['query'],_0x24ea8f[_0x1f15('0x3d')]),_0x140326);if(_0x25a9c4[_0x1f15('0x3b')][_0x1f15('0x48')]){_0x1d2256[_0x1f15('0x46')]=_[_0x1f15('0x49')](_0x1d2256[_0x1f15('0x46')],{'$or':_[_0x1f15('0x37')](_0x140326,function(_0x26bca5){if(_0x26bca5[_0x1f15('0x4a')]!=='VIRTUAL'){var _0x29bf12={};_0x29bf12[_0x26bca5[_0x1f15('0x34')]]={'$like':'%'+_0x25a9c4['query'][_0x1f15('0x48')]+'%'};return _0x29bf12;}})});}_0x1d2256=_[_0x1f15('0x49')]({},_0x1d2256,_0x25a9c4[_0x1f15('0x4b')]);var _0x5bd917={'where':_0x1d2256[_0x1f15('0x46')]};return db[_0x1f15('0x38')]['count'](_0x5bd917)[_0x1f15('0x1f')](function(_0x5b8533){_0x5a61a7[_0x1f15('0x2c')]=_0x5b8533;if(_0x25a9c4[_0x1f15('0x3b')][_0x1f15('0x4c')]){_0x1d2256[_0x1f15('0x4d')]=[{'all':!![]}];}return db['OpenchannelMessage'][_0x1f15('0x4e')](_0x1d2256);})[_0x1f15('0x1f')](function(_0x357ed9){_0x5a61a7[_0x1f15('0x4f')]=_0x357ed9;return _0x5a61a7;})[_0x1f15('0x1f')](respondWithFilteredResult(_0x56fc97,_0x1d2256))[_0x1f15('0x28')](handleError(_0x56fc97,null));};exports[_0x1f15('0x50')]=function(_0x2cbcb7,_0x421eb7){var _0x5eaffb={'raw':!![],'where':{'id':_0x2cbcb7[_0x1f15('0x51')]['id']}},_0x2a105b={};_0x2a105b['model']=_[_0x1f15('0x3c')](db[_0x1f15('0x38')][_0x1f15('0x52')]);_0x2a105b[_0x1f15('0x3b')]=_[_0x1f15('0x3c')](_0x2cbcb7['query']);_0x2a105b[_0x1f15('0x3d')]=_[_0x1f15('0x3e')](_0x2a105b[_0x1f15('0x3a')],_0x2a105b[_0x1f15('0x3b')]);_0x5eaffb[_0x1f15('0x40')]=_[_0x1f15('0x3e')](_0x2a105b['model'],qs[_0x1f15('0x3f')](_0x2cbcb7[_0x1f15('0x3b')][_0x1f15('0x3f')]));_0x5eaffb[_0x1f15('0x40')]=_0x5eaffb[_0x1f15('0x40')][_0x1f15('0x41')]?_0x5eaffb[_0x1f15('0x40')]:_0x2a105b['model'];if(_0x2cbcb7['query'][_0x1f15('0x4c')]){_0x5eaffb[_0x1f15('0x4d')]=[{'all':!![]}];}_0x5eaffb=_[_0x1f15('0x49')]({},_0x5eaffb,_0x2cbcb7[_0x1f15('0x4b')]);return db[_0x1f15('0x38')][_0x1f15('0x53')](_0x5eaffb)['then'](handleEntityNotFound(_0x421eb7,null))[_0x1f15('0x1f')](respondWithResult(_0x421eb7,null))[_0x1f15('0x28')](handleError(_0x421eb7,null));};exports[_0x1f15('0x54')]=function(_0x5e98be,_0x53c27f){return db[_0x1f15('0x38')][_0x1f15('0x54')](_0x5e98be['body'],{})[_0x1f15('0x1f')](respondWithResult(_0x53c27f,0xc9))['catch'](handleError(_0x53c27f,null));};exports['update']=function(_0x29f8cb,_0x17974f){if(_0x29f8cb[_0x1f15('0x55')]['id']){delete _0x29f8cb[_0x1f15('0x55')]['id'];}return db['OpenchannelMessage'][_0x1f15('0x53')]({'where':{'id':_0x29f8cb[_0x1f15('0x51')]['id']}})['then'](handleEntityNotFound(_0x17974f,null))[_0x1f15('0x1f')](saveUpdates(_0x29f8cb[_0x1f15('0x55')],null))[_0x1f15('0x1f')](respondWithResult(_0x17974f,null))[_0x1f15('0x28')](handleError(_0x17974f,null));};exports[_0x1f15('0x33')]=function(_0x359f5a,_0x29d749){return db[_0x1f15('0x38')][_0x1f15('0x53')]({'where':{'id':_0x359f5a[_0x1f15('0x51')]['id']}})[_0x1f15('0x1f')](handleEntityNotFound(_0x29d749,null))[_0x1f15('0x1f')](removeEntity(_0x29d749,null))['catch'](handleError(_0x29d749,null));};exports['describe']=function(_0x6ec85a,_0x13c146){return db['OpenchannelMessage'][_0x1f15('0x56')]()[_0x1f15('0x1f')](respondWithResult(_0x13c146,null))[_0x1f15('0x28')](handleError(_0x13c146,null));};var interaction_log=require(_0x1f15('0x57'))('openchannel-interactions');exports[_0x1f15('0x58')]=function(_0xa9de42,_0x47d0c6,_0x17f5c2){var _0x2ac5a7={'channel':'openchannel'};if(_0xa9de42[_0x1f15('0x55')]['id']){delete _0xa9de42['body']['id'];}_0xa9de42[_0x1f15('0x55')][_0x1f15('0x59')]=!![];_0xa9de42[_0x1f15('0x55')][_0x1f15('0x5a')]=moment()[_0x1f15('0x5b')]('YYYY-MM-DD\x20HH:mm:ss');_0xa9de42[_0x1f15('0x55')]['UserId']=_0xa9de42['body'][_0x1f15('0x5c')]||_0xa9de42[_0x1f15('0x5d')]['id'];return db['OpenchannelMessage'][_0x1f15('0x53')]({'where':{'id':_0xa9de42[_0x1f15('0x51')]['id'],'UserId':null},'include':[{'model':db[_0x1f15('0x5e')],'as':_0x1f15('0x5f')}]})['then'](handleEntityNotFound(_0x47d0c6,null))[_0x1f15('0x1f')](saveUpdates(_0xa9de42[_0x1f15('0x55')],null))[_0x1f15('0x1f')](function(_0x59413a){if(_0x59413a){_0x2ac5a7[_0x1f15('0x25')]=_0x59413a[_0x1f15('0x60')]({'plain':!![]});return db[_0x1f15('0x61')][_0x1f15('0x53')]({'where':{'id':_0x59413a[_0x1f15('0x62')]}});}return null;})[_0x1f15('0x1f')](handleEntityNotFound(_0x47d0c6,null))[_0x1f15('0x1f')](function(_0x2f3ebc){if(_0x2f3ebc){return _0x2f3ebc[_0x1f15('0x32')]({'UserId':_0xa9de42[_0x1f15('0x55')][_0x1f15('0x5c')],'read1stAt':_[_0x1f15('0x63')](_0x2f3ebc[_0x1f15('0x64')])?moment()['format'](_0x1f15('0x65')):undefined});}return null;})[_0x1f15('0x1f')](function(_0x47c179){if(_0x47c179){_0x2ac5a7['interaction']=_0x47c179[_0x1f15('0x60')]({'plain':!![]});interaction_log[_0x1f15('0x26')](_0x1f15('0x66'),_0xa9de42['user']['id'],_0xa9de42[_0x1f15('0x5d')][_0x1f15('0x34')],_0xa9de42['user'][_0x1f15('0x67')],_0x2ac5a7[_0x1f15('0x68')]['id'],_0xa9de42[_0x1f15('0x55')]?JSON[_0x1f15('0x69')](_0xa9de42['body']):'null');return respondWithRpcPromise(_0x1f15('0x6a'),_0x1f15('0x6b'),_0x2ac5a7);}return null;})[_0x1f15('0x1f')](function(_0x5a2a13){if(_0x5a2a13){if(_0xa9de42[_0x1f15('0x55')][_0x1f15('0x6c')]){_0x2ac5a7[_0x1f15('0x25')][_0x1f15('0x6d')]=util[_0x1f15('0x5b')]('SIP/%s',_0xa9de42['user']['name']);_0x2ac5a7[_0x1f15('0x25')]['channel']=_0x2ac5a7[_0x1f15('0x6e')];_0x2ac5a7[_0x1f15('0x25')]['event']=_0x1f15('0x58');return respondWithRpcPromise(_0x1f15('0x6f'),_0x1f15('0x6f'),{'event':_0x1f15('0x70'),'message':_0x2ac5a7[_0x1f15('0x25')]},client9002)[_0x1f15('0x1f')](function(){return _0x2ac5a7;});}return _0x2ac5a7;}return null;})['then'](respondWithResult(_0x47d0c6,null))[_0x1f15('0x28')](handleError(_0x47d0c6,null));};var interaction_log=require(_0x1f15('0x57'))(_0x1f15('0x71'));exports['reject']=function(_0x168044,_0x399eb7,_0x5a72c1){var _0x87d986={'agent':{},'channel':'openchannel'};if(_0x168044['body']['id']){delete _0x168044[_0x1f15('0x55')]['id'];}_0x168044[_0x1f15('0x55')]['UserId']=_0x168044[_0x1f15('0x55')][_0x1f15('0x5c')]||_0x168044[_0x1f15('0x5d')]['id'];_0x87d986[_0x1f15('0x72')]['id']=_0x168044[_0x1f15('0x55')][_0x1f15('0x5c')];return db['OpenchannelMessage'][_0x1f15('0x53')]({'where':{'id':_0x168044[_0x1f15('0x51')]['id'],'UserId':null}})[_0x1f15('0x1f')](handleEntityNotFound(_0x399eb7,null))[_0x1f15('0x1f')](function(_0x5526ea){if(_0x5526ea){_0x87d986['message']=_0x5526ea[_0x1f15('0x60')]({'plain':!![]});return db[_0x1f15('0x61')]['find']({'where':{'id':_0x5526ea[_0x1f15('0x62')]}});}return null;})[_0x1f15('0x1f')](handleEntityNotFound(_0x399eb7,null))[_0x1f15('0x1f')](function(_0x2f9a19){if(_0x2f9a19){_0x87d986[_0x1f15('0x68')]=_0x2f9a19[_0x1f15('0x60')]({'plain':!![]});interaction_log['info']('[OPENCHANNELMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x168044[_0x1f15('0x5d')]['id'],_0x168044[_0x1f15('0x5d')][_0x1f15('0x34')],_0x168044[_0x1f15('0x5d')][_0x1f15('0x67')],_0x87d986[_0x1f15('0x68')]['id'],_0x168044[_0x1f15('0x55')]?JSON[_0x1f15('0x69')](_0x168044[_0x1f15('0x55')]):'null');return respondWithRpcPromise(_0x1f15('0x73'),_0x1f15('0x74'),_0x87d986);}return null;})[_0x1f15('0x1f')](function(_0x24fb02){if(_0x24fb02){_0x24fb02[_0x1f15('0x25')][_0x1f15('0x6d')]=util[_0x1f15('0x5b')]('SIP/%s',_0x168044[_0x1f15('0x5d')]['name']);_0x24fb02[_0x1f15('0x25')][_0x1f15('0x6e')]=_0x87d986[_0x1f15('0x6e')];_0x24fb02['message'][_0x1f15('0x75')]=_0x1f15('0x76');respondWithRpcPromise(_0x1f15('0x6f'),_0x1f15('0x6f'),{'event':_0x1f15('0x77'),'message':_0x24fb02[_0x1f15('0x25')]},client9002);return _0x87d986;}return null;})['then'](respondWithResult(_0x399eb7,null))[_0x1f15('0x28')](handleError(_0x399eb7,null));};
\ No newline at end of file