Built motion from commit 639a1a7f.|2.6.19
[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 _0x652a=['YYYY-MM-DD\x20HH:mm:ss','[CHAT]\x20Sending\x20updates\x20for\x20interactions:','emit','chatInteraction:update','inspect','start','lodash','ioredis','util','../../config/environment','schedule','redis','defaults','localhost','Setting','chatTimeout','ChatInteraction','then','length','map','info','join','update','format'];(function(_0x30f806,_0x3bd0d8){var _0xddbfc7=function(_0x1ed34f){while(--_0x1ed34f){_0x30f806['push'](_0x30f806['shift']());}};_0xddbfc7(++_0x3bd0d8);}(_0x652a,0x1b6));var _0xa652=function(_0x25d7f4,_0x25f79f){_0x25d7f4=_0x25d7f4-0x0;var _0x4112d8=_0x652a[_0x25d7f4];return _0x4112d8;};'use strict';var _=require(_0xa652('0x0'));var moment=require('moment');var Redis=require(_0xa652('0x1'));var util=require(_0xa652('0x2'));var config=require(_0xa652('0x3'));var db=require('../../mysqldb')['db'];var logger=require('../logger')(_0xa652('0x4'));config[_0xa652('0x5')]=_[_0xa652('0x6')](config[_0xa652('0x5')],{'host':_0xa652('0x7'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0xa652('0x5')]));function closeInteractions(){var _0x25e206=0x0;var _0xc0bfb8=[];return db[_0xa652('0x8')]['find']({'raw':!![],'attributes':['id',_0xa652('0x9')],'where':{'id':0x1}})['then'](function(_0x4f35dd){_0x25e206=_0x4f35dd[_0xa652('0x9')];if(_0x25e206){return db[_0xa652('0xa')]['findAll']({'raw':!![],'attributes':['id','lastMsgAt'],'where':{'closed':![],'lastMsgAt':{'$lt':moment()['subtract'](_0x4f35dd[_0xa652('0x9')],'minutes')}}});}else{return[];}})[_0xa652('0xb')](function(_0x3f0f88){if(_0x3f0f88&&_0x3f0f88[_0xa652('0xc')]){_0xc0bfb8=_[_0xa652('0xd')](_0x3f0f88||[],'id');logger[_0xa652('0xe')]('[CHAT]\x20Interactions\x20to\x20close:',_0xc0bfb8[_0xa652('0xf')]());return db[_0xa652('0xa')][_0xa652('0x10')]({'closeReason':'system','disposition':'timeout','closed':!![],'closedAt':moment()[_0xa652('0x11')](_0xa652('0x12'))},{'where':{'id':_0xc0bfb8}});}})[_0xa652('0xb')](function(){if(_0xc0bfb8&&_0xc0bfb8['length']){logger['info'](_0xa652('0x13'),_0xc0bfb8[_0xa652('0xf')]());for(var _0x578b23=0x0;_0x578b23<_0xc0bfb8[_0xa652('0xc')];_0x578b23++){io[_0xa652('0x14')](_0xa652('0x15'),{'id':_0xc0bfb8[_0x578b23],'closed':!![]});}}})['catch'](function(_0x1291ee){logger['error']('[CHAT]\x20Error\x20closing\x20interactions',_0x1291ee?util[_0xa652('0x16')](_0x1291ee,{'showHidden':![],'depth':null}):'');});}exports[_0xa652('0x17')]=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};