Built motion from commit fe909640.|2.6.8
[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 _0xf66a=['../../mysqldb','jayson/promise','request','then','info','CmHopper,\x20%s,\x20%s','request\x20sent','debug','error','message','result','catch','CmHopper','options','raw','where','attributes','limit','include','model','map','GetCmHopper','stringify','ShowCmHopper','CreateCmHopper','create','body','UpdateCmHopper','UpdateCmHopper\x20hopper\x20options\x20[%s]\x20active\x20status\x20[%s]','DestroyCmHopper','destroy','GetContactDialer','CmContact','describe','sequelize','transaction','findAll','order','LOCK','Contact','keys','User','Agent','name','voicePause','UserId','push','includes','update','all','length','GetContactDialer\x20hopperId\x20[%s]\x20-\x20contactId\x20[%s]\x20-\x20active\x20status\x20[%s]','dataValues','ContactId','active','MoveContactManagedDialer','CmHopperFinal','MoveContactManagedDialer\x20hopper\x20options\x20[%s]\x20active\x20status\x20[%s]','COUNT','literal','`scheduledat`\x20>=\x20','format','\x22%s\x22','YYYY-MM-DD\x20HH:mm:ss','\x20,\x201,\x20null','contactsRescheduled','CountReScheduled','GetContactRecallMe','UPDATE','GetContactByPhone','findOne','phone','dialTimezone','getContactByPhone','ResetActiveCalls','CmHopperHandlePreviewRecallNotifications','voiceQueueIds','interval','NOW()\x20+\x20INTERVAL\x20','CmList','List','NOW()','util','moment'];(function(_0x45730c,_0x5aa7a1){var _0xf66e31=function(_0x2428bc){while(--_0x2428bc){_0x45730c['push'](_0x45730c['shift']());}};_0xf66e31(++_0x5aa7a1);}(_0xf66a,0xa6));var _0xaf66=function(_0x5cc3ab,_0x46bff0){_0x5cc3ab=_0x5cc3ab-0x0;var _0x200382=_0xf66a[_0x5cc3ab];return _0x200382;};'use strict';var _=require('lodash');var util=require(_0xaf66('0x0'));var moment=require(_0xaf66('0x1'));var BPromise=require('bluebird');var db=require(_0xaf66('0x2'))['db'];var logger=require('../../config/logger')('rpc');var jayson=require(_0xaf66('0x3'));var client=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x3ab9ea,_0x14f5b9,_0x2df7b5){return new BPromise(function(_0x3592e2,_0x259953){return client[_0xaf66('0x4')](_0x3ab9ea,_0x2df7b5)[_0xaf66('0x5')](function(_0x1ec847){logger[_0xaf66('0x6')](_0xaf66('0x7'),_0x14f5b9,_0xaf66('0x8'));logger[_0xaf66('0x9')]('CmHopper,\x20%s,\x20%s,\x20%s',_0x14f5b9,_0xaf66('0x8'),JSON['stringify'](_0x1ec847));if(_0x1ec847[_0xaf66('0xa')]){if(_0x1ec847[_0xaf66('0xa')]['code']===0x1f4){logger['error'](_0xaf66('0x7'),_0x14f5b9,_0x1ec847[_0xaf66('0xa')][_0xaf66('0xb')]);return _0x259953(_0x1ec847[_0xaf66('0xa')][_0xaf66('0xb')]);}logger[_0xaf66('0xa')](_0xaf66('0x7'),_0x14f5b9,_0x1ec847['error'][_0xaf66('0xb')]);return _0x3592e2(_0x1ec847['error'][_0xaf66('0xb')]);}else{logger[_0xaf66('0x6')](_0xaf66('0x7'),_0x14f5b9,_0xaf66('0x8'));_0x3592e2(_0x1ec847[_0xaf66('0xc')][_0xaf66('0xb')]);}})[_0xaf66('0xd')](function(_0x3b00f3){logger[_0xaf66('0xa')](_0xaf66('0x7'),_0x14f5b9,_0x3b00f3);_0x259953(_0x3b00f3);});});}exports['GetCmHopper']=function(_0x5e8de4){var _0x369465=this;return new Promise(function(_0x6ec060,_0x3e71f7){return db[_0xaf66('0xe')]['findAll']({'raw':_0x5e8de4[_0xaf66('0xf')]?_0x5e8de4[_0xaf66('0xf')][_0xaf66('0x10')]===undefined?!![]:![]:!![],'where':_0x5e8de4[_0xaf66('0xf')]?_0x5e8de4[_0xaf66('0xf')][_0xaf66('0x11')]||null:null,'attributes':_0x5e8de4[_0xaf66('0xf')]?_0x5e8de4[_0xaf66('0xf')][_0xaf66('0x12')]||null:null,'limit':_0x5e8de4[_0xaf66('0xf')]?_0x5e8de4[_0xaf66('0xf')][_0xaf66('0x13')]||null:null,'include':_0x5e8de4[_0xaf66('0xf')]?_0x5e8de4[_0xaf66('0xf')][_0xaf66('0x14')]?_['map'](_0x5e8de4[_0xaf66('0xf')][_0xaf66('0x14')],function(_0x4d81cb){return{'model':db[_0x4d81cb[_0xaf66('0x15')]],'as':_0x4d81cb['as'],'attributes':_0x4d81cb[_0xaf66('0x12')],'include':_0x4d81cb[_0xaf66('0x14')]?_[_0xaf66('0x16')](_0x4d81cb[_0xaf66('0x14')],function(_0x21adaf){return{'model':db[_0x21adaf[_0xaf66('0x15')]],'as':_0x21adaf['as'],'attributes':_0x21adaf[_0xaf66('0x12')],'include':_0x21adaf[_0xaf66('0x14')]?_[_0xaf66('0x16')](_0x21adaf[_0xaf66('0x14')],function(_0x2dbc8f){return{'model':db[_0x2dbc8f[_0xaf66('0x15')]],'as':_0x2dbc8f['as'],'attributes':_0x2dbc8f[_0xaf66('0x12')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x1f4101){logger[_0xaf66('0x6')](_0xaf66('0x17'),_0x5e8de4);logger[_0xaf66('0x9')](_0xaf66('0x17'),_0x5e8de4,JSON[_0xaf66('0x18')](_0x1f4101));_0x6ec060(_0x1f4101);})[_0xaf66('0xd')](function(_0x175d17){logger[_0xaf66('0xa')](_0xaf66('0x17'),_0x175d17[_0xaf66('0xb')],_0x5e8de4);_0x3e71f7(_0x369465[_0xaf66('0xa')](0x1f4,_0x175d17['message']));});});};exports[_0xaf66('0x19')]=function(_0x3aa3a2){var _0x4eff60=this;return new Promise(function(_0x3a0b8e,_0x364e57){return db['CmHopper']['find']({'raw':_0x3aa3a2[_0xaf66('0xf')]?_0x3aa3a2['options'][_0xaf66('0x10')]===undefined?!![]:![]:!![],'where':_0x3aa3a2[_0xaf66('0xf')]?_0x3aa3a2[_0xaf66('0xf')][_0xaf66('0x11')]||null:null,'attributes':_0x3aa3a2[_0xaf66('0xf')]?_0x3aa3a2[_0xaf66('0xf')]['attributes']||null:null,'include':_0x3aa3a2[_0xaf66('0xf')]?_0x3aa3a2[_0xaf66('0xf')][_0xaf66('0x14')]?_[_0xaf66('0x16')](_0x3aa3a2[_0xaf66('0xf')][_0xaf66('0x14')],function(_0xd28c3a){return{'model':db[_0xd28c3a[_0xaf66('0x15')]],'as':_0xd28c3a['as'],'attributes':_0xd28c3a[_0xaf66('0x12')],'include':_0xd28c3a[_0xaf66('0x14')]?_['map'](_0xd28c3a[_0xaf66('0x14')],function(_0x25013c){return{'model':db[_0x25013c['model']],'as':_0x25013c['as'],'attributes':_0x25013c[_0xaf66('0x12')],'include':_0x25013c[_0xaf66('0x14')]?_[_0xaf66('0x16')](_0x25013c['include'],function(_0x569d04){return{'model':db[_0x569d04[_0xaf66('0x15')]],'as':_0x569d04['as'],'attributes':_0x569d04[_0xaf66('0x12')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x39d922){logger[_0xaf66('0x6')](_0xaf66('0x19'),_0x3aa3a2);logger[_0xaf66('0x9')](_0xaf66('0x19'),_0x3aa3a2,JSON['stringify'](_0x39d922));_0x3a0b8e(_0x39d922);})[_0xaf66('0xd')](function(_0x2be2bb){logger[_0xaf66('0xa')](_0xaf66('0x19'),_0x2be2bb[_0xaf66('0xb')],_0x3aa3a2);_0x364e57(_0x4eff60[_0xaf66('0xa')](0x1f4,_0x2be2bb[_0xaf66('0xb')]));});});};exports[_0xaf66('0x1a')]=function(_0x2ae12d){var _0x44a5d2=this;return new Promise(function(_0x43f5ad,_0x458ec8){return db[_0xaf66('0xe')][_0xaf66('0x1b')](_0x2ae12d[_0xaf66('0x1c')],{'raw':_0x2ae12d[_0xaf66('0xf')]?_0x2ae12d[_0xaf66('0xf')][_0xaf66('0x10')]===undefined?!![]:![]:!![]})[_0xaf66('0x5')](function(_0x3c5609){logger[_0xaf66('0x6')](_0xaf66('0x1a'),_0x2ae12d);logger[_0xaf66('0x9')](_0xaf66('0x1a'),_0x2ae12d,JSON['stringify'](_0x3c5609));_0x43f5ad(_0x3c5609);})[_0xaf66('0xd')](function(_0x371564){logger['error'](_0xaf66('0x1a'),_0x371564['message'],_0x2ae12d);_0x458ec8(_0x44a5d2[_0xaf66('0xa')](0x1f4,_0x371564['message']));});});};exports[_0xaf66('0x1d')]=function(_0x178c67){var _0x187f1d=this;return new Promise(function(_0x574d4a,_0x170836){return db[_0xaf66('0xe')]['update'](_0x178c67[_0xaf66('0x1c')],{'raw':_0x178c67['options']?_0x178c67[_0xaf66('0xf')][_0xaf66('0x10')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x178c67[_0xaf66('0xf')]?_0x178c67['options'][_0xaf66('0x11')]||null:null,'attributes':_0x178c67['options']?_0x178c67[_0xaf66('0xf')][_0xaf66('0x12')]||null:null,'limit':_0x178c67['options']?_0x178c67[_0xaf66('0xf')][_0xaf66('0x13')]||null:null})['then'](function(_0x4863b0){logger['info'](_0xaf66('0x1d'),_0x178c67);logger[_0xaf66('0x6')](_0xaf66('0x1e'),JSON['stringify'](_0x178c67[_0xaf66('0xf')][_0xaf66('0x11')]),_0x178c67[_0xaf66('0x1c')]['active']);logger[_0xaf66('0x9')](_0xaf66('0x1d'),_0x178c67,JSON['stringify'](_0x4863b0));_0x574d4a(_0x4863b0);})[_0xaf66('0xd')](function(_0x1feee0){logger[_0xaf66('0xa')]('UpdateCmHopper',_0x1feee0[_0xaf66('0xb')],_0x178c67);_0x170836(_0x187f1d[_0xaf66('0xa')](0x1f4,_0x1feee0[_0xaf66('0xb')]));});});};exports[_0xaf66('0x1f')]=function(_0x50027d){var _0x3cff12=this;return new Promise(function(_0x3f836c,_0xfc2a6){return db[_0xaf66('0xe')][_0xaf66('0x20')]({'where':_0x50027d['options']?_0x50027d[_0xaf66('0xf')][_0xaf66('0x11')]||null:null})[_0xaf66('0x5')](function(_0x966d40){logger[_0xaf66('0x6')]('DestroyCmHopper',_0x50027d);logger[_0xaf66('0x9')](_0xaf66('0x1f'),_0x50027d,JSON[_0xaf66('0x18')](_0x966d40));_0x3f836c(_0x966d40);})[_0xaf66('0xd')](function(_0x82cc85){logger['error'](_0xaf66('0x1f'),_0x82cc85[_0xaf66('0xb')],_0x50027d);_0xfc2a6(_0x3cff12['error'](0x1f4,_0x82cc85[_0xaf66('0xb')]));});});};exports[_0xaf66('0x21')]=function(_0x5225f5){var _0x20023b=this;return new Promise(function(_0x4c2574,_0x56e11b){return db[_0xaf66('0x22')][_0xaf66('0x23')]()[_0xaf66('0x5')](function(_0xf28d79){return db[_0xaf66('0x24')][_0xaf66('0x25')](function(_0xf245f5){return db[_0xaf66('0xe')][_0xaf66('0x26')]({'where':_0x5225f5['options']?_0x5225f5[_0xaf66('0xf')][_0xaf66('0x11')]||null:null,'attributes':_0x5225f5[_0xaf66('0xf')]?_0x5225f5[_0xaf66('0xf')][_0xaf66('0x12')]||null:null,'limit':_0x5225f5[_0xaf66('0xf')]?_0x5225f5[_0xaf66('0xf')]['limit']||null:null,'order':_0x5225f5[_0xaf66('0xf')]?_0x5225f5[_0xaf66('0xf')][_0xaf66('0x27')]||null:null,'transaction':_0xf245f5,'lock':_0xf245f5[_0xaf66('0x28')]['UPDATE'],'include':[{'model':db[_0xaf66('0x22')],'as':_0xaf66('0x29'),'attributes':_[_0xaf66('0x2a')](_0xf28d79)},{'model':db[_0xaf66('0x2b')],'as':_0xaf66('0x2c'),'attributes':['id',_0xaf66('0x2d'),_0xaf66('0x2e')]}]})[_0xaf66('0x5')](function(_0x5c8b99){var _0x320202=[];var _0xf96b81=[];for(var _0x401a0e=0x0;_0x401a0e<_0x5c8b99['length'];_0x401a0e+=0x1){var _0x4b3e31=_0x5c8b99[_0x401a0e][_0xaf66('0x2f')];if(_0x4b3e31===null){_0x320202[_0xaf66('0x30')](_0x5c8b99[_0x401a0e]['update'](_0x5225f5[_0xaf66('0x1c')],{'transaction':_0xf245f5}));}else if(!_0xf96b81[_0xaf66('0x31')](_0x4b3e31)){_0xf96b81[_0xaf66('0x30')](_0x4b3e31);_0x320202[_0xaf66('0x30')](_0x5c8b99[_0x401a0e][_0xaf66('0x32')](_0x5225f5['body'],{'transaction':_0xf245f5}));}}return BPromise[_0xaf66('0x33')](_0x320202);});})[_0xaf66('0x5')](function(_0x1225e8){logger[_0xaf66('0x6')](_0xaf66('0x21'),_0x5225f5);if(_0x1225e8[_0xaf66('0x34')]>0x0){logger['info'](_0xaf66('0x35'),_0x1225e8[0x0][_0xaf66('0x36')]['id'],_0x1225e8[0x0][_0xaf66('0x36')][_0xaf66('0x37')],_0x1225e8[0x0][_0xaf66('0x36')][_0xaf66('0x38')]);}logger[_0xaf66('0x9')]('GetContactDialer',_0x5225f5,JSON[_0xaf66('0x18')](_0x1225e8));_0x4c2574(_0x1225e8);})['catch'](function(_0x12d32a){logger[_0xaf66('0xa')](_0xaf66('0x21'),_0x12d32a[_0xaf66('0xb')],_0x5225f5);_0x56e11b(_0x20023b[_0xaf66('0xa')](0x1f4,_0x12d32a[_0xaf66('0xb')]));});});});};exports[_0xaf66('0x39')]=function(_0x23b75e){var _0x4eeda3=this;return new Promise(function(_0x5297ce,_0x5bcda0){return db[_0xaf66('0x24')][_0xaf66('0x25')](function(_0x30124c){return db[_0xaf66('0x3a')][_0xaf66('0x1b')](_0x23b75e['body'],{'raw':_0x23b75e[_0xaf66('0xf')]?_0x23b75e[_0xaf66('0xf')][_0xaf66('0x10')]===undefined?!![]:![]:!![],'transaction':_0x30124c})[_0xaf66('0x5')](function(){logger[_0xaf66('0x6')](_0xaf66('0x3b'),JSON[_0xaf66('0x18')](_0x23b75e[_0xaf66('0xf')][_0xaf66('0x11')]),_0x23b75e[_0xaf66('0xf')][_0xaf66('0x11')][_0xaf66('0x38')]);return db['CmHopper']['destroy']({'where':_0x23b75e[_0xaf66('0xf')]?_0x23b75e['options']['where']||null:null,'transaction':_0x30124c});});})[_0xaf66('0x5')](function(_0x1d695d){logger[_0xaf66('0x6')]('MoveContactManagedDialer',_0x23b75e);logger['debug'](_0xaf66('0x39'),_0x23b75e,JSON[_0xaf66('0x18')](_0x1d695d));_0x5297ce(_0x1d695d);})['catch'](function(_0x4f22e5){logger[_0xaf66('0xa')](_0xaf66('0x39'),_0x4f22e5[_0xaf66('0xb')],_0x23b75e);_0x5bcda0(_0x4eeda3[_0xaf66('0xa')](0x1f4,_0x4f22e5['message']));});});};exports['CountReScheduled']=function(_0x58c3e3){var _0x168b46=this;return new Promise(function(_0x884d2a,_0x3c1cb8){return db[_0xaf66('0xe')][_0xaf66('0x26')]({'raw':_0x58c3e3[_0xaf66('0xf')]?_0x58c3e3[_0xaf66('0xf')][_0xaf66('0x10')]===undefined?!![]:![]:!![],'where':_0x58c3e3['options']?_0x58c3e3[_0xaf66('0xf')][_0xaf66('0x11')]||null:null,'attributes':[[db['sequelize']['fn'](_0xaf66('0x3c'),db['sequelize']['fn']('IF',db['sequelize'][_0xaf66('0x3d')](_0xaf66('0x3e')+util[_0xaf66('0x3f')](_0xaf66('0x40'),moment()[_0xaf66('0x3f')](_0xaf66('0x41')))+_0xaf66('0x42')))),_0xaf66('0x43')]]})[_0xaf66('0x5')](function(_0xa8aaa1){logger[_0xaf66('0x6')](_0xaf66('0x44'),_0x58c3e3);logger['debug'](_0xaf66('0x44'),_0x58c3e3,JSON[_0xaf66('0x18')](_0xa8aaa1));_0x884d2a(_0xa8aaa1);})[_0xaf66('0xd')](function(_0x18a322){logger[_0xaf66('0xa')](_0xaf66('0x44'),_0x18a322[_0xaf66('0xb')],_0x58c3e3);_0x3c1cb8(_0x168b46[_0xaf66('0xa')](0x1f4,_0x18a322[_0xaf66('0xb')]));});});};exports[_0xaf66('0x45')]=function(_0x4b5627){var _0x3a938a=this;return new Promise(function(_0x4da631,_0x197dc4){return db[_0xaf66('0x22')]['describe']()[_0xaf66('0x5')](function(_0x15cfc6){return db[_0xaf66('0x24')][_0xaf66('0x25')](function(_0x2c5a67){return db[_0xaf66('0xe')][_0xaf66('0x26')]({'where':_0x4b5627['options']?_0x4b5627[_0xaf66('0xf')][_0xaf66('0x11')]||null:null,'attributes':_0x4b5627['options']?_0x4b5627[_0xaf66('0xf')][_0xaf66('0x12')]||null:null,'limit':0x1,'order':_0x4b5627['options']?_0x4b5627[_0xaf66('0xf')][_0xaf66('0x27')]||null:null,'group':db['CmHopper']['UserId'],'transaction':_0x2c5a67,'lock':_0x2c5a67['LOCK'][_0xaf66('0x46')],'include':_0x4b5627[_0xaf66('0xf')]?_0x4b5627[_0xaf66('0xf')][_0xaf66('0x14')]?_[_0xaf66('0x16')](_0x4b5627[_0xaf66('0xf')][_0xaf66('0x14')],function(_0xbce4d6){return{'model':db[_0xbce4d6[_0xaf66('0x15')]],'as':_0xbce4d6['as'],'attributes':_0xbce4d6[_0xaf66('0x12')],'include':_0xbce4d6[_0xaf66('0x14')]?_['map'](_0xbce4d6[_0xaf66('0x14')],function(_0x40d230){return{'model':db[_0x40d230[_0xaf66('0x15')]],'as':_0x40d230['as'],'attributes':_0x40d230['attributes'],'include':_0x40d230[_0xaf66('0x14')]?_[_0xaf66('0x16')](_0x40d230['include'],function(_0x37cf9b){return{'model':db[_0x37cf9b[_0xaf66('0x15')]],'as':_0x37cf9b['as'],'attributes':_0x37cf9b[_0xaf66('0x12')]};}):[]};}):[]};}):[]:[]})[_0xaf66('0x5')](function(_0x2efae2){var _0x318fcd=[];for(var _0x2c03da=0x0;_0x2c03da<_0x2efae2[_0xaf66('0x34')];_0x2c03da+=0x1){_0x318fcd['push'](_0x2efae2[_0x2c03da][_0xaf66('0x32')](_0x4b5627[_0xaf66('0x1c')],{'transaction':_0x2c5a67}));}return BPromise[_0xaf66('0x33')](_0x318fcd);});})['then'](function(_0x214674){logger['info']('GetContactRecallMe',_0x4b5627);logger[_0xaf66('0x9')]('GetContactRecallMe',_0x4b5627,JSON[_0xaf66('0x18')](_0x214674));_0x4da631(_0x214674);})[_0xaf66('0xd')](function(_0x3cd7cf){logger[_0xaf66('0xa')](_0xaf66('0x45'),_0x3cd7cf['message'],_0x4b5627);_0x197dc4(_0x3a938a[_0xaf66('0xa')](0x1f4,_0x3cd7cf[_0xaf66('0xb')]));});});});};exports['GetCmHopperPreview']=function(_0x4cb990){var _0x25f152=this;return new Promise(function(_0x5c6d36,_0x1146bc){db[_0xaf66('0x22')]['describe']()[_0xaf66('0x5')](function(_0x1fb4dc){return db['CmHopper']['findAll']({'raw':_0x4cb990[_0xaf66('0xf')]?_0x4cb990[_0xaf66('0xf')][_0xaf66('0x10')]===undefined?!![]:![]:!![],'where':_0x4cb990['options']?_0x4cb990[_0xaf66('0xf')][_0xaf66('0x11')]||null:null,'attributes':_0x4cb990[_0xaf66('0xf')]?_0x4cb990[_0xaf66('0xf')][_0xaf66('0x12')]||null:null,'limit':_0x4cb990[_0xaf66('0xf')]?_0x4cb990[_0xaf66('0xf')][_0xaf66('0x13')]||null:null,'include':_0x4cb990[_0xaf66('0xf')]?_0x4cb990[_0xaf66('0xf')][_0xaf66('0x14')]?_[_0xaf66('0x16')](_0x4cb990[_0xaf66('0xf')][_0xaf66('0x14')],function(_0x56ae57){return{'model':db[_0x56ae57[_0xaf66('0x15')]],'as':_0x56ae57['as'],'attributes':_0x56ae57['as']==='Contact'?_[_0xaf66('0x2a')](_0x1fb4dc):_0x56ae57['attributes'],'include':_0x56ae57[_0xaf66('0x14')]?_[_0xaf66('0x16')](_0x56ae57[_0xaf66('0x14')],function(_0x37dda6){return{'model':db[_0x37dda6[_0xaf66('0x15')]],'as':_0x37dda6['as'],'attributes':_0x37dda6['attributes'],'include':_0x37dda6[_0xaf66('0x14')]?_[_0xaf66('0x16')](_0x37dda6[_0xaf66('0x14')],function(_0x2d7cd6){return{'model':db[_0x2d7cd6[_0xaf66('0x15')]],'as':_0x2d7cd6['as'],'attributes':_0x2d7cd6[_0xaf66('0x12')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x1e8188){logger['info'](_0xaf66('0x17'),_0x4cb990);logger[_0xaf66('0x9')]('GetCmHopper',_0x4cb990,JSON['stringify'](_0x1e8188));_0x5c6d36(_0x1e8188);})[_0xaf66('0xd')](function(_0xec5c10){logger[_0xaf66('0xa')](_0xaf66('0x17'),_0xec5c10[_0xaf66('0xb')],_0x4cb990);_0x1146bc(_0x25f152[_0xaf66('0xa')](0x1f4,_0xec5c10[_0xaf66('0xb')]));});});});};exports[_0xaf66('0x47')]=function(_0x18cb4f){var _0x23c381=this;return new Promise(function(_0x1df1ff,_0x52f9be){return db[_0xaf66('0x22')][_0xaf66('0x48')]({'raw':!![],'where':{'phone':_0x18cb4f[_0xaf66('0xf')][_0xaf66('0x11')][_0xaf66('0x49')]},'attributes':['id',_0xaf66('0x4a')],'order':[['id','DESC']]})[_0xaf66('0x5')](function(_0x3c42d3){logger[_0xaf66('0x6')]('getContactByPhone',_0x18cb4f);logger[_0xaf66('0x9')]('getContactByPhone',_0x18cb4f,JSON[_0xaf66('0x18')](_0x3c42d3));_0x1df1ff(_0x3c42d3);})[_0xaf66('0xd')](function(_0x1f1033){logger[_0xaf66('0xa')](_0xaf66('0x4b'),_0x1f1033['message'],_0x18cb4f);_0x52f9be(_0x23c381[_0xaf66('0xa')](0x1f4,_0x1f1033[_0xaf66('0xb')]));});});};exports['ResetActiveCalls']=function(_0x4ad901){var _0x51e89c=this;return new Promise(function(_0x12accb,_0x2c027b){return db[_0xaf66('0x24')][_0xaf66('0x25')](function(_0x400b98){return db[_0xaf66('0xe')][_0xaf66('0x32')](_0x4ad901['body'],{'where':{},'transaction':_0x400b98})[_0xaf66('0x5')](function(_0x3d3e59){logger[_0xaf66('0x6')](_0xaf66('0x4c'),_0x4ad901);logger[_0xaf66('0x9')]('ResetActiveCalls',_0x4ad901,JSON[_0xaf66('0x18')](_0x3d3e59));_0x12accb(_0x3d3e59);})[_0xaf66('0xd')](function(_0x230431){logger[_0xaf66('0xa')](_0xaf66('0x4c'),_0x230431[_0xaf66('0xb')],_0x4ad901);_0x2c027b(_0x51e89c['error'](0x1f4,_0x230431[_0xaf66('0xb')]));});});});};exports[_0xaf66('0x4d')]=function(_0x10fad0){var _0x136760=this;var _0x3d2252=_0x10fad0[_0xaf66('0x1c')]['where'][_0xaf66('0x4e')];var _0x173fa3=_0x10fad0[_0xaf66('0x1c')][_0xaf66('0x11')][_0xaf66('0x4f')];var _0x364081=_0x10fad0[_0xaf66('0x1c')][_0xaf66('0x11')]['availableAgentsIds'];return new Promise(function(_0x390935,_0x7b0e58){return db[_0xaf66('0xe')][_0xaf66('0x26')]({'where':{'voiceQueueId':{'$in':_0x3d2252},'recallme':0x1,'active':0x0,'recallmeNotifiedDate':{'$eq':null},'scheduledat':{'$and':{'$lte':db[_0xaf66('0x24')][_0xaf66('0x3d')](_0xaf66('0x50')+_0x173fa3+'\x20MINUTE'),'$gt':db[_0xaf66('0x24')][_0xaf66('0x3d')]('NOW()')}},'UserId':{'$in':_0x364081}},'include':[{'model':db[_0xaf66('0x22')],'as':_0xaf66('0x29')},{'model':db['User'],'as':_0xaf66('0x2c'),'attributes':['id',_0xaf66('0x2d'),'voicePause']},{'model':db[_0xaf66('0x51')],'as':_0xaf66('0x52')}]})[_0xaf66('0x5')](function(_0x5bb5e8){if(_0x5bb5e8[_0xaf66('0x34')]>0x0){return db[_0xaf66('0x24')][_0xaf66('0x25')](function(_0x87aa47){return db['CmHopper'][_0xaf66('0x32')]({'recallmeNotifiedDate':db['sequelize'][_0xaf66('0x3d')](_0xaf66('0x53'))},{'where':{'id':{'$in':_['map'](_0x5bb5e8,'id')}},'transaction':_0x87aa47})[_0xaf66('0x5')](function(){_0x390935(_0x5bb5e8);})[_0xaf66('0xd')](function(_0x341df2){logger[_0xaf66('0xa')](_0xaf66('0x4d'),_0x341df2['message'],_0x10fad0);_0x7b0e58(_0x136760['error'](0x1f4,_0x341df2['message']));});})['catch'](function(_0x4ff4af){logger['error'](_0xaf66('0x4d'),_0x4ff4af[_0xaf66('0xb')],_0x10fad0);_0x7b0e58(_0x136760[_0xaf66('0xa')](0x1f4,_0x4ff4af['message']));});}else{_0x390935(_0x5bb5e8);}});});};