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