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