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