Built motion from commit da617fac.|2.6.6
[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 _0x968c=['WhatsappInteraction','findAll','lastMsgAt','subtract','length','info','join','update','format','YYYY-MM-DD\x20HH:mm:ss','then','[WHATSAPP]\x20Sending\x20updates\x20for\x20interactions:','emit','whatsappInteraction:update','catch','error','start','lodash','moment','../../mysqldb','../logger','schedule','redis','localhost','socket.io-emitter'];(function(_0x690346,_0x40dc57){var _0x5e4dab=function(_0x52ef75){while(--_0x52ef75){_0x690346['push'](_0x690346['shift']());}};_0x5e4dab(++_0x40dc57);}(_0x968c,0xd9));var _0xc968=function(_0x3aca1e,_0x5233f6){_0x3aca1e=_0x3aca1e-0x0;var _0x3f63c9=_0x968c[_0x3aca1e];return _0x3f63c9;};'use strict';var _=require(_0xc968('0x0'));var moment=require(_0xc968('0x1'));var Redis=require('ioredis');var util=require('util');var config=require('../../config/environment');var db=require(_0xc968('0x2'))['db'];var logger=require(_0xc968('0x3'))(_0xc968('0x4'));config['redis']=_['defaults'](config[_0xc968('0x5')],{'host':_0xc968('0x6'),'port':0x18eb});var io=require(_0xc968('0x7'))(new Redis(config[_0xc968('0x5')]));function closeInteractions(){var _0x3648ba=[];return db[_0xc968('0x8')][_0xc968('0x9')]({'raw':!![],'attributes':['id',_0xc968('0xa')],'where':{'closed':![],'lastMsgDirection':'in','lastMsgAt':{'$lt':moment()[_0xc968('0xb')](0x18,'hours')}}})['then'](function(_0x431b0c){if(_0x431b0c&&_0x431b0c[_0xc968('0xc')]){_0x3648ba=_['map'](_0x431b0c||[],'id');logger[_0xc968('0xd')]('[WHATSAPP]\x20Interactions\x20to\x20close:',_0x3648ba[_0xc968('0xe')]());return db[_0xc968('0x8')][_0xc968('0xf')]({'closeReason':'system','disposition':'timeout','closed':!![],'closedAt':moment()[_0xc968('0x10')](_0xc968('0x11'))},{'where':{'id':_0x3648ba}});}})[_0xc968('0x12')](function(){if(_0x3648ba&&_0x3648ba[_0xc968('0xc')]){logger[_0xc968('0xd')](_0xc968('0x13'),_0x3648ba['join']());for(var _0x1bf905=0x0;_0x1bf905<_0x3648ba[_0xc968('0xc')];_0x1bf905++){io[_0xc968('0x14')](_0xc968('0x15'),{'id':_0x3648ba[_0x1bf905],'closed':!![]});}}})[_0xc968('0x16')](function(_0x4c0161){logger[_0xc968('0x17')]('[WHATSAPP]\x20Error\x20closing\x20interactions',_0x4c0161?util['inspect'](_0x4c0161,{'showHidden':![],'depth':null}):'');});}exports[_0xc968('0x18')]=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};