Built motion from commit 47436d59.|2.6.7
[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 _0xf564=['length','emit','chatInteraction:update','catch','[CHAT]\x20Error\x20closing\x20interactions','inspect','start','moment','ioredis','../../config/environment','../../mysqldb','schedule','defaults','localhost','socket.io-emitter','redis','Setting','find','then','chatTimeout','ChatInteraction','lastMsgAt','subtract','minutes','map','join','update','system','timeout','format','YYYY-MM-DD\x20HH:mm:ss','info','[CHAT]\x20Sending\x20updates\x20for\x20interactions:'];(function(_0x4d0d77,_0x5723de){var _0x56a9f4=function(_0x3dd5ab){while(--_0x3dd5ab){_0x4d0d77['push'](_0x4d0d77['shift']());}};_0x56a9f4(++_0x5723de);}(_0xf564,0x6a));var _0x4f56=function(_0xa3fadc,_0xd1e16){_0xa3fadc=_0xa3fadc-0x0;var _0x23ecb8=_0xf564[_0xa3fadc];return _0x23ecb8;};'use strict';var _=require('lodash');var moment=require(_0x4f56('0x0'));var Redis=require(_0x4f56('0x1'));var util=require('util');var config=require(_0x4f56('0x2'));var db=require(_0x4f56('0x3'))['db'];var logger=require('../logger')(_0x4f56('0x4'));config['redis']=_[_0x4f56('0x5')](config['redis'],{'host':_0x4f56('0x6'),'port':0x18eb});var io=require(_0x4f56('0x7'))(new Redis(config[_0x4f56('0x8')]));function closeInteractions(){var _0x48ae5c=0x0;var _0xdb3991=[];return db[_0x4f56('0x9')][_0x4f56('0xa')]({'raw':!![],'attributes':['id','chatTimeout'],'where':{'id':0x1}})[_0x4f56('0xb')](function(_0x1facf4){_0x48ae5c=_0x1facf4[_0x4f56('0xc')];if(_0x48ae5c){return db[_0x4f56('0xd')]['findAll']({'raw':!![],'attributes':['id',_0x4f56('0xe')],'where':{'closed':![],'lastMsgAt':{'$lt':moment()[_0x4f56('0xf')](_0x1facf4[_0x4f56('0xc')],_0x4f56('0x10'))}}});}else{return[];}})[_0x4f56('0xb')](function(_0x477603){if(_0x477603&&_0x477603['length']){_0xdb3991=_[_0x4f56('0x11')](_0x477603||[],'id');logger['info']('[CHAT]\x20Interactions\x20to\x20close:',_0xdb3991[_0x4f56('0x12')]());return db[_0x4f56('0xd')][_0x4f56('0x13')]({'closeReason':_0x4f56('0x14'),'disposition':_0x4f56('0x15'),'closed':!![],'closedAt':moment()[_0x4f56('0x16')](_0x4f56('0x17'))},{'where':{'id':_0xdb3991}});}})['then'](function(){if(_0xdb3991&&_0xdb3991['length']){logger[_0x4f56('0x18')](_0x4f56('0x19'),_0xdb3991[_0x4f56('0x12')]());for(var _0x21ebb7=0x0;_0x21ebb7<_0xdb3991[_0x4f56('0x1a')];_0x21ebb7++){io[_0x4f56('0x1b')](_0x4f56('0x1c'),{'id':_0xdb3991[_0x21ebb7],'closed':!![]});}}})[_0x4f56('0x1d')](function(_0x4d76f9){logger['error'](_0x4f56('0x1e'),_0x4d76f9?util[_0x4f56('0x1f')](_0x4d76f9,{'showHidden':![],'depth':null}):'');});}exports[_0x4f56('0x20')]=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};