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