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