Built motion from commit 9d7072cc.|2.5.39
[motion2.git] / server / api / chatMessage / chatMessage.controller.js
index 932d7f5..4edc428 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 _0x2d34=['reject','save','stack','name','send','index','rawAttributes','type','key','model','keys','query','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','sort','where','pick','filter','map','merge','options','ChatMessage','includeAll','findAll','show','params','include','find','create','body','update','destroy','describe','accept','chat','read','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','ChatInteraction','ChatInteractionId','read1stAt','interaction','get','[CHATMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','AcceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','Sequelize','QueryTypes','SELECT','contact','User','fullname','email','internal','manual','SIP/%s','channel','motionChannel','event','EventManager','acceptmessage','formData','[CHATMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','interface','rejectmessage','parse','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','path','to-csv','fs-extra','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','socket.io-emitter','./chatMessage.socket','client','http','request','then','info','ChatMessage,\x20%s,\x20%s','request\x20sent','debug','ChatMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','sendStatus','status','end','offset','undefined','count','limit','set','Content-Range','json'];(function(_0x14add3,_0x13ce8d){var _0x4a174f=function(_0x2b3ed7){while(--_0x2b3ed7){_0x14add3['push'](_0x14add3['shift']());}};_0x4a174f(++_0x13ce8d);}(_0x2d34,0x156));var _0x42d3=function(_0x4f7b41,_0x133043){_0x4f7b41=_0x4f7b41-0x0;var _0x5caa2b=_0x2d34[_0x4f7b41];return _0x5caa2b;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x42d3('0x0'));var zipdir=require(_0x42d3('0x1'));var jsonpatch=require(_0x42d3('0x2'));var rp=require(_0x42d3('0x3'));var moment=require(_0x42d3('0x4'));var BPromise=require(_0x42d3('0x5'));var Mustache=require('mustache');var util=require('util');var path=require(_0x42d3('0x6'));var sox=require('sox');var csv=require(_0x42d3('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x42d3('0x8'));var _=require('lodash');var squel=require('squel');var crypto=require(_0x42d3('0x9'));var jsforce=require(_0x42d3('0xa'));var deskjs=require(_0x42d3('0xb'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x42d3('0xc'));var Redis=require(_0x42d3('0xd'));var authService=require(_0x42d3('0xe'));var qs=require('../../components/parsers/qs');var as=require(_0x42d3('0xf'));var hardwareService=require(_0x42d3('0x10'));var logger=require(_0x42d3('0x11'))(_0x42d3('0x12'));var utils=require(_0x42d3('0x13'));var config=require(_0x42d3('0x14'));var licenseUtil=require(_0x42d3('0x15'));var db=require(_0x42d3('0x16'))['db'];config[_0x42d3('0x17')]=_[_0x42d3('0x18')](config[_0x42d3('0x17')],{'host':'localhost','port':0x18eb});var socket=require(_0x42d3('0x19'))(new Redis(config[_0x42d3('0x17')]));require(_0x42d3('0x1a'))['register'](socket);var jayson=require('jayson/promise');var client=jayson[_0x42d3('0x1b')][_0x42d3('0x1c')]({'port':0x232c});var client9002=jayson['client'][_0x42d3('0x1c')]({'port':0x232a});function respondWithRpcPromise(_0x460abe,_0x18c64c,_0x29f928,_0x1cb8d7){return new BPromise(function(_0x552ec3,_0x314432){var _0x463e53=_0x1cb8d7||client;return _0x463e53[_0x42d3('0x1d')](_0x460abe,_0x29f928)[_0x42d3('0x1e')](function(_0xc9a998){logger[_0x42d3('0x1f')](_0x42d3('0x20'),_0x18c64c,_0x42d3('0x21'));logger[_0x42d3('0x22')](_0x42d3('0x23'),_0x18c64c,_0x42d3('0x21'),JSON[_0x42d3('0x24')](_0xc9a998));if(_0xc9a998[_0x42d3('0x25')]){if(_0xc9a998[_0x42d3('0x25')][_0x42d3('0x26')]===0x1f4){logger[_0x42d3('0x25')](_0x42d3('0x20'),_0x18c64c,_0xc9a998[_0x42d3('0x25')][_0x42d3('0x27')]);return _0x314432(_0xc9a998[_0x42d3('0x25')][_0x42d3('0x27')]);}logger[_0x42d3('0x25')]('ChatMessage,\x20%s,\x20%s',_0x18c64c,_0xc9a998[_0x42d3('0x25')][_0x42d3('0x27')]);return _0x552ec3(_0xc9a998[_0x42d3('0x25')][_0x42d3('0x27')]);}else{logger[_0x42d3('0x1f')](_0x42d3('0x20'),_0x18c64c,_0x42d3('0x21'));_0x552ec3(_0xc9a998['result']['message']);}})[_0x42d3('0x28')](function(_0x4040be){logger[_0x42d3('0x25')](_0x42d3('0x20'),_0x18c64c,_0x4040be);_0x314432(_0x4040be);});});}function respondWithStatusCode(_0x23a1cb,_0x22d485){_0x22d485=_0x22d485||0xcc;return function(_0x460d49){if(_0x460d49){return _0x23a1cb[_0x42d3('0x29')](_0x22d485);}return _0x23a1cb[_0x42d3('0x2a')](_0x22d485)[_0x42d3('0x2b')]();};}function respondWithResult(_0x18b48c,_0x23a71b){_0x23a71b=_0x23a71b||0xc8;return function(_0x306e30){if(_0x306e30){return _0x18b48c[_0x42d3('0x2a')](_0x23a71b)['json'](_0x306e30);}};}function respondWithFilteredResult(_0x2ff955,_0x5c8b68){return function(_0x13ec03){if(_0x13ec03){var _0x211f5e=typeof _0x5c8b68[_0x42d3('0x2c')]===_0x42d3('0x2d')&&typeof _0x5c8b68['limit']===_0x42d3('0x2d');var _0x4a0e06=_0x13ec03[_0x42d3('0x2e')];var _0x254947=_0x211f5e?0x0:_0x5c8b68['offset'];var _0x560fc8=_0x211f5e?_0x13ec03[_0x42d3('0x2e')]:_0x5c8b68['offset']+_0x5c8b68[_0x42d3('0x2f')];var _0x2c70b7;if(_0x560fc8>=_0x4a0e06){_0x560fc8=_0x4a0e06;_0x2c70b7=0xc8;}else{_0x2c70b7=0xce;}_0x2ff955[_0x42d3('0x2a')](_0x2c70b7);return _0x2ff955[_0x42d3('0x30')](_0x42d3('0x31'),_0x254947+'-'+_0x560fc8+'/'+_0x4a0e06)[_0x42d3('0x32')](_0x13ec03);}return null;};}function patchUpdates(_0x4e62fc){return function(_0x2e1398){try{jsonpatch['apply'](_0x2e1398,_0x4e62fc,!![]);}catch(_0x5699e2){return BPromise[_0x42d3('0x33')](_0x5699e2);}return _0x2e1398[_0x42d3('0x34')]();};}function saveUpdates(_0x49b10c,_0x3dbcb1){return function(_0x1fc760){if(_0x1fc760){return _0x1fc760['update'](_0x49b10c)['then'](function(_0x4b7aa3){return _0x4b7aa3;});}return null;};}function removeEntity(_0x42afa6,_0x3fd0ec){return function(_0xb7615a){if(_0xb7615a){return _0xb7615a['destroy']()[_0x42d3('0x1e')](function(){_0x42afa6[_0x42d3('0x2a')](0xcc)[_0x42d3('0x2b')]();});}};}function handleEntityNotFound(_0x5106bd,_0x5d6e56){return function(_0x437929){if(!_0x437929){_0x5106bd[_0x42d3('0x29')](0x194);}return _0x437929;};}function handleError(_0x2053da,_0x13f02d){_0x13f02d=_0x13f02d||0x1f4;return function(_0x11c028){logger[_0x42d3('0x25')](_0x11c028[_0x42d3('0x35')]);if(_0x11c028[_0x42d3('0x36')]){delete _0x11c028[_0x42d3('0x36')];}_0x2053da[_0x42d3('0x2a')](_0x13f02d)[_0x42d3('0x37')](_0x11c028);};}exports[_0x42d3('0x38')]=function(_0x216112,_0x336c41){var _0x343c45={},_0x1fe9dc={},_0x5c1215={'count':0x0,'rows':[]};var _0x41cdd3=_['map'](db['ChatMessage'][_0x42d3('0x39')],function(_0x1ed69f){return{'name':_0x1ed69f['fieldName'],'type':_0x1ed69f[_0x42d3('0x3a')][_0x42d3('0x3b')]};});_0x1fe9dc[_0x42d3('0x3c')]=_['map'](_0x41cdd3,_0x42d3('0x36'));_0x1fe9dc['query']=_[_0x42d3('0x3d')](_0x216112[_0x42d3('0x3e')]);_0x1fe9dc[_0x42d3('0x3f')]=_['intersection'](_0x1fe9dc[_0x42d3('0x3c')],_0x1fe9dc[_0x42d3('0x3e')]);_0x343c45[_0x42d3('0x40')]=_[_0x42d3('0x41')](_0x1fe9dc['model'],qs[_0x42d3('0x42')](_0x216112[_0x42d3('0x3e')][_0x42d3('0x42')]));_0x343c45['attributes']=_0x343c45['attributes'][_0x42d3('0x43')]?_0x343c45[_0x42d3('0x40')]:_0x1fe9dc[_0x42d3('0x3c')];if(!_0x216112['query'][_0x42d3('0x44')](_0x42d3('0x45'))){_0x343c45[_0x42d3('0x2f')]=qs[_0x42d3('0x2f')](_0x216112[_0x42d3('0x3e')][_0x42d3('0x2f')]);_0x343c45[_0x42d3('0x2c')]=qs[_0x42d3('0x2c')](_0x216112[_0x42d3('0x3e')][_0x42d3('0x2c')]);}_0x343c45['order']=qs[_0x42d3('0x46')](_0x216112[_0x42d3('0x3e')][_0x42d3('0x46')]);_0x343c45[_0x42d3('0x47')]=qs['filters'](_[_0x42d3('0x48')](_0x216112[_0x42d3('0x3e')],_0x1fe9dc[_0x42d3('0x3f')]),_0x41cdd3);if(_0x216112[_0x42d3('0x3e')][_0x42d3('0x49')]){_0x343c45[_0x42d3('0x47')]=_['merge'](_0x343c45[_0x42d3('0x47')],{'$or':_[_0x42d3('0x4a')](_0x41cdd3,function(_0x489132){if(_0x489132[_0x42d3('0x3a')]!=='VIRTUAL'){var _0x468801={};_0x468801[_0x489132[_0x42d3('0x36')]]={'$like':'%'+_0x216112[_0x42d3('0x3e')][_0x42d3('0x49')]+'%'};return _0x468801;}})});}_0x343c45=_[_0x42d3('0x4b')]({},_0x343c45,_0x216112[_0x42d3('0x4c')]);var _0x53e334={'where':_0x343c45['where']};return db[_0x42d3('0x4d')][_0x42d3('0x2e')](_0x53e334)[_0x42d3('0x1e')](function(_0x1b0798){_0x5c1215[_0x42d3('0x2e')]=_0x1b0798;if(_0x216112[_0x42d3('0x3e')][_0x42d3('0x4e')]){_0x343c45['include']=[{'all':!![]}];}return db[_0x42d3('0x4d')][_0x42d3('0x4f')](_0x343c45);})[_0x42d3('0x1e')](function(_0x32e73a){_0x5c1215['rows']=_0x32e73a;return _0x5c1215;})['then'](respondWithFilteredResult(_0x336c41,_0x343c45))[_0x42d3('0x28')](handleError(_0x336c41,null));};exports[_0x42d3('0x50')]=function(_0x475bc0,_0x20e895){var _0x35fb71={'raw':!![],'where':{'id':_0x475bc0[_0x42d3('0x51')]['id']}},_0x49c816={};_0x49c816[_0x42d3('0x3c')]=_[_0x42d3('0x3d')](db['ChatMessage'][_0x42d3('0x39')]);_0x49c816[_0x42d3('0x3e')]=_[_0x42d3('0x3d')](_0x475bc0[_0x42d3('0x3e')]);_0x49c816[_0x42d3('0x3f')]=_['intersection'](_0x49c816[_0x42d3('0x3c')],_0x49c816[_0x42d3('0x3e')]);_0x35fb71['attributes']=_[_0x42d3('0x41')](_0x49c816[_0x42d3('0x3c')],qs[_0x42d3('0x42')](_0x475bc0[_0x42d3('0x3e')][_0x42d3('0x42')]));_0x35fb71[_0x42d3('0x40')]=_0x35fb71['attributes'][_0x42d3('0x43')]?_0x35fb71['attributes']:_0x49c816['model'];if(_0x475bc0[_0x42d3('0x3e')][_0x42d3('0x4e')]){_0x35fb71[_0x42d3('0x52')]=[{'all':!![]}];}_0x35fb71=_['merge']({},_0x35fb71,_0x475bc0[_0x42d3('0x4c')]);return db['ChatMessage'][_0x42d3('0x53')](_0x35fb71)[_0x42d3('0x1e')](handleEntityNotFound(_0x20e895,null))[_0x42d3('0x1e')](respondWithResult(_0x20e895,null))[_0x42d3('0x28')](handleError(_0x20e895,null));};exports['create']=function(_0x301b90,_0x24e836){return db[_0x42d3('0x4d')][_0x42d3('0x54')](_0x301b90[_0x42d3('0x55')],{})[_0x42d3('0x1e')](respondWithResult(_0x24e836,0xc9))[_0x42d3('0x28')](handleError(_0x24e836,null));};exports[_0x42d3('0x56')]=function(_0x226ea4,_0x4daab6){if(_0x226ea4[_0x42d3('0x55')]['id']){delete _0x226ea4[_0x42d3('0x55')]['id'];}return db[_0x42d3('0x4d')][_0x42d3('0x53')]({'where':{'id':_0x226ea4['params']['id']}})['then'](handleEntityNotFound(_0x4daab6,null))[_0x42d3('0x1e')](saveUpdates(_0x226ea4[_0x42d3('0x55')],null))[_0x42d3('0x1e')](respondWithResult(_0x4daab6,null))[_0x42d3('0x28')](handleError(_0x4daab6,null));};exports[_0x42d3('0x57')]=function(_0x3c07c8,_0x1929c4){return db[_0x42d3('0x4d')]['find']({'where':{'id':_0x3c07c8[_0x42d3('0x51')]['id']}})[_0x42d3('0x1e')](handleEntityNotFound(_0x1929c4,null))[_0x42d3('0x1e')](removeEntity(_0x1929c4,null))[_0x42d3('0x28')](handleError(_0x1929c4,null));};exports[_0x42d3('0x58')]=function(_0x46894a,_0x52b5fc){return db[_0x42d3('0x4d')][_0x42d3('0x58')]()[_0x42d3('0x1e')](respondWithResult(_0x52b5fc,null))['catch'](handleError(_0x52b5fc,null));};var interaction_log=require(_0x42d3('0x11'))('chat-interactions');exports[_0x42d3('0x59')]=function(_0x3c8751,_0x332eb2,_0x5a4a47){var _0x46b19a={'agent':{},'channel':_0x42d3('0x5a')};if(_0x3c8751[_0x42d3('0x55')]['id']){delete _0x3c8751['body']['id'];}_0x3c8751[_0x42d3('0x55')][_0x42d3('0x5b')]=!![];_0x3c8751['body']['readAt']=moment()[_0x42d3('0x5c')](_0x42d3('0x5d'));_0x3c8751['body'][_0x42d3('0x5e')]=_0x3c8751[_0x42d3('0x55')][_0x42d3('0x5e')]||_0x3c8751[_0x42d3('0x5f')]['id'];_0x46b19a[_0x42d3('0x60')]['id']=_0x3c8751[_0x42d3('0x55')][_0x42d3('0x5e')];return db[_0x42d3('0x4d')]['find']({'where':{'id':_0x3c8751[_0x42d3('0x51')]['id'],'UserId':null}})[_0x42d3('0x1e')](handleEntityNotFound(_0x332eb2,null))[_0x42d3('0x1e')](saveUpdates(_0x3c8751['body'],null))[_0x42d3('0x1e')](function(_0x5abc9d){if(_0x5abc9d){_0x46b19a[_0x42d3('0x27')]=_0x5abc9d['get']({'plain':!![]});return db[_0x42d3('0x61')][_0x42d3('0x53')]({'where':{'id':_0x5abc9d[_0x42d3('0x62')]}});}return null;})[_0x42d3('0x1e')](handleEntityNotFound(_0x332eb2,null))[_0x42d3('0x1e')](function(_0x51bdf){if(_0x51bdf){return _0x51bdf[_0x42d3('0x56')]({'UserId':_0x3c8751[_0x42d3('0x55')][_0x42d3('0x5e')],'read1stAt':_['isNil'](_0x51bdf[_0x42d3('0x63')])?moment()[_0x42d3('0x5c')](_0x42d3('0x5d')):undefined});}return null;})[_0x42d3('0x1e')](function(_0x3aacef){if(_0x3aacef){_0x46b19a[_0x42d3('0x64')]=_0x3aacef[_0x42d3('0x65')]({'plain':!![]});interaction_log['info'](_0x42d3('0x66'),_0x3c8751[_0x42d3('0x5f')]['id'],_0x3c8751[_0x42d3('0x5f')][_0x42d3('0x36')],_0x3c8751['user'][_0x42d3('0x67')],_0x46b19a[_0x42d3('0x64')]['id'],_0x3c8751[_0x42d3('0x55')]?JSON['stringify'](_0x3c8751[_0x42d3('0x55')]):_0x42d3('0x68'));return respondWithRpcPromise(_0x42d3('0x69'),'acceptMessage',_0x46b19a);}return null;})[_0x42d3('0x1e')](function(_0x736f67){var _0x408d02=_0x42d3('0x6a')+_0x736f67['message'][_0x42d3('0x6b')];return db[_0x42d3('0x6c')][_0x42d3('0x3e')](_0x408d02,{'type':db[_0x42d3('0x6d')][_0x42d3('0x6e')][_0x42d3('0x6f')],'raw':!![]})[_0x42d3('0x1e')](function(_0x3c262a){return _0x3c262a;});})[_0x42d3('0x1e')](function(_0x429921){if(_0x429921){_0x46b19a['message'][_0x42d3('0x70')]=_0x429921[0x0];if(!_0x3c8751[_0x42d3('0x55')]['UserId'])return;return db[_0x42d3('0x71')][_0x42d3('0x53')]({'where':{'id':_0x3c8751['body'][_0x42d3('0x5e')],'role':_0x42d3('0x60')},'attributes':['id',_0x42d3('0x36'),_0x42d3('0x72'),_0x42d3('0x73'),_0x42d3('0x74')],'raw':!![]});}return null;})['then'](function(_0xf04261){if(!_0xf04261)return null;_0x46b19a[_0x42d3('0x27')]['agent']=_0xf04261;return _0x46b19a;})[_0x42d3('0x1e')](function(_0x3ed984){if(_0x3ed984){if(_0x3c8751[_0x42d3('0x55')][_0x42d3('0x75')]){_0x46b19a[_0x42d3('0x27')]['interface']=util['format'](_0x42d3('0x76'),_0x3c8751[_0x42d3('0x5f')][_0x42d3('0x36')]);_0x46b19a[_0x42d3('0x27')][_0x42d3('0x77')]=_0x46b19a[_0x42d3('0x77')];_0x46b19a[_0x42d3('0x27')][_0x42d3('0x78')]=_0x46b19a[_0x42d3('0x77')];_0x46b19a[_0x42d3('0x27')][_0x42d3('0x79')]=_0x42d3('0x59');return respondWithRpcPromise('EventManager',_0x42d3('0x7a'),{'event':_0x42d3('0x7b'),'message':_['merge'](_0x46b19a[_0x42d3('0x27')],JSON['parse'](_0x46b19a[_0x42d3('0x64')][_0x42d3('0x7c')]))},client9002)['then'](function(){return _0x46b19a;});}return _0x46b19a;}return null;})[_0x42d3('0x1e')](respondWithResult(_0x332eb2,null))[_0x42d3('0x28')](handleError(_0x332eb2,null));};var interaction_log=require(_0x42d3('0x11'))('chat-interactions');exports[_0x42d3('0x33')]=function(_0x16452a,_0x4ca127,_0x325d61){var _0x1e4fd2={'agent':{},'channel':_0x42d3('0x5a')};if(_0x16452a[_0x42d3('0x55')]['id']){delete _0x16452a[_0x42d3('0x55')]['id'];}_0x16452a['body'][_0x42d3('0x5e')]=_0x16452a[_0x42d3('0x55')]['UserId']||_0x16452a[_0x42d3('0x5f')]['id'];_0x1e4fd2[_0x42d3('0x60')]['id']=_0x16452a[_0x42d3('0x55')][_0x42d3('0x5e')];return db[_0x42d3('0x4d')][_0x42d3('0x53')]({'where':{'id':_0x16452a[_0x42d3('0x51')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x4ca127,null))[_0x42d3('0x1e')](function(_0x11eb10){if(_0x11eb10){_0x1e4fd2[_0x42d3('0x27')]=_0x11eb10[_0x42d3('0x65')]({'plain':!![]});return db[_0x42d3('0x61')][_0x42d3('0x53')]({'where':{'id':_0x11eb10[_0x42d3('0x62')]}});}return null;})['then'](handleEntityNotFound(_0x4ca127,null))[_0x42d3('0x1e')](function(_0x583131){if(_0x583131){_0x1e4fd2[_0x42d3('0x64')]=_0x583131[_0x42d3('0x65')]({'plain':!![]});interaction_log[_0x42d3('0x1f')](_0x42d3('0x7d'),_0x16452a[_0x42d3('0x5f')]['id'],_0x16452a[_0x42d3('0x5f')][_0x42d3('0x36')],_0x16452a['user'][_0x42d3('0x67')],_0x1e4fd2[_0x42d3('0x64')]['id'],_0x16452a['body']?JSON['stringify'](_0x16452a['body']):'null');return respondWithRpcPromise(_0x42d3('0x7e'),_0x42d3('0x7f'),_0x1e4fd2);}return null;})[_0x42d3('0x1e')](function(_0x5c79f7){var _0x18fe92=_0x42d3('0x6a')+_0x5c79f7[_0x42d3('0x27')][_0x42d3('0x6b')];return db[_0x42d3('0x6c')][_0x42d3('0x3e')](_0x18fe92,{'type':db['Sequelize'][_0x42d3('0x6e')][_0x42d3('0x6f')],'raw':!![]})[_0x42d3('0x1e')](function(_0xe27a4b){return _0xe27a4b;});})[_0x42d3('0x1e')](function(_0x411ee4){if(_0x411ee4){_0x1e4fd2['message'][_0x42d3('0x70')]=_0x411ee4[0x0];if(!_0x16452a[_0x42d3('0x55')][_0x42d3('0x5e')])return;return db[_0x42d3('0x71')]['find']({'where':{'id':_0x16452a['body'][_0x42d3('0x5e')],'role':'agent'},'attributes':['id','name','fullname',_0x42d3('0x73'),_0x42d3('0x74')],'raw':!![]});}return null;})['then'](function(_0x397552){if(!_0x397552)return null;_0x1e4fd2[_0x42d3('0x27')][_0x42d3('0x60')]=_0x397552;return _0x1e4fd2;})[_0x42d3('0x1e')](function(_0x3538d7){if(_0x3538d7){_0x3538d7[_0x42d3('0x27')][_0x42d3('0x80')]=util[_0x42d3('0x5c')]('SIP/%s',_0x16452a['user'][_0x42d3('0x36')]);_0x3538d7[_0x42d3('0x27')][_0x42d3('0x77')]=_0x1e4fd2['channel'];_0x3538d7[_0x42d3('0x27')][_0x42d3('0x78')]=_0x1e4fd2[_0x42d3('0x77')];_0x3538d7['message'][_0x42d3('0x79')]=_0x42d3('0x33');respondWithRpcPromise(_0x42d3('0x7a'),_0x42d3('0x7a'),{'event':_0x42d3('0x81'),'message':_['merge'](_0x1e4fd2[_0x42d3('0x27')],JSON[_0x42d3('0x82')](_0x1e4fd2[_0x42d3('0x64')][_0x42d3('0x7c')]))},client9002);return _0x1e4fd2;}return null;})['then'](respondWithResult(_0x4ca127,null))[_0x42d3('0x28')](handleError(_0x4ca127,null));};
\ No newline at end of file