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