Built motion from commit (unavailable).|2.5.24
[motion2.git] / server / api / chatMessage / chatMessage.controller.js
index 9f8d783..74db39e 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xed1d=['html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','to-csv','ejs','lodash','squel','desk.js','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./chatMessage.socket','register','http','client','Sequelize','The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.','request','info','ChatMessage,\x20%s,\x20%s','ChatMessage,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','catch','sendStatus','status','end','json','count','offset','limit','Content-Range','reject','save','update','then','destroy','stack','name','send','map','ChatMessage','rawAttributes','fieldName','type','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','pick','filter','where','merge','includeAll','include','findAll','rows','show','params','options','find','create','body','describe','accept','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','CmContact','ChatInteraction','ChatInteractionId','read1stAt','interaction','get','[CHATMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','null','acceptMessage','interface','SIP/%s','channel','event','EventManager','acceptmessage','parse','formData','chat-interactions','chat','[CHATMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectmessage'];(function(_0x19950b,_0x53d0d7){var _0x3c6b41=function(_0x3924ad){while(--_0x3924ad){_0x19950b['push'](_0x19950b['shift']());}};_0x3c6b41(++_0x53d0d7);}(_0xed1d,0xec));var _0xded1=function(_0x349811,_0x2fb811){_0x349811=_0x349811-0x0;var _0x4fa6bb=_0xed1d[_0x349811];return _0x4fa6bb;};'use strict';var pdf=require(_0xded1('0x0'));var emlformat=require(_0xded1('0x1'));var rimraf=require(_0xded1('0x2'));var zipdir=require(_0xded1('0x3'));var jsonpatch=require(_0xded1('0x4'));var rp=require(_0xded1('0x5'));var moment=require(_0xded1('0x6'));var BPromise=require(_0xded1('0x7'));var Mustache=require(_0xded1('0x8'));var util=require('util');var path=require(_0xded1('0x9'));var sox=require('sox');var csv=require(_0xded1('0xa'));var ejs=require(_0xded1('0xb'));var fs=require('fs');var _=require(_0xded1('0xc'));var squel=require(_0xded1('0xd'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xded1('0xe'));var toCsv=require(_0xded1('0xa'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0xded1('0xf'));var qs=require(_0xded1('0x10'));var as=require(_0xded1('0x11'));var hardwareService=require(_0xded1('0x12'));var logger=require(_0xded1('0x13'))('api');var utils=require('../../config/utils');var config=require(_0xded1('0x14'));var db=require(_0xded1('0x15'))['db'];config[_0xded1('0x16')]=_[_0xded1('0x17')](config[_0xded1('0x16')],{'host':_0xded1('0x18'),'port':0x18eb});var socket=require(_0xded1('0x19'))(new Redis(config[_0xded1('0x16')]));require(_0xded1('0x1a'))[_0xded1('0x1b')](socket);var jayson=require('jayson/promise');var client=jayson['client'][_0xded1('0x1c')]({'port':0x232c});var client9002=jayson[_0xded1('0x1d')][_0xded1('0x1c')]({'port':0x232a});function checkPasswordPattern(_0x7b6411,_0x236132,_0x3ba7b0){if(_0x3ba7b0){var _0x593f97=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x593f97['test'](_0x236132)){return _0x7b6411;}else{throw new db[(_0xded1('0x1e'))]['ValidationError'](_0xded1('0x1f'));}}else{return _0x7b6411;}}function respondWithRpcPromise(_0x488add,_0x43314e,_0x12d73a,_0x419c23){return new BPromise(function(_0x13aa1b,_0x1aa552){var _0xf2cf05=_0x419c23||client;return _0xf2cf05[_0xded1('0x20')](_0x488add,_0x12d73a)['then'](function(_0x1157f8){logger[_0xded1('0x21')](_0xded1('0x22'),_0x43314e,'request\x20sent');logger['debug'](_0xded1('0x23'),_0x43314e,_0xded1('0x24'),JSON[_0xded1('0x25')](_0x1157f8));if(_0x1157f8[_0xded1('0x26')]){if(_0x1157f8[_0xded1('0x26')][_0xded1('0x27')]===0x1f4){logger[_0xded1('0x26')](_0xded1('0x22'),_0x43314e,_0x1157f8[_0xded1('0x26')]['message']);return _0x1aa552(_0x1157f8['error']['message']);}logger[_0xded1('0x26')](_0xded1('0x22'),_0x43314e,_0x1157f8['error']['message']);return _0x13aa1b(_0x1157f8[_0xded1('0x26')][_0xded1('0x28')]);}else{logger[_0xded1('0x21')]('ChatMessage,\x20%s,\x20%s',_0x43314e,'request\x20sent');_0x13aa1b(_0x1157f8['result'][_0xded1('0x28')]);}})[_0xded1('0x29')](function(_0x1dc556){logger[_0xded1('0x26')](_0xded1('0x22'),_0x43314e,_0x1dc556);_0x1aa552(_0x1dc556);});});}function respondWithStatusCode(_0x1e6227,_0x1320ea){_0x1320ea=_0x1320ea||0xcc;return function(_0x1020f2){if(_0x1020f2){return _0x1e6227[_0xded1('0x2a')](_0x1320ea);}return _0x1e6227[_0xded1('0x2b')](_0x1320ea)[_0xded1('0x2c')]();};}function respondWithResult(_0x2ca599,_0x24e024){_0x24e024=_0x24e024||0xc8;return function(_0x4f349f){if(_0x4f349f){return _0x2ca599[_0xded1('0x2b')](_0x24e024)[_0xded1('0x2d')](_0x4f349f);}};}function respondWithFilteredResult(_0x577590,_0xa61603){return function(_0x353256){if(_0x353256){var _0x20b71b=_0x353256[_0xded1('0x2e')],_0x1577ca=_0xa61603[_0xded1('0x2f')],_0x4d052a=_0xa61603[_0xded1('0x2f')]+_0xa61603[_0xded1('0x30')],_0x5f52a9;if(_0x4d052a>=_0x20b71b){_0x4d052a=_0x20b71b;_0x5f52a9=0xc8;}else{_0x5f52a9=0xce;}_0x577590['status'](_0x5f52a9);return _0x577590['set'](_0xded1('0x31'),_0x1577ca+'-'+_0x4d052a+'/'+_0x20b71b)[_0xded1('0x2d')](_0x353256);}return null;};}function patchUpdates(_0x31a1dd){return function(_0x4f440d){try{jsonpatch['apply'](_0x4f440d,_0x31a1dd,!![]);}catch(_0x34004a){return BPromise[_0xded1('0x32')](_0x34004a);}return _0x4f440d[_0xded1('0x33')]();};}function saveUpdates(_0x3bfed4,_0x2090fc){return function(_0x3d0d64){if(_0x3d0d64){return _0x3d0d64[_0xded1('0x34')](_0x3bfed4)[_0xded1('0x35')](function(_0x1e1637){return _0x1e1637;});}return null;};}function removeEntity(_0x2b1b4a,_0x502558){return function(_0xbda9be){if(_0xbda9be){return _0xbda9be[_0xded1('0x36')]()['then'](function(){_0x2b1b4a[_0xded1('0x2b')](0xcc)[_0xded1('0x2c')]();});}};}function handleEntityNotFound(_0x575e7e,_0x35348f){return function(_0x976fce){if(!_0x976fce){_0x575e7e[_0xded1('0x2a')](0x194);}return _0x976fce;};}function handleError(_0x475e7e,_0x33d5dc){_0x33d5dc=_0x33d5dc||0x1f4;return function(_0x575e61){logger[_0xded1('0x26')](_0x575e61[_0xded1('0x37')]);if(_0x575e61['name']){delete _0x575e61[_0xded1('0x38')];}_0x475e7e[_0xded1('0x2b')](_0x33d5dc)[_0xded1('0x39')](_0x575e61);};}exports['index']=function(_0x1f621e,_0x130bc3){var _0x10b477={},_0x3f88a3={},_0x24b6c3={'count':0x0,'rows':[]};var _0x37f961=_[_0xded1('0x3a')](db[_0xded1('0x3b')][_0xded1('0x3c')],function(_0x56f9c3){return{'name':_0x56f9c3[_0xded1('0x3d')],'type':_0x56f9c3[_0xded1('0x3e')]['key']};});_0x3f88a3[_0xded1('0x3f')]=_[_0xded1('0x3a')](_0x37f961,_0xded1('0x38'));_0x3f88a3[_0xded1('0x40')]=_[_0xded1('0x41')](_0x1f621e[_0xded1('0x40')]);_0x3f88a3[_0xded1('0x42')]=_['intersection'](_0x3f88a3[_0xded1('0x3f')],_0x3f88a3[_0xded1('0x40')]);_0x10b477['attributes']=_[_0xded1('0x43')](_0x3f88a3[_0xded1('0x3f')],qs['fields'](_0x1f621e[_0xded1('0x40')][_0xded1('0x44')]));_0x10b477[_0xded1('0x45')]=_0x10b477[_0xded1('0x45')][_0xded1('0x46')]?_0x10b477['attributes']:_0x3f88a3[_0xded1('0x3f')];if(!_0x1f621e[_0xded1('0x40')][_0xded1('0x47')](_0xded1('0x48'))){_0x10b477[_0xded1('0x30')]=qs[_0xded1('0x30')](_0x1f621e[_0xded1('0x40')][_0xded1('0x30')]);_0x10b477[_0xded1('0x2f')]=qs[_0xded1('0x2f')](_0x1f621e[_0xded1('0x40')][_0xded1('0x2f')]);}_0x10b477[_0xded1('0x49')]=qs['sort'](_0x1f621e[_0xded1('0x40')]['sort']);_0x10b477['where']=qs['filters'](_[_0xded1('0x4a')](_0x1f621e[_0xded1('0x40')],_0x3f88a3['filters']));if(_0x1f621e[_0xded1('0x40')][_0xded1('0x4b')]){_0x10b477[_0xded1('0x4c')]=_[_0xded1('0x4d')](_0x10b477['where'],{'$or':_[_0xded1('0x3a')](_0x37f961,function(_0x52e57e){if(_0x52e57e['type']!=='VIRTUAL'){var _0x3fb8d1={};_0x3fb8d1[_0x52e57e[_0xded1('0x38')]]={'$like':'%'+_0x1f621e[_0xded1('0x40')][_0xded1('0x4b')]+'%'};return _0x3fb8d1;}})});}_0x10b477=_[_0xded1('0x4d')]({},_0x10b477,_0x1f621e['options']);var _0x3c614d={'where':_0x10b477[_0xded1('0x4c')]};return db[_0xded1('0x3b')]['count'](_0x3c614d)[_0xded1('0x35')](function(_0x25665f){_0x24b6c3[_0xded1('0x2e')]=_0x25665f;if(_0x1f621e[_0xded1('0x40')][_0xded1('0x4e')]){_0x10b477[_0xded1('0x4f')]=[{'all':!![]}];}return db[_0xded1('0x3b')][_0xded1('0x50')](_0x10b477);})['then'](function(_0x3a5688){_0x24b6c3[_0xded1('0x51')]=_0x3a5688;return _0x24b6c3;})[_0xded1('0x35')](respondWithFilteredResult(_0x130bc3,_0x10b477))[_0xded1('0x29')](handleError(_0x130bc3,null));};exports[_0xded1('0x52')]=function(_0x22829a,_0x1d0998){var _0x4c8761={'raw':!![],'where':{'id':_0x22829a[_0xded1('0x53')]['id']}},_0x4e43f8={};_0x4e43f8[_0xded1('0x3f')]=_['keys'](db[_0xded1('0x3b')][_0xded1('0x3c')]);_0x4e43f8[_0xded1('0x40')]=_[_0xded1('0x41')](_0x22829a[_0xded1('0x40')]);_0x4e43f8[_0xded1('0x42')]=_['intersection'](_0x4e43f8[_0xded1('0x3f')],_0x4e43f8[_0xded1('0x40')]);_0x4c8761[_0xded1('0x45')]=_['intersection'](_0x4e43f8[_0xded1('0x3f')],qs[_0xded1('0x44')](_0x22829a[_0xded1('0x40')]['fields']));_0x4c8761[_0xded1('0x45')]=_0x4c8761[_0xded1('0x45')][_0xded1('0x46')]?_0x4c8761[_0xded1('0x45')]:_0x4e43f8[_0xded1('0x3f')];if(_0x22829a['query']['includeAll']){_0x4c8761['include']=[{'all':!![]}];}_0x4c8761=_[_0xded1('0x4d')]({},_0x4c8761,_0x22829a[_0xded1('0x54')]);return db[_0xded1('0x3b')][_0xded1('0x55')](_0x4c8761)[_0xded1('0x35')](handleEntityNotFound(_0x1d0998,null))[_0xded1('0x35')](respondWithResult(_0x1d0998,null))[_0xded1('0x29')](handleError(_0x1d0998,null));};exports[_0xded1('0x56')]=function(_0x54ac55,_0x573abd){return db[_0xded1('0x3b')][_0xded1('0x56')](_0x54ac55[_0xded1('0x57')],{})[_0xded1('0x35')](respondWithResult(_0x573abd,0xc9))[_0xded1('0x29')](handleError(_0x573abd,null));};exports['update']=function(_0x5972de,_0xbf5fb4){if(_0x5972de[_0xded1('0x57')]['id']){delete _0x5972de[_0xded1('0x57')]['id'];}return db['ChatMessage'][_0xded1('0x55')]({'where':{'id':_0x5972de[_0xded1('0x53')]['id']}})[_0xded1('0x35')](handleEntityNotFound(_0xbf5fb4,null))[_0xded1('0x35')](saveUpdates(_0x5972de['body'],null))[_0xded1('0x35')](respondWithResult(_0xbf5fb4,null))[_0xded1('0x29')](handleError(_0xbf5fb4,null));};exports[_0xded1('0x36')]=function(_0x17b73d,_0x4fdb57){return db[_0xded1('0x3b')]['find']({'where':{'id':_0x17b73d[_0xded1('0x53')]['id']}})[_0xded1('0x35')](handleEntityNotFound(_0x4fdb57,null))[_0xded1('0x35')](removeEntity(_0x4fdb57,null))['catch'](handleError(_0x4fdb57,null));};exports[_0xded1('0x58')]=function(_0x1776c4,_0x1ac34b){return db[_0xded1('0x3b')][_0xded1('0x58')]()[_0xded1('0x35')](respondWithResult(_0x1ac34b,null))[_0xded1('0x29')](handleError(_0x1ac34b,null));};var interaction_log=require(_0xded1('0x13'))('chat-interactions');exports[_0xded1('0x59')]=function(_0x266d37,_0x362a92,_0x5affc9){var _0x2311ff={'channel':'chat'};if(_0x266d37[_0xded1('0x57')]['id']){delete _0x266d37[_0xded1('0x57')]['id'];}_0x266d37['body'][_0xded1('0x5a')]=!![];_0x266d37[_0xded1('0x57')][_0xded1('0x5b')]=moment()[_0xded1('0x5c')](_0xded1('0x5d'));_0x266d37[_0xded1('0x57')][_0xded1('0x5e')]=_0x266d37['body'][_0xded1('0x5e')]||_0x266d37[_0xded1('0x5f')]['id'];return db[_0xded1('0x3b')][_0xded1('0x55')]({'where':{'id':_0x266d37['params']['id'],'UserId':null},'include':[{'model':db[_0xded1('0x60')],'as':'Contact'}]})['then'](handleEntityNotFound(_0x362a92,null))['then'](saveUpdates(_0x266d37[_0xded1('0x57')],null))[_0xded1('0x35')](function(_0x22e9bd){if(_0x22e9bd){_0x2311ff[_0xded1('0x28')]=_0x22e9bd['get']({'plain':!![]});return db[_0xded1('0x61')][_0xded1('0x55')]({'where':{'id':_0x22e9bd[_0xded1('0x62')]}});}return null;})[_0xded1('0x35')](handleEntityNotFound(_0x362a92,null))[_0xded1('0x35')](function(_0x1bf8a5){if(_0x1bf8a5){return _0x1bf8a5[_0xded1('0x34')]({'UserId':_0x266d37[_0xded1('0x57')][_0xded1('0x5e')],'read1stAt':_['isNil'](_0x1bf8a5[_0xded1('0x63')])?moment()[_0xded1('0x5c')](_0xded1('0x5d')):undefined});}return null;})[_0xded1('0x35')](function(_0x1e6178){if(_0x1e6178){_0x2311ff[_0xded1('0x64')]=_0x1e6178[_0xded1('0x65')]({'plain':!![]});interaction_log['info'](_0xded1('0x66'),_0x266d37['user']['id'],_0x266d37[_0xded1('0x5f')][_0xded1('0x38')],_0x266d37[_0xded1('0x5f')]['role'],_0x2311ff['interaction']['id'],_0x266d37['body']?JSON[_0xded1('0x25')](_0x266d37[_0xded1('0x57')]):_0xded1('0x67'));return respondWithRpcPromise('AcceptMessage',_0xded1('0x68'),_0x2311ff);}return null;})[_0xded1('0x35')](function(_0x31bdc7){if(_0x31bdc7){if(_0x266d37['body']['manual']){_0x2311ff['message'][_0xded1('0x69')]=util['format'](_0xded1('0x6a'),_0x266d37[_0xded1('0x5f')][_0xded1('0x38')]);_0x2311ff['message'][_0xded1('0x6b')]=_0x2311ff['channel'];_0x2311ff[_0xded1('0x28')][_0xded1('0x6c')]='accept';return respondWithRpcPromise('EventManager',_0xded1('0x6d'),{'event':_0xded1('0x6e'),'message':_['merge'](_0x2311ff[_0xded1('0x28')],JSON[_0xded1('0x6f')](_0x2311ff[_0xded1('0x64')][_0xded1('0x70')]))},client9002)[_0xded1('0x35')](function(){return _0x2311ff;});}return _0x2311ff;}return null;})[_0xded1('0x35')](respondWithResult(_0x362a92,null))[_0xded1('0x29')](handleError(_0x362a92,null));};var interaction_log=require(_0xded1('0x13'))(_0xded1('0x71'));exports[_0xded1('0x32')]=function(_0x3202d5,_0x10a126,_0x4a2ffc){var _0x42d200={'agent':{},'channel':_0xded1('0x72')};if(_0x3202d5[_0xded1('0x57')]['id']){delete _0x3202d5[_0xded1('0x57')]['id'];}_0x3202d5[_0xded1('0x57')][_0xded1('0x5e')]=_0x3202d5[_0xded1('0x57')]['UserId']||_0x3202d5[_0xded1('0x5f')]['id'];_0x42d200['agent']['id']=_0x3202d5['body']['UserId'];return db[_0xded1('0x3b')][_0xded1('0x55')]({'where':{'id':_0x3202d5[_0xded1('0x53')]['id'],'UserId':null}})[_0xded1('0x35')](handleEntityNotFound(_0x10a126,null))[_0xded1('0x35')](function(_0x59a2a7){if(_0x59a2a7){_0x42d200[_0xded1('0x28')]=_0x59a2a7[_0xded1('0x65')]({'plain':!![]});return db[_0xded1('0x61')]['find']({'where':{'id':_0x59a2a7[_0xded1('0x62')]}});}return null;})[_0xded1('0x35')](handleEntityNotFound(_0x10a126,null))[_0xded1('0x35')](function(_0xfe0c76){if(_0xfe0c76){_0x42d200[_0xded1('0x64')]=_0xfe0c76[_0xded1('0x65')]({'plain':!![]});interaction_log['info'](_0xded1('0x73'),_0x3202d5[_0xded1('0x5f')]['id'],_0x3202d5[_0xded1('0x5f')][_0xded1('0x38')],_0x3202d5[_0xded1('0x5f')]['role'],_0x42d200[_0xded1('0x64')]['id'],_0x3202d5['body']?JSON[_0xded1('0x25')](_0x3202d5['body']):_0xded1('0x67'));return respondWithRpcPromise(_0xded1('0x74'),'rejectMessage',_0x42d200);}return null;})['then'](function(_0x553a63){if(_0x553a63){_0x553a63[_0xded1('0x28')][_0xded1('0x69')]=util['format']('SIP/%s',_0x3202d5[_0xded1('0x5f')][_0xded1('0x38')]);_0x553a63[_0xded1('0x28')][_0xded1('0x6b')]=_0x42d200[_0xded1('0x6b')];_0x553a63['message'][_0xded1('0x6c')]='reject';respondWithRpcPromise('EventManager',_0xded1('0x6d'),{'event':_0xded1('0x75'),'message':_0x553a63['message']},client9002);return _0x42d200;}return null;})['then'](respondWithResult(_0x10a126,null))[_0xded1('0x29')](handleError(_0x10a126,null));};
\ No newline at end of file
+var _0x8cc8=['html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./chatMessage.socket','register','jayson/promise','client','http','request','then','info','request\x20sent','debug','error','ChatMessage,\x20%s,\x20%s','message','result','catch','sendStatus','status','end','json','count','offset','set','Content-Range','apply','reject','save','update','stack','name','send','index','type','key','map','query','intersection','model','attributes','fields','length','hasOwnProperty','limit','order','sort','where','pick','filters','filter','merge','ChatMessage','includeAll','include','rows','show','params','keys','options','find','create','body','destroy','describe','chat','read','readAt','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','CmContact','Contact','ChatInteraction','ChatInteractionId','read1stAt','format','interaction','get','role','stringify','null','AcceptMessage','acceptMessage','manual','interface','SIP/%s','channel','event','EventManager','acceptmessage','parse','formData','[CHATMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','rejectMessage','rejectmessage'];(function(_0x220f18,_0xf132b1){var _0xe36f17=function(_0x2dbbae){while(--_0x2dbbae){_0x220f18['push'](_0x220f18['shift']());}};_0xe36f17(++_0xf132b1);}(_0x8cc8,0x177));var _0x88cc=function(_0x188e18,_0xd3ff47){_0x188e18=_0x188e18-0x0;var _0x54f848=_0x8cc8[_0x188e18];return _0x54f848;};'use strict';var pdf=require(_0x88cc('0x0'));var emlformat=require(_0x88cc('0x1'));var rimraf=require(_0x88cc('0x2'));var zipdir=require(_0x88cc('0x3'));var jsonpatch=require(_0x88cc('0x4'));var rp=require(_0x88cc('0x5'));var moment=require(_0x88cc('0x6'));var BPromise=require(_0x88cc('0x7'));var Mustache=require(_0x88cc('0x8'));var util=require(_0x88cc('0x9'));var path=require(_0x88cc('0xa'));var sox=require(_0x88cc('0xb'));var csv=require(_0x88cc('0xc'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0x88cc('0xd'));var crypto=require(_0x88cc('0xe'));var jsforce=require(_0x88cc('0xf'));var deskjs=require(_0x88cc('0x10'));var toCsv=require('to-csv');var querystring=require(_0x88cc('0x11'));var Papa=require(_0x88cc('0x12'));var Redis=require('ioredis');var authService=require(_0x88cc('0x13'));var qs=require('../../components/parsers/qs');var as=require(_0x88cc('0x14'));var hardwareService=require(_0x88cc('0x15'));var logger=require(_0x88cc('0x16'))(_0x88cc('0x17'));var utils=require('../../config/utils');var config=require(_0x88cc('0x18'));var licenseUtil=require(_0x88cc('0x19'));var db=require(_0x88cc('0x1a'))['db'];config[_0x88cc('0x1b')]=_[_0x88cc('0x1c')](config[_0x88cc('0x1b')],{'host':_0x88cc('0x1d'),'port':0x18eb});var socket=require(_0x88cc('0x1e'))(new Redis(config['redis']));require(_0x88cc('0x1f'))[_0x88cc('0x20')](socket);var jayson=require(_0x88cc('0x21'));var client=jayson[_0x88cc('0x22')][_0x88cc('0x23')]({'port':0x232c});var client9002=jayson[_0x88cc('0x22')]['http']({'port':0x232a});function respondWithRpcPromise(_0x3305f3,_0x468101,_0x1a42ab,_0x2625db){return new BPromise(function(_0x13ff73,_0x4c24d9){var _0x30edea=_0x2625db||client;return _0x30edea[_0x88cc('0x24')](_0x3305f3,_0x1a42ab)[_0x88cc('0x25')](function(_0x3a6289){logger[_0x88cc('0x26')]('ChatMessage,\x20%s,\x20%s',_0x468101,_0x88cc('0x27'));logger[_0x88cc('0x28')]('ChatMessage,\x20%s,\x20%s,\x20%s',_0x468101,_0x88cc('0x27'),JSON['stringify'](_0x3a6289));if(_0x3a6289[_0x88cc('0x29')]){if(_0x3a6289[_0x88cc('0x29')]['code']===0x1f4){logger[_0x88cc('0x29')](_0x88cc('0x2a'),_0x468101,_0x3a6289[_0x88cc('0x29')][_0x88cc('0x2b')]);return _0x4c24d9(_0x3a6289[_0x88cc('0x29')][_0x88cc('0x2b')]);}logger['error'](_0x88cc('0x2a'),_0x468101,_0x3a6289[_0x88cc('0x29')][_0x88cc('0x2b')]);return _0x13ff73(_0x3a6289[_0x88cc('0x29')][_0x88cc('0x2b')]);}else{logger[_0x88cc('0x26')](_0x88cc('0x2a'),_0x468101,_0x88cc('0x27'));_0x13ff73(_0x3a6289[_0x88cc('0x2c')][_0x88cc('0x2b')]);}})[_0x88cc('0x2d')](function(_0x35c695){logger[_0x88cc('0x29')]('ChatMessage,\x20%s,\x20%s',_0x468101,_0x35c695);_0x4c24d9(_0x35c695);});});}function respondWithStatusCode(_0x155e43,_0x337bab){_0x337bab=_0x337bab||0xcc;return function(_0x44ae48){if(_0x44ae48){return _0x155e43[_0x88cc('0x2e')](_0x337bab);}return _0x155e43[_0x88cc('0x2f')](_0x337bab)[_0x88cc('0x30')]();};}function respondWithResult(_0x2962b8,_0xdced80){_0xdced80=_0xdced80||0xc8;return function(_0x55b1f2){if(_0x55b1f2){return _0x2962b8['status'](_0xdced80)[_0x88cc('0x31')](_0x55b1f2);}};}function respondWithFilteredResult(_0x45f1c6,_0x1c1d57){return function(_0x5b77ae){if(_0x5b77ae){var _0x570ea0=_0x5b77ae[_0x88cc('0x32')],_0x18ced1=_0x1c1d57[_0x88cc('0x33')],_0x2cc552=_0x1c1d57[_0x88cc('0x33')]+_0x1c1d57['limit'],_0x5511b9;if(_0x2cc552>=_0x570ea0){_0x2cc552=_0x570ea0;_0x5511b9=0xc8;}else{_0x5511b9=0xce;}_0x45f1c6[_0x88cc('0x2f')](_0x5511b9);return _0x45f1c6[_0x88cc('0x34')](_0x88cc('0x35'),_0x18ced1+'-'+_0x2cc552+'/'+_0x570ea0)['json'](_0x5b77ae);}return null;};}function patchUpdates(_0x2a9de4){return function(_0x1ffc13){try{jsonpatch[_0x88cc('0x36')](_0x1ffc13,_0x2a9de4,!![]);}catch(_0x1c359d){return BPromise[_0x88cc('0x37')](_0x1c359d);}return _0x1ffc13[_0x88cc('0x38')]();};}function saveUpdates(_0x5628d9,_0x216cac){return function(_0x395525){if(_0x395525){return _0x395525[_0x88cc('0x39')](_0x5628d9)[_0x88cc('0x25')](function(_0x240108){return _0x240108;});}return null;};}function removeEntity(_0xd80e8e,_0x1ff6ac){return function(_0x579a1f){if(_0x579a1f){return _0x579a1f['destroy']()[_0x88cc('0x25')](function(){_0xd80e8e[_0x88cc('0x2f')](0xcc)[_0x88cc('0x30')]();});}};}function handleEntityNotFound(_0x129af1,_0xa40547){return function(_0x5eea4a){if(!_0x5eea4a){_0x129af1[_0x88cc('0x2e')](0x194);}return _0x5eea4a;};}function handleError(_0x1656d6,_0x4418f8){_0x4418f8=_0x4418f8||0x1f4;return function(_0x3baf9f){logger[_0x88cc('0x29')](_0x3baf9f[_0x88cc('0x3a')]);if(_0x3baf9f[_0x88cc('0x3b')]){delete _0x3baf9f[_0x88cc('0x3b')];}_0x1656d6[_0x88cc('0x2f')](_0x4418f8)[_0x88cc('0x3c')](_0x3baf9f);};}exports[_0x88cc('0x3d')]=function(_0x36dc7e,_0x526193){var _0x199cde={},_0x348873={},_0x52e231={'count':0x0,'rows':[]};var _0x30bdd2=_['map'](db['ChatMessage']['rawAttributes'],function(_0x2beb74){return{'name':_0x2beb74['fieldName'],'type':_0x2beb74[_0x88cc('0x3e')][_0x88cc('0x3f')]};});_0x348873['model']=_[_0x88cc('0x40')](_0x30bdd2,'name');_0x348873[_0x88cc('0x41')]=_['keys'](_0x36dc7e[_0x88cc('0x41')]);_0x348873['filters']=_[_0x88cc('0x42')](_0x348873[_0x88cc('0x43')],_0x348873[_0x88cc('0x41')]);_0x199cde[_0x88cc('0x44')]=_['intersection'](_0x348873[_0x88cc('0x43')],qs['fields'](_0x36dc7e[_0x88cc('0x41')][_0x88cc('0x45')]));_0x199cde[_0x88cc('0x44')]=_0x199cde[_0x88cc('0x44')][_0x88cc('0x46')]?_0x199cde[_0x88cc('0x44')]:_0x348873[_0x88cc('0x43')];if(!_0x36dc7e[_0x88cc('0x41')][_0x88cc('0x47')]('nolimit')){_0x199cde[_0x88cc('0x48')]=qs[_0x88cc('0x48')](_0x36dc7e[_0x88cc('0x41')]['limit']);_0x199cde[_0x88cc('0x33')]=qs[_0x88cc('0x33')](_0x36dc7e[_0x88cc('0x41')]['offset']);}_0x199cde[_0x88cc('0x49')]=qs[_0x88cc('0x4a')](_0x36dc7e[_0x88cc('0x41')][_0x88cc('0x4a')]);_0x199cde[_0x88cc('0x4b')]=qs['filters'](_[_0x88cc('0x4c')](_0x36dc7e[_0x88cc('0x41')],_0x348873[_0x88cc('0x4d')]),_0x30bdd2);if(_0x36dc7e[_0x88cc('0x41')][_0x88cc('0x4e')]){_0x199cde['where']=_[_0x88cc('0x4f')](_0x199cde['where'],{'$or':_['map'](_0x30bdd2,function(_0x2e6cad){if(_0x2e6cad[_0x88cc('0x3e')]!=='VIRTUAL'){var _0x492eb8={};_0x492eb8[_0x2e6cad[_0x88cc('0x3b')]]={'$like':'%'+_0x36dc7e[_0x88cc('0x41')][_0x88cc('0x4e')]+'%'};return _0x492eb8;}})});}_0x199cde=_[_0x88cc('0x4f')]({},_0x199cde,_0x36dc7e['options']);var _0x1c8a92={'where':_0x199cde[_0x88cc('0x4b')]};return db[_0x88cc('0x50')][_0x88cc('0x32')](_0x1c8a92)[_0x88cc('0x25')](function(_0x39f6ce){_0x52e231[_0x88cc('0x32')]=_0x39f6ce;if(_0x36dc7e[_0x88cc('0x41')][_0x88cc('0x51')]){_0x199cde[_0x88cc('0x52')]=[{'all':!![]}];}return db[_0x88cc('0x50')]['findAll'](_0x199cde);})[_0x88cc('0x25')](function(_0x421571){_0x52e231[_0x88cc('0x53')]=_0x421571;return _0x52e231;})['then'](respondWithFilteredResult(_0x526193,_0x199cde))[_0x88cc('0x2d')](handleError(_0x526193,null));};exports[_0x88cc('0x54')]=function(_0x4b36f7,_0x38b30d){var _0x1a9b3a={'raw':!![],'where':{'id':_0x4b36f7[_0x88cc('0x55')]['id']}},_0x370260={};_0x370260['model']=_[_0x88cc('0x56')](db[_0x88cc('0x50')]['rawAttributes']);_0x370260[_0x88cc('0x41')]=_[_0x88cc('0x56')](_0x4b36f7[_0x88cc('0x41')]);_0x370260[_0x88cc('0x4d')]=_[_0x88cc('0x42')](_0x370260[_0x88cc('0x43')],_0x370260[_0x88cc('0x41')]);_0x1a9b3a[_0x88cc('0x44')]=_[_0x88cc('0x42')](_0x370260[_0x88cc('0x43')],qs[_0x88cc('0x45')](_0x4b36f7[_0x88cc('0x41')][_0x88cc('0x45')]));_0x1a9b3a[_0x88cc('0x44')]=_0x1a9b3a[_0x88cc('0x44')][_0x88cc('0x46')]?_0x1a9b3a[_0x88cc('0x44')]:_0x370260['model'];if(_0x4b36f7[_0x88cc('0x41')][_0x88cc('0x51')]){_0x1a9b3a['include']=[{'all':!![]}];}_0x1a9b3a=_['merge']({},_0x1a9b3a,_0x4b36f7[_0x88cc('0x57')]);return db[_0x88cc('0x50')][_0x88cc('0x58')](_0x1a9b3a)['then'](handleEntityNotFound(_0x38b30d,null))['then'](respondWithResult(_0x38b30d,null))[_0x88cc('0x2d')](handleError(_0x38b30d,null));};exports[_0x88cc('0x59')]=function(_0x36547c,_0x27c61f){return db[_0x88cc('0x50')][_0x88cc('0x59')](_0x36547c['body'],{})[_0x88cc('0x25')](respondWithResult(_0x27c61f,0xc9))[_0x88cc('0x2d')](handleError(_0x27c61f,null));};exports[_0x88cc('0x39')]=function(_0x285141,_0x18b72d){if(_0x285141[_0x88cc('0x5a')]['id']){delete _0x285141[_0x88cc('0x5a')]['id'];}return db[_0x88cc('0x50')]['find']({'where':{'id':_0x285141[_0x88cc('0x55')]['id']}})[_0x88cc('0x25')](handleEntityNotFound(_0x18b72d,null))['then'](saveUpdates(_0x285141[_0x88cc('0x5a')],null))[_0x88cc('0x25')](respondWithResult(_0x18b72d,null))[_0x88cc('0x2d')](handleError(_0x18b72d,null));};exports[_0x88cc('0x5b')]=function(_0x228123,_0x44b658){return db['ChatMessage']['find']({'where':{'id':_0x228123[_0x88cc('0x55')]['id']}})['then'](handleEntityNotFound(_0x44b658,null))[_0x88cc('0x25')](removeEntity(_0x44b658,null))['catch'](handleError(_0x44b658,null));};exports[_0x88cc('0x5c')]=function(_0x251bfb,_0x1933e4){return db[_0x88cc('0x50')][_0x88cc('0x5c')]()[_0x88cc('0x25')](respondWithResult(_0x1933e4,null))[_0x88cc('0x2d')](handleError(_0x1933e4,null));};var interaction_log=require(_0x88cc('0x16'))('chat-interactions');exports['accept']=function(_0x345a16,_0x12c704,_0x17f5ec){var _0x5aca5e={'agent':{},'channel':_0x88cc('0x5d')};if(_0x345a16[_0x88cc('0x5a')]['id']){delete _0x345a16[_0x88cc('0x5a')]['id'];}_0x345a16['body'][_0x88cc('0x5e')]=!![];_0x345a16[_0x88cc('0x5a')][_0x88cc('0x5f')]=moment()['format'](_0x88cc('0x60'));_0x345a16[_0x88cc('0x5a')][_0x88cc('0x61')]=_0x345a16[_0x88cc('0x5a')][_0x88cc('0x61')]||_0x345a16[_0x88cc('0x62')]['id'];_0x5aca5e[_0x88cc('0x63')]['id']=_0x345a16[_0x88cc('0x5a')]['UserId'];return db[_0x88cc('0x50')]['find']({'where':{'id':_0x345a16[_0x88cc('0x55')]['id'],'UserId':null},'include':[{'model':db[_0x88cc('0x64')],'as':_0x88cc('0x65')}]})[_0x88cc('0x25')](handleEntityNotFound(_0x12c704,null))[_0x88cc('0x25')](saveUpdates(_0x345a16[_0x88cc('0x5a')],null))[_0x88cc('0x25')](function(_0x5a781d){if(_0x5a781d){_0x5aca5e[_0x88cc('0x2b')]=_0x5a781d['get']({'plain':!![]});return db[_0x88cc('0x66')][_0x88cc('0x58')]({'where':{'id':_0x5a781d[_0x88cc('0x67')]}});}return null;})['then'](handleEntityNotFound(_0x12c704,null))[_0x88cc('0x25')](function(_0x4d0876){if(_0x4d0876){return _0x4d0876[_0x88cc('0x39')]({'UserId':_0x345a16[_0x88cc('0x5a')]['UserId'],'read1stAt':_['isNil'](_0x4d0876[_0x88cc('0x68')])?moment()[_0x88cc('0x69')](_0x88cc('0x60')):undefined});}return null;})[_0x88cc('0x25')](function(_0x33f3f3){if(_0x33f3f3){_0x5aca5e[_0x88cc('0x6a')]=_0x33f3f3[_0x88cc('0x6b')]({'plain':!![]});interaction_log[_0x88cc('0x26')]('[CHATMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x345a16[_0x88cc('0x62')]['id'],_0x345a16[_0x88cc('0x62')][_0x88cc('0x3b')],_0x345a16[_0x88cc('0x62')][_0x88cc('0x6c')],_0x5aca5e['interaction']['id'],_0x345a16[_0x88cc('0x5a')]?JSON[_0x88cc('0x6d')](_0x345a16[_0x88cc('0x5a')]):_0x88cc('0x6e'));return respondWithRpcPromise(_0x88cc('0x6f'),_0x88cc('0x70'),_0x5aca5e);}return null;})[_0x88cc('0x25')](function(_0x542739){if(_0x542739){if(_0x345a16[_0x88cc('0x5a')][_0x88cc('0x71')]){_0x5aca5e[_0x88cc('0x2b')][_0x88cc('0x72')]=util[_0x88cc('0x69')](_0x88cc('0x73'),_0x345a16[_0x88cc('0x62')][_0x88cc('0x3b')]);_0x5aca5e['message'][_0x88cc('0x74')]=_0x5aca5e[_0x88cc('0x74')];_0x5aca5e[_0x88cc('0x2b')][_0x88cc('0x75')]='accept';return respondWithRpcPromise(_0x88cc('0x76'),'EventManager',{'event':_0x88cc('0x77'),'message':_[_0x88cc('0x4f')](_0x5aca5e[_0x88cc('0x2b')],JSON[_0x88cc('0x78')](_0x5aca5e[_0x88cc('0x6a')][_0x88cc('0x79')]))},client9002)[_0x88cc('0x25')](function(){return _0x5aca5e;});}return _0x5aca5e;}return null;})[_0x88cc('0x25')](respondWithResult(_0x12c704,null))['catch'](handleError(_0x12c704,null));};var interaction_log=require('../../config/logger')('chat-interactions');exports[_0x88cc('0x37')]=function(_0x235c0a,_0x5a4511,_0x19d714){var _0x21408d={'agent':{},'channel':_0x88cc('0x5d')};if(_0x235c0a[_0x88cc('0x5a')]['id']){delete _0x235c0a[_0x88cc('0x5a')]['id'];}_0x235c0a['body'][_0x88cc('0x61')]=_0x235c0a['body'][_0x88cc('0x61')]||_0x235c0a[_0x88cc('0x62')]['id'];_0x21408d['agent']['id']=_0x235c0a[_0x88cc('0x5a')][_0x88cc('0x61')];return db[_0x88cc('0x50')][_0x88cc('0x58')]({'where':{'id':_0x235c0a[_0x88cc('0x55')]['id'],'UserId':null}})[_0x88cc('0x25')](handleEntityNotFound(_0x5a4511,null))[_0x88cc('0x25')](function(_0x1dc30d){if(_0x1dc30d){_0x21408d[_0x88cc('0x2b')]=_0x1dc30d[_0x88cc('0x6b')]({'plain':!![]});return db['ChatInteraction']['find']({'where':{'id':_0x1dc30d[_0x88cc('0x67')]}});}return null;})[_0x88cc('0x25')](handleEntityNotFound(_0x5a4511,null))[_0x88cc('0x25')](function(_0xc4b61d){if(_0xc4b61d){_0x21408d[_0x88cc('0x6a')]=_0xc4b61d[_0x88cc('0x6b')]({'plain':!![]});interaction_log[_0x88cc('0x26')](_0x88cc('0x7a'),_0x235c0a[_0x88cc('0x62')]['id'],_0x235c0a[_0x88cc('0x62')][_0x88cc('0x3b')],_0x235c0a['user'][_0x88cc('0x6c')],_0x21408d['interaction']['id'],_0x235c0a['body']?JSON[_0x88cc('0x6d')](_0x235c0a[_0x88cc('0x5a')]):'null');return respondWithRpcPromise('RejectMessage',_0x88cc('0x7b'),_0x21408d);}return null;})['then'](function(_0x28d7d6){if(_0x28d7d6){_0x28d7d6[_0x88cc('0x2b')]['interface']=util[_0x88cc('0x69')]('SIP/%s',_0x235c0a[_0x88cc('0x62')]['name']);_0x28d7d6[_0x88cc('0x2b')][_0x88cc('0x74')]=_0x21408d[_0x88cc('0x74')];_0x28d7d6['message'][_0x88cc('0x75')]=_0x88cc('0x37');respondWithRpcPromise(_0x88cc('0x76'),_0x88cc('0x76'),{'event':_0x88cc('0x7c'),'message':_0x28d7d6[_0x88cc('0x2b')]},client9002);return _0x21408d;}return null;})['then'](respondWithResult(_0x5a4511,null))[_0x88cc('0x2d')](handleError(_0x5a4511,null));};
\ No newline at end of file