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