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