Built motion from commit 9d7072cc.|2.5.39
[motion2.git] / server / api / chatMessage / chatMessage.controller.js
index 9019925..4edc428 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x402f=['sox','to-csv','ejs','lodash','squel','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','redis','socket.io-emitter','./chatMessage.socket','register','jayson/promise','client','request','then','info','ChatMessage,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','result','catch','end','status','offset','limit','Content-Range','json','apply','reject','save','update','sendStatus','stack','name','send','ChatMessage','rawAttributes','fieldName','type','key','model','map','query','keys','filters','intersection','attributes','fields','length','nolimit','order','sort','where','pick','filter','VIRTUAL','options','count','include','findAll','rows','show','merge','find','create','body','destroy','chat-interactions','accept','chat','read','format','UserId','user','agent','params','CmContact','Contact','get','ChatInteraction','ChatInteractionId','isNil','read1stAt','YYYY-MM-DD\x20HH:mm:ss','interaction','[CHATMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','AcceptMessage','manual','interface','SIP/%s','channel','event','EventManager','acceptmessage','formData','[CHATMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','rejectmessage','html-pdf','rimraf','request-promise','moment','bluebird','util'];(function(_0x5830d6,_0x4a4a51){var _0x57debb=function(_0x1ef169){while(--_0x1ef169){_0x5830d6['push'](_0x5830d6['shift']());}};_0x57debb(++_0x4a4a51);}(_0x402f,0x6f));var _0xf402=function(_0x4852ff,_0x35118d){_0x4852ff=_0x4852ff-0x0;var _0x3ee92e=_0x402f[_0x4852ff];return _0x3ee92e;};'use strict';var pdf=require(_0xf402('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xf402('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xf402('0x2'));var moment=require(_0xf402('0x3'));var BPromise=require(_0xf402('0x4'));var Mustache=require('mustache');var util=require(_0xf402('0x5'));var path=require('path');var sox=require(_0xf402('0x6'));var csv=require(_0xf402('0x7'));var ejs=require(_0xf402('0x8'));var fs=require('fs');var _=require(_0xf402('0x9'));var squel=require(_0xf402('0xa'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xf402('0xb'));var toCsv=require(_0xf402('0x7'));var querystring=require(_0xf402('0xc'));var Papa=require(_0xf402('0xd'));var Redis=require(_0xf402('0xe'));var authService=require(_0xf402('0xf'));var qs=require(_0xf402('0x10'));var as=require(_0xf402('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf402('0x12'))('api');var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];config[_0xf402('0x13')]=_['defaults'](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0xf402('0x14'))(new Redis(config['redis']));require(_0xf402('0x15'))[_0xf402('0x16')](socket);var jayson=require(_0xf402('0x17'));var client=jayson[_0xf402('0x18')]['http']({'port':0x232c});var client9002=jayson[_0xf402('0x18')]['http']({'port':0x232a});function respondWithRpcPromise(_0x3af9e3,_0x5e38d8,_0x5cc240,_0x545d1a){return new BPromise(function(_0xb45d00,_0x1e66a3){var _0xd406bf=_0x545d1a||client;return _0xd406bf[_0xf402('0x19')](_0x3af9e3,_0x5cc240)[_0xf402('0x1a')](function(_0x5d7236){logger[_0xf402('0x1b')](_0xf402('0x1c'),_0x5e38d8,_0xf402('0x1d'));logger[_0xf402('0x1e')]('ChatMessage,\x20%s,\x20%s,\x20%s',_0x5e38d8,_0xf402('0x1d'),JSON[_0xf402('0x1f')](_0x5d7236));if(_0x5d7236[_0xf402('0x20')]){if(_0x5d7236[_0xf402('0x20')][_0xf402('0x21')]===0x1f4){logger[_0xf402('0x20')](_0xf402('0x1c'),_0x5e38d8,_0x5d7236[_0xf402('0x20')][_0xf402('0x22')]);return _0x1e66a3(_0x5d7236['error'][_0xf402('0x22')]);}logger['error'](_0xf402('0x1c'),_0x5e38d8,_0x5d7236[_0xf402('0x20')][_0xf402('0x22')]);return _0xb45d00(_0x5d7236[_0xf402('0x20')][_0xf402('0x22')]);}else{logger[_0xf402('0x1b')](_0xf402('0x1c'),_0x5e38d8,_0xf402('0x1d'));_0xb45d00(_0x5d7236[_0xf402('0x23')][_0xf402('0x22')]);}})[_0xf402('0x24')](function(_0xfad629){logger['error'](_0xf402('0x1c'),_0x5e38d8,_0xfad629);_0x1e66a3(_0xfad629);});});}function respondWithStatusCode(_0x16c21c,_0x28fc75){_0x28fc75=_0x28fc75||0xcc;return function(_0x35543b){if(_0x35543b){return _0x16c21c['sendStatus'](_0x28fc75);}return _0x16c21c['status'](_0x28fc75)[_0xf402('0x25')]();};}function respondWithResult(_0x3f837e,_0x3a6a8d){_0x3a6a8d=_0x3a6a8d||0xc8;return function(_0xb7c8e4){if(_0xb7c8e4){return _0x3f837e[_0xf402('0x26')](_0x3a6a8d)['json'](_0xb7c8e4);}};}function respondWithFilteredResult(_0x39a38a,_0x47c0fb){return function(_0x1574e3){if(_0x1574e3){var _0xe3dc2f=_0x1574e3['count'],_0x45ead3=_0x47c0fb[_0xf402('0x27')],_0xb28d88=_0x47c0fb[_0xf402('0x27')]+_0x47c0fb[_0xf402('0x28')],_0xd82d61;if(_0xb28d88>=_0xe3dc2f){_0xb28d88=_0xe3dc2f;_0xd82d61=0xc8;}else{_0xd82d61=0xce;}_0x39a38a['status'](_0xd82d61);return _0x39a38a['set'](_0xf402('0x29'),_0x45ead3+'-'+_0xb28d88+'/'+_0xe3dc2f)[_0xf402('0x2a')](_0x1574e3);}return null;};}function patchUpdates(_0x1ecc55){return function(_0x221d6d){try{jsonpatch[_0xf402('0x2b')](_0x221d6d,_0x1ecc55,!![]);}catch(_0x4a593b){return BPromise[_0xf402('0x2c')](_0x4a593b);}return _0x221d6d[_0xf402('0x2d')]();};}function saveUpdates(_0x44aa26,_0x1f2cc4){return function(_0x176b17){if(_0x176b17){return _0x176b17[_0xf402('0x2e')](_0x44aa26)['then'](function(_0x69b6ff){return _0x69b6ff;});}return null;};}function removeEntity(_0x209eae,_0x1af6a5){return function(_0x53d725){if(_0x53d725){return _0x53d725['destroy']()[_0xf402('0x1a')](function(){_0x209eae[_0xf402('0x26')](0xcc)[_0xf402('0x25')]();});}};}function handleEntityNotFound(_0x5cf566,_0x291636){return function(_0x335b34){if(!_0x335b34){_0x5cf566[_0xf402('0x2f')](0x194);}return _0x335b34;};}function handleError(_0x29b86a,_0xa90acd){_0xa90acd=_0xa90acd||0x1f4;return function(_0x2c4217){logger['error'](_0x2c4217[_0xf402('0x30')]);if(_0x2c4217[_0xf402('0x31')]){delete _0x2c4217[_0xf402('0x31')];}_0x29b86a[_0xf402('0x26')](_0xa90acd)[_0xf402('0x32')](_0x2c4217);};}exports['index']=function(_0x330d85,_0x55d87d){var _0x40e9e4={},_0x50a430={},_0x5ac297={'count':0x0,'rows':[]};var _0x66f414=_['map'](db[_0xf402('0x33')][_0xf402('0x34')],function(_0x5dc99b){return{'name':_0x5dc99b[_0xf402('0x35')],'type':_0x5dc99b[_0xf402('0x36')][_0xf402('0x37')]};});_0x50a430[_0xf402('0x38')]=_[_0xf402('0x39')](_0x66f414,_0xf402('0x31'));_0x50a430[_0xf402('0x3a')]=_[_0xf402('0x3b')](_0x330d85['query']);_0x50a430[_0xf402('0x3c')]=_[_0xf402('0x3d')](_0x50a430[_0xf402('0x38')],_0x50a430[_0xf402('0x3a')]);_0x40e9e4[_0xf402('0x3e')]=_['intersection'](_0x50a430[_0xf402('0x38')],qs['fields'](_0x330d85[_0xf402('0x3a')][_0xf402('0x3f')]));_0x40e9e4[_0xf402('0x3e')]=_0x40e9e4[_0xf402('0x3e')][_0xf402('0x40')]?_0x40e9e4[_0xf402('0x3e')]:_0x50a430[_0xf402('0x38')];if(!_0x330d85['query']['hasOwnProperty'](_0xf402('0x41'))){_0x40e9e4[_0xf402('0x28')]=qs[_0xf402('0x28')](_0x330d85[_0xf402('0x3a')][_0xf402('0x28')]);_0x40e9e4[_0xf402('0x27')]=qs['offset'](_0x330d85[_0xf402('0x3a')][_0xf402('0x27')]);}_0x40e9e4[_0xf402('0x42')]=qs[_0xf402('0x43')](_0x330d85['query'][_0xf402('0x43')]);_0x40e9e4[_0xf402('0x44')]=qs[_0xf402('0x3c')](_[_0xf402('0x45')](_0x330d85[_0xf402('0x3a')],_0x50a430[_0xf402('0x3c')]),_0x66f414);if(_0x330d85['query'][_0xf402('0x46')]){_0x40e9e4[_0xf402('0x44')]=_['merge'](_0x40e9e4['where'],{'$or':_[_0xf402('0x39')](_0x66f414,function(_0x3ac553){if(_0x3ac553['type']!==_0xf402('0x47')){var _0x1152c8={};_0x1152c8[_0x3ac553[_0xf402('0x31')]]={'$like':'%'+_0x330d85['query'][_0xf402('0x46')]+'%'};return _0x1152c8;}})});}_0x40e9e4=_['merge']({},_0x40e9e4,_0x330d85[_0xf402('0x48')]);var _0x4b72ba={'where':_0x40e9e4[_0xf402('0x44')]};return db[_0xf402('0x33')]['count'](_0x4b72ba)['then'](function(_0x32b863){_0x5ac297[_0xf402('0x49')]=_0x32b863;if(_0x330d85['query']['includeAll']){_0x40e9e4[_0xf402('0x4a')]=[{'all':!![]}];}return db[_0xf402('0x33')][_0xf402('0x4b')](_0x40e9e4);})[_0xf402('0x1a')](function(_0x20a1cd){_0x5ac297[_0xf402('0x4c')]=_0x20a1cd;return _0x5ac297;})[_0xf402('0x1a')](respondWithFilteredResult(_0x55d87d,_0x40e9e4))[_0xf402('0x24')](handleError(_0x55d87d,null));};exports[_0xf402('0x4d')]=function(_0x4816f9,_0x1f128d){var _0x71825e={'raw':!![],'where':{'id':_0x4816f9['params']['id']}},_0x29f869={};_0x29f869[_0xf402('0x38')]=_[_0xf402('0x3b')](db[_0xf402('0x33')][_0xf402('0x34')]);_0x29f869['query']=_[_0xf402('0x3b')](_0x4816f9[_0xf402('0x3a')]);_0x29f869[_0xf402('0x3c')]=_[_0xf402('0x3d')](_0x29f869[_0xf402('0x38')],_0x29f869[_0xf402('0x3a')]);_0x71825e[_0xf402('0x3e')]=_[_0xf402('0x3d')](_0x29f869[_0xf402('0x38')],qs[_0xf402('0x3f')](_0x4816f9[_0xf402('0x3a')][_0xf402('0x3f')]));_0x71825e[_0xf402('0x3e')]=_0x71825e['attributes']['length']?_0x71825e[_0xf402('0x3e')]:_0x29f869['model'];if(_0x4816f9['query']['includeAll']){_0x71825e[_0xf402('0x4a')]=[{'all':!![]}];}_0x71825e=_[_0xf402('0x4e')]({},_0x71825e,_0x4816f9['options']);return db[_0xf402('0x33')][_0xf402('0x4f')](_0x71825e)[_0xf402('0x1a')](handleEntityNotFound(_0x1f128d,null))[_0xf402('0x1a')](respondWithResult(_0x1f128d,null))[_0xf402('0x24')](handleError(_0x1f128d,null));};exports[_0xf402('0x50')]=function(_0x14c159,_0x138a56){return db['ChatMessage']['create'](_0x14c159[_0xf402('0x51')],{})[_0xf402('0x1a')](respondWithResult(_0x138a56,0xc9))['catch'](handleError(_0x138a56,null));};exports[_0xf402('0x2e')]=function(_0x2ee779,_0x49b1d6){if(_0x2ee779['body']['id']){delete _0x2ee779[_0xf402('0x51')]['id'];}return db['ChatMessage'][_0xf402('0x4f')]({'where':{'id':_0x2ee779['params']['id']}})[_0xf402('0x1a')](handleEntityNotFound(_0x49b1d6,null))[_0xf402('0x1a')](saveUpdates(_0x2ee779['body'],null))['then'](respondWithResult(_0x49b1d6,null))[_0xf402('0x24')](handleError(_0x49b1d6,null));};exports[_0xf402('0x52')]=function(_0x4e9b13,_0x13cd79){return db[_0xf402('0x33')][_0xf402('0x4f')]({'where':{'id':_0x4e9b13['params']['id']}})[_0xf402('0x1a')](handleEntityNotFound(_0x13cd79,null))[_0xf402('0x1a')](removeEntity(_0x13cd79,null))[_0xf402('0x24')](handleError(_0x13cd79,null));};exports['describe']=function(_0x82e852,_0x7938cc){return db[_0xf402('0x33')]['describe']()[_0xf402('0x1a')](respondWithResult(_0x7938cc,null))[_0xf402('0x24')](handleError(_0x7938cc,null));};var interaction_log=require('../../config/logger')(_0xf402('0x53'));exports[_0xf402('0x54')]=function(_0x470b41,_0x40cec0,_0x4b9ab1){var _0x3d21b2={'agent':{},'channel':_0xf402('0x55')};if(_0x470b41['body']['id']){delete _0x470b41[_0xf402('0x51')]['id'];}_0x470b41[_0xf402('0x51')][_0xf402('0x56')]=!![];_0x470b41[_0xf402('0x51')]['readAt']=moment()[_0xf402('0x57')]('YYYY-MM-DD\x20HH:mm:ss');_0x470b41[_0xf402('0x51')][_0xf402('0x58')]=_0x470b41[_0xf402('0x51')]['UserId']||_0x470b41[_0xf402('0x59')]['id'];_0x3d21b2[_0xf402('0x5a')]['id']=_0x470b41['body']['UserId'];return db['ChatMessage']['find']({'where':{'id':_0x470b41[_0xf402('0x5b')]['id'],'UserId':null},'include':[{'model':db[_0xf402('0x5c')],'as':_0xf402('0x5d')}]})[_0xf402('0x1a')](handleEntityNotFound(_0x40cec0,null))['then'](saveUpdates(_0x470b41[_0xf402('0x51')],null))[_0xf402('0x1a')](function(_0x385a95){if(_0x385a95){_0x3d21b2[_0xf402('0x22')]=_0x385a95[_0xf402('0x5e')]({'plain':!![]});return db[_0xf402('0x5f')][_0xf402('0x4f')]({'where':{'id':_0x385a95[_0xf402('0x60')]}});}return null;})[_0xf402('0x1a')](handleEntityNotFound(_0x40cec0,null))[_0xf402('0x1a')](function(_0x624e79){if(_0x624e79){return _0x624e79['update']({'UserId':_0x470b41[_0xf402('0x51')][_0xf402('0x58')],'read1stAt':_[_0xf402('0x61')](_0x624e79[_0xf402('0x62')])?moment()[_0xf402('0x57')](_0xf402('0x63')):undefined});}return null;})[_0xf402('0x1a')](function(_0xc313cc){if(_0xc313cc){_0x3d21b2[_0xf402('0x64')]=_0xc313cc['get']({'plain':!![]});interaction_log[_0xf402('0x1b')](_0xf402('0x65'),_0x470b41[_0xf402('0x59')]['id'],_0x470b41[_0xf402('0x59')]['name'],_0x470b41['user'][_0xf402('0x66')],_0x3d21b2['interaction']['id'],_0x470b41['body']?JSON[_0xf402('0x1f')](_0x470b41[_0xf402('0x51')]):_0xf402('0x67'));return respondWithRpcPromise(_0xf402('0x68'),'acceptMessage',_0x3d21b2);}return null;})['then'](function(_0x4b67fa){if(_0x4b67fa){if(_0x470b41[_0xf402('0x51')][_0xf402('0x69')]){_0x3d21b2[_0xf402('0x22')][_0xf402('0x6a')]=util['format'](_0xf402('0x6b'),_0x470b41[_0xf402('0x59')][_0xf402('0x31')]);_0x3d21b2[_0xf402('0x22')][_0xf402('0x6c')]=_0x3d21b2[_0xf402('0x6c')];_0x3d21b2[_0xf402('0x22')][_0xf402('0x6d')]='accept';return respondWithRpcPromise('EventManager',_0xf402('0x6e'),{'event':_0xf402('0x6f'),'message':_[_0xf402('0x4e')](_0x3d21b2[_0xf402('0x22')],JSON['parse'](_0x3d21b2[_0xf402('0x64')][_0xf402('0x70')]))},client9002)[_0xf402('0x1a')](function(){return _0x3d21b2;});}return _0x3d21b2;}return null;})[_0xf402('0x1a')](respondWithResult(_0x40cec0,null))[_0xf402('0x24')](handleError(_0x40cec0,null));};var interaction_log=require(_0xf402('0x12'))(_0xf402('0x53'));exports['reject']=function(_0x20956b,_0x57641c,_0x470455){var _0x511f35={'agent':{},'channel':_0xf402('0x55')};if(_0x20956b[_0xf402('0x51')]['id']){delete _0x20956b[_0xf402('0x51')]['id'];}_0x20956b[_0xf402('0x51')][_0xf402('0x58')]=_0x20956b[_0xf402('0x51')]['UserId']||_0x20956b[_0xf402('0x59')]['id'];_0x511f35[_0xf402('0x5a')]['id']=_0x20956b['body'][_0xf402('0x58')];return db[_0xf402('0x33')][_0xf402('0x4f')]({'where':{'id':_0x20956b[_0xf402('0x5b')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x57641c,null))['then'](function(_0x2705e8){if(_0x2705e8){_0x511f35['message']=_0x2705e8[_0xf402('0x5e')]({'plain':!![]});return db['ChatInteraction']['find']({'where':{'id':_0x2705e8[_0xf402('0x60')]}});}return null;})[_0xf402('0x1a')](handleEntityNotFound(_0x57641c,null))[_0xf402('0x1a')](function(_0x2f2177){if(_0x2f2177){_0x511f35[_0xf402('0x64')]=_0x2f2177[_0xf402('0x5e')]({'plain':!![]});interaction_log[_0xf402('0x1b')](_0xf402('0x71'),_0x20956b[_0xf402('0x59')]['id'],_0x20956b['user'][_0xf402('0x31')],_0x20956b[_0xf402('0x59')][_0xf402('0x66')],_0x511f35[_0xf402('0x64')]['id'],_0x20956b[_0xf402('0x51')]?JSON[_0xf402('0x1f')](_0x20956b[_0xf402('0x51')]):_0xf402('0x67'));return respondWithRpcPromise(_0xf402('0x72'),_0xf402('0x73'),_0x511f35);}return null;})[_0xf402('0x1a')](function(_0x5060fd){if(_0x5060fd){_0x5060fd['message'][_0xf402('0x6a')]=util['format'](_0xf402('0x6b'),_0x20956b[_0xf402('0x59')][_0xf402('0x31')]);_0x5060fd['message']['channel']=_0x511f35[_0xf402('0x6c')];_0x5060fd[_0xf402('0x22')][_0xf402('0x6d')]='reject';respondWithRpcPromise('EventManager',_0xf402('0x6e'),{'event':_0xf402('0x74'),'message':_0x5060fd['message']},client9002);return _0x511f35;}return null;})[_0xf402('0x1a')](respondWithResult(_0x57641c,null))[_0xf402('0x24')](handleError(_0x57641c,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