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