Built motion from commit e0fa946e.|2.6.5
[motion2.git] / server / config / schedule / whatsapp.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 _0xcc46=['join','WhatsappInteraction','update','system','timeout','format','YYYY-MM-DD\x20HH:mm:ss','then','emit','whatsappInteraction:update','catch','[WHATSAPP]\x20Error\x20closing\x20interactions','inspect','start','lodash','moment','ioredis','util','../../mysqldb','schedule','redis','defaults','socket.io-emitter','findAll','hours','length','map','info','[WHATSAPP]\x20Interactions\x20to\x20close:'];(function(_0x33719b,_0x1ed33e){var _0x1a3427=function(_0x1d2ce8){while(--_0x1d2ce8){_0x33719b['push'](_0x33719b['shift']());}};_0x1a3427(++_0x1ed33e);}(_0xcc46,0x82));var _0x6cc4=function(_0x14e0a5,_0x2d0c56){_0x14e0a5=_0x14e0a5-0x0;var _0x5eff01=_0xcc46[_0x14e0a5];return _0x5eff01;};'use strict';var _=require(_0x6cc4('0x0'));var moment=require(_0x6cc4('0x1'));var Redis=require(_0x6cc4('0x2'));var util=require(_0x6cc4('0x3'));var config=require('../../config/environment');var db=require(_0x6cc4('0x4'))['db'];var logger=require('../logger')(_0x6cc4('0x5'));config[_0x6cc4('0x6')]=_[_0x6cc4('0x7')](config[_0x6cc4('0x6')],{'host':'localhost','port':0x18eb});var io=require(_0x6cc4('0x8'))(new Redis(config[_0x6cc4('0x6')]));function closeInteractions(){var _0xc4f774=[];return db['WhatsappInteraction'][_0x6cc4('0x9')]({'raw':!![],'attributes':['id','lastMsgAt'],'where':{'closed':![],'lastMsgDirection':'in','lastMsgAt':{'$lt':moment()['subtract'](0x18,_0x6cc4('0xa'))}}})['then'](function(_0x3d1eff){if(_0x3d1eff&&_0x3d1eff[_0x6cc4('0xb')]){_0xc4f774=_[_0x6cc4('0xc')](_0x3d1eff||[],'id');logger[_0x6cc4('0xd')](_0x6cc4('0xe'),_0xc4f774[_0x6cc4('0xf')]());return db[_0x6cc4('0x10')][_0x6cc4('0x11')]({'closeReason':_0x6cc4('0x12'),'disposition':_0x6cc4('0x13'),'closed':!![],'closedAt':moment()[_0x6cc4('0x14')](_0x6cc4('0x15'))},{'where':{'id':_0xc4f774}});}})[_0x6cc4('0x16')](function(){if(_0xc4f774&&_0xc4f774[_0x6cc4('0xb')]){logger[_0x6cc4('0xd')]('[WHATSAPP]\x20Sending\x20updates\x20for\x20interactions:',_0xc4f774[_0x6cc4('0xf')]());for(var _0x132679=0x0;_0x132679<_0xc4f774[_0x6cc4('0xb')];_0x132679++){io[_0x6cc4('0x17')](_0x6cc4('0x18'),{'id':_0xc4f774[_0x132679],'closed':!![]});}}})[_0x6cc4('0x19')](function(_0x3a9271){logger['error'](_0x6cc4('0x1a'),_0x3a9271?util[_0x6cc4('0x1b')](_0x3a9271,{'showHidden':![],'depth':null}):'');});}exports[_0x6cc4('0x1c')]=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};