cbeaceac7ecd7a8ac4f6b7533931cd067b9c49b1
[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 _0x9e00=['chatTimeout','ChatInteraction','lastMsgAt','subtract','minutes','update','system','timeout','YYYY-MM-DD\x20HH:mm:ss','map','length','emit','chatInteraction:update','error','start','moment','../../config/environment','defaults','redis','Setting','then'];(function(_0x3b3200,_0xc9454c){var _0x3650c1=function(_0x2dc786){while(--_0x2dc786){_0x3b3200['push'](_0x3b3200['shift']());}};_0x3650c1(++_0xc9454c);}(_0x9e00,0x1c8));var _0x09e0=function(_0x1facfa,_0x1acf7d){_0x1facfa=_0x1facfa-0x0;var _0x9ec701=_0x9e00[_0x1facfa];return _0x9ec701;};'use strict';var _=require('lodash');var moment=require(_0x09e0('0x0'));var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var config=require(_0x09e0('0x1'));config['redis']=_[_0x09e0('0x2')](config[_0x09e0('0x3')],{'host':'localhost','port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x09e0('0x3')]));function closeInteractions(){var _0xc1aeb6=0x0;var _0x1660f4=[];return db[_0x09e0('0x4')]['find']({'raw':!![],'attributes':['id','chatTimeout'],'where':{'id':0x1}})[_0x09e0('0x5')](function(_0x59f912){_0xc1aeb6=_0x59f912[_0x09e0('0x6')];if(_0xc1aeb6){return db[_0x09e0('0x7')]['findAll']({'raw':!![],'attributes':['id',_0x09e0('0x8')],'where':{'closed':![],'lastMsgAt':{'$lt':moment()[_0x09e0('0x9')](_0x59f912[_0x09e0('0x6')],_0x09e0('0xa'))}}});}else{return[];}})['then'](function(_0x8d579e){_0x1660f4=_0x8d579e;if(_0xc1aeb6){return db[_0x09e0('0x7')][_0x09e0('0xb')]({'closeReason':_0x09e0('0xc'),'disposition':_0x09e0('0xd'),'closed':!![],'closedAt':moment()['format'](_0x09e0('0xe'))},{'where':{'id':_[_0x09e0('0xf')](_0x1660f4||[],'id')}});}})['then'](function(_0x1b5a5a){for(var _0x55ac5c=0x0;_0x55ac5c<_0x1660f4[_0x09e0('0x10')];_0x55ac5c++){io[_0x09e0('0x11')](_0x09e0('0x12'),{'id':_0x1660f4[_0x55ac5c]['id'],'closed':!![]});}})['catch'](function(_0x5b0855){console[_0x09e0('0x13')](_0x5b0855);});}exports[_0x09e0('0x14')]=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};