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