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