Built motion from commit (unavailable).|2.5.21
[motion2.git] / server / api / chatMessage / chatMessage.controller.js
index 3110d24..932d7f5 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xd53f=['order','sort','where','pick','filter','merge','type','VIRTUAL','include','findAll','rows','rawAttributes','includeAll','options','find','create','body','params','describe','chat','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','CmContact','ChatInteraction','ChatInteractionId','isNil','read1stAt','[CHATMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','user','role','interaction','null','AcceptMessage','acceptMessage','manual','interface','SIP/%s','event','accept','EventManager','acceptmessage','parse','formData','reject','agent','get','[CHATMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','channel','rejectmessage','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','ejs','squel','jsforce','to-csv','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','defaults','redis','localhost','socket.io-emitter','./chatMessage.socket','register','jayson/promise','client','http','then','ChatMessage,\x20%s,\x20%s','debug','ChatMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','request\x20sent','result','catch','sendStatus','end','status','json','count','offset','limit','set','Content-Range','apply','save','update','destroy','stack','name','send','index','map','ChatMessage','fieldName','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit'];(function(_0x1f745a,_0x1d9356){var _0x57d65f=function(_0x3e9dcc){while(--_0x3e9dcc){_0x1f745a['push'](_0x1f745a['shift']());}};_0x57d65f(++_0x1d9356);}(_0xd53f,0x131));var _0xfd53=function(_0x3b3d30,_0x169f99){_0x3b3d30=_0x3b3d30-0x0;var _0x40d27a=_0xd53f[_0x3b3d30];return _0x40d27a;};'use strict';var pdf=require(_0xfd53('0x0'));var emlformat=require(_0xfd53('0x1'));var rimraf=require(_0xfd53('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0xfd53('0x3'));var rp=require(_0xfd53('0x4'));var moment=require('moment');var BPromise=require(_0xfd53('0x5'));var Mustache=require(_0xfd53('0x6'));var util=require(_0xfd53('0x7'));var path=require(_0xfd53('0x8'));var sox=require(_0xfd53('0x9'));var csv=require('to-csv');var ejs=require(_0xfd53('0xa'));var fs=require('fs');var _=require('lodash');var squel=require(_0xfd53('0xb'));var crypto=require('crypto');var jsforce=require(_0xfd53('0xc'));var deskjs=require('desk.js');var toCsv=require(_0xfd53('0xd'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xfd53('0xe'));var authService=require('../../components/auth/service');var qs=require(_0xfd53('0xf'));var as=require(_0xfd53('0x10'));var hardwareService=require(_0xfd53('0x11'));var logger=require(_0xfd53('0x12'))('api');var utils=require(_0xfd53('0x13'));var config=require(_0xfd53('0x14'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];config['redis']=_[_0xfd53('0x15')](config[_0xfd53('0x16')],{'host':_0xfd53('0x17'),'port':0x18eb});var socket=require(_0xfd53('0x18'))(new Redis(config[_0xfd53('0x16')]));require(_0xfd53('0x19'))[_0xfd53('0x1a')](socket);var jayson=require(_0xfd53('0x1b'));var client=jayson[_0xfd53('0x1c')][_0xfd53('0x1d')]({'port':0x232c});var client9002=jayson[_0xfd53('0x1c')][_0xfd53('0x1d')]({'port':0x232a});function respondWithRpcPromise(_0x481026,_0x1571a9,_0x2d9e67,_0x2f11a0){return new BPromise(function(_0x4dfde6,_0x3725ba){var _0x5dc190=_0x2f11a0||client;return _0x5dc190['request'](_0x481026,_0x2d9e67)[_0xfd53('0x1e')](function(_0xa99c29){logger['info'](_0xfd53('0x1f'),_0x1571a9,'request\x20sent');logger[_0xfd53('0x20')](_0xfd53('0x21'),_0x1571a9,'request\x20sent',JSON[_0xfd53('0x22')](_0xa99c29));if(_0xa99c29[_0xfd53('0x23')]){if(_0xa99c29['error'][_0xfd53('0x24')]===0x1f4){logger['error'](_0xfd53('0x1f'),_0x1571a9,_0xa99c29[_0xfd53('0x23')][_0xfd53('0x25')]);return _0x3725ba(_0xa99c29[_0xfd53('0x23')][_0xfd53('0x25')]);}logger[_0xfd53('0x23')](_0xfd53('0x1f'),_0x1571a9,_0xa99c29[_0xfd53('0x23')]['message']);return _0x4dfde6(_0xa99c29[_0xfd53('0x23')][_0xfd53('0x25')]);}else{logger[_0xfd53('0x26')](_0xfd53('0x1f'),_0x1571a9,_0xfd53('0x27'));_0x4dfde6(_0xa99c29[_0xfd53('0x28')][_0xfd53('0x25')]);}})[_0xfd53('0x29')](function(_0x427019){logger[_0xfd53('0x23')]('ChatMessage,\x20%s,\x20%s',_0x1571a9,_0x427019);_0x3725ba(_0x427019);});});}function respondWithStatusCode(_0x32ac71,_0x16d4b5){_0x16d4b5=_0x16d4b5||0xcc;return function(_0x342b9c){if(_0x342b9c){return _0x32ac71[_0xfd53('0x2a')](_0x16d4b5);}return _0x32ac71['status'](_0x16d4b5)[_0xfd53('0x2b')]();};}function respondWithResult(_0xce6194,_0x1373f4){_0x1373f4=_0x1373f4||0xc8;return function(_0x336b3a){if(_0x336b3a){return _0xce6194[_0xfd53('0x2c')](_0x1373f4)[_0xfd53('0x2d')](_0x336b3a);}};}function respondWithFilteredResult(_0x29f1ac,_0x9b3ec8){return function(_0x224bc3){if(_0x224bc3){var _0x445e41=_0x224bc3[_0xfd53('0x2e')],_0x1266de=_0x9b3ec8[_0xfd53('0x2f')],_0x2d30f4=_0x9b3ec8[_0xfd53('0x2f')]+_0x9b3ec8[_0xfd53('0x30')],_0x29fc52;if(_0x2d30f4>=_0x445e41){_0x2d30f4=_0x445e41;_0x29fc52=0xc8;}else{_0x29fc52=0xce;}_0x29f1ac[_0xfd53('0x2c')](_0x29fc52);return _0x29f1ac[_0xfd53('0x31')](_0xfd53('0x32'),_0x1266de+'-'+_0x2d30f4+'/'+_0x445e41)[_0xfd53('0x2d')](_0x224bc3);}return null;};}function patchUpdates(_0x1ceefa){return function(_0x31a948){try{jsonpatch[_0xfd53('0x33')](_0x31a948,_0x1ceefa,!![]);}catch(_0x4b9845){return BPromise['reject'](_0x4b9845);}return _0x31a948[_0xfd53('0x34')]();};}function saveUpdates(_0x1c0b2f,_0x3273b0){return function(_0x2c7253){if(_0x2c7253){return _0x2c7253[_0xfd53('0x35')](_0x1c0b2f)[_0xfd53('0x1e')](function(_0x29021b){return _0x29021b;});}return null;};}function removeEntity(_0x51ec3a,_0x4c5bf5){return function(_0x9f618b){if(_0x9f618b){return _0x9f618b[_0xfd53('0x36')]()['then'](function(){_0x51ec3a[_0xfd53('0x2c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x1045a9,_0x4a31a5){return function(_0x2a0cc7){if(!_0x2a0cc7){_0x1045a9[_0xfd53('0x2a')](0x194);}return _0x2a0cc7;};}function handleError(_0x5a76a3,_0x264d02){_0x264d02=_0x264d02||0x1f4;return function(_0x5d5684){logger[_0xfd53('0x23')](_0x5d5684[_0xfd53('0x37')]);if(_0x5d5684['name']){delete _0x5d5684[_0xfd53('0x38')];}_0x5a76a3[_0xfd53('0x2c')](_0x264d02)[_0xfd53('0x39')](_0x5d5684);};}exports[_0xfd53('0x3a')]=function(_0x4bfb9e,_0x245121){var _0x458fb8={},_0x3d2c00={},_0x3cec96={'count':0x0,'rows':[]};var _0x626d2c=_[_0xfd53('0x3b')](db[_0xfd53('0x3c')]['rawAttributes'],function(_0x1ad0cd){return{'name':_0x1ad0cd[_0xfd53('0x3d')],'type':_0x1ad0cd['type'][_0xfd53('0x3e')]};});_0x3d2c00[_0xfd53('0x3f')]=_[_0xfd53('0x3b')](_0x626d2c,_0xfd53('0x38'));_0x3d2c00[_0xfd53('0x40')]=_[_0xfd53('0x41')](_0x4bfb9e[_0xfd53('0x40')]);_0x3d2c00[_0xfd53('0x42')]=_[_0xfd53('0x43')](_0x3d2c00[_0xfd53('0x3f')],_0x3d2c00[_0xfd53('0x40')]);_0x458fb8[_0xfd53('0x44')]=_[_0xfd53('0x43')](_0x3d2c00[_0xfd53('0x3f')],qs[_0xfd53('0x45')](_0x4bfb9e[_0xfd53('0x40')][_0xfd53('0x45')]));_0x458fb8[_0xfd53('0x44')]=_0x458fb8[_0xfd53('0x44')][_0xfd53('0x46')]?_0x458fb8[_0xfd53('0x44')]:_0x3d2c00[_0xfd53('0x3f')];if(!_0x4bfb9e['query'][_0xfd53('0x47')](_0xfd53('0x48'))){_0x458fb8[_0xfd53('0x30')]=qs[_0xfd53('0x30')](_0x4bfb9e['query']['limit']);_0x458fb8['offset']=qs['offset'](_0x4bfb9e[_0xfd53('0x40')][_0xfd53('0x2f')]);}_0x458fb8[_0xfd53('0x49')]=qs[_0xfd53('0x4a')](_0x4bfb9e['query'][_0xfd53('0x4a')]);_0x458fb8[_0xfd53('0x4b')]=qs[_0xfd53('0x42')](_[_0xfd53('0x4c')](_0x4bfb9e['query'],_0x3d2c00[_0xfd53('0x42')]),_0x626d2c);if(_0x4bfb9e[_0xfd53('0x40')][_0xfd53('0x4d')]){_0x458fb8[_0xfd53('0x4b')]=_[_0xfd53('0x4e')](_0x458fb8[_0xfd53('0x4b')],{'$or':_[_0xfd53('0x3b')](_0x626d2c,function(_0x3e8096){if(_0x3e8096[_0xfd53('0x4f')]!==_0xfd53('0x50')){var _0x4cfc23={};_0x4cfc23[_0x3e8096[_0xfd53('0x38')]]={'$like':'%'+_0x4bfb9e[_0xfd53('0x40')][_0xfd53('0x4d')]+'%'};return _0x4cfc23;}})});}_0x458fb8=_[_0xfd53('0x4e')]({},_0x458fb8,_0x4bfb9e['options']);var _0x243639={'where':_0x458fb8[_0xfd53('0x4b')]};return db[_0xfd53('0x3c')]['count'](_0x243639)[_0xfd53('0x1e')](function(_0x557191){_0x3cec96[_0xfd53('0x2e')]=_0x557191;if(_0x4bfb9e[_0xfd53('0x40')]['includeAll']){_0x458fb8[_0xfd53('0x51')]=[{'all':!![]}];}return db[_0xfd53('0x3c')][_0xfd53('0x52')](_0x458fb8);})['then'](function(_0x3c40a6){_0x3cec96[_0xfd53('0x53')]=_0x3c40a6;return _0x3cec96;})[_0xfd53('0x1e')](respondWithFilteredResult(_0x245121,_0x458fb8))[_0xfd53('0x29')](handleError(_0x245121,null));};exports['show']=function(_0x20ffb6,_0x56e8aa){var _0x1a1dd0={'raw':!![],'where':{'id':_0x20ffb6['params']['id']}},_0x2c4a={};_0x2c4a['model']=_[_0xfd53('0x41')](db['ChatMessage'][_0xfd53('0x54')]);_0x2c4a[_0xfd53('0x40')]=_[_0xfd53('0x41')](_0x20ffb6[_0xfd53('0x40')]);_0x2c4a['filters']=_['intersection'](_0x2c4a['model'],_0x2c4a[_0xfd53('0x40')]);_0x1a1dd0[_0xfd53('0x44')]=_['intersection'](_0x2c4a[_0xfd53('0x3f')],qs[_0xfd53('0x45')](_0x20ffb6['query'][_0xfd53('0x45')]));_0x1a1dd0[_0xfd53('0x44')]=_0x1a1dd0[_0xfd53('0x44')]['length']?_0x1a1dd0[_0xfd53('0x44')]:_0x2c4a['model'];if(_0x20ffb6[_0xfd53('0x40')][_0xfd53('0x55')]){_0x1a1dd0[_0xfd53('0x51')]=[{'all':!![]}];}_0x1a1dd0=_[_0xfd53('0x4e')]({},_0x1a1dd0,_0x20ffb6[_0xfd53('0x56')]);return db[_0xfd53('0x3c')][_0xfd53('0x57')](_0x1a1dd0)['then'](handleEntityNotFound(_0x56e8aa,null))[_0xfd53('0x1e')](respondWithResult(_0x56e8aa,null))[_0xfd53('0x29')](handleError(_0x56e8aa,null));};exports[_0xfd53('0x58')]=function(_0x5018c6,_0x58bbe1){return db['ChatMessage'][_0xfd53('0x58')](_0x5018c6[_0xfd53('0x59')],{})[_0xfd53('0x1e')](respondWithResult(_0x58bbe1,0xc9))[_0xfd53('0x29')](handleError(_0x58bbe1,null));};exports[_0xfd53('0x35')]=function(_0xd9c26f,_0xd8207a){if(_0xd9c26f[_0xfd53('0x59')]['id']){delete _0xd9c26f[_0xfd53('0x59')]['id'];}return db[_0xfd53('0x3c')][_0xfd53('0x57')]({'where':{'id':_0xd9c26f['params']['id']}})[_0xfd53('0x1e')](handleEntityNotFound(_0xd8207a,null))[_0xfd53('0x1e')](saveUpdates(_0xd9c26f[_0xfd53('0x59')],null))[_0xfd53('0x1e')](respondWithResult(_0xd8207a,null))[_0xfd53('0x29')](handleError(_0xd8207a,null));};exports[_0xfd53('0x36')]=function(_0x170dda,_0x4d5703){return db[_0xfd53('0x3c')][_0xfd53('0x57')]({'where':{'id':_0x170dda[_0xfd53('0x5a')]['id']}})['then'](handleEntityNotFound(_0x4d5703,null))[_0xfd53('0x1e')](removeEntity(_0x4d5703,null))[_0xfd53('0x29')](handleError(_0x4d5703,null));};exports[_0xfd53('0x5b')]=function(_0x286963,_0x11b8ed){return db[_0xfd53('0x3c')][_0xfd53('0x5b')]()['then'](respondWithResult(_0x11b8ed,null))[_0xfd53('0x29')](handleError(_0x11b8ed,null));};var interaction_log=require(_0xfd53('0x12'))('chat-interactions');exports['accept']=function(_0x404b00,_0xf059cc,_0x4715b0){var _0xded6f4={'agent':{},'channel':_0xfd53('0x5c')};if(_0x404b00[_0xfd53('0x59')]['id']){delete _0x404b00[_0xfd53('0x59')]['id'];}_0x404b00[_0xfd53('0x59')][_0xfd53('0x5d')]=!![];_0x404b00[_0xfd53('0x59')][_0xfd53('0x5e')]=moment()[_0xfd53('0x5f')](_0xfd53('0x60'));_0x404b00[_0xfd53('0x59')][_0xfd53('0x61')]=_0x404b00['body'][_0xfd53('0x61')]||_0x404b00['user']['id'];_0xded6f4['agent']['id']=_0x404b00['body'][_0xfd53('0x61')];return db['ChatMessage'][_0xfd53('0x57')]({'where':{'id':_0x404b00[_0xfd53('0x5a')]['id'],'UserId':null},'include':[{'model':db[_0xfd53('0x62')],'as':'Contact'}]})[_0xfd53('0x1e')](handleEntityNotFound(_0xf059cc,null))[_0xfd53('0x1e')](saveUpdates(_0x404b00[_0xfd53('0x59')],null))[_0xfd53('0x1e')](function(_0x466108){if(_0x466108){_0xded6f4['message']=_0x466108['get']({'plain':!![]});return db[_0xfd53('0x63')][_0xfd53('0x57')]({'where':{'id':_0x466108[_0xfd53('0x64')]}});}return null;})[_0xfd53('0x1e')](handleEntityNotFound(_0xf059cc,null))[_0xfd53('0x1e')](function(_0x34b0b0){if(_0x34b0b0){return _0x34b0b0[_0xfd53('0x35')]({'UserId':_0x404b00[_0xfd53('0x59')]['UserId'],'read1stAt':_[_0xfd53('0x65')](_0x34b0b0[_0xfd53('0x66')])?moment()['format'](_0xfd53('0x60')):undefined});}return null;})['then'](function(_0x485c14){if(_0x485c14){_0xded6f4['interaction']=_0x485c14['get']({'plain':!![]});interaction_log[_0xfd53('0x26')](_0xfd53('0x67'),_0x404b00['user']['id'],_0x404b00[_0xfd53('0x68')][_0xfd53('0x38')],_0x404b00[_0xfd53('0x68')][_0xfd53('0x69')],_0xded6f4[_0xfd53('0x6a')]['id'],_0x404b00['body']?JSON[_0xfd53('0x22')](_0x404b00['body']):_0xfd53('0x6b'));return respondWithRpcPromise(_0xfd53('0x6c'),_0xfd53('0x6d'),_0xded6f4);}return null;})['then'](function(_0x490644){if(_0x490644){if(_0x404b00[_0xfd53('0x59')][_0xfd53('0x6e')]){_0xded6f4[_0xfd53('0x25')][_0xfd53('0x6f')]=util[_0xfd53('0x5f')](_0xfd53('0x70'),_0x404b00['user'][_0xfd53('0x38')]);_0xded6f4[_0xfd53('0x25')]['channel']=_0xded6f4['channel'];_0xded6f4[_0xfd53('0x25')][_0xfd53('0x71')]=_0xfd53('0x72');return respondWithRpcPromise('EventManager',_0xfd53('0x73'),{'event':_0xfd53('0x74'),'message':_[_0xfd53('0x4e')](_0xded6f4[_0xfd53('0x25')],JSON[_0xfd53('0x75')](_0xded6f4['interaction'][_0xfd53('0x76')]))},client9002)['then'](function(){return _0xded6f4;});}return _0xded6f4;}return null;})['then'](respondWithResult(_0xf059cc,null))[_0xfd53('0x29')](handleError(_0xf059cc,null));};var interaction_log=require(_0xfd53('0x12'))('chat-interactions');exports[_0xfd53('0x77')]=function(_0x5ba320,_0x384af1,_0x1ff65f){var _0x79ff7b={'agent':{},'channel':'chat'};if(_0x5ba320[_0xfd53('0x59')]['id']){delete _0x5ba320['body']['id'];}_0x5ba320[_0xfd53('0x59')][_0xfd53('0x61')]=_0x5ba320['body'][_0xfd53('0x61')]||_0x5ba320['user']['id'];_0x79ff7b[_0xfd53('0x78')]['id']=_0x5ba320['body']['UserId'];return db[_0xfd53('0x3c')]['find']({'where':{'id':_0x5ba320[_0xfd53('0x5a')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x384af1,null))[_0xfd53('0x1e')](function(_0x387f01){if(_0x387f01){_0x79ff7b[_0xfd53('0x25')]=_0x387f01[_0xfd53('0x79')]({'plain':!![]});return db['ChatInteraction'][_0xfd53('0x57')]({'where':{'id':_0x387f01['ChatInteractionId']}});}return null;})[_0xfd53('0x1e')](handleEntityNotFound(_0x384af1,null))[_0xfd53('0x1e')](function(_0x1ec6c6){if(_0x1ec6c6){_0x79ff7b['interaction']=_0x1ec6c6['get']({'plain':!![]});interaction_log['info'](_0xfd53('0x7a'),_0x5ba320[_0xfd53('0x68')]['id'],_0x5ba320['user']['name'],_0x5ba320['user'][_0xfd53('0x69')],_0x79ff7b[_0xfd53('0x6a')]['id'],_0x5ba320[_0xfd53('0x59')]?JSON[_0xfd53('0x22')](_0x5ba320[_0xfd53('0x59')]):_0xfd53('0x6b'));return respondWithRpcPromise(_0xfd53('0x7b'),'rejectMessage',_0x79ff7b);}return null;})[_0xfd53('0x1e')](function(_0x385bd2){if(_0x385bd2){_0x385bd2[_0xfd53('0x25')][_0xfd53('0x6f')]=util['format'](_0xfd53('0x70'),_0x5ba320[_0xfd53('0x68')][_0xfd53('0x38')]);_0x385bd2['message'][_0xfd53('0x7c')]=_0x79ff7b[_0xfd53('0x7c')];_0x385bd2[_0xfd53('0x25')][_0xfd53('0x71')]='reject';respondWithRpcPromise(_0xfd53('0x73'),'EventManager',{'event':_0xfd53('0x7d'),'message':_0x385bd2[_0xfd53('0x25')]},client9002);return _0x79ff7b;}return null;})[_0xfd53('0x1e')](respondWithResult(_0x384af1,null))[_0xfd53('0x29')](handleError(_0x384af1,null));};
\ No newline at end of file
+var _0x5f22=['catch','sendStatus','status','json','count','offset','limit','set','Content-Range','apply','reject','update','destroy','name','send','index','map','ChatMessage','rawAttributes','fieldName','key','model','keys','query','filters','intersection','attributes','fields','length','nolimit','order','sort','where','pick','filter','merge','type','VIRTUAL','options','includeAll','findAll','rows','show','params','include','find','create','body','describe','accept','chat','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','CmContact','get','ChatInteraction','ChatInteractionId','isNil','read1stAt','interaction','[CHATMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','AcceptMessage','interface','channel','event','EventManager','acceptmessage','parse','chat-interactions','RejectMessage','rejectMessage','SIP/%s','rejectmessage','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','path','to-csv','ejs','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','defaults','localhost','socket.io-emitter','./chatMessage.socket','register','jayson/promise','client','http','request','then','info','request\x20sent','debug','ChatMessage,\x20%s,\x20%s,\x20%s','stringify','error','ChatMessage,\x20%s,\x20%s','message'];(function(_0x587eeb,_0x437854){var _0x4791ec=function(_0x4f44e0){while(--_0x4f44e0){_0x587eeb['push'](_0x587eeb['shift']());}};_0x4791ec(++_0x437854);}(_0x5f22,0x144));var _0x25f2=function(_0x2df724,_0x411382){_0x2df724=_0x2df724-0x0;var _0x1b2504=_0x5f22[_0x2df724];return _0x1b2504;};'use strict';var pdf=require(_0x25f2('0x0'));var emlformat=require(_0x25f2('0x1'));var rimraf=require(_0x25f2('0x2'));var zipdir=require(_0x25f2('0x3'));var jsonpatch=require(_0x25f2('0x4'));var rp=require('request-promise');var moment=require(_0x25f2('0x5'));var BPromise=require(_0x25f2('0x6'));var Mustache=require('mustache');var util=require('util');var path=require(_0x25f2('0x7'));var sox=require('sox');var csv=require(_0x25f2('0x8'));var ejs=require(_0x25f2('0x9'));var fs=require('fs');var _=require('lodash');var squel=require(_0x25f2('0xa'));var crypto=require(_0x25f2('0xb'));var jsforce=require(_0x25f2('0xc'));var deskjs=require(_0x25f2('0xd'));var toCsv=require('to-csv');var querystring=require(_0x25f2('0xe'));var Papa=require(_0x25f2('0xf'));var Redis=require(_0x25f2('0x10'));var authService=require(_0x25f2('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x25f2('0x12'));var hardwareService=require(_0x25f2('0x13'));var logger=require(_0x25f2('0x14'))('api');var utils=require(_0x25f2('0x15'));var config=require(_0x25f2('0x16'));var licenseUtil=require(_0x25f2('0x17'));var db=require('../../mysqldb')['db'];config['redis']=_[_0x25f2('0x18')](config['redis'],{'host':_0x25f2('0x19'),'port':0x18eb});var socket=require(_0x25f2('0x1a'))(new Redis(config['redis']));require(_0x25f2('0x1b'))[_0x25f2('0x1c')](socket);var jayson=require(_0x25f2('0x1d'));var client=jayson[_0x25f2('0x1e')][_0x25f2('0x1f')]({'port':0x232c});var client9002=jayson[_0x25f2('0x1e')][_0x25f2('0x1f')]({'port':0x232a});function respondWithRpcPromise(_0x9329a6,_0x822fa8,_0x1e9d54,_0x3db9ab){return new BPromise(function(_0x5d97df,_0x3e8b61){var _0x4fd6bb=_0x3db9ab||client;return _0x4fd6bb[_0x25f2('0x20')](_0x9329a6,_0x1e9d54)[_0x25f2('0x21')](function(_0x421829){logger[_0x25f2('0x22')]('ChatMessage,\x20%s,\x20%s',_0x822fa8,_0x25f2('0x23'));logger[_0x25f2('0x24')](_0x25f2('0x25'),_0x822fa8,_0x25f2('0x23'),JSON[_0x25f2('0x26')](_0x421829));if(_0x421829[_0x25f2('0x27')]){if(_0x421829[_0x25f2('0x27')]['code']===0x1f4){logger[_0x25f2('0x27')](_0x25f2('0x28'),_0x822fa8,_0x421829[_0x25f2('0x27')]['message']);return _0x3e8b61(_0x421829[_0x25f2('0x27')][_0x25f2('0x29')]);}logger[_0x25f2('0x27')](_0x25f2('0x28'),_0x822fa8,_0x421829['error'][_0x25f2('0x29')]);return _0x5d97df(_0x421829[_0x25f2('0x27')][_0x25f2('0x29')]);}else{logger[_0x25f2('0x22')](_0x25f2('0x28'),_0x822fa8,_0x25f2('0x23'));_0x5d97df(_0x421829['result'][_0x25f2('0x29')]);}})[_0x25f2('0x2a')](function(_0x7bec3e){logger['error']('ChatMessage,\x20%s,\x20%s',_0x822fa8,_0x7bec3e);_0x3e8b61(_0x7bec3e);});});}function respondWithStatusCode(_0x23d5fe,_0x376cab){_0x376cab=_0x376cab||0xcc;return function(_0x4d7207){if(_0x4d7207){return _0x23d5fe[_0x25f2('0x2b')](_0x376cab);}return _0x23d5fe[_0x25f2('0x2c')](_0x376cab)['end']();};}function respondWithResult(_0x569495,_0x2751b6){_0x2751b6=_0x2751b6||0xc8;return function(_0x36b073){if(_0x36b073){return _0x569495[_0x25f2('0x2c')](_0x2751b6)[_0x25f2('0x2d')](_0x36b073);}};}function respondWithFilteredResult(_0x1886a8,_0x180cfa){return function(_0x47fe33){if(_0x47fe33){var _0x344b56=_0x47fe33[_0x25f2('0x2e')],_0x2f5e29=_0x180cfa[_0x25f2('0x2f')],_0x5c28a4=_0x180cfa['offset']+_0x180cfa[_0x25f2('0x30')],_0x1dc046;if(_0x5c28a4>=_0x344b56){_0x5c28a4=_0x344b56;_0x1dc046=0xc8;}else{_0x1dc046=0xce;}_0x1886a8[_0x25f2('0x2c')](_0x1dc046);return _0x1886a8[_0x25f2('0x31')](_0x25f2('0x32'),_0x2f5e29+'-'+_0x5c28a4+'/'+_0x344b56)[_0x25f2('0x2d')](_0x47fe33);}return null;};}function patchUpdates(_0x9173cf){return function(_0x58c816){try{jsonpatch[_0x25f2('0x33')](_0x58c816,_0x9173cf,!![]);}catch(_0x3028ac){return BPromise[_0x25f2('0x34')](_0x3028ac);}return _0x58c816['save']();};}function saveUpdates(_0xae3a27,_0x3d172a){return function(_0xca881b){if(_0xca881b){return _0xca881b[_0x25f2('0x35')](_0xae3a27)[_0x25f2('0x21')](function(_0x306002){return _0x306002;});}return null;};}function removeEntity(_0xffb468,_0x131f11){return function(_0x28a42b){if(_0x28a42b){return _0x28a42b[_0x25f2('0x36')]()[_0x25f2('0x21')](function(){_0xffb468['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x5b4465,_0x5688bc){return function(_0xa690c1){if(!_0xa690c1){_0x5b4465[_0x25f2('0x2b')](0x194);}return _0xa690c1;};}function handleError(_0x3a94c6,_0x5b8787){_0x5b8787=_0x5b8787||0x1f4;return function(_0x2d3673){logger['error'](_0x2d3673['stack']);if(_0x2d3673[_0x25f2('0x37')]){delete _0x2d3673['name'];}_0x3a94c6[_0x25f2('0x2c')](_0x5b8787)[_0x25f2('0x38')](_0x2d3673);};}exports[_0x25f2('0x39')]=function(_0x52650a,_0x14e1a6){var _0x13dc43={},_0x1ac24a={},_0x1e33d5={'count':0x0,'rows':[]};var _0x47139a=_[_0x25f2('0x3a')](db[_0x25f2('0x3b')][_0x25f2('0x3c')],function(_0x1f8156){return{'name':_0x1f8156[_0x25f2('0x3d')],'type':_0x1f8156['type'][_0x25f2('0x3e')]};});_0x1ac24a[_0x25f2('0x3f')]=_[_0x25f2('0x3a')](_0x47139a,_0x25f2('0x37'));_0x1ac24a['query']=_[_0x25f2('0x40')](_0x52650a[_0x25f2('0x41')]);_0x1ac24a[_0x25f2('0x42')]=_[_0x25f2('0x43')](_0x1ac24a[_0x25f2('0x3f')],_0x1ac24a[_0x25f2('0x41')]);_0x13dc43[_0x25f2('0x44')]=_[_0x25f2('0x43')](_0x1ac24a['model'],qs[_0x25f2('0x45')](_0x52650a[_0x25f2('0x41')][_0x25f2('0x45')]));_0x13dc43[_0x25f2('0x44')]=_0x13dc43[_0x25f2('0x44')][_0x25f2('0x46')]?_0x13dc43[_0x25f2('0x44')]:_0x1ac24a[_0x25f2('0x3f')];if(!_0x52650a['query']['hasOwnProperty'](_0x25f2('0x47'))){_0x13dc43[_0x25f2('0x30')]=qs['limit'](_0x52650a[_0x25f2('0x41')]['limit']);_0x13dc43[_0x25f2('0x2f')]=qs['offset'](_0x52650a['query']['offset']);}_0x13dc43[_0x25f2('0x48')]=qs[_0x25f2('0x49')](_0x52650a[_0x25f2('0x41')]['sort']);_0x13dc43[_0x25f2('0x4a')]=qs[_0x25f2('0x42')](_[_0x25f2('0x4b')](_0x52650a[_0x25f2('0x41')],_0x1ac24a['filters']),_0x47139a);if(_0x52650a[_0x25f2('0x41')][_0x25f2('0x4c')]){_0x13dc43[_0x25f2('0x4a')]=_[_0x25f2('0x4d')](_0x13dc43[_0x25f2('0x4a')],{'$or':_['map'](_0x47139a,function(_0x27308b){if(_0x27308b[_0x25f2('0x4e')]!==_0x25f2('0x4f')){var _0x27ba46={};_0x27ba46[_0x27308b[_0x25f2('0x37')]]={'$like':'%'+_0x52650a['query'][_0x25f2('0x4c')]+'%'};return _0x27ba46;}})});}_0x13dc43=_[_0x25f2('0x4d')]({},_0x13dc43,_0x52650a[_0x25f2('0x50')]);var _0x2ce1f0={'where':_0x13dc43[_0x25f2('0x4a')]};return db['ChatMessage'][_0x25f2('0x2e')](_0x2ce1f0)[_0x25f2('0x21')](function(_0x2c7971){_0x1e33d5[_0x25f2('0x2e')]=_0x2c7971;if(_0x52650a[_0x25f2('0x41')][_0x25f2('0x51')]){_0x13dc43['include']=[{'all':!![]}];}return db[_0x25f2('0x3b')][_0x25f2('0x52')](_0x13dc43);})[_0x25f2('0x21')](function(_0x26a88d){_0x1e33d5[_0x25f2('0x53')]=_0x26a88d;return _0x1e33d5;})[_0x25f2('0x21')](respondWithFilteredResult(_0x14e1a6,_0x13dc43))['catch'](handleError(_0x14e1a6,null));};exports[_0x25f2('0x54')]=function(_0x17df86,_0x112588){var _0x41dddf={'raw':!![],'where':{'id':_0x17df86[_0x25f2('0x55')]['id']}},_0x610025={};_0x610025[_0x25f2('0x3f')]=_[_0x25f2('0x40')](db[_0x25f2('0x3b')][_0x25f2('0x3c')]);_0x610025[_0x25f2('0x41')]=_[_0x25f2('0x40')](_0x17df86[_0x25f2('0x41')]);_0x610025[_0x25f2('0x42')]=_['intersection'](_0x610025['model'],_0x610025[_0x25f2('0x41')]);_0x41dddf[_0x25f2('0x44')]=_[_0x25f2('0x43')](_0x610025[_0x25f2('0x3f')],qs[_0x25f2('0x45')](_0x17df86[_0x25f2('0x41')][_0x25f2('0x45')]));_0x41dddf[_0x25f2('0x44')]=_0x41dddf[_0x25f2('0x44')]['length']?_0x41dddf[_0x25f2('0x44')]:_0x610025[_0x25f2('0x3f')];if(_0x17df86[_0x25f2('0x41')][_0x25f2('0x51')]){_0x41dddf[_0x25f2('0x56')]=[{'all':!![]}];}_0x41dddf=_[_0x25f2('0x4d')]({},_0x41dddf,_0x17df86[_0x25f2('0x50')]);return db[_0x25f2('0x3b')][_0x25f2('0x57')](_0x41dddf)[_0x25f2('0x21')](handleEntityNotFound(_0x112588,null))[_0x25f2('0x21')](respondWithResult(_0x112588,null))[_0x25f2('0x2a')](handleError(_0x112588,null));};exports['create']=function(_0x51f497,_0x35cb47){return db[_0x25f2('0x3b')][_0x25f2('0x58')](_0x51f497[_0x25f2('0x59')],{})[_0x25f2('0x21')](respondWithResult(_0x35cb47,0xc9))['catch'](handleError(_0x35cb47,null));};exports[_0x25f2('0x35')]=function(_0x316e6a,_0x126f51){if(_0x316e6a[_0x25f2('0x59')]['id']){delete _0x316e6a[_0x25f2('0x59')]['id'];}return db['ChatMessage'][_0x25f2('0x57')]({'where':{'id':_0x316e6a[_0x25f2('0x55')]['id']}})['then'](handleEntityNotFound(_0x126f51,null))[_0x25f2('0x21')](saveUpdates(_0x316e6a[_0x25f2('0x59')],null))['then'](respondWithResult(_0x126f51,null))[_0x25f2('0x2a')](handleError(_0x126f51,null));};exports['destroy']=function(_0x5c82dc,_0x145f58){return db[_0x25f2('0x3b')][_0x25f2('0x57')]({'where':{'id':_0x5c82dc[_0x25f2('0x55')]['id']}})['then'](handleEntityNotFound(_0x145f58,null))[_0x25f2('0x21')](removeEntity(_0x145f58,null))[_0x25f2('0x2a')](handleError(_0x145f58,null));};exports[_0x25f2('0x5a')]=function(_0x530126,_0x580af6){return db[_0x25f2('0x3b')][_0x25f2('0x5a')]()[_0x25f2('0x21')](respondWithResult(_0x580af6,null))[_0x25f2('0x2a')](handleError(_0x580af6,null));};var interaction_log=require(_0x25f2('0x14'))('chat-interactions');exports[_0x25f2('0x5b')]=function(_0x3ef774,_0x14ee49,_0x2dcee1){var _0xb73254={'agent':{},'channel':_0x25f2('0x5c')};if(_0x3ef774[_0x25f2('0x59')]['id']){delete _0x3ef774['body']['id'];}_0x3ef774[_0x25f2('0x59')][_0x25f2('0x5d')]=!![];_0x3ef774[_0x25f2('0x59')][_0x25f2('0x5e')]=moment()[_0x25f2('0x5f')](_0x25f2('0x60'));_0x3ef774[_0x25f2('0x59')][_0x25f2('0x61')]=_0x3ef774[_0x25f2('0x59')][_0x25f2('0x61')]||_0x3ef774[_0x25f2('0x62')]['id'];_0xb73254[_0x25f2('0x63')]['id']=_0x3ef774['body'][_0x25f2('0x61')];return db[_0x25f2('0x3b')]['find']({'where':{'id':_0x3ef774[_0x25f2('0x55')]['id'],'UserId':null},'include':[{'model':db[_0x25f2('0x64')],'as':'Contact'}]})[_0x25f2('0x21')](handleEntityNotFound(_0x14ee49,null))[_0x25f2('0x21')](saveUpdates(_0x3ef774[_0x25f2('0x59')],null))[_0x25f2('0x21')](function(_0x3163b0){if(_0x3163b0){_0xb73254['message']=_0x3163b0[_0x25f2('0x65')]({'plain':!![]});return db[_0x25f2('0x66')][_0x25f2('0x57')]({'where':{'id':_0x3163b0[_0x25f2('0x67')]}});}return null;})[_0x25f2('0x21')](handleEntityNotFound(_0x14ee49,null))[_0x25f2('0x21')](function(_0x4a5ee2){if(_0x4a5ee2){return _0x4a5ee2[_0x25f2('0x35')]({'UserId':_0x3ef774[_0x25f2('0x59')][_0x25f2('0x61')],'read1stAt':_[_0x25f2('0x68')](_0x4a5ee2[_0x25f2('0x69')])?moment()['format'](_0x25f2('0x60')):undefined});}return null;})['then'](function(_0x39090e){if(_0x39090e){_0xb73254[_0x25f2('0x6a')]=_0x39090e[_0x25f2('0x65')]({'plain':!![]});interaction_log['info'](_0x25f2('0x6b'),_0x3ef774[_0x25f2('0x62')]['id'],_0x3ef774[_0x25f2('0x62')][_0x25f2('0x37')],_0x3ef774[_0x25f2('0x62')][_0x25f2('0x6c')],_0xb73254[_0x25f2('0x6a')]['id'],_0x3ef774[_0x25f2('0x59')]?JSON[_0x25f2('0x26')](_0x3ef774[_0x25f2('0x59')]):_0x25f2('0x6d'));return respondWithRpcPromise(_0x25f2('0x6e'),'acceptMessage',_0xb73254);}return null;})[_0x25f2('0x21')](function(_0x27f462){if(_0x27f462){if(_0x3ef774['body']['manual']){_0xb73254['message'][_0x25f2('0x6f')]=util[_0x25f2('0x5f')]('SIP/%s',_0x3ef774['user'][_0x25f2('0x37')]);_0xb73254['message'][_0x25f2('0x70')]=_0xb73254['channel'];_0xb73254['message'][_0x25f2('0x71')]=_0x25f2('0x5b');return respondWithRpcPromise('EventManager',_0x25f2('0x72'),{'event':_0x25f2('0x73'),'message':_[_0x25f2('0x4d')](_0xb73254[_0x25f2('0x29')],JSON[_0x25f2('0x74')](_0xb73254[_0x25f2('0x6a')]['formData']))},client9002)[_0x25f2('0x21')](function(){return _0xb73254;});}return _0xb73254;}return null;})[_0x25f2('0x21')](respondWithResult(_0x14ee49,null))[_0x25f2('0x2a')](handleError(_0x14ee49,null));};var interaction_log=require(_0x25f2('0x14'))(_0x25f2('0x75'));exports['reject']=function(_0x5932c6,_0x1f87cc,_0x121642){var _0x2cd705={'agent':{},'channel':_0x25f2('0x5c')};if(_0x5932c6[_0x25f2('0x59')]['id']){delete _0x5932c6[_0x25f2('0x59')]['id'];}_0x5932c6['body'][_0x25f2('0x61')]=_0x5932c6[_0x25f2('0x59')][_0x25f2('0x61')]||_0x5932c6[_0x25f2('0x62')]['id'];_0x2cd705[_0x25f2('0x63')]['id']=_0x5932c6[_0x25f2('0x59')]['UserId'];return db['ChatMessage'][_0x25f2('0x57')]({'where':{'id':_0x5932c6[_0x25f2('0x55')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x1f87cc,null))['then'](function(_0x3122fd){if(_0x3122fd){_0x2cd705[_0x25f2('0x29')]=_0x3122fd[_0x25f2('0x65')]({'plain':!![]});return db[_0x25f2('0x66')][_0x25f2('0x57')]({'where':{'id':_0x3122fd[_0x25f2('0x67')]}});}return null;})['then'](handleEntityNotFound(_0x1f87cc,null))[_0x25f2('0x21')](function(_0x249909){if(_0x249909){_0x2cd705[_0x25f2('0x6a')]=_0x249909['get']({'plain':!![]});interaction_log[_0x25f2('0x22')]('[CHATMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x5932c6[_0x25f2('0x62')]['id'],_0x5932c6[_0x25f2('0x62')][_0x25f2('0x37')],_0x5932c6[_0x25f2('0x62')][_0x25f2('0x6c')],_0x2cd705[_0x25f2('0x6a')]['id'],_0x5932c6[_0x25f2('0x59')]?JSON[_0x25f2('0x26')](_0x5932c6[_0x25f2('0x59')]):_0x25f2('0x6d'));return respondWithRpcPromise(_0x25f2('0x76'),_0x25f2('0x77'),_0x2cd705);}return null;})[_0x25f2('0x21')](function(_0x57a519){if(_0x57a519){_0x57a519['message'][_0x25f2('0x6f')]=util['format'](_0x25f2('0x78'),_0x5932c6['user'][_0x25f2('0x37')]);_0x57a519[_0x25f2('0x29')][_0x25f2('0x70')]=_0x2cd705['channel'];_0x57a519[_0x25f2('0x29')][_0x25f2('0x71')]=_0x25f2('0x34');respondWithRpcPromise(_0x25f2('0x72'),'EventManager',{'event':_0x25f2('0x79'),'message':_0x57a519['message']},client9002);return _0x2cd705;}return null;})['then'](respondWithResult(_0x1f87cc,null))[_0x25f2('0x2a')](handleError(_0x1f87cc,null));};
\ No newline at end of file