Built motion from commit (unavailable).|2.5.17
[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 _0x30dc=['includes','UserId','push','all','GetContactDialer','MoveContactManagedDialer','sequelize','COUNT','literal','`scheduledat`\x20>=\x20','format','\x22%s\x22','YYYY-MM-DD\x20HH:mm:ss','CountReScheduled','GetContactRecallMe','order','LOCK','GetCmHopperPreview','lodash','util','moment','bluebird','randomstring','ioredis','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','http','request','then','info','CmHopper,\x20%s,\x20%s','debug','error','message','request\x20sent','result','catch','GetCmHopper','CmHopper','findAll','options','raw','where','attributes','limit','include','map','model','stringify','ShowCmHopper','find','CreateCmHopper','body','UpdateCmHopper','update','DestroyCmHopper','destroy','CmContact','describe','transaction','UPDATE','Contact','name','voicePause','length'];(function(_0x14add3,_0x13ce8d){var _0x4a174f=function(_0x2b3ed7){while(--_0x2b3ed7){_0x14add3['push'](_0x14add3['shift']());}};_0x4a174f(++_0x13ce8d);}(_0x30dc,0x9a));var _0xc30d=function(_0x57041d,_0x3c34ad){_0x57041d=_0x57041d-0x0;var _0x5c5372=_0x30dc[_0x57041d];return _0x5c5372;};'use strict';var _=require(_0xc30d('0x0'));var util=require(_0xc30d('0x1'));var moment=require(_0xc30d('0x2'));var BPromise=require(_0xc30d('0x3'));var rs=require(_0xc30d('0x4'));var fs=require('fs');var Redis=require(_0xc30d('0x5'));var db=require('../../mysqldb')['db'];var utils=require(_0xc30d('0x6'));var logger=require(_0xc30d('0x7'))(_0xc30d('0x8'));var config=require(_0xc30d('0x9'));var jayson=require(_0xc30d('0xa'));var client=jayson['client'][_0xc30d('0xb')]({'port':0x232a});function respondWithRpcPromise(_0x466e07,_0x268ef7,_0x466664){return new BPromise(function(_0x3a503b,_0x12d53d){return client[_0xc30d('0xc')](_0x466e07,_0x466664)[_0xc30d('0xd')](function(_0x5e81e2){logger[_0xc30d('0xe')](_0xc30d('0xf'),_0x268ef7,'request\x20sent');logger[_0xc30d('0x10')]('CmHopper,\x20%s,\x20%s,\x20%s',_0x268ef7,'request\x20sent',JSON['stringify'](_0x5e81e2));if(_0x5e81e2[_0xc30d('0x11')]){if(_0x5e81e2['error']['code']===0x1f4){logger[_0xc30d('0x11')]('CmHopper,\x20%s,\x20%s',_0x268ef7,_0x5e81e2[_0xc30d('0x11')][_0xc30d('0x12')]);return _0x12d53d(_0x5e81e2[_0xc30d('0x11')][_0xc30d('0x12')]);}logger[_0xc30d('0x11')]('CmHopper,\x20%s,\x20%s',_0x268ef7,_0x5e81e2[_0xc30d('0x11')][_0xc30d('0x12')]);return _0x3a503b(_0x5e81e2[_0xc30d('0x11')][_0xc30d('0x12')]);}else{logger['info'](_0xc30d('0xf'),_0x268ef7,_0xc30d('0x13'));_0x3a503b(_0x5e81e2[_0xc30d('0x14')][_0xc30d('0x12')]);}})[_0xc30d('0x15')](function(_0x2fea18){logger['error'](_0xc30d('0xf'),_0x268ef7,_0x2fea18);_0x12d53d(_0x2fea18);});});}exports[_0xc30d('0x16')]=function(_0x11f1b7){var _0x157401=this;return new Promise(function(_0x10e370,_0x5373fd){return db[_0xc30d('0x17')][_0xc30d('0x18')]({'raw':_0x11f1b7[_0xc30d('0x19')]?_0x11f1b7[_0xc30d('0x19')][_0xc30d('0x1a')]===undefined?!![]:![]:!![],'where':_0x11f1b7[_0xc30d('0x19')]?_0x11f1b7[_0xc30d('0x19')][_0xc30d('0x1b')]||null:null,'attributes':_0x11f1b7['options']?_0x11f1b7[_0xc30d('0x19')][_0xc30d('0x1c')]||null:null,'limit':_0x11f1b7['options']?_0x11f1b7[_0xc30d('0x19')][_0xc30d('0x1d')]||null:null,'include':_0x11f1b7[_0xc30d('0x19')]?_0x11f1b7[_0xc30d('0x19')][_0xc30d('0x1e')]?_[_0xc30d('0x1f')](_0x11f1b7[_0xc30d('0x19')][_0xc30d('0x1e')],function(_0x1f0e9f){return{'model':db[_0x1f0e9f[_0xc30d('0x20')]],'as':_0x1f0e9f['as'],'attributes':_0x1f0e9f[_0xc30d('0x1c')],'include':_0x1f0e9f[_0xc30d('0x1e')]?_[_0xc30d('0x1f')](_0x1f0e9f['include'],function(_0x4a6bc8){return{'model':db[_0x4a6bc8[_0xc30d('0x20')]],'as':_0x4a6bc8['as'],'attributes':_0x4a6bc8[_0xc30d('0x1c')],'include':_0x4a6bc8[_0xc30d('0x1e')]?_[_0xc30d('0x1f')](_0x4a6bc8['include'],function(_0x4d0830){return{'model':db[_0x4d0830['model']],'as':_0x4d0830['as'],'attributes':_0x4d0830[_0xc30d('0x1c')]};}):[]};}):[]};}):[]:[]})[_0xc30d('0xd')](function(_0x417548){logger[_0xc30d('0xe')](_0xc30d('0x16'),_0x11f1b7);logger[_0xc30d('0x10')](_0xc30d('0x16'),_0x11f1b7,JSON[_0xc30d('0x21')](_0x417548));_0x10e370(_0x417548);})['catch'](function(_0x40e973){logger['error'](_0xc30d('0x16'),_0x40e973['message'],_0x11f1b7);_0x5373fd(_0x157401[_0xc30d('0x11')](0x1f4,_0x40e973[_0xc30d('0x12')]));});});};exports[_0xc30d('0x22')]=function(_0x557759){var _0xa9da11=this;return new Promise(function(_0x2dfeda,_0x11da77){return db[_0xc30d('0x17')][_0xc30d('0x23')]({'raw':_0x557759['options']?_0x557759[_0xc30d('0x19')]['raw']===undefined?!![]:![]:!![],'where':_0x557759[_0xc30d('0x19')]?_0x557759[_0xc30d('0x19')]['where']||null:null,'attributes':_0x557759[_0xc30d('0x19')]?_0x557759[_0xc30d('0x19')]['attributes']||null:null,'include':_0x557759[_0xc30d('0x19')]?_0x557759['options'][_0xc30d('0x1e')]?_[_0xc30d('0x1f')](_0x557759[_0xc30d('0x19')][_0xc30d('0x1e')],function(_0x33e4da){return{'model':db[_0x33e4da[_0xc30d('0x20')]],'as':_0x33e4da['as'],'attributes':_0x33e4da[_0xc30d('0x1c')],'include':_0x33e4da[_0xc30d('0x1e')]?_[_0xc30d('0x1f')](_0x33e4da[_0xc30d('0x1e')],function(_0x7d7a5){return{'model':db[_0x7d7a5[_0xc30d('0x20')]],'as':_0x7d7a5['as'],'attributes':_0x7d7a5[_0xc30d('0x1c')],'include':_0x7d7a5[_0xc30d('0x1e')]?_[_0xc30d('0x1f')](_0x7d7a5[_0xc30d('0x1e')],function(_0x2b2f5f){return{'model':db[_0x2b2f5f[_0xc30d('0x20')]],'as':_0x2b2f5f['as'],'attributes':_0x2b2f5f[_0xc30d('0x1c')]};}):[]};}):[]};}):[]:[]})[_0xc30d('0xd')](function(_0x1924e7){logger[_0xc30d('0xe')]('ShowCmHopper',_0x557759);logger[_0xc30d('0x10')](_0xc30d('0x22'),_0x557759,JSON['stringify'](_0x1924e7));_0x2dfeda(_0x1924e7);})[_0xc30d('0x15')](function(_0x190855){logger[_0xc30d('0x11')]('ShowCmHopper',_0x190855[_0xc30d('0x12')],_0x557759);_0x11da77(_0xa9da11['error'](0x1f4,_0x190855['message']));});});};exports[_0xc30d('0x24')]=function(_0xa977b){var _0x43f52b=this;return new Promise(function(_0x5732ea,_0x3b7927){return db['CmHopper']['create'](_0xa977b[_0xc30d('0x25')],{'raw':_0xa977b['options']?_0xa977b[_0xc30d('0x19')][_0xc30d('0x1a')]===undefined?!![]:![]:!![]})[_0xc30d('0xd')](function(_0x8fe816){logger[_0xc30d('0xe')](_0xc30d('0x24'),_0xa977b);logger[_0xc30d('0x10')](_0xc30d('0x24'),_0xa977b,JSON['stringify'](_0x8fe816));_0x5732ea(_0x8fe816);})[_0xc30d('0x15')](function(_0x26aa60){logger[_0xc30d('0x11')](_0xc30d('0x24'),_0x26aa60['message'],_0xa977b);_0x3b7927(_0x43f52b['error'](0x1f4,_0x26aa60[_0xc30d('0x12')]));});});};exports[_0xc30d('0x26')]=function(_0x107382){var _0x3011c9=this;return new Promise(function(_0x5d687e,_0x1dc2b3){return db[_0xc30d('0x17')][_0xc30d('0x27')](_0x107382['body'],{'raw':_0x107382['options']?_0x107382['options']['raw']===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x107382[_0xc30d('0x19')]?_0x107382[_0xc30d('0x19')][_0xc30d('0x1b')]||null:null,'attributes':_0x107382['options']?_0x107382[_0xc30d('0x19')]['attributes']||null:null,'limit':_0x107382['options']?_0x107382[_0xc30d('0x19')][_0xc30d('0x1d')]||null:null})['then'](function(_0x10f6c9){logger['info'](_0xc30d('0x26'),_0x107382);logger[_0xc30d('0x10')](_0xc30d('0x26'),_0x107382,JSON[_0xc30d('0x21')](_0x10f6c9));_0x5d687e(_0x10f6c9);})[_0xc30d('0x15')](function(_0x1e4646){logger[_0xc30d('0x11')](_0xc30d('0x26'),_0x1e4646['message'],_0x107382);_0x1dc2b3(_0x3011c9[_0xc30d('0x11')](0x1f4,_0x1e4646[_0xc30d('0x12')]));});});};exports[_0xc30d('0x28')]=function(_0x1c3480){var _0x57e5b5=this;return new Promise(function(_0xa57208,_0x5903ca){return db[_0xc30d('0x17')][_0xc30d('0x29')]({'where':_0x1c3480[_0xc30d('0x19')]?_0x1c3480['options'][_0xc30d('0x1b')]||null:null})['then'](function(_0x14477c){logger[_0xc30d('0xe')](_0xc30d('0x28'),_0x1c3480);logger[_0xc30d('0x10')](_0xc30d('0x28'),_0x1c3480,JSON[_0xc30d('0x21')](_0x14477c));_0xa57208(_0x14477c);})['catch'](function(_0x28cae7){logger['error']('DestroyCmHopper',_0x28cae7[_0xc30d('0x12')],_0x1c3480);_0x5903ca(_0x57e5b5[_0xc30d('0x11')](0x1f4,_0x28cae7['message']));});});};exports['GetContactDialer']=function(_0x3bae12){var _0x8fce0c=this;return new Promise(function(_0x28ad76,_0x1fa364){return db[_0xc30d('0x2a')][_0xc30d('0x2b')]()[_0xc30d('0xd')](function(_0x5aeb63){return db['sequelize'][_0xc30d('0x2c')](function(_0x2e835b){return db['CmHopper'][_0xc30d('0x18')]({'where':_0x3bae12[_0xc30d('0x19')]?_0x3bae12[_0xc30d('0x19')][_0xc30d('0x1b')]||null:null,'attributes':_0x3bae12[_0xc30d('0x19')]?_0x3bae12[_0xc30d('0x19')][_0xc30d('0x1c')]||null:null,'limit':_0x3bae12[_0xc30d('0x19')]?_0x3bae12[_0xc30d('0x19')][_0xc30d('0x1d')]||null:null,'order':_0x3bae12[_0xc30d('0x19')]?_0x3bae12[_0xc30d('0x19')]['order']||null:null,'transaction':_0x2e835b,'lock':_0x2e835b['LOCK'][_0xc30d('0x2d')],'include':[{'model':db[_0xc30d('0x2a')],'as':_0xc30d('0x2e'),'attributes':_['keys'](_0x5aeb63)},{'model':db['User'],'as':'Agent','attributes':['id',_0xc30d('0x2f'),_0xc30d('0x30')]}]})[_0xc30d('0xd')](function(_0x4dbbb2){var _0x244280=[];var _0x4c71cb=[];for(var _0x566fa7=0x0;_0x566fa7<_0x4dbbb2[_0xc30d('0x31')];_0x566fa7+=0x1){if(!_0x4c71cb[_0xc30d('0x32')](_0x4dbbb2[_0x566fa7]['UserId'])){_0x4c71cb['push'](_0x4dbbb2[_0x566fa7][_0xc30d('0x33')]);_0x244280[_0xc30d('0x34')](_0x4dbbb2[_0x566fa7][_0xc30d('0x27')](_0x3bae12[_0xc30d('0x25')],{'transaction':_0x2e835b}));}}return BPromise[_0xc30d('0x35')](_0x244280);});})[_0xc30d('0xd')](function(_0x66b490){logger[_0xc30d('0xe')](_0xc30d('0x36'),_0x3bae12);logger[_0xc30d('0x10')](_0xc30d('0x36'),_0x3bae12,JSON['stringify'](_0x66b490));_0x28ad76(_0x66b490);})[_0xc30d('0x15')](function(_0xee47db){logger[_0xc30d('0x11')]('GetContactDialer',_0xee47db['message'],_0x3bae12);_0x1fa364(_0x8fce0c[_0xc30d('0x11')](0x1f4,_0xee47db[_0xc30d('0x12')]));});});});};exports[_0xc30d('0x37')]=function(_0x178bc4){var _0x308004=this;return new Promise(function(_0x101e2e,_0x26f2c7){return db['sequelize'][_0xc30d('0x2c')](function(_0x44ef62){return db['CmHopperFinal']['create'](_0x178bc4[_0xc30d('0x25')],{'raw':_0x178bc4[_0xc30d('0x19')]?_0x178bc4['options'][_0xc30d('0x1a')]===undefined?!![]:![]:!![],'transaction':_0x44ef62})[_0xc30d('0xd')](function(){return db[_0xc30d('0x17')][_0xc30d('0x29')]({'where':_0x178bc4[_0xc30d('0x19')]?_0x178bc4[_0xc30d('0x19')][_0xc30d('0x1b')]||null:null,'transaction':_0x44ef62});});})[_0xc30d('0xd')](function(_0x293d6e){logger[_0xc30d('0xe')](_0xc30d('0x37'),_0x178bc4);logger[_0xc30d('0x10')](_0xc30d('0x37'),_0x178bc4,JSON[_0xc30d('0x21')](_0x293d6e));_0x101e2e(_0x293d6e);})[_0xc30d('0x15')](function(_0x38da19){logger[_0xc30d('0x11')]('MoveContactManagedDialer',_0x38da19[_0xc30d('0x12')],_0x178bc4);_0x26f2c7(_0x308004[_0xc30d('0x11')](0x1f4,_0x38da19['message']));});});};exports['CountReScheduled']=function(_0x2a7710){var _0x56d8d1=this;return new Promise(function(_0xa0eab9,_0x170523){return db[_0xc30d('0x17')][_0xc30d('0x18')]({'raw':_0x2a7710['options']?_0x2a7710['options'][_0xc30d('0x1a')]===undefined?!![]:![]:!![],'where':_0x2a7710[_0xc30d('0x19')]?_0x2a7710[_0xc30d('0x19')][_0xc30d('0x1b')]||null:null,'attributes':[[db[_0xc30d('0x38')]['fn'](_0xc30d('0x39'),db[_0xc30d('0x38')]['fn']('IF',db['sequelize'][_0xc30d('0x3a')](_0xc30d('0x3b')+util[_0xc30d('0x3c')](_0xc30d('0x3d'),moment()[_0xc30d('0x3c')](_0xc30d('0x3e')))+'\x20,\x201,\x20null'))),'contactsRescheduled']]})[_0xc30d('0xd')](function(_0x585255){logger['info'](_0xc30d('0x3f'),_0x2a7710);logger[_0xc30d('0x10')]('CountReScheduled',_0x2a7710,JSON[_0xc30d('0x21')](_0x585255));_0xa0eab9(_0x585255);})[_0xc30d('0x15')](function(_0x45c052){logger[_0xc30d('0x11')](_0xc30d('0x3f'),_0x45c052[_0xc30d('0x12')],_0x2a7710);_0x170523(_0x56d8d1[_0xc30d('0x11')](0x1f4,_0x45c052[_0xc30d('0x12')]));});});};exports[_0xc30d('0x40')]=function(_0x363691){var _0x4d8aac=this;return new Promise(function(_0x3973c9,_0x1fbc34){return db[_0xc30d('0x2a')][_0xc30d('0x2b')]()[_0xc30d('0xd')](function(_0xd905d5){return db[_0xc30d('0x38')]['transaction'](function(_0x120f6a){return db[_0xc30d('0x17')][_0xc30d('0x18')]({'where':_0x363691[_0xc30d('0x19')]?_0x363691[_0xc30d('0x19')][_0xc30d('0x1b')]||null:null,'attributes':_0x363691[_0xc30d('0x19')]?_0x363691[_0xc30d('0x19')][_0xc30d('0x1c')]||null:null,'limit':0x1,'order':_0x363691[_0xc30d('0x19')]?_0x363691[_0xc30d('0x19')][_0xc30d('0x41')]||null:null,'group':db[_0xc30d('0x17')][_0xc30d('0x33')],'transaction':_0x120f6a,'lock':_0x120f6a[_0xc30d('0x42')]['UPDATE'],'include':_0x363691[_0xc30d('0x19')]?_0x363691['options'][_0xc30d('0x1e')]?_[_0xc30d('0x1f')](_0x363691[_0xc30d('0x19')][_0xc30d('0x1e')],function(_0x2640f6){return{'model':db[_0x2640f6['model']],'as':_0x2640f6['as'],'attributes':_0x2640f6['attributes'],'include':_0x2640f6[_0xc30d('0x1e')]?_[_0xc30d('0x1f')](_0x2640f6['include'],function(_0x2e025d){return{'model':db[_0x2e025d[_0xc30d('0x20')]],'as':_0x2e025d['as'],'attributes':_0x2e025d[_0xc30d('0x1c')],'include':_0x2e025d['include']?_[_0xc30d('0x1f')](_0x2e025d['include'],function(_0x41c8ed){return{'model':db[_0x41c8ed[_0xc30d('0x20')]],'as':_0x41c8ed['as'],'attributes':_0x41c8ed[_0xc30d('0x1c')]};}):[]};}):[]};}):[]:[]})[_0xc30d('0xd')](function(_0x1e4071){var _0x3ccef6=[];for(var _0x199292=0x0;_0x199292<_0x1e4071[_0xc30d('0x31')];_0x199292+=0x1){_0x3ccef6[_0xc30d('0x34')](_0x1e4071[_0x199292][_0xc30d('0x27')](_0x363691[_0xc30d('0x25')],{'transaction':_0x120f6a}));}return BPromise[_0xc30d('0x35')](_0x3ccef6);});})[_0xc30d('0xd')](function(_0x2f5754){logger['info'](_0xc30d('0x40'),_0x363691);logger[_0xc30d('0x10')](_0xc30d('0x40'),_0x363691,JSON[_0xc30d('0x21')](_0x2f5754));_0x3973c9(_0x2f5754);})['catch'](function(_0x24746d){logger['error'](_0xc30d('0x40'),_0x24746d['message'],_0x363691);_0x1fbc34(_0x4d8aac[_0xc30d('0x11')](0x1f4,_0x24746d[_0xc30d('0x12')]));});});});};exports[_0xc30d('0x43')]=function(_0x1ef26a){var _0x1b2849=this;return new Promise(function(_0x59cad5,_0x2a8564){db['CmContact']['describe']()[_0xc30d('0xd')](function(_0x545e86){return db[_0xc30d('0x17')]['findAll']({'raw':_0x1ef26a[_0xc30d('0x19')]?_0x1ef26a['options'][_0xc30d('0x1a')]===undefined?!![]:![]:!![],'where':_0x1ef26a['options']?_0x1ef26a[_0xc30d('0x19')][_0xc30d('0x1b')]||null:null,'attributes':_0x1ef26a[_0xc30d('0x19')]?_0x1ef26a[_0xc30d('0x19')][_0xc30d('0x1c')]||null:null,'limit':_0x1ef26a[_0xc30d('0x19')]?_0x1ef26a[_0xc30d('0x19')][_0xc30d('0x1d')]||null:null,'include':_0x1ef26a[_0xc30d('0x19')]?_0x1ef26a[_0xc30d('0x19')][_0xc30d('0x1e')]?_[_0xc30d('0x1f')](_0x1ef26a[_0xc30d('0x19')][_0xc30d('0x1e')],function(_0x4160ba){return{'model':db[_0x4160ba[_0xc30d('0x20')]],'as':_0x4160ba['as'],'attributes':_0x4160ba['as']===_0xc30d('0x2e')?_['keys'](_0x545e86):_0x4160ba[_0xc30d('0x1c')],'include':_0x4160ba[_0xc30d('0x1e')]?_[_0xc30d('0x1f')](_0x4160ba[_0xc30d('0x1e')],function(_0x1b17d2){return{'model':db[_0x1b17d2[_0xc30d('0x20')]],'as':_0x1b17d2['as'],'attributes':_0x1b17d2[_0xc30d('0x1c')],'include':_0x1b17d2['include']?_[_0xc30d('0x1f')](_0x1b17d2['include'],function(_0x569fa4){return{'model':db[_0x569fa4['model']],'as':_0x569fa4['as'],'attributes':_0x569fa4[_0xc30d('0x1c')]};}):[]};}):[]};}):[]:[]})[_0xc30d('0xd')](function(_0x4e2ca0){logger[_0xc30d('0xe')](_0xc30d('0x16'),_0x1ef26a);logger[_0xc30d('0x10')](_0xc30d('0x16'),_0x1ef26a,JSON[_0xc30d('0x21')](_0x4e2ca0));_0x59cad5(_0x4e2ca0);})['catch'](function(_0x36751f){logger['error'](_0xc30d('0x16'),_0x36751f[_0xc30d('0x12')],_0x1ef26a);_0x2a8564(_0x1b2849['error'](0x1f4,_0x36751f['message']));});});});};