Built motion from commit f9526609.|2.6.29
[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 _0x101e=['start','ioredis','../../config/environment','schedule','defaults','localhost','socket.io-emitter','redis','WhatsappInteraction','length','map','info','[WHATSAPP]\x20Interactions\x20to\x20close:','join','system','YYYY-MM-DD\x20HH:mm:ss','emit','whatsappInteraction:update','catch','error','[WHATSAPP]\x20Error\x20closing\x20interactions'];(function(_0x31ea14,_0x1e0a8f){var _0x55dfcb=function(_0x113c3f){while(--_0x113c3f){_0x31ea14['push'](_0x31ea14['shift']());}};_0x55dfcb(++_0x1e0a8f);}(_0x101e,0xbe));var _0xe101=function(_0x19e35c,_0x29cd1e){_0x19e35c=_0x19e35c-0x0;var _0x3e1fe8=_0x101e[_0x19e35c];return _0x3e1fe8;};'use strict';var _=require('lodash');var moment=require('moment');var Redis=require(_0xe101('0x0'));var util=require('util');var config=require(_0xe101('0x1'));var db=require('../../mysqldb')['db'];var logger=require('../logger')(_0xe101('0x2'));config['redis']=_[_0xe101('0x3')](config['redis'],{'host':_0xe101('0x4'),'port':0x18eb});var io=require(_0xe101('0x5'))(new Redis(config[_0xe101('0x6')]));function closeInteractions(){var _0x834bdc=[];return db[_0xe101('0x7')]['findAll']({'raw':!![],'attributes':['id','lastMsgAt'],'where':{'closed':![],'lastMsgDirection':'in','lastMsgAt':{'$lt':moment()['subtract'](0x18,'hours')}}})['then'](function(_0x4d6983){if(_0x4d6983&&_0x4d6983[_0xe101('0x8')]){_0x834bdc=_[_0xe101('0x9')](_0x4d6983||[],'id');logger[_0xe101('0xa')](_0xe101('0xb'),_0x834bdc[_0xe101('0xc')]());return db[_0xe101('0x7')]['update']({'closeReason':_0xe101('0xd'),'disposition':'timeout','closed':!![],'closedAt':moment()['format'](_0xe101('0xe'))},{'where':{'id':_0x834bdc}});}})['then'](function(){if(_0x834bdc&&_0x834bdc[_0xe101('0x8')]){logger[_0xe101('0xa')]('[WHATSAPP]\x20Sending\x20updates\x20for\x20interactions:',_0x834bdc[_0xe101('0xc')]());for(var _0x510636=0x0;_0x510636<_0x834bdc['length'];_0x510636++){io[_0xe101('0xf')](_0xe101('0x10'),{'id':_0x834bdc[_0x510636],'closed':!![]});}}})[_0xe101('0x11')](function(_0x1070ea){logger[_0xe101('0x12')](_0xe101('0x13'),_0x1070ea?util['inspect'](_0x1070ea,{'showHidden':![],'depth':null}):'');});}exports[_0xe101('0x14')]=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};