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