Built motion from commit (unavailable).|2.5.4
[motion2.git] / server / config / schedule / chat.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 _0xbcd0=['start','lodash','moment','../../mysqldb','../../config/environment','redis','localhost','socket.io-emitter','Setting','find','chatTimeout','then','ChatInteraction','lastMsgAt','update','system','timeout','format','YYYY-MM-DD\x20HH:mm:ss','length','chatInteraction:update','catch','error'];(function(_0x555ea8,_0x4f0c19){var _0x543af4=function(_0x265d2f){while(--_0x265d2f){_0x555ea8['push'](_0x555ea8['shift']());}};_0x543af4(++_0x4f0c19);}(_0xbcd0,0x8b));var _0x0bcd=function(_0x428d49,_0x59f03c){_0x428d49=_0x428d49-0x0;var _0x3ff07c=_0xbcd0[_0x428d49];return _0x3ff07c;};'use strict';var _=require(_0x0bcd('0x0'));var moment=require(_0x0bcd('0x1'));var Redis=require('ioredis');var db=require(_0x0bcd('0x2'))['db'];var config=require(_0x0bcd('0x3'));config[_0x0bcd('0x4')]=_['defaults'](config[_0x0bcd('0x4')],{'host':_0x0bcd('0x5'),'port':0x18eb});var io=require(_0x0bcd('0x6'))(new Redis(config[_0x0bcd('0x4')]));function closeInteractions(){var _0x105e5e=0x0;var _0x496075=[];return db[_0x0bcd('0x7')][_0x0bcd('0x8')]({'raw':!![],'attributes':['id',_0x0bcd('0x9')],'where':{'id':0x1}})[_0x0bcd('0xa')](function(_0x18db65){_0x105e5e=_0x18db65['chatTimeout'];if(_0x105e5e){return db[_0x0bcd('0xb')]['findAll']({'raw':!![],'attributes':['id',_0x0bcd('0xc')],'where':{'closed':![],'lastMsgAt':{'$lt':moment()['subtract'](_0x18db65[_0x0bcd('0x9')],'minutes')}}});}else{return[];}})[_0x0bcd('0xa')](function(_0x2d25c3){_0x496075=_0x2d25c3;if(_0x105e5e){return db['ChatInteraction'][_0x0bcd('0xd')]({'closeReason':_0x0bcd('0xe'),'disposition':_0x0bcd('0xf'),'closed':!![],'closedAt':moment()[_0x0bcd('0x10')](_0x0bcd('0x11'))},{'where':{'id':_['map'](_0x496075||[],'id')}});}})[_0x0bcd('0xa')](function(_0x136547){for(var _0x3201b5=0x0;_0x3201b5<_0x496075[_0x0bcd('0x12')];_0x3201b5++){io['emit'](_0x0bcd('0x13'),{'id':_0x496075[_0x3201b5]['id'],'closed':!![]});}})[_0x0bcd('0x14')](function(_0x258a35){console[_0x0bcd('0x15')](_0x258a35);});}exports[_0x0bcd('0x16')]=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};