Built motion from commit 00bf23f6.|2.6.16
[motion2.git] / server / api / chatMessage / chatMessage.controller.js
index 54f5c48..525a727 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xbf13=['to-csv','ejs','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','redis','localhost','./chatMessage.socket','register','request','then','info','request\x20sent','debug','ChatMessage,\x20%s,\x20%s,\x20%s','error','ChatMessage,\x20%s,\x20%s','message','result','catch','sendStatus','status','end','count','offset','limit','set','Content-Range','json','reject','save','update','destroy','stack','name','send','index','map','ChatMessage','rawAttributes','fieldName','type','key','model','query','keys','filters','attributes','fields','length','sort','where','pick','filter','merge','VIRTUAL','options','findAll','rows','show','params','intersection','includeAll','include','find','create','body','../../config/logger','chat-interactions','read','YYYY-MM-DD\x20HH:mm:ss','UserId','user','Contact','get','read1stAt','format','interaction','[CHATMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','stringify','null','AcceptMessage','acceptMessage','manual','interface','SIP/%s','channel','accept','EventManager','acceptmessage','parse','chat','ChatInteraction','ChatInteractionId','[CHATMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','event','html-pdf','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','path','sox'];(function(_0x4ed13c,_0xeca59a){var _0xefde65=function(_0x41eddf){while(--_0x41eddf){_0x4ed13c['push'](_0x4ed13c['shift']());}};_0xefde65(++_0xeca59a);}(_0xbf13,0x159));var _0x3bf1=function(_0x3e9d35,_0x25ab2a){_0x3e9d35=_0x3e9d35-0x0;var _0xac638c=_0xbf13[_0x3e9d35];return _0xac638c;};'use strict';var pdf=require(_0x3bf1('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x3bf1('0x1'));var zipdir=require(_0x3bf1('0x2'));var jsonpatch=require(_0x3bf1('0x3'));var rp=require(_0x3bf1('0x4'));var moment=require('moment');var BPromise=require(_0x3bf1('0x5'));var Mustache=require(_0x3bf1('0x6'));var util=require('util');var path=require(_0x3bf1('0x7'));var sox=require(_0x3bf1('0x8'));var csv=require(_0x3bf1('0x9'));var ejs=require(_0x3bf1('0xa'));var fs=require('fs');var _=require(_0x3bf1('0xb'));var squel=require('squel');var crypto=require(_0x3bf1('0xc'));var jsforce=require(_0x3bf1('0xd'));var deskjs=require(_0x3bf1('0xe'));var toCsv=require(_0x3bf1('0x9'));var querystring=require(_0x3bf1('0xf'));var Papa=require(_0x3bf1('0x10'));var Redis=require(_0x3bf1('0x11'));var authService=require(_0x3bf1('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0x3bf1('0x13'));var hardwareService=require(_0x3bf1('0x14'));var logger=require('../../config/logger')(_0x3bf1('0x15'));var utils=require('../../config/utils');var config=require(_0x3bf1('0x16'));var licenseUtil=require(_0x3bf1('0x17'));var db=require('../../mysqldb')['db'];config[_0x3bf1('0x18')]=_['defaults'](config[_0x3bf1('0x18')],{'host':_0x3bf1('0x19'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x3bf1('0x18')]));require(_0x3bf1('0x1a'))[_0x3bf1('0x1b')](socket);var jayson=require('jayson/promise');var client=jayson['client']['http']({'port':0x232c});var client9002=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x571f77,_0x3a36bc,_0x1d2660,_0x268cd7){return new BPromise(function(_0xe8626e,_0x33271a){var _0x5948ee=_0x268cd7||client;return _0x5948ee[_0x3bf1('0x1c')](_0x571f77,_0x1d2660)[_0x3bf1('0x1d')](function(_0x35f942){logger[_0x3bf1('0x1e')]('ChatMessage,\x20%s,\x20%s',_0x3a36bc,_0x3bf1('0x1f'));logger[_0x3bf1('0x20')](_0x3bf1('0x21'),_0x3a36bc,'request\x20sent',JSON['stringify'](_0x35f942));if(_0x35f942[_0x3bf1('0x22')]){if(_0x35f942['error']['code']===0x1f4){logger[_0x3bf1('0x22')](_0x3bf1('0x23'),_0x3a36bc,_0x35f942['error']['message']);return _0x33271a(_0x35f942[_0x3bf1('0x22')][_0x3bf1('0x24')]);}logger[_0x3bf1('0x22')](_0x3bf1('0x23'),_0x3a36bc,_0x35f942['error'][_0x3bf1('0x24')]);return _0xe8626e(_0x35f942[_0x3bf1('0x22')]['message']);}else{logger[_0x3bf1('0x1e')](_0x3bf1('0x23'),_0x3a36bc,_0x3bf1('0x1f'));_0xe8626e(_0x35f942[_0x3bf1('0x25')]['message']);}})[_0x3bf1('0x26')](function(_0x4a7169){logger[_0x3bf1('0x22')](_0x3bf1('0x23'),_0x3a36bc,_0x4a7169);_0x33271a(_0x4a7169);});});}function respondWithStatusCode(_0xd71580,_0x394ade){_0x394ade=_0x394ade||0xcc;return function(_0x4c9164){if(_0x4c9164){return _0xd71580[_0x3bf1('0x27')](_0x394ade);}return _0xd71580[_0x3bf1('0x28')](_0x394ade)[_0x3bf1('0x29')]();};}function respondWithResult(_0x10ce38,_0x3553b6){_0x3553b6=_0x3553b6||0xc8;return function(_0x50b812){if(_0x50b812){return _0x10ce38['status'](_0x3553b6)['json'](_0x50b812);}};}function respondWithFilteredResult(_0xf54488,_0x24c313){return function(_0x301804){if(_0x301804){var _0x3b52e8=_0x301804[_0x3bf1('0x2a')],_0x12648c=_0x24c313[_0x3bf1('0x2b')],_0x533d7f=_0x24c313[_0x3bf1('0x2b')]+_0x24c313[_0x3bf1('0x2c')],_0x3dd85b;if(_0x533d7f>=_0x3b52e8){_0x533d7f=_0x3b52e8;_0x3dd85b=0xc8;}else{_0x3dd85b=0xce;}_0xf54488[_0x3bf1('0x28')](_0x3dd85b);return _0xf54488[_0x3bf1('0x2d')](_0x3bf1('0x2e'),_0x12648c+'-'+_0x533d7f+'/'+_0x3b52e8)[_0x3bf1('0x2f')](_0x301804);}return null;};}function patchUpdates(_0x4a67a6){return function(_0x5ca171){try{jsonpatch['apply'](_0x5ca171,_0x4a67a6,!![]);}catch(_0xf6a0ea){return BPromise[_0x3bf1('0x30')](_0xf6a0ea);}return _0x5ca171[_0x3bf1('0x31')]();};}function saveUpdates(_0x405815,_0x44b921){return function(_0x26a318){if(_0x26a318){return _0x26a318[_0x3bf1('0x32')](_0x405815)[_0x3bf1('0x1d')](function(_0x46051e){return _0x46051e;});}return null;};}function removeEntity(_0x390022,_0x37ca95){return function(_0x159176){if(_0x159176){return _0x159176[_0x3bf1('0x33')]()['then'](function(){_0x390022[_0x3bf1('0x28')](0xcc)[_0x3bf1('0x29')]();});}};}function handleEntityNotFound(_0x402334,_0xe5a250){return function(_0x43d610){if(!_0x43d610){_0x402334[_0x3bf1('0x27')](0x194);}return _0x43d610;};}function handleError(_0x3b04fd,_0x28c0e1){_0x28c0e1=_0x28c0e1||0x1f4;return function(_0x3e49b6){logger[_0x3bf1('0x22')](_0x3e49b6[_0x3bf1('0x34')]);if(_0x3e49b6[_0x3bf1('0x35')]){delete _0x3e49b6['name'];}_0x3b04fd[_0x3bf1('0x28')](_0x28c0e1)[_0x3bf1('0x36')](_0x3e49b6);};}exports[_0x3bf1('0x37')]=function(_0x3e6f71,_0x2b4b10){var _0x2bde1a={},_0xf50386={},_0x5bbce8={'count':0x0,'rows':[]};var _0x36acf5=_[_0x3bf1('0x38')](db[_0x3bf1('0x39')][_0x3bf1('0x3a')],function(_0x51054c){return{'name':_0x51054c[_0x3bf1('0x3b')],'type':_0x51054c[_0x3bf1('0x3c')][_0x3bf1('0x3d')]};});_0xf50386[_0x3bf1('0x3e')]=_[_0x3bf1('0x38')](_0x36acf5,'name');_0xf50386[_0x3bf1('0x3f')]=_[_0x3bf1('0x40')](_0x3e6f71[_0x3bf1('0x3f')]);_0xf50386[_0x3bf1('0x41')]=_['intersection'](_0xf50386['model'],_0xf50386[_0x3bf1('0x3f')]);_0x2bde1a[_0x3bf1('0x42')]=_['intersection'](_0xf50386['model'],qs['fields'](_0x3e6f71[_0x3bf1('0x3f')][_0x3bf1('0x43')]));_0x2bde1a[_0x3bf1('0x42')]=_0x2bde1a[_0x3bf1('0x42')][_0x3bf1('0x44')]?_0x2bde1a[_0x3bf1('0x42')]:_0xf50386[_0x3bf1('0x3e')];if(!_0x3e6f71[_0x3bf1('0x3f')]['hasOwnProperty']('nolimit')){_0x2bde1a[_0x3bf1('0x2c')]=qs[_0x3bf1('0x2c')](_0x3e6f71[_0x3bf1('0x3f')][_0x3bf1('0x2c')]);_0x2bde1a[_0x3bf1('0x2b')]=qs[_0x3bf1('0x2b')](_0x3e6f71[_0x3bf1('0x3f')]['offset']);}_0x2bde1a['order']=qs['sort'](_0x3e6f71[_0x3bf1('0x3f')][_0x3bf1('0x45')]);_0x2bde1a[_0x3bf1('0x46')]=qs[_0x3bf1('0x41')](_[_0x3bf1('0x47')](_0x3e6f71[_0x3bf1('0x3f')],_0xf50386['filters']),_0x36acf5);if(_0x3e6f71[_0x3bf1('0x3f')][_0x3bf1('0x48')]){_0x2bde1a['where']=_[_0x3bf1('0x49')](_0x2bde1a['where'],{'$or':_['map'](_0x36acf5,function(_0x1bb336){if(_0x1bb336['type']!==_0x3bf1('0x4a')){var _0x107412={};_0x107412[_0x1bb336['name']]={'$like':'%'+_0x3e6f71['query']['filter']+'%'};return _0x107412;}})});}_0x2bde1a=_[_0x3bf1('0x49')]({},_0x2bde1a,_0x3e6f71[_0x3bf1('0x4b')]);var _0x41da89={'where':_0x2bde1a[_0x3bf1('0x46')]};return db[_0x3bf1('0x39')][_0x3bf1('0x2a')](_0x41da89)[_0x3bf1('0x1d')](function(_0x18b202){_0x5bbce8[_0x3bf1('0x2a')]=_0x18b202;if(_0x3e6f71[_0x3bf1('0x3f')]['includeAll']){_0x2bde1a['include']=[{'all':!![]}];}return db[_0x3bf1('0x39')][_0x3bf1('0x4c')](_0x2bde1a);})[_0x3bf1('0x1d')](function(_0x283651){_0x5bbce8[_0x3bf1('0x4d')]=_0x283651;return _0x5bbce8;})[_0x3bf1('0x1d')](respondWithFilteredResult(_0x2b4b10,_0x2bde1a))[_0x3bf1('0x26')](handleError(_0x2b4b10,null));};exports[_0x3bf1('0x4e')]=function(_0xe77b21,_0x2ceaed){var _0x39bbd3={'raw':!![],'where':{'id':_0xe77b21[_0x3bf1('0x4f')]['id']}},_0x2de4e6={};_0x2de4e6[_0x3bf1('0x3e')]=_[_0x3bf1('0x40')](db[_0x3bf1('0x39')][_0x3bf1('0x3a')]);_0x2de4e6[_0x3bf1('0x3f')]=_[_0x3bf1('0x40')](_0xe77b21['query']);_0x2de4e6[_0x3bf1('0x41')]=_[_0x3bf1('0x50')](_0x2de4e6[_0x3bf1('0x3e')],_0x2de4e6[_0x3bf1('0x3f')]);_0x39bbd3[_0x3bf1('0x42')]=_[_0x3bf1('0x50')](_0x2de4e6[_0x3bf1('0x3e')],qs[_0x3bf1('0x43')](_0xe77b21[_0x3bf1('0x3f')][_0x3bf1('0x43')]));_0x39bbd3['attributes']=_0x39bbd3[_0x3bf1('0x42')][_0x3bf1('0x44')]?_0x39bbd3[_0x3bf1('0x42')]:_0x2de4e6['model'];if(_0xe77b21[_0x3bf1('0x3f')][_0x3bf1('0x51')]){_0x39bbd3[_0x3bf1('0x52')]=[{'all':!![]}];}_0x39bbd3=_['merge']({},_0x39bbd3,_0xe77b21['options']);return db[_0x3bf1('0x39')][_0x3bf1('0x53')](_0x39bbd3)[_0x3bf1('0x1d')](handleEntityNotFound(_0x2ceaed,null))['then'](respondWithResult(_0x2ceaed,null))[_0x3bf1('0x26')](handleError(_0x2ceaed,null));};exports[_0x3bf1('0x54')]=function(_0x7aa20c,_0x4dce58){return db['ChatMessage'][_0x3bf1('0x54')](_0x7aa20c['body'],{})['then'](respondWithResult(_0x4dce58,0xc9))[_0x3bf1('0x26')](handleError(_0x4dce58,null));};exports[_0x3bf1('0x32')]=function(_0x3f364d,_0x5a2520){if(_0x3f364d[_0x3bf1('0x55')]['id']){delete _0x3f364d['body']['id'];}return db['ChatMessage'][_0x3bf1('0x53')]({'where':{'id':_0x3f364d[_0x3bf1('0x4f')]['id']}})[_0x3bf1('0x1d')](handleEntityNotFound(_0x5a2520,null))['then'](saveUpdates(_0x3f364d[_0x3bf1('0x55')],null))[_0x3bf1('0x1d')](respondWithResult(_0x5a2520,null))['catch'](handleError(_0x5a2520,null));};exports[_0x3bf1('0x33')]=function(_0x2d7f5d,_0x2ea167){return db[_0x3bf1('0x39')]['find']({'where':{'id':_0x2d7f5d['params']['id']}})['then'](handleEntityNotFound(_0x2ea167,null))[_0x3bf1('0x1d')](removeEntity(_0x2ea167,null))[_0x3bf1('0x26')](handleError(_0x2ea167,null));};exports['describe']=function(_0x32c2c2,_0x4798ef){return db['ChatMessage']['describe']()['then'](respondWithResult(_0x4798ef,null))[_0x3bf1('0x26')](handleError(_0x4798ef,null));};var interaction_log=require(_0x3bf1('0x56'))(_0x3bf1('0x57'));exports['accept']=function(_0x36743b,_0xaf0a53,_0x38cdea){var _0x518cbb={'agent':{},'channel':'chat'};if(_0x36743b[_0x3bf1('0x55')]['id']){delete _0x36743b['body']['id'];}_0x36743b[_0x3bf1('0x55')][_0x3bf1('0x58')]=!![];_0x36743b[_0x3bf1('0x55')]['readAt']=moment()['format'](_0x3bf1('0x59'));_0x36743b[_0x3bf1('0x55')][_0x3bf1('0x5a')]=_0x36743b['body'][_0x3bf1('0x5a')]||_0x36743b[_0x3bf1('0x5b')]['id'];_0x518cbb['agent']['id']=_0x36743b[_0x3bf1('0x55')][_0x3bf1('0x5a')];return db[_0x3bf1('0x39')][_0x3bf1('0x53')]({'where':{'id':_0x36743b['params']['id'],'UserId':null},'include':[{'model':db['CmContact'],'as':_0x3bf1('0x5c')}]})[_0x3bf1('0x1d')](handleEntityNotFound(_0xaf0a53,null))['then'](saveUpdates(_0x36743b[_0x3bf1('0x55')],null))['then'](function(_0x52dba9){if(_0x52dba9){_0x518cbb[_0x3bf1('0x24')]=_0x52dba9[_0x3bf1('0x5d')]({'plain':!![]});return db['ChatInteraction'][_0x3bf1('0x53')]({'where':{'id':_0x52dba9['ChatInteractionId']}});}return null;})[_0x3bf1('0x1d')](handleEntityNotFound(_0xaf0a53,null))[_0x3bf1('0x1d')](function(_0x2f9aa2){if(_0x2f9aa2){return _0x2f9aa2[_0x3bf1('0x32')]({'UserId':_0x36743b['body'][_0x3bf1('0x5a')],'read1stAt':_['isNil'](_0x2f9aa2[_0x3bf1('0x5e')])?moment()[_0x3bf1('0x5f')](_0x3bf1('0x59')):undefined});}return null;})[_0x3bf1('0x1d')](function(_0xd9276b){if(_0xd9276b){_0x518cbb[_0x3bf1('0x60')]=_0xd9276b[_0x3bf1('0x5d')]({'plain':!![]});interaction_log['info'](_0x3bf1('0x61'),_0x36743b['user']['id'],_0x36743b[_0x3bf1('0x5b')][_0x3bf1('0x35')],_0x36743b['user'][_0x3bf1('0x62')],_0x518cbb[_0x3bf1('0x60')]['id'],_0x36743b['body']?JSON[_0x3bf1('0x63')](_0x36743b[_0x3bf1('0x55')]):_0x3bf1('0x64'));return respondWithRpcPromise(_0x3bf1('0x65'),_0x3bf1('0x66'),_0x518cbb);}return null;})[_0x3bf1('0x1d')](function(_0x127b60){if(_0x127b60){if(_0x36743b[_0x3bf1('0x55')][_0x3bf1('0x67')]){_0x518cbb[_0x3bf1('0x24')][_0x3bf1('0x68')]=util[_0x3bf1('0x5f')](_0x3bf1('0x69'),_0x36743b[_0x3bf1('0x5b')]['name']);_0x518cbb[_0x3bf1('0x24')][_0x3bf1('0x6a')]=_0x518cbb[_0x3bf1('0x6a')];_0x518cbb['message']['event']=_0x3bf1('0x6b');return respondWithRpcPromise(_0x3bf1('0x6c'),_0x3bf1('0x6c'),{'event':_0x3bf1('0x6d'),'message':_[_0x3bf1('0x49')](_0x518cbb[_0x3bf1('0x24')],JSON[_0x3bf1('0x6e')](_0x518cbb[_0x3bf1('0x60')]['formData']))},client9002)[_0x3bf1('0x1d')](function(){return _0x518cbb;});}return _0x518cbb;}return null;})[_0x3bf1('0x1d')](respondWithResult(_0xaf0a53,null))['catch'](handleError(_0xaf0a53,null));};var interaction_log=require(_0x3bf1('0x56'))(_0x3bf1('0x57'));exports[_0x3bf1('0x30')]=function(_0xef69c5,_0x234687,_0x239b89){var _0xf5abf2={'agent':{},'channel':_0x3bf1('0x6f')};if(_0xef69c5[_0x3bf1('0x55')]['id']){delete _0xef69c5['body']['id'];}_0xef69c5['body'][_0x3bf1('0x5a')]=_0xef69c5[_0x3bf1('0x55')][_0x3bf1('0x5a')]||_0xef69c5[_0x3bf1('0x5b')]['id'];_0xf5abf2['agent']['id']=_0xef69c5['body'][_0x3bf1('0x5a')];return db['ChatMessage'][_0x3bf1('0x53')]({'where':{'id':_0xef69c5[_0x3bf1('0x4f')]['id'],'UserId':null}})[_0x3bf1('0x1d')](handleEntityNotFound(_0x234687,null))['then'](function(_0x27dea3){if(_0x27dea3){_0xf5abf2[_0x3bf1('0x24')]=_0x27dea3[_0x3bf1('0x5d')]({'plain':!![]});return db[_0x3bf1('0x70')]['find']({'where':{'id':_0x27dea3[_0x3bf1('0x71')]}});}return null;})['then'](handleEntityNotFound(_0x234687,null))['then'](function(_0x1c598f){if(_0x1c598f){_0xf5abf2['interaction']=_0x1c598f[_0x3bf1('0x5d')]({'plain':!![]});interaction_log[_0x3bf1('0x1e')](_0x3bf1('0x72'),_0xef69c5['user']['id'],_0xef69c5[_0x3bf1('0x5b')]['name'],_0xef69c5[_0x3bf1('0x5b')]['role'],_0xf5abf2['interaction']['id'],_0xef69c5[_0x3bf1('0x55')]?JSON[_0x3bf1('0x63')](_0xef69c5['body']):_0x3bf1('0x64'));return respondWithRpcPromise(_0x3bf1('0x73'),_0x3bf1('0x74'),_0xf5abf2);}return null;})[_0x3bf1('0x1d')](function(_0x56dc0b){if(_0x56dc0b){_0x56dc0b[_0x3bf1('0x24')][_0x3bf1('0x68')]=util[_0x3bf1('0x5f')](_0x3bf1('0x69'),_0xef69c5[_0x3bf1('0x5b')][_0x3bf1('0x35')]);_0x56dc0b['message'][_0x3bf1('0x6a')]=_0xf5abf2['channel'];_0x56dc0b['message'][_0x3bf1('0x75')]=_0x3bf1('0x30');respondWithRpcPromise(_0x3bf1('0x6c'),'EventManager',{'event':'rejectmessage','message':_0x56dc0b[_0x3bf1('0x24')]},client9002);return _0xf5abf2;}return null;})[_0x3bf1('0x1d')](respondWithResult(_0x234687,null))['catch'](handleError(_0x234687,null));};
\ No newline at end of file
+var _0x3a71=['info','[CHATMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','contact','User','email','internal','manual','interface','SIP/%s','channel','event','accept','EventManager','acceptmessage','parse','formData','reject','[CHATMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','Sequelize','SELECT','motionChannel','eml-format','rimraf','fast-json-patch','request-promise','bluebird','util','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','localhost','./chatMessage.socket','jayson/promise','client','http','request','ChatMessage,\x20%s,\x20%s','debug','ChatMessage,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','result','sendStatus','status','json','offset','undefined','count','limit','set','Content-Range','apply','then','destroy','end','stack','name','send','index','map','ChatMessage','rawAttributes','fieldName','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','merge','type','VIRTUAL','filter','options','includeAll','include','findAll','rows','catch','show','params','keys','find','create','body','update','describe','chat-interactions','chat','read','format','UserId','user','agent','ChatInteraction','YYYY-MM-DD\x20HH:mm:ss','interaction','get'];(function(_0x549cc0,_0x4b244d){var _0x1bfc0f=function(_0x2660d0){while(--_0x2660d0){_0x549cc0['push'](_0x549cc0['shift']());}};_0x1bfc0f(++_0x4b244d);}(_0x3a71,0x1ad));var _0x13a7=function(_0x27d7b9,_0x4c1554){_0x27d7b9=_0x27d7b9-0x0;var _0x1a8dd0=_0x3a71[_0x27d7b9];return _0x1a8dd0;};'use strict';var emlformat=require(_0x13a7('0x0'));var rimraf=require(_0x13a7('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x13a7('0x2'));var rp=require(_0x13a7('0x3'));var moment=require('moment');var BPromise=require(_0x13a7('0x4'));var Mustache=require('mustache');var util=require(_0x13a7('0x5'));var path=require('path');var sox=require('sox');var csv=require(_0x13a7('0x6'));var ejs=require(_0x13a7('0x7'));var fs=require('fs');var fs_extra=require(_0x13a7('0x8'));var _=require(_0x13a7('0x9'));var squel=require(_0x13a7('0xa'));var crypto=require(_0x13a7('0xb'));var jsforce=require('jsforce');var deskjs=require(_0x13a7('0xc'));var toCsv=require('to-csv');var querystring=require(_0x13a7('0xd'));var Papa=require(_0x13a7('0xe'));var Redis=require('ioredis');var authService=require(_0x13a7('0xf'));var qs=require(_0x13a7('0x10'));var as=require(_0x13a7('0x11'));var hardwareService=require(_0x13a7('0x12'));var logger=require(_0x13a7('0x13'))(_0x13a7('0x14'));var utils=require(_0x13a7('0x15'));var config=require(_0x13a7('0x16'));var licenseUtil=require(_0x13a7('0x17'));var db=require(_0x13a7('0x18'))['db'];config[_0x13a7('0x19')]=_['defaults'](config['redis'],{'host':_0x13a7('0x1a'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x13a7('0x19')]));require(_0x13a7('0x1b'))['register'](socket);var jayson=require(_0x13a7('0x1c'));var client=jayson[_0x13a7('0x1d')][_0x13a7('0x1e')]({'port':0x232c});var client9002=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x2affd4,_0x2f2282,_0x58ebcb,_0x3c845e){return new BPromise(function(_0x334657,_0x2ff99a){var _0x1ee96f=_0x3c845e||client;return _0x1ee96f[_0x13a7('0x1f')](_0x2affd4,_0x58ebcb)['then'](function(_0x2a0517){logger['info'](_0x13a7('0x20'),_0x2f2282,'request\x20sent');logger[_0x13a7('0x21')](_0x13a7('0x22'),_0x2f2282,_0x13a7('0x23'),JSON[_0x13a7('0x24')](_0x2a0517));if(_0x2a0517[_0x13a7('0x25')]){if(_0x2a0517[_0x13a7('0x25')][_0x13a7('0x26')]===0x1f4){logger[_0x13a7('0x25')](_0x13a7('0x20'),_0x2f2282,_0x2a0517[_0x13a7('0x25')][_0x13a7('0x27')]);return _0x2ff99a(_0x2a0517['error'][_0x13a7('0x27')]);}logger[_0x13a7('0x25')](_0x13a7('0x20'),_0x2f2282,_0x2a0517[_0x13a7('0x25')][_0x13a7('0x27')]);return _0x334657(_0x2a0517['error']['message']);}else{logger['info'](_0x13a7('0x20'),_0x2f2282,_0x13a7('0x23'));_0x334657(_0x2a0517[_0x13a7('0x28')][_0x13a7('0x27')]);}})['catch'](function(_0x17a2f1){logger[_0x13a7('0x25')](_0x13a7('0x20'),_0x2f2282,_0x17a2f1);_0x2ff99a(_0x17a2f1);});});}function respondWithStatusCode(_0x58ca1f,_0xf6b27){_0xf6b27=_0xf6b27||0xcc;return function(_0x4f0b2e){if(_0x4f0b2e){return _0x58ca1f[_0x13a7('0x29')](_0xf6b27);}return _0x58ca1f[_0x13a7('0x2a')](_0xf6b27)['end']();};}function respondWithResult(_0x571e2d,_0x51b48c){_0x51b48c=_0x51b48c||0xc8;return function(_0x485e4f){if(_0x485e4f){return _0x571e2d[_0x13a7('0x2a')](_0x51b48c)[_0x13a7('0x2b')](_0x485e4f);}};}function respondWithFilteredResult(_0x5a03bb,_0x4e1142){return function(_0x545947){if(_0x545947){var _0x2c9954=typeof _0x4e1142[_0x13a7('0x2c')]===_0x13a7('0x2d')&&typeof _0x4e1142['limit']===_0x13a7('0x2d');var _0x2ce2a6=_0x545947[_0x13a7('0x2e')];var _0x1e4d04=_0x2c9954?0x0:_0x4e1142[_0x13a7('0x2c')];var _0x3e65a9=_0x2c9954?_0x545947[_0x13a7('0x2e')]:_0x4e1142['offset']+_0x4e1142[_0x13a7('0x2f')];var _0x20448d;if(_0x3e65a9>=_0x2ce2a6){_0x3e65a9=_0x2ce2a6;_0x20448d=0xc8;}else{_0x20448d=0xce;}_0x5a03bb[_0x13a7('0x2a')](_0x20448d);return _0x5a03bb[_0x13a7('0x30')](_0x13a7('0x31'),_0x1e4d04+'-'+_0x3e65a9+'/'+_0x2ce2a6)[_0x13a7('0x2b')](_0x545947);}return null;};}function patchUpdates(_0x502a9a){return function(_0x34d58e){try{jsonpatch[_0x13a7('0x32')](_0x34d58e,_0x502a9a,!![]);}catch(_0x2a5072){return BPromise['reject'](_0x2a5072);}return _0x34d58e['save']();};}function saveUpdates(_0x7d854e,_0x1c44e5){return function(_0x1be5da){if(_0x1be5da){return _0x1be5da['update'](_0x7d854e)[_0x13a7('0x33')](function(_0x1aaad8){return _0x1aaad8;});}return null;};}function removeEntity(_0xcb0fae,_0x1cc7a8){return function(_0x4a1c33){if(_0x4a1c33){return _0x4a1c33[_0x13a7('0x34')]()[_0x13a7('0x33')](function(){_0xcb0fae[_0x13a7('0x2a')](0xcc)[_0x13a7('0x35')]();});}};}function handleEntityNotFound(_0x1ae2ea,_0x549497){return function(_0xfdae39){if(!_0xfdae39){_0x1ae2ea['sendStatus'](0x194);}return _0xfdae39;};}function handleError(_0x3d2f69,_0x54aff0){_0x54aff0=_0x54aff0||0x1f4;return function(_0x58be94){logger[_0x13a7('0x25')](_0x58be94[_0x13a7('0x36')]);if(_0x58be94[_0x13a7('0x37')]){delete _0x58be94[_0x13a7('0x37')];}_0x3d2f69['status'](_0x54aff0)[_0x13a7('0x38')](_0x58be94);};}exports[_0x13a7('0x39')]=function(_0x5ed4de,_0x295798){var _0x4ba208={},_0x4f02c4={},_0x5b7550={'count':0x0,'rows':[]};var _0xba47d6=_[_0x13a7('0x3a')](db[_0x13a7('0x3b')][_0x13a7('0x3c')],function(_0x1cf607){return{'name':_0x1cf607[_0x13a7('0x3d')],'type':_0x1cf607['type']['key']};});_0x4f02c4[_0x13a7('0x3e')]=_[_0x13a7('0x3a')](_0xba47d6,_0x13a7('0x37'));_0x4f02c4[_0x13a7('0x3f')]=_['keys'](_0x5ed4de[_0x13a7('0x3f')]);_0x4f02c4[_0x13a7('0x40')]=_[_0x13a7('0x41')](_0x4f02c4[_0x13a7('0x3e')],_0x4f02c4[_0x13a7('0x3f')]);_0x4ba208[_0x13a7('0x42')]=_[_0x13a7('0x41')](_0x4f02c4[_0x13a7('0x3e')],qs[_0x13a7('0x43')](_0x5ed4de[_0x13a7('0x3f')]['fields']));_0x4ba208[_0x13a7('0x42')]=_0x4ba208['attributes'][_0x13a7('0x44')]?_0x4ba208[_0x13a7('0x42')]:_0x4f02c4['model'];if(!_0x5ed4de['query'][_0x13a7('0x45')](_0x13a7('0x46'))){_0x4ba208['limit']=qs[_0x13a7('0x2f')](_0x5ed4de[_0x13a7('0x3f')]['limit']);_0x4ba208['offset']=qs[_0x13a7('0x2c')](_0x5ed4de[_0x13a7('0x3f')][_0x13a7('0x2c')]);}_0x4ba208[_0x13a7('0x47')]=qs[_0x13a7('0x48')](_0x5ed4de['query']['sort']);_0x4ba208['where']=qs[_0x13a7('0x40')](_['pick'](_0x5ed4de[_0x13a7('0x3f')],_0x4f02c4[_0x13a7('0x40')]),_0xba47d6);if(_0x5ed4de[_0x13a7('0x3f')]['filter']){_0x4ba208[_0x13a7('0x49')]=_[_0x13a7('0x4a')](_0x4ba208[_0x13a7('0x49')],{'$or':_[_0x13a7('0x3a')](_0xba47d6,function(_0x15b1b7){if(_0x15b1b7[_0x13a7('0x4b')]!==_0x13a7('0x4c')){var _0x4c8e02={};_0x4c8e02[_0x15b1b7['name']]={'$like':'%'+_0x5ed4de[_0x13a7('0x3f')][_0x13a7('0x4d')]+'%'};return _0x4c8e02;}})});}_0x4ba208=_[_0x13a7('0x4a')]({},_0x4ba208,_0x5ed4de[_0x13a7('0x4e')]);var _0x220e10={'where':_0x4ba208[_0x13a7('0x49')]};return db['ChatMessage'][_0x13a7('0x2e')](_0x220e10)['then'](function(_0x3ec86d){_0x5b7550['count']=_0x3ec86d;if(_0x5ed4de[_0x13a7('0x3f')][_0x13a7('0x4f')]){_0x4ba208[_0x13a7('0x50')]=[{'all':!![]}];}return db[_0x13a7('0x3b')][_0x13a7('0x51')](_0x4ba208);})[_0x13a7('0x33')](function(_0x348bfd){_0x5b7550[_0x13a7('0x52')]=_0x348bfd;return _0x5b7550;})[_0x13a7('0x33')](respondWithFilteredResult(_0x295798,_0x4ba208))[_0x13a7('0x53')](handleError(_0x295798,null));};exports[_0x13a7('0x54')]=function(_0x9a2799,_0x48aaa6){var _0x6432bc={'raw':!![],'where':{'id':_0x9a2799[_0x13a7('0x55')]['id']}},_0x58c0a5={};_0x58c0a5[_0x13a7('0x3e')]=_['keys'](db[_0x13a7('0x3b')][_0x13a7('0x3c')]);_0x58c0a5[_0x13a7('0x3f')]=_[_0x13a7('0x56')](_0x9a2799['query']);_0x58c0a5['filters']=_[_0x13a7('0x41')](_0x58c0a5[_0x13a7('0x3e')],_0x58c0a5[_0x13a7('0x3f')]);_0x6432bc[_0x13a7('0x42')]=_[_0x13a7('0x41')](_0x58c0a5['model'],qs[_0x13a7('0x43')](_0x9a2799[_0x13a7('0x3f')][_0x13a7('0x43')]));_0x6432bc['attributes']=_0x6432bc[_0x13a7('0x42')][_0x13a7('0x44')]?_0x6432bc[_0x13a7('0x42')]:_0x58c0a5['model'];if(_0x9a2799['query'][_0x13a7('0x4f')]){_0x6432bc[_0x13a7('0x50')]=[{'all':!![]}];}_0x6432bc=_[_0x13a7('0x4a')]({},_0x6432bc,_0x9a2799[_0x13a7('0x4e')]);return db[_0x13a7('0x3b')][_0x13a7('0x57')](_0x6432bc)[_0x13a7('0x33')](handleEntityNotFound(_0x48aaa6,null))[_0x13a7('0x33')](respondWithResult(_0x48aaa6,null))[_0x13a7('0x53')](handleError(_0x48aaa6,null));};exports[_0x13a7('0x58')]=function(_0xf6cc0c,_0x1ff769){return db[_0x13a7('0x3b')][_0x13a7('0x58')](_0xf6cc0c[_0x13a7('0x59')],{})[_0x13a7('0x33')](respondWithResult(_0x1ff769,0xc9))['catch'](handleError(_0x1ff769,null));};exports[_0x13a7('0x5a')]=function(_0xd7b2d2,_0x3a5c5c){if(_0xd7b2d2[_0x13a7('0x59')]['id']){delete _0xd7b2d2[_0x13a7('0x59')]['id'];}return db[_0x13a7('0x3b')][_0x13a7('0x57')]({'where':{'id':_0xd7b2d2[_0x13a7('0x55')]['id']}})['then'](handleEntityNotFound(_0x3a5c5c,null))[_0x13a7('0x33')](saveUpdates(_0xd7b2d2[_0x13a7('0x59')],null))[_0x13a7('0x33')](respondWithResult(_0x3a5c5c,null))[_0x13a7('0x53')](handleError(_0x3a5c5c,null));};exports[_0x13a7('0x34')]=function(_0x4183cb,_0x194426){return db['ChatMessage'][_0x13a7('0x57')]({'where':{'id':_0x4183cb[_0x13a7('0x55')]['id']}})[_0x13a7('0x33')](handleEntityNotFound(_0x194426,null))[_0x13a7('0x33')](removeEntity(_0x194426,null))['catch'](handleError(_0x194426,null));};exports['describe']=function(_0xc26147,_0x24969e){return db[_0x13a7('0x3b')][_0x13a7('0x5b')]()[_0x13a7('0x33')](respondWithResult(_0x24969e,null))[_0x13a7('0x53')](handleError(_0x24969e,null));};var interaction_log=require(_0x13a7('0x13'))(_0x13a7('0x5c'));exports['accept']=function(_0x1b8250,_0x4867bc,_0x70e9a8){var _0x30c17c={'agent':{},'channel':_0x13a7('0x5d')};if(_0x1b8250[_0x13a7('0x59')]['id']){delete _0x1b8250[_0x13a7('0x59')]['id'];}_0x1b8250[_0x13a7('0x59')][_0x13a7('0x5e')]=!![];_0x1b8250[_0x13a7('0x59')]['readAt']=moment()[_0x13a7('0x5f')]('YYYY-MM-DD\x20HH:mm:ss');_0x1b8250[_0x13a7('0x59')][_0x13a7('0x60')]=_0x1b8250[_0x13a7('0x59')][_0x13a7('0x60')]||_0x1b8250[_0x13a7('0x61')]['id'];_0x30c17c[_0x13a7('0x62')]['id']=_0x1b8250[_0x13a7('0x59')][_0x13a7('0x60')];return db['ChatMessage']['find']({'where':{'id':_0x1b8250[_0x13a7('0x55')]['id'],'UserId':null}})[_0x13a7('0x33')](handleEntityNotFound(_0x4867bc,null))[_0x13a7('0x33')](saveUpdates(_0x1b8250[_0x13a7('0x59')],null))[_0x13a7('0x33')](function(_0x9832a){if(_0x9832a){_0x30c17c[_0x13a7('0x27')]=_0x9832a['get']({'plain':!![]});return db[_0x13a7('0x63')][_0x13a7('0x57')]({'where':{'id':_0x9832a['ChatInteractionId']}});}return null;})[_0x13a7('0x33')](handleEntityNotFound(_0x4867bc,null))[_0x13a7('0x33')](function(_0x1b969a){if(_0x1b969a){return _0x1b969a['update']({'UserId':_0x1b8250['body'][_0x13a7('0x60')],'read1stAt':_['isNil'](_0x1b969a['read1stAt'])?moment()['format'](_0x13a7('0x64')):undefined});}return null;})[_0x13a7('0x33')](function(_0x571d98){if(_0x571d98){_0x30c17c[_0x13a7('0x65')]=_0x571d98[_0x13a7('0x66')]({'plain':!![]});interaction_log[_0x13a7('0x67')](_0x13a7('0x68'),_0x1b8250['user']['id'],_0x1b8250[_0x13a7('0x61')][_0x13a7('0x37')],_0x1b8250[_0x13a7('0x61')][_0x13a7('0x69')],_0x30c17c[_0x13a7('0x65')]['id'],_0x1b8250[_0x13a7('0x59')]?JSON['stringify'](_0x1b8250[_0x13a7('0x59')]):_0x13a7('0x6a'));return respondWithRpcPromise(_0x13a7('0x6b'),_0x13a7('0x6c'),_0x30c17c);}return null;})[_0x13a7('0x33')](function(_0x4be950){var _0x379cf5=_0x13a7('0x6d')+_0x4be950[_0x13a7('0x27')][_0x13a7('0x6e')];return db[_0x13a7('0x6f')]['query'](_0x379cf5,{'type':db['Sequelize']['QueryTypes']['SELECT'],'raw':!![]})[_0x13a7('0x33')](function(_0x523c08){return _0x523c08;});})[_0x13a7('0x33')](function(_0x38dde4){if(_0x38dde4){_0x30c17c[_0x13a7('0x27')][_0x13a7('0x70')]=_0x38dde4[0x0];if(!_0x1b8250[_0x13a7('0x59')][_0x13a7('0x60')])return;return db[_0x13a7('0x71')]['find']({'where':{'id':_0x1b8250[_0x13a7('0x59')][_0x13a7('0x60')],'role':'agent'},'attributes':['id',_0x13a7('0x37'),'fullname',_0x13a7('0x72'),_0x13a7('0x73')],'raw':!![]});}return null;})[_0x13a7('0x33')](function(_0x1bd698){if(!_0x1bd698)return null;_0x30c17c[_0x13a7('0x27')][_0x13a7('0x62')]=_0x1bd698;return _0x30c17c;})[_0x13a7('0x33')](function(_0x492827){if(_0x492827){if(_0x1b8250[_0x13a7('0x59')][_0x13a7('0x74')]){_0x30c17c[_0x13a7('0x27')][_0x13a7('0x75')]=util[_0x13a7('0x5f')](_0x13a7('0x76'),_0x1b8250[_0x13a7('0x61')]['name']);_0x30c17c[_0x13a7('0x27')][_0x13a7('0x77')]=_0x30c17c[_0x13a7('0x77')];_0x30c17c['message']['motionChannel']=_0x30c17c['channel'];_0x30c17c['message'][_0x13a7('0x78')]=_0x13a7('0x79');return respondWithRpcPromise(_0x13a7('0x7a'),_0x13a7('0x7a'),{'event':_0x13a7('0x7b'),'message':_['merge'](_0x30c17c[_0x13a7('0x27')],JSON[_0x13a7('0x7c')](_0x30c17c['interaction'][_0x13a7('0x7d')]))},client9002)[_0x13a7('0x33')](function(){return _0x30c17c;});}return _0x30c17c;}return null;})[_0x13a7('0x33')](respondWithResult(_0x4867bc,null))['catch'](handleError(_0x4867bc,null));};var interaction_log=require('../../config/logger')(_0x13a7('0x5c'));exports[_0x13a7('0x7e')]=function(_0x30b48f,_0x3c3ee3,_0x5b6854){var _0x4c3016={'agent':{},'channel':'chat'};if(_0x30b48f[_0x13a7('0x59')]['id']){delete _0x30b48f[_0x13a7('0x59')]['id'];}_0x30b48f[_0x13a7('0x59')]['UserId']=_0x30b48f[_0x13a7('0x59')][_0x13a7('0x60')]||_0x30b48f[_0x13a7('0x61')]['id'];_0x4c3016['agent']['id']=_0x30b48f[_0x13a7('0x59')][_0x13a7('0x60')];return db[_0x13a7('0x3b')][_0x13a7('0x57')]({'where':{'id':_0x30b48f['params']['id'],'UserId':null}})[_0x13a7('0x33')](handleEntityNotFound(_0x3c3ee3,null))[_0x13a7('0x33')](function(_0xb8444){if(_0xb8444){_0x4c3016[_0x13a7('0x27')]=_0xb8444[_0x13a7('0x66')]({'plain':!![]});return db[_0x13a7('0x63')][_0x13a7('0x57')]({'where':{'id':_0xb8444['ChatInteractionId']}});}return null;})[_0x13a7('0x33')](handleEntityNotFound(_0x3c3ee3,null))[_0x13a7('0x33')](function(_0x4039a4){if(_0x4039a4){_0x4c3016[_0x13a7('0x65')]=_0x4039a4[_0x13a7('0x66')]({'plain':!![]});interaction_log[_0x13a7('0x67')](_0x13a7('0x7f'),_0x30b48f[_0x13a7('0x61')]['id'],_0x30b48f[_0x13a7('0x61')][_0x13a7('0x37')],_0x30b48f[_0x13a7('0x61')]['role'],_0x4c3016['interaction']['id'],_0x30b48f[_0x13a7('0x59')]?JSON[_0x13a7('0x24')](_0x30b48f[_0x13a7('0x59')]):_0x13a7('0x6a'));return respondWithRpcPromise(_0x13a7('0x80'),_0x13a7('0x81'),_0x4c3016);}return null;})[_0x13a7('0x33')](function(_0xe4f503){var _0x4c69bb=_0x13a7('0x6d')+_0xe4f503[_0x13a7('0x27')][_0x13a7('0x6e')];return db['sequelize'][_0x13a7('0x3f')](_0x4c69bb,{'type':db[_0x13a7('0x82')]['QueryTypes'][_0x13a7('0x83')],'raw':!![]})['then'](function(_0x5a2412){return _0x5a2412;});})[_0x13a7('0x33')](function(_0x287634){if(_0x287634){_0x4c3016['message']['contact']=_0x287634[0x0];if(!_0x30b48f[_0x13a7('0x59')][_0x13a7('0x60')])return;return db[_0x13a7('0x71')][_0x13a7('0x57')]({'where':{'id':_0x30b48f[_0x13a7('0x59')][_0x13a7('0x60')],'role':_0x13a7('0x62')},'attributes':['id','name','fullname',_0x13a7('0x72'),_0x13a7('0x73')],'raw':!![]});}return null;})[_0x13a7('0x33')](function(_0x45ebad){if(!_0x45ebad)return null;_0x4c3016['message']['agent']=_0x45ebad;return _0x4c3016;})['then'](function(_0xd16f1c){if(_0xd16f1c){_0xd16f1c[_0x13a7('0x27')]['interface']=util[_0x13a7('0x5f')](_0x13a7('0x76'),_0x30b48f[_0x13a7('0x61')][_0x13a7('0x37')]);_0xd16f1c['message']['channel']=_0x4c3016[_0x13a7('0x77')];_0xd16f1c['message'][_0x13a7('0x84')]=_0x4c3016[_0x13a7('0x77')];_0xd16f1c[_0x13a7('0x27')]['event']=_0x13a7('0x7e');respondWithRpcPromise(_0x13a7('0x7a'),'EventManager',{'event':'rejectmessage','message':_[_0x13a7('0x4a')](_0x4c3016[_0x13a7('0x27')],JSON[_0x13a7('0x7c')](_0x4c3016[_0x13a7('0x65')][_0x13a7('0x7d')]))},client9002);return _0x4c3016;}return null;})[_0x13a7('0x33')](respondWithResult(_0x3c3ee3,null))['catch'](handleError(_0x3c3ee3,null));};
\ No newline at end of file