Built motion from commit c738b9ac.|2.6.25
[motion2.git] / server / api / chatMessage / chatMessage.controller.js
index 932d7f5..4218708 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x5f22=['catch','sendStatus','status','json','count','offset','limit','set','Content-Range','apply','reject','update','destroy','name','send','index','map','ChatMessage','rawAttributes','fieldName','key','model','keys','query','filters','intersection','attributes','fields','length','nolimit','order','sort','where','pick','filter','merge','type','VIRTUAL','options','includeAll','findAll','rows','show','params','include','find','create','body','describe','accept','chat','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','CmContact','get','ChatInteraction','ChatInteractionId','isNil','read1stAt','interaction','[CHATMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','AcceptMessage','interface','channel','event','EventManager','acceptmessage','parse','chat-interactions','RejectMessage','rejectMessage','SIP/%s','rejectmessage','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','path','to-csv','ejs','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','defaults','localhost','socket.io-emitter','./chatMessage.socket','register','jayson/promise','client','http','request','then','info','request\x20sent','debug','ChatMessage,\x20%s,\x20%s,\x20%s','stringify','error','ChatMessage,\x20%s,\x20%s','message'];(function(_0x587eeb,_0x437854){var _0x4791ec=function(_0x4f44e0){while(--_0x4f44e0){_0x587eeb['push'](_0x587eeb['shift']());}};_0x4791ec(++_0x437854);}(_0x5f22,0x144));var _0x25f2=function(_0x2df724,_0x411382){_0x2df724=_0x2df724-0x0;var _0x1b2504=_0x5f22[_0x2df724];return _0x1b2504;};'use strict';var pdf=require(_0x25f2('0x0'));var emlformat=require(_0x25f2('0x1'));var rimraf=require(_0x25f2('0x2'));var zipdir=require(_0x25f2('0x3'));var jsonpatch=require(_0x25f2('0x4'));var rp=require('request-promise');var moment=require(_0x25f2('0x5'));var BPromise=require(_0x25f2('0x6'));var Mustache=require('mustache');var util=require('util');var path=require(_0x25f2('0x7'));var sox=require('sox');var csv=require(_0x25f2('0x8'));var ejs=require(_0x25f2('0x9'));var fs=require('fs');var _=require('lodash');var squel=require(_0x25f2('0xa'));var crypto=require(_0x25f2('0xb'));var jsforce=require(_0x25f2('0xc'));var deskjs=require(_0x25f2('0xd'));var toCsv=require('to-csv');var querystring=require(_0x25f2('0xe'));var Papa=require(_0x25f2('0xf'));var Redis=require(_0x25f2('0x10'));var authService=require(_0x25f2('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x25f2('0x12'));var hardwareService=require(_0x25f2('0x13'));var logger=require(_0x25f2('0x14'))('api');var utils=require(_0x25f2('0x15'));var config=require(_0x25f2('0x16'));var licenseUtil=require(_0x25f2('0x17'));var db=require('../../mysqldb')['db'];config['redis']=_[_0x25f2('0x18')](config['redis'],{'host':_0x25f2('0x19'),'port':0x18eb});var socket=require(_0x25f2('0x1a'))(new Redis(config['redis']));require(_0x25f2('0x1b'))[_0x25f2('0x1c')](socket);var jayson=require(_0x25f2('0x1d'));var client=jayson[_0x25f2('0x1e')][_0x25f2('0x1f')]({'port':0x232c});var client9002=jayson[_0x25f2('0x1e')][_0x25f2('0x1f')]({'port':0x232a});function respondWithRpcPromise(_0x9329a6,_0x822fa8,_0x1e9d54,_0x3db9ab){return new BPromise(function(_0x5d97df,_0x3e8b61){var _0x4fd6bb=_0x3db9ab||client;return _0x4fd6bb[_0x25f2('0x20')](_0x9329a6,_0x1e9d54)[_0x25f2('0x21')](function(_0x421829){logger[_0x25f2('0x22')]('ChatMessage,\x20%s,\x20%s',_0x822fa8,_0x25f2('0x23'));logger[_0x25f2('0x24')](_0x25f2('0x25'),_0x822fa8,_0x25f2('0x23'),JSON[_0x25f2('0x26')](_0x421829));if(_0x421829[_0x25f2('0x27')]){if(_0x421829[_0x25f2('0x27')]['code']===0x1f4){logger[_0x25f2('0x27')](_0x25f2('0x28'),_0x822fa8,_0x421829[_0x25f2('0x27')]['message']);return _0x3e8b61(_0x421829[_0x25f2('0x27')][_0x25f2('0x29')]);}logger[_0x25f2('0x27')](_0x25f2('0x28'),_0x822fa8,_0x421829['error'][_0x25f2('0x29')]);return _0x5d97df(_0x421829[_0x25f2('0x27')][_0x25f2('0x29')]);}else{logger[_0x25f2('0x22')](_0x25f2('0x28'),_0x822fa8,_0x25f2('0x23'));_0x5d97df(_0x421829['result'][_0x25f2('0x29')]);}})[_0x25f2('0x2a')](function(_0x7bec3e){logger['error']('ChatMessage,\x20%s,\x20%s',_0x822fa8,_0x7bec3e);_0x3e8b61(_0x7bec3e);});});}function respondWithStatusCode(_0x23d5fe,_0x376cab){_0x376cab=_0x376cab||0xcc;return function(_0x4d7207){if(_0x4d7207){return _0x23d5fe[_0x25f2('0x2b')](_0x376cab);}return _0x23d5fe[_0x25f2('0x2c')](_0x376cab)['end']();};}function respondWithResult(_0x569495,_0x2751b6){_0x2751b6=_0x2751b6||0xc8;return function(_0x36b073){if(_0x36b073){return _0x569495[_0x25f2('0x2c')](_0x2751b6)[_0x25f2('0x2d')](_0x36b073);}};}function respondWithFilteredResult(_0x1886a8,_0x180cfa){return function(_0x47fe33){if(_0x47fe33){var _0x344b56=_0x47fe33[_0x25f2('0x2e')],_0x2f5e29=_0x180cfa[_0x25f2('0x2f')],_0x5c28a4=_0x180cfa['offset']+_0x180cfa[_0x25f2('0x30')],_0x1dc046;if(_0x5c28a4>=_0x344b56){_0x5c28a4=_0x344b56;_0x1dc046=0xc8;}else{_0x1dc046=0xce;}_0x1886a8[_0x25f2('0x2c')](_0x1dc046);return _0x1886a8[_0x25f2('0x31')](_0x25f2('0x32'),_0x2f5e29+'-'+_0x5c28a4+'/'+_0x344b56)[_0x25f2('0x2d')](_0x47fe33);}return null;};}function patchUpdates(_0x9173cf){return function(_0x58c816){try{jsonpatch[_0x25f2('0x33')](_0x58c816,_0x9173cf,!![]);}catch(_0x3028ac){return BPromise[_0x25f2('0x34')](_0x3028ac);}return _0x58c816['save']();};}function saveUpdates(_0xae3a27,_0x3d172a){return function(_0xca881b){if(_0xca881b){return _0xca881b[_0x25f2('0x35')](_0xae3a27)[_0x25f2('0x21')](function(_0x306002){return _0x306002;});}return null;};}function removeEntity(_0xffb468,_0x131f11){return function(_0x28a42b){if(_0x28a42b){return _0x28a42b[_0x25f2('0x36')]()[_0x25f2('0x21')](function(){_0xffb468['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x5b4465,_0x5688bc){return function(_0xa690c1){if(!_0xa690c1){_0x5b4465[_0x25f2('0x2b')](0x194);}return _0xa690c1;};}function handleError(_0x3a94c6,_0x5b8787){_0x5b8787=_0x5b8787||0x1f4;return function(_0x2d3673){logger['error'](_0x2d3673['stack']);if(_0x2d3673[_0x25f2('0x37')]){delete _0x2d3673['name'];}_0x3a94c6[_0x25f2('0x2c')](_0x5b8787)[_0x25f2('0x38')](_0x2d3673);};}exports[_0x25f2('0x39')]=function(_0x52650a,_0x14e1a6){var _0x13dc43={},_0x1ac24a={},_0x1e33d5={'count':0x0,'rows':[]};var _0x47139a=_[_0x25f2('0x3a')](db[_0x25f2('0x3b')][_0x25f2('0x3c')],function(_0x1f8156){return{'name':_0x1f8156[_0x25f2('0x3d')],'type':_0x1f8156['type'][_0x25f2('0x3e')]};});_0x1ac24a[_0x25f2('0x3f')]=_[_0x25f2('0x3a')](_0x47139a,_0x25f2('0x37'));_0x1ac24a['query']=_[_0x25f2('0x40')](_0x52650a[_0x25f2('0x41')]);_0x1ac24a[_0x25f2('0x42')]=_[_0x25f2('0x43')](_0x1ac24a[_0x25f2('0x3f')],_0x1ac24a[_0x25f2('0x41')]);_0x13dc43[_0x25f2('0x44')]=_[_0x25f2('0x43')](_0x1ac24a['model'],qs[_0x25f2('0x45')](_0x52650a[_0x25f2('0x41')][_0x25f2('0x45')]));_0x13dc43[_0x25f2('0x44')]=_0x13dc43[_0x25f2('0x44')][_0x25f2('0x46')]?_0x13dc43[_0x25f2('0x44')]:_0x1ac24a[_0x25f2('0x3f')];if(!_0x52650a['query']['hasOwnProperty'](_0x25f2('0x47'))){_0x13dc43[_0x25f2('0x30')]=qs['limit'](_0x52650a[_0x25f2('0x41')]['limit']);_0x13dc43[_0x25f2('0x2f')]=qs['offset'](_0x52650a['query']['offset']);}_0x13dc43[_0x25f2('0x48')]=qs[_0x25f2('0x49')](_0x52650a[_0x25f2('0x41')]['sort']);_0x13dc43[_0x25f2('0x4a')]=qs[_0x25f2('0x42')](_[_0x25f2('0x4b')](_0x52650a[_0x25f2('0x41')],_0x1ac24a['filters']),_0x47139a);if(_0x52650a[_0x25f2('0x41')][_0x25f2('0x4c')]){_0x13dc43[_0x25f2('0x4a')]=_[_0x25f2('0x4d')](_0x13dc43[_0x25f2('0x4a')],{'$or':_['map'](_0x47139a,function(_0x27308b){if(_0x27308b[_0x25f2('0x4e')]!==_0x25f2('0x4f')){var _0x27ba46={};_0x27ba46[_0x27308b[_0x25f2('0x37')]]={'$like':'%'+_0x52650a['query'][_0x25f2('0x4c')]+'%'};return _0x27ba46;}})});}_0x13dc43=_[_0x25f2('0x4d')]({},_0x13dc43,_0x52650a[_0x25f2('0x50')]);var _0x2ce1f0={'where':_0x13dc43[_0x25f2('0x4a')]};return db['ChatMessage'][_0x25f2('0x2e')](_0x2ce1f0)[_0x25f2('0x21')](function(_0x2c7971){_0x1e33d5[_0x25f2('0x2e')]=_0x2c7971;if(_0x52650a[_0x25f2('0x41')][_0x25f2('0x51')]){_0x13dc43['include']=[{'all':!![]}];}return db[_0x25f2('0x3b')][_0x25f2('0x52')](_0x13dc43);})[_0x25f2('0x21')](function(_0x26a88d){_0x1e33d5[_0x25f2('0x53')]=_0x26a88d;return _0x1e33d5;})[_0x25f2('0x21')](respondWithFilteredResult(_0x14e1a6,_0x13dc43))['catch'](handleError(_0x14e1a6,null));};exports[_0x25f2('0x54')]=function(_0x17df86,_0x112588){var _0x41dddf={'raw':!![],'where':{'id':_0x17df86[_0x25f2('0x55')]['id']}},_0x610025={};_0x610025[_0x25f2('0x3f')]=_[_0x25f2('0x40')](db[_0x25f2('0x3b')][_0x25f2('0x3c')]);_0x610025[_0x25f2('0x41')]=_[_0x25f2('0x40')](_0x17df86[_0x25f2('0x41')]);_0x610025[_0x25f2('0x42')]=_['intersection'](_0x610025['model'],_0x610025[_0x25f2('0x41')]);_0x41dddf[_0x25f2('0x44')]=_[_0x25f2('0x43')](_0x610025[_0x25f2('0x3f')],qs[_0x25f2('0x45')](_0x17df86[_0x25f2('0x41')][_0x25f2('0x45')]));_0x41dddf[_0x25f2('0x44')]=_0x41dddf[_0x25f2('0x44')]['length']?_0x41dddf[_0x25f2('0x44')]:_0x610025[_0x25f2('0x3f')];if(_0x17df86[_0x25f2('0x41')][_0x25f2('0x51')]){_0x41dddf[_0x25f2('0x56')]=[{'all':!![]}];}_0x41dddf=_[_0x25f2('0x4d')]({},_0x41dddf,_0x17df86[_0x25f2('0x50')]);return db[_0x25f2('0x3b')][_0x25f2('0x57')](_0x41dddf)[_0x25f2('0x21')](handleEntityNotFound(_0x112588,null))[_0x25f2('0x21')](respondWithResult(_0x112588,null))[_0x25f2('0x2a')](handleError(_0x112588,null));};exports['create']=function(_0x51f497,_0x35cb47){return db[_0x25f2('0x3b')][_0x25f2('0x58')](_0x51f497[_0x25f2('0x59')],{})[_0x25f2('0x21')](respondWithResult(_0x35cb47,0xc9))['catch'](handleError(_0x35cb47,null));};exports[_0x25f2('0x35')]=function(_0x316e6a,_0x126f51){if(_0x316e6a[_0x25f2('0x59')]['id']){delete _0x316e6a[_0x25f2('0x59')]['id'];}return db['ChatMessage'][_0x25f2('0x57')]({'where':{'id':_0x316e6a[_0x25f2('0x55')]['id']}})['then'](handleEntityNotFound(_0x126f51,null))[_0x25f2('0x21')](saveUpdates(_0x316e6a[_0x25f2('0x59')],null))['then'](respondWithResult(_0x126f51,null))[_0x25f2('0x2a')](handleError(_0x126f51,null));};exports['destroy']=function(_0x5c82dc,_0x145f58){return db[_0x25f2('0x3b')][_0x25f2('0x57')]({'where':{'id':_0x5c82dc[_0x25f2('0x55')]['id']}})['then'](handleEntityNotFound(_0x145f58,null))[_0x25f2('0x21')](removeEntity(_0x145f58,null))[_0x25f2('0x2a')](handleError(_0x145f58,null));};exports[_0x25f2('0x5a')]=function(_0x530126,_0x580af6){return db[_0x25f2('0x3b')][_0x25f2('0x5a')]()[_0x25f2('0x21')](respondWithResult(_0x580af6,null))[_0x25f2('0x2a')](handleError(_0x580af6,null));};var interaction_log=require(_0x25f2('0x14'))('chat-interactions');exports[_0x25f2('0x5b')]=function(_0x3ef774,_0x14ee49,_0x2dcee1){var _0xb73254={'agent':{},'channel':_0x25f2('0x5c')};if(_0x3ef774[_0x25f2('0x59')]['id']){delete _0x3ef774['body']['id'];}_0x3ef774[_0x25f2('0x59')][_0x25f2('0x5d')]=!![];_0x3ef774[_0x25f2('0x59')][_0x25f2('0x5e')]=moment()[_0x25f2('0x5f')](_0x25f2('0x60'));_0x3ef774[_0x25f2('0x59')][_0x25f2('0x61')]=_0x3ef774[_0x25f2('0x59')][_0x25f2('0x61')]||_0x3ef774[_0x25f2('0x62')]['id'];_0xb73254[_0x25f2('0x63')]['id']=_0x3ef774['body'][_0x25f2('0x61')];return db[_0x25f2('0x3b')]['find']({'where':{'id':_0x3ef774[_0x25f2('0x55')]['id'],'UserId':null},'include':[{'model':db[_0x25f2('0x64')],'as':'Contact'}]})[_0x25f2('0x21')](handleEntityNotFound(_0x14ee49,null))[_0x25f2('0x21')](saveUpdates(_0x3ef774[_0x25f2('0x59')],null))[_0x25f2('0x21')](function(_0x3163b0){if(_0x3163b0){_0xb73254['message']=_0x3163b0[_0x25f2('0x65')]({'plain':!![]});return db[_0x25f2('0x66')][_0x25f2('0x57')]({'where':{'id':_0x3163b0[_0x25f2('0x67')]}});}return null;})[_0x25f2('0x21')](handleEntityNotFound(_0x14ee49,null))[_0x25f2('0x21')](function(_0x4a5ee2){if(_0x4a5ee2){return _0x4a5ee2[_0x25f2('0x35')]({'UserId':_0x3ef774[_0x25f2('0x59')][_0x25f2('0x61')],'read1stAt':_[_0x25f2('0x68')](_0x4a5ee2[_0x25f2('0x69')])?moment()['format'](_0x25f2('0x60')):undefined});}return null;})['then'](function(_0x39090e){if(_0x39090e){_0xb73254[_0x25f2('0x6a')]=_0x39090e[_0x25f2('0x65')]({'plain':!![]});interaction_log['info'](_0x25f2('0x6b'),_0x3ef774[_0x25f2('0x62')]['id'],_0x3ef774[_0x25f2('0x62')][_0x25f2('0x37')],_0x3ef774[_0x25f2('0x62')][_0x25f2('0x6c')],_0xb73254[_0x25f2('0x6a')]['id'],_0x3ef774[_0x25f2('0x59')]?JSON[_0x25f2('0x26')](_0x3ef774[_0x25f2('0x59')]):_0x25f2('0x6d'));return respondWithRpcPromise(_0x25f2('0x6e'),'acceptMessage',_0xb73254);}return null;})[_0x25f2('0x21')](function(_0x27f462){if(_0x27f462){if(_0x3ef774['body']['manual']){_0xb73254['message'][_0x25f2('0x6f')]=util[_0x25f2('0x5f')]('SIP/%s',_0x3ef774['user'][_0x25f2('0x37')]);_0xb73254['message'][_0x25f2('0x70')]=_0xb73254['channel'];_0xb73254['message'][_0x25f2('0x71')]=_0x25f2('0x5b');return respondWithRpcPromise('EventManager',_0x25f2('0x72'),{'event':_0x25f2('0x73'),'message':_[_0x25f2('0x4d')](_0xb73254[_0x25f2('0x29')],JSON[_0x25f2('0x74')](_0xb73254[_0x25f2('0x6a')]['formData']))},client9002)[_0x25f2('0x21')](function(){return _0xb73254;});}return _0xb73254;}return null;})[_0x25f2('0x21')](respondWithResult(_0x14ee49,null))[_0x25f2('0x2a')](handleError(_0x14ee49,null));};var interaction_log=require(_0x25f2('0x14'))(_0x25f2('0x75'));exports['reject']=function(_0x5932c6,_0x1f87cc,_0x121642){var _0x2cd705={'agent':{},'channel':_0x25f2('0x5c')};if(_0x5932c6[_0x25f2('0x59')]['id']){delete _0x5932c6[_0x25f2('0x59')]['id'];}_0x5932c6['body'][_0x25f2('0x61')]=_0x5932c6[_0x25f2('0x59')][_0x25f2('0x61')]||_0x5932c6[_0x25f2('0x62')]['id'];_0x2cd705[_0x25f2('0x63')]['id']=_0x5932c6[_0x25f2('0x59')]['UserId'];return db['ChatMessage'][_0x25f2('0x57')]({'where':{'id':_0x5932c6[_0x25f2('0x55')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x1f87cc,null))['then'](function(_0x3122fd){if(_0x3122fd){_0x2cd705[_0x25f2('0x29')]=_0x3122fd[_0x25f2('0x65')]({'plain':!![]});return db[_0x25f2('0x66')][_0x25f2('0x57')]({'where':{'id':_0x3122fd[_0x25f2('0x67')]}});}return null;})['then'](handleEntityNotFound(_0x1f87cc,null))[_0x25f2('0x21')](function(_0x249909){if(_0x249909){_0x2cd705[_0x25f2('0x6a')]=_0x249909['get']({'plain':!![]});interaction_log[_0x25f2('0x22')]('[CHATMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x5932c6[_0x25f2('0x62')]['id'],_0x5932c6[_0x25f2('0x62')][_0x25f2('0x37')],_0x5932c6[_0x25f2('0x62')][_0x25f2('0x6c')],_0x2cd705[_0x25f2('0x6a')]['id'],_0x5932c6[_0x25f2('0x59')]?JSON[_0x25f2('0x26')](_0x5932c6[_0x25f2('0x59')]):_0x25f2('0x6d'));return respondWithRpcPromise(_0x25f2('0x76'),_0x25f2('0x77'),_0x2cd705);}return null;})[_0x25f2('0x21')](function(_0x57a519){if(_0x57a519){_0x57a519['message'][_0x25f2('0x6f')]=util['format'](_0x25f2('0x78'),_0x5932c6['user'][_0x25f2('0x37')]);_0x57a519[_0x25f2('0x29')][_0x25f2('0x70')]=_0x2cd705['channel'];_0x57a519[_0x25f2('0x29')][_0x25f2('0x71')]=_0x25f2('0x34');respondWithRpcPromise(_0x25f2('0x72'),'EventManager',{'event':_0x25f2('0x79'),'message':_0x57a519['message']},client9002);return _0x2cd705;}return null;})['then'](respondWithResult(_0x1f87cc,null))[_0x25f2('0x2a')](handleError(_0x1f87cc,null));};
\ No newline at end of file
+var _0x1ae0=['params','describe','chat-interactions','accept','chat','format','UserId','user','agent','get','ChatInteractionId','read1stAt','interaction','null','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','Sequelize','QueryTypes','SELECT','User','email','internal','manual','interface','channel','event','EventManager','acceptmessage','parse','ChatInteraction','[CHATMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','rejectMessage','contact','fullname','SIP/%s','motionChannel','formData','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','path','sox','to-csv','ejs','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./chatMessage.socket','register','jayson/promise','client','http','request','then','info','ChatMessage,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','result','catch','status','json','undefined','offset','limit','set','reject','save','update','destroy','end','sendStatus','stack','send','map','ChatMessage','rawAttributes','fieldName','key','model','name','query','keys','filters','intersection','attributes','length','hasOwnProperty','sort','where','pick','filter','merge','type','options','count','includeAll','include','rows','fields','create','body','find'];(function(_0x447b00,_0x44800a){var _0x315e68=function(_0x2391ff){while(--_0x2391ff){_0x447b00['push'](_0x447b00['shift']());}};_0x315e68(++_0x44800a);}(_0x1ae0,0xaa));var _0x01ae=function(_0x2cfc10,_0x401877){_0x2cfc10=_0x2cfc10-0x0;var _0x2cf73d=_0x1ae0[_0x2cfc10];return _0x2cf73d;};'use strict';var emlformat=require(_0x01ae('0x0'));var rimraf=require(_0x01ae('0x1'));var zipdir=require(_0x01ae('0x2'));var jsonpatch=require(_0x01ae('0x3'));var rp=require(_0x01ae('0x4'));var moment=require(_0x01ae('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x01ae('0x6'));var util=require('util');var path=require(_0x01ae('0x7'));var sox=require(_0x01ae('0x8'));var csv=require(_0x01ae('0x9'));var ejs=require(_0x01ae('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x01ae('0xb'));var squel=require(_0x01ae('0xc'));var crypto=require(_0x01ae('0xd'));var jsforce=require('jsforce');var deskjs=require(_0x01ae('0xe'));var toCsv=require('to-csv');var querystring=require(_0x01ae('0xf'));var Papa=require(_0x01ae('0x10'));var Redis=require(_0x01ae('0x11'));var authService=require(_0x01ae('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0x01ae('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x01ae('0x14'));var utils=require(_0x01ae('0x15'));var config=require(_0x01ae('0x16'));var licenseUtil=require(_0x01ae('0x17'));var db=require(_0x01ae('0x18'))['db'];config[_0x01ae('0x19')]=_[_0x01ae('0x1a')](config['redis'],{'host':_0x01ae('0x1b'),'port':0x18eb});var socket=require(_0x01ae('0x1c'))(new Redis(config[_0x01ae('0x19')]));require(_0x01ae('0x1d'))[_0x01ae('0x1e')](socket);var jayson=require(_0x01ae('0x1f'));var client=jayson[_0x01ae('0x20')][_0x01ae('0x21')]({'port':0x232c});var client9002=jayson['client'][_0x01ae('0x21')]({'port':0x232a});function respondWithRpcPromise(_0x34ac71,_0x54b0e1,_0x5ec912,_0x2d57e9){return new BPromise(function(_0x3a4736,_0x42ffae){var _0x5ef19b=_0x2d57e9||client;return _0x5ef19b[_0x01ae('0x22')](_0x34ac71,_0x5ec912)[_0x01ae('0x23')](function(_0x32bce9){logger[_0x01ae('0x24')](_0x01ae('0x25'),_0x54b0e1,_0x01ae('0x26'));logger['debug']('ChatMessage,\x20%s,\x20%s,\x20%s',_0x54b0e1,_0x01ae('0x26'),JSON[_0x01ae('0x27')](_0x32bce9));if(_0x32bce9[_0x01ae('0x28')]){if(_0x32bce9[_0x01ae('0x28')][_0x01ae('0x29')]===0x1f4){logger[_0x01ae('0x28')](_0x01ae('0x25'),_0x54b0e1,_0x32bce9[_0x01ae('0x28')][_0x01ae('0x2a')]);return _0x42ffae(_0x32bce9[_0x01ae('0x28')]['message']);}logger['error'](_0x01ae('0x25'),_0x54b0e1,_0x32bce9[_0x01ae('0x28')][_0x01ae('0x2a')]);return _0x3a4736(_0x32bce9[_0x01ae('0x28')][_0x01ae('0x2a')]);}else{logger['info'](_0x01ae('0x25'),_0x54b0e1,'request\x20sent');_0x3a4736(_0x32bce9[_0x01ae('0x2b')][_0x01ae('0x2a')]);}})[_0x01ae('0x2c')](function(_0x56bb96){logger[_0x01ae('0x28')](_0x01ae('0x25'),_0x54b0e1,_0x56bb96);_0x42ffae(_0x56bb96);});});}function respondWithStatusCode(_0x74b97e,_0x4d660d){_0x4d660d=_0x4d660d||0xcc;return function(_0xef85b){if(_0xef85b){return _0x74b97e['sendStatus'](_0x4d660d);}return _0x74b97e[_0x01ae('0x2d')](_0x4d660d)['end']();};}function respondWithResult(_0x1d9c18,_0xc3834){_0xc3834=_0xc3834||0xc8;return function(_0x4ff121){if(_0x4ff121){return _0x1d9c18[_0x01ae('0x2d')](_0xc3834)[_0x01ae('0x2e')](_0x4ff121);}};}function respondWithFilteredResult(_0x552b23,_0x173360){return function(_0x4efcd4){if(_0x4efcd4){var _0xaeca38=typeof _0x173360['offset']===_0x01ae('0x2f')&&typeof _0x173360['limit']==='undefined';var _0x40f202=_0x4efcd4['count'];var _0x3ca0aa=_0xaeca38?0x0:_0x173360[_0x01ae('0x30')];var _0x25f830=_0xaeca38?_0x4efcd4['count']:_0x173360['offset']+_0x173360[_0x01ae('0x31')];var _0x417f49;if(_0x25f830>=_0x40f202){_0x25f830=_0x40f202;_0x417f49=0xc8;}else{_0x417f49=0xce;}_0x552b23[_0x01ae('0x2d')](_0x417f49);return _0x552b23[_0x01ae('0x32')]('Content-Range',_0x3ca0aa+'-'+_0x25f830+'/'+_0x40f202)[_0x01ae('0x2e')](_0x4efcd4);}return null;};}function patchUpdates(_0x4fa3e3){return function(_0x59f99a){try{jsonpatch['apply'](_0x59f99a,_0x4fa3e3,!![]);}catch(_0x1b83c9){return BPromise[_0x01ae('0x33')](_0x1b83c9);}return _0x59f99a[_0x01ae('0x34')]();};}function saveUpdates(_0x59fde5,_0x2f0a63){return function(_0x4e052d){if(_0x4e052d){return _0x4e052d[_0x01ae('0x35')](_0x59fde5)[_0x01ae('0x23')](function(_0x5bd4d8){return _0x5bd4d8;});}return null;};}function removeEntity(_0xef0962,_0x461d5c){return function(_0x313901){if(_0x313901){return _0x313901[_0x01ae('0x36')]()[_0x01ae('0x23')](function(){_0xef0962['status'](0xcc)[_0x01ae('0x37')]();});}};}function handleEntityNotFound(_0x4f5be4,_0x566a40){return function(_0x588a0a){if(!_0x588a0a){_0x4f5be4[_0x01ae('0x38')](0x194);}return _0x588a0a;};}function handleError(_0x1b9984,_0x3815dd){_0x3815dd=_0x3815dd||0x1f4;return function(_0x5b9166){logger[_0x01ae('0x28')](_0x5b9166[_0x01ae('0x39')]);if(_0x5b9166['name']){delete _0x5b9166['name'];}_0x1b9984[_0x01ae('0x2d')](_0x3815dd)[_0x01ae('0x3a')](_0x5b9166);};}exports['index']=function(_0x2f8e0f,_0x5f249b){var _0x375d9d={},_0x1cd964={},_0xab4644={'count':0x0,'rows':[]};var _0x68186=_[_0x01ae('0x3b')](db[_0x01ae('0x3c')][_0x01ae('0x3d')],function(_0x2403a0){return{'name':_0x2403a0[_0x01ae('0x3e')],'type':_0x2403a0['type'][_0x01ae('0x3f')]};});_0x1cd964[_0x01ae('0x40')]=_[_0x01ae('0x3b')](_0x68186,_0x01ae('0x41'));_0x1cd964[_0x01ae('0x42')]=_[_0x01ae('0x43')](_0x2f8e0f[_0x01ae('0x42')]);_0x1cd964[_0x01ae('0x44')]=_[_0x01ae('0x45')](_0x1cd964['model'],_0x1cd964[_0x01ae('0x42')]);_0x375d9d[_0x01ae('0x46')]=_[_0x01ae('0x45')](_0x1cd964[_0x01ae('0x40')],qs['fields'](_0x2f8e0f[_0x01ae('0x42')]['fields']));_0x375d9d[_0x01ae('0x46')]=_0x375d9d[_0x01ae('0x46')][_0x01ae('0x47')]?_0x375d9d[_0x01ae('0x46')]:_0x1cd964[_0x01ae('0x40')];if(!_0x2f8e0f[_0x01ae('0x42')][_0x01ae('0x48')]('nolimit')){_0x375d9d[_0x01ae('0x31')]=qs[_0x01ae('0x31')](_0x2f8e0f[_0x01ae('0x42')][_0x01ae('0x31')]);_0x375d9d['offset']=qs[_0x01ae('0x30')](_0x2f8e0f[_0x01ae('0x42')][_0x01ae('0x30')]);}_0x375d9d['order']=qs['sort'](_0x2f8e0f['query'][_0x01ae('0x49')]);_0x375d9d[_0x01ae('0x4a')]=qs[_0x01ae('0x44')](_[_0x01ae('0x4b')](_0x2f8e0f[_0x01ae('0x42')],_0x1cd964[_0x01ae('0x44')]),_0x68186);if(_0x2f8e0f[_0x01ae('0x42')][_0x01ae('0x4c')]){_0x375d9d['where']=_[_0x01ae('0x4d')](_0x375d9d[_0x01ae('0x4a')],{'$or':_[_0x01ae('0x3b')](_0x68186,function(_0x1191f4){if(_0x1191f4[_0x01ae('0x4e')]!=='VIRTUAL'){var _0xbcee25={};_0xbcee25[_0x1191f4[_0x01ae('0x41')]]={'$like':'%'+_0x2f8e0f[_0x01ae('0x42')]['filter']+'%'};return _0xbcee25;}})});}_0x375d9d=_[_0x01ae('0x4d')]({},_0x375d9d,_0x2f8e0f[_0x01ae('0x4f')]);var _0x542989={'where':_0x375d9d[_0x01ae('0x4a')]};return db[_0x01ae('0x3c')][_0x01ae('0x50')](_0x542989)[_0x01ae('0x23')](function(_0x25b09a){_0xab4644[_0x01ae('0x50')]=_0x25b09a;if(_0x2f8e0f[_0x01ae('0x42')][_0x01ae('0x51')]){_0x375d9d[_0x01ae('0x52')]=[{'all':!![]}];}return db[_0x01ae('0x3c')]['findAll'](_0x375d9d);})['then'](function(_0x40fac1){_0xab4644[_0x01ae('0x53')]=_0x40fac1;return _0xab4644;})[_0x01ae('0x23')](respondWithFilteredResult(_0x5f249b,_0x375d9d))[_0x01ae('0x2c')](handleError(_0x5f249b,null));};exports['show']=function(_0x428352,_0x52f375){var _0x7b7df3={'raw':!![],'where':{'id':_0x428352['params']['id']}},_0x5282e5={};_0x5282e5[_0x01ae('0x40')]=_[_0x01ae('0x43')](db[_0x01ae('0x3c')][_0x01ae('0x3d')]);_0x5282e5[_0x01ae('0x42')]=_[_0x01ae('0x43')](_0x428352[_0x01ae('0x42')]);_0x5282e5[_0x01ae('0x44')]=_[_0x01ae('0x45')](_0x5282e5[_0x01ae('0x40')],_0x5282e5[_0x01ae('0x42')]);_0x7b7df3[_0x01ae('0x46')]=_[_0x01ae('0x45')](_0x5282e5[_0x01ae('0x40')],qs[_0x01ae('0x54')](_0x428352[_0x01ae('0x42')][_0x01ae('0x54')]));_0x7b7df3[_0x01ae('0x46')]=_0x7b7df3[_0x01ae('0x46')][_0x01ae('0x47')]?_0x7b7df3[_0x01ae('0x46')]:_0x5282e5['model'];if(_0x428352['query'][_0x01ae('0x51')]){_0x7b7df3[_0x01ae('0x52')]=[{'all':!![]}];}_0x7b7df3=_[_0x01ae('0x4d')]({},_0x7b7df3,_0x428352[_0x01ae('0x4f')]);return db['ChatMessage']['find'](_0x7b7df3)[_0x01ae('0x23')](handleEntityNotFound(_0x52f375,null))[_0x01ae('0x23')](respondWithResult(_0x52f375,null))[_0x01ae('0x2c')](handleError(_0x52f375,null));};exports[_0x01ae('0x55')]=function(_0x10d6bf,_0x2a9868){return db['ChatMessage'][_0x01ae('0x55')](_0x10d6bf[_0x01ae('0x56')],{})[_0x01ae('0x23')](respondWithResult(_0x2a9868,0xc9))[_0x01ae('0x2c')](handleError(_0x2a9868,null));};exports[_0x01ae('0x35')]=function(_0x271b14,_0x3d13a4){if(_0x271b14[_0x01ae('0x56')]['id']){delete _0x271b14[_0x01ae('0x56')]['id'];}return db[_0x01ae('0x3c')][_0x01ae('0x57')]({'where':{'id':_0x271b14['params']['id']}})['then'](handleEntityNotFound(_0x3d13a4,null))[_0x01ae('0x23')](saveUpdates(_0x271b14[_0x01ae('0x56')],null))[_0x01ae('0x23')](respondWithResult(_0x3d13a4,null))['catch'](handleError(_0x3d13a4,null));};exports[_0x01ae('0x36')]=function(_0x3d015f,_0x296f99){return db[_0x01ae('0x3c')]['find']({'where':{'id':_0x3d015f[_0x01ae('0x58')]['id']}})[_0x01ae('0x23')](handleEntityNotFound(_0x296f99,null))[_0x01ae('0x23')](removeEntity(_0x296f99,null))[_0x01ae('0x2c')](handleError(_0x296f99,null));};exports[_0x01ae('0x59')]=function(_0x36af5f,_0x56f158){return db[_0x01ae('0x3c')][_0x01ae('0x59')]()[_0x01ae('0x23')](respondWithResult(_0x56f158,null))[_0x01ae('0x2c')](handleError(_0x56f158,null));};var interaction_log=require('../../config/logger')(_0x01ae('0x5a'));exports[_0x01ae('0x5b')]=function(_0x16e3b4,_0x41e8d5,_0x24b7cd){var _0x3b74df={'agent':{},'channel':_0x01ae('0x5c')};if(_0x16e3b4['body']['id']){delete _0x16e3b4[_0x01ae('0x56')]['id'];}_0x16e3b4[_0x01ae('0x56')]['read']=!![];_0x16e3b4[_0x01ae('0x56')]['readAt']=moment()[_0x01ae('0x5d')]('YYYY-MM-DD\x20HH:mm:ss');_0x16e3b4[_0x01ae('0x56')][_0x01ae('0x5e')]=_0x16e3b4[_0x01ae('0x56')]['UserId']||_0x16e3b4[_0x01ae('0x5f')]['id'];_0x3b74df[_0x01ae('0x60')]['id']=_0x16e3b4[_0x01ae('0x56')][_0x01ae('0x5e')];return db[_0x01ae('0x3c')]['find']({'where':{'id':_0x16e3b4[_0x01ae('0x58')]['id'],'UserId':null}})[_0x01ae('0x23')](handleEntityNotFound(_0x41e8d5,null))['then'](saveUpdates(_0x16e3b4['body'],null))[_0x01ae('0x23')](function(_0x5f2cc8){if(_0x5f2cc8){_0x3b74df['message']=_0x5f2cc8[_0x01ae('0x61')]({'plain':!![]});return db['ChatInteraction']['find']({'where':{'id':_0x5f2cc8[_0x01ae('0x62')]}});}return null;})[_0x01ae('0x23')](handleEntityNotFound(_0x41e8d5,null))[_0x01ae('0x23')](function(_0x48dd03){if(_0x48dd03){return _0x48dd03[_0x01ae('0x35')]({'UserId':_0x16e3b4[_0x01ae('0x56')]['UserId'],'read1stAt':_['isNil'](_0x48dd03[_0x01ae('0x63')])?moment()['format']('YYYY-MM-DD\x20HH:mm:ss'):undefined});}return null;})['then'](function(_0x4fe1af){if(_0x4fe1af){_0x3b74df[_0x01ae('0x64')]=_0x4fe1af[_0x01ae('0x61')]({'plain':!![]});interaction_log[_0x01ae('0x24')]('[CHATMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x16e3b4['user']['id'],_0x16e3b4[_0x01ae('0x5f')][_0x01ae('0x41')],_0x16e3b4['user']['role'],_0x3b74df[_0x01ae('0x64')]['id'],_0x16e3b4[_0x01ae('0x56')]?JSON[_0x01ae('0x27')](_0x16e3b4[_0x01ae('0x56')]):_0x01ae('0x65'));return respondWithRpcPromise(_0x01ae('0x66'),_0x01ae('0x67'),_0x3b74df);}return null;})[_0x01ae('0x23')](function(_0xfd518d){var _0x13bea5=_0x01ae('0x68')+_0xfd518d[_0x01ae('0x2a')][_0x01ae('0x69')];return db[_0x01ae('0x6a')][_0x01ae('0x42')](_0x13bea5,{'type':db[_0x01ae('0x6b')][_0x01ae('0x6c')][_0x01ae('0x6d')],'raw':!![]})['then'](function(_0x246701){return _0x246701;});})[_0x01ae('0x23')](function(_0x59fa4e){if(_0x59fa4e){_0x3b74df[_0x01ae('0x2a')]['contact']=_0x59fa4e[0x0];if(!_0x16e3b4[_0x01ae('0x56')][_0x01ae('0x5e')])return;return db[_0x01ae('0x6e')][_0x01ae('0x57')]({'where':{'id':_0x16e3b4[_0x01ae('0x56')][_0x01ae('0x5e')],'role':_0x01ae('0x60')},'attributes':['id',_0x01ae('0x41'),'fullname',_0x01ae('0x6f'),_0x01ae('0x70')],'raw':!![]});}return null;})[_0x01ae('0x23')](function(_0x1b7d68){if(!_0x1b7d68)return null;_0x3b74df[_0x01ae('0x2a')][_0x01ae('0x60')]=_0x1b7d68;return _0x3b74df;})['then'](function(_0x3b1a04){if(_0x3b1a04){if(_0x16e3b4[_0x01ae('0x56')][_0x01ae('0x71')]){_0x3b74df[_0x01ae('0x2a')][_0x01ae('0x72')]=util[_0x01ae('0x5d')]('SIP/%s',_0x16e3b4[_0x01ae('0x5f')][_0x01ae('0x41')]);_0x3b74df['message'][_0x01ae('0x73')]=_0x3b74df[_0x01ae('0x73')];_0x3b74df[_0x01ae('0x2a')]['motionChannel']=_0x3b74df['channel'];_0x3b74df['message'][_0x01ae('0x74')]=_0x01ae('0x5b');return respondWithRpcPromise(_0x01ae('0x75'),_0x01ae('0x75'),{'event':_0x01ae('0x76'),'message':_[_0x01ae('0x4d')](_0x3b74df['message'],JSON[_0x01ae('0x77')](_0x3b74df[_0x01ae('0x64')]['formData']))},client9002)[_0x01ae('0x23')](function(){return _0x3b74df;});}return _0x3b74df;}return null;})[_0x01ae('0x23')](respondWithResult(_0x41e8d5,null))[_0x01ae('0x2c')](handleError(_0x41e8d5,null));};var interaction_log=require('../../config/logger')(_0x01ae('0x5a'));exports[_0x01ae('0x33')]=function(_0x555f5e,_0x145236,_0x2c764e){var _0x4b8690={'agent':{},'channel':_0x01ae('0x5c')};if(_0x555f5e[_0x01ae('0x56')]['id']){delete _0x555f5e[_0x01ae('0x56')]['id'];}_0x555f5e[_0x01ae('0x56')][_0x01ae('0x5e')]=_0x555f5e[_0x01ae('0x56')][_0x01ae('0x5e')]||_0x555f5e[_0x01ae('0x5f')]['id'];_0x4b8690[_0x01ae('0x60')]['id']=_0x555f5e[_0x01ae('0x56')][_0x01ae('0x5e')];return db['ChatMessage'][_0x01ae('0x57')]({'where':{'id':_0x555f5e[_0x01ae('0x58')]['id'],'UserId':null}})[_0x01ae('0x23')](handleEntityNotFound(_0x145236,null))[_0x01ae('0x23')](function(_0x2b79a3){if(_0x2b79a3){_0x4b8690[_0x01ae('0x2a')]=_0x2b79a3[_0x01ae('0x61')]({'plain':!![]});return db[_0x01ae('0x78')][_0x01ae('0x57')]({'where':{'id':_0x2b79a3[_0x01ae('0x62')]}});}return null;})[_0x01ae('0x23')](handleEntityNotFound(_0x145236,null))[_0x01ae('0x23')](function(_0x146ac2){if(_0x146ac2){_0x4b8690[_0x01ae('0x64')]=_0x146ac2['get']({'plain':!![]});interaction_log['info'](_0x01ae('0x79'),_0x555f5e['user']['id'],_0x555f5e[_0x01ae('0x5f')][_0x01ae('0x41')],_0x555f5e[_0x01ae('0x5f')][_0x01ae('0x7a')],_0x4b8690['interaction']['id'],_0x555f5e[_0x01ae('0x56')]?JSON[_0x01ae('0x27')](_0x555f5e['body']):_0x01ae('0x65'));return respondWithRpcPromise('RejectMessage',_0x01ae('0x7b'),_0x4b8690);}return null;})['then'](function(_0x2c1930){var _0x25085a=_0x01ae('0x68')+_0x2c1930['message'][_0x01ae('0x69')];return db[_0x01ae('0x6a')]['query'](_0x25085a,{'type':db[_0x01ae('0x6b')]['QueryTypes'][_0x01ae('0x6d')],'raw':!![]})[_0x01ae('0x23')](function(_0x480e03){return _0x480e03;});})[_0x01ae('0x23')](function(_0x2df211){if(_0x2df211){_0x4b8690[_0x01ae('0x2a')][_0x01ae('0x7c')]=_0x2df211[0x0];if(!_0x555f5e['body']['UserId'])return;return db[_0x01ae('0x6e')][_0x01ae('0x57')]({'where':{'id':_0x555f5e[_0x01ae('0x56')][_0x01ae('0x5e')],'role':'agent'},'attributes':['id',_0x01ae('0x41'),_0x01ae('0x7d'),_0x01ae('0x6f'),'internal'],'raw':!![]});}return null;})[_0x01ae('0x23')](function(_0x30938d){if(!_0x30938d)return null;_0x4b8690[_0x01ae('0x2a')]['agent']=_0x30938d;return _0x4b8690;})[_0x01ae('0x23')](function(_0x258062){if(_0x258062){_0x258062['message'][_0x01ae('0x72')]=util[_0x01ae('0x5d')](_0x01ae('0x7e'),_0x555f5e[_0x01ae('0x5f')][_0x01ae('0x41')]);_0x258062[_0x01ae('0x2a')][_0x01ae('0x73')]=_0x4b8690[_0x01ae('0x73')];_0x258062[_0x01ae('0x2a')][_0x01ae('0x7f')]=_0x4b8690[_0x01ae('0x73')];_0x258062[_0x01ae('0x2a')][_0x01ae('0x74')]=_0x01ae('0x33');respondWithRpcPromise(_0x01ae('0x75'),_0x01ae('0x75'),{'event':'rejectmessage','message':_['merge'](_0x4b8690[_0x01ae('0x2a')],JSON[_0x01ae('0x77')](_0x4b8690[_0x01ae('0x64')][_0x01ae('0x80')]))},client9002);return _0x4b8690;}return null;})[_0x01ae('0x23')](respondWithResult(_0x145236,null))['catch'](handleError(_0x145236,null));};
\ No newline at end of file