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