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