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