d2e3fd31c2148877b6214040f04541bc404fcc15
[motion2.git] / server / config / schedule / chat.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xc5dd=['start','lodash','moment','ioredis','util','../../config/environment','../logger','defaults','redis','localhost','socket.io-emitter','Setting','then','chatTimeout','ChatInteraction','lastMsgAt','subtract','length','map','info','[CHAT]\x20Interactions\x20to\x20close:','update','system','timeout','[CHAT]\x20Sending\x20updates\x20for\x20interactions:','join','emit','chatInteraction:update','catch','error','inspect'];(function(_0x3145af,_0x53a1d5){var _0x37758a=function(_0x4b1627){while(--_0x4b1627){_0x3145af['push'](_0x3145af['shift']());}};_0x37758a(++_0x53a1d5);}(_0xc5dd,0x194));var _0xdc5d=function(_0x6ca5bf,_0x12a8a8){_0x6ca5bf=_0x6ca5bf-0x0;var _0x47afb2=_0xc5dd[_0x6ca5bf];return _0x47afb2;};'use strict';var _=require(_0xdc5d('0x0'));var moment=require(_0xdc5d('0x1'));var Redis=require(_0xdc5d('0x2'));var util=require(_0xdc5d('0x3'));var config=require(_0xdc5d('0x4'));var db=require('../../mysqldb')['db'];var logger=require(_0xdc5d('0x5'))('schedule');config['redis']=_[_0xdc5d('0x6')](config[_0xdc5d('0x7')],{'host':_0xdc5d('0x8'),'port':0x18eb});var io=require(_0xdc5d('0x9'))(new Redis(config[_0xdc5d('0x7')]));function closeInteractions(){var _0x35495f=0x0;var _0x7703c3=[];return db[_0xdc5d('0xa')]['find']({'raw':!![],'attributes':['id','chatTimeout'],'where':{'id':0x1}})[_0xdc5d('0xb')](function(_0x1800f9){_0x35495f=_0x1800f9[_0xdc5d('0xc')];if(_0x35495f){return db[_0xdc5d('0xd')]['findAll']({'raw':!![],'attributes':['id',_0xdc5d('0xe')],'where':{'closed':![],'lastMsgAt':{'$lt':moment()[_0xdc5d('0xf')](_0x1800f9[_0xdc5d('0xc')],'minutes')}}});}else{return[];}})[_0xdc5d('0xb')](function(_0x60555f){if(_0x60555f&&_0x60555f[_0xdc5d('0x10')]){_0x7703c3=_[_0xdc5d('0x11')](_0x60555f||[],'id');logger[_0xdc5d('0x12')](_0xdc5d('0x13'),_0x7703c3['join']());return db[_0xdc5d('0xd')][_0xdc5d('0x14')]({'closeReason':_0xdc5d('0x15'),'disposition':_0xdc5d('0x16'),'closed':!![],'closedAt':moment()['format']('YYYY-MM-DD\x20HH:mm:ss')},{'where':{'id':_0x7703c3}});}})['then'](function(){if(_0x7703c3&&_0x7703c3[_0xdc5d('0x10')]){logger[_0xdc5d('0x12')](_0xdc5d('0x17'),_0x7703c3[_0xdc5d('0x18')]());for(var _0x2f6e52=0x0;_0x2f6e52<_0x7703c3[_0xdc5d('0x10')];_0x2f6e52++){io[_0xdc5d('0x19')](_0xdc5d('0x1a'),{'id':_0x7703c3[_0x2f6e52],'closed':!![]});}}})[_0xdc5d('0x1b')](function(_0x2d3a09){logger[_0xdc5d('0x1c')]('[CHAT]\x20Error\x20closing\x20interactions',_0x2d3a09?util[_0xdc5d('0x1d')](_0x2d3a09,{'showHidden':![],'depth':null}):'');});}exports[_0xdc5d('0x1e')]=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};