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