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