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