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