Built motion from commit (unavailable).|2.5.4
[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 _0x4624=['UserId','push','all','MoveContactManagedDialer','destroy','CountReScheduled','literal','format','\x22%s\x22','YYYY-MM-DD\x20HH:mm:ss','\x20,\x201,\x20null','describe','GetContactRecallMe','lodash','moment','bluebird','ioredis','../../mysqldb','../../config/utils','../../config/environment','jayson/promise','client','http','request','info','CmHopper,\x20%s,\x20%s','request\x20sent','debug','CmHopper,\x20%s,\x20%s,\x20%s','stringify','error','message','result','catch','GetCmHopper','CmHopper','findAll','options','where','limit','include','map','attributes','model','ShowCmHopper','raw','then','CreateCmHopper','create','UpdateCmHopper','update','body','DestroyCmHopper','GetContactDialer','sequelize','transaction','order','UPDATE','CmContact','Contact','keys','User','Agent','name','voicePause','length','includes'];(function(_0x21837a,_0x49860f){var _0x56a837=function(_0xe4fab9){while(--_0xe4fab9){_0x21837a['push'](_0x21837a['shift']());}};_0x56a837(++_0x49860f);}(_0x4624,0x15c));var _0x4462=function(_0x2420df,_0x12c14a){_0x2420df=_0x2420df-0x0;var _0xaa2aea=_0x4624[_0x2420df];return _0xaa2aea;};'use strict';var _=require(_0x4462('0x0'));var util=require('util');var moment=require(_0x4462('0x1'));var BPromise=require(_0x4462('0x2'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x4462('0x3'));var db=require(_0x4462('0x4'))['db'];var utils=require(_0x4462('0x5'));var logger=require('../../config/logger')('rpc');var config=require(_0x4462('0x6'));var jayson=require(_0x4462('0x7'));var client=jayson[_0x4462('0x8')][_0x4462('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x2c0cc6,_0x2e6334,_0x2626d3){return new BPromise(function(_0x289bfc,_0x20bc15){return client[_0x4462('0xa')](_0x2c0cc6,_0x2626d3)['then'](function(_0x27f00b){logger[_0x4462('0xb')](_0x4462('0xc'),_0x2e6334,_0x4462('0xd'));logger[_0x4462('0xe')](_0x4462('0xf'),_0x2e6334,_0x4462('0xd'),JSON[_0x4462('0x10')](_0x27f00b));if(_0x27f00b['error']){if(_0x27f00b[_0x4462('0x11')]['code']===0x1f4){logger[_0x4462('0x11')](_0x4462('0xc'),_0x2e6334,_0x27f00b[_0x4462('0x11')][_0x4462('0x12')]);return _0x20bc15(_0x27f00b[_0x4462('0x11')][_0x4462('0x12')]);}logger[_0x4462('0x11')](_0x4462('0xc'),_0x2e6334,_0x27f00b[_0x4462('0x11')]['message']);return _0x289bfc(_0x27f00b[_0x4462('0x11')][_0x4462('0x12')]);}else{logger[_0x4462('0xb')](_0x4462('0xc'),_0x2e6334,_0x4462('0xd'));_0x289bfc(_0x27f00b[_0x4462('0x13')][_0x4462('0x12')]);}})[_0x4462('0x14')](function(_0x69f42f){logger[_0x4462('0x11')](_0x4462('0xc'),_0x2e6334,_0x69f42f);_0x20bc15(_0x69f42f);});});}exports[_0x4462('0x15')]=function(_0x498416){var _0x5ebf94=this;return new Promise(function(_0x82ffd1,_0x19461f){return db[_0x4462('0x16')][_0x4462('0x17')]({'raw':_0x498416['options']?_0x498416[_0x4462('0x18')]['raw']===undefined?!![]:![]:!![],'where':_0x498416['options']?_0x498416[_0x4462('0x18')][_0x4462('0x19')]||null:null,'attributes':_0x498416[_0x4462('0x18')]?_0x498416[_0x4462('0x18')]['attributes']||null:null,'limit':_0x498416[_0x4462('0x18')]?_0x498416[_0x4462('0x18')][_0x4462('0x1a')]||null:null,'include':_0x498416[_0x4462('0x18')]?_0x498416[_0x4462('0x18')][_0x4462('0x1b')]?_[_0x4462('0x1c')](_0x498416[_0x4462('0x18')]['include'],function(_0xcd75f0){return{'model':db[_0xcd75f0['model']],'as':_0xcd75f0['as'],'attributes':_0xcd75f0[_0x4462('0x1d')],'include':_0xcd75f0['include']?_['map'](_0xcd75f0[_0x4462('0x1b')],function(_0xe46cf){return{'model':db[_0xe46cf['model']],'as':_0xe46cf['as'],'attributes':_0xe46cf['attributes'],'include':_0xe46cf[_0x4462('0x1b')]?_[_0x4462('0x1c')](_0xe46cf[_0x4462('0x1b')],function(_0x5dad9b){return{'model':db[_0x5dad9b[_0x4462('0x1e')]],'as':_0x5dad9b['as'],'attributes':_0x5dad9b[_0x4462('0x1d')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x1084cb){logger[_0x4462('0xb')](_0x4462('0x15'),_0x498416);logger[_0x4462('0xe')]('GetCmHopper',_0x498416,JSON[_0x4462('0x10')](_0x1084cb));_0x82ffd1(_0x1084cb);})[_0x4462('0x14')](function(_0x546e05){logger[_0x4462('0x11')]('GetCmHopper',_0x546e05[_0x4462('0x12')],_0x498416);_0x19461f(_0x5ebf94[_0x4462('0x11')](0x1f4,_0x546e05[_0x4462('0x12')]));});});};exports[_0x4462('0x1f')]=function(_0x240077){var _0x60c379=this;return new Promise(function(_0x2b61cd,_0x56e6fe){return db['CmHopper']['find']({'raw':_0x240077[_0x4462('0x18')]?_0x240077['options'][_0x4462('0x20')]===undefined?!![]:![]:!![],'where':_0x240077[_0x4462('0x18')]?_0x240077[_0x4462('0x18')]['where']||null:null,'attributes':_0x240077[_0x4462('0x18')]?_0x240077[_0x4462('0x18')][_0x4462('0x1d')]||null:null,'include':_0x240077[_0x4462('0x18')]?_0x240077['options'][_0x4462('0x1b')]?_['map'](_0x240077[_0x4462('0x18')][_0x4462('0x1b')],function(_0xe35dd4){return{'model':db[_0xe35dd4[_0x4462('0x1e')]],'as':_0xe35dd4['as'],'attributes':_0xe35dd4[_0x4462('0x1d')],'include':_0xe35dd4[_0x4462('0x1b')]?_['map'](_0xe35dd4['include'],function(_0x21c260){return{'model':db[_0x21c260[_0x4462('0x1e')]],'as':_0x21c260['as'],'attributes':_0x21c260[_0x4462('0x1d')],'include':_0x21c260[_0x4462('0x1b')]?_[_0x4462('0x1c')](_0x21c260[_0x4462('0x1b')],function(_0x464ef4){return{'model':db[_0x464ef4[_0x4462('0x1e')]],'as':_0x464ef4['as'],'attributes':_0x464ef4[_0x4462('0x1d')]};}):[]};}):[]};}):[]:[]})[_0x4462('0x21')](function(_0x2cc087){logger['info'](_0x4462('0x1f'),_0x240077);logger[_0x4462('0xe')](_0x4462('0x1f'),_0x240077,JSON[_0x4462('0x10')](_0x2cc087));_0x2b61cd(_0x2cc087);})['catch'](function(_0x5db747){logger['error'](_0x4462('0x1f'),_0x5db747[_0x4462('0x12')],_0x240077);_0x56e6fe(_0x60c379[_0x4462('0x11')](0x1f4,_0x5db747['message']));});});};exports[_0x4462('0x22')]=function(_0xbe3cd1){var _0x219455=this;return new Promise(function(_0x415bec,_0x151c0e){return db['CmHopper'][_0x4462('0x23')](_0xbe3cd1['body'],{'raw':_0xbe3cd1[_0x4462('0x18')]?_0xbe3cd1['options']['raw']===undefined?!![]:![]:!![]})[_0x4462('0x21')](function(_0x129d3c){logger['info']('CreateCmHopper',_0xbe3cd1);logger[_0x4462('0xe')](_0x4462('0x22'),_0xbe3cd1,JSON[_0x4462('0x10')](_0x129d3c));_0x415bec(_0x129d3c);})[_0x4462('0x14')](function(_0x31fdf2){logger[_0x4462('0x11')](_0x4462('0x22'),_0x31fdf2[_0x4462('0x12')],_0xbe3cd1);_0x151c0e(_0x219455[_0x4462('0x11')](0x1f4,_0x31fdf2['message']));});});};exports[_0x4462('0x24')]=function(_0x3b1ab9){var _0x1c5e48=this;return new Promise(function(_0x52f2f6,_0x1d6e2c){return db[_0x4462('0x16')][_0x4462('0x25')](_0x3b1ab9[_0x4462('0x26')],{'raw':_0x3b1ab9[_0x4462('0x18')]?_0x3b1ab9[_0x4462('0x18')][_0x4462('0x20')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x3b1ab9[_0x4462('0x18')]?_0x3b1ab9['options']['where']||null:null,'attributes':_0x3b1ab9[_0x4462('0x18')]?_0x3b1ab9['options'][_0x4462('0x1d')]||null:null,'limit':_0x3b1ab9['options']?_0x3b1ab9[_0x4462('0x18')][_0x4462('0x1a')]||null:null})[_0x4462('0x21')](function(_0x403659){logger[_0x4462('0xb')]('UpdateCmHopper',_0x3b1ab9);logger[_0x4462('0xe')]('UpdateCmHopper',_0x3b1ab9,JSON[_0x4462('0x10')](_0x403659));_0x52f2f6(_0x403659);})[_0x4462('0x14')](function(_0x180d55){logger[_0x4462('0x11')](_0x4462('0x24'),_0x180d55[_0x4462('0x12')],_0x3b1ab9);_0x1d6e2c(_0x1c5e48[_0x4462('0x11')](0x1f4,_0x180d55[_0x4462('0x12')]));});});};exports[_0x4462('0x27')]=function(_0x1cc359){var _0x347fdc=this;return new Promise(function(_0x5549cc,_0x2cf2a4){return db['CmHopper']['destroy']({'where':_0x1cc359[_0x4462('0x18')]?_0x1cc359[_0x4462('0x18')][_0x4462('0x19')]||null:null})[_0x4462('0x21')](function(_0x316ebc){logger[_0x4462('0xb')](_0x4462('0x27'),_0x1cc359);logger['debug'](_0x4462('0x27'),_0x1cc359,JSON['stringify'](_0x316ebc));_0x5549cc(_0x316ebc);})[_0x4462('0x14')](function(_0x1c2921){logger['error'](_0x4462('0x27'),_0x1c2921[_0x4462('0x12')],_0x1cc359);_0x2cf2a4(_0x347fdc[_0x4462('0x11')](0x1f4,_0x1c2921[_0x4462('0x12')]));});});};exports[_0x4462('0x28')]=function(_0x365608){var _0x1babb5=this;return new Promise(function(_0x2735d0,_0x4c3268){return db['CmContact']['describe']()[_0x4462('0x21')](function(_0x3f4a15){return db[_0x4462('0x29')][_0x4462('0x2a')](function(_0x21c498){return db[_0x4462('0x16')][_0x4462('0x17')]({'where':_0x365608[_0x4462('0x18')]?_0x365608[_0x4462('0x18')][_0x4462('0x19')]||null:null,'attributes':_0x365608[_0x4462('0x18')]?_0x365608[_0x4462('0x18')][_0x4462('0x1d')]||null:null,'limit':_0x365608[_0x4462('0x18')]?_0x365608[_0x4462('0x18')]['limit']||null:null,'order':_0x365608[_0x4462('0x18')]?_0x365608['options'][_0x4462('0x2b')]||null:null,'transaction':_0x21c498,'lock':_0x21c498['LOCK'][_0x4462('0x2c')],'include':[{'model':db[_0x4462('0x2d')],'as':_0x4462('0x2e'),'attributes':_[_0x4462('0x2f')](_0x3f4a15)},{'model':db[_0x4462('0x30')],'as':_0x4462('0x31'),'attributes':['id',_0x4462('0x32'),_0x4462('0x33')]}]})[_0x4462('0x21')](function(_0x4d1d74){var _0x243e67=[];var _0x598913=[];for(var _0xc1ddb0=0x0;_0xc1ddb0<_0x4d1d74[_0x4462('0x34')];_0xc1ddb0+=0x1){if(!_0x598913[_0x4462('0x35')](_0x4d1d74[_0xc1ddb0][_0x4462('0x36')])){_0x598913[_0x4462('0x37')](_0x4d1d74[_0xc1ddb0][_0x4462('0x36')]);_0x243e67[_0x4462('0x37')](_0x4d1d74[_0xc1ddb0][_0x4462('0x25')](_0x365608[_0x4462('0x26')],{'transaction':_0x21c498}));}}return BPromise[_0x4462('0x38')](_0x243e67);});})[_0x4462('0x21')](function(_0x306f44){logger[_0x4462('0xb')](_0x4462('0x28'),_0x365608);logger[_0x4462('0xe')](_0x4462('0x28'),_0x365608,JSON[_0x4462('0x10')](_0x306f44));_0x2735d0(_0x306f44);})[_0x4462('0x14')](function(_0x36cccc){logger[_0x4462('0x11')](_0x4462('0x28'),_0x36cccc['message'],_0x365608);_0x4c3268(_0x1babb5['error'](0x1f4,_0x36cccc['message']));});});});};exports[_0x4462('0x39')]=function(_0x5a1932){var _0x266a52=this;return new Promise(function(_0x210e30,_0x5384a4){return db[_0x4462('0x29')][_0x4462('0x2a')](function(_0x1e85d9){return db['CmHopperFinal'][_0x4462('0x23')](_0x5a1932['body'],{'raw':_0x5a1932[_0x4462('0x18')]?_0x5a1932['options'][_0x4462('0x20')]===undefined?!![]:![]:!![],'transaction':_0x1e85d9})[_0x4462('0x21')](function(){return db[_0x4462('0x16')][_0x4462('0x3a')]({'where':_0x5a1932[_0x4462('0x18')]?_0x5a1932[_0x4462('0x18')]['where']||null:null,'transaction':_0x1e85d9});});})[_0x4462('0x21')](function(_0x10fa85){logger[_0x4462('0xb')]('MoveContactManagedDialer',_0x5a1932);logger[_0x4462('0xe')](_0x4462('0x39'),_0x5a1932,JSON[_0x4462('0x10')](_0x10fa85));_0x210e30(_0x10fa85);})[_0x4462('0x14')](function(_0x125662){logger[_0x4462('0x11')](_0x4462('0x39'),_0x125662[_0x4462('0x12')],_0x5a1932);_0x5384a4(_0x266a52[_0x4462('0x11')](0x1f4,_0x125662[_0x4462('0x12')]));});});};exports[_0x4462('0x3b')]=function(_0x2fc715){var _0x5ba2e5=this;return new Promise(function(_0x208822,_0x5d84d7){return db[_0x4462('0x16')][_0x4462('0x17')]({'raw':_0x2fc715[_0x4462('0x18')]?_0x2fc715[_0x4462('0x18')][_0x4462('0x20')]===undefined?!![]:![]:!![],'where':_0x2fc715['options']?_0x2fc715['options'][_0x4462('0x19')]||null:null,'attributes':[[db[_0x4462('0x29')]['fn']('COUNT',db[_0x4462('0x29')]['fn']('IF',db[_0x4462('0x29')][_0x4462('0x3c')]('`scheduledat`\x20>=\x20'+util[_0x4462('0x3d')](_0x4462('0x3e'),moment()[_0x4462('0x3d')](_0x4462('0x3f')))+_0x4462('0x40')))),'contactsRescheduled']]})['then'](function(_0x7b890){logger[_0x4462('0xb')](_0x4462('0x3b'),_0x2fc715);logger['debug'](_0x4462('0x3b'),_0x2fc715,JSON[_0x4462('0x10')](_0x7b890));_0x208822(_0x7b890);})['catch'](function(_0x78e6b9){logger[_0x4462('0x11')]('CountReScheduled',_0x78e6b9[_0x4462('0x12')],_0x2fc715);_0x5d84d7(_0x5ba2e5[_0x4462('0x11')](0x1f4,_0x78e6b9[_0x4462('0x12')]));});});};exports['GetContactRecallMe']=function(_0x25c199){var _0x29b78f=this;return new Promise(function(_0xf6937c,_0x386d65){return db['CmContact'][_0x4462('0x41')]()[_0x4462('0x21')](function(_0x2ef19c){return db[_0x4462('0x29')][_0x4462('0x2a')](function(_0x4e6a38){return db['CmHopper'][_0x4462('0x17')]({'where':_0x25c199['options']?_0x25c199[_0x4462('0x18')]['where']||null:null,'attributes':_0x25c199[_0x4462('0x18')]?_0x25c199[_0x4462('0x18')][_0x4462('0x1d')]||null:null,'limit':0x1,'order':_0x25c199[_0x4462('0x18')]?_0x25c199['options'][_0x4462('0x2b')]||null:null,'group':db['CmHopper'][_0x4462('0x36')],'transaction':_0x4e6a38,'lock':_0x4e6a38['LOCK']['UPDATE'],'include':_0x25c199['options']?_0x25c199[_0x4462('0x18')][_0x4462('0x1b')]?_[_0x4462('0x1c')](_0x25c199[_0x4462('0x18')][_0x4462('0x1b')],function(_0x3a5a5b){return{'model':db[_0x3a5a5b[_0x4462('0x1e')]],'as':_0x3a5a5b['as'],'attributes':_0x3a5a5b[_0x4462('0x1d')],'include':_0x3a5a5b['include']?_[_0x4462('0x1c')](_0x3a5a5b[_0x4462('0x1b')],function(_0x5e37fa){return{'model':db[_0x5e37fa[_0x4462('0x1e')]],'as':_0x5e37fa['as'],'attributes':_0x5e37fa[_0x4462('0x1d')],'include':_0x5e37fa[_0x4462('0x1b')]?_[_0x4462('0x1c')](_0x5e37fa[_0x4462('0x1b')],function(_0x40cf63){return{'model':db[_0x40cf63[_0x4462('0x1e')]],'as':_0x40cf63['as'],'attributes':_0x40cf63[_0x4462('0x1d')]};}):[]};}):[]};}):[]:[]})[_0x4462('0x21')](function(_0x1a8794){var _0x5726c2=[];for(var _0x496288=0x0;_0x496288<_0x1a8794[_0x4462('0x34')];_0x496288+=0x1){_0x5726c2[_0x4462('0x37')](_0x1a8794[_0x496288][_0x4462('0x25')](_0x25c199[_0x4462('0x26')],{'transaction':_0x4e6a38}));}return BPromise[_0x4462('0x38')](_0x5726c2);});})[_0x4462('0x21')](function(_0x1c069b){logger['info'](_0x4462('0x42'),_0x25c199);logger[_0x4462('0xe')](_0x4462('0x42'),_0x25c199,JSON[_0x4462('0x10')](_0x1c069b));_0xf6937c(_0x1c069b);})[_0x4462('0x14')](function(_0xa5eab3){logger['error'](_0x4462('0x42'),_0xa5eab3[_0x4462('0x12')],_0x25c199);_0x386d65(_0x29b78f['error'](0x1f4,_0xa5eab3['message']));});});});};exports['GetCmHopperPreview']=function(_0x48460c){var _0xecd338=this;return new Promise(function(_0x542581,_0x1a68d2){db['CmContact'][_0x4462('0x41')]()['then'](function(_0x467da1){return db[_0x4462('0x16')][_0x4462('0x17')]({'raw':_0x48460c['options']?_0x48460c[_0x4462('0x18')][_0x4462('0x20')]===undefined?!![]:![]:!![],'where':_0x48460c[_0x4462('0x18')]?_0x48460c['options'][_0x4462('0x19')]||null:null,'attributes':_0x48460c[_0x4462('0x18')]?_0x48460c[_0x4462('0x18')][_0x4462('0x1d')]||null:null,'limit':_0x48460c[_0x4462('0x18')]?_0x48460c['options']['limit']||null:null,'include':_0x48460c[_0x4462('0x18')]?_0x48460c['options'][_0x4462('0x1b')]?_[_0x4462('0x1c')](_0x48460c[_0x4462('0x18')][_0x4462('0x1b')],function(_0x5410ba){return{'model':db[_0x5410ba[_0x4462('0x1e')]],'as':_0x5410ba['as'],'attributes':_0x5410ba['as']===_0x4462('0x2e')?_['keys'](_0x467da1):_0x5410ba[_0x4462('0x1d')],'include':_0x5410ba[_0x4462('0x1b')]?_['map'](_0x5410ba[_0x4462('0x1b')],function(_0x395f08){return{'model':db[_0x395f08['model']],'as':_0x395f08['as'],'attributes':_0x395f08['attributes'],'include':_0x395f08[_0x4462('0x1b')]?_['map'](_0x395f08[_0x4462('0x1b')],function(_0x41f465){return{'model':db[_0x41f465['model']],'as':_0x41f465['as'],'attributes':_0x41f465[_0x4462('0x1d')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x24e29f){logger[_0x4462('0xb')](_0x4462('0x15'),_0x48460c);logger[_0x4462('0xe')](_0x4462('0x15'),_0x48460c,JSON['stringify'](_0x24e29f));_0x542581(_0x24e29f);})['catch'](function(_0x4e2b44){logger[_0x4462('0x11')](_0x4462('0x15'),_0x4e2b44[_0x4462('0x12')],_0x48460c);_0x1a68d2(_0xecd338[_0x4462('0x11')](0x1f4,_0x4e2b44[_0x4462('0x12')]));});});});};