5d179a1342bf5f23a655ce2f78370512fa516c72
[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 _0x2c26=['findAll','lastMsgAt','subtract','then','length','map','info','[WHATSAPP]\x20Interactions\x20to\x20close:','join','update','system','format','YYYY-MM-DD\x20HH:mm:ss','[WHATSAPP]\x20Sending\x20updates\x20for\x20interactions:','whatsappInteraction:update','catch','error','[WHATSAPP]\x20Error\x20closing\x20interactions','inspect','start','lodash','moment','ioredis','../../config/environment','../../mysqldb','../logger','schedule','defaults','redis','localhost','socket.io-emitter','WhatsappInteraction'];(function(_0x502c7d,_0x2f1285){var _0x30b7ed=function(_0x2d92f3){while(--_0x2d92f3){_0x502c7d['push'](_0x502c7d['shift']());}};_0x30b7ed(++_0x2f1285);}(_0x2c26,0xb4));var _0x62c2=function(_0x2127f1,_0x15035c){_0x2127f1=_0x2127f1-0x0;var _0x53ec75=_0x2c26[_0x2127f1];return _0x53ec75;};'use strict';var _=require(_0x62c2('0x0'));var moment=require(_0x62c2('0x1'));var Redis=require(_0x62c2('0x2'));var util=require('util');var config=require(_0x62c2('0x3'));var db=require(_0x62c2('0x4'))['db'];var logger=require(_0x62c2('0x5'))(_0x62c2('0x6'));config['redis']=_[_0x62c2('0x7')](config[_0x62c2('0x8')],{'host':_0x62c2('0x9'),'port':0x18eb});var io=require(_0x62c2('0xa'))(new Redis(config[_0x62c2('0x8')]));function closeInteractions(){var _0x34a786=[];return db[_0x62c2('0xb')][_0x62c2('0xc')]({'raw':!![],'attributes':['id',_0x62c2('0xd')],'where':{'closed':![],'lastMsgDirection':'in','lastMsgAt':{'$lt':moment()[_0x62c2('0xe')](0x18,'hours')}}})[_0x62c2('0xf')](function(_0x54b732){if(_0x54b732&&_0x54b732[_0x62c2('0x10')]){_0x34a786=_[_0x62c2('0x11')](_0x54b732||[],'id');logger[_0x62c2('0x12')](_0x62c2('0x13'),_0x34a786[_0x62c2('0x14')]());return db[_0x62c2('0xb')][_0x62c2('0x15')]({'closeReason':_0x62c2('0x16'),'disposition':'timeout','closed':!![],'closedAt':moment()[_0x62c2('0x17')](_0x62c2('0x18'))},{'where':{'id':_0x34a786}});}})[_0x62c2('0xf')](function(){if(_0x34a786&&_0x34a786[_0x62c2('0x10')]){logger[_0x62c2('0x12')](_0x62c2('0x19'),_0x34a786[_0x62c2('0x14')]());for(var _0x136c26=0x0;_0x136c26<_0x34a786[_0x62c2('0x10')];_0x136c26++){io['emit'](_0x62c2('0x1a'),{'id':_0x34a786[_0x136c26],'closed':!![]});}}})[_0x62c2('0x1b')](function(_0xba717c){logger[_0x62c2('0x1c')](_0x62c2('0x1d'),_0xba717c?util[_0x62c2('0x1e')](_0xba717c,{'showHidden':![],'depth':null}):'');});}exports[_0x62c2('0x1f')]=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};