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