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