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