ea8661b45ed12e551b4253ce7195332181ac8167
[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 _0xd86f=['[CHAT]\x20Error\x20closing\x20interactions','inspect','lodash','moment','ioredis','util','../../config/environment','../../mysqldb','schedule','defaults','redis','localhost','socket.io-emitter','Setting','find','chatTimeout','ChatInteraction','lastMsgAt','then','length','map','update','format','info','[CHAT]\x20Sending\x20updates\x20for\x20interactions:','join','emit','chatInteraction:update','error'];(function(_0x206a86,_0x99cc6e){var _0x24b9bb=function(_0x186257){while(--_0x186257){_0x206a86['push'](_0x206a86['shift']());}};_0x24b9bb(++_0x99cc6e);}(_0xd86f,0x17b));var _0xfd86=function(_0xfae23b,_0x2be4ba){_0xfae23b=_0xfae23b-0x0;var _0x200640=_0xd86f[_0xfae23b];return _0x200640;};'use strict';var _=require(_0xfd86('0x0'));var moment=require(_0xfd86('0x1'));var Redis=require(_0xfd86('0x2'));var util=require(_0xfd86('0x3'));var config=require(_0xfd86('0x4'));var db=require(_0xfd86('0x5'))['db'];var logger=require('../logger')(_0xfd86('0x6'));config['redis']=_[_0xfd86('0x7')](config[_0xfd86('0x8')],{'host':_0xfd86('0x9'),'port':0x18eb});var io=require(_0xfd86('0xa'))(new Redis(config['redis']));function closeInteractions(){var _0xceda9e=0x0;var _0x458fdc=[];return db[_0xfd86('0xb')][_0xfd86('0xc')]({'raw':!![],'attributes':['id',_0xfd86('0xd')],'where':{'id':0x1}})['then'](function(_0x4ec831){_0xceda9e=_0x4ec831[_0xfd86('0xd')];if(_0xceda9e){return db[_0xfd86('0xe')]['findAll']({'raw':!![],'attributes':['id',_0xfd86('0xf')],'where':{'closed':![],'lastMsgAt':{'$lt':moment()['subtract'](_0x4ec831[_0xfd86('0xd')],'minutes')}}});}else{return[];}})[_0xfd86('0x10')](function(_0x8a711a){if(_0x8a711a&&_0x8a711a[_0xfd86('0x11')]){_0x458fdc=_[_0xfd86('0x12')](_0x8a711a||[],'id');logger['info']('[CHAT]\x20Interactions\x20to\x20close:',_0x458fdc['join']());return db['ChatInteraction'][_0xfd86('0x13')]({'closeReason':'system','disposition':'timeout','closed':!![],'closedAt':moment()[_0xfd86('0x14')]('YYYY-MM-DD\x20HH:mm:ss')},{'where':{'id':_0x458fdc}});}})['then'](function(){if(_0x458fdc&&_0x458fdc['length']){logger[_0xfd86('0x15')](_0xfd86('0x16'),_0x458fdc[_0xfd86('0x17')]());for(var _0x4bb9f8=0x0;_0x4bb9f8<_0x458fdc['length'];_0x4bb9f8++){io[_0xfd86('0x18')](_0xfd86('0x19'),{'id':_0x458fdc[_0x4bb9f8],'closed':!![]});}}})['catch'](function(_0x1848f2){logger[_0xfd86('0x1a')](_0xfd86('0x1b'),_0x1848f2?util[_0xfd86('0x1c')](_0x1848f2,{'showHidden':![],'depth':null}):'');});}exports['start']=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};