Built motion from commit 1fa89557.|2.6.10
[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 _0x22a5=['join','length','start','lodash','ioredis','util','../../config/environment','schedule','redis','defaults','Setting','chatTimeout','then','ChatInteraction','findAll','subtract','minutes','map','info','[CHAT]\x20Interactions\x20to\x20close:','update','system','format','YYYY-MM-DD\x20HH:mm:ss','[CHAT]\x20Sending\x20updates\x20for\x20interactions:'];(function(_0x59ee6f,_0x450239){var _0x4c0979=function(_0x565e92){while(--_0x565e92){_0x59ee6f['push'](_0x59ee6f['shift']());}};_0x4c0979(++_0x450239);}(_0x22a5,0x148));var _0x522a=function(_0x44c911,_0x2cb94e){_0x44c911=_0x44c911-0x0;var _0x5e0516=_0x22a5[_0x44c911];return _0x5e0516;};'use strict';var _=require(_0x522a('0x0'));var moment=require('moment');var Redis=require(_0x522a('0x1'));var util=require(_0x522a('0x2'));var config=require(_0x522a('0x3'));var db=require('../../mysqldb')['db'];var logger=require('../logger')(_0x522a('0x4'));config[_0x522a('0x5')]=_[_0x522a('0x6')](config[_0x522a('0x5')],{'host':'localhost','port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x522a('0x5')]));function closeInteractions(){var _0x580440=0x0;var _0x1d248d=[];return db[_0x522a('0x7')]['find']({'raw':!![],'attributes':['id',_0x522a('0x8')],'where':{'id':0x1}})[_0x522a('0x9')](function(_0x2c99da){_0x580440=_0x2c99da[_0x522a('0x8')];if(_0x580440){return db[_0x522a('0xa')][_0x522a('0xb')]({'raw':!![],'attributes':['id','lastMsgAt'],'where':{'closed':![],'lastMsgAt':{'$lt':moment()[_0x522a('0xc')](_0x2c99da[_0x522a('0x8')],_0x522a('0xd'))}}});}else{return[];}})[_0x522a('0x9')](function(_0xacfcac){if(_0xacfcac&&_0xacfcac['length']){_0x1d248d=_[_0x522a('0xe')](_0xacfcac||[],'id');logger[_0x522a('0xf')](_0x522a('0x10'),_0x1d248d['join']());return db[_0x522a('0xa')][_0x522a('0x11')]({'closeReason':_0x522a('0x12'),'disposition':'timeout','closed':!![],'closedAt':moment()[_0x522a('0x13')](_0x522a('0x14'))},{'where':{'id':_0x1d248d}});}})[_0x522a('0x9')](function(){if(_0x1d248d&&_0x1d248d['length']){logger[_0x522a('0xf')](_0x522a('0x15'),_0x1d248d[_0x522a('0x16')]());for(var _0x84e23e=0x0;_0x84e23e<_0x1d248d[_0x522a('0x17')];_0x84e23e++){io['emit']('chatInteraction:update',{'id':_0x1d248d[_0x84e23e],'closed':!![]});}}})['catch'](function(_0x4d02fb){logger['error']('[CHAT]\x20Error\x20closing\x20interactions',_0x4d02fb?util['inspect'](_0x4d02fb,{'showHidden':![],'depth':null}):'');});}exports[_0x522a('0x18')]=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};