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