Built motion from commit fa4c4286.|2.6.29
[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 _0xf286=['then','ChatInteraction','findAll','lastMsgAt','minutes','length','[CHAT]\x20Interactions\x20to\x20close:','join','update','system','format','[CHAT]\x20Sending\x20updates\x20for\x20interactions:','emit','error','lodash','ioredis','util','schedule','redis','defaults','localhost','Setting','find','chatTimeout'];(function(_0xd71efe,_0x415e07){var _0x191161=function(_0x2a9a9f){while(--_0x2a9a9f){_0xd71efe['push'](_0xd71efe['shift']());}};_0x191161(++_0x415e07);}(_0xf286,0x12e));var _0x6f28=function(_0x3cb6dc,_0x120dd3){_0x3cb6dc=_0x3cb6dc-0x0;var _0x47ec89=_0xf286[_0x3cb6dc];return _0x47ec89;};'use strict';var _=require(_0x6f28('0x0'));var moment=require('moment');var Redis=require(_0x6f28('0x1'));var util=require(_0x6f28('0x2'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];var logger=require('../logger')(_0x6f28('0x3'));config[_0x6f28('0x4')]=_[_0x6f28('0x5')](config['redis'],{'host':_0x6f28('0x6'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x6f28('0x4')]));function closeInteractions(){var _0x39d5ce=0x0;var _0x42a4d2=[];return db[_0x6f28('0x7')][_0x6f28('0x8')]({'raw':!![],'attributes':['id',_0x6f28('0x9')],'where':{'id':0x1}})[_0x6f28('0xa')](function(_0x15cb59){_0x39d5ce=_0x15cb59['chatTimeout'];if(_0x39d5ce){return db[_0x6f28('0xb')][_0x6f28('0xc')]({'raw':!![],'attributes':['id',_0x6f28('0xd')],'where':{'closed':![],'lastMsgAt':{'$lt':moment()['subtract'](_0x15cb59['chatTimeout'],_0x6f28('0xe'))}}});}else{return[];}})[_0x6f28('0xa')](function(_0x41af7a){if(_0x41af7a&&_0x41af7a[_0x6f28('0xf')]){_0x42a4d2=_['map'](_0x41af7a||[],'id');logger['info'](_0x6f28('0x10'),_0x42a4d2[_0x6f28('0x11')]());return db[_0x6f28('0xb')][_0x6f28('0x12')]({'closeReason':_0x6f28('0x13'),'disposition':'timeout','closed':!![],'closedAt':moment()[_0x6f28('0x14')]('YYYY-MM-DD\x20HH:mm:ss')},{'where':{'id':_0x42a4d2}});}})[_0x6f28('0xa')](function(){if(_0x42a4d2&&_0x42a4d2[_0x6f28('0xf')]){logger['info'](_0x6f28('0x15'),_0x42a4d2[_0x6f28('0x11')]());for(var _0x5e78aa=0x0;_0x5e78aa<_0x42a4d2[_0x6f28('0xf')];_0x5e78aa++){io[_0x6f28('0x16')]('chatInteraction:update',{'id':_0x42a4d2[_0x5e78aa],'closed':!![]});}}})['catch'](function(_0x34f399){logger[_0x6f28('0x17')]('[CHAT]\x20Error\x20closing\x20interactions',_0x34f399?util['inspect'](_0x34f399,{'showHidden':![],'depth':null}):'');});}exports['start']=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};