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