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