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