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