128cb557d4dd3ad249c487d7b39c1d3230895bb3
[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 _0x052e=['info','update','system','format','YYYY-MM-DD\x20HH:mm:ss','catch','error','[WHATSAPP]\x20Error\x20closing\x20interactions','inspect','start','lodash','moment','ioredis','../../config/environment','schedule','redis','defaults','localhost','socket.io-emitter','WhatsappInteraction','lastMsgAt','hours','then','length','map'];(function(_0x20484c,_0x1abbe6){var _0x3e5356=function(_0x13a45a){while(--_0x13a45a){_0x20484c['push'](_0x20484c['shift']());}};_0x3e5356(++_0x1abbe6);}(_0x052e,0x6e));var _0xe052=function(_0x315bd7,_0x36a963){_0x315bd7=_0x315bd7-0x0;var _0x378931=_0x052e[_0x315bd7];return _0x378931;};'use strict';var _=require(_0xe052('0x0'));var moment=require(_0xe052('0x1'));var Redis=require(_0xe052('0x2'));var util=require('util');var config=require(_0xe052('0x3'));var db=require('../../mysqldb')['db'];var logger=require('../logger')(_0xe052('0x4'));config[_0xe052('0x5')]=_[_0xe052('0x6')](config[_0xe052('0x5')],{'host':_0xe052('0x7'),'port':0x18eb});var io=require(_0xe052('0x8'))(new Redis(config['redis']));function closeInteractions(){var _0x140a74=[];return db[_0xe052('0x9')]['findAll']({'raw':!![],'attributes':['id',_0xe052('0xa')],'where':{'closed':![],'lastMsgDirection':'in','lastMsgAt':{'$lt':moment()['subtract'](0x18,_0xe052('0xb'))}}})[_0xe052('0xc')](function(_0x30fcf6){if(_0x30fcf6&&_0x30fcf6[_0xe052('0xd')]){_0x140a74=_[_0xe052('0xe')](_0x30fcf6||[],'id');logger[_0xe052('0xf')]('[WHATSAPP]\x20Interactions\x20to\x20close:',_0x140a74['join']());return db[_0xe052('0x9')][_0xe052('0x10')]({'closeReason':_0xe052('0x11'),'disposition':'timeout','closed':!![],'closedAt':moment()[_0xe052('0x12')](_0xe052('0x13'))},{'where':{'id':_0x140a74}});}})[_0xe052('0xc')](function(){if(_0x140a74&&_0x140a74['length']){logger[_0xe052('0xf')]('[WHATSAPP]\x20Sending\x20updates\x20for\x20interactions:',_0x140a74['join']());for(var _0x10ce21=0x0;_0x10ce21<_0x140a74[_0xe052('0xd')];_0x10ce21++){io['emit']('whatsappInteraction:update',{'id':_0x140a74[_0x10ce21],'closed':!![]});}}})[_0xe052('0x14')](function(_0x47ed1f){logger[_0xe052('0x15')](_0xe052('0x16'),_0x47ed1f?util[_0xe052('0x17')](_0x47ed1f,{'showHidden':![],'depth':null}):'');});}exports[_0xe052('0x18')]=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};