Built motion from commit (unavailable).|2.6.0
[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 _0x9f6d=['info','[CHAT]\x20Sending\x20updates\x20for\x20interactions:','emit','chatInteraction:update','[CHAT]\x20Error\x20closing\x20interactions','inspect','start','lodash','moment','ioredis','util','../../mysqldb','../logger','schedule','redis','defaults','localhost','socket.io-emitter','find','chatTimeout','then','findAll','subtract','minutes','length','join','update','system','format'];(function(_0x2c1923,_0x5446e9){var _0x73c9b4=function(_0x1c0f5d){while(--_0x1c0f5d){_0x2c1923['push'](_0x2c1923['shift']());}};_0x73c9b4(++_0x5446e9);}(_0x9f6d,0x180));var _0xd9f6=function(_0x3ee0ca,_0x6c9851){_0x3ee0ca=_0x3ee0ca-0x0;var _0x65fd58=_0x9f6d[_0x3ee0ca];return _0x65fd58;};'use strict';var _=require(_0xd9f6('0x0'));var moment=require(_0xd9f6('0x1'));var Redis=require(_0xd9f6('0x2'));var util=require(_0xd9f6('0x3'));var config=require('../../config/environment');var db=require(_0xd9f6('0x4'))['db'];var logger=require(_0xd9f6('0x5'))(_0xd9f6('0x6'));config[_0xd9f6('0x7')]=_[_0xd9f6('0x8')](config[_0xd9f6('0x7')],{'host':_0xd9f6('0x9'),'port':0x18eb});var io=require(_0xd9f6('0xa'))(new Redis(config[_0xd9f6('0x7')]));function closeInteractions(){var _0x26f7e8=0x0;var _0x175ccb=[];return db['Setting'][_0xd9f6('0xb')]({'raw':!![],'attributes':['id',_0xd9f6('0xc')],'where':{'id':0x1}})[_0xd9f6('0xd')](function(_0x292d66){_0x26f7e8=_0x292d66[_0xd9f6('0xc')];if(_0x26f7e8){return db['ChatInteraction'][_0xd9f6('0xe')]({'raw':!![],'attributes':['id','lastMsgAt'],'where':{'closed':![],'lastMsgAt':{'$lt':moment()[_0xd9f6('0xf')](_0x292d66['chatTimeout'],_0xd9f6('0x10'))}}});}else{return[];}})[_0xd9f6('0xd')](function(_0x5b2a62){if(_0x5b2a62&&_0x5b2a62[_0xd9f6('0x11')]){_0x175ccb=_['map'](_0x5b2a62||[],'id');logger['info']('[CHAT]\x20Interactions\x20to\x20close:',_0x175ccb[_0xd9f6('0x12')]());return db['ChatInteraction'][_0xd9f6('0x13')]({'closeReason':_0xd9f6('0x14'),'disposition':'timeout','closed':!![],'closedAt':moment()[_0xd9f6('0x15')]('YYYY-MM-DD\x20HH:mm:ss')},{'where':{'id':_0x175ccb}});}})[_0xd9f6('0xd')](function(){if(_0x175ccb&&_0x175ccb['length']){logger[_0xd9f6('0x16')](_0xd9f6('0x17'),_0x175ccb[_0xd9f6('0x12')]());for(var _0x112cac=0x0;_0x112cac<_0x175ccb['length'];_0x112cac++){io[_0xd9f6('0x18')](_0xd9f6('0x19'),{'id':_0x175ccb[_0x112cac],'closed':!![]});}}})['catch'](function(_0x434d2c){logger['error'](_0xd9f6('0x1a'),_0x434d2c?util[_0xd9f6('0x1b')](_0x434d2c,{'showHidden':![],'depth':null}):'');});}exports[_0xd9f6('0x1c')]=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};