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