Built motion from commit 25580385.|2.6.2
[motion2.git] / server / api / openchannelMessage / openchannelMessage.controller.js
index 4edd507..a9da64e 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x8ad6=['findAll','params','keys','includeAll','create','update','body','find','destroy','describe','openchannel-interactions','openchannel','read','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','Contact','get','OpenchannelInteraction','OpenchannelInteractionId','isNil','read1stAt','interaction','[OPENCHANNELMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','AcceptMessage','acceptMessage','manual','SIP/%s','channel','event','accept','EventManager','reject','interface','rejectmessage','html-pdf','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','path','sox','to-csv','ejs','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','defaults','redis','./openchannelMessage.socket','register','client','http','then','info','OpenchannelMessage,\x20%s,\x20%s','request\x20sent','debug','OpenchannelMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','sendStatus','status','end','json','offset','set','Content-Range','apply','stack','name','send','index','map','OpenchannelMessage','rawAttributes','fieldName','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','limit','sort','filter','where','type','VIRTUAL','merge','options','count','include'];(function(_0x4e9d3c,_0x1f4b98){var _0x2d0825=function(_0x384676){while(--_0x384676){_0x4e9d3c['push'](_0x4e9d3c['shift']());}};_0x2d0825(++_0x1f4b98);}(_0x8ad6,0x9c));var _0x68ad=function(_0x2c9d73,_0x127513){_0x2c9d73=_0x2c9d73-0x0;var _0x2e2e7e=_0x8ad6[_0x2c9d73];return _0x2e2e7e;};'use strict';var pdf=require(_0x68ad('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x68ad('0x1'));var zipdir=require(_0x68ad('0x2'));var jsonpatch=require(_0x68ad('0x3'));var rp=require(_0x68ad('0x4'));var moment=require(_0x68ad('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x68ad('0x6'));var util=require('util');var path=require(_0x68ad('0x7'));var sox=require(_0x68ad('0x8'));var csv=require(_0x68ad('0x9'));var ejs=require(_0x68ad('0xa'));var fs=require('fs');var _=require('lodash');var squel=require(_0x68ad('0xb'));var crypto=require(_0x68ad('0xc'));var jsforce=require(_0x68ad('0xd'));var deskjs=require(_0x68ad('0xe'));var toCsv=require(_0x68ad('0x9'));var querystring=require(_0x68ad('0xf'));var Papa=require(_0x68ad('0x10'));var Redis=require(_0x68ad('0x11'));var authService=require(_0x68ad('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0x68ad('0x13'));var hardwareService=require(_0x68ad('0x14'));var logger=require(_0x68ad('0x15'))(_0x68ad('0x16'));var utils=require('../../config/utils');var config=require(_0x68ad('0x17'));var licenseUtil=require(_0x68ad('0x18'));var db=require(_0x68ad('0x19'))['db'];config['redis']=_[_0x68ad('0x1a')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x68ad('0x1b')]));require(_0x68ad('0x1c'))[_0x68ad('0x1d')](socket);var jayson=require('jayson/promise');var client=jayson[_0x68ad('0x1e')][_0x68ad('0x1f')]({'port':0x232c});var client9002=jayson[_0x68ad('0x1e')][_0x68ad('0x1f')]({'port':0x232a});function respondWithRpcPromise(_0x18c6ac,_0x40cf0b,_0x27bed7,_0x2fa61c){return new BPromise(function(_0x3451e4,_0x281de1){var _0x5cbb9c=_0x2fa61c||client;return _0x5cbb9c['request'](_0x18c6ac,_0x27bed7)[_0x68ad('0x20')](function(_0x4b310b){logger[_0x68ad('0x21')](_0x68ad('0x22'),_0x40cf0b,_0x68ad('0x23'));logger[_0x68ad('0x24')](_0x68ad('0x25'),_0x40cf0b,_0x68ad('0x23'),JSON[_0x68ad('0x26')](_0x4b310b));if(_0x4b310b[_0x68ad('0x27')]){if(_0x4b310b['error'][_0x68ad('0x28')]===0x1f4){logger['error']('OpenchannelMessage,\x20%s,\x20%s',_0x40cf0b,_0x4b310b[_0x68ad('0x27')]['message']);return _0x281de1(_0x4b310b[_0x68ad('0x27')]['message']);}logger[_0x68ad('0x27')](_0x68ad('0x22'),_0x40cf0b,_0x4b310b[_0x68ad('0x27')]['message']);return _0x3451e4(_0x4b310b['error'][_0x68ad('0x29')]);}else{logger[_0x68ad('0x21')](_0x68ad('0x22'),_0x40cf0b,'request\x20sent');_0x3451e4(_0x4b310b['result'][_0x68ad('0x29')]);}})[_0x68ad('0x2a')](function(_0x2550f2){logger[_0x68ad('0x27')](_0x68ad('0x22'),_0x40cf0b,_0x2550f2);_0x281de1(_0x2550f2);});});}function respondWithStatusCode(_0x1bc3fc,_0x5cbd12){_0x5cbd12=_0x5cbd12||0xcc;return function(_0x37b1f2){if(_0x37b1f2){return _0x1bc3fc[_0x68ad('0x2b')](_0x5cbd12);}return _0x1bc3fc[_0x68ad('0x2c')](_0x5cbd12)[_0x68ad('0x2d')]();};}function respondWithResult(_0x4ddbe0,_0x254c88){_0x254c88=_0x254c88||0xc8;return function(_0x5ad54a){if(_0x5ad54a){return _0x4ddbe0[_0x68ad('0x2c')](_0x254c88)[_0x68ad('0x2e')](_0x5ad54a);}};}function respondWithFilteredResult(_0x24d0b3,_0x25c5d1){return function(_0xc7cdb3){if(_0xc7cdb3){var _0x5e8fba=_0xc7cdb3['count'],_0x2644b2=_0x25c5d1[_0x68ad('0x2f')],_0x19fd7e=_0x25c5d1[_0x68ad('0x2f')]+_0x25c5d1['limit'],_0x31865a;if(_0x19fd7e>=_0x5e8fba){_0x19fd7e=_0x5e8fba;_0x31865a=0xc8;}else{_0x31865a=0xce;}_0x24d0b3['status'](_0x31865a);return _0x24d0b3[_0x68ad('0x30')](_0x68ad('0x31'),_0x2644b2+'-'+_0x19fd7e+'/'+_0x5e8fba)[_0x68ad('0x2e')](_0xc7cdb3);}return null;};}function patchUpdates(_0x23f8f8){return function(_0x21e9ce){try{jsonpatch[_0x68ad('0x32')](_0x21e9ce,_0x23f8f8,!![]);}catch(_0x3768c1){return BPromise['reject'](_0x3768c1);}return _0x21e9ce['save']();};}function saveUpdates(_0xec6d48,_0x27eb1c){return function(_0x4e88ff){if(_0x4e88ff){return _0x4e88ff['update'](_0xec6d48)['then'](function(_0x4afffc){return _0x4afffc;});}return null;};}function removeEntity(_0x396db7,_0x494073){return function(_0x19f21d){if(_0x19f21d){return _0x19f21d['destroy']()[_0x68ad('0x20')](function(){_0x396db7[_0x68ad('0x2c')](0xcc)[_0x68ad('0x2d')]();});}};}function handleEntityNotFound(_0x58adb7,_0x42c18e){return function(_0x31f0cd){if(!_0x31f0cd){_0x58adb7[_0x68ad('0x2b')](0x194);}return _0x31f0cd;};}function handleError(_0x5a4652,_0x34282c){_0x34282c=_0x34282c||0x1f4;return function(_0x46ae84){logger['error'](_0x46ae84[_0x68ad('0x33')]);if(_0x46ae84[_0x68ad('0x34')]){delete _0x46ae84[_0x68ad('0x34')];}_0x5a4652[_0x68ad('0x2c')](_0x34282c)[_0x68ad('0x35')](_0x46ae84);};}exports[_0x68ad('0x36')]=function(_0x9359b9,_0x2340a7){var _0x46012e={},_0x49c439={},_0x12d28a={'count':0x0,'rows':[]};var _0xd1f6df=_[_0x68ad('0x37')](db[_0x68ad('0x38')][_0x68ad('0x39')],function(_0x2ed916){return{'name':_0x2ed916[_0x68ad('0x3a')],'type':_0x2ed916['type'][_0x68ad('0x3b')]};});_0x49c439[_0x68ad('0x3c')]=_[_0x68ad('0x37')](_0xd1f6df,_0x68ad('0x34'));_0x49c439[_0x68ad('0x3d')]=_['keys'](_0x9359b9[_0x68ad('0x3d')]);_0x49c439[_0x68ad('0x3e')]=_[_0x68ad('0x3f')](_0x49c439['model'],_0x49c439[_0x68ad('0x3d')]);_0x46012e[_0x68ad('0x40')]=_[_0x68ad('0x3f')](_0x49c439[_0x68ad('0x3c')],qs[_0x68ad('0x41')](_0x9359b9[_0x68ad('0x3d')][_0x68ad('0x41')]));_0x46012e[_0x68ad('0x40')]=_0x46012e[_0x68ad('0x40')][_0x68ad('0x42')]?_0x46012e['attributes']:_0x49c439[_0x68ad('0x3c')];if(!_0x9359b9[_0x68ad('0x3d')][_0x68ad('0x43')]('nolimit')){_0x46012e['limit']=qs[_0x68ad('0x44')](_0x9359b9[_0x68ad('0x3d')][_0x68ad('0x44')]);_0x46012e[_0x68ad('0x2f')]=qs['offset'](_0x9359b9[_0x68ad('0x3d')][_0x68ad('0x2f')]);}_0x46012e['order']=qs[_0x68ad('0x45')](_0x9359b9['query']['sort']);_0x46012e['where']=qs[_0x68ad('0x3e')](_['pick'](_0x9359b9['query'],_0x49c439[_0x68ad('0x3e')]),_0xd1f6df);if(_0x9359b9['query'][_0x68ad('0x46')]){_0x46012e['where']=_['merge'](_0x46012e[_0x68ad('0x47')],{'$or':_[_0x68ad('0x37')](_0xd1f6df,function(_0x12281c){if(_0x12281c[_0x68ad('0x48')]!==_0x68ad('0x49')){var _0x43d56b={};_0x43d56b[_0x12281c[_0x68ad('0x34')]]={'$like':'%'+_0x9359b9[_0x68ad('0x3d')]['filter']+'%'};return _0x43d56b;}})});}_0x46012e=_[_0x68ad('0x4a')]({},_0x46012e,_0x9359b9[_0x68ad('0x4b')]);var _0x50477a={'where':_0x46012e[_0x68ad('0x47')]};return db[_0x68ad('0x38')][_0x68ad('0x4c')](_0x50477a)[_0x68ad('0x20')](function(_0x3b3b91){_0x12d28a[_0x68ad('0x4c')]=_0x3b3b91;if(_0x9359b9['query']['includeAll']){_0x46012e[_0x68ad('0x4d')]=[{'all':!![]}];}return db[_0x68ad('0x38')][_0x68ad('0x4e')](_0x46012e);})[_0x68ad('0x20')](function(_0x235681){_0x12d28a['rows']=_0x235681;return _0x12d28a;})[_0x68ad('0x20')](respondWithFilteredResult(_0x2340a7,_0x46012e))[_0x68ad('0x2a')](handleError(_0x2340a7,null));};exports['show']=function(_0x58a8ee,_0x537386){var _0x56b903={'raw':!![],'where':{'id':_0x58a8ee[_0x68ad('0x4f')]['id']}},_0x503c32={};_0x503c32[_0x68ad('0x3c')]=_[_0x68ad('0x50')](db[_0x68ad('0x38')][_0x68ad('0x39')]);_0x503c32[_0x68ad('0x3d')]=_['keys'](_0x58a8ee['query']);_0x503c32[_0x68ad('0x3e')]=_['intersection'](_0x503c32['model'],_0x503c32[_0x68ad('0x3d')]);_0x56b903['attributes']=_[_0x68ad('0x3f')](_0x503c32[_0x68ad('0x3c')],qs['fields'](_0x58a8ee['query']['fields']));_0x56b903[_0x68ad('0x40')]=_0x56b903[_0x68ad('0x40')][_0x68ad('0x42')]?_0x56b903[_0x68ad('0x40')]:_0x503c32[_0x68ad('0x3c')];if(_0x58a8ee[_0x68ad('0x3d')][_0x68ad('0x51')]){_0x56b903[_0x68ad('0x4d')]=[{'all':!![]}];}_0x56b903=_['merge']({},_0x56b903,_0x58a8ee[_0x68ad('0x4b')]);return db[_0x68ad('0x38')]['find'](_0x56b903)[_0x68ad('0x20')](handleEntityNotFound(_0x537386,null))['then'](respondWithResult(_0x537386,null))[_0x68ad('0x2a')](handleError(_0x537386,null));};exports['create']=function(_0x3d5d57,_0x24086b){return db['OpenchannelMessage'][_0x68ad('0x52')](_0x3d5d57['body'],{})['then'](respondWithResult(_0x24086b,0xc9))[_0x68ad('0x2a')](handleError(_0x24086b,null));};exports[_0x68ad('0x53')]=function(_0xffb640,_0x4b7f3a){if(_0xffb640[_0x68ad('0x54')]['id']){delete _0xffb640[_0x68ad('0x54')]['id'];}return db[_0x68ad('0x38')][_0x68ad('0x55')]({'where':{'id':_0xffb640[_0x68ad('0x4f')]['id']}})['then'](handleEntityNotFound(_0x4b7f3a,null))[_0x68ad('0x20')](saveUpdates(_0xffb640['body'],null))['then'](respondWithResult(_0x4b7f3a,null))[_0x68ad('0x2a')](handleError(_0x4b7f3a,null));};exports[_0x68ad('0x56')]=function(_0x1cd055,_0x4f613b){return db['OpenchannelMessage']['find']({'where':{'id':_0x1cd055[_0x68ad('0x4f')]['id']}})[_0x68ad('0x20')](handleEntityNotFound(_0x4f613b,null))['then'](removeEntity(_0x4f613b,null))[_0x68ad('0x2a')](handleError(_0x4f613b,null));};exports['describe']=function(_0x5ae667,_0x27c914){return db['OpenchannelMessage'][_0x68ad('0x57')]()['then'](respondWithResult(_0x27c914,null))[_0x68ad('0x2a')](handleError(_0x27c914,null));};var interaction_log=require(_0x68ad('0x15'))(_0x68ad('0x58'));exports['accept']=function(_0x530830,_0x549de0,_0x493d7b){var _0x346dcd={'agent':{},'channel':_0x68ad('0x59')};if(_0x530830[_0x68ad('0x54')]['id']){delete _0x530830[_0x68ad('0x54')]['id'];}_0x530830['body'][_0x68ad('0x5a')]=!![];_0x530830[_0x68ad('0x54')]['readAt']=moment()[_0x68ad('0x5b')](_0x68ad('0x5c'));_0x530830[_0x68ad('0x54')][_0x68ad('0x5d')]=_0x530830['body'][_0x68ad('0x5d')]||_0x530830[_0x68ad('0x5e')]['id'];_0x346dcd[_0x68ad('0x5f')]['id']=_0x530830['body'][_0x68ad('0x5d')];return db[_0x68ad('0x38')][_0x68ad('0x55')]({'where':{'id':_0x530830['params']['id'],'UserId':null},'include':[{'model':db['CmContact'],'as':_0x68ad('0x60')}]})[_0x68ad('0x20')](handleEntityNotFound(_0x549de0,null))[_0x68ad('0x20')](saveUpdates(_0x530830[_0x68ad('0x54')],null))[_0x68ad('0x20')](function(_0x258133){if(_0x258133){_0x346dcd[_0x68ad('0x29')]=_0x258133[_0x68ad('0x61')]({'plain':!![]});return db[_0x68ad('0x62')][_0x68ad('0x55')]({'where':{'id':_0x258133[_0x68ad('0x63')]}});}return null;})[_0x68ad('0x20')](handleEntityNotFound(_0x549de0,null))['then'](function(_0x433903){if(_0x433903){return _0x433903[_0x68ad('0x53')]({'UserId':_0x530830[_0x68ad('0x54')][_0x68ad('0x5d')],'read1stAt':_[_0x68ad('0x64')](_0x433903[_0x68ad('0x65')])?moment()['format'](_0x68ad('0x5c')):undefined});}return null;})[_0x68ad('0x20')](function(_0xc6e562){if(_0xc6e562){_0x346dcd[_0x68ad('0x66')]=_0xc6e562[_0x68ad('0x61')]({'plain':!![]});interaction_log[_0x68ad('0x21')](_0x68ad('0x67'),_0x530830[_0x68ad('0x5e')]['id'],_0x530830[_0x68ad('0x5e')][_0x68ad('0x34')],_0x530830[_0x68ad('0x5e')][_0x68ad('0x68')],_0x346dcd[_0x68ad('0x66')]['id'],_0x530830[_0x68ad('0x54')]?JSON['stringify'](_0x530830[_0x68ad('0x54')]):_0x68ad('0x69'));return respondWithRpcPromise(_0x68ad('0x6a'),_0x68ad('0x6b'),_0x346dcd);}return null;})['then'](function(_0x15de47){if(_0x15de47){if(_0x530830[_0x68ad('0x54')][_0x68ad('0x6c')]){_0x346dcd[_0x68ad('0x29')]['interface']=util[_0x68ad('0x5b')](_0x68ad('0x6d'),_0x530830[_0x68ad('0x5e')][_0x68ad('0x34')]);_0x346dcd[_0x68ad('0x29')][_0x68ad('0x6e')]=_0x346dcd['channel'];_0x346dcd[_0x68ad('0x29')][_0x68ad('0x6f')]=_0x68ad('0x70');return respondWithRpcPromise(_0x68ad('0x71'),_0x68ad('0x71'),{'event':'acceptmessage','message':_0x346dcd['message']},client9002)[_0x68ad('0x20')](function(){return _0x346dcd;});}return _0x346dcd;}return null;})[_0x68ad('0x20')](respondWithResult(_0x549de0,null))[_0x68ad('0x2a')](handleError(_0x549de0,null));};var interaction_log=require(_0x68ad('0x15'))('openchannel-interactions');exports[_0x68ad('0x72')]=function(_0x26eea7,_0xaec44f,_0x466517){var _0x5911cd={'agent':{},'channel':_0x68ad('0x59')};if(_0x26eea7[_0x68ad('0x54')]['id']){delete _0x26eea7['body']['id'];}_0x26eea7[_0x68ad('0x54')]['UserId']=_0x26eea7['body'][_0x68ad('0x5d')]||_0x26eea7[_0x68ad('0x5e')]['id'];_0x5911cd[_0x68ad('0x5f')]['id']=_0x26eea7[_0x68ad('0x54')]['UserId'];return db[_0x68ad('0x38')][_0x68ad('0x55')]({'where':{'id':_0x26eea7[_0x68ad('0x4f')]['id'],'UserId':null}})[_0x68ad('0x20')](handleEntityNotFound(_0xaec44f,null))[_0x68ad('0x20')](function(_0x529007){if(_0x529007){_0x5911cd[_0x68ad('0x29')]=_0x529007[_0x68ad('0x61')]({'plain':!![]});return db[_0x68ad('0x62')]['find']({'where':{'id':_0x529007[_0x68ad('0x63')]}});}return null;})['then'](handleEntityNotFound(_0xaec44f,null))[_0x68ad('0x20')](function(_0x59f69a){if(_0x59f69a){_0x5911cd['interaction']=_0x59f69a['get']({'plain':!![]});interaction_log[_0x68ad('0x21')]('[OPENCHANNELMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x26eea7[_0x68ad('0x5e')]['id'],_0x26eea7[_0x68ad('0x5e')][_0x68ad('0x34')],_0x26eea7[_0x68ad('0x5e')]['role'],_0x5911cd[_0x68ad('0x66')]['id'],_0x26eea7[_0x68ad('0x54')]?JSON[_0x68ad('0x26')](_0x26eea7[_0x68ad('0x54')]):'null');return respondWithRpcPromise('RejectMessage','rejectMessage',_0x5911cd);}return null;})[_0x68ad('0x20')](function(_0x27a056){if(_0x27a056){_0x27a056[_0x68ad('0x29')][_0x68ad('0x73')]=util[_0x68ad('0x5b')]('SIP/%s',_0x26eea7['user']['name']);_0x27a056[_0x68ad('0x29')][_0x68ad('0x6e')]=_0x5911cd[_0x68ad('0x6e')];_0x27a056[_0x68ad('0x29')]['event']='reject';respondWithRpcPromise(_0x68ad('0x71'),_0x68ad('0x71'),{'event':_0x68ad('0x74'),'message':_0x27a056['message']},client9002);return _0x5911cd;}return null;})[_0x68ad('0x20')](respondWithResult(_0xaec44f,null))[_0x68ad('0x2a')](handleError(_0xaec44f,null));};
\ No newline at end of file
+var _0x88d5=['fs-extra','lodash','jsforce','desk.js','querystring','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','defaults','redis','localhost','socket.io-emitter','jayson/promise','client','http','then','OpenchannelMessage,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','info','result','catch','status','end','json','undefined','limit','count','offset','apply','save','update','stack','name','send','index','map','OpenchannelMessage','fieldName','key','model','query','filters','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','type','VIRTUAL','options','includeAll','findAll','rows','show','keys','rawAttributes','attributes','include','merge','find','create','body','destroy','params','describe','openchannel-interactions','accept','read','readAt','format','UserId','user','agent','get','read1stAt','YYYY-MM-DD\x20HH:mm:ss','interaction','[OPENCHANNELMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','QueryTypes','SELECT','contact','User','fullname','email','internal','interface','SIP/%s','channel','motionChannel','EventManager','acceptmessage','reject','OpenchannelInteraction','OpenchannelInteractionId','[OPENCHANNELMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','Sequelize','event','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','path','sox','to-csv','ejs'];(function(_0x1bd79c,_0x8530e9){var _0x2017c2=function(_0xf23916){while(--_0xf23916){_0x1bd79c['push'](_0x1bd79c['shift']());}};_0x2017c2(++_0x8530e9);}(_0x88d5,0x76));var _0x588d=function(_0x3f096b,_0x1a864f){_0x3f096b=_0x3f096b-0x0;var _0x204ba4=_0x88d5[_0x3f096b];return _0x204ba4;};'use strict';var emlformat=require(_0x588d('0x0'));var rimraf=require(_0x588d('0x1'));var zipdir=require(_0x588d('0x2'));var jsonpatch=require(_0x588d('0x3'));var rp=require(_0x588d('0x4'));var moment=require('moment');var BPromise=require(_0x588d('0x5'));var Mustache=require(_0x588d('0x6'));var util=require('util');var path=require(_0x588d('0x7'));var sox=require(_0x588d('0x8'));var csv=require(_0x588d('0x9'));var ejs=require(_0x588d('0xa'));var fs=require('fs');var fs_extra=require(_0x588d('0xb'));var _=require(_0x588d('0xc'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x588d('0xd'));var deskjs=require(_0x588d('0xe'));var toCsv=require(_0x588d('0x9'));var querystring=require(_0x588d('0xf'));var Papa=require('papaparse');var Redis=require(_0x588d('0x10'));var authService=require('../../components/auth/service');var qs=require(_0x588d('0x11'));var as=require(_0x588d('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x588d('0x13'))(_0x588d('0x14'));var utils=require(_0x588d('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0x588d('0x16'));var db=require(_0x588d('0x17'))['db'];config['redis']=_[_0x588d('0x18')](config[_0x588d('0x19')],{'host':_0x588d('0x1a'),'port':0x18eb});var socket=require(_0x588d('0x1b'))(new Redis(config[_0x588d('0x19')]));require('./openchannelMessage.socket')['register'](socket);var jayson=require(_0x588d('0x1c'));var client=jayson[_0x588d('0x1d')][_0x588d('0x1e')]({'port':0x232c});var client9002=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x27b5a4,_0x11c022,_0x4a6557,_0x139f75){return new BPromise(function(_0x73302d,_0x19df79){var _0x2d64b1=_0x139f75||client;return _0x2d64b1['request'](_0x27b5a4,_0x4a6557)[_0x588d('0x1f')](function(_0x432da4){logger['info'](_0x588d('0x20'),_0x11c022,_0x588d('0x21'));logger['debug']('OpenchannelMessage,\x20%s,\x20%s,\x20%s',_0x11c022,_0x588d('0x21'),JSON[_0x588d('0x22')](_0x432da4));if(_0x432da4['error']){if(_0x432da4[_0x588d('0x23')][_0x588d('0x24')]===0x1f4){logger[_0x588d('0x23')]('OpenchannelMessage,\x20%s,\x20%s',_0x11c022,_0x432da4[_0x588d('0x23')]['message']);return _0x19df79(_0x432da4['error']['message']);}logger['error'](_0x588d('0x20'),_0x11c022,_0x432da4[_0x588d('0x23')][_0x588d('0x25')]);return _0x73302d(_0x432da4['error'][_0x588d('0x25')]);}else{logger[_0x588d('0x26')](_0x588d('0x20'),_0x11c022,_0x588d('0x21'));_0x73302d(_0x432da4[_0x588d('0x27')][_0x588d('0x25')]);}})[_0x588d('0x28')](function(_0x1d53f3){logger['error'](_0x588d('0x20'),_0x11c022,_0x1d53f3);_0x19df79(_0x1d53f3);});});}function respondWithStatusCode(_0xb5e483,_0x50b365){_0x50b365=_0x50b365||0xcc;return function(_0x7cb1e1){if(_0x7cb1e1){return _0xb5e483['sendStatus'](_0x50b365);}return _0xb5e483[_0x588d('0x29')](_0x50b365)[_0x588d('0x2a')]();};}function respondWithResult(_0x27c6c0,_0x18d4bc){_0x18d4bc=_0x18d4bc||0xc8;return function(_0x576598){if(_0x576598){return _0x27c6c0[_0x588d('0x29')](_0x18d4bc)[_0x588d('0x2b')](_0x576598);}};}function respondWithFilteredResult(_0x56e764,_0x2a0a31){return function(_0x59f25f){if(_0x59f25f){var _0x1b3033=typeof _0x2a0a31['offset']===_0x588d('0x2c')&&typeof _0x2a0a31[_0x588d('0x2d')]==='undefined';var _0x365217=_0x59f25f[_0x588d('0x2e')];var _0x15669a=_0x1b3033?0x0:_0x2a0a31[_0x588d('0x2f')];var _0x19e72e=_0x1b3033?_0x59f25f[_0x588d('0x2e')]:_0x2a0a31[_0x588d('0x2f')]+_0x2a0a31[_0x588d('0x2d')];var _0xd67306;if(_0x19e72e>=_0x365217){_0x19e72e=_0x365217;_0xd67306=0xc8;}else{_0xd67306=0xce;}_0x56e764[_0x588d('0x29')](_0xd67306);return _0x56e764['set']('Content-Range',_0x15669a+'-'+_0x19e72e+'/'+_0x365217)[_0x588d('0x2b')](_0x59f25f);}return null;};}function patchUpdates(_0x37b86f){return function(_0x2c2ea3){try{jsonpatch[_0x588d('0x30')](_0x2c2ea3,_0x37b86f,!![]);}catch(_0x186d37){return BPromise['reject'](_0x186d37);}return _0x2c2ea3[_0x588d('0x31')]();};}function saveUpdates(_0x4d43aa,_0x372003){return function(_0x1c56ea){if(_0x1c56ea){return _0x1c56ea[_0x588d('0x32')](_0x4d43aa)[_0x588d('0x1f')](function(_0x28e7ac){return _0x28e7ac;});}return null;};}function removeEntity(_0x1ef5f0,_0x57f171){return function(_0x18269a){if(_0x18269a){return _0x18269a['destroy']()[_0x588d('0x1f')](function(){_0x1ef5f0[_0x588d('0x29')](0xcc)[_0x588d('0x2a')]();});}};}function handleEntityNotFound(_0x56b1a5,_0x1369d8){return function(_0x47b3e5){if(!_0x47b3e5){_0x56b1a5['sendStatus'](0x194);}return _0x47b3e5;};}function handleError(_0x592a19,_0x2983a){_0x2983a=_0x2983a||0x1f4;return function(_0x58122a){logger[_0x588d('0x23')](_0x58122a[_0x588d('0x33')]);if(_0x58122a['name']){delete _0x58122a[_0x588d('0x34')];}_0x592a19[_0x588d('0x29')](_0x2983a)[_0x588d('0x35')](_0x58122a);};}exports[_0x588d('0x36')]=function(_0x174dfc,_0x1c7762){var _0x5a55b4={},_0x262b4e={},_0x232310={'count':0x0,'rows':[]};var _0x5cb680=_[_0x588d('0x37')](db[_0x588d('0x38')]['rawAttributes'],function(_0x162ee7){return{'name':_0x162ee7[_0x588d('0x39')],'type':_0x162ee7['type'][_0x588d('0x3a')]};});_0x262b4e[_0x588d('0x3b')]=_[_0x588d('0x37')](_0x5cb680,'name');_0x262b4e[_0x588d('0x3c')]=_['keys'](_0x174dfc[_0x588d('0x3c')]);_0x262b4e[_0x588d('0x3d')]=_[_0x588d('0x3e')](_0x262b4e[_0x588d('0x3b')],_0x262b4e[_0x588d('0x3c')]);_0x5a55b4['attributes']=_['intersection'](_0x262b4e[_0x588d('0x3b')],qs[_0x588d('0x3f')](_0x174dfc[_0x588d('0x3c')][_0x588d('0x3f')]));_0x5a55b4['attributes']=_0x5a55b4['attributes'][_0x588d('0x40')]?_0x5a55b4['attributes']:_0x262b4e[_0x588d('0x3b')];if(!_0x174dfc['query'][_0x588d('0x41')](_0x588d('0x42'))){_0x5a55b4['limit']=qs[_0x588d('0x2d')](_0x174dfc[_0x588d('0x3c')][_0x588d('0x2d')]);_0x5a55b4[_0x588d('0x2f')]=qs[_0x588d('0x2f')](_0x174dfc['query'][_0x588d('0x2f')]);}_0x5a55b4[_0x588d('0x43')]=qs[_0x588d('0x44')](_0x174dfc[_0x588d('0x3c')][_0x588d('0x44')]);_0x5a55b4[_0x588d('0x45')]=qs[_0x588d('0x3d')](_[_0x588d('0x46')](_0x174dfc[_0x588d('0x3c')],_0x262b4e[_0x588d('0x3d')]),_0x5cb680);if(_0x174dfc[_0x588d('0x3c')][_0x588d('0x47')]){_0x5a55b4['where']=_['merge'](_0x5a55b4[_0x588d('0x45')],{'$or':_[_0x588d('0x37')](_0x5cb680,function(_0x8c3864){if(_0x8c3864[_0x588d('0x48')]!==_0x588d('0x49')){var _0x55c311={};_0x55c311[_0x8c3864[_0x588d('0x34')]]={'$like':'%'+_0x174dfc[_0x588d('0x3c')]['filter']+'%'};return _0x55c311;}})});}_0x5a55b4=_['merge']({},_0x5a55b4,_0x174dfc[_0x588d('0x4a')]);var _0x5b33a3={'where':_0x5a55b4[_0x588d('0x45')]};return db['OpenchannelMessage'][_0x588d('0x2e')](_0x5b33a3)[_0x588d('0x1f')](function(_0x4edc17){_0x232310[_0x588d('0x2e')]=_0x4edc17;if(_0x174dfc['query'][_0x588d('0x4b')]){_0x5a55b4['include']=[{'all':!![]}];}return db[_0x588d('0x38')][_0x588d('0x4c')](_0x5a55b4);})[_0x588d('0x1f')](function(_0x5a0131){_0x232310[_0x588d('0x4d')]=_0x5a0131;return _0x232310;})[_0x588d('0x1f')](respondWithFilteredResult(_0x1c7762,_0x5a55b4))[_0x588d('0x28')](handleError(_0x1c7762,null));};exports[_0x588d('0x4e')]=function(_0x5ead05,_0x546384){var _0x40ca4f={'raw':!![],'where':{'id':_0x5ead05['params']['id']}},_0xf0d0c3={};_0xf0d0c3['model']=_[_0x588d('0x4f')](db[_0x588d('0x38')][_0x588d('0x50')]);_0xf0d0c3[_0x588d('0x3c')]=_[_0x588d('0x4f')](_0x5ead05[_0x588d('0x3c')]);_0xf0d0c3[_0x588d('0x3d')]=_[_0x588d('0x3e')](_0xf0d0c3[_0x588d('0x3b')],_0xf0d0c3[_0x588d('0x3c')]);_0x40ca4f['attributes']=_['intersection'](_0xf0d0c3[_0x588d('0x3b')],qs['fields'](_0x5ead05[_0x588d('0x3c')][_0x588d('0x3f')]));_0x40ca4f['attributes']=_0x40ca4f[_0x588d('0x51')]['length']?_0x40ca4f['attributes']:_0xf0d0c3['model'];if(_0x5ead05[_0x588d('0x3c')][_0x588d('0x4b')]){_0x40ca4f[_0x588d('0x52')]=[{'all':!![]}];}_0x40ca4f=_[_0x588d('0x53')]({},_0x40ca4f,_0x5ead05[_0x588d('0x4a')]);return db['OpenchannelMessage'][_0x588d('0x54')](_0x40ca4f)[_0x588d('0x1f')](handleEntityNotFound(_0x546384,null))[_0x588d('0x1f')](respondWithResult(_0x546384,null))[_0x588d('0x28')](handleError(_0x546384,null));};exports[_0x588d('0x55')]=function(_0x1891b0,_0x488c41){return db[_0x588d('0x38')][_0x588d('0x55')](_0x1891b0[_0x588d('0x56')],{})[_0x588d('0x1f')](respondWithResult(_0x488c41,0xc9))['catch'](handleError(_0x488c41,null));};exports[_0x588d('0x32')]=function(_0x4594f8,_0x2dbefe){if(_0x4594f8[_0x588d('0x56')]['id']){delete _0x4594f8[_0x588d('0x56')]['id'];}return db[_0x588d('0x38')][_0x588d('0x54')]({'where':{'id':_0x4594f8['params']['id']}})[_0x588d('0x1f')](handleEntityNotFound(_0x2dbefe,null))[_0x588d('0x1f')](saveUpdates(_0x4594f8[_0x588d('0x56')],null))[_0x588d('0x1f')](respondWithResult(_0x2dbefe,null))[_0x588d('0x28')](handleError(_0x2dbefe,null));};exports[_0x588d('0x57')]=function(_0x2e476f,_0x22edd0){return db[_0x588d('0x38')]['find']({'where':{'id':_0x2e476f[_0x588d('0x58')]['id']}})[_0x588d('0x1f')](handleEntityNotFound(_0x22edd0,null))[_0x588d('0x1f')](removeEntity(_0x22edd0,null))['catch'](handleError(_0x22edd0,null));};exports['describe']=function(_0x5a011f,_0x199d61){return db[_0x588d('0x38')][_0x588d('0x59')]()['then'](respondWithResult(_0x199d61,null))[_0x588d('0x28')](handleError(_0x199d61,null));};var interaction_log=require(_0x588d('0x13'))(_0x588d('0x5a'));exports[_0x588d('0x5b')]=function(_0x28b103,_0x5adfca,_0x21a363){var _0x525d11={'agent':{},'channel':'openchannel'};if(_0x28b103[_0x588d('0x56')]['id']){delete _0x28b103['body']['id'];}_0x28b103['body'][_0x588d('0x5c')]=!![];_0x28b103[_0x588d('0x56')][_0x588d('0x5d')]=moment()[_0x588d('0x5e')]('YYYY-MM-DD\x20HH:mm:ss');_0x28b103[_0x588d('0x56')]['UserId']=_0x28b103[_0x588d('0x56')][_0x588d('0x5f')]||_0x28b103[_0x588d('0x60')]['id'];_0x525d11[_0x588d('0x61')]['id']=_0x28b103['body']['UserId'];return db[_0x588d('0x38')][_0x588d('0x54')]({'where':{'id':_0x28b103[_0x588d('0x58')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x5adfca,null))[_0x588d('0x1f')](saveUpdates(_0x28b103[_0x588d('0x56')],null))['then'](function(_0x562b1c){if(_0x562b1c){_0x525d11[_0x588d('0x25')]=_0x562b1c[_0x588d('0x62')]({'plain':!![]});return db['OpenchannelInteraction'][_0x588d('0x54')]({'where':{'id':_0x562b1c['OpenchannelInteractionId']}});}return null;})[_0x588d('0x1f')](handleEntityNotFound(_0x5adfca,null))['then'](function(_0x49d2fd){if(_0x49d2fd){return _0x49d2fd[_0x588d('0x32')]({'UserId':_0x28b103[_0x588d('0x56')][_0x588d('0x5f')],'read1stAt':_['isNil'](_0x49d2fd[_0x588d('0x63')])?moment()['format'](_0x588d('0x64')):undefined});}return null;})['then'](function(_0x7c5bb7){if(_0x7c5bb7){_0x525d11[_0x588d('0x65')]=_0x7c5bb7[_0x588d('0x62')]({'plain':!![]});interaction_log[_0x588d('0x26')](_0x588d('0x66'),_0x28b103[_0x588d('0x60')]['id'],_0x28b103['user'][_0x588d('0x34')],_0x28b103['user'][_0x588d('0x67')],_0x525d11['interaction']['id'],_0x28b103[_0x588d('0x56')]?JSON['stringify'](_0x28b103['body']):_0x588d('0x68'));return respondWithRpcPromise('AcceptMessage','acceptMessage',_0x525d11);}return null;})['then'](function(_0x476415){var _0xf5d30c=_0x588d('0x69')+_0x476415[_0x588d('0x25')][_0x588d('0x6a')];return db[_0x588d('0x6b')][_0x588d('0x3c')](_0xf5d30c,{'type':db['Sequelize'][_0x588d('0x6c')][_0x588d('0x6d')],'raw':!![]})[_0x588d('0x1f')](function(_0x15af7d){return _0x15af7d;});})['then'](function(_0x58c17c){if(_0x58c17c){_0x525d11[_0x588d('0x25')][_0x588d('0x6e')]=_0x58c17c[0x0];if(!_0x28b103['body'][_0x588d('0x5f')])return;return db[_0x588d('0x6f')]['find']({'where':{'id':_0x28b103[_0x588d('0x56')][_0x588d('0x5f')],'role':'agent'},'attributes':['id',_0x588d('0x34'),_0x588d('0x70'),_0x588d('0x71'),_0x588d('0x72')],'raw':!![]});}return null;})[_0x588d('0x1f')](function(_0x330744){if(!_0x330744)return null;_0x525d11[_0x588d('0x25')][_0x588d('0x61')]=_0x330744;return _0x525d11;})[_0x588d('0x1f')](function(_0x4f318d){if(_0x4f318d){if(_0x28b103['body']['manual']){_0x525d11[_0x588d('0x25')][_0x588d('0x73')]=util[_0x588d('0x5e')](_0x588d('0x74'),_0x28b103[_0x588d('0x60')][_0x588d('0x34')]);_0x525d11[_0x588d('0x25')]['channel']=_0x525d11[_0x588d('0x75')];_0x525d11[_0x588d('0x25')][_0x588d('0x76')]=_0x525d11[_0x588d('0x75')];_0x525d11[_0x588d('0x25')]['event']='accept';return respondWithRpcPromise('EventManager',_0x588d('0x77'),{'event':_0x588d('0x78'),'message':_0x525d11[_0x588d('0x25')]},client9002)['then'](function(){return _0x525d11;});}return _0x525d11;}return null;})[_0x588d('0x1f')](respondWithResult(_0x5adfca,null))[_0x588d('0x28')](handleError(_0x5adfca,null));};var interaction_log=require(_0x588d('0x13'))(_0x588d('0x5a'));exports[_0x588d('0x79')]=function(_0x2c0c08,_0x792b24,_0x2a522e){var _0x519be6={'agent':{},'channel':'openchannel'};if(_0x2c0c08[_0x588d('0x56')]['id']){delete _0x2c0c08[_0x588d('0x56')]['id'];}_0x2c0c08[_0x588d('0x56')][_0x588d('0x5f')]=_0x2c0c08[_0x588d('0x56')]['UserId']||_0x2c0c08[_0x588d('0x60')]['id'];_0x519be6[_0x588d('0x61')]['id']=_0x2c0c08['body'][_0x588d('0x5f')];return db['OpenchannelMessage'][_0x588d('0x54')]({'where':{'id':_0x2c0c08[_0x588d('0x58')]['id'],'UserId':null}})[_0x588d('0x1f')](handleEntityNotFound(_0x792b24,null))[_0x588d('0x1f')](function(_0x5205d7){if(_0x5205d7){_0x519be6['message']=_0x5205d7[_0x588d('0x62')]({'plain':!![]});return db[_0x588d('0x7a')][_0x588d('0x54')]({'where':{'id':_0x5205d7[_0x588d('0x7b')]}});}return null;})[_0x588d('0x1f')](handleEntityNotFound(_0x792b24,null))[_0x588d('0x1f')](function(_0x46bc9b){if(_0x46bc9b){_0x519be6['interaction']=_0x46bc9b[_0x588d('0x62')]({'plain':!![]});interaction_log[_0x588d('0x26')](_0x588d('0x7c'),_0x2c0c08[_0x588d('0x60')]['id'],_0x2c0c08[_0x588d('0x60')][_0x588d('0x34')],_0x2c0c08[_0x588d('0x60')][_0x588d('0x67')],_0x519be6['interaction']['id'],_0x2c0c08['body']?JSON[_0x588d('0x22')](_0x2c0c08[_0x588d('0x56')]):'null');return respondWithRpcPromise(_0x588d('0x7d'),_0x588d('0x7e'),_0x519be6);}return null;})[_0x588d('0x1f')](function(_0x3f7f63){var _0x10bdbc=_0x588d('0x69')+_0x3f7f63[_0x588d('0x25')][_0x588d('0x6a')];return db[_0x588d('0x6b')]['query'](_0x10bdbc,{'type':db[_0x588d('0x7f')]['QueryTypes'][_0x588d('0x6d')],'raw':!![]})[_0x588d('0x1f')](function(_0x33f160){return _0x33f160;});})[_0x588d('0x1f')](function(_0x4f8d31){if(_0x4f8d31){_0x519be6['message']['contact']=_0x4f8d31[0x0];if(!_0x2c0c08[_0x588d('0x56')][_0x588d('0x5f')])return;return db[_0x588d('0x6f')][_0x588d('0x54')]({'where':{'id':_0x2c0c08[_0x588d('0x56')]['UserId'],'role':_0x588d('0x61')},'attributes':['id',_0x588d('0x34'),_0x588d('0x70'),_0x588d('0x71'),'internal'],'raw':!![]});}return null;})[_0x588d('0x1f')](function(_0x89eeaf){if(!_0x89eeaf)return null;_0x519be6[_0x588d('0x25')][_0x588d('0x61')]=_0x89eeaf;return _0x519be6;})[_0x588d('0x1f')](function(_0x528b4a){if(_0x528b4a){_0x528b4a[_0x588d('0x25')][_0x588d('0x73')]=util[_0x588d('0x5e')](_0x588d('0x74'),_0x2c0c08[_0x588d('0x60')][_0x588d('0x34')]);_0x528b4a[_0x588d('0x25')][_0x588d('0x75')]=_0x519be6[_0x588d('0x75')];_0x528b4a[_0x588d('0x25')][_0x588d('0x76')]=_0x519be6[_0x588d('0x75')];_0x528b4a['message'][_0x588d('0x80')]=_0x588d('0x79');respondWithRpcPromise(_0x588d('0x77'),_0x588d('0x77'),{'event':'rejectmessage','message':_0x528b4a[_0x588d('0x25')]},client9002);return _0x519be6;}return null;})[_0x588d('0x1f')](respondWithResult(_0x792b24,null))[_0x588d('0x28')](handleError(_0x792b24,null));};
\ No newline at end of file