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