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