Built motion from commit (unavailable).|2.5.5
[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 _0x951c=['chatTimeout','then','lastMsgAt','subtract','minutes','ChatInteraction','update','system','YYYY-MM-DD\x20HH:mm:ss','map','length','chatInteraction:update','error','lodash','ioredis','../../mysqldb','../../config/environment','redis','localhost','socket.io-emitter','Setting','find'];(function(_0x58e469,_0x95ee3e){var _0x4c01c5=function(_0x1ef7ae){while(--_0x1ef7ae){_0x58e469['push'](_0x58e469['shift']());}};_0x4c01c5(++_0x95ee3e);}(_0x951c,0x115));var _0xc951=function(_0x3b96d8,_0x17e32e){_0x3b96d8=_0x3b96d8-0x0;var _0x37c4fa=_0x951c[_0x3b96d8];return _0x37c4fa;};'use strict';var _=require(_0xc951('0x0'));var moment=require('moment');var Redis=require(_0xc951('0x1'));var db=require(_0xc951('0x2'))['db'];var config=require(_0xc951('0x3'));config[_0xc951('0x4')]=_['defaults'](config[_0xc951('0x4')],{'host':_0xc951('0x5'),'port':0x18eb});var io=require(_0xc951('0x6'))(new Redis(config[_0xc951('0x4')]));function closeInteractions(){var _0x11b817=0x0;var _0x162de7=[];return db[_0xc951('0x7')][_0xc951('0x8')]({'raw':!![],'attributes':['id',_0xc951('0x9')],'where':{'id':0x1}})[_0xc951('0xa')](function(_0x34d669){_0x11b817=_0x34d669['chatTimeout'];if(_0x11b817){return db['ChatInteraction']['findAll']({'raw':!![],'attributes':['id',_0xc951('0xb')],'where':{'closed':![],'lastMsgAt':{'$lt':moment()[_0xc951('0xc')](_0x34d669[_0xc951('0x9')],_0xc951('0xd'))}}});}else{return[];}})[_0xc951('0xa')](function(_0xa35ca1){_0x162de7=_0xa35ca1;if(_0x11b817){return db[_0xc951('0xe')][_0xc951('0xf')]({'closeReason':_0xc951('0x10'),'disposition':'timeout','closed':!![],'closedAt':moment()['format'](_0xc951('0x11'))},{'where':{'id':_[_0xc951('0x12')](_0x162de7||[],'id')}});}})[_0xc951('0xa')](function(_0x5d288f){for(var _0x2e02dd=0x0;_0x2e02dd<_0x162de7[_0xc951('0x13')];_0x2e02dd++){io['emit'](_0xc951('0x14'),{'id':_0x162de7[_0x2e02dd]['id'],'closed':!![]});}})['catch'](function(_0x388f0a){console[_0xc951('0x15')](_0x388f0a);});}exports['start']=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};