Built motion from commit a61a4a20.|2.5.46
[motion2.git] / server / api / chatMessage / chatMessage.controller.js
index d277e59..4300ae3 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x771f=['agent','CmContact','Contact','ChatInteraction','ChatInteractionId','isNil','read1stAt','get','role','interaction','null','AcceptMessage','acceptMessage','manual','interface','SIP/%s','channel','event','EventManager','acceptmessage','parse','formData','RejectMessage','eml-format','rimraf','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','squel','desk.js','querystring','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','socket.io-emitter','./chatMessage.socket','jayson/promise','client','http','request','info','debug','ChatMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','ChatMessage,\x20%s,\x20%s','request\x20sent','result','sendStatus','end','status','json','offset','limit','count','Content-Range','apply','reject','save','update','then','destroy','stack','name','send','map','ChatMessage','type','key','model','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filter','merge','options','includeAll','include','rows','catch','params','rawAttributes','find','create','body','describe','chat-interactions','accept','chat','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x771f,0x105));var _0xf771=function(_0xb99421,_0xaab133){_0xb99421=_0xb99421-0x0;var _0x4b3ec7=_0x771f[_0xb99421];return _0x4b3ec7;};'use strict';var emlformat=require(_0xf771('0x0'));var rimraf=require(_0xf771('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xf771('0x2'));var moment=require(_0xf771('0x3'));var BPromise=require(_0xf771('0x4'));var Mustache=require(_0xf771('0x5'));var util=require(_0xf771('0x6'));var path=require(_0xf771('0x7'));var sox=require('sox');var csv=require(_0xf771('0x8'));var ejs=require(_0xf771('0x9'));var fs=require('fs');var fs_extra=require(_0xf771('0xa'));var _=require(_0xf771('0xb'));var squel=require(_0xf771('0xc'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xf771('0xd'));var toCsv=require(_0xf771('0x8'));var querystring=require(_0xf771('0xe'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0xf771('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0xf771('0x10'));var hardwareService=require(_0xf771('0x11'));var logger=require('../../config/logger')(_0xf771('0x12'));var utils=require('../../config/utils');var config=require(_0xf771('0x13'));var licenseUtil=require(_0xf771('0x14'));var db=require(_0xf771('0x15'))['db'];config[_0xf771('0x16')]=_[_0xf771('0x17')](config[_0xf771('0x16')],{'host':'localhost','port':0x18eb});var socket=require(_0xf771('0x18'))(new Redis(config[_0xf771('0x16')]));require(_0xf771('0x19'))['register'](socket);var jayson=require(_0xf771('0x1a'));var client=jayson['client']['http']({'port':0x232c});var client9002=jayson[_0xf771('0x1b')][_0xf771('0x1c')]({'port':0x232a});function respondWithRpcPromise(_0x10c1db,_0x517884,_0x45dce6,_0x37cdd7){return new BPromise(function(_0x4aac86,_0x1726f8){var _0x29aaf5=_0x37cdd7||client;return _0x29aaf5[_0xf771('0x1d')](_0x10c1db,_0x45dce6)['then'](function(_0x57ee84){logger[_0xf771('0x1e')]('ChatMessage,\x20%s,\x20%s',_0x517884,'request\x20sent');logger[_0xf771('0x1f')](_0xf771('0x20'),_0x517884,'request\x20sent',JSON[_0xf771('0x21')](_0x57ee84));if(_0x57ee84[_0xf771('0x22')]){if(_0x57ee84['error'][_0xf771('0x23')]===0x1f4){logger[_0xf771('0x22')]('ChatMessage,\x20%s,\x20%s',_0x517884,_0x57ee84[_0xf771('0x22')][_0xf771('0x24')]);return _0x1726f8(_0x57ee84[_0xf771('0x22')][_0xf771('0x24')]);}logger['error'](_0xf771('0x25'),_0x517884,_0x57ee84['error'][_0xf771('0x24')]);return _0x4aac86(_0x57ee84[_0xf771('0x22')][_0xf771('0x24')]);}else{logger['info'](_0xf771('0x25'),_0x517884,_0xf771('0x26'));_0x4aac86(_0x57ee84[_0xf771('0x27')][_0xf771('0x24')]);}})['catch'](function(_0x28b4ca){logger[_0xf771('0x22')](_0xf771('0x25'),_0x517884,_0x28b4ca);_0x1726f8(_0x28b4ca);});});}function respondWithStatusCode(_0x544558,_0x1879d4){_0x1879d4=_0x1879d4||0xcc;return function(_0x3dc985){if(_0x3dc985){return _0x544558[_0xf771('0x28')](_0x1879d4);}return _0x544558['status'](_0x1879d4)[_0xf771('0x29')]();};}function respondWithResult(_0x1c058a,_0x2fafff){_0x2fafff=_0x2fafff||0xc8;return function(_0x35175f){if(_0x35175f){return _0x1c058a[_0xf771('0x2a')](_0x2fafff)[_0xf771('0x2b')](_0x35175f);}};}function respondWithFilteredResult(_0x337d0c,_0x2bd689){return function(_0x1fadb3){if(_0x1fadb3){var _0x271fd5=typeof _0x2bd689[_0xf771('0x2c')]==='undefined'&&typeof _0x2bd689[_0xf771('0x2d')]==='undefined';var _0x484927=_0x1fadb3[_0xf771('0x2e')];var _0x11bd8a=_0x271fd5?0x0:_0x2bd689[_0xf771('0x2c')];var _0x3ed6b2=_0x271fd5?_0x1fadb3['count']:_0x2bd689[_0xf771('0x2c')]+_0x2bd689[_0xf771('0x2d')];var _0x27e755;if(_0x3ed6b2>=_0x484927){_0x3ed6b2=_0x484927;_0x27e755=0xc8;}else{_0x27e755=0xce;}_0x337d0c[_0xf771('0x2a')](_0x27e755);return _0x337d0c['set'](_0xf771('0x2f'),_0x11bd8a+'-'+_0x3ed6b2+'/'+_0x484927)['json'](_0x1fadb3);}return null;};}function patchUpdates(_0x3d281e){return function(_0x51c851){try{jsonpatch[_0xf771('0x30')](_0x51c851,_0x3d281e,!![]);}catch(_0x25ca0b){return BPromise[_0xf771('0x31')](_0x25ca0b);}return _0x51c851[_0xf771('0x32')]();};}function saveUpdates(_0x1e7750,_0x20a945){return function(_0x25b52e){if(_0x25b52e){return _0x25b52e[_0xf771('0x33')](_0x1e7750)[_0xf771('0x34')](function(_0x3175be){return _0x3175be;});}return null;};}function removeEntity(_0x1c4841,_0x590cab){return function(_0x21771c){if(_0x21771c){return _0x21771c[_0xf771('0x35')]()[_0xf771('0x34')](function(){_0x1c4841[_0xf771('0x2a')](0xcc)[_0xf771('0x29')]();});}};}function handleEntityNotFound(_0x523e14,_0x12c245){return function(_0x3c9bcd){if(!_0x3c9bcd){_0x523e14[_0xf771('0x28')](0x194);}return _0x3c9bcd;};}function handleError(_0x73e26c,_0x11b90e){_0x11b90e=_0x11b90e||0x1f4;return function(_0x5dc6c2){logger['error'](_0x5dc6c2[_0xf771('0x36')]);if(_0x5dc6c2['name']){delete _0x5dc6c2[_0xf771('0x37')];}_0x73e26c[_0xf771('0x2a')](_0x11b90e)[_0xf771('0x38')](_0x5dc6c2);};}exports['index']=function(_0x25db9a,_0x4c75c8){var _0x3a234b={},_0x25284c={},_0x16124a={'count':0x0,'rows':[]};var _0x278789=_[_0xf771('0x39')](db[_0xf771('0x3a')]['rawAttributes'],function(_0x54a8a7){return{'name':_0x54a8a7['fieldName'],'type':_0x54a8a7[_0xf771('0x3b')][_0xf771('0x3c')]};});_0x25284c[_0xf771('0x3d')]=_[_0xf771('0x39')](_0x278789,_0xf771('0x37'));_0x25284c['query']=_[_0xf771('0x3e')](_0x25db9a[_0xf771('0x3f')]);_0x25284c[_0xf771('0x40')]=_[_0xf771('0x41')](_0x25284c[_0xf771('0x3d')],_0x25284c['query']);_0x3a234b[_0xf771('0x42')]=_[_0xf771('0x41')](_0x25284c[_0xf771('0x3d')],qs[_0xf771('0x43')](_0x25db9a[_0xf771('0x3f')][_0xf771('0x43')]));_0x3a234b[_0xf771('0x42')]=_0x3a234b[_0xf771('0x42')][_0xf771('0x44')]?_0x3a234b['attributes']:_0x25284c[_0xf771('0x3d')];if(!_0x25db9a['query'][_0xf771('0x45')](_0xf771('0x46'))){_0x3a234b[_0xf771('0x2d')]=qs['limit'](_0x25db9a[_0xf771('0x3f')][_0xf771('0x2d')]);_0x3a234b[_0xf771('0x2c')]=qs[_0xf771('0x2c')](_0x25db9a['query']['offset']);}_0x3a234b[_0xf771('0x47')]=qs[_0xf771('0x48')](_0x25db9a[_0xf771('0x3f')][_0xf771('0x48')]);_0x3a234b[_0xf771('0x49')]=qs['filters'](_['pick'](_0x25db9a[_0xf771('0x3f')],_0x25284c[_0xf771('0x40')]),_0x278789);if(_0x25db9a[_0xf771('0x3f')][_0xf771('0x4a')]){_0x3a234b[_0xf771('0x49')]=_[_0xf771('0x4b')](_0x3a234b['where'],{'$or':_[_0xf771('0x39')](_0x278789,function(_0x531885){if(_0x531885['type']!=='VIRTUAL'){var _0x472f81={};_0x472f81[_0x531885[_0xf771('0x37')]]={'$like':'%'+_0x25db9a[_0xf771('0x3f')][_0xf771('0x4a')]+'%'};return _0x472f81;}})});}_0x3a234b=_[_0xf771('0x4b')]({},_0x3a234b,_0x25db9a[_0xf771('0x4c')]);var _0x104dc0={'where':_0x3a234b[_0xf771('0x49')]};return db['ChatMessage'][_0xf771('0x2e')](_0x104dc0)['then'](function(_0x3ab09c){_0x16124a['count']=_0x3ab09c;if(_0x25db9a['query'][_0xf771('0x4d')]){_0x3a234b[_0xf771('0x4e')]=[{'all':!![]}];}return db['ChatMessage']['findAll'](_0x3a234b);})[_0xf771('0x34')](function(_0x527df8){_0x16124a[_0xf771('0x4f')]=_0x527df8;return _0x16124a;})['then'](respondWithFilteredResult(_0x4c75c8,_0x3a234b))[_0xf771('0x50')](handleError(_0x4c75c8,null));};exports['show']=function(_0x42f2d7,_0x3bb911){var _0x595c3b={'raw':!![],'where':{'id':_0x42f2d7[_0xf771('0x51')]['id']}},_0xed9d0={};_0xed9d0[_0xf771('0x3d')]=_[_0xf771('0x3e')](db[_0xf771('0x3a')][_0xf771('0x52')]);_0xed9d0[_0xf771('0x3f')]=_[_0xf771('0x3e')](_0x42f2d7[_0xf771('0x3f')]);_0xed9d0[_0xf771('0x40')]=_[_0xf771('0x41')](_0xed9d0[_0xf771('0x3d')],_0xed9d0['query']);_0x595c3b[_0xf771('0x42')]=_[_0xf771('0x41')](_0xed9d0[_0xf771('0x3d')],qs['fields'](_0x42f2d7[_0xf771('0x3f')][_0xf771('0x43')]));_0x595c3b[_0xf771('0x42')]=_0x595c3b['attributes'][_0xf771('0x44')]?_0x595c3b['attributes']:_0xed9d0[_0xf771('0x3d')];if(_0x42f2d7[_0xf771('0x3f')][_0xf771('0x4d')]){_0x595c3b[_0xf771('0x4e')]=[{'all':!![]}];}_0x595c3b=_[_0xf771('0x4b')]({},_0x595c3b,_0x42f2d7['options']);return db['ChatMessage'][_0xf771('0x53')](_0x595c3b)['then'](handleEntityNotFound(_0x3bb911,null))[_0xf771('0x34')](respondWithResult(_0x3bb911,null))[_0xf771('0x50')](handleError(_0x3bb911,null));};exports[_0xf771('0x54')]=function(_0x49db0f,_0xbb96be){return db[_0xf771('0x3a')]['create'](_0x49db0f[_0xf771('0x55')],{})[_0xf771('0x34')](respondWithResult(_0xbb96be,0xc9))[_0xf771('0x50')](handleError(_0xbb96be,null));};exports[_0xf771('0x33')]=function(_0xf44743,_0x171ed5){if(_0xf44743[_0xf771('0x55')]['id']){delete _0xf44743[_0xf771('0x55')]['id'];}return db[_0xf771('0x3a')][_0xf771('0x53')]({'where':{'id':_0xf44743[_0xf771('0x51')]['id']}})['then'](handleEntityNotFound(_0x171ed5,null))['then'](saveUpdates(_0xf44743[_0xf771('0x55')],null))[_0xf771('0x34')](respondWithResult(_0x171ed5,null))[_0xf771('0x50')](handleError(_0x171ed5,null));};exports['destroy']=function(_0x3de757,_0x51c2e7){return db[_0xf771('0x3a')]['find']({'where':{'id':_0x3de757['params']['id']}})[_0xf771('0x34')](handleEntityNotFound(_0x51c2e7,null))[_0xf771('0x34')](removeEntity(_0x51c2e7,null))['catch'](handleError(_0x51c2e7,null));};exports[_0xf771('0x56')]=function(_0x185f43,_0x40c785){return db[_0xf771('0x3a')][_0xf771('0x56')]()[_0xf771('0x34')](respondWithResult(_0x40c785,null))[_0xf771('0x50')](handleError(_0x40c785,null));};var interaction_log=require('../../config/logger')(_0xf771('0x57'));exports[_0xf771('0x58')]=function(_0x4bd8c4,_0xc046be,_0x2d7a6f){var _0x5e14a7={'agent':{},'channel':_0xf771('0x59')};if(_0x4bd8c4[_0xf771('0x55')]['id']){delete _0x4bd8c4['body']['id'];}_0x4bd8c4[_0xf771('0x55')][_0xf771('0x5a')]=!![];_0x4bd8c4[_0xf771('0x55')][_0xf771('0x5b')]=moment()[_0xf771('0x5c')](_0xf771('0x5d'));_0x4bd8c4[_0xf771('0x55')][_0xf771('0x5e')]=_0x4bd8c4[_0xf771('0x55')][_0xf771('0x5e')]||_0x4bd8c4[_0xf771('0x5f')]['id'];_0x5e14a7[_0xf771('0x60')]['id']=_0x4bd8c4[_0xf771('0x55')]['UserId'];return db['ChatMessage'][_0xf771('0x53')]({'where':{'id':_0x4bd8c4[_0xf771('0x51')]['id'],'UserId':null},'include':[{'model':db[_0xf771('0x61')],'as':_0xf771('0x62')}]})[_0xf771('0x34')](handleEntityNotFound(_0xc046be,null))['then'](saveUpdates(_0x4bd8c4[_0xf771('0x55')],null))[_0xf771('0x34')](function(_0x2da3cc){if(_0x2da3cc){_0x5e14a7[_0xf771('0x24')]=_0x2da3cc['get']({'plain':!![]});return db[_0xf771('0x63')][_0xf771('0x53')]({'where':{'id':_0x2da3cc[_0xf771('0x64')]}});}return null;})[_0xf771('0x34')](handleEntityNotFound(_0xc046be,null))['then'](function(_0x564d71){if(_0x564d71){return _0x564d71['update']({'UserId':_0x4bd8c4[_0xf771('0x55')][_0xf771('0x5e')],'read1stAt':_[_0xf771('0x65')](_0x564d71[_0xf771('0x66')])?moment()[_0xf771('0x5c')](_0xf771('0x5d')):undefined});}return null;})[_0xf771('0x34')](function(_0x44689a){if(_0x44689a){_0x5e14a7['interaction']=_0x44689a[_0xf771('0x67')]({'plain':!![]});interaction_log[_0xf771('0x1e')]('[CHATMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x4bd8c4[_0xf771('0x5f')]['id'],_0x4bd8c4['user'][_0xf771('0x37')],_0x4bd8c4[_0xf771('0x5f')][_0xf771('0x68')],_0x5e14a7[_0xf771('0x69')]['id'],_0x4bd8c4[_0xf771('0x55')]?JSON[_0xf771('0x21')](_0x4bd8c4['body']):_0xf771('0x6a'));return respondWithRpcPromise(_0xf771('0x6b'),_0xf771('0x6c'),_0x5e14a7);}return null;})[_0xf771('0x34')](function(_0x456ea9){if(_0x456ea9){if(_0x4bd8c4[_0xf771('0x55')][_0xf771('0x6d')]){_0x5e14a7[_0xf771('0x24')][_0xf771('0x6e')]=util['format'](_0xf771('0x6f'),_0x4bd8c4[_0xf771('0x5f')][_0xf771('0x37')]);_0x5e14a7[_0xf771('0x24')]['channel']=_0x5e14a7[_0xf771('0x70')];_0x5e14a7[_0xf771('0x24')][_0xf771('0x71')]='accept';return respondWithRpcPromise(_0xf771('0x72'),_0xf771('0x72'),{'event':_0xf771('0x73'),'message':_[_0xf771('0x4b')](_0x5e14a7[_0xf771('0x24')],JSON[_0xf771('0x74')](_0x5e14a7[_0xf771('0x69')][_0xf771('0x75')]))},client9002)['then'](function(){return _0x5e14a7;});}return _0x5e14a7;}return null;})['then'](respondWithResult(_0xc046be,null))[_0xf771('0x50')](handleError(_0xc046be,null));};var interaction_log=require('../../config/logger')('chat-interactions');exports[_0xf771('0x31')]=function(_0x4af459,_0x5e61e0,_0x58860a){var _0xe8bfd6={'agent':{},'channel':'chat'};if(_0x4af459['body']['id']){delete _0x4af459[_0xf771('0x55')]['id'];}_0x4af459[_0xf771('0x55')][_0xf771('0x5e')]=_0x4af459[_0xf771('0x55')][_0xf771('0x5e')]||_0x4af459[_0xf771('0x5f')]['id'];_0xe8bfd6[_0xf771('0x60')]['id']=_0x4af459[_0xf771('0x55')][_0xf771('0x5e')];return db['ChatMessage'][_0xf771('0x53')]({'where':{'id':_0x4af459[_0xf771('0x51')]['id'],'UserId':null}})[_0xf771('0x34')](handleEntityNotFound(_0x5e61e0,null))[_0xf771('0x34')](function(_0x37c356){if(_0x37c356){_0xe8bfd6[_0xf771('0x24')]=_0x37c356[_0xf771('0x67')]({'plain':!![]});return db[_0xf771('0x63')][_0xf771('0x53')]({'where':{'id':_0x37c356[_0xf771('0x64')]}});}return null;})[_0xf771('0x34')](handleEntityNotFound(_0x5e61e0,null))[_0xf771('0x34')](function(_0x317828){if(_0x317828){_0xe8bfd6[_0xf771('0x69')]=_0x317828['get']({'plain':!![]});interaction_log['info']('[CHATMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x4af459[_0xf771('0x5f')]['id'],_0x4af459['user'][_0xf771('0x37')],_0x4af459['user'][_0xf771('0x68')],_0xe8bfd6[_0xf771('0x69')]['id'],_0x4af459[_0xf771('0x55')]?JSON[_0xf771('0x21')](_0x4af459[_0xf771('0x55')]):_0xf771('0x6a'));return respondWithRpcPromise(_0xf771('0x76'),'rejectMessage',_0xe8bfd6);}return null;})[_0xf771('0x34')](function(_0x144301){if(_0x144301){_0x144301[_0xf771('0x24')][_0xf771('0x6e')]=util[_0xf771('0x5c')](_0xf771('0x6f'),_0x4af459[_0xf771('0x5f')][_0xf771('0x37')]);_0x144301[_0xf771('0x24')][_0xf771('0x70')]=_0xe8bfd6[_0xf771('0x70')];_0x144301[_0xf771('0x24')]['event']=_0xf771('0x31');respondWithRpcPromise('EventManager',_0xf771('0x72'),{'event':'rejectmessage','message':_0x144301['message']},client9002);return _0xe8bfd6;}return null;})['then'](respondWithResult(_0x5e61e0,null))[_0xf771('0x50')](handleError(_0x5e61e0,null));};
\ No newline at end of file
+var _0x85c6=['accept','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','ChatInteractionId','read1stAt','interaction','get','role','null','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','sequelize','Sequelize','QueryTypes','SELECT','contact','User','agent','internal','SIP/%s','channel','motionChannel','event','EventManager','formData','chat','RejectMessage','ContactId','fullname','email','interface','reject','parse','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','redis','defaults','localhost','socket.io-emitter','./chatMessage.socket','register','client','http','request','then','info','ChatMessage,\x20%s,\x20%s','ChatMessage,\x20%s,\x20%s,\x20%s','request\x20sent','error','message','result','status','end','json','offset','limit','undefined','count','set','Content-Range','apply','save','sendStatus','stack','name','send','index','map','ChatMessage','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','nolimit','sort','where','filter','merge','VIRTUAL','include','findAll','catch','show','rawAttributes','options','find','create','update','body','params','destroy','describe','chat-interactions'];(function(_0x37de6e,_0x2d81e7){var _0x2c63a3=function(_0x4ba309){while(--_0x4ba309){_0x37de6e['push'](_0x37de6e['shift']());}};_0x2c63a3(++_0x2d81e7);}(_0x85c6,0x19f));var _0x685c=function(_0x506b1b,_0x4888d6){_0x506b1b=_0x506b1b-0x0;var _0x489d65=_0x85c6[_0x506b1b];return _0x489d65;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x685c('0x0'));var zipdir=require(_0x685c('0x1'));var jsonpatch=require(_0x685c('0x2'));var rp=require(_0x685c('0x3'));var moment=require(_0x685c('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x685c('0x5'));var util=require(_0x685c('0x6'));var path=require(_0x685c('0x7'));var sox=require(_0x685c('0x8'));var csv=require(_0x685c('0x9'));var ejs=require(_0x685c('0xa'));var fs=require('fs');var fs_extra=require(_0x685c('0xb'));var _=require(_0x685c('0xc'));var squel=require('squel');var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x685c('0xd'));var toCsv=require(_0x685c('0x9'));var querystring=require(_0x685c('0xe'));var Papa=require(_0x685c('0xf'));var Redis=require(_0x685c('0x10'));var authService=require(_0x685c('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x685c('0x12'));var hardwareService=require(_0x685c('0x13'));var logger=require('../../config/logger')(_0x685c('0x14'));var utils=require('../../config/utils');var config=require(_0x685c('0x15'));var licenseUtil=require(_0x685c('0x16'));var db=require('../../mysqldb')['db'];config[_0x685c('0x17')]=_[_0x685c('0x18')](config['redis'],{'host':_0x685c('0x19'),'port':0x18eb});var socket=require(_0x685c('0x1a'))(new Redis(config[_0x685c('0x17')]));require(_0x685c('0x1b'))[_0x685c('0x1c')](socket);var jayson=require('jayson/promise');var client=jayson[_0x685c('0x1d')][_0x685c('0x1e')]({'port':0x232c});var client9002=jayson[_0x685c('0x1d')]['http']({'port':0x232a});function respondWithRpcPromise(_0x408a41,_0x3da04e,_0x102010,_0x4c6a0c){return new BPromise(function(_0x198390,_0x474204){var _0x23997c=_0x4c6a0c||client;return _0x23997c[_0x685c('0x1f')](_0x408a41,_0x102010)[_0x685c('0x20')](function(_0x51058f){logger[_0x685c('0x21')](_0x685c('0x22'),_0x3da04e,'request\x20sent');logger['debug'](_0x685c('0x23'),_0x3da04e,_0x685c('0x24'),JSON['stringify'](_0x51058f));if(_0x51058f['error']){if(_0x51058f[_0x685c('0x25')]['code']===0x1f4){logger['error'](_0x685c('0x22'),_0x3da04e,_0x51058f['error'][_0x685c('0x26')]);return _0x474204(_0x51058f[_0x685c('0x25')][_0x685c('0x26')]);}logger[_0x685c('0x25')]('ChatMessage,\x20%s,\x20%s',_0x3da04e,_0x51058f[_0x685c('0x25')][_0x685c('0x26')]);return _0x198390(_0x51058f[_0x685c('0x25')][_0x685c('0x26')]);}else{logger['info'](_0x685c('0x22'),_0x3da04e,_0x685c('0x24'));_0x198390(_0x51058f[_0x685c('0x27')][_0x685c('0x26')]);}})['catch'](function(_0x2280b0){logger[_0x685c('0x25')](_0x685c('0x22'),_0x3da04e,_0x2280b0);_0x474204(_0x2280b0);});});}function respondWithStatusCode(_0x3d7590,_0x227ed0){_0x227ed0=_0x227ed0||0xcc;return function(_0x2b84bd){if(_0x2b84bd){return _0x3d7590['sendStatus'](_0x227ed0);}return _0x3d7590[_0x685c('0x28')](_0x227ed0)[_0x685c('0x29')]();};}function respondWithResult(_0x3a74c8,_0x4b3e1d){_0x4b3e1d=_0x4b3e1d||0xc8;return function(_0x4a1d6b){if(_0x4a1d6b){return _0x3a74c8[_0x685c('0x28')](_0x4b3e1d)[_0x685c('0x2a')](_0x4a1d6b);}};}function respondWithFilteredResult(_0x4158a5,_0x27c514){return function(_0x1f7a1a){if(_0x1f7a1a){var _0x51fe76=typeof _0x27c514[_0x685c('0x2b')]==='undefined'&&typeof _0x27c514[_0x685c('0x2c')]===_0x685c('0x2d');var _0x4810b8=_0x1f7a1a[_0x685c('0x2e')];var _0x27833f=_0x51fe76?0x0:_0x27c514['offset'];var _0x27f2c7=_0x51fe76?_0x1f7a1a[_0x685c('0x2e')]:_0x27c514['offset']+_0x27c514[_0x685c('0x2c')];var _0x183962;if(_0x27f2c7>=_0x4810b8){_0x27f2c7=_0x4810b8;_0x183962=0xc8;}else{_0x183962=0xce;}_0x4158a5[_0x685c('0x28')](_0x183962);return _0x4158a5[_0x685c('0x2f')](_0x685c('0x30'),_0x27833f+'-'+_0x27f2c7+'/'+_0x4810b8)[_0x685c('0x2a')](_0x1f7a1a);}return null;};}function patchUpdates(_0x59169d){return function(_0x3b6358){try{jsonpatch[_0x685c('0x31')](_0x3b6358,_0x59169d,!![]);}catch(_0x416e6d){return BPromise['reject'](_0x416e6d);}return _0x3b6358[_0x685c('0x32')]();};}function saveUpdates(_0x8e7123,_0x25c731){return function(_0x4caa74){if(_0x4caa74){return _0x4caa74['update'](_0x8e7123)[_0x685c('0x20')](function(_0x3dc3ef){return _0x3dc3ef;});}return null;};}function removeEntity(_0x47f8af,_0x9670aa){return function(_0x206086){if(_0x206086){return _0x206086['destroy']()[_0x685c('0x20')](function(){_0x47f8af[_0x685c('0x28')](0xcc)[_0x685c('0x29')]();});}};}function handleEntityNotFound(_0x569ea2,_0x27527f){return function(_0x497d4a){if(!_0x497d4a){_0x569ea2[_0x685c('0x33')](0x194);}return _0x497d4a;};}function handleError(_0x450e36,_0x28f3b1){_0x28f3b1=_0x28f3b1||0x1f4;return function(_0x4df849){logger[_0x685c('0x25')](_0x4df849[_0x685c('0x34')]);if(_0x4df849[_0x685c('0x35')]){delete _0x4df849[_0x685c('0x35')];}_0x450e36['status'](_0x28f3b1)[_0x685c('0x36')](_0x4df849);};}exports[_0x685c('0x37')]=function(_0x4567e9,_0x9eafbb){var _0x3719db={},_0x2c5dfe={},_0x2947d1={'count':0x0,'rows':[]};var _0x4856f7=_[_0x685c('0x38')](db[_0x685c('0x39')]['rawAttributes'],function(_0x277c41){return{'name':_0x277c41[_0x685c('0x3a')],'type':_0x277c41[_0x685c('0x3b')][_0x685c('0x3c')]};});_0x2c5dfe[_0x685c('0x3d')]=_['map'](_0x4856f7,_0x685c('0x35'));_0x2c5dfe[_0x685c('0x3e')]=_[_0x685c('0x3f')](_0x4567e9[_0x685c('0x3e')]);_0x2c5dfe[_0x685c('0x40')]=_[_0x685c('0x41')](_0x2c5dfe[_0x685c('0x3d')],_0x2c5dfe['query']);_0x3719db[_0x685c('0x42')]=_['intersection'](_0x2c5dfe[_0x685c('0x3d')],qs[_0x685c('0x43')](_0x4567e9[_0x685c('0x3e')][_0x685c('0x43')]));_0x3719db[_0x685c('0x42')]=_0x3719db[_0x685c('0x42')][_0x685c('0x44')]?_0x3719db[_0x685c('0x42')]:_0x2c5dfe[_0x685c('0x3d')];if(!_0x4567e9[_0x685c('0x3e')]['hasOwnProperty'](_0x685c('0x45'))){_0x3719db['limit']=qs[_0x685c('0x2c')](_0x4567e9['query']['limit']);_0x3719db[_0x685c('0x2b')]=qs[_0x685c('0x2b')](_0x4567e9[_0x685c('0x3e')][_0x685c('0x2b')]);}_0x3719db['order']=qs[_0x685c('0x46')](_0x4567e9[_0x685c('0x3e')][_0x685c('0x46')]);_0x3719db[_0x685c('0x47')]=qs[_0x685c('0x40')](_['pick'](_0x4567e9['query'],_0x2c5dfe[_0x685c('0x40')]),_0x4856f7);if(_0x4567e9[_0x685c('0x3e')][_0x685c('0x48')]){_0x3719db['where']=_[_0x685c('0x49')](_0x3719db[_0x685c('0x47')],{'$or':_['map'](_0x4856f7,function(_0x5abe96){if(_0x5abe96[_0x685c('0x3b')]!==_0x685c('0x4a')){var _0x490608={};_0x490608[_0x5abe96[_0x685c('0x35')]]={'$like':'%'+_0x4567e9[_0x685c('0x3e')]['filter']+'%'};return _0x490608;}})});}_0x3719db=_[_0x685c('0x49')]({},_0x3719db,_0x4567e9['options']);var _0x2279e4={'where':_0x3719db[_0x685c('0x47')]};return db[_0x685c('0x39')][_0x685c('0x2e')](_0x2279e4)[_0x685c('0x20')](function(_0x58bc9a){_0x2947d1[_0x685c('0x2e')]=_0x58bc9a;if(_0x4567e9['query']['includeAll']){_0x3719db[_0x685c('0x4b')]=[{'all':!![]}];}return db[_0x685c('0x39')][_0x685c('0x4c')](_0x3719db);})[_0x685c('0x20')](function(_0x3e94f8){_0x2947d1['rows']=_0x3e94f8;return _0x2947d1;})[_0x685c('0x20')](respondWithFilteredResult(_0x9eafbb,_0x3719db))[_0x685c('0x4d')](handleError(_0x9eafbb,null));};exports[_0x685c('0x4e')]=function(_0x1f7334,_0x4a2706){var _0x136065={'raw':!![],'where':{'id':_0x1f7334['params']['id']}},_0x22675e={};_0x22675e[_0x685c('0x3d')]=_[_0x685c('0x3f')](db[_0x685c('0x39')][_0x685c('0x4f')]);_0x22675e[_0x685c('0x3e')]=_['keys'](_0x1f7334[_0x685c('0x3e')]);_0x22675e[_0x685c('0x40')]=_['intersection'](_0x22675e['model'],_0x22675e[_0x685c('0x3e')]);_0x136065[_0x685c('0x42')]=_[_0x685c('0x41')](_0x22675e[_0x685c('0x3d')],qs[_0x685c('0x43')](_0x1f7334[_0x685c('0x3e')][_0x685c('0x43')]));_0x136065[_0x685c('0x42')]=_0x136065[_0x685c('0x42')][_0x685c('0x44')]?_0x136065[_0x685c('0x42')]:_0x22675e[_0x685c('0x3d')];if(_0x1f7334[_0x685c('0x3e')]['includeAll']){_0x136065[_0x685c('0x4b')]=[{'all':!![]}];}_0x136065=_['merge']({},_0x136065,_0x1f7334[_0x685c('0x50')]);return db[_0x685c('0x39')][_0x685c('0x51')](_0x136065)[_0x685c('0x20')](handleEntityNotFound(_0x4a2706,null))[_0x685c('0x20')](respondWithResult(_0x4a2706,null))[_0x685c('0x4d')](handleError(_0x4a2706,null));};exports[_0x685c('0x52')]=function(_0x4525c1,_0x36524f){return db[_0x685c('0x39')]['create'](_0x4525c1['body'],{})[_0x685c('0x20')](respondWithResult(_0x36524f,0xc9))[_0x685c('0x4d')](handleError(_0x36524f,null));};exports[_0x685c('0x53')]=function(_0x5821f1,_0x1629f1){if(_0x5821f1[_0x685c('0x54')]['id']){delete _0x5821f1['body']['id'];}return db[_0x685c('0x39')][_0x685c('0x51')]({'where':{'id':_0x5821f1[_0x685c('0x55')]['id']}})['then'](handleEntityNotFound(_0x1629f1,null))['then'](saveUpdates(_0x5821f1[_0x685c('0x54')],null))[_0x685c('0x20')](respondWithResult(_0x1629f1,null))[_0x685c('0x4d')](handleError(_0x1629f1,null));};exports[_0x685c('0x56')]=function(_0x50c18d,_0x2f55a4){return db[_0x685c('0x39')][_0x685c('0x51')]({'where':{'id':_0x50c18d[_0x685c('0x55')]['id']}})['then'](handleEntityNotFound(_0x2f55a4,null))[_0x685c('0x20')](removeEntity(_0x2f55a4,null))[_0x685c('0x4d')](handleError(_0x2f55a4,null));};exports[_0x685c('0x57')]=function(_0xc61836,_0xc0ed2b){return db['ChatMessage']['describe']()[_0x685c('0x20')](respondWithResult(_0xc0ed2b,null))[_0x685c('0x4d')](handleError(_0xc0ed2b,null));};var interaction_log=require('../../config/logger')(_0x685c('0x58'));exports[_0x685c('0x59')]=function(_0x1c266e,_0x2de12a,_0x608c9b){var _0x4faa60={'agent':{},'channel':'chat'};if(_0x1c266e[_0x685c('0x54')]['id']){delete _0x1c266e[_0x685c('0x54')]['id'];}_0x1c266e[_0x685c('0x54')][_0x685c('0x5a')]=!![];_0x1c266e[_0x685c('0x54')][_0x685c('0x5b')]=moment()[_0x685c('0x5c')](_0x685c('0x5d'));_0x1c266e['body'][_0x685c('0x5e')]=_0x1c266e[_0x685c('0x54')][_0x685c('0x5e')]||_0x1c266e[_0x685c('0x5f')]['id'];_0x4faa60['agent']['id']=_0x1c266e[_0x685c('0x54')][_0x685c('0x5e')];return db[_0x685c('0x39')][_0x685c('0x51')]({'where':{'id':_0x1c266e[_0x685c('0x55')]['id'],'UserId':null}})[_0x685c('0x20')](handleEntityNotFound(_0x2de12a,null))[_0x685c('0x20')](saveUpdates(_0x1c266e[_0x685c('0x54')],null))[_0x685c('0x20')](function(_0x440bd9){if(_0x440bd9){_0x4faa60[_0x685c('0x26')]=_0x440bd9['get']({'plain':!![]});return db['ChatInteraction']['find']({'where':{'id':_0x440bd9[_0x685c('0x60')]}});}return null;})['then'](handleEntityNotFound(_0x2de12a,null))[_0x685c('0x20')](function(_0xa4f302){if(_0xa4f302){return _0xa4f302[_0x685c('0x53')]({'UserId':_0x1c266e[_0x685c('0x54')]['UserId'],'read1stAt':_['isNil'](_0xa4f302[_0x685c('0x61')])?moment()[_0x685c('0x5c')](_0x685c('0x5d')):undefined});}return null;})[_0x685c('0x20')](function(_0x141e1c){if(_0x141e1c){_0x4faa60[_0x685c('0x62')]=_0x141e1c[_0x685c('0x63')]({'plain':!![]});interaction_log[_0x685c('0x21')]('[CHATMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x1c266e[_0x685c('0x5f')]['id'],_0x1c266e['user'][_0x685c('0x35')],_0x1c266e[_0x685c('0x5f')][_0x685c('0x64')],_0x4faa60[_0x685c('0x62')]['id'],_0x1c266e[_0x685c('0x54')]?JSON['stringify'](_0x1c266e[_0x685c('0x54')]):_0x685c('0x65'));return respondWithRpcPromise('AcceptMessage',_0x685c('0x66'),_0x4faa60);}return null;})[_0x685c('0x20')](function(_0x2875d5){var _0x37285e=_0x685c('0x67')+_0x2875d5['message']['ContactId'];return db[_0x685c('0x68')][_0x685c('0x3e')](_0x37285e,{'type':db[_0x685c('0x69')][_0x685c('0x6a')][_0x685c('0x6b')],'raw':!![]})[_0x685c('0x20')](function(_0x1837d7){return _0x1837d7;});})['then'](function(_0xa6f4cf){if(_0xa6f4cf){_0x4faa60['message'][_0x685c('0x6c')]=_0xa6f4cf[0x0];if(!_0x1c266e[_0x685c('0x54')]['UserId'])return;return db[_0x685c('0x6d')][_0x685c('0x51')]({'where':{'id':_0x1c266e[_0x685c('0x54')][_0x685c('0x5e')],'role':_0x685c('0x6e')},'attributes':['id',_0x685c('0x35'),'fullname','email',_0x685c('0x6f')],'raw':!![]});}return null;})[_0x685c('0x20')](function(_0x5a7eae){if(!_0x5a7eae)return null;_0x4faa60['message'][_0x685c('0x6e')]=_0x5a7eae;return _0x4faa60;})[_0x685c('0x20')](function(_0x5a2bf3){if(_0x5a2bf3){if(_0x1c266e[_0x685c('0x54')]['manual']){_0x4faa60[_0x685c('0x26')]['interface']=util['format'](_0x685c('0x70'),_0x1c266e['user'][_0x685c('0x35')]);_0x4faa60['message'][_0x685c('0x71')]=_0x4faa60[_0x685c('0x71')];_0x4faa60[_0x685c('0x26')][_0x685c('0x72')]=_0x4faa60[_0x685c('0x71')];_0x4faa60[_0x685c('0x26')][_0x685c('0x73')]='accept';return respondWithRpcPromise('EventManager',_0x685c('0x74'),{'event':'acceptmessage','message':_[_0x685c('0x49')](_0x4faa60[_0x685c('0x26')],JSON['parse'](_0x4faa60[_0x685c('0x62')][_0x685c('0x75')]))},client9002)[_0x685c('0x20')](function(){return _0x4faa60;});}return _0x4faa60;}return null;})[_0x685c('0x20')](respondWithResult(_0x2de12a,null))[_0x685c('0x4d')](handleError(_0x2de12a,null));};var interaction_log=require('../../config/logger')(_0x685c('0x58'));exports['reject']=function(_0x1de38d,_0x52e294,_0x29deb1){var _0x5ddbfd={'agent':{},'channel':_0x685c('0x76')};if(_0x1de38d[_0x685c('0x54')]['id']){delete _0x1de38d['body']['id'];}_0x1de38d[_0x685c('0x54')][_0x685c('0x5e')]=_0x1de38d[_0x685c('0x54')][_0x685c('0x5e')]||_0x1de38d[_0x685c('0x5f')]['id'];_0x5ddbfd['agent']['id']=_0x1de38d[_0x685c('0x54')][_0x685c('0x5e')];return db[_0x685c('0x39')][_0x685c('0x51')]({'where':{'id':_0x1de38d['params']['id'],'UserId':null}})[_0x685c('0x20')](handleEntityNotFound(_0x52e294,null))['then'](function(_0x5303ca){if(_0x5303ca){_0x5ddbfd[_0x685c('0x26')]=_0x5303ca[_0x685c('0x63')]({'plain':!![]});return db['ChatInteraction']['find']({'where':{'id':_0x5303ca[_0x685c('0x60')]}});}return null;})[_0x685c('0x20')](handleEntityNotFound(_0x52e294,null))[_0x685c('0x20')](function(_0x595940){if(_0x595940){_0x5ddbfd[_0x685c('0x62')]=_0x595940['get']({'plain':!![]});interaction_log[_0x685c('0x21')]('[CHATMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x1de38d[_0x685c('0x5f')]['id'],_0x1de38d[_0x685c('0x5f')][_0x685c('0x35')],_0x1de38d[_0x685c('0x5f')][_0x685c('0x64')],_0x5ddbfd['interaction']['id'],_0x1de38d[_0x685c('0x54')]?JSON['stringify'](_0x1de38d[_0x685c('0x54')]):_0x685c('0x65'));return respondWithRpcPromise(_0x685c('0x77'),'rejectMessage',_0x5ddbfd);}return null;})[_0x685c('0x20')](function(_0x28ec1c){var _0x4bd1e9=_0x685c('0x67')+_0x28ec1c['message'][_0x685c('0x78')];return db[_0x685c('0x68')][_0x685c('0x3e')](_0x4bd1e9,{'type':db[_0x685c('0x69')][_0x685c('0x6a')]['SELECT'],'raw':!![]})['then'](function(_0x570eff){return _0x570eff;});})[_0x685c('0x20')](function(_0x5da422){if(_0x5da422){_0x5ddbfd['message'][_0x685c('0x6c')]=_0x5da422[0x0];if(!_0x1de38d[_0x685c('0x54')][_0x685c('0x5e')])return;return db[_0x685c('0x6d')][_0x685c('0x51')]({'where':{'id':_0x1de38d[_0x685c('0x54')][_0x685c('0x5e')],'role':_0x685c('0x6e')},'attributes':['id',_0x685c('0x35'),_0x685c('0x79'),_0x685c('0x7a'),_0x685c('0x6f')],'raw':!![]});}return null;})['then'](function(_0x3369a2){if(!_0x3369a2)return null;_0x5ddbfd[_0x685c('0x26')][_0x685c('0x6e')]=_0x3369a2;return _0x5ddbfd;})[_0x685c('0x20')](function(_0x535f1a){if(_0x535f1a){_0x535f1a['message'][_0x685c('0x7b')]=util[_0x685c('0x5c')](_0x685c('0x70'),_0x1de38d[_0x685c('0x5f')][_0x685c('0x35')]);_0x535f1a[_0x685c('0x26')]['channel']=_0x5ddbfd[_0x685c('0x71')];_0x535f1a[_0x685c('0x26')][_0x685c('0x72')]=_0x5ddbfd[_0x685c('0x71')];_0x535f1a[_0x685c('0x26')][_0x685c('0x73')]=_0x685c('0x7c');respondWithRpcPromise('EventManager',_0x685c('0x74'),{'event':'rejectmessage','message':_['merge'](_0x5ddbfd[_0x685c('0x26')],JSON[_0x685c('0x7d')](_0x5ddbfd[_0x685c('0x62')][_0x685c('0x75')]))},client9002);return _0x5ddbfd;}return null;})['then'](respondWithResult(_0x52e294,null))[_0x685c('0x4d')](handleError(_0x52e294,null));};
\ No newline at end of file