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