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