Built motion from commit (unavailable).|2.5.22
[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 _0xff83=['UserId','push','MoveContactManagedDialer','CmHopperFinal','create','COUNT','literal','`scheduledat`\x20>=\x20','format','\x22%s\x22','\x20,\x201,\x20null','CountReScheduled','GetContactRecallMe','GetCmHopperPreview','lodash','util','bluebird','ioredis','../../mysqldb','../../config/utils','rpc','../../config/environment','jayson/promise','client','http','then','info','CmHopper,\x20%s,\x20%s','request\x20sent','debug','CmHopper,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','GetCmHopper','CmHopper','findAll','options','limit','include','map','model','attributes','ShowCmHopper','find','CreateCmHopper','body','raw','UpdateCmHopper','update','where','DestroyCmHopper','destroy','GetContactDialer','CmContact','describe','sequelize','transaction','order','UPDATE','keys','User','Agent','name','voicePause','length','includes'];(function(_0xb7a7d2,_0x5ba4bd){var _0x4fc367=function(_0x5eeaec){while(--_0x5eeaec){_0xb7a7d2['push'](_0xb7a7d2['shift']());}};_0x4fc367(++_0x5ba4bd);}(_0xff83,0x167));var _0x3ff8=function(_0x4154a6,_0x2c0b8e){_0x4154a6=_0x4154a6-0x0;var _0x3b2786=_0xff83[_0x4154a6];return _0x3b2786;};'use strict';var _=require(_0x3ff8('0x0'));var util=require(_0x3ff8('0x1'));var moment=require('moment');var BPromise=require(_0x3ff8('0x2'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x3ff8('0x3'));var db=require(_0x3ff8('0x4'))['db'];var utils=require(_0x3ff8('0x5'));var logger=require('../../config/logger')(_0x3ff8('0x6'));var config=require(_0x3ff8('0x7'));var jayson=require(_0x3ff8('0x8'));var client=jayson[_0x3ff8('0x9')][_0x3ff8('0xa')]({'port':0x232a});function respondWithRpcPromise(_0x5f39f0,_0x83a2e8,_0x50407c){return new BPromise(function(_0x5aba9b,_0x18f6e5){return client['request'](_0x5f39f0,_0x50407c)[_0x3ff8('0xb')](function(_0x161423){logger[_0x3ff8('0xc')](_0x3ff8('0xd'),_0x83a2e8,_0x3ff8('0xe'));logger[_0x3ff8('0xf')](_0x3ff8('0x10'),_0x83a2e8,_0x3ff8('0xe'),JSON[_0x3ff8('0x11')](_0x161423));if(_0x161423[_0x3ff8('0x12')]){if(_0x161423[_0x3ff8('0x12')][_0x3ff8('0x13')]===0x1f4){logger[_0x3ff8('0x12')](_0x3ff8('0xd'),_0x83a2e8,_0x161423[_0x3ff8('0x12')]['message']);return _0x18f6e5(_0x161423[_0x3ff8('0x12')][_0x3ff8('0x14')]);}logger['error'](_0x3ff8('0xd'),_0x83a2e8,_0x161423['error'][_0x3ff8('0x14')]);return _0x5aba9b(_0x161423[_0x3ff8('0x12')]['message']);}else{logger['info'](_0x3ff8('0xd'),_0x83a2e8,_0x3ff8('0xe'));_0x5aba9b(_0x161423['result'][_0x3ff8('0x14')]);}})[_0x3ff8('0x15')](function(_0x31b77d){logger[_0x3ff8('0x12')](_0x3ff8('0xd'),_0x83a2e8,_0x31b77d);_0x18f6e5(_0x31b77d);});});}exports[_0x3ff8('0x16')]=function(_0x1fc663){var _0x19ec36=this;return new Promise(function(_0x3f8ed3,_0x3aa9b7){return db[_0x3ff8('0x17')][_0x3ff8('0x18')]({'raw':_0x1fc663[_0x3ff8('0x19')]?_0x1fc663[_0x3ff8('0x19')]['raw']===undefined?!![]:![]:!![],'where':_0x1fc663[_0x3ff8('0x19')]?_0x1fc663[_0x3ff8('0x19')]['where']||null:null,'attributes':_0x1fc663[_0x3ff8('0x19')]?_0x1fc663[_0x3ff8('0x19')]['attributes']||null:null,'limit':_0x1fc663[_0x3ff8('0x19')]?_0x1fc663[_0x3ff8('0x19')][_0x3ff8('0x1a')]||null:null,'include':_0x1fc663[_0x3ff8('0x19')]?_0x1fc663[_0x3ff8('0x19')][_0x3ff8('0x1b')]?_[_0x3ff8('0x1c')](_0x1fc663[_0x3ff8('0x19')]['include'],function(_0x34c8ce){return{'model':db[_0x34c8ce[_0x3ff8('0x1d')]],'as':_0x34c8ce['as'],'attributes':_0x34c8ce[_0x3ff8('0x1e')],'include':_0x34c8ce[_0x3ff8('0x1b')]?_['map'](_0x34c8ce[_0x3ff8('0x1b')],function(_0x5087bf){return{'model':db[_0x5087bf[_0x3ff8('0x1d')]],'as':_0x5087bf['as'],'attributes':_0x5087bf[_0x3ff8('0x1e')],'include':_0x5087bf[_0x3ff8('0x1b')]?_['map'](_0x5087bf[_0x3ff8('0x1b')],function(_0xbf1208){return{'model':db[_0xbf1208[_0x3ff8('0x1d')]],'as':_0xbf1208['as'],'attributes':_0xbf1208[_0x3ff8('0x1e')]};}):[]};}):[]};}):[]:[]})[_0x3ff8('0xb')](function(_0x383594){logger['info']('GetCmHopper',_0x1fc663);logger[_0x3ff8('0xf')](_0x3ff8('0x16'),_0x1fc663,JSON['stringify'](_0x383594));_0x3f8ed3(_0x383594);})[_0x3ff8('0x15')](function(_0x427ec8){logger[_0x3ff8('0x12')]('GetCmHopper',_0x427ec8[_0x3ff8('0x14')],_0x1fc663);_0x3aa9b7(_0x19ec36[_0x3ff8('0x12')](0x1f4,_0x427ec8['message']));});});};exports[_0x3ff8('0x1f')]=function(_0x3ad76e){var _0x39dc62=this;return new Promise(function(_0x463ca5,_0x128229){return db[_0x3ff8('0x17')][_0x3ff8('0x20')]({'raw':_0x3ad76e[_0x3ff8('0x19')]?_0x3ad76e[_0x3ff8('0x19')]['raw']===undefined?!![]:![]:!![],'where':_0x3ad76e[_0x3ff8('0x19')]?_0x3ad76e[_0x3ff8('0x19')]['where']||null:null,'attributes':_0x3ad76e['options']?_0x3ad76e[_0x3ff8('0x19')][_0x3ff8('0x1e')]||null:null,'include':_0x3ad76e['options']?_0x3ad76e['options'][_0x3ff8('0x1b')]?_[_0x3ff8('0x1c')](_0x3ad76e[_0x3ff8('0x19')]['include'],function(_0x5b5fde){return{'model':db[_0x5b5fde[_0x3ff8('0x1d')]],'as':_0x5b5fde['as'],'attributes':_0x5b5fde[_0x3ff8('0x1e')],'include':_0x5b5fde['include']?_[_0x3ff8('0x1c')](_0x5b5fde['include'],function(_0x1246cd){return{'model':db[_0x1246cd['model']],'as':_0x1246cd['as'],'attributes':_0x1246cd[_0x3ff8('0x1e')],'include':_0x1246cd[_0x3ff8('0x1b')]?_['map'](_0x1246cd[_0x3ff8('0x1b')],function(_0x2c923a){return{'model':db[_0x2c923a[_0x3ff8('0x1d')]],'as':_0x2c923a['as'],'attributes':_0x2c923a[_0x3ff8('0x1e')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x5659d9){logger['info'](_0x3ff8('0x1f'),_0x3ad76e);logger[_0x3ff8('0xf')](_0x3ff8('0x1f'),_0x3ad76e,JSON[_0x3ff8('0x11')](_0x5659d9));_0x463ca5(_0x5659d9);})[_0x3ff8('0x15')](function(_0x2f1ea0){logger[_0x3ff8('0x12')](_0x3ff8('0x1f'),_0x2f1ea0[_0x3ff8('0x14')],_0x3ad76e);_0x128229(_0x39dc62[_0x3ff8('0x12')](0x1f4,_0x2f1ea0[_0x3ff8('0x14')]));});});};exports[_0x3ff8('0x21')]=function(_0x788c85){var _0x5c1bf0=this;return new Promise(function(_0x88f898,_0x56cf37){return db[_0x3ff8('0x17')]['create'](_0x788c85[_0x3ff8('0x22')],{'raw':_0x788c85['options']?_0x788c85[_0x3ff8('0x19')][_0x3ff8('0x23')]===undefined?!![]:![]:!![]})[_0x3ff8('0xb')](function(_0x39b159){logger['info']('CreateCmHopper',_0x788c85);logger['debug']('CreateCmHopper',_0x788c85,JSON[_0x3ff8('0x11')](_0x39b159));_0x88f898(_0x39b159);})[_0x3ff8('0x15')](function(_0x5c99de){logger[_0x3ff8('0x12')](_0x3ff8('0x21'),_0x5c99de[_0x3ff8('0x14')],_0x788c85);_0x56cf37(_0x5c1bf0['error'](0x1f4,_0x5c99de[_0x3ff8('0x14')]));});});};exports[_0x3ff8('0x24')]=function(_0x4ceb6f){var _0x3684d5=this;return new Promise(function(_0x434938,_0x338099){return db[_0x3ff8('0x17')][_0x3ff8('0x25')](_0x4ceb6f[_0x3ff8('0x22')],{'raw':_0x4ceb6f[_0x3ff8('0x19')]?_0x4ceb6f[_0x3ff8('0x19')]['raw']===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x4ceb6f[_0x3ff8('0x19')]?_0x4ceb6f['options'][_0x3ff8('0x26')]||null:null,'attributes':_0x4ceb6f['options']?_0x4ceb6f[_0x3ff8('0x19')][_0x3ff8('0x1e')]||null:null,'limit':_0x4ceb6f['options']?_0x4ceb6f['options'][_0x3ff8('0x1a')]||null:null})['then'](function(_0x42e323){logger[_0x3ff8('0xc')](_0x3ff8('0x24'),_0x4ceb6f);logger[_0x3ff8('0xf')](_0x3ff8('0x24'),_0x4ceb6f,JSON[_0x3ff8('0x11')](_0x42e323));_0x434938(_0x42e323);})[_0x3ff8('0x15')](function(_0x3803dd){logger[_0x3ff8('0x12')]('UpdateCmHopper',_0x3803dd['message'],_0x4ceb6f);_0x338099(_0x3684d5[_0x3ff8('0x12')](0x1f4,_0x3803dd[_0x3ff8('0x14')]));});});};exports[_0x3ff8('0x27')]=function(_0xa1aa9d){var _0x118130=this;return new Promise(function(_0x309b1a,_0x2484a2){return db[_0x3ff8('0x17')][_0x3ff8('0x28')]({'where':_0xa1aa9d[_0x3ff8('0x19')]?_0xa1aa9d[_0x3ff8('0x19')][_0x3ff8('0x26')]||null:null})[_0x3ff8('0xb')](function(_0x9bc85){logger[_0x3ff8('0xc')](_0x3ff8('0x27'),_0xa1aa9d);logger[_0x3ff8('0xf')](_0x3ff8('0x27'),_0xa1aa9d,JSON[_0x3ff8('0x11')](_0x9bc85));_0x309b1a(_0x9bc85);})[_0x3ff8('0x15')](function(_0x511cf8){logger[_0x3ff8('0x12')]('DestroyCmHopper',_0x511cf8[_0x3ff8('0x14')],_0xa1aa9d);_0x2484a2(_0x118130['error'](0x1f4,_0x511cf8[_0x3ff8('0x14')]));});});};exports[_0x3ff8('0x29')]=function(_0x45243c){var _0xb8aeff=this;return new Promise(function(_0x212221,_0x3f6a23){return db[_0x3ff8('0x2a')][_0x3ff8('0x2b')]()[_0x3ff8('0xb')](function(_0x2b9849){return db[_0x3ff8('0x2c')][_0x3ff8('0x2d')](function(_0xdc3102){return db['CmHopper'][_0x3ff8('0x18')]({'where':_0x45243c[_0x3ff8('0x19')]?_0x45243c[_0x3ff8('0x19')]['where']||null:null,'attributes':_0x45243c[_0x3ff8('0x19')]?_0x45243c[_0x3ff8('0x19')][_0x3ff8('0x1e')]||null:null,'limit':_0x45243c[_0x3ff8('0x19')]?_0x45243c[_0x3ff8('0x19')][_0x3ff8('0x1a')]||null:null,'order':_0x45243c[_0x3ff8('0x19')]?_0x45243c[_0x3ff8('0x19')][_0x3ff8('0x2e')]||null:null,'transaction':_0xdc3102,'lock':_0xdc3102['LOCK'][_0x3ff8('0x2f')],'include':[{'model':db[_0x3ff8('0x2a')],'as':'Contact','attributes':_[_0x3ff8('0x30')](_0x2b9849)},{'model':db[_0x3ff8('0x31')],'as':_0x3ff8('0x32'),'attributes':['id',_0x3ff8('0x33'),_0x3ff8('0x34')]}]})['then'](function(_0x41a527){var _0x3b36e4=[];var _0x561321=[];for(var _0x1f5a0a=0x0;_0x1f5a0a<_0x41a527[_0x3ff8('0x35')];_0x1f5a0a+=0x1){if(!_0x561321[_0x3ff8('0x36')](_0x41a527[_0x1f5a0a][_0x3ff8('0x37')])){_0x561321[_0x3ff8('0x38')](_0x41a527[_0x1f5a0a][_0x3ff8('0x37')]);_0x3b36e4['push'](_0x41a527[_0x1f5a0a][_0x3ff8('0x25')](_0x45243c[_0x3ff8('0x22')],{'transaction':_0xdc3102}));}}return BPromise['all'](_0x3b36e4);});})['then'](function(_0xd32aab){logger[_0x3ff8('0xc')]('GetContactDialer',_0x45243c);logger[_0x3ff8('0xf')]('GetContactDialer',_0x45243c,JSON[_0x3ff8('0x11')](_0xd32aab));_0x212221(_0xd32aab);})[_0x3ff8('0x15')](function(_0x3fb4c3){logger[_0x3ff8('0x12')]('GetContactDialer',_0x3fb4c3[_0x3ff8('0x14')],_0x45243c);_0x3f6a23(_0xb8aeff[_0x3ff8('0x12')](0x1f4,_0x3fb4c3['message']));});});});};exports[_0x3ff8('0x39')]=function(_0x7255af){var _0x1eaddc=this;return new Promise(function(_0x17ca4c,_0x1419e3){return db[_0x3ff8('0x2c')][_0x3ff8('0x2d')](function(_0x5871f6){return db[_0x3ff8('0x3a')][_0x3ff8('0x3b')](_0x7255af['body'],{'raw':_0x7255af[_0x3ff8('0x19')]?_0x7255af[_0x3ff8('0x19')][_0x3ff8('0x23')]===undefined?!![]:![]:!![],'transaction':_0x5871f6})[_0x3ff8('0xb')](function(){return db[_0x3ff8('0x17')]['destroy']({'where':_0x7255af[_0x3ff8('0x19')]?_0x7255af['options'][_0x3ff8('0x26')]||null:null,'transaction':_0x5871f6});});})[_0x3ff8('0xb')](function(_0x46249a){logger['info']('MoveContactManagedDialer',_0x7255af);logger[_0x3ff8('0xf')](_0x3ff8('0x39'),_0x7255af,JSON[_0x3ff8('0x11')](_0x46249a));_0x17ca4c(_0x46249a);})[_0x3ff8('0x15')](function(_0x25a98b){logger[_0x3ff8('0x12')](_0x3ff8('0x39'),_0x25a98b['message'],_0x7255af);_0x1419e3(_0x1eaddc[_0x3ff8('0x12')](0x1f4,_0x25a98b[_0x3ff8('0x14')]));});});};exports['CountReScheduled']=function(_0x5df866){var _0x6d9541=this;return new Promise(function(_0x5b1eea,_0x596b42){return db['CmHopper'][_0x3ff8('0x18')]({'raw':_0x5df866[_0x3ff8('0x19')]?_0x5df866[_0x3ff8('0x19')][_0x3ff8('0x23')]===undefined?!![]:![]:!![],'where':_0x5df866[_0x3ff8('0x19')]?_0x5df866[_0x3ff8('0x19')][_0x3ff8('0x26')]||null:null,'attributes':[[db[_0x3ff8('0x2c')]['fn'](_0x3ff8('0x3c'),db[_0x3ff8('0x2c')]['fn']('IF',db[_0x3ff8('0x2c')][_0x3ff8('0x3d')](_0x3ff8('0x3e')+util[_0x3ff8('0x3f')](_0x3ff8('0x40'),moment()['format']('YYYY-MM-DD\x20HH:mm:ss'))+_0x3ff8('0x41')))),'contactsRescheduled']]})[_0x3ff8('0xb')](function(_0x597b25){logger[_0x3ff8('0xc')]('CountReScheduled',_0x5df866);logger[_0x3ff8('0xf')](_0x3ff8('0x42'),_0x5df866,JSON[_0x3ff8('0x11')](_0x597b25));_0x5b1eea(_0x597b25);})[_0x3ff8('0x15')](function(_0x3fa201){logger[_0x3ff8('0x12')](_0x3ff8('0x42'),_0x3fa201[_0x3ff8('0x14')],_0x5df866);_0x596b42(_0x6d9541[_0x3ff8('0x12')](0x1f4,_0x3fa201[_0x3ff8('0x14')]));});});};exports['GetContactRecallMe']=function(_0x55a963){var _0x50fd13=this;return new Promise(function(_0x5103ef,_0x26b58b){return db['CmContact'][_0x3ff8('0x2b')]()[_0x3ff8('0xb')](function(_0x12e793){return db[_0x3ff8('0x2c')][_0x3ff8('0x2d')](function(_0x452789){return db[_0x3ff8('0x17')]['findAll']({'where':_0x55a963[_0x3ff8('0x19')]?_0x55a963[_0x3ff8('0x19')][_0x3ff8('0x26')]||null:null,'attributes':_0x55a963['options']?_0x55a963[_0x3ff8('0x19')][_0x3ff8('0x1e')]||null:null,'limit':0x1,'order':_0x55a963[_0x3ff8('0x19')]?_0x55a963[_0x3ff8('0x19')][_0x3ff8('0x2e')]||null:null,'group':db[_0x3ff8('0x17')]['UserId'],'transaction':_0x452789,'lock':_0x452789['LOCK'][_0x3ff8('0x2f')],'include':_0x55a963[_0x3ff8('0x19')]?_0x55a963[_0x3ff8('0x19')][_0x3ff8('0x1b')]?_['map'](_0x55a963['options'][_0x3ff8('0x1b')],function(_0x3a2fad){return{'model':db[_0x3a2fad[_0x3ff8('0x1d')]],'as':_0x3a2fad['as'],'attributes':_0x3a2fad[_0x3ff8('0x1e')],'include':_0x3a2fad['include']?_[_0x3ff8('0x1c')](_0x3a2fad['include'],function(_0x4d7222){return{'model':db[_0x4d7222[_0x3ff8('0x1d')]],'as':_0x4d7222['as'],'attributes':_0x4d7222[_0x3ff8('0x1e')],'include':_0x4d7222[_0x3ff8('0x1b')]?_['map'](_0x4d7222[_0x3ff8('0x1b')],function(_0x11e868){return{'model':db[_0x11e868['model']],'as':_0x11e868['as'],'attributes':_0x11e868[_0x3ff8('0x1e')]};}):[]};}):[]};}):[]:[]})[_0x3ff8('0xb')](function(_0x2b8988){var _0x33a3b0=[];for(var _0x5ababe=0x0;_0x5ababe<_0x2b8988[_0x3ff8('0x35')];_0x5ababe+=0x1){_0x33a3b0[_0x3ff8('0x38')](_0x2b8988[_0x5ababe]['update'](_0x55a963['body'],{'transaction':_0x452789}));}return BPromise['all'](_0x33a3b0);});})['then'](function(_0x1ac946){logger['info'](_0x3ff8('0x43'),_0x55a963);logger[_0x3ff8('0xf')](_0x3ff8('0x43'),_0x55a963,JSON[_0x3ff8('0x11')](_0x1ac946));_0x5103ef(_0x1ac946);})[_0x3ff8('0x15')](function(_0x2a184a){logger[_0x3ff8('0x12')]('GetContactRecallMe',_0x2a184a[_0x3ff8('0x14')],_0x55a963);_0x26b58b(_0x50fd13[_0x3ff8('0x12')](0x1f4,_0x2a184a[_0x3ff8('0x14')]));});});});};exports[_0x3ff8('0x44')]=function(_0x3b2098){var _0x1506d5=this;return new Promise(function(_0x201120,_0x2d5dd3){db[_0x3ff8('0x2a')][_0x3ff8('0x2b')]()[_0x3ff8('0xb')](function(_0x342d2f){return db[_0x3ff8('0x17')][_0x3ff8('0x18')]({'raw':_0x3b2098[_0x3ff8('0x19')]?_0x3b2098[_0x3ff8('0x19')][_0x3ff8('0x23')]===undefined?!![]:![]:!![],'where':_0x3b2098[_0x3ff8('0x19')]?_0x3b2098['options'][_0x3ff8('0x26')]||null:null,'attributes':_0x3b2098[_0x3ff8('0x19')]?_0x3b2098['options'][_0x3ff8('0x1e')]||null:null,'limit':_0x3b2098[_0x3ff8('0x19')]?_0x3b2098['options']['limit']||null:null,'include':_0x3b2098[_0x3ff8('0x19')]?_0x3b2098[_0x3ff8('0x19')]['include']?_['map'](_0x3b2098['options'][_0x3ff8('0x1b')],function(_0x2889ad){return{'model':db[_0x2889ad['model']],'as':_0x2889ad['as'],'attributes':_0x2889ad['as']==='Contact'?_[_0x3ff8('0x30')](_0x342d2f):_0x2889ad['attributes'],'include':_0x2889ad[_0x3ff8('0x1b')]?_['map'](_0x2889ad['include'],function(_0x43fd60){return{'model':db[_0x43fd60[_0x3ff8('0x1d')]],'as':_0x43fd60['as'],'attributes':_0x43fd60[_0x3ff8('0x1e')],'include':_0x43fd60[_0x3ff8('0x1b')]?_['map'](_0x43fd60['include'],function(_0x2af6b2){return{'model':db[_0x2af6b2['model']],'as':_0x2af6b2['as'],'attributes':_0x2af6b2['attributes']};}):[]};}):[]};}):[]:[]})[_0x3ff8('0xb')](function(_0x4adff9){logger[_0x3ff8('0xc')](_0x3ff8('0x16'),_0x3b2098);logger[_0x3ff8('0xf')]('GetCmHopper',_0x3b2098,JSON[_0x3ff8('0x11')](_0x4adff9));_0x201120(_0x4adff9);})['catch'](function(_0x3ba466){logger[_0x3ff8('0x12')](_0x3ff8('0x16'),_0x3ba466[_0x3ff8('0x14')],_0x3b2098);_0x2d5dd3(_0x1506d5[_0x3ff8('0x12')](0x1f4,_0x3ba466[_0x3ff8('0x14')]));});});});};