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