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