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