Built motion from commit 06eb8eb0.|2.6.31
[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 _0xc614=['util','../../config/environment','../logger','schedule','redis','defaults','localhost','socket.io-emitter','Setting','find','chatTimeout','then','findAll','lastMsgAt','subtract','minutes','length','map','ChatInteraction','update','timeout','info','[CHAT]\x20Sending\x20updates\x20for\x20interactions:','join','emit','chatInteraction:update','catch','error','[CHAT]\x20Error\x20closing\x20interactions','start','moment'];(function(_0x38a1c5,_0x3773ee){var _0x2bddf5=function(_0x4ee0cb){while(--_0x4ee0cb){_0x38a1c5['push'](_0x38a1c5['shift']());}};_0x2bddf5(++_0x3773ee);}(_0xc614,0x135));var _0x4c61=function(_0x34d067,_0x13d2fe){_0x34d067=_0x34d067-0x0;var _0x308b9a=_0xc614[_0x34d067];return _0x308b9a;};'use strict';var _=require('lodash');var moment=require(_0x4c61('0x0'));var Redis=require('ioredis');var util=require(_0x4c61('0x1'));var config=require(_0x4c61('0x2'));var db=require('../../mysqldb')['db'];var logger=require(_0x4c61('0x3'))(_0x4c61('0x4'));config[_0x4c61('0x5')]=_[_0x4c61('0x6')](config[_0x4c61('0x5')],{'host':_0x4c61('0x7'),'port':0x18eb});var io=require(_0x4c61('0x8'))(new Redis(config[_0x4c61('0x5')]));function closeInteractions(){var _0xcc5ee=0x0;var _0xa9e53a=[];return db[_0x4c61('0x9')][_0x4c61('0xa')]({'raw':!![],'attributes':['id',_0x4c61('0xb')],'where':{'id':0x1}})[_0x4c61('0xc')](function(_0x41275f){_0xcc5ee=_0x41275f[_0x4c61('0xb')];if(_0xcc5ee){return db['ChatInteraction'][_0x4c61('0xd')]({'raw':!![],'attributes':['id',_0x4c61('0xe')],'where':{'closed':![],'lastMsgAt':{'$lt':moment()[_0x4c61('0xf')](_0x41275f[_0x4c61('0xb')],_0x4c61('0x10'))}}});}else{return[];}})[_0x4c61('0xc')](function(_0x54abfa){if(_0x54abfa&&_0x54abfa[_0x4c61('0x11')]){_0xa9e53a=_[_0x4c61('0x12')](_0x54abfa||[],'id');logger['info']('[CHAT]\x20Interactions\x20to\x20close:',_0xa9e53a['join']());return db[_0x4c61('0x13')][_0x4c61('0x14')]({'closeReason':'system','disposition':_0x4c61('0x15'),'closed':!![],'closedAt':moment()['format']('YYYY-MM-DD\x20HH:mm:ss')},{'where':{'id':_0xa9e53a}});}})[_0x4c61('0xc')](function(){if(_0xa9e53a&&_0xa9e53a[_0x4c61('0x11')]){logger[_0x4c61('0x16')](_0x4c61('0x17'),_0xa9e53a[_0x4c61('0x18')]());for(var _0xe6a164=0x0;_0xe6a164<_0xa9e53a[_0x4c61('0x11')];_0xe6a164++){io[_0x4c61('0x19')](_0x4c61('0x1a'),{'id':_0xa9e53a[_0xe6a164],'closed':!![]});}}})[_0x4c61('0x1b')](function(_0x3c13b6){logger[_0x4c61('0x1c')](_0x4c61('0x1d'),_0x3c13b6?util['inspect'](_0x3c13b6,{'showHidden':![],'depth':null}):'');});}exports[_0x4c61('0x1e')]=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};