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