e84ac875c1da46e7c6d7a1d2efc79803ee7db6eb
[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 _0x10bb=['lastMsgAt','subtract','then','length','map','[CHAT]\x20Interactions\x20to\x20close:','join','update','system','format','[CHAT]\x20Sending\x20updates\x20for\x20interactions:','chatInteraction:update','catch','error','[CHAT]\x20Error\x20closing\x20interactions','inspect','lodash','ioredis','util','../../config/environment','../../mysqldb','schedule','redis','defaults','localhost','socket.io-emitter','Setting','find','chatTimeout','ChatInteraction'];(function(_0x303fae,_0x5eb2ce){var _0x449405=function(_0x4dccb8){while(--_0x4dccb8){_0x303fae['push'](_0x303fae['shift']());}};_0x449405(++_0x5eb2ce);}(_0x10bb,0xe2));var _0xb10b=function(_0x712a7e,_0x1814e2){_0x712a7e=_0x712a7e-0x0;var _0x1fa17f=_0x10bb[_0x712a7e];return _0x1fa17f;};'use strict';var _=require(_0xb10b('0x0'));var moment=require('moment');var Redis=require(_0xb10b('0x1'));var util=require(_0xb10b('0x2'));var config=require(_0xb10b('0x3'));var db=require(_0xb10b('0x4'))['db'];var logger=require('../logger')(_0xb10b('0x5'));config[_0xb10b('0x6')]=_[_0xb10b('0x7')](config[_0xb10b('0x6')],{'host':_0xb10b('0x8'),'port':0x18eb});var io=require(_0xb10b('0x9'))(new Redis(config[_0xb10b('0x6')]));function closeInteractions(){var _0x27b48f=0x0;var _0x13a1f3=[];return db[_0xb10b('0xa')][_0xb10b('0xb')]({'raw':!![],'attributes':['id',_0xb10b('0xc')],'where':{'id':0x1}})['then'](function(_0x3ae881){_0x27b48f=_0x3ae881[_0xb10b('0xc')];if(_0x27b48f){return db[_0xb10b('0xd')]['findAll']({'raw':!![],'attributes':['id',_0xb10b('0xe')],'where':{'closed':![],'lastMsgAt':{'$lt':moment()[_0xb10b('0xf')](_0x3ae881['chatTimeout'],'minutes')}}});}else{return[];}})[_0xb10b('0x10')](function(_0x589448){if(_0x589448&&_0x589448[_0xb10b('0x11')]){_0x13a1f3=_[_0xb10b('0x12')](_0x589448||[],'id');logger['info'](_0xb10b('0x13'),_0x13a1f3[_0xb10b('0x14')]());return db[_0xb10b('0xd')][_0xb10b('0x15')]({'closeReason':_0xb10b('0x16'),'disposition':'timeout','closed':!![],'closedAt':moment()[_0xb10b('0x17')]('YYYY-MM-DD\x20HH:mm:ss')},{'where':{'id':_0x13a1f3}});}})[_0xb10b('0x10')](function(){if(_0x13a1f3&&_0x13a1f3['length']){logger['info'](_0xb10b('0x18'),_0x13a1f3[_0xb10b('0x14')]());for(var _0x49b634=0x0;_0x49b634<_0x13a1f3[_0xb10b('0x11')];_0x49b634++){io['emit'](_0xb10b('0x19'),{'id':_0x13a1f3[_0x49b634],'closed':!![]});}}})[_0xb10b('0x1a')](function(_0x3c4858){logger[_0xb10b('0x1b')](_0xb10b('0x1c'),_0x3c4858?util[_0xb10b('0x1d')](_0x3c4858,{'showHidden':![],'depth':null}):'');});}exports['start']=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};