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