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