76d879db6fcd457c16f0d97c5152c27c384c17ad
[motion2.git] / server / api / cmHopper / cmHopper.rpc.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 _0x3699=['code','message','result','catch','GetCmHopper','CmHopper','findAll','options','raw','attributes','limit','include','model','map','info','ShowCmHopper','find','CreateCmHopper','create','body','stringify','UpdateCmHopper','where','DestroyCmHopper','CmContact','transaction','order','LOCK','UPDATE','Contact','keys','Agent','UserId','push','update','all','GetContactDialer','MoveContactManagedDialer','CmHopperFinal','destroy','sequelize','COUNT','literal','`scheduledat`\x20>=\x20','format','\x22%s\x22','YYYY-MM-DD\x20HH:mm:ss','CountReScheduled','length','GetContactRecallMe','GetCmHopperPreview','describe','lodash','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','client','request','then','CmHopper,\x20%s,\x20%s','debug','request\x20sent','error'];(function(_0x29b609,_0x19d388){var _0x54c952=function(_0xb3c38d){while(--_0xb3c38d){_0x29b609['push'](_0x29b609['shift']());}};_0x54c952(++_0x19d388);}(_0x3699,0xbe));var _0x9369=function(_0x27cc2b,_0x5ab446){_0x27cc2b=_0x27cc2b-0x0;var _0x2c97eb=_0x3699[_0x27cc2b];return _0x2c97eb;};'use strict';var _=require(_0x9369('0x0'));var util=require(_0x9369('0x1'));var moment=require(_0x9369('0x2'));var BPromise=require(_0x9369('0x3'));var rs=require(_0x9369('0x4'));var fs=require('fs');var Redis=require(_0x9369('0x5'));var db=require(_0x9369('0x6'))['db'];var utils=require(_0x9369('0x7'));var logger=require(_0x9369('0x8'))(_0x9369('0x9'));var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson[_0x9369('0xa')]['http']({'port':0x232a});function respondWithRpcPromise(_0x51ce09,_0x4571ff,_0x276b65){return new BPromise(function(_0x2f87ca,_0x48b9de){return client[_0x9369('0xb')](_0x51ce09,_0x276b65)[_0x9369('0xc')](function(_0x41932c){logger['info'](_0x9369('0xd'),_0x4571ff,'request\x20sent');logger[_0x9369('0xe')]('CmHopper,\x20%s,\x20%s,\x20%s',_0x4571ff,_0x9369('0xf'),JSON['stringify'](_0x41932c));if(_0x41932c[_0x9369('0x10')]){if(_0x41932c[_0x9369('0x10')][_0x9369('0x11')]===0x1f4){logger[_0x9369('0x10')](_0x9369('0xd'),_0x4571ff,_0x41932c['error'][_0x9369('0x12')]);return _0x48b9de(_0x41932c[_0x9369('0x10')]['message']);}logger['error']('CmHopper,\x20%s,\x20%s',_0x4571ff,_0x41932c[_0x9369('0x10')][_0x9369('0x12')]);return _0x2f87ca(_0x41932c[_0x9369('0x10')][_0x9369('0x12')]);}else{logger['info'](_0x9369('0xd'),_0x4571ff,_0x9369('0xf'));_0x2f87ca(_0x41932c[_0x9369('0x13')][_0x9369('0x12')]);}})[_0x9369('0x14')](function(_0x2a757d){logger['error'](_0x9369('0xd'),_0x4571ff,_0x2a757d);_0x48b9de(_0x2a757d);});});}exports[_0x9369('0x15')]=function(_0x3b21bd){var _0x273792=this;return new Promise(function(_0x38472c,_0x5921ed){return db[_0x9369('0x16')][_0x9369('0x17')]({'raw':_0x3b21bd[_0x9369('0x18')]?_0x3b21bd[_0x9369('0x18')][_0x9369('0x19')]===undefined?!![]:![]:!![],'where':_0x3b21bd['options']?_0x3b21bd[_0x9369('0x18')]['where']||null:null,'attributes':_0x3b21bd[_0x9369('0x18')]?_0x3b21bd[_0x9369('0x18')][_0x9369('0x1a')]||null:null,'limit':_0x3b21bd[_0x9369('0x18')]?_0x3b21bd[_0x9369('0x18')][_0x9369('0x1b')]||null:null,'include':_0x3b21bd[_0x9369('0x18')]?_0x3b21bd[_0x9369('0x18')][_0x9369('0x1c')]?_['map'](_0x3b21bd[_0x9369('0x18')][_0x9369('0x1c')],function(_0x57afa8){return{'model':db[_0x57afa8[_0x9369('0x1d')]],'as':_0x57afa8['as'],'attributes':_0x57afa8[_0x9369('0x1a')],'include':_0x57afa8['include']?_[_0x9369('0x1e')](_0x57afa8['include'],function(_0x17a259){return{'model':db[_0x17a259[_0x9369('0x1d')]],'as':_0x17a259['as'],'attributes':_0x17a259[_0x9369('0x1a')],'include':_0x17a259[_0x9369('0x1c')]?_[_0x9369('0x1e')](_0x17a259['include'],function(_0x104cf1){return{'model':db[_0x104cf1[_0x9369('0x1d')]],'as':_0x104cf1['as'],'attributes':_0x104cf1[_0x9369('0x1a')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x461876){logger[_0x9369('0x1f')](_0x9369('0x15'),_0x3b21bd);logger['debug'](_0x9369('0x15'),_0x3b21bd,JSON['stringify'](_0x461876));_0x38472c(_0x461876);})[_0x9369('0x14')](function(_0x813726){logger['error'](_0x9369('0x15'),_0x813726[_0x9369('0x12')],_0x3b21bd);_0x5921ed(_0x273792[_0x9369('0x10')](0x1f4,_0x813726[_0x9369('0x12')]));});});};exports[_0x9369('0x20')]=function(_0x50aeb1){var _0x2ccff5=this;return new Promise(function(_0x3264f1,_0x3b86b9){return db[_0x9369('0x16')][_0x9369('0x21')]({'raw':_0x50aeb1[_0x9369('0x18')]?_0x50aeb1['options'][_0x9369('0x19')]===undefined?!![]:![]:!![],'where':_0x50aeb1['options']?_0x50aeb1[_0x9369('0x18')]['where']||null:null,'attributes':_0x50aeb1['options']?_0x50aeb1[_0x9369('0x18')][_0x9369('0x1a')]||null:null,'include':_0x50aeb1['options']?_0x50aeb1[_0x9369('0x18')]['include']?_[_0x9369('0x1e')](_0x50aeb1['options'][_0x9369('0x1c')],function(_0x3e9a55){return{'model':db[_0x3e9a55[_0x9369('0x1d')]],'as':_0x3e9a55['as'],'attributes':_0x3e9a55[_0x9369('0x1a')],'include':_0x3e9a55[_0x9369('0x1c')]?_[_0x9369('0x1e')](_0x3e9a55[_0x9369('0x1c')],function(_0x21251c){return{'model':db[_0x21251c[_0x9369('0x1d')]],'as':_0x21251c['as'],'attributes':_0x21251c['attributes'],'include':_0x21251c['include']?_['map'](_0x21251c[_0x9369('0x1c')],function(_0x20fd0a){return{'model':db[_0x20fd0a['model']],'as':_0x20fd0a['as'],'attributes':_0x20fd0a[_0x9369('0x1a')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x16d86c){logger[_0x9369('0x1f')]('ShowCmHopper',_0x50aeb1);logger[_0x9369('0xe')](_0x9369('0x20'),_0x50aeb1,JSON['stringify'](_0x16d86c));_0x3264f1(_0x16d86c);})[_0x9369('0x14')](function(_0x5c0780){logger['error'](_0x9369('0x20'),_0x5c0780[_0x9369('0x12')],_0x50aeb1);_0x3b86b9(_0x2ccff5[_0x9369('0x10')](0x1f4,_0x5c0780['message']));});});};exports[_0x9369('0x22')]=function(_0x15d981){var _0x5d036d=this;return new Promise(function(_0x1c8870,_0x1ba7e3){return db[_0x9369('0x16')][_0x9369('0x23')](_0x15d981[_0x9369('0x24')],{'raw':_0x15d981[_0x9369('0x18')]?_0x15d981[_0x9369('0x18')][_0x9369('0x19')]===undefined?!![]:![]:!![]})[_0x9369('0xc')](function(_0x54e964){logger['info']('CreateCmHopper',_0x15d981);logger[_0x9369('0xe')](_0x9369('0x22'),_0x15d981,JSON[_0x9369('0x25')](_0x54e964));_0x1c8870(_0x54e964);})[_0x9369('0x14')](function(_0x36f627){logger[_0x9369('0x10')](_0x9369('0x22'),_0x36f627[_0x9369('0x12')],_0x15d981);_0x1ba7e3(_0x5d036d[_0x9369('0x10')](0x1f4,_0x36f627[_0x9369('0x12')]));});});};exports[_0x9369('0x26')]=function(_0x4ee425){var _0x22c685=this;return new Promise(function(_0x273b6d,_0x39d467){return db['CmHopper']['update'](_0x4ee425[_0x9369('0x24')],{'raw':_0x4ee425[_0x9369('0x18')]?_0x4ee425[_0x9369('0x18')][_0x9369('0x19')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x4ee425[_0x9369('0x18')]?_0x4ee425[_0x9369('0x18')]['where']||null:null,'attributes':_0x4ee425[_0x9369('0x18')]?_0x4ee425[_0x9369('0x18')]['attributes']||null:null,'limit':_0x4ee425[_0x9369('0x18')]?_0x4ee425[_0x9369('0x18')][_0x9369('0x1b')]||null:null})[_0x9369('0xc')](function(_0x5c56ca){logger['info'](_0x9369('0x26'),_0x4ee425);logger['debug'](_0x9369('0x26'),_0x4ee425,JSON[_0x9369('0x25')](_0x5c56ca));_0x273b6d(_0x5c56ca);})[_0x9369('0x14')](function(_0x1fd772){logger[_0x9369('0x10')]('UpdateCmHopper',_0x1fd772['message'],_0x4ee425);_0x39d467(_0x22c685[_0x9369('0x10')](0x1f4,_0x1fd772[_0x9369('0x12')]));});});};exports['DestroyCmHopper']=function(_0xe1bdac){var _0xc6562d=this;return new Promise(function(_0x407092,_0x175f51){return db['CmHopper']['destroy']({'where':_0xe1bdac[_0x9369('0x18')]?_0xe1bdac[_0x9369('0x18')][_0x9369('0x27')]||null:null})[_0x9369('0xc')](function(_0x5585c6){logger[_0x9369('0x1f')](_0x9369('0x28'),_0xe1bdac);logger[_0x9369('0xe')](_0x9369('0x28'),_0xe1bdac,JSON[_0x9369('0x25')](_0x5585c6));_0x407092(_0x5585c6);})[_0x9369('0x14')](function(_0x1838de){logger['error'](_0x9369('0x28'),_0x1838de[_0x9369('0x12')],_0xe1bdac);_0x175f51(_0xc6562d[_0x9369('0x10')](0x1f4,_0x1838de[_0x9369('0x12')]));});});};exports['GetContactDialer']=function(_0xb260ed){var _0x1c1609=this;return new Promise(function(_0x306e6b,_0x5eba30){return db[_0x9369('0x29')]['describe']()[_0x9369('0xc')](function(_0x3555d5){return db['sequelize'][_0x9369('0x2a')](function(_0xe02100){return db[_0x9369('0x16')]['findAll']({'where':_0xb260ed['options']?_0xb260ed[_0x9369('0x18')][_0x9369('0x27')]||null:null,'attributes':_0xb260ed[_0x9369('0x18')]?_0xb260ed['options'][_0x9369('0x1a')]||null:null,'limit':_0xb260ed[_0x9369('0x18')]?_0xb260ed['options']['limit']||null:null,'order':_0xb260ed[_0x9369('0x18')]?_0xb260ed['options'][_0x9369('0x2b')]||null:null,'transaction':_0xe02100,'lock':_0xe02100[_0x9369('0x2c')][_0x9369('0x2d')],'include':[{'model':db[_0x9369('0x29')],'as':_0x9369('0x2e'),'attributes':_[_0x9369('0x2f')](_0x3555d5)},{'model':db['User'],'as':_0x9369('0x30'),'attributes':['id','name','voicePause']}]})[_0x9369('0xc')](function(_0x159988){var _0x3e3beb=[];var _0x3931c5=[];for(var _0x36bf68=0x0;_0x36bf68<_0x159988['length'];_0x36bf68+=0x1){var _0x4e318f=_0x159988[_0x36bf68][_0x9369('0x31')];if(_0x4e318f===null){_0x3e3beb[_0x9369('0x32')](_0x159988[_0x36bf68]['update'](_0xb260ed['body'],{'transaction':_0xe02100}));}else if(!_0x3931c5['includes'](_0x4e318f)){_0x3931c5[_0x9369('0x32')](_0x4e318f);_0x3e3beb[_0x9369('0x32')](_0x159988[_0x36bf68][_0x9369('0x33')](_0xb260ed[_0x9369('0x24')],{'transaction':_0xe02100}));}}return BPromise[_0x9369('0x34')](_0x3e3beb);});})['then'](function(_0x278578){logger[_0x9369('0x1f')](_0x9369('0x35'),_0xb260ed);logger['debug']('GetContactDialer',_0xb260ed,JSON[_0x9369('0x25')](_0x278578));_0x306e6b(_0x278578);})[_0x9369('0x14')](function(_0x45599f){logger[_0x9369('0x10')](_0x9369('0x35'),_0x45599f[_0x9369('0x12')],_0xb260ed);_0x5eba30(_0x1c1609[_0x9369('0x10')](0x1f4,_0x45599f[_0x9369('0x12')]));});});});};exports[_0x9369('0x36')]=function(_0x438f90){var _0x15099f=this;return new Promise(function(_0x54684d,_0x59f06b){return db['sequelize'][_0x9369('0x2a')](function(_0x273c7d){return db[_0x9369('0x37')][_0x9369('0x23')](_0x438f90[_0x9369('0x24')],{'raw':_0x438f90[_0x9369('0x18')]?_0x438f90[_0x9369('0x18')][_0x9369('0x19')]===undefined?!![]:![]:!![],'transaction':_0x273c7d})[_0x9369('0xc')](function(){return db[_0x9369('0x16')][_0x9369('0x38')]({'where':_0x438f90[_0x9369('0x18')]?_0x438f90[_0x9369('0x18')][_0x9369('0x27')]||null:null,'transaction':_0x273c7d});});})['then'](function(_0x1a39e6){logger['info'](_0x9369('0x36'),_0x438f90);logger[_0x9369('0xe')](_0x9369('0x36'),_0x438f90,JSON[_0x9369('0x25')](_0x1a39e6));_0x54684d(_0x1a39e6);})['catch'](function(_0x41fd3a){logger[_0x9369('0x10')](_0x9369('0x36'),_0x41fd3a[_0x9369('0x12')],_0x438f90);_0x59f06b(_0x15099f['error'](0x1f4,_0x41fd3a[_0x9369('0x12')]));});});};exports['CountReScheduled']=function(_0xa57f57){var _0x4a9d56=this;return new Promise(function(_0x22c35d,_0x1793bc){return db[_0x9369('0x16')][_0x9369('0x17')]({'raw':_0xa57f57['options']?_0xa57f57[_0x9369('0x18')][_0x9369('0x19')]===undefined?!![]:![]:!![],'where':_0xa57f57[_0x9369('0x18')]?_0xa57f57[_0x9369('0x18')][_0x9369('0x27')]||null:null,'attributes':[[db[_0x9369('0x39')]['fn'](_0x9369('0x3a'),db[_0x9369('0x39')]['fn']('IF',db[_0x9369('0x39')][_0x9369('0x3b')](_0x9369('0x3c')+util[_0x9369('0x3d')](_0x9369('0x3e'),moment()[_0x9369('0x3d')](_0x9369('0x3f')))+'\x20,\x201,\x20null'))),'contactsRescheduled']]})[_0x9369('0xc')](function(_0x42377d){logger['info'](_0x9369('0x40'),_0xa57f57);logger[_0x9369('0xe')](_0x9369('0x40'),_0xa57f57,JSON['stringify'](_0x42377d));_0x22c35d(_0x42377d);})['catch'](function(_0x4a162f){logger[_0x9369('0x10')](_0x9369('0x40'),_0x4a162f[_0x9369('0x12')],_0xa57f57);_0x1793bc(_0x4a9d56[_0x9369('0x10')](0x1f4,_0x4a162f[_0x9369('0x12')]));});});};exports['GetContactRecallMe']=function(_0x4db09c){var _0x5c23ea=this;return new Promise(function(_0x5a3ffb,_0x1b9dcb){return db['CmContact']['describe']()['then'](function(_0x27afc6){return db[_0x9369('0x39')][_0x9369('0x2a')](function(_0x502b89){return db[_0x9369('0x16')][_0x9369('0x17')]({'where':_0x4db09c[_0x9369('0x18')]?_0x4db09c[_0x9369('0x18')][_0x9369('0x27')]||null:null,'attributes':_0x4db09c[_0x9369('0x18')]?_0x4db09c[_0x9369('0x18')][_0x9369('0x1a')]||null:null,'limit':0x1,'order':_0x4db09c[_0x9369('0x18')]?_0x4db09c[_0x9369('0x18')][_0x9369('0x2b')]||null:null,'group':db[_0x9369('0x16')]['UserId'],'transaction':_0x502b89,'lock':_0x502b89[_0x9369('0x2c')][_0x9369('0x2d')],'include':_0x4db09c[_0x9369('0x18')]?_0x4db09c[_0x9369('0x18')]['include']?_['map'](_0x4db09c[_0x9369('0x18')][_0x9369('0x1c')],function(_0x5dfb0b){return{'model':db[_0x5dfb0b[_0x9369('0x1d')]],'as':_0x5dfb0b['as'],'attributes':_0x5dfb0b[_0x9369('0x1a')],'include':_0x5dfb0b[_0x9369('0x1c')]?_[_0x9369('0x1e')](_0x5dfb0b[_0x9369('0x1c')],function(_0x404de5){return{'model':db[_0x404de5[_0x9369('0x1d')]],'as':_0x404de5['as'],'attributes':_0x404de5[_0x9369('0x1a')],'include':_0x404de5[_0x9369('0x1c')]?_[_0x9369('0x1e')](_0x404de5[_0x9369('0x1c')],function(_0x2b7906){return{'model':db[_0x2b7906[_0x9369('0x1d')]],'as':_0x2b7906['as'],'attributes':_0x2b7906[_0x9369('0x1a')]};}):[]};}):[]};}):[]:[]})[_0x9369('0xc')](function(_0x2a5078){var _0x130dc4=[];for(var _0x2fa60a=0x0;_0x2fa60a<_0x2a5078[_0x9369('0x41')];_0x2fa60a+=0x1){_0x130dc4[_0x9369('0x32')](_0x2a5078[_0x2fa60a][_0x9369('0x33')](_0x4db09c['body'],{'transaction':_0x502b89}));}return BPromise[_0x9369('0x34')](_0x130dc4);});})[_0x9369('0xc')](function(_0x2bc652){logger[_0x9369('0x1f')](_0x9369('0x42'),_0x4db09c);logger[_0x9369('0xe')](_0x9369('0x42'),_0x4db09c,JSON['stringify'](_0x2bc652));_0x5a3ffb(_0x2bc652);})['catch'](function(_0x410de6){logger[_0x9369('0x10')](_0x9369('0x42'),_0x410de6['message'],_0x4db09c);_0x1b9dcb(_0x5c23ea[_0x9369('0x10')](0x1f4,_0x410de6[_0x9369('0x12')]));});});});};exports[_0x9369('0x43')]=function(_0xbde981){var _0x5d7781=this;return new Promise(function(_0x55fca1,_0x279636){db[_0x9369('0x29')][_0x9369('0x44')]()[_0x9369('0xc')](function(_0x58d55b){return db[_0x9369('0x16')][_0x9369('0x17')]({'raw':_0xbde981[_0x9369('0x18')]?_0xbde981['options']['raw']===undefined?!![]:![]:!![],'where':_0xbde981[_0x9369('0x18')]?_0xbde981[_0x9369('0x18')][_0x9369('0x27')]||null:null,'attributes':_0xbde981[_0x9369('0x18')]?_0xbde981[_0x9369('0x18')][_0x9369('0x1a')]||null:null,'limit':_0xbde981[_0x9369('0x18')]?_0xbde981['options']['limit']||null:null,'include':_0xbde981[_0x9369('0x18')]?_0xbde981[_0x9369('0x18')][_0x9369('0x1c')]?_[_0x9369('0x1e')](_0xbde981[_0x9369('0x18')][_0x9369('0x1c')],function(_0x2bd7fb){return{'model':db[_0x2bd7fb[_0x9369('0x1d')]],'as':_0x2bd7fb['as'],'attributes':_0x2bd7fb['as']===_0x9369('0x2e')?_[_0x9369('0x2f')](_0x58d55b):_0x2bd7fb[_0x9369('0x1a')],'include':_0x2bd7fb[_0x9369('0x1c')]?_[_0x9369('0x1e')](_0x2bd7fb[_0x9369('0x1c')],function(_0x1a3361){return{'model':db[_0x1a3361[_0x9369('0x1d')]],'as':_0x1a3361['as'],'attributes':_0x1a3361[_0x9369('0x1a')],'include':_0x1a3361['include']?_['map'](_0x1a3361[_0x9369('0x1c')],function(_0x4dca1e){return{'model':db[_0x4dca1e['model']],'as':_0x4dca1e['as'],'attributes':_0x4dca1e[_0x9369('0x1a')]};}):[]};}):[]};}):[]:[]})[_0x9369('0xc')](function(_0x139161){logger[_0x9369('0x1f')](_0x9369('0x15'),_0xbde981);logger[_0x9369('0xe')](_0x9369('0x15'),_0xbde981,JSON[_0x9369('0x25')](_0x139161));_0x55fca1(_0x139161);})['catch'](function(_0x1f6eef){logger[_0x9369('0x10')]('GetCmHopper',_0x1f6eef[_0x9369('0x12')],_0xbde981);_0x279636(_0x5d7781[_0x9369('0x10')](0x1f4,_0x1f6eef[_0x9369('0x12')]));});});});};