Built motion from commit 00bf23f6.|2.6.16
[motion2.git] / server / api / chatMessage / chatMessage.controller.js
index a7ffe02..525a727 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x9f43=['[CHATMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','null','RejectMessage','rejectMessage','interface','channel','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','path','sox','to-csv','ejs','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/utils','../../config/license/util','../../mysqldb','redis','defaults','localhost','./chatMessage.socket','register','client','http','request','then','info','ChatMessage,\x20%s,\x20%s','debug','ChatMessage,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','result','catch','end','json','offset','limit','undefined','count','set','apply','reject','save','update','destroy','status','sendStatus','stack','name','send','map','ChatMessage','fieldName','type','key','query','filters','intersection','model','fields','length','attributes','nolimit','sort','pick','filter','where','VIRTUAL','merge','options','includeAll','findAll','show','params','rawAttributes','keys','include','find','create','body','describe','../../config/logger','chat-interactions','accept','chat','read','readAt','UserId','user','agent','CmContact','Contact','get','ChatInteraction','isNil','read1stAt','format','YYYY-MM-DD\x20HH:mm:ss','[CHATMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','acceptMessage','manual','SIP/%s','event','EventManager','acceptmessage','parse','ChatInteractionId','interaction'];(function(_0x115b7f,_0x3e5fcf){var _0x36974f=function(_0x80e6bb){while(--_0x80e6bb){_0x115b7f['push'](_0x115b7f['shift']());}};_0x36974f(++_0x3e5fcf);}(_0x9f43,0x81));var _0x39f4=function(_0x3a9635,_0x1ab817){_0x3a9635=_0x3a9635-0x0;var _0x10d08c=_0x9f43[_0x3a9635];return _0x10d08c;};'use strict';var emlformat=require(_0x39f4('0x0'));var rimraf=require(_0x39f4('0x1'));var zipdir=require(_0x39f4('0x2'));var jsonpatch=require(_0x39f4('0x3'));var rp=require(_0x39f4('0x4'));var moment=require(_0x39f4('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x39f4('0x6'));var util=require('util');var path=require(_0x39f4('0x7'));var sox=require(_0x39f4('0x8'));var csv=require(_0x39f4('0x9'));var ejs=require(_0x39f4('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x39f4('0xb'));var deskjs=require(_0x39f4('0xc'));var toCsv=require(_0x39f4('0x9'));var querystring=require('querystring');var Papa=require(_0x39f4('0xd'));var Redis=require(_0x39f4('0xe'));var authService=require(_0x39f4('0xf'));var qs=require(_0x39f4('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x39f4('0x11'));var logger=require('../../config/logger')('api');var utils=require(_0x39f4('0x12'));var config=require('../../config/environment');var licenseUtil=require(_0x39f4('0x13'));var db=require(_0x39f4('0x14'))['db'];config[_0x39f4('0x15')]=_[_0x39f4('0x16')](config[_0x39f4('0x15')],{'host':_0x39f4('0x17'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x39f4('0x18'))[_0x39f4('0x19')](socket);var jayson=require('jayson/promise');var client=jayson[_0x39f4('0x1a')][_0x39f4('0x1b')]({'port':0x232c});var client9002=jayson['client'][_0x39f4('0x1b')]({'port':0x232a});function respondWithRpcPromise(_0x2fd629,_0x5d6364,_0x1a21a0,_0x58fdd9){return new BPromise(function(_0x14098f,_0x13a009){var _0x54c444=_0x58fdd9||client;return _0x54c444[_0x39f4('0x1c')](_0x2fd629,_0x1a21a0)[_0x39f4('0x1d')](function(_0x5c4536){logger[_0x39f4('0x1e')](_0x39f4('0x1f'),_0x5d6364,'request\x20sent');logger[_0x39f4('0x20')](_0x39f4('0x21'),_0x5d6364,_0x39f4('0x22'),JSON[_0x39f4('0x23')](_0x5c4536));if(_0x5c4536[_0x39f4('0x24')]){if(_0x5c4536[_0x39f4('0x24')][_0x39f4('0x25')]===0x1f4){logger[_0x39f4('0x24')](_0x39f4('0x1f'),_0x5d6364,_0x5c4536[_0x39f4('0x24')]['message']);return _0x13a009(_0x5c4536[_0x39f4('0x24')][_0x39f4('0x26')]);}logger['error']('ChatMessage,\x20%s,\x20%s',_0x5d6364,_0x5c4536['error']['message']);return _0x14098f(_0x5c4536[_0x39f4('0x24')]['message']);}else{logger['info'](_0x39f4('0x1f'),_0x5d6364,'request\x20sent');_0x14098f(_0x5c4536[_0x39f4('0x27')]['message']);}})[_0x39f4('0x28')](function(_0x32e8d7){logger[_0x39f4('0x24')](_0x39f4('0x1f'),_0x5d6364,_0x32e8d7);_0x13a009(_0x32e8d7);});});}function respondWithStatusCode(_0x5644f6,_0x5cba2c){_0x5cba2c=_0x5cba2c||0xcc;return function(_0x22fbcf){if(_0x22fbcf){return _0x5644f6['sendStatus'](_0x5cba2c);}return _0x5644f6['status'](_0x5cba2c)[_0x39f4('0x29')]();};}function respondWithResult(_0x15d050,_0x2cc7f5){_0x2cc7f5=_0x2cc7f5||0xc8;return function(_0x3b2f44){if(_0x3b2f44){return _0x15d050['status'](_0x2cc7f5)[_0x39f4('0x2a')](_0x3b2f44);}};}function respondWithFilteredResult(_0x5e96f8,_0x327cc9){return function(_0x5a5d40){if(_0x5a5d40){var _0x5d838e=typeof _0x327cc9[_0x39f4('0x2b')]==='undefined'&&typeof _0x327cc9[_0x39f4('0x2c')]===_0x39f4('0x2d');var _0x17c123=_0x5a5d40[_0x39f4('0x2e')];var _0x5687f2=_0x5d838e?0x0:_0x327cc9[_0x39f4('0x2b')];var _0x4a816e=_0x5d838e?_0x5a5d40['count']:_0x327cc9['offset']+_0x327cc9['limit'];var _0x37a698;if(_0x4a816e>=_0x17c123){_0x4a816e=_0x17c123;_0x37a698=0xc8;}else{_0x37a698=0xce;}_0x5e96f8['status'](_0x37a698);return _0x5e96f8[_0x39f4('0x2f')]('Content-Range',_0x5687f2+'-'+_0x4a816e+'/'+_0x17c123)['json'](_0x5a5d40);}return null;};}function patchUpdates(_0xef339d){return function(_0x2ab3e7){try{jsonpatch[_0x39f4('0x30')](_0x2ab3e7,_0xef339d,!![]);}catch(_0x304ea4){return BPromise[_0x39f4('0x31')](_0x304ea4);}return _0x2ab3e7[_0x39f4('0x32')]();};}function saveUpdates(_0x1ee4aa,_0xc6f3be){return function(_0x23618b){if(_0x23618b){return _0x23618b[_0x39f4('0x33')](_0x1ee4aa)[_0x39f4('0x1d')](function(_0x19e0be){return _0x19e0be;});}return null;};}function removeEntity(_0x4bebaa,_0x12a99b){return function(_0x5ce321){if(_0x5ce321){return _0x5ce321[_0x39f4('0x34')]()[_0x39f4('0x1d')](function(){_0x4bebaa[_0x39f4('0x35')](0xcc)[_0x39f4('0x29')]();});}};}function handleEntityNotFound(_0x5d0477,_0x2aec5c){return function(_0xce2a7f){if(!_0xce2a7f){_0x5d0477[_0x39f4('0x36')](0x194);}return _0xce2a7f;};}function handleError(_0x1cfe2c,_0x223b0b){_0x223b0b=_0x223b0b||0x1f4;return function(_0x49cf58){logger['error'](_0x49cf58[_0x39f4('0x37')]);if(_0x49cf58[_0x39f4('0x38')]){delete _0x49cf58[_0x39f4('0x38')];}_0x1cfe2c['status'](_0x223b0b)[_0x39f4('0x39')](_0x49cf58);};}exports['index']=function(_0x16efcd,_0x90c65b){var _0xe11322={},_0x18ce59={},_0x3ddc92={'count':0x0,'rows':[]};var _0x5d0da6=_[_0x39f4('0x3a')](db[_0x39f4('0x3b')]['rawAttributes'],function(_0x594f0c){return{'name':_0x594f0c[_0x39f4('0x3c')],'type':_0x594f0c[_0x39f4('0x3d')][_0x39f4('0x3e')]};});_0x18ce59['model']=_['map'](_0x5d0da6,_0x39f4('0x38'));_0x18ce59[_0x39f4('0x3f')]=_['keys'](_0x16efcd[_0x39f4('0x3f')]);_0x18ce59[_0x39f4('0x40')]=_[_0x39f4('0x41')](_0x18ce59[_0x39f4('0x42')],_0x18ce59['query']);_0xe11322['attributes']=_['intersection'](_0x18ce59[_0x39f4('0x42')],qs[_0x39f4('0x43')](_0x16efcd[_0x39f4('0x3f')]['fields']));_0xe11322['attributes']=_0xe11322['attributes'][_0x39f4('0x44')]?_0xe11322[_0x39f4('0x45')]:_0x18ce59[_0x39f4('0x42')];if(!_0x16efcd[_0x39f4('0x3f')]['hasOwnProperty'](_0x39f4('0x46'))){_0xe11322[_0x39f4('0x2c')]=qs[_0x39f4('0x2c')](_0x16efcd[_0x39f4('0x3f')][_0x39f4('0x2c')]);_0xe11322[_0x39f4('0x2b')]=qs[_0x39f4('0x2b')](_0x16efcd['query'][_0x39f4('0x2b')]);}_0xe11322['order']=qs[_0x39f4('0x47')](_0x16efcd[_0x39f4('0x3f')]['sort']);_0xe11322['where']=qs['filters'](_[_0x39f4('0x48')](_0x16efcd[_0x39f4('0x3f')],_0x18ce59['filters']),_0x5d0da6);if(_0x16efcd[_0x39f4('0x3f')][_0x39f4('0x49')]){_0xe11322[_0x39f4('0x4a')]=_['merge'](_0xe11322[_0x39f4('0x4a')],{'$or':_[_0x39f4('0x3a')](_0x5d0da6,function(_0x453d90){if(_0x453d90[_0x39f4('0x3d')]!==_0x39f4('0x4b')){var _0x56d01c={};_0x56d01c[_0x453d90[_0x39f4('0x38')]]={'$like':'%'+_0x16efcd[_0x39f4('0x3f')][_0x39f4('0x49')]+'%'};return _0x56d01c;}})});}_0xe11322=_[_0x39f4('0x4c')]({},_0xe11322,_0x16efcd[_0x39f4('0x4d')]);var _0x5852fd={'where':_0xe11322['where']};return db[_0x39f4('0x3b')][_0x39f4('0x2e')](_0x5852fd)['then'](function(_0x3d8561){_0x3ddc92['count']=_0x3d8561;if(_0x16efcd[_0x39f4('0x3f')][_0x39f4('0x4e')]){_0xe11322['include']=[{'all':!![]}];}return db[_0x39f4('0x3b')][_0x39f4('0x4f')](_0xe11322);})['then'](function(_0x474fe3){_0x3ddc92['rows']=_0x474fe3;return _0x3ddc92;})[_0x39f4('0x1d')](respondWithFilteredResult(_0x90c65b,_0xe11322))[_0x39f4('0x28')](handleError(_0x90c65b,null));};exports[_0x39f4('0x50')]=function(_0x1dcefb,_0x1a4d18){var _0x34ed01={'raw':!![],'where':{'id':_0x1dcefb[_0x39f4('0x51')]['id']}},_0x3d54ce={};_0x3d54ce[_0x39f4('0x42')]=_['keys'](db[_0x39f4('0x3b')][_0x39f4('0x52')]);_0x3d54ce[_0x39f4('0x3f')]=_[_0x39f4('0x53')](_0x1dcefb[_0x39f4('0x3f')]);_0x3d54ce[_0x39f4('0x40')]=_['intersection'](_0x3d54ce['model'],_0x3d54ce[_0x39f4('0x3f')]);_0x34ed01['attributes']=_[_0x39f4('0x41')](_0x3d54ce[_0x39f4('0x42')],qs[_0x39f4('0x43')](_0x1dcefb['query'][_0x39f4('0x43')]));_0x34ed01['attributes']=_0x34ed01['attributes'][_0x39f4('0x44')]?_0x34ed01[_0x39f4('0x45')]:_0x3d54ce[_0x39f4('0x42')];if(_0x1dcefb[_0x39f4('0x3f')][_0x39f4('0x4e')]){_0x34ed01[_0x39f4('0x54')]=[{'all':!![]}];}_0x34ed01=_[_0x39f4('0x4c')]({},_0x34ed01,_0x1dcefb[_0x39f4('0x4d')]);return db[_0x39f4('0x3b')][_0x39f4('0x55')](_0x34ed01)[_0x39f4('0x1d')](handleEntityNotFound(_0x1a4d18,null))['then'](respondWithResult(_0x1a4d18,null))[_0x39f4('0x28')](handleError(_0x1a4d18,null));};exports['create']=function(_0x411d41,_0x33875e){return db['ChatMessage'][_0x39f4('0x56')](_0x411d41[_0x39f4('0x57')],{})[_0x39f4('0x1d')](respondWithResult(_0x33875e,0xc9))[_0x39f4('0x28')](handleError(_0x33875e,null));};exports['update']=function(_0x37ecd2,_0x4702ca){if(_0x37ecd2['body']['id']){delete _0x37ecd2[_0x39f4('0x57')]['id'];}return db[_0x39f4('0x3b')][_0x39f4('0x55')]({'where':{'id':_0x37ecd2[_0x39f4('0x51')]['id']}})[_0x39f4('0x1d')](handleEntityNotFound(_0x4702ca,null))[_0x39f4('0x1d')](saveUpdates(_0x37ecd2[_0x39f4('0x57')],null))[_0x39f4('0x1d')](respondWithResult(_0x4702ca,null))['catch'](handleError(_0x4702ca,null));};exports[_0x39f4('0x34')]=function(_0x3b0824,_0x563418){return db[_0x39f4('0x3b')][_0x39f4('0x55')]({'where':{'id':_0x3b0824[_0x39f4('0x51')]['id']}})[_0x39f4('0x1d')](handleEntityNotFound(_0x563418,null))['then'](removeEntity(_0x563418,null))[_0x39f4('0x28')](handleError(_0x563418,null));};exports[_0x39f4('0x58')]=function(_0x4a9e55,_0x419fa3){return db[_0x39f4('0x3b')][_0x39f4('0x58')]()[_0x39f4('0x1d')](respondWithResult(_0x419fa3,null))['catch'](handleError(_0x419fa3,null));};var interaction_log=require(_0x39f4('0x59'))(_0x39f4('0x5a'));exports[_0x39f4('0x5b')]=function(_0xb7dd00,_0x2eedcf,_0x4aeb0b){var _0x21ba49={'agent':{},'channel':_0x39f4('0x5c')};if(_0xb7dd00[_0x39f4('0x57')]['id']){delete _0xb7dd00[_0x39f4('0x57')]['id'];}_0xb7dd00[_0x39f4('0x57')][_0x39f4('0x5d')]=!![];_0xb7dd00['body'][_0x39f4('0x5e')]=moment()['format']('YYYY-MM-DD\x20HH:mm:ss');_0xb7dd00[_0x39f4('0x57')][_0x39f4('0x5f')]=_0xb7dd00[_0x39f4('0x57')][_0x39f4('0x5f')]||_0xb7dd00[_0x39f4('0x60')]['id'];_0x21ba49[_0x39f4('0x61')]['id']=_0xb7dd00[_0x39f4('0x57')][_0x39f4('0x5f')];return db[_0x39f4('0x3b')][_0x39f4('0x55')]({'where':{'id':_0xb7dd00[_0x39f4('0x51')]['id'],'UserId':null},'include':[{'model':db[_0x39f4('0x62')],'as':_0x39f4('0x63')}]})[_0x39f4('0x1d')](handleEntityNotFound(_0x2eedcf,null))[_0x39f4('0x1d')](saveUpdates(_0xb7dd00['body'],null))[_0x39f4('0x1d')](function(_0x225585){if(_0x225585){_0x21ba49[_0x39f4('0x26')]=_0x225585[_0x39f4('0x64')]({'plain':!![]});return db[_0x39f4('0x65')][_0x39f4('0x55')]({'where':{'id':_0x225585['ChatInteractionId']}});}return null;})['then'](handleEntityNotFound(_0x2eedcf,null))[_0x39f4('0x1d')](function(_0x49f34e){if(_0x49f34e){return _0x49f34e['update']({'UserId':_0xb7dd00['body'][_0x39f4('0x5f')],'read1stAt':_[_0x39f4('0x66')](_0x49f34e[_0x39f4('0x67')])?moment()[_0x39f4('0x68')](_0x39f4('0x69')):undefined});}return null;})[_0x39f4('0x1d')](function(_0x37d030){if(_0x37d030){_0x21ba49['interaction']=_0x37d030[_0x39f4('0x64')]({'plain':!![]});interaction_log[_0x39f4('0x1e')](_0x39f4('0x6a'),_0xb7dd00['user']['id'],_0xb7dd00[_0x39f4('0x60')][_0x39f4('0x38')],_0xb7dd00[_0x39f4('0x60')][_0x39f4('0x6b')],_0x21ba49['interaction']['id'],_0xb7dd00[_0x39f4('0x57')]?JSON[_0x39f4('0x23')](_0xb7dd00[_0x39f4('0x57')]):'null');return respondWithRpcPromise('AcceptMessage',_0x39f4('0x6c'),_0x21ba49);}return null;})[_0x39f4('0x1d')](function(_0x18a4bc){if(_0x18a4bc){if(_0xb7dd00[_0x39f4('0x57')][_0x39f4('0x6d')]){_0x21ba49['message']['interface']=util['format'](_0x39f4('0x6e'),_0xb7dd00['user'][_0x39f4('0x38')]);_0x21ba49['message']['channel']=_0x21ba49['channel'];_0x21ba49[_0x39f4('0x26')][_0x39f4('0x6f')]=_0x39f4('0x5b');return respondWithRpcPromise('EventManager',_0x39f4('0x70'),{'event':_0x39f4('0x71'),'message':_[_0x39f4('0x4c')](_0x21ba49[_0x39f4('0x26')],JSON[_0x39f4('0x72')](_0x21ba49['interaction']['formData']))},client9002)['then'](function(){return _0x21ba49;});}return _0x21ba49;}return null;})['then'](respondWithResult(_0x2eedcf,null))[_0x39f4('0x28')](handleError(_0x2eedcf,null));};var interaction_log=require(_0x39f4('0x59'))(_0x39f4('0x5a'));exports[_0x39f4('0x31')]=function(_0x478b9e,_0x38c6c5,_0x5cf737){var _0x2ccb5a={'agent':{},'channel':_0x39f4('0x5c')};if(_0x478b9e[_0x39f4('0x57')]['id']){delete _0x478b9e[_0x39f4('0x57')]['id'];}_0x478b9e[_0x39f4('0x57')][_0x39f4('0x5f')]=_0x478b9e[_0x39f4('0x57')][_0x39f4('0x5f')]||_0x478b9e[_0x39f4('0x60')]['id'];_0x2ccb5a['agent']['id']=_0x478b9e[_0x39f4('0x57')][_0x39f4('0x5f')];return db[_0x39f4('0x3b')][_0x39f4('0x55')]({'where':{'id':_0x478b9e[_0x39f4('0x51')]['id'],'UserId':null}})[_0x39f4('0x1d')](handleEntityNotFound(_0x38c6c5,null))[_0x39f4('0x1d')](function(_0x3e11c5){if(_0x3e11c5){_0x2ccb5a['message']=_0x3e11c5[_0x39f4('0x64')]({'plain':!![]});return db[_0x39f4('0x65')][_0x39f4('0x55')]({'where':{'id':_0x3e11c5[_0x39f4('0x73')]}});}return null;})[_0x39f4('0x1d')](handleEntityNotFound(_0x38c6c5,null))[_0x39f4('0x1d')](function(_0x4e9990){if(_0x4e9990){_0x2ccb5a[_0x39f4('0x74')]=_0x4e9990[_0x39f4('0x64')]({'plain':!![]});interaction_log['info'](_0x39f4('0x75'),_0x478b9e['user']['id'],_0x478b9e[_0x39f4('0x60')][_0x39f4('0x38')],_0x478b9e[_0x39f4('0x60')][_0x39f4('0x6b')],_0x2ccb5a[_0x39f4('0x74')]['id'],_0x478b9e['body']?JSON[_0x39f4('0x23')](_0x478b9e[_0x39f4('0x57')]):_0x39f4('0x76'));return respondWithRpcPromise(_0x39f4('0x77'),_0x39f4('0x78'),_0x2ccb5a);}return null;})['then'](function(_0x232bae){if(_0x232bae){_0x232bae[_0x39f4('0x26')][_0x39f4('0x79')]=util['format'](_0x39f4('0x6e'),_0x478b9e[_0x39f4('0x60')][_0x39f4('0x38')]);_0x232bae[_0x39f4('0x26')][_0x39f4('0x7a')]=_0x2ccb5a[_0x39f4('0x7a')];_0x232bae[_0x39f4('0x26')][_0x39f4('0x6f')]=_0x39f4('0x31');respondWithRpcPromise(_0x39f4('0x70'),'EventManager',{'event':'rejectmessage','message':_0x232bae['message']},client9002);return _0x2ccb5a;}return null;})['then'](respondWithResult(_0x38c6c5,null))[_0x39f4('0x28')](handleError(_0x38c6c5,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