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