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