Built motion from commit 8356fca3.|2.6.19
[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 _0x5728=['start','lodash','moment','ioredis','../../config/environment','../../mysqldb','schedule','redis','defaults','localhost','WhatsappInteraction','findAll','lastMsgAt','subtract','hours','then','length','[WHATSAPP]\x20Interactions\x20to\x20close:','update','system','timeout','format','YYYY-MM-DD\x20HH:mm:ss','info','join','emit','whatsappInteraction:update','catch','[WHATSAPP]\x20Error\x20closing\x20interactions','inspect'];(function(_0x2dafbe,_0x5d04de){var _0x58a45a=function(_0x50ac96){while(--_0x50ac96){_0x2dafbe['push'](_0x2dafbe['shift']());}};_0x58a45a(++_0x5d04de);}(_0x5728,0xb5));var _0x8572=function(_0x19c6e4,_0x45dadb){_0x19c6e4=_0x19c6e4-0x0;var _0x31ead6=_0x5728[_0x19c6e4];return _0x31ead6;};'use strict';var _=require(_0x8572('0x0'));var moment=require(_0x8572('0x1'));var Redis=require(_0x8572('0x2'));var util=require('util');var config=require(_0x8572('0x3'));var db=require(_0x8572('0x4'))['db'];var logger=require('../logger')(_0x8572('0x5'));config[_0x8572('0x6')]=_[_0x8572('0x7')](config[_0x8572('0x6')],{'host':_0x8572('0x8'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config['redis']));function closeInteractions(){var _0x523f40=[];return db[_0x8572('0x9')][_0x8572('0xa')]({'raw':!![],'attributes':['id',_0x8572('0xb')],'where':{'closed':![],'lastMsgDirection':'in','lastMsgAt':{'$lt':moment()[_0x8572('0xc')](0x18,_0x8572('0xd'))}}})[_0x8572('0xe')](function(_0x1d0f23){if(_0x1d0f23&&_0x1d0f23[_0x8572('0xf')]){_0x523f40=_['map'](_0x1d0f23||[],'id');logger['info'](_0x8572('0x10'),_0x523f40['join']());return db['WhatsappInteraction'][_0x8572('0x11')]({'closeReason':_0x8572('0x12'),'disposition':_0x8572('0x13'),'closed':!![],'closedAt':moment()[_0x8572('0x14')](_0x8572('0x15'))},{'where':{'id':_0x523f40}});}})[_0x8572('0xe')](function(){if(_0x523f40&&_0x523f40[_0x8572('0xf')]){logger[_0x8572('0x16')]('[WHATSAPP]\x20Sending\x20updates\x20for\x20interactions:',_0x523f40[_0x8572('0x17')]());for(var _0x1055c8=0x0;_0x1055c8<_0x523f40['length'];_0x1055c8++){io[_0x8572('0x18')](_0x8572('0x19'),{'id':_0x523f40[_0x1055c8],'closed':!![]});}}})[_0x8572('0x1a')](function(_0x3036a2){logger['error'](_0x8572('0x1b'),_0x3036a2?util[_0x8572('0x1c')](_0x3036a2,{'showHidden':![],'depth':null}):'');});}exports[_0x8572('0x1d')]=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};