Built motion from commit 47436d59.|2.6.7
[motion2.git] / server / api / whatsappQueue / whatsappQueue.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 _0x5f07=['moment','randomstring','ioredis','../../mysqldb','../../config/logger','../../config/environment','jayson/promise','client','http','redis','defaults','localhost','socket.io-emitter','./whatsappQueue.socket','register','request','then','info','WhatsappQueue,\x20%s,\x20%s','debug','request\x20sent','stringify','error','code','message','result','catch','GetWhatsappQueue','WhatsappQueue','findAll','options','raw','where','include','map','model','attributes','ShowWhatsappQueue','find','lodash','util'];(function(_0x20cb20,_0x256051){var _0x2fcf4b=function(_0x26200b){while(--_0x26200b){_0x20cb20['push'](_0x20cb20['shift']());}};_0x2fcf4b(++_0x256051);}(_0x5f07,0x79));var _0x75f0=function(_0x1b828b,_0x344400){_0x1b828b=_0x1b828b-0x0;var _0x98da1a=_0x5f07[_0x1b828b];return _0x98da1a;};'use strict';var _=require(_0x75f0('0x0'));var util=require(_0x75f0('0x1'));var moment=require(_0x75f0('0x2'));var BPromise=require('bluebird');var rs=require(_0x75f0('0x3'));var fs=require('fs');var Redis=require(_0x75f0('0x4'));var db=require(_0x75f0('0x5'))['db'];var utils=require('../../config/utils');var logger=require(_0x75f0('0x6'))('rpc');var config=require(_0x75f0('0x7'));var jayson=require(_0x75f0('0x8'));var client=jayson[_0x75f0('0x9')][_0x75f0('0xa')]({'port':0x232a});config[_0x75f0('0xb')]=_[_0x75f0('0xc')](config['redis'],{'host':_0x75f0('0xd'),'port':0x18eb});var socket=require(_0x75f0('0xe'))(new Redis(config[_0x75f0('0xb')]));require(_0x75f0('0xf'))[_0x75f0('0x10')](socket);function respondWithRpcPromise(_0x6ea498,_0x542849,_0x288ddb){return new BPromise(function(_0xe3083c,_0x286085){return client[_0x75f0('0x11')](_0x6ea498,_0x288ddb)[_0x75f0('0x12')](function(_0x2adf06){logger[_0x75f0('0x13')](_0x75f0('0x14'),_0x542849,'request\x20sent');logger[_0x75f0('0x15')]('WhatsappQueue,\x20%s,\x20%s,\x20%s',_0x542849,_0x75f0('0x16'),JSON[_0x75f0('0x17')](_0x2adf06));if(_0x2adf06[_0x75f0('0x18')]){if(_0x2adf06[_0x75f0('0x18')][_0x75f0('0x19')]===0x1f4){logger[_0x75f0('0x18')]('WhatsappQueue,\x20%s,\x20%s',_0x542849,_0x2adf06[_0x75f0('0x18')][_0x75f0('0x1a')]);return _0x286085(_0x2adf06['error'][_0x75f0('0x1a')]);}logger[_0x75f0('0x18')]('WhatsappQueue,\x20%s,\x20%s',_0x542849,_0x2adf06[_0x75f0('0x18')]['message']);return _0xe3083c(_0x2adf06[_0x75f0('0x18')][_0x75f0('0x1a')]);}else{logger[_0x75f0('0x13')](_0x75f0('0x14'),_0x542849,_0x75f0('0x16'));_0xe3083c(_0x2adf06[_0x75f0('0x1b')][_0x75f0('0x1a')]);}})[_0x75f0('0x1c')](function(_0x24003d){logger['error'](_0x75f0('0x14'),_0x542849,_0x24003d);_0x286085(_0x24003d);});});}exports[_0x75f0('0x1d')]=function(_0x19a3b9){var _0x42c07f=this;return new Promise(function(_0x285562,_0x494c6b){return db[_0x75f0('0x1e')][_0x75f0('0x1f')]({'raw':_0x19a3b9['options']?_0x19a3b9[_0x75f0('0x20')][_0x75f0('0x21')]===undefined?!![]:![]:!![],'where':_0x19a3b9[_0x75f0('0x20')]?_0x19a3b9['options'][_0x75f0('0x22')]||null:null,'attributes':_0x19a3b9[_0x75f0('0x20')]?_0x19a3b9['options']['attributes']||null:null,'limit':_0x19a3b9['options']?_0x19a3b9[_0x75f0('0x20')]['limit']||null:null,'include':_0x19a3b9[_0x75f0('0x20')]?_0x19a3b9['options'][_0x75f0('0x23')]?_[_0x75f0('0x24')](_0x19a3b9[_0x75f0('0x20')][_0x75f0('0x23')],function(_0x4506f5){return{'model':db[_0x4506f5[_0x75f0('0x25')]],'as':_0x4506f5['as'],'attributes':_0x4506f5[_0x75f0('0x26')],'include':_0x4506f5['include']?_[_0x75f0('0x24')](_0x4506f5[_0x75f0('0x23')],function(_0x323575){return{'model':db[_0x323575[_0x75f0('0x25')]],'as':_0x323575['as'],'attributes':_0x323575[_0x75f0('0x26')],'include':_0x323575['include']?_[_0x75f0('0x24')](_0x323575[_0x75f0('0x23')],function(_0x44ea17){return{'model':db[_0x44ea17['model']],'as':_0x44ea17['as'],'attributes':_0x44ea17[_0x75f0('0x26')]};}):[]};}):[]};}):[]:[]})[_0x75f0('0x12')](function(_0x42b22a){logger[_0x75f0('0x13')](_0x75f0('0x1d'),_0x19a3b9);logger[_0x75f0('0x15')](_0x75f0('0x1d'),_0x19a3b9,JSON[_0x75f0('0x17')](_0x42b22a));_0x285562(_0x42b22a);})[_0x75f0('0x1c')](function(_0xdf88b2){logger[_0x75f0('0x18')](_0x75f0('0x1d'),_0xdf88b2[_0x75f0('0x1a')],_0x19a3b9);_0x494c6b(_0x42c07f[_0x75f0('0x18')](0x1f4,_0xdf88b2[_0x75f0('0x1a')]));});});};exports[_0x75f0('0x27')]=function(_0x36a1c7){var _0x51600c=this;return new Promise(function(_0x851386,_0x7524a3){return db[_0x75f0('0x1e')][_0x75f0('0x28')]({'raw':_0x36a1c7['options']?_0x36a1c7[_0x75f0('0x20')][_0x75f0('0x21')]===undefined?!![]:![]:!![],'where':_0x36a1c7[_0x75f0('0x20')]?_0x36a1c7['options'][_0x75f0('0x22')]||null:null,'attributes':_0x36a1c7['options']?_0x36a1c7[_0x75f0('0x20')][_0x75f0('0x26')]||null:null,'include':_0x36a1c7[_0x75f0('0x20')]?_0x36a1c7['options'][_0x75f0('0x23')]?_['map'](_0x36a1c7['options'][_0x75f0('0x23')],function(_0x8cab95){return{'model':db[_0x8cab95[_0x75f0('0x25')]],'as':_0x8cab95['as'],'attributes':_0x8cab95['attributes'],'include':_0x8cab95[_0x75f0('0x23')]?_[_0x75f0('0x24')](_0x8cab95[_0x75f0('0x23')],function(_0x1dddbf){return{'model':db[_0x1dddbf[_0x75f0('0x25')]],'as':_0x1dddbf['as'],'attributes':_0x1dddbf[_0x75f0('0x26')],'include':_0x1dddbf[_0x75f0('0x23')]?_[_0x75f0('0x24')](_0x1dddbf[_0x75f0('0x23')],function(_0x1b60be){return{'model':db[_0x1b60be[_0x75f0('0x25')]],'as':_0x1b60be['as'],'attributes':_0x1b60be['attributes']};}):[]};}):[]};}):[]:[]})['then'](function(_0x52b781){logger[_0x75f0('0x13')]('ShowWhatsappQueue',_0x36a1c7);logger['debug']('ShowWhatsappQueue',_0x36a1c7,JSON[_0x75f0('0x17')](_0x52b781));_0x851386(_0x52b781);})[_0x75f0('0x1c')](function(_0x1b529f){logger[_0x75f0('0x18')](_0x75f0('0x27'),_0x1b529f[_0x75f0('0x1a')],_0x36a1c7);_0x7524a3(_0x51600c['error'](0x1f4,_0x1b529f[_0x75f0('0x1a')]));});});};