Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / chatMessage / chatMessage.controller.js
index 6a1c368..32e22c8 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xdbcd=['client','then','info','debug','ChatMessage,\x20%s,\x20%s,\x20%s','request\x20sent','error','ChatMessage,\x20%s,\x20%s','message','result','catch','status','end','json','offset','limit','undefined','count','set','Content-Range','apply','save','update','destroy','sendStatus','name','send','index','map','rawAttributes','fieldName','key','query','filters','intersection','model','attributes','fields','hasOwnProperty','order','sort','where','merge','type','VIRTUAL','options','includeAll','include','ChatMessage','findAll','rows','params','keys','length','find','create','body','describe','../../config/logger','accept','chat','read','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','ChatInteraction','ChatInteractionId','isNil','interaction','[CHATMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','stringify','null','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','Sequelize','QueryTypes','SELECT','User','agent','fullname','internal','manual','interface','SIP/%s','motionChannel','channel','event','EventManager','acceptmessage','parse','formData','chat-interactions','reject','get','[CHATMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','rejectMessage','ContactId','sequelize','contact','email','rimraf','zip-dir','fast-json-patch','moment','mustache','util','path','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','querystring','../../components/auth/service','../../components/parsers/advancedSearch','api','../../config/utils','../../config/license/util','../../mysqldb','redis','socket.io-emitter','./chatMessage.socket','register','jayson/promise','http'];(function(_0x2419f5,_0x5babca){var _0x2d9bd3=function(_0x3f94ec){while(--_0x3f94ec){_0x2419f5['push'](_0x2419f5['shift']());}};_0x2d9bd3(++_0x5babca);}(_0xdbcd,0x67));var _0xddbc=function(_0x187aad,_0xfadd51){_0x187aad=_0x187aad-0x0;var _0x16e487=_0xdbcd[_0x187aad];return _0x16e487;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xddbc('0x0'));var zipdir=require(_0xddbc('0x1'));var jsonpatch=require(_0xddbc('0x2'));var rp=require('request-promise');var moment=require(_0xddbc('0x3'));var BPromise=require('bluebird');var Mustache=require(_0xddbc('0x4'));var util=require(_0xddbc('0x5'));var path=require(_0xddbc('0x6'));var sox=require(_0xddbc('0x7'));var csv=require(_0xddbc('0x8'));var ejs=require(_0xddbc('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xddbc('0xa'));var squel=require(_0xddbc('0xb'));var crypto=require('crypto');var jsforce=require(_0xddbc('0xc'));var deskjs=require(_0xddbc('0xd'));var toCsv=require(_0xddbc('0x8'));var querystring=require(_0xddbc('0xe'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0xddbc('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0xddbc('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xddbc('0x11'));var utils=require(_0xddbc('0x12'));var config=require('../../config/environment');var licenseUtil=require(_0xddbc('0x13'));var db=require(_0xddbc('0x14'))['db'];config[_0xddbc('0x15')]=_['defaults'](config[_0xddbc('0x15')],{'host':'localhost','port':0x18eb});var socket=require(_0xddbc('0x16'))(new Redis(config[_0xddbc('0x15')]));require(_0xddbc('0x17'))[_0xddbc('0x18')](socket);var jayson=require(_0xddbc('0x19'));var client=jayson['client'][_0xddbc('0x1a')]({'port':0x232c});var client9002=jayson[_0xddbc('0x1b')][_0xddbc('0x1a')]({'port':0x232a});function respondWithRpcPromise(_0x5dc036,_0x424a23,_0x128698,_0x18cc83){return new BPromise(function(_0x44e0be,_0xa9addf){var _0x3af297=_0x18cc83||client;return _0x3af297['request'](_0x5dc036,_0x128698)[_0xddbc('0x1c')](function(_0x32e2ff){logger[_0xddbc('0x1d')]('ChatMessage,\x20%s,\x20%s',_0x424a23,'request\x20sent');logger[_0xddbc('0x1e')](_0xddbc('0x1f'),_0x424a23,_0xddbc('0x20'),JSON['stringify'](_0x32e2ff));if(_0x32e2ff[_0xddbc('0x21')]){if(_0x32e2ff[_0xddbc('0x21')]['code']===0x1f4){logger['error'](_0xddbc('0x22'),_0x424a23,_0x32e2ff[_0xddbc('0x21')][_0xddbc('0x23')]);return _0xa9addf(_0x32e2ff[_0xddbc('0x21')]['message']);}logger[_0xddbc('0x21')](_0xddbc('0x22'),_0x424a23,_0x32e2ff['error']['message']);return _0x44e0be(_0x32e2ff[_0xddbc('0x21')]['message']);}else{logger[_0xddbc('0x1d')]('ChatMessage,\x20%s,\x20%s',_0x424a23,_0xddbc('0x20'));_0x44e0be(_0x32e2ff[_0xddbc('0x24')][_0xddbc('0x23')]);}})[_0xddbc('0x25')](function(_0x404270){logger['error'](_0xddbc('0x22'),_0x424a23,_0x404270);_0xa9addf(_0x404270);});});}function respondWithStatusCode(_0x1696f4,_0x9b2e33){_0x9b2e33=_0x9b2e33||0xcc;return function(_0xedda1){if(_0xedda1){return _0x1696f4['sendStatus'](_0x9b2e33);}return _0x1696f4[_0xddbc('0x26')](_0x9b2e33)[_0xddbc('0x27')]();};}function respondWithResult(_0x22b2af,_0x20a536){_0x20a536=_0x20a536||0xc8;return function(_0xe6b98d){if(_0xe6b98d){return _0x22b2af['status'](_0x20a536)[_0xddbc('0x28')](_0xe6b98d);}};}function respondWithFilteredResult(_0x3d5235,_0x49fa43){return function(_0x5b5fd1){if(_0x5b5fd1){var _0x2e1217=typeof _0x49fa43[_0xddbc('0x29')]==='undefined'&&typeof _0x49fa43[_0xddbc('0x2a')]===_0xddbc('0x2b');var _0x4b3819=_0x5b5fd1[_0xddbc('0x2c')];var _0x20178e=_0x2e1217?0x0:_0x49fa43[_0xddbc('0x29')];var _0x1bcd71=_0x2e1217?_0x5b5fd1['count']:_0x49fa43[_0xddbc('0x29')]+_0x49fa43[_0xddbc('0x2a')];var _0xcd4b80;if(_0x1bcd71>=_0x4b3819){_0x1bcd71=_0x4b3819;_0xcd4b80=0xc8;}else{_0xcd4b80=0xce;}_0x3d5235[_0xddbc('0x26')](_0xcd4b80);return _0x3d5235[_0xddbc('0x2d')](_0xddbc('0x2e'),_0x20178e+'-'+_0x1bcd71+'/'+_0x4b3819)[_0xddbc('0x28')](_0x5b5fd1);}return null;};}function patchUpdates(_0x3419fc){return function(_0x92da56){try{jsonpatch[_0xddbc('0x2f')](_0x92da56,_0x3419fc,!![]);}catch(_0x175146){return BPromise['reject'](_0x175146);}return _0x92da56[_0xddbc('0x30')]();};}function saveUpdates(_0x22e3de,_0x1fae8b){return function(_0x557135){if(_0x557135){return _0x557135[_0xddbc('0x31')](_0x22e3de)[_0xddbc('0x1c')](function(_0x5f03d3){return _0x5f03d3;});}return null;};}function removeEntity(_0xa6fcba,_0x76b27c){return function(_0x494d3e){if(_0x494d3e){return _0x494d3e[_0xddbc('0x32')]()[_0xddbc('0x1c')](function(){_0xa6fcba['status'](0xcc)[_0xddbc('0x27')]();});}};}function handleEntityNotFound(_0x546679,_0x5d2477){return function(_0x4ed5e7){if(!_0x4ed5e7){_0x546679[_0xddbc('0x33')](0x194);}return _0x4ed5e7;};}function handleError(_0x2f8182,_0x47cb22){_0x47cb22=_0x47cb22||0x1f4;return function(_0x40a85e){logger[_0xddbc('0x21')](_0x40a85e['stack']);if(_0x40a85e[_0xddbc('0x34')]){delete _0x40a85e['name'];}_0x2f8182[_0xddbc('0x26')](_0x47cb22)[_0xddbc('0x35')](_0x40a85e);};}exports[_0xddbc('0x36')]=function(_0x1cdd7c,_0x583a0b){var _0x55c2b5={},_0x2ec4cd={},_0x456839={'count':0x0,'rows':[]};var _0x50d9de=_[_0xddbc('0x37')](db['ChatMessage'][_0xddbc('0x38')],function(_0x17c828){return{'name':_0x17c828[_0xddbc('0x39')],'type':_0x17c828['type'][_0xddbc('0x3a')]};});_0x2ec4cd['model']=_[_0xddbc('0x37')](_0x50d9de,'name');_0x2ec4cd[_0xddbc('0x3b')]=_['keys'](_0x1cdd7c['query']);_0x2ec4cd[_0xddbc('0x3c')]=_[_0xddbc('0x3d')](_0x2ec4cd[_0xddbc('0x3e')],_0x2ec4cd[_0xddbc('0x3b')]);_0x55c2b5[_0xddbc('0x3f')]=_[_0xddbc('0x3d')](_0x2ec4cd['model'],qs['fields'](_0x1cdd7c[_0xddbc('0x3b')][_0xddbc('0x40')]));_0x55c2b5[_0xddbc('0x3f')]=_0x55c2b5[_0xddbc('0x3f')]['length']?_0x55c2b5[_0xddbc('0x3f')]:_0x2ec4cd[_0xddbc('0x3e')];if(!_0x1cdd7c[_0xddbc('0x3b')][_0xddbc('0x41')]('nolimit')){_0x55c2b5[_0xddbc('0x2a')]=qs[_0xddbc('0x2a')](_0x1cdd7c[_0xddbc('0x3b')][_0xddbc('0x2a')]);_0x55c2b5[_0xddbc('0x29')]=qs[_0xddbc('0x29')](_0x1cdd7c[_0xddbc('0x3b')][_0xddbc('0x29')]);}_0x55c2b5[_0xddbc('0x42')]=qs[_0xddbc('0x43')](_0x1cdd7c[_0xddbc('0x3b')]['sort']);_0x55c2b5[_0xddbc('0x44')]=qs[_0xddbc('0x3c')](_['pick'](_0x1cdd7c[_0xddbc('0x3b')],_0x2ec4cd['filters']),_0x50d9de);if(_0x1cdd7c['query']['filter']){_0x55c2b5[_0xddbc('0x44')]=_[_0xddbc('0x45')](_0x55c2b5[_0xddbc('0x44')],{'$or':_[_0xddbc('0x37')](_0x50d9de,function(_0x2cd4de){if(_0x2cd4de[_0xddbc('0x46')]!==_0xddbc('0x47')){var _0x4d8aa4={};_0x4d8aa4[_0x2cd4de[_0xddbc('0x34')]]={'$like':'%'+_0x1cdd7c[_0xddbc('0x3b')]['filter']+'%'};return _0x4d8aa4;}})});}_0x55c2b5=_[_0xddbc('0x45')]({},_0x55c2b5,_0x1cdd7c[_0xddbc('0x48')]);var _0x2acc5e={'where':_0x55c2b5[_0xddbc('0x44')]};return db['ChatMessage'][_0xddbc('0x2c')](_0x2acc5e)['then'](function(_0x3ca067){_0x456839[_0xddbc('0x2c')]=_0x3ca067;if(_0x1cdd7c['query'][_0xddbc('0x49')]){_0x55c2b5[_0xddbc('0x4a')]=[{'all':!![]}];}return db[_0xddbc('0x4b')][_0xddbc('0x4c')](_0x55c2b5);})[_0xddbc('0x1c')](function(_0x568da6){_0x456839[_0xddbc('0x4d')]=_0x568da6;return _0x456839;})[_0xddbc('0x1c')](respondWithFilteredResult(_0x583a0b,_0x55c2b5))['catch'](handleError(_0x583a0b,null));};exports['show']=function(_0xa66da4,_0x3a8ac2){var _0x5b90fc={'raw':!![],'where':{'id':_0xa66da4[_0xddbc('0x4e')]['id']}},_0x402f6c={};_0x402f6c[_0xddbc('0x3e')]=_['keys'](db[_0xddbc('0x4b')][_0xddbc('0x38')]);_0x402f6c[_0xddbc('0x3b')]=_[_0xddbc('0x4f')](_0xa66da4[_0xddbc('0x3b')]);_0x402f6c[_0xddbc('0x3c')]=_[_0xddbc('0x3d')](_0x402f6c[_0xddbc('0x3e')],_0x402f6c[_0xddbc('0x3b')]);_0x5b90fc[_0xddbc('0x3f')]=_[_0xddbc('0x3d')](_0x402f6c[_0xddbc('0x3e')],qs[_0xddbc('0x40')](_0xa66da4[_0xddbc('0x3b')][_0xddbc('0x40')]));_0x5b90fc[_0xddbc('0x3f')]=_0x5b90fc[_0xddbc('0x3f')][_0xddbc('0x50')]?_0x5b90fc[_0xddbc('0x3f')]:_0x402f6c[_0xddbc('0x3e')];if(_0xa66da4['query'][_0xddbc('0x49')]){_0x5b90fc[_0xddbc('0x4a')]=[{'all':!![]}];}_0x5b90fc=_['merge']({},_0x5b90fc,_0xa66da4[_0xddbc('0x48')]);return db['ChatMessage'][_0xddbc('0x51')](_0x5b90fc)[_0xddbc('0x1c')](handleEntityNotFound(_0x3a8ac2,null))['then'](respondWithResult(_0x3a8ac2,null))['catch'](handleError(_0x3a8ac2,null));};exports['create']=function(_0x15cedd,_0x376077){return db[_0xddbc('0x4b')][_0xddbc('0x52')](_0x15cedd[_0xddbc('0x53')],{})['then'](respondWithResult(_0x376077,0xc9))[_0xddbc('0x25')](handleError(_0x376077,null));};exports[_0xddbc('0x31')]=function(_0x5c3523,_0x42844c){if(_0x5c3523['body']['id']){delete _0x5c3523[_0xddbc('0x53')]['id'];}return db[_0xddbc('0x4b')][_0xddbc('0x51')]({'where':{'id':_0x5c3523[_0xddbc('0x4e')]['id']}})[_0xddbc('0x1c')](handleEntityNotFound(_0x42844c,null))[_0xddbc('0x1c')](saveUpdates(_0x5c3523[_0xddbc('0x53')],null))[_0xddbc('0x1c')](respondWithResult(_0x42844c,null))[_0xddbc('0x25')](handleError(_0x42844c,null));};exports[_0xddbc('0x32')]=function(_0x20eb74,_0xed477){return db[_0xddbc('0x4b')][_0xddbc('0x51')]({'where':{'id':_0x20eb74['params']['id']}})[_0xddbc('0x1c')](handleEntityNotFound(_0xed477,null))['then'](removeEntity(_0xed477,null))[_0xddbc('0x25')](handleError(_0xed477,null));};exports[_0xddbc('0x54')]=function(_0x1853c5,_0x5aa05a){return db[_0xddbc('0x4b')][_0xddbc('0x54')]()[_0xddbc('0x1c')](respondWithResult(_0x5aa05a,null))[_0xddbc('0x25')](handleError(_0x5aa05a,null));};var interaction_log=require(_0xddbc('0x55'))('chat-interactions');exports[_0xddbc('0x56')]=function(_0x843fbd,_0x36c9ae,_0x4490e6){var _0x5bd960={'agent':{},'channel':_0xddbc('0x57')};if(_0x843fbd[_0xddbc('0x53')]['id']){delete _0x843fbd['body']['id'];}_0x843fbd[_0xddbc('0x53')][_0xddbc('0x58')]=!![];_0x843fbd[_0xddbc('0x53')]['readAt']=moment()[_0xddbc('0x59')](_0xddbc('0x5a'));_0x843fbd[_0xddbc('0x53')]['UserId']=_0x843fbd['body'][_0xddbc('0x5b')]||_0x843fbd[_0xddbc('0x5c')]['id'];_0x5bd960['agent']['id']=_0x843fbd[_0xddbc('0x53')]['UserId'];return db[_0xddbc('0x4b')]['find']({'where':{'id':_0x843fbd[_0xddbc('0x4e')]['id'],'UserId':null}})[_0xddbc('0x1c')](handleEntityNotFound(_0x36c9ae,null))[_0xddbc('0x1c')](saveUpdates(_0x843fbd[_0xddbc('0x53')],null))['then'](function(_0x2ffc85){if(_0x2ffc85){_0x5bd960[_0xddbc('0x23')]=_0x2ffc85['get']({'plain':!![]});return db[_0xddbc('0x5d')][_0xddbc('0x51')]({'where':{'id':_0x2ffc85[_0xddbc('0x5e')]}});}return null;})[_0xddbc('0x1c')](handleEntityNotFound(_0x36c9ae,null))['then'](function(_0x6f2bf9){if(_0x6f2bf9){return _0x6f2bf9['update']({'UserId':_0x843fbd[_0xddbc('0x53')][_0xddbc('0x5b')],'read1stAt':_[_0xddbc('0x5f')](_0x6f2bf9['read1stAt'])?moment()[_0xddbc('0x59')](_0xddbc('0x5a')):undefined});}return null;})[_0xddbc('0x1c')](function(_0x58bf85){if(_0x58bf85){_0x5bd960[_0xddbc('0x60')]=_0x58bf85['get']({'plain':!![]});interaction_log[_0xddbc('0x1d')](_0xddbc('0x61'),_0x843fbd[_0xddbc('0x5c')]['id'],_0x843fbd['user'][_0xddbc('0x34')],_0x843fbd[_0xddbc('0x5c')]['role'],_0x5bd960[_0xddbc('0x60')]['id'],_0x843fbd[_0xddbc('0x53')]?JSON[_0xddbc('0x62')](_0x843fbd[_0xddbc('0x53')]):_0xddbc('0x63'));return respondWithRpcPromise(_0xddbc('0x64'),_0xddbc('0x65'),_0x5bd960);}return null;})[_0xddbc('0x1c')](function(_0x701ae8){var _0x3ce435=_0xddbc('0x66')+_0x701ae8['message']['ContactId'];return db['sequelize'][_0xddbc('0x3b')](_0x3ce435,{'type':db[_0xddbc('0x67')][_0xddbc('0x68')][_0xddbc('0x69')],'raw':!![]})['then'](function(_0x28ca58){return _0x28ca58;});})['then'](function(_0x3b3bc8){if(_0x3b3bc8){_0x5bd960[_0xddbc('0x23')]['contact']=_0x3b3bc8[0x0];if(!_0x843fbd['body'][_0xddbc('0x5b')])return;return db[_0xddbc('0x6a')]['find']({'where':{'id':_0x843fbd[_0xddbc('0x53')][_0xddbc('0x5b')],'role':_0xddbc('0x6b')},'attributes':['id',_0xddbc('0x34'),_0xddbc('0x6c'),'email',_0xddbc('0x6d')],'raw':!![]});}return null;})['then'](function(_0x2cf1f2){if(!_0x2cf1f2)return null;_0x5bd960[_0xddbc('0x23')]['agent']=_0x2cf1f2;return _0x5bd960;})[_0xddbc('0x1c')](function(_0xc1886d){if(_0xc1886d){if(_0x843fbd['body'][_0xddbc('0x6e')]){_0x5bd960[_0xddbc('0x23')][_0xddbc('0x6f')]=util[_0xddbc('0x59')](_0xddbc('0x70'),_0x843fbd[_0xddbc('0x5c')]['name']);_0x5bd960['message']['channel']=_0x5bd960['channel'];_0x5bd960[_0xddbc('0x23')][_0xddbc('0x71')]=_0x5bd960[_0xddbc('0x72')];_0x5bd960[_0xddbc('0x23')][_0xddbc('0x73')]=_0xddbc('0x56');return respondWithRpcPromise(_0xddbc('0x74'),_0xddbc('0x74'),{'event':_0xddbc('0x75'),'message':_[_0xddbc('0x45')](_0x5bd960['message'],JSON[_0xddbc('0x76')](_0x5bd960[_0xddbc('0x60')][_0xddbc('0x77')]))},client9002)[_0xddbc('0x1c')](function(){return _0x5bd960;});}return _0x5bd960;}return null;})[_0xddbc('0x1c')](respondWithResult(_0x36c9ae,null))['catch'](handleError(_0x36c9ae,null));};var interaction_log=require('../../config/logger')(_0xddbc('0x78'));exports[_0xddbc('0x79')]=function(_0x3284db,_0x401fdf,_0x3385c7){var _0x25ab0c={'agent':{},'channel':'chat'};if(_0x3284db[_0xddbc('0x53')]['id']){delete _0x3284db[_0xddbc('0x53')]['id'];}_0x3284db[_0xddbc('0x53')][_0xddbc('0x5b')]=_0x3284db[_0xddbc('0x53')][_0xddbc('0x5b')]||_0x3284db['user']['id'];_0x25ab0c[_0xddbc('0x6b')]['id']=_0x3284db['body'][_0xddbc('0x5b')];return db[_0xddbc('0x4b')]['find']({'where':{'id':_0x3284db[_0xddbc('0x4e')]['id'],'UserId':null}})[_0xddbc('0x1c')](handleEntityNotFound(_0x401fdf,null))[_0xddbc('0x1c')](function(_0x40c563){if(_0x40c563){_0x25ab0c[_0xddbc('0x23')]=_0x40c563[_0xddbc('0x7a')]({'plain':!![]});return db[_0xddbc('0x5d')][_0xddbc('0x51')]({'where':{'id':_0x40c563[_0xddbc('0x5e')]}});}return null;})['then'](handleEntityNotFound(_0x401fdf,null))['then'](function(_0x2a7d94){if(_0x2a7d94){_0x25ab0c[_0xddbc('0x60')]=_0x2a7d94[_0xddbc('0x7a')]({'plain':!![]});interaction_log[_0xddbc('0x1d')](_0xddbc('0x7b'),_0x3284db[_0xddbc('0x5c')]['id'],_0x3284db['user']['name'],_0x3284db[_0xddbc('0x5c')][_0xddbc('0x7c')],_0x25ab0c[_0xddbc('0x60')]['id'],_0x3284db[_0xddbc('0x53')]?JSON[_0xddbc('0x62')](_0x3284db[_0xddbc('0x53')]):_0xddbc('0x63'));return respondWithRpcPromise('RejectMessage',_0xddbc('0x7d'),_0x25ab0c);}return null;})[_0xddbc('0x1c')](function(_0x2b6a6e){var _0x3cc190=_0xddbc('0x66')+_0x2b6a6e['message'][_0xddbc('0x7e')];return db[_0xddbc('0x7f')]['query'](_0x3cc190,{'type':db[_0xddbc('0x67')]['QueryTypes'][_0xddbc('0x69')],'raw':!![]})[_0xddbc('0x1c')](function(_0x5f36d0){return _0x5f36d0;});})[_0xddbc('0x1c')](function(_0x169bee){if(_0x169bee){_0x25ab0c[_0xddbc('0x23')][_0xddbc('0x80')]=_0x169bee[0x0];if(!_0x3284db[_0xddbc('0x53')][_0xddbc('0x5b')])return;return db['User'][_0xddbc('0x51')]({'where':{'id':_0x3284db[_0xddbc('0x53')][_0xddbc('0x5b')],'role':'agent'},'attributes':['id',_0xddbc('0x34'),'fullname',_0xddbc('0x81'),'internal'],'raw':!![]});}return null;})['then'](function(_0xb57952){if(!_0xb57952)return null;_0x25ab0c['message'][_0xddbc('0x6b')]=_0xb57952;return _0x25ab0c;})[_0xddbc('0x1c')](function(_0x2c8e76){if(_0x2c8e76){_0x2c8e76[_0xddbc('0x23')][_0xddbc('0x6f')]=util[_0xddbc('0x59')]('SIP/%s',_0x3284db[_0xddbc('0x5c')]['name']);_0x2c8e76['message'][_0xddbc('0x72')]=_0x25ab0c[_0xddbc('0x72')];_0x2c8e76[_0xddbc('0x23')][_0xddbc('0x71')]=_0x25ab0c['channel'];_0x2c8e76['message'][_0xddbc('0x73')]=_0xddbc('0x79');respondWithRpcPromise('EventManager','EventManager',{'event':'rejectmessage','message':_['merge'](_0x25ab0c[_0xddbc('0x23')],JSON[_0xddbc('0x76')](_0x25ab0c[_0xddbc('0x60')][_0xddbc('0x77')]))},client9002);return _0x25ab0c;}return null;})[_0xddbc('0x1c')](respondWithResult(_0x401fdf,null))[_0xddbc('0x25')](handleError(_0x401fdf,null));};
\ No newline at end of file
+var _0x4ed6=['sequelize','QueryTypes','SELECT','contact','fullname','interface','format','channel','EventManager','rejectmessage','parse','formData','util','lodash','ioredis','../../components/interaction/service','../../components/parsers/qs','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./chatMessage.socket','register','jayson/promise','client','http','then','info','ChatMessage,\x20%s,\x20%s','debug','ChatMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','request\x20sent','result','catch','status','json','offset','undefined','count','Content-Range','destroy','end','sendStatus','stack','name','send','index','map','ChatMessage','fieldName','key','model','keys','query','intersection','fields','attributes','length','hasOwnProperty','nolimit','limit','sort','where','pick','filters','filter','merge','type','VIRTUAL','options','includeAll','include','findAll','params','rawAttributes','create','update','body','find','describe','accept','chat','acceptMessage','reject','UserId','user','agent','get','ChatInteractionId','interaction','[CHATMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','null','RejectMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'];(function(_0x516132,_0x8ad071){var _0x10b198=function(_0x41dcd9){while(--_0x41dcd9){_0x516132['push'](_0x516132['shift']());}};_0x10b198(++_0x8ad071);}(_0x4ed6,0xd8));var _0x64ed=function(_0x4f832f,_0x511dff){_0x4f832f=_0x4f832f-0x0;var _0x1c68f9=_0x4ed6[_0x4f832f];return _0x1c68f9;};'use strict';var util=require(_0x64ed('0x0'));var _=require(_0x64ed('0x1'));var Redis=require(_0x64ed('0x2'));var interactionService=require(_0x64ed('0x3'));var qs=require(_0x64ed('0x4'));var logger=require(_0x64ed('0x5'))(_0x64ed('0x6'));var config=require(_0x64ed('0x7'));var db=require(_0x64ed('0x8'))['db'];config[_0x64ed('0x9')]=_[_0x64ed('0xa')](config[_0x64ed('0x9')],{'host':_0x64ed('0xb'),'port':0x18eb});var socket=require(_0x64ed('0xc'))(new Redis(config[_0x64ed('0x9')]));require(_0x64ed('0xd'))[_0x64ed('0xe')](socket);var jayson=require(_0x64ed('0xf'));var client=jayson[_0x64ed('0x10')][_0x64ed('0x11')]({'port':0x232c});var client9002=jayson[_0x64ed('0x10')][_0x64ed('0x11')]({'port':0x232a});var interaction_log=require(_0x64ed('0x5'))('chat-interactions');function respondWithRpcPromise(_0x4d372b,_0x5cc453,_0x439eb4,_0x1cce0c){return new Promise(function(_0x3ae23b,_0x452622){var _0xae883b=_0x1cce0c||client;return _0xae883b['request'](_0x4d372b,_0x439eb4)[_0x64ed('0x12')](function(_0x398e61){logger[_0x64ed('0x13')](_0x64ed('0x14'),_0x5cc453,'request\x20sent');logger[_0x64ed('0x15')](_0x64ed('0x16'),_0x5cc453,'request\x20sent',JSON[_0x64ed('0x17')](_0x398e61));if(_0x398e61[_0x64ed('0x18')]){if(_0x398e61['error'][_0x64ed('0x19')]===0x1f4){logger[_0x64ed('0x18')](_0x64ed('0x14'),_0x5cc453,_0x398e61[_0x64ed('0x18')]['message']);return _0x452622(_0x398e61[_0x64ed('0x18')][_0x64ed('0x1a')]);}logger[_0x64ed('0x18')]('ChatMessage,\x20%s,\x20%s',_0x5cc453,_0x398e61[_0x64ed('0x18')][_0x64ed('0x1a')]);return _0x3ae23b(_0x398e61[_0x64ed('0x18')]['message']);}else{logger[_0x64ed('0x13')]('ChatMessage,\x20%s,\x20%s',_0x5cc453,_0x64ed('0x1b'));_0x3ae23b(_0x398e61[_0x64ed('0x1c')][_0x64ed('0x1a')]);}})[_0x64ed('0x1d')](function(_0x5ab531){logger[_0x64ed('0x18')](_0x64ed('0x14'),_0x5cc453,_0x5ab531);_0x452622(_0x5ab531);});});}function respondWithResult(_0x3baeb4,_0x41a02b){_0x41a02b=_0x41a02b||0xc8;return function(_0xa8eac6){if(_0xa8eac6){return _0x3baeb4[_0x64ed('0x1e')](_0x41a02b)[_0x64ed('0x1f')](_0xa8eac6);}};}function respondWithFilteredResult(_0x83d90a,_0x3cd3df){return function(_0xb115c){if(_0xb115c){var _0x1ecd32=typeof _0x3cd3df[_0x64ed('0x20')]===_0x64ed('0x21')&&typeof _0x3cd3df['limit']===_0x64ed('0x21');var _0x55f942=_0xb115c[_0x64ed('0x22')];var _0x35757e=_0x1ecd32?0x0:_0x3cd3df[_0x64ed('0x20')];var _0x542c47=_0x1ecd32?_0xb115c[_0x64ed('0x22')]:_0x3cd3df[_0x64ed('0x20')]+_0x3cd3df['limit'];var _0x382367;if(_0x542c47>=_0x55f942){_0x542c47=_0x55f942;_0x382367=0xc8;}else{_0x382367=0xce;}_0x83d90a[_0x64ed('0x1e')](_0x382367);return _0x83d90a['set'](_0x64ed('0x23'),_0x35757e+'-'+_0x542c47+'/'+_0x55f942)['json'](_0xb115c);}return null;};}function saveUpdates(_0x47e54f){return function(_0x2bc47a){if(_0x2bc47a){return _0x2bc47a['update'](_0x47e54f)[_0x64ed('0x12')](function(_0x255185){return _0x255185;});}return null;};}function removeEntity(_0x19a680){return function(_0x42e91f){if(_0x42e91f){return _0x42e91f[_0x64ed('0x24')]()['then'](function(){_0x19a680[_0x64ed('0x1e')](0xcc)[_0x64ed('0x25')]();});}};}function handleEntityNotFound(_0x323b98){return function(_0x3e805c){if(!_0x3e805c){_0x323b98[_0x64ed('0x26')](0x194);}return _0x3e805c;};}function handleError(_0x31fe89,_0x22a268){_0x22a268=_0x22a268||0x1f4;return function(_0x54f712){logger[_0x64ed('0x18')](_0x54f712[_0x64ed('0x27')]);if(_0x54f712['name']){delete _0x54f712[_0x64ed('0x28')];}_0x31fe89[_0x64ed('0x1e')](_0x22a268)[_0x64ed('0x29')](_0x54f712);};}exports[_0x64ed('0x2a')]=function(_0x2af688,_0x184729){var _0x33ee9e={},_0x1aa4bc={},_0x210980={'count':0x0,'rows':[]};var _0x2d2c86=_[_0x64ed('0x2b')](db[_0x64ed('0x2c')]['rawAttributes'],function(_0x2b050f){return{'name':_0x2b050f[_0x64ed('0x2d')],'type':_0x2b050f['type'][_0x64ed('0x2e')]};});_0x1aa4bc[_0x64ed('0x2f')]=_['map'](_0x2d2c86,_0x64ed('0x28'));_0x1aa4bc['query']=_[_0x64ed('0x30')](_0x2af688[_0x64ed('0x31')]);_0x1aa4bc['filters']=_[_0x64ed('0x32')](_0x1aa4bc['model'],_0x1aa4bc[_0x64ed('0x31')]);_0x33ee9e['attributes']=_[_0x64ed('0x32')](_0x1aa4bc[_0x64ed('0x2f')],qs[_0x64ed('0x33')](_0x2af688['query']['fields']));_0x33ee9e['attributes']=_0x33ee9e[_0x64ed('0x34')][_0x64ed('0x35')]?_0x33ee9e[_0x64ed('0x34')]:_0x1aa4bc[_0x64ed('0x2f')];if(!_0x2af688[_0x64ed('0x31')][_0x64ed('0x36')](_0x64ed('0x37'))){_0x33ee9e['limit']=qs['limit'](_0x2af688[_0x64ed('0x31')][_0x64ed('0x38')]);_0x33ee9e[_0x64ed('0x20')]=qs[_0x64ed('0x20')](_0x2af688[_0x64ed('0x31')][_0x64ed('0x20')]);}_0x33ee9e['order']=qs[_0x64ed('0x39')](_0x2af688['query'][_0x64ed('0x39')]);_0x33ee9e[_0x64ed('0x3a')]=qs['filters'](_[_0x64ed('0x3b')](_0x2af688['query'],_0x1aa4bc[_0x64ed('0x3c')]),_0x2d2c86);if(_0x2af688[_0x64ed('0x31')][_0x64ed('0x3d')]){_0x33ee9e[_0x64ed('0x3a')]=_[_0x64ed('0x3e')](_0x33ee9e[_0x64ed('0x3a')],{'$or':_[_0x64ed('0x2b')](_0x2d2c86,function(_0x5187fd){if(_0x5187fd[_0x64ed('0x3f')]!==_0x64ed('0x40')){var _0x3b6334={};_0x3b6334[_0x5187fd[_0x64ed('0x28')]]={'$like':'%'+_0x2af688[_0x64ed('0x31')][_0x64ed('0x3d')]+'%'};return _0x3b6334;}})});}_0x33ee9e=_[_0x64ed('0x3e')]({},_0x33ee9e,_0x2af688[_0x64ed('0x41')]);var _0x2251e1={'where':_0x33ee9e[_0x64ed('0x3a')]};return db[_0x64ed('0x2c')][_0x64ed('0x22')](_0x2251e1)[_0x64ed('0x12')](function(_0x4e9f0d){_0x210980[_0x64ed('0x22')]=_0x4e9f0d;if(_0x2af688[_0x64ed('0x31')][_0x64ed('0x42')]){_0x33ee9e[_0x64ed('0x43')]=[{'all':!![]}];}return db['ChatMessage'][_0x64ed('0x44')](_0x33ee9e);})['then'](function(_0x2d51e5){_0x210980['rows']=_0x2d51e5;return _0x210980;})[_0x64ed('0x12')](respondWithFilteredResult(_0x184729,_0x33ee9e))[_0x64ed('0x1d')](handleError(_0x184729,null));};exports['show']=function(_0x288d95,_0x3e7fc8){var _0x541395={'raw':!![],'where':{'id':_0x288d95[_0x64ed('0x45')]['id']}},_0x203410={};_0x203410[_0x64ed('0x2f')]=_[_0x64ed('0x30')](db[_0x64ed('0x2c')][_0x64ed('0x46')]);_0x203410[_0x64ed('0x31')]=_[_0x64ed('0x30')](_0x288d95['query']);_0x203410['filters']=_[_0x64ed('0x32')](_0x203410['model'],_0x203410['query']);_0x541395[_0x64ed('0x34')]=_[_0x64ed('0x32')](_0x203410[_0x64ed('0x2f')],qs[_0x64ed('0x33')](_0x288d95[_0x64ed('0x31')][_0x64ed('0x33')]));_0x541395[_0x64ed('0x34')]=_0x541395[_0x64ed('0x34')]['length']?_0x541395[_0x64ed('0x34')]:_0x203410[_0x64ed('0x2f')];if(_0x288d95[_0x64ed('0x31')][_0x64ed('0x42')]){_0x541395[_0x64ed('0x43')]=[{'all':!![]}];}_0x541395=_['merge']({},_0x541395,_0x288d95[_0x64ed('0x41')]);return db['ChatMessage']['find'](_0x541395)[_0x64ed('0x12')](handleEntityNotFound(_0x3e7fc8,null))['then'](respondWithResult(_0x3e7fc8,null))[_0x64ed('0x1d')](handleError(_0x3e7fc8,null));};exports[_0x64ed('0x47')]=function(_0x570fe8,_0x5dea8a){return db[_0x64ed('0x2c')][_0x64ed('0x47')](_0x570fe8['body'],{})[_0x64ed('0x12')](respondWithResult(_0x5dea8a,0xc9))[_0x64ed('0x1d')](handleError(_0x5dea8a,null));};exports[_0x64ed('0x48')]=function(_0x5ac811,_0x2d8e07){if(_0x5ac811[_0x64ed('0x49')]['id']){delete _0x5ac811['body']['id'];}return db[_0x64ed('0x2c')][_0x64ed('0x4a')]({'where':{'id':_0x5ac811[_0x64ed('0x45')]['id']}})['then'](handleEntityNotFound(_0x2d8e07,null))['then'](saveUpdates(_0x5ac811[_0x64ed('0x49')],null))[_0x64ed('0x12')](respondWithResult(_0x2d8e07,null))[_0x64ed('0x1d')](handleError(_0x2d8e07,null));};exports[_0x64ed('0x24')]=function(_0x34c4bb,_0x3c3734){return db[_0x64ed('0x2c')][_0x64ed('0x4a')]({'where':{'id':_0x34c4bb[_0x64ed('0x45')]['id']}})[_0x64ed('0x12')](handleEntityNotFound(_0x3c3734,null))[_0x64ed('0x12')](removeEntity(_0x3c3734,null))[_0x64ed('0x1d')](handleError(_0x3c3734,null));};exports[_0x64ed('0x4b')]=function(_0x201dc6,_0x2cfadf){return db['ChatMessage'][_0x64ed('0x4b')]()[_0x64ed('0x12')](respondWithResult(_0x2cfadf,null))[_0x64ed('0x1d')](handleError(_0x2cfadf,null));};exports[_0x64ed('0x4c')]=function(_0x13a3f3,_0x360ae8){var _0x31bfd9=_0x64ed('0x4d');return interactionService[_0x64ed('0x4e')](_0x13a3f3,_0x31bfd9)[_0x64ed('0x12')](respondWithResult(_0x360ae8,null))['catch'](handleError(_0x360ae8,null));};exports[_0x64ed('0x4f')]=function(_0x233f08,_0x2942c9){var _0x59027c={'agent':{},'channel':'chat'};if(_0x233f08['body']['id']){delete _0x233f08[_0x64ed('0x49')]['id'];}_0x233f08[_0x64ed('0x49')][_0x64ed('0x50')]=_0x233f08[_0x64ed('0x49')]['UserId']||_0x233f08[_0x64ed('0x51')]['id'];_0x59027c[_0x64ed('0x52')]['id']=_0x233f08[_0x64ed('0x49')]['UserId'];return db[_0x64ed('0x2c')][_0x64ed('0x4a')]({'where':{'id':_0x233f08[_0x64ed('0x45')]['id'],'UserId':null}})[_0x64ed('0x12')](handleEntityNotFound(_0x2942c9,null))['then'](function(_0x402373){if(_0x402373){_0x59027c[_0x64ed('0x1a')]=_0x402373[_0x64ed('0x53')]({'plain':!![]});return db['ChatInteraction'][_0x64ed('0x4a')]({'where':{'id':_0x402373[_0x64ed('0x54')]}});}return null;})[_0x64ed('0x12')](handleEntityNotFound(_0x2942c9,null))['then'](function(_0xf3ad1f){if(_0xf3ad1f){_0x59027c[_0x64ed('0x55')]=_0xf3ad1f[_0x64ed('0x53')]({'plain':!![]});interaction_log['info'](_0x64ed('0x56'),_0x233f08[_0x64ed('0x51')]['id'],_0x233f08['user']['name'],_0x233f08[_0x64ed('0x51')]['role'],_0x59027c[_0x64ed('0x55')]['id'],_0x233f08[_0x64ed('0x49')]?JSON[_0x64ed('0x17')](_0x233f08[_0x64ed('0x49')]):_0x64ed('0x57'));return respondWithRpcPromise(_0x64ed('0x58'),'rejectMessage',_0x59027c);}return null;})[_0x64ed('0x12')](function(_0x229f84){var _0x50ba98=_0x64ed('0x59')+_0x229f84[_0x64ed('0x1a')]['ContactId'];return db[_0x64ed('0x5a')]['query'](_0x50ba98,{'type':db['Sequelize'][_0x64ed('0x5b')][_0x64ed('0x5c')],'raw':!![]})['then'](function(_0x481189){return _0x481189;});})['then'](function(_0x51b91a){if(_0x51b91a){_0x59027c[_0x64ed('0x1a')][_0x64ed('0x5d')]=_0x51b91a[0x0];if(!_0x233f08[_0x64ed('0x49')][_0x64ed('0x50')])return;return db['User'][_0x64ed('0x4a')]({'where':{'id':_0x233f08[_0x64ed('0x49')][_0x64ed('0x50')],'role':_0x64ed('0x52')},'attributes':['id',_0x64ed('0x28'),_0x64ed('0x5e'),'email','internal'],'raw':!![]});}return null;})[_0x64ed('0x12')](function(_0x5e7b88){if(!_0x5e7b88)return null;_0x59027c[_0x64ed('0x1a')][_0x64ed('0x52')]=_0x5e7b88;return _0x59027c;})['then'](function(_0x38d0ca){if(_0x38d0ca){_0x38d0ca[_0x64ed('0x1a')][_0x64ed('0x5f')]=util[_0x64ed('0x60')]('SIP/%s',_0x233f08[_0x64ed('0x51')][_0x64ed('0x28')]);_0x38d0ca[_0x64ed('0x1a')]['channel']=_0x59027c[_0x64ed('0x61')];_0x38d0ca[_0x64ed('0x1a')]['motionChannel']=_0x59027c['channel'];_0x38d0ca[_0x64ed('0x1a')]['event']='reject';respondWithRpcPromise('EventManager',_0x64ed('0x62'),{'event':_0x64ed('0x63'),'message':_['merge'](_0x59027c[_0x64ed('0x1a')],JSON[_0x64ed('0x64')](_0x59027c[_0x64ed('0x55')][_0x64ed('0x65')]))},client9002);return _0x59027c;}return null;})[_0x64ed('0x12')](respondWithResult(_0x2942c9,null))[_0x64ed('0x1d')](handleError(_0x2942c9,null));};
\ No newline at end of file