4ba8bb7d751065c4fd5685fa1f9d75fd185b8c92
[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 _0x517b=['chatTimeout','findAll','minutes','then','ChatInteraction','update','system','timeout','length','emit','error','start','lodash','moment','ioredis','../../mysqldb','../../config/environment','redis','defaults','localhost','socket.io-emitter','Setting'];(function(_0x492aca,_0xaeaee0){var _0x5c5c95=function(_0x3a204a){while(--_0x3a204a){_0x492aca['push'](_0x492aca['shift']());}};_0x5c5c95(++_0xaeaee0);}(_0x517b,0x198));var _0xb517=function(_0x146105,_0x8089e7){_0x146105=_0x146105-0x0;var _0x3be58b=_0x517b[_0x146105];return _0x3be58b;};'use strict';var _=require(_0xb517('0x0'));var moment=require(_0xb517('0x1'));var Redis=require(_0xb517('0x2'));var db=require(_0xb517('0x3'))['db'];var config=require(_0xb517('0x4'));config[_0xb517('0x5')]=_[_0xb517('0x6')](config['redis'],{'host':_0xb517('0x7'),'port':0x18eb});var io=require(_0xb517('0x8'))(new Redis(config[_0xb517('0x5')]));function closeInteractions(){var _0x17d1c4=0x0;var _0x4f5732=[];return db[_0xb517('0x9')]['find']({'raw':!![],'attributes':['id',_0xb517('0xa')],'where':{'id':0x1}})['then'](function(_0x5177bb){_0x17d1c4=_0x5177bb[_0xb517('0xa')];if(_0x17d1c4){return db['ChatInteraction'][_0xb517('0xb')]({'raw':!![],'attributes':['id','lastMsgAt'],'where':{'closed':![],'lastMsgAt':{'$lt':moment()['subtract'](_0x5177bb[_0xb517('0xa')],_0xb517('0xc'))}}});}else{return[];}})[_0xb517('0xd')](function(_0x224537){_0x4f5732=_0x224537;if(_0x17d1c4){return db[_0xb517('0xe')][_0xb517('0xf')]({'closeReason':_0xb517('0x10'),'disposition':_0xb517('0x11'),'closed':!![],'closedAt':moment()['format']('YYYY-MM-DD\x20HH:mm:ss')},{'where':{'id':_['map'](_0x4f5732||[],'id')}});}})['then'](function(_0x6d956d){for(var _0x47a04e=0x0;_0x47a04e<_0x4f5732[_0xb517('0x12')];_0x47a04e++){io[_0xb517('0x13')]('chatInteraction:update',{'id':_0x4f5732[_0x47a04e]['id'],'closed':!![]});}})['catch'](function(_0xdc8def){console[_0xb517('0x14')](_0xdc8def);});}exports[_0xb517('0x15')]=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};