Built motion from commit (unavailable).|2.5.1
[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 _0xad2e=['name','voicePause','length','includes','UserId','push','sequelize','CmHopperFinal','CountReScheduled','COUNT','literal','`scheduledat`\x20>=\x20','format','YYYY-MM-DD\x20HH:mm:ss','\x20,\x201,\x20null','contactsRescheduled','all','GetContactRecallMe','GetCmHopperPreview','Contact','util','moment','bluebird','randomstring','../../mysqldb','../../config/utils','../../config/logger','jayson/promise','client','http','request','then','info','CmHopper,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','result','catch','GetCmHopper','CmHopper','findAll','options','raw','where','limit','include','attributes','map','model','debug','find','ShowCmHopper','create','body','CreateCmHopper','UpdateCmHopper','update','DestroyCmHopper','destroy','GetContactDialer','CmContact','describe','transaction','order','LOCK','UPDATE','keys','User','Agent'];(function(_0x145fc7,_0x3907f4){var _0x241a7d=function(_0x49c355){while(--_0x49c355){_0x145fc7['push'](_0x145fc7['shift']());}};_0x241a7d(++_0x3907f4);}(_0xad2e,0xa4));var _0xead2=function(_0xed80dc,_0x1fa8dc){_0xed80dc=_0xed80dc-0x0;var _0x124c4d=_0xad2e[_0xed80dc];return _0x124c4d;};'use strict';var _=require('lodash');var util=require(_0xead2('0x0'));var moment=require(_0xead2('0x1'));var BPromise=require(_0xead2('0x2'));var rs=require(_0xead2('0x3'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0xead2('0x4'))['db'];var utils=require(_0xead2('0x5'));var logger=require(_0xead2('0x6'))('rpc');var config=require('../../config/environment');var jayson=require(_0xead2('0x7'));var client=jayson[_0xead2('0x8')][_0xead2('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x116dc8,_0xe506e8,_0x5dee3e){return new BPromise(function(_0x4a9845,_0x16e36c){return client[_0xead2('0xa')](_0x116dc8,_0x5dee3e)[_0xead2('0xb')](function(_0x534b1d){logger[_0xead2('0xc')](_0xead2('0xd'),_0xe506e8,_0xead2('0xe'));logger['debug']('CmHopper,\x20%s,\x20%s,\x20%s',_0xe506e8,_0xead2('0xe'),JSON[_0xead2('0xf')](_0x534b1d));if(_0x534b1d[_0xead2('0x10')]){if(_0x534b1d[_0xead2('0x10')][_0xead2('0x11')]===0x1f4){logger[_0xead2('0x10')](_0xead2('0xd'),_0xe506e8,_0x534b1d[_0xead2('0x10')][_0xead2('0x12')]);return _0x16e36c(_0x534b1d[_0xead2('0x10')]['message']);}logger[_0xead2('0x10')](_0xead2('0xd'),_0xe506e8,_0x534b1d[_0xead2('0x10')]['message']);return _0x4a9845(_0x534b1d[_0xead2('0x10')][_0xead2('0x12')]);}else{logger['info'](_0xead2('0xd'),_0xe506e8,_0xead2('0xe'));_0x4a9845(_0x534b1d[_0xead2('0x13')][_0xead2('0x12')]);}})[_0xead2('0x14')](function(_0x5f33bb){logger['error']('CmHopper,\x20%s,\x20%s',_0xe506e8,_0x5f33bb);_0x16e36c(_0x5f33bb);});});}exports[_0xead2('0x15')]=function(_0x5c6d69){var _0x5d2483=this;return new Promise(function(_0xdbbd6b,_0x19a24a){return db[_0xead2('0x16')][_0xead2('0x17')]({'raw':_0x5c6d69['options']?_0x5c6d69[_0xead2('0x18')][_0xead2('0x19')]===undefined?!![]:![]:!![],'where':_0x5c6d69[_0xead2('0x18')]?_0x5c6d69['options'][_0xead2('0x1a')]||null:null,'attributes':_0x5c6d69[_0xead2('0x18')]?_0x5c6d69[_0xead2('0x18')]['attributes']||null:null,'limit':_0x5c6d69[_0xead2('0x18')]?_0x5c6d69[_0xead2('0x18')][_0xead2('0x1b')]||null:null,'include':_0x5c6d69['options']?_0x5c6d69[_0xead2('0x18')][_0xead2('0x1c')]?_['map'](_0x5c6d69[_0xead2('0x18')][_0xead2('0x1c')],function(_0xf9e726){return{'model':db[_0xf9e726['model']],'as':_0xf9e726['as'],'attributes':_0xf9e726[_0xead2('0x1d')],'include':_0xf9e726[_0xead2('0x1c')]?_[_0xead2('0x1e')](_0xf9e726['include'],function(_0x4388df){return{'model':db[_0x4388df[_0xead2('0x1f')]],'as':_0x4388df['as'],'attributes':_0x4388df['attributes'],'include':_0x4388df['include']?_[_0xead2('0x1e')](_0x4388df[_0xead2('0x1c')],function(_0xfbf38d){return{'model':db[_0xfbf38d[_0xead2('0x1f')]],'as':_0xfbf38d['as'],'attributes':_0xfbf38d[_0xead2('0x1d')]};}):[]};}):[]};}):[]:[]})[_0xead2('0xb')](function(_0x2cd202){logger[_0xead2('0xc')]('GetCmHopper',_0x5c6d69);logger[_0xead2('0x20')](_0xead2('0x15'),_0x5c6d69,JSON[_0xead2('0xf')](_0x2cd202));_0xdbbd6b(_0x2cd202);})['catch'](function(_0x399201){logger[_0xead2('0x10')]('GetCmHopper',_0x399201[_0xead2('0x12')],_0x5c6d69);_0x19a24a(_0x5d2483[_0xead2('0x10')](0x1f4,_0x399201['message']));});});};exports['ShowCmHopper']=function(_0x3c9948){var _0x12a28e=this;return new Promise(function(_0x4afa7e,_0x3819ea){return db[_0xead2('0x16')][_0xead2('0x21')]({'raw':_0x3c9948[_0xead2('0x18')]?_0x3c9948[_0xead2('0x18')]['raw']===undefined?!![]:![]:!![],'where':_0x3c9948[_0xead2('0x18')]?_0x3c9948[_0xead2('0x18')]['where']||null:null,'attributes':_0x3c9948[_0xead2('0x18')]?_0x3c9948[_0xead2('0x18')][_0xead2('0x1d')]||null:null,'include':_0x3c9948[_0xead2('0x18')]?_0x3c9948[_0xead2('0x18')][_0xead2('0x1c')]?_[_0xead2('0x1e')](_0x3c9948[_0xead2('0x18')]['include'],function(_0x49b385){return{'model':db[_0x49b385[_0xead2('0x1f')]],'as':_0x49b385['as'],'attributes':_0x49b385[_0xead2('0x1d')],'include':_0x49b385[_0xead2('0x1c')]?_['map'](_0x49b385[_0xead2('0x1c')],function(_0x5e4517){return{'model':db[_0x5e4517[_0xead2('0x1f')]],'as':_0x5e4517['as'],'attributes':_0x5e4517['attributes'],'include':_0x5e4517[_0xead2('0x1c')]?_[_0xead2('0x1e')](_0x5e4517[_0xead2('0x1c')],function(_0xaf2f97){return{'model':db[_0xaf2f97[_0xead2('0x1f')]],'as':_0xaf2f97['as'],'attributes':_0xaf2f97[_0xead2('0x1d')]};}):[]};}):[]};}):[]:[]})[_0xead2('0xb')](function(_0x283b23){logger[_0xead2('0xc')]('ShowCmHopper',_0x3c9948);logger['debug'](_0xead2('0x22'),_0x3c9948,JSON['stringify'](_0x283b23));_0x4afa7e(_0x283b23);})[_0xead2('0x14')](function(_0x21a113){logger[_0xead2('0x10')](_0xead2('0x22'),_0x21a113[_0xead2('0x12')],_0x3c9948);_0x3819ea(_0x12a28e[_0xead2('0x10')](0x1f4,_0x21a113['message']));});});};exports['CreateCmHopper']=function(_0x1070f6){var _0x3c9884=this;return new Promise(function(_0x526f5a,_0x1d9278){return db[_0xead2('0x16')][_0xead2('0x23')](_0x1070f6[_0xead2('0x24')],{'raw':_0x1070f6[_0xead2('0x18')]?_0x1070f6['options'][_0xead2('0x19')]===undefined?!![]:![]:!![]})[_0xead2('0xb')](function(_0x4aefb1){logger[_0xead2('0xc')](_0xead2('0x25'),_0x1070f6);logger[_0xead2('0x20')](_0xead2('0x25'),_0x1070f6,JSON[_0xead2('0xf')](_0x4aefb1));_0x526f5a(_0x4aefb1);})[_0xead2('0x14')](function(_0x70a52d){logger[_0xead2('0x10')](_0xead2('0x25'),_0x70a52d['message'],_0x1070f6);_0x1d9278(_0x3c9884[_0xead2('0x10')](0x1f4,_0x70a52d[_0xead2('0x12')]));});});};exports[_0xead2('0x26')]=function(_0x1c4ee2){var _0xeed8b6=this;return new Promise(function(_0x526156,_0x2dcc2d){return db[_0xead2('0x16')][_0xead2('0x27')](_0x1c4ee2[_0xead2('0x24')],{'raw':_0x1c4ee2['options']?_0x1c4ee2[_0xead2('0x18')][_0xead2('0x19')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x1c4ee2[_0xead2('0x18')]?_0x1c4ee2[_0xead2('0x18')]['where']||null:null,'attributes':_0x1c4ee2[_0xead2('0x18')]?_0x1c4ee2['options'][_0xead2('0x1d')]||null:null,'limit':_0x1c4ee2['options']?_0x1c4ee2['options']['limit']||null:null})['then'](function(_0x55193a){logger[_0xead2('0xc')](_0xead2('0x26'),_0x1c4ee2);logger[_0xead2('0x20')](_0xead2('0x26'),_0x1c4ee2,JSON['stringify'](_0x55193a));_0x526156(_0x55193a);})[_0xead2('0x14')](function(_0x4b4af6){logger[_0xead2('0x10')]('UpdateCmHopper',_0x4b4af6['message'],_0x1c4ee2);_0x2dcc2d(_0xeed8b6['error'](0x1f4,_0x4b4af6[_0xead2('0x12')]));});});};exports[_0xead2('0x28')]=function(_0x278b63){var _0x198226=this;return new Promise(function(_0x226a47,_0xa86640){return db[_0xead2('0x16')][_0xead2('0x29')]({'where':_0x278b63[_0xead2('0x18')]?_0x278b63[_0xead2('0x18')][_0xead2('0x1a')]||null:null})[_0xead2('0xb')](function(_0x33f614){logger[_0xead2('0xc')]('DestroyCmHopper',_0x278b63);logger[_0xead2('0x20')]('DestroyCmHopper',_0x278b63,JSON[_0xead2('0xf')](_0x33f614));_0x226a47(_0x33f614);})[_0xead2('0x14')](function(_0x15aec1){logger[_0xead2('0x10')](_0xead2('0x28'),_0x15aec1['message'],_0x278b63);_0xa86640(_0x198226[_0xead2('0x10')](0x1f4,_0x15aec1[_0xead2('0x12')]));});});};exports[_0xead2('0x2a')]=function(_0x6bbfca){var _0x1fb53e=this;return new Promise(function(_0x1c86c1,_0x227e94){return db[_0xead2('0x2b')][_0xead2('0x2c')]()[_0xead2('0xb')](function(_0x24c0a1){return db['sequelize'][_0xead2('0x2d')](function(_0x373881){return db[_0xead2('0x16')]['findAll']({'where':_0x6bbfca['options']?_0x6bbfca[_0xead2('0x18')][_0xead2('0x1a')]||null:null,'attributes':_0x6bbfca[_0xead2('0x18')]?_0x6bbfca['options'][_0xead2('0x1d')]||null:null,'limit':_0x6bbfca[_0xead2('0x18')]?_0x6bbfca['options']['limit']||null:null,'order':_0x6bbfca['options']?_0x6bbfca[_0xead2('0x18')][_0xead2('0x2e')]||null:null,'transaction':_0x373881,'lock':_0x373881[_0xead2('0x2f')][_0xead2('0x30')],'include':[{'model':db[_0xead2('0x2b')],'as':'Contact','attributes':_[_0xead2('0x31')](_0x24c0a1)},{'model':db[_0xead2('0x32')],'as':_0xead2('0x33'),'attributes':['id',_0xead2('0x34'),_0xead2('0x35')]}]})['then'](function(_0x53f37a){var _0x44c0e9=[];var _0x5cb5ea=[];for(var _0x3ca0b1=0x0;_0x3ca0b1<_0x53f37a[_0xead2('0x36')];_0x3ca0b1+=0x1){if(!_0x5cb5ea[_0xead2('0x37')](_0x53f37a[_0x3ca0b1][_0xead2('0x38')])){_0x5cb5ea[_0xead2('0x39')](_0x53f37a[_0x3ca0b1][_0xead2('0x38')]);_0x44c0e9[_0xead2('0x39')](_0x53f37a[_0x3ca0b1][_0xead2('0x27')](_0x6bbfca[_0xead2('0x24')],{'transaction':_0x373881}));}}return BPromise['all'](_0x44c0e9);});})['then'](function(_0x4152d2){logger[_0xead2('0xc')](_0xead2('0x2a'),_0x6bbfca);logger[_0xead2('0x20')](_0xead2('0x2a'),_0x6bbfca,JSON[_0xead2('0xf')](_0x4152d2));_0x1c86c1(_0x4152d2);})[_0xead2('0x14')](function(_0x25661a){logger[_0xead2('0x10')](_0xead2('0x2a'),_0x25661a[_0xead2('0x12')],_0x6bbfca);_0x227e94(_0x1fb53e[_0xead2('0x10')](0x1f4,_0x25661a[_0xead2('0x12')]));});});});};exports['MoveContactManagedDialer']=function(_0x46bc8f){var _0xda1dfe=this;return new Promise(function(_0x2085e1,_0x240b84){return db[_0xead2('0x3a')][_0xead2('0x2d')](function(_0x31d2b8){return db[_0xead2('0x3b')]['create'](_0x46bc8f[_0xead2('0x24')],{'raw':_0x46bc8f[_0xead2('0x18')]?_0x46bc8f['options'][_0xead2('0x19')]===undefined?!![]:![]:!![],'transaction':_0x31d2b8})[_0xead2('0xb')](function(){return db[_0xead2('0x16')][_0xead2('0x29')]({'where':_0x46bc8f[_0xead2('0x18')]?_0x46bc8f[_0xead2('0x18')][_0xead2('0x1a')]||null:null,'transaction':_0x31d2b8});});})[_0xead2('0xb')](function(_0x48927a){logger[_0xead2('0xc')]('MoveContactManagedDialer',_0x46bc8f);logger[_0xead2('0x20')]('MoveContactManagedDialer',_0x46bc8f,JSON[_0xead2('0xf')](_0x48927a));_0x2085e1(_0x48927a);})[_0xead2('0x14')](function(_0x50f960){logger[_0xead2('0x10')]('MoveContactManagedDialer',_0x50f960['message'],_0x46bc8f);_0x240b84(_0xda1dfe[_0xead2('0x10')](0x1f4,_0x50f960[_0xead2('0x12')]));});});};exports[_0xead2('0x3c')]=function(_0x45ac0e){var _0x1f00b8=this;return new Promise(function(_0x3e9e4f,_0x5e85e4){return db['CmHopper']['findAll']({'raw':_0x45ac0e[_0xead2('0x18')]?_0x45ac0e[_0xead2('0x18')]['raw']===undefined?!![]:![]:!![],'where':_0x45ac0e[_0xead2('0x18')]?_0x45ac0e['options'][_0xead2('0x1a')]||null:null,'attributes':[[db['sequelize']['fn'](_0xead2('0x3d'),db[_0xead2('0x3a')]['fn']('IF',db[_0xead2('0x3a')][_0xead2('0x3e')](_0xead2('0x3f')+util[_0xead2('0x40')]('\x22%s\x22',moment()[_0xead2('0x40')](_0xead2('0x41')))+_0xead2('0x42')))),_0xead2('0x43')]]})['then'](function(_0x217484){logger[_0xead2('0xc')](_0xead2('0x3c'),_0x45ac0e);logger[_0xead2('0x20')]('CountReScheduled',_0x45ac0e,JSON['stringify'](_0x217484));_0x3e9e4f(_0x217484);})['catch'](function(_0x5bbc61){logger[_0xead2('0x10')](_0xead2('0x3c'),_0x5bbc61[_0xead2('0x12')],_0x45ac0e);_0x5e85e4(_0x1f00b8['error'](0x1f4,_0x5bbc61[_0xead2('0x12')]));});});};exports['GetContactRecallMe']=function(_0x45616a){var _0x2ddb2d=this;return new Promise(function(_0x3760d4,_0x1e140d){return db[_0xead2('0x2b')][_0xead2('0x2c')]()['then'](function(_0x3e1d0d){return db[_0xead2('0x3a')][_0xead2('0x2d')](function(_0x5cd59c){return db[_0xead2('0x16')][_0xead2('0x17')]({'where':_0x45616a[_0xead2('0x18')]?_0x45616a[_0xead2('0x18')]['where']||null:null,'attributes':_0x45616a[_0xead2('0x18')]?_0x45616a[_0xead2('0x18')]['attributes']||null:null,'limit':0x1,'order':_0x45616a['options']?_0x45616a[_0xead2('0x18')]['order']||null:null,'group':db[_0xead2('0x16')][_0xead2('0x38')],'transaction':_0x5cd59c,'lock':_0x5cd59c[_0xead2('0x2f')][_0xead2('0x30')],'include':_0x45616a[_0xead2('0x18')]?_0x45616a[_0xead2('0x18')]['include']?_[_0xead2('0x1e')](_0x45616a['options'][_0xead2('0x1c')],function(_0x52a5a6){return{'model':db[_0x52a5a6[_0xead2('0x1f')]],'as':_0x52a5a6['as'],'attributes':_0x52a5a6[_0xead2('0x1d')],'include':_0x52a5a6['include']?_[_0xead2('0x1e')](_0x52a5a6['include'],function(_0x3ff043){return{'model':db[_0x3ff043[_0xead2('0x1f')]],'as':_0x3ff043['as'],'attributes':_0x3ff043['attributes'],'include':_0x3ff043[_0xead2('0x1c')]?_[_0xead2('0x1e')](_0x3ff043[_0xead2('0x1c')],function(_0x303f15){return{'model':db[_0x303f15[_0xead2('0x1f')]],'as':_0x303f15['as'],'attributes':_0x303f15[_0xead2('0x1d')]};}):[]};}):[]};}):[]:[]})[_0xead2('0xb')](function(_0x50a6cf){var _0x51b7df=[];for(var _0x3c0ea5=0x0;_0x3c0ea5<_0x50a6cf[_0xead2('0x36')];_0x3c0ea5+=0x1){_0x51b7df[_0xead2('0x39')](_0x50a6cf[_0x3c0ea5]['update'](_0x45616a[_0xead2('0x24')],{'transaction':_0x5cd59c}));}return BPromise[_0xead2('0x44')](_0x51b7df);});})[_0xead2('0xb')](function(_0x4320c6){logger[_0xead2('0xc')]('GetContactRecallMe',_0x45616a);logger['debug'](_0xead2('0x45'),_0x45616a,JSON[_0xead2('0xf')](_0x4320c6));_0x3760d4(_0x4320c6);})['catch'](function(_0x35b15c){logger[_0xead2('0x10')]('GetContactRecallMe',_0x35b15c['message'],_0x45616a);_0x1e140d(_0x2ddb2d[_0xead2('0x10')](0x1f4,_0x35b15c['message']));});});});};exports[_0xead2('0x46')]=function(_0x40871e){var _0x10a903=this;return new Promise(function(_0x81f95b,_0x3b25d7){db['CmContact'][_0xead2('0x2c')]()[_0xead2('0xb')](function(_0x389d3f){return db[_0xead2('0x16')][_0xead2('0x17')]({'raw':_0x40871e[_0xead2('0x18')]?_0x40871e['options'][_0xead2('0x19')]===undefined?!![]:![]:!![],'where':_0x40871e[_0xead2('0x18')]?_0x40871e[_0xead2('0x18')][_0xead2('0x1a')]||null:null,'attributes':_0x40871e[_0xead2('0x18')]?_0x40871e[_0xead2('0x18')][_0xead2('0x1d')]||null:null,'limit':_0x40871e[_0xead2('0x18')]?_0x40871e[_0xead2('0x18')][_0xead2('0x1b')]||null:null,'include':_0x40871e[_0xead2('0x18')]?_0x40871e[_0xead2('0x18')][_0xead2('0x1c')]?_[_0xead2('0x1e')](_0x40871e[_0xead2('0x18')][_0xead2('0x1c')],function(_0x2ec1a2){return{'model':db[_0x2ec1a2[_0xead2('0x1f')]],'as':_0x2ec1a2['as'],'attributes':_0x2ec1a2['as']===_0xead2('0x47')?_['keys'](_0x389d3f):_0x2ec1a2['attributes'],'include':_0x2ec1a2[_0xead2('0x1c')]?_[_0xead2('0x1e')](_0x2ec1a2[_0xead2('0x1c')],function(_0x10ed29){return{'model':db[_0x10ed29[_0xead2('0x1f')]],'as':_0x10ed29['as'],'attributes':_0x10ed29[_0xead2('0x1d')],'include':_0x10ed29[_0xead2('0x1c')]?_[_0xead2('0x1e')](_0x10ed29[_0xead2('0x1c')],function(_0x4857bf){return{'model':db[_0x4857bf['model']],'as':_0x4857bf['as'],'attributes':_0x4857bf[_0xead2('0x1d')]};}):[]};}):[]};}):[]:[]})[_0xead2('0xb')](function(_0x518665){logger[_0xead2('0xc')](_0xead2('0x15'),_0x40871e);logger[_0xead2('0x20')]('GetCmHopper',_0x40871e,JSON[_0xead2('0xf')](_0x518665));_0x81f95b(_0x518665);})[_0xead2('0x14')](function(_0x5cdc28){logger['error']('GetCmHopper',_0x5cdc28[_0xead2('0x12')],_0x40871e);_0x3b25d7(_0x10a903[_0xead2('0x10')](0x1f4,_0x5cdc28[_0xead2('0x12')]));});});});};