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