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