Built motion from commit b0a9a629.|2.6.33
[motion2.git] / server / api / chatMessage / chatMessage.controller.js
index 8ee7af3..8bca6a4 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x0f49=['readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','CmContact','Contact','get','ChatInteraction','ChatInteractionId','read1stAt','interaction','AcceptMessage','acceptMessage','manual','interface','SIP/%s','user','channel','event','EventManager','acceptmessage','formData','chat-interactions','agent','[CHATMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','RejectMessage','rejectMessage','rejectmessage','html-pdf','eml-format','zip-dir','fast-json-patch','request-promise','moment','mustache','sox','squel','crypto','jsforce','desk.js','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','socket.io-emitter','./chatMessage.socket','jayson/promise','client','http','request','then','info','ChatMessage,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','result','message','catch','sendStatus','status','end','json','count','offset','limit','Content-Range','reject','save','update','destroy','name','send','ChatMessage','rawAttributes','fieldName','type','key','model','map','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','VIRTUAL','merge','options','findAll','show','params','keys','includeAll','include','create','body','find','describe','accept','chat','read'];(function(_0x383356,_0x33d2f5){var _0x32ee5a=function(_0x2741db){while(--_0x2741db){_0x383356['push'](_0x383356['shift']());}};_0x32ee5a(++_0x33d2f5);}(_0x0f49,0x97));var _0x90f4=function(_0x289a67,_0x1e5a3c){_0x289a67=_0x289a67-0x0;var _0x572b49=_0x0f49[_0x289a67];return _0x572b49;};'use strict';var pdf=require(_0x90f4('0x0'));var emlformat=require(_0x90f4('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x90f4('0x2'));var jsonpatch=require(_0x90f4('0x3'));var rp=require(_0x90f4('0x4'));var moment=require(_0x90f4('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x90f4('0x6'));var util=require('util');var path=require('path');var sox=require(_0x90f4('0x7'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0x90f4('0x8'));var crypto=require(_0x90f4('0x9'));var jsforce=require(_0x90f4('0xa'));var deskjs=require(_0x90f4('0xb'));var toCsv=require(_0x90f4('0xc'));var querystring=require('querystring');var Papa=require(_0x90f4('0xd'));var Redis=require(_0x90f4('0xe'));var authService=require(_0x90f4('0xf'));var qs=require(_0x90f4('0x10'));var as=require(_0x90f4('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x90f4('0x12'))(_0x90f4('0x13'));var utils=require(_0x90f4('0x14'));var config=require(_0x90f4('0x15'));var licenseUtil=require(_0x90f4('0x16'));var db=require(_0x90f4('0x17'))['db'];config[_0x90f4('0x18')]=_[_0x90f4('0x19')](config[_0x90f4('0x18')],{'host':'localhost','port':0x18eb});var socket=require(_0x90f4('0x1a'))(new Redis(config['redis']));require(_0x90f4('0x1b'))['register'](socket);var jayson=require(_0x90f4('0x1c'));var client=jayson[_0x90f4('0x1d')][_0x90f4('0x1e')]({'port':0x232c});var client9002=jayson[_0x90f4('0x1d')][_0x90f4('0x1e')]({'port':0x232a});function respondWithRpcPromise(_0x8aae3c,_0x1530ed,_0x140a1c,_0x121be1){return new BPromise(function(_0x40c073,_0x41e54d){var _0x102f71=_0x121be1||client;return _0x102f71[_0x90f4('0x1f')](_0x8aae3c,_0x140a1c)[_0x90f4('0x20')](function(_0x5be345){logger[_0x90f4('0x21')](_0x90f4('0x22'),_0x1530ed,_0x90f4('0x23'));logger[_0x90f4('0x24')]('ChatMessage,\x20%s,\x20%s,\x20%s',_0x1530ed,_0x90f4('0x23'),JSON[_0x90f4('0x25')](_0x5be345));if(_0x5be345[_0x90f4('0x26')]){if(_0x5be345[_0x90f4('0x26')][_0x90f4('0x27')]===0x1f4){logger[_0x90f4('0x26')](_0x90f4('0x22'),_0x1530ed,_0x5be345[_0x90f4('0x26')]['message']);return _0x41e54d(_0x5be345[_0x90f4('0x26')]['message']);}logger[_0x90f4('0x26')](_0x90f4('0x22'),_0x1530ed,_0x5be345[_0x90f4('0x26')]['message']);return _0x40c073(_0x5be345['error']['message']);}else{logger[_0x90f4('0x21')](_0x90f4('0x22'),_0x1530ed,'request\x20sent');_0x40c073(_0x5be345[_0x90f4('0x28')][_0x90f4('0x29')]);}})[_0x90f4('0x2a')](function(_0x1b82f2){logger['error'](_0x90f4('0x22'),_0x1530ed,_0x1b82f2);_0x41e54d(_0x1b82f2);});});}function respondWithStatusCode(_0xc46dec,_0x196a8e){_0x196a8e=_0x196a8e||0xcc;return function(_0x201ebe){if(_0x201ebe){return _0xc46dec[_0x90f4('0x2b')](_0x196a8e);}return _0xc46dec[_0x90f4('0x2c')](_0x196a8e)[_0x90f4('0x2d')]();};}function respondWithResult(_0x2c7533,_0x242d07){_0x242d07=_0x242d07||0xc8;return function(_0x59896c){if(_0x59896c){return _0x2c7533[_0x90f4('0x2c')](_0x242d07)[_0x90f4('0x2e')](_0x59896c);}};}function respondWithFilteredResult(_0x2c8bd1,_0x4f56ec){return function(_0x3dbdbd){if(_0x3dbdbd){var _0x370233=_0x3dbdbd[_0x90f4('0x2f')],_0x3ba5a2=_0x4f56ec['offset'],_0x257f13=_0x4f56ec[_0x90f4('0x30')]+_0x4f56ec[_0x90f4('0x31')],_0x3a245f;if(_0x257f13>=_0x370233){_0x257f13=_0x370233;_0x3a245f=0xc8;}else{_0x3a245f=0xce;}_0x2c8bd1[_0x90f4('0x2c')](_0x3a245f);return _0x2c8bd1['set'](_0x90f4('0x32'),_0x3ba5a2+'-'+_0x257f13+'/'+_0x370233)[_0x90f4('0x2e')](_0x3dbdbd);}return null;};}function patchUpdates(_0xfa655e){return function(_0x1714fd){try{jsonpatch['apply'](_0x1714fd,_0xfa655e,!![]);}catch(_0x37b12f){return BPromise[_0x90f4('0x33')](_0x37b12f);}return _0x1714fd[_0x90f4('0x34')]();};}function saveUpdates(_0x5f0678,_0x291fd9){return function(_0x707272){if(_0x707272){return _0x707272[_0x90f4('0x35')](_0x5f0678)[_0x90f4('0x20')](function(_0x435303){return _0x435303;});}return null;};}function removeEntity(_0x115335,_0x682b66){return function(_0xa6cf62){if(_0xa6cf62){return _0xa6cf62[_0x90f4('0x36')]()['then'](function(){_0x115335[_0x90f4('0x2c')](0xcc)[_0x90f4('0x2d')]();});}};}function handleEntityNotFound(_0x3162f4,_0x3324f2){return function(_0x3bee1b){if(!_0x3bee1b){_0x3162f4[_0x90f4('0x2b')](0x194);}return _0x3bee1b;};}function handleError(_0x4cb75e,_0x599811){_0x599811=_0x599811||0x1f4;return function(_0x28c384){logger[_0x90f4('0x26')](_0x28c384['stack']);if(_0x28c384[_0x90f4('0x37')]){delete _0x28c384[_0x90f4('0x37')];}_0x4cb75e[_0x90f4('0x2c')](_0x599811)[_0x90f4('0x38')](_0x28c384);};}exports['index']=function(_0x323a01,_0x51fd2e){var _0x3968b7={},_0x410695={},_0x13e65e={'count':0x0,'rows':[]};var _0x57d7db=_['map'](db[_0x90f4('0x39')][_0x90f4('0x3a')],function(_0x5cc82a){return{'name':_0x5cc82a[_0x90f4('0x3b')],'type':_0x5cc82a[_0x90f4('0x3c')][_0x90f4('0x3d')]};});_0x410695[_0x90f4('0x3e')]=_[_0x90f4('0x3f')](_0x57d7db,_0x90f4('0x37'));_0x410695['query']=_['keys'](_0x323a01[_0x90f4('0x40')]);_0x410695[_0x90f4('0x41')]=_[_0x90f4('0x42')](_0x410695[_0x90f4('0x3e')],_0x410695[_0x90f4('0x40')]);_0x3968b7[_0x90f4('0x43')]=_[_0x90f4('0x42')](_0x410695[_0x90f4('0x3e')],qs[_0x90f4('0x44')](_0x323a01[_0x90f4('0x40')][_0x90f4('0x44')]));_0x3968b7['attributes']=_0x3968b7[_0x90f4('0x43')][_0x90f4('0x45')]?_0x3968b7[_0x90f4('0x43')]:_0x410695['model'];if(!_0x323a01['query'][_0x90f4('0x46')](_0x90f4('0x47'))){_0x3968b7[_0x90f4('0x31')]=qs[_0x90f4('0x31')](_0x323a01[_0x90f4('0x40')][_0x90f4('0x31')]);_0x3968b7[_0x90f4('0x30')]=qs[_0x90f4('0x30')](_0x323a01[_0x90f4('0x40')]['offset']);}_0x3968b7[_0x90f4('0x48')]=qs[_0x90f4('0x49')](_0x323a01[_0x90f4('0x40')][_0x90f4('0x49')]);_0x3968b7[_0x90f4('0x4a')]=qs[_0x90f4('0x41')](_[_0x90f4('0x4b')](_0x323a01[_0x90f4('0x40')],_0x410695[_0x90f4('0x41')]),_0x57d7db);if(_0x323a01['query'][_0x90f4('0x4c')]){_0x3968b7[_0x90f4('0x4a')]=_['merge'](_0x3968b7[_0x90f4('0x4a')],{'$or':_[_0x90f4('0x3f')](_0x57d7db,function(_0x4593aa){if(_0x4593aa['type']!==_0x90f4('0x4d')){var _0x16d9c9={};_0x16d9c9[_0x4593aa['name']]={'$like':'%'+_0x323a01['query'][_0x90f4('0x4c')]+'%'};return _0x16d9c9;}})});}_0x3968b7=_[_0x90f4('0x4e')]({},_0x3968b7,_0x323a01[_0x90f4('0x4f')]);var _0x1452fd={'where':_0x3968b7['where']};return db['ChatMessage'][_0x90f4('0x2f')](_0x1452fd)[_0x90f4('0x20')](function(_0x5b75d9){_0x13e65e['count']=_0x5b75d9;if(_0x323a01[_0x90f4('0x40')]['includeAll']){_0x3968b7['include']=[{'all':!![]}];}return db[_0x90f4('0x39')][_0x90f4('0x50')](_0x3968b7);})['then'](function(_0x221ad2){_0x13e65e['rows']=_0x221ad2;return _0x13e65e;})['then'](respondWithFilteredResult(_0x51fd2e,_0x3968b7))[_0x90f4('0x2a')](handleError(_0x51fd2e,null));};exports[_0x90f4('0x51')]=function(_0x1cd853,_0x5f1cd5){var _0x44a169={'raw':!![],'where':{'id':_0x1cd853[_0x90f4('0x52')]['id']}},_0x2ce8e9={};_0x2ce8e9[_0x90f4('0x3e')]=_[_0x90f4('0x53')](db[_0x90f4('0x39')][_0x90f4('0x3a')]);_0x2ce8e9['query']=_['keys'](_0x1cd853[_0x90f4('0x40')]);_0x2ce8e9['filters']=_[_0x90f4('0x42')](_0x2ce8e9['model'],_0x2ce8e9[_0x90f4('0x40')]);_0x44a169[_0x90f4('0x43')]=_['intersection'](_0x2ce8e9[_0x90f4('0x3e')],qs[_0x90f4('0x44')](_0x1cd853[_0x90f4('0x40')][_0x90f4('0x44')]));_0x44a169[_0x90f4('0x43')]=_0x44a169['attributes'][_0x90f4('0x45')]?_0x44a169[_0x90f4('0x43')]:_0x2ce8e9[_0x90f4('0x3e')];if(_0x1cd853[_0x90f4('0x40')][_0x90f4('0x54')]){_0x44a169[_0x90f4('0x55')]=[{'all':!![]}];}_0x44a169=_[_0x90f4('0x4e')]({},_0x44a169,_0x1cd853[_0x90f4('0x4f')]);return db['ChatMessage']['find'](_0x44a169)['then'](handleEntityNotFound(_0x5f1cd5,null))['then'](respondWithResult(_0x5f1cd5,null))[_0x90f4('0x2a')](handleError(_0x5f1cd5,null));};exports[_0x90f4('0x56')]=function(_0x4d8089,_0x1984b2){return db[_0x90f4('0x39')]['create'](_0x4d8089[_0x90f4('0x57')],{})[_0x90f4('0x20')](respondWithResult(_0x1984b2,0xc9))[_0x90f4('0x2a')](handleError(_0x1984b2,null));};exports[_0x90f4('0x35')]=function(_0x469aee,_0x104448){if(_0x469aee[_0x90f4('0x57')]['id']){delete _0x469aee[_0x90f4('0x57')]['id'];}return db[_0x90f4('0x39')][_0x90f4('0x58')]({'where':{'id':_0x469aee['params']['id']}})[_0x90f4('0x20')](handleEntityNotFound(_0x104448,null))[_0x90f4('0x20')](saveUpdates(_0x469aee[_0x90f4('0x57')],null))[_0x90f4('0x20')](respondWithResult(_0x104448,null))[_0x90f4('0x2a')](handleError(_0x104448,null));};exports['destroy']=function(_0x1ee06d,_0x344568){return db[_0x90f4('0x39')][_0x90f4('0x58')]({'where':{'id':_0x1ee06d[_0x90f4('0x52')]['id']}})[_0x90f4('0x20')](handleEntityNotFound(_0x344568,null))['then'](removeEntity(_0x344568,null))['catch'](handleError(_0x344568,null));};exports[_0x90f4('0x59')]=function(_0x10351a,_0xb72575){return db[_0x90f4('0x39')][_0x90f4('0x59')]()['then'](respondWithResult(_0xb72575,null))[_0x90f4('0x2a')](handleError(_0xb72575,null));};var interaction_log=require(_0x90f4('0x12'))('chat-interactions');exports[_0x90f4('0x5a')]=function(_0x19baa8,_0x471cc3,_0x4e5c4d){var _0x84f7a6={'channel':_0x90f4('0x5b')};if(_0x19baa8[_0x90f4('0x57')]['id']){delete _0x19baa8['body']['id'];}_0x19baa8['body'][_0x90f4('0x5c')]=!![];_0x19baa8[_0x90f4('0x57')][_0x90f4('0x5d')]=moment()[_0x90f4('0x5e')](_0x90f4('0x5f'));_0x19baa8['body'][_0x90f4('0x60')]=_0x19baa8[_0x90f4('0x57')][_0x90f4('0x60')]||_0x19baa8['user']['id'];return db['ChatMessage'][_0x90f4('0x58')]({'where':{'id':_0x19baa8[_0x90f4('0x52')]['id'],'UserId':null},'include':[{'model':db[_0x90f4('0x61')],'as':_0x90f4('0x62')}]})[_0x90f4('0x20')](handleEntityNotFound(_0x471cc3,null))['then'](saveUpdates(_0x19baa8[_0x90f4('0x57')],null))[_0x90f4('0x20')](function(_0x188f3e){if(_0x188f3e){_0x84f7a6['message']=_0x188f3e[_0x90f4('0x63')]({'plain':!![]});return db[_0x90f4('0x64')][_0x90f4('0x58')]({'where':{'id':_0x188f3e[_0x90f4('0x65')]}});}return null;})[_0x90f4('0x20')](handleEntityNotFound(_0x471cc3,null))[_0x90f4('0x20')](function(_0x1cb8cb){if(_0x1cb8cb){return _0x1cb8cb[_0x90f4('0x35')]({'UserId':_0x19baa8[_0x90f4('0x57')][_0x90f4('0x60')],'read1stAt':_['isNil'](_0x1cb8cb[_0x90f4('0x66')])?moment()[_0x90f4('0x5e')](_0x90f4('0x5f')):undefined});}return null;})[_0x90f4('0x20')](function(_0x29e973){if(_0x29e973){_0x84f7a6['interaction']=_0x29e973[_0x90f4('0x63')]({'plain':!![]});interaction_log['info']('[CHATMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x19baa8['user']['id'],_0x19baa8['user'][_0x90f4('0x37')],_0x19baa8['user']['role'],_0x84f7a6[_0x90f4('0x67')]['id'],_0x19baa8[_0x90f4('0x57')]?JSON[_0x90f4('0x25')](_0x19baa8[_0x90f4('0x57')]):'null');return respondWithRpcPromise(_0x90f4('0x68'),_0x90f4('0x69'),_0x84f7a6);}return null;})['then'](function(_0x19df22){if(_0x19df22){if(_0x19baa8['body'][_0x90f4('0x6a')]){_0x84f7a6[_0x90f4('0x29')][_0x90f4('0x6b')]=util['format'](_0x90f4('0x6c'),_0x19baa8[_0x90f4('0x6d')][_0x90f4('0x37')]);_0x84f7a6[_0x90f4('0x29')][_0x90f4('0x6e')]=_0x84f7a6[_0x90f4('0x6e')];_0x84f7a6[_0x90f4('0x29')][_0x90f4('0x6f')]='accept';return respondWithRpcPromise(_0x90f4('0x70'),_0x90f4('0x70'),{'event':_0x90f4('0x71'),'message':_['merge'](_0x84f7a6[_0x90f4('0x29')],JSON['parse'](_0x84f7a6[_0x90f4('0x67')][_0x90f4('0x72')]))},client9002)[_0x90f4('0x20')](function(){return _0x84f7a6;});}return _0x84f7a6;}return null;})[_0x90f4('0x20')](respondWithResult(_0x471cc3,null))[_0x90f4('0x2a')](handleError(_0x471cc3,null));};var interaction_log=require(_0x90f4('0x12'))(_0x90f4('0x73'));exports[_0x90f4('0x33')]=function(_0x39e168,_0x3653fd,_0x298273){var _0x212475={'agent':{},'channel':_0x90f4('0x5b')};if(_0x39e168[_0x90f4('0x57')]['id']){delete _0x39e168[_0x90f4('0x57')]['id'];}_0x39e168['body'][_0x90f4('0x60')]=_0x39e168[_0x90f4('0x57')][_0x90f4('0x60')]||_0x39e168[_0x90f4('0x6d')]['id'];_0x212475[_0x90f4('0x74')]['id']=_0x39e168[_0x90f4('0x57')][_0x90f4('0x60')];return db[_0x90f4('0x39')]['find']({'where':{'id':_0x39e168[_0x90f4('0x52')]['id'],'UserId':null}})[_0x90f4('0x20')](handleEntityNotFound(_0x3653fd,null))[_0x90f4('0x20')](function(_0x2b0c2a){if(_0x2b0c2a){_0x212475['message']=_0x2b0c2a[_0x90f4('0x63')]({'plain':!![]});return db[_0x90f4('0x64')][_0x90f4('0x58')]({'where':{'id':_0x2b0c2a[_0x90f4('0x65')]}});}return null;})[_0x90f4('0x20')](handleEntityNotFound(_0x3653fd,null))[_0x90f4('0x20')](function(_0x30bd42){if(_0x30bd42){_0x212475[_0x90f4('0x67')]=_0x30bd42[_0x90f4('0x63')]({'plain':!![]});interaction_log[_0x90f4('0x21')](_0x90f4('0x75'),_0x39e168[_0x90f4('0x6d')]['id'],_0x39e168[_0x90f4('0x6d')][_0x90f4('0x37')],_0x39e168[_0x90f4('0x6d')][_0x90f4('0x76')],_0x212475[_0x90f4('0x67')]['id'],_0x39e168[_0x90f4('0x57')]?JSON[_0x90f4('0x25')](_0x39e168[_0x90f4('0x57')]):'null');return respondWithRpcPromise(_0x90f4('0x77'),_0x90f4('0x78'),_0x212475);}return null;})[_0x90f4('0x20')](function(_0x56bdee){if(_0x56bdee){_0x56bdee['message'][_0x90f4('0x6b')]=util[_0x90f4('0x5e')](_0x90f4('0x6c'),_0x39e168[_0x90f4('0x6d')][_0x90f4('0x37')]);_0x56bdee[_0x90f4('0x29')][_0x90f4('0x6e')]=_0x212475[_0x90f4('0x6e')];_0x56bdee[_0x90f4('0x29')][_0x90f4('0x6f')]=_0x90f4('0x33');respondWithRpcPromise(_0x90f4('0x70'),_0x90f4('0x70'),{'event':_0x90f4('0x79'),'message':_0x56bdee['message']},client9002);return _0x212475;}return null;})['then'](respondWithResult(_0x3653fd,null))[_0x90f4('0x2a')](handleError(_0x3653fd,null));};
\ No newline at end of file
+var _0x960a=['interface','SIP/%s','channel','event','EventManager','parse','formData','util','lodash','ioredis','../../components/interaction/service','../../config/environment','../../mysqldb','redis','defaults','localhost','jayson/promise','client','http','../../config/logger','chat-interactions','then','info','ChatMessage,\x20%s,\x20%s','request\x20sent','ChatMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','json','undefined','limit','count','offset','status','set','destroy','end','sendStatus','name','send','index','map','ChatMessage','rawAttributes','type','key','model','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','findAll','show','params','keys','find','create','body','update','describe','accept','chat','acceptMessage','reject','UserId','user','agent','ChatInteraction','ChatInteractionId','interaction','get','role','RejectMessage','rejectMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','QueryTypes','SELECT','contact','User','email'];(function(_0x5ebec4,_0x474731){var _0x3b9d3b=function(_0x3aa9da){while(--_0x3aa9da){_0x5ebec4['push'](_0x5ebec4['shift']());}};_0x3b9d3b(++_0x474731);}(_0x960a,0x18f));var _0xa960=function(_0x1b2aea,_0x1c51ff){_0x1b2aea=_0x1b2aea-0x0;var _0x2ff88c=_0x960a[_0x1b2aea];return _0x2ff88c;};'use strict';var util=require(_0xa960('0x0'));var _=require(_0xa960('0x1'));var Redis=require(_0xa960('0x2'));var interactionService=require(_0xa960('0x3'));var qs=require('../../components/parsers/qs');var logger=require('../../config/logger')('api');var config=require(_0xa960('0x4'));var db=require(_0xa960('0x5'))['db'];config[_0xa960('0x6')]=_[_0xa960('0x7')](config[_0xa960('0x6')],{'host':_0xa960('0x8'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require('./chatMessage.socket')['register'](socket);var jayson=require(_0xa960('0x9'));var client=jayson[_0xa960('0xa')][_0xa960('0xb')]({'port':0x232c});var client9002=jayson[_0xa960('0xa')][_0xa960('0xb')]({'port':0x232a});var interaction_log=require(_0xa960('0xc'))(_0xa960('0xd'));function respondWithRpcPromise(_0x5de2f6,_0x1b9980,_0x218d30,_0x18cb56){return new Promise(function(_0x3aeeae,_0xa6fc5f){var _0x36a988=_0x18cb56||client;return _0x36a988['request'](_0x5de2f6,_0x218d30)[_0xa960('0xe')](function(_0x4110dc){logger[_0xa960('0xf')](_0xa960('0x10'),_0x1b9980,_0xa960('0x11'));logger['debug'](_0xa960('0x12'),_0x1b9980,_0xa960('0x11'),JSON[_0xa960('0x13')](_0x4110dc));if(_0x4110dc[_0xa960('0x14')]){if(_0x4110dc[_0xa960('0x14')][_0xa960('0x15')]===0x1f4){logger[_0xa960('0x14')](_0xa960('0x10'),_0x1b9980,_0x4110dc[_0xa960('0x14')]['message']);return _0xa6fc5f(_0x4110dc[_0xa960('0x14')][_0xa960('0x16')]);}logger[_0xa960('0x14')]('ChatMessage,\x20%s,\x20%s',_0x1b9980,_0x4110dc['error'][_0xa960('0x16')]);return _0x3aeeae(_0x4110dc[_0xa960('0x14')][_0xa960('0x16')]);}else{logger[_0xa960('0xf')](_0xa960('0x10'),_0x1b9980,_0xa960('0x11'));_0x3aeeae(_0x4110dc['result'][_0xa960('0x16')]);}})[_0xa960('0x17')](function(_0x311c82){logger[_0xa960('0x14')](_0xa960('0x10'),_0x1b9980,_0x311c82);_0xa6fc5f(_0x311c82);});});}function respondWithResult(_0x307cf8,_0x5a408d){_0x5a408d=_0x5a408d||0xc8;return function(_0x1532a0){if(_0x1532a0){return _0x307cf8['status'](_0x5a408d)[_0xa960('0x18')](_0x1532a0);}};}function respondWithFilteredResult(_0x4ea051,_0x76ab41){return function(_0x57dfc4){if(_0x57dfc4){var _0x18d70a=typeof _0x76ab41['offset']===_0xa960('0x19')&&typeof _0x76ab41[_0xa960('0x1a')]===_0xa960('0x19');var _0x4b443a=_0x57dfc4[_0xa960('0x1b')];var _0xcdd616=_0x18d70a?0x0:_0x76ab41[_0xa960('0x1c')];var _0x458b27=_0x18d70a?_0x57dfc4[_0xa960('0x1b')]:_0x76ab41[_0xa960('0x1c')]+_0x76ab41[_0xa960('0x1a')];var _0x52e27d;if(_0x458b27>=_0x4b443a){_0x458b27=_0x4b443a;_0x52e27d=0xc8;}else{_0x52e27d=0xce;}_0x4ea051[_0xa960('0x1d')](_0x52e27d);return _0x4ea051[_0xa960('0x1e')]('Content-Range',_0xcdd616+'-'+_0x458b27+'/'+_0x4b443a)[_0xa960('0x18')](_0x57dfc4);}return null;};}function saveUpdates(_0x40b451){return function(_0x3e0647){if(_0x3e0647){return _0x3e0647['update'](_0x40b451)[_0xa960('0xe')](function(_0x2fb446){return _0x2fb446;});}return null;};}function removeEntity(_0x3ac980){return function(_0x2376d9){if(_0x2376d9){return _0x2376d9[_0xa960('0x1f')]()[_0xa960('0xe')](function(){_0x3ac980[_0xa960('0x1d')](0xcc)[_0xa960('0x20')]();});}};}function handleEntityNotFound(_0x14ce5d){return function(_0x4d6437){if(!_0x4d6437){_0x14ce5d[_0xa960('0x21')](0x194);}return _0x4d6437;};}function handleError(_0xd64cb9,_0x4aa39d){_0x4aa39d=_0x4aa39d||0x1f4;return function(_0x401af3){logger['error'](_0x401af3['stack']);if(_0x401af3[_0xa960('0x22')]){delete _0x401af3[_0xa960('0x22')];}_0xd64cb9['status'](_0x4aa39d)[_0xa960('0x23')](_0x401af3);};}exports[_0xa960('0x24')]=function(_0x36252c,_0x4e928d){var _0x47435f={},_0x5b066a={},_0x1c9e12={'count':0x0,'rows':[]};var _0x37467a=_[_0xa960('0x25')](db[_0xa960('0x26')][_0xa960('0x27')],function(_0x108be3){return{'name':_0x108be3['fieldName'],'type':_0x108be3[_0xa960('0x28')][_0xa960('0x29')]};});_0x5b066a[_0xa960('0x2a')]=_[_0xa960('0x25')](_0x37467a,_0xa960('0x22'));_0x5b066a[_0xa960('0x2b')]=_['keys'](_0x36252c[_0xa960('0x2b')]);_0x5b066a[_0xa960('0x2c')]=_[_0xa960('0x2d')](_0x5b066a['model'],_0x5b066a['query']);_0x47435f['attributes']=_[_0xa960('0x2d')](_0x5b066a[_0xa960('0x2a')],qs[_0xa960('0x2e')](_0x36252c[_0xa960('0x2b')][_0xa960('0x2e')]));_0x47435f[_0xa960('0x2f')]=_0x47435f[_0xa960('0x2f')][_0xa960('0x30')]?_0x47435f[_0xa960('0x2f')]:_0x5b066a[_0xa960('0x2a')];if(!_0x36252c['query'][_0xa960('0x31')](_0xa960('0x32'))){_0x47435f[_0xa960('0x1a')]=qs['limit'](_0x36252c['query']['limit']);_0x47435f[_0xa960('0x1c')]=qs['offset'](_0x36252c[_0xa960('0x2b')][_0xa960('0x1c')]);}_0x47435f[_0xa960('0x33')]=qs[_0xa960('0x34')](_0x36252c[_0xa960('0x2b')][_0xa960('0x34')]);_0x47435f[_0xa960('0x35')]=qs[_0xa960('0x2c')](_[_0xa960('0x36')](_0x36252c[_0xa960('0x2b')],_0x5b066a['filters']),_0x37467a);if(_0x36252c[_0xa960('0x2b')][_0xa960('0x37')]){_0x47435f['where']=_[_0xa960('0x38')](_0x47435f['where'],{'$or':_[_0xa960('0x25')](_0x37467a,function(_0x5b6c3f){if(_0x5b6c3f[_0xa960('0x28')]!==_0xa960('0x39')){var _0x21cddf={};_0x21cddf[_0x5b6c3f[_0xa960('0x22')]]={'$like':'%'+_0x36252c[_0xa960('0x2b')]['filter']+'%'};return _0x21cddf;}})});}_0x47435f=_['merge']({},_0x47435f,_0x36252c['options']);var _0x2473dc={'where':_0x47435f[_0xa960('0x35')]};return db['ChatMessage'][_0xa960('0x1b')](_0x2473dc)[_0xa960('0xe')](function(_0x540a9f){_0x1c9e12[_0xa960('0x1b')]=_0x540a9f;if(_0x36252c[_0xa960('0x2b')][_0xa960('0x3a')]){_0x47435f[_0xa960('0x3b')]=[{'all':!![]}];}return db['ChatMessage'][_0xa960('0x3c')](_0x47435f);})['then'](function(_0x26720e){_0x1c9e12['rows']=_0x26720e;return _0x1c9e12;})['then'](respondWithFilteredResult(_0x4e928d,_0x47435f))[_0xa960('0x17')](handleError(_0x4e928d,null));};exports[_0xa960('0x3d')]=function(_0x110c17,_0x2332fc){var _0x5f0d2d={'raw':!![],'where':{'id':_0x110c17[_0xa960('0x3e')]['id']}},_0x430c0b={};_0x430c0b['model']=_[_0xa960('0x3f')](db[_0xa960('0x26')]['rawAttributes']);_0x430c0b[_0xa960('0x2b')]=_['keys'](_0x110c17['query']);_0x430c0b[_0xa960('0x2c')]=_['intersection'](_0x430c0b[_0xa960('0x2a')],_0x430c0b[_0xa960('0x2b')]);_0x5f0d2d[_0xa960('0x2f')]=_[_0xa960('0x2d')](_0x430c0b[_0xa960('0x2a')],qs[_0xa960('0x2e')](_0x110c17['query'][_0xa960('0x2e')]));_0x5f0d2d[_0xa960('0x2f')]=_0x5f0d2d[_0xa960('0x2f')]['length']?_0x5f0d2d[_0xa960('0x2f')]:_0x430c0b[_0xa960('0x2a')];if(_0x110c17[_0xa960('0x2b')][_0xa960('0x3a')]){_0x5f0d2d[_0xa960('0x3b')]=[{'all':!![]}];}_0x5f0d2d=_[_0xa960('0x38')]({},_0x5f0d2d,_0x110c17['options']);return db[_0xa960('0x26')][_0xa960('0x40')](_0x5f0d2d)[_0xa960('0xe')](handleEntityNotFound(_0x2332fc,null))[_0xa960('0xe')](respondWithResult(_0x2332fc,null))[_0xa960('0x17')](handleError(_0x2332fc,null));};exports[_0xa960('0x41')]=function(_0x1dc2fa,_0x10f1c0){return db[_0xa960('0x26')][_0xa960('0x41')](_0x1dc2fa[_0xa960('0x42')],{})[_0xa960('0xe')](respondWithResult(_0x10f1c0,0xc9))[_0xa960('0x17')](handleError(_0x10f1c0,null));};exports[_0xa960('0x43')]=function(_0x5b6817,_0x280dcf){if(_0x5b6817[_0xa960('0x42')]['id']){delete _0x5b6817[_0xa960('0x42')]['id'];}return db[_0xa960('0x26')][_0xa960('0x40')]({'where':{'id':_0x5b6817[_0xa960('0x3e')]['id']}})[_0xa960('0xe')](handleEntityNotFound(_0x280dcf,null))[_0xa960('0xe')](saveUpdates(_0x5b6817[_0xa960('0x42')],null))['then'](respondWithResult(_0x280dcf,null))[_0xa960('0x17')](handleError(_0x280dcf,null));};exports[_0xa960('0x1f')]=function(_0x4a9d66,_0x12ad6f){return db[_0xa960('0x26')]['find']({'where':{'id':_0x4a9d66[_0xa960('0x3e')]['id']}})[_0xa960('0xe')](handleEntityNotFound(_0x12ad6f,null))[_0xa960('0xe')](removeEntity(_0x12ad6f,null))[_0xa960('0x17')](handleError(_0x12ad6f,null));};exports[_0xa960('0x44')]=function(_0x5f2ad1,_0x14f6e6){return db[_0xa960('0x26')]['describe']()['then'](respondWithResult(_0x14f6e6,null))[_0xa960('0x17')](handleError(_0x14f6e6,null));};exports[_0xa960('0x45')]=function(_0x4c1e6d,_0x30650f){var _0x5d87d8=_0xa960('0x46');return interactionService[_0xa960('0x47')](_0x4c1e6d,_0x5d87d8)[_0xa960('0xe')](respondWithResult(_0x30650f,null))[_0xa960('0x17')](handleError(_0x30650f,null));};exports[_0xa960('0x48')]=function(_0xdc17fa,_0x47f4e7){var _0x3fc48={'agent':{},'channel':_0xa960('0x46')};if(_0xdc17fa['body']['id']){delete _0xdc17fa[_0xa960('0x42')]['id'];}_0xdc17fa['body'][_0xa960('0x49')]=_0xdc17fa[_0xa960('0x42')][_0xa960('0x49')]||_0xdc17fa[_0xa960('0x4a')]['id'];_0x3fc48[_0xa960('0x4b')]['id']=_0xdc17fa[_0xa960('0x42')][_0xa960('0x49')];return db[_0xa960('0x26')][_0xa960('0x40')]({'where':{'id':_0xdc17fa[_0xa960('0x3e')]['id'],'UserId':null}})[_0xa960('0xe')](handleEntityNotFound(_0x47f4e7,null))[_0xa960('0xe')](function(_0x1224b4){if(_0x1224b4){_0x3fc48['message']=_0x1224b4['get']({'plain':!![]});return db[_0xa960('0x4c')][_0xa960('0x40')]({'where':{'id':_0x1224b4[_0xa960('0x4d')]}});}return null;})['then'](handleEntityNotFound(_0x47f4e7,null))[_0xa960('0xe')](function(_0x577b84){if(_0x577b84){_0x3fc48[_0xa960('0x4e')]=_0x577b84[_0xa960('0x4f')]({'plain':!![]});interaction_log[_0xa960('0xf')]('[CHATMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0xdc17fa['user']['id'],_0xdc17fa['user']['name'],_0xdc17fa[_0xa960('0x4a')][_0xa960('0x50')],_0x3fc48[_0xa960('0x4e')]['id'],_0xdc17fa[_0xa960('0x42')]?JSON[_0xa960('0x13')](_0xdc17fa[_0xa960('0x42')]):'null');return respondWithRpcPromise(_0xa960('0x51'),_0xa960('0x52'),_0x3fc48);}return null;})[_0xa960('0xe')](function(_0x2ac80d){var _0x3705e2=_0xa960('0x53')+_0x2ac80d[_0xa960('0x16')][_0xa960('0x54')];return db[_0xa960('0x55')][_0xa960('0x2b')](_0x3705e2,{'type':db['Sequelize'][_0xa960('0x56')][_0xa960('0x57')],'raw':!![]})[_0xa960('0xe')](function(_0x8ecc5){return _0x8ecc5;});})[_0xa960('0xe')](function(_0x495cb9){if(_0x495cb9){_0x3fc48[_0xa960('0x16')][_0xa960('0x58')]=_0x495cb9[0x0];if(!_0xdc17fa[_0xa960('0x42')][_0xa960('0x49')])return;return db[_0xa960('0x59')]['find']({'where':{'id':_0xdc17fa[_0xa960('0x42')][_0xa960('0x49')],'role':_0xa960('0x4b')},'attributes':['id',_0xa960('0x22'),'fullname',_0xa960('0x5a'),'internal'],'raw':!![]});}return null;})[_0xa960('0xe')](function(_0x9ede29){if(!_0x9ede29)return null;_0x3fc48[_0xa960('0x16')][_0xa960('0x4b')]=_0x9ede29;return _0x3fc48;})[_0xa960('0xe')](function(_0x514e4e){if(_0x514e4e){_0x514e4e['message'][_0xa960('0x5b')]=util['format'](_0xa960('0x5c'),_0xdc17fa[_0xa960('0x4a')][_0xa960('0x22')]);_0x514e4e[_0xa960('0x16')][_0xa960('0x5d')]=_0x3fc48['channel'];_0x514e4e['message']['motionChannel']=_0x3fc48['channel'];_0x514e4e[_0xa960('0x16')][_0xa960('0x5e')]='reject';respondWithRpcPromise(_0xa960('0x5f'),_0xa960('0x5f'),{'event':'rejectmessage','message':_[_0xa960('0x38')](_0x3fc48[_0xa960('0x16')],JSON[_0xa960('0x60')](_0x3fc48[_0xa960('0x4e')][_0xa960('0x61')]))},client9002);return _0x3fc48;}return null;})[_0xa960('0xe')](respondWithResult(_0x47f4e7,null))[_0xa960('0x17')](handleError(_0x47f4e7,null));};
\ No newline at end of file