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