722ab75b3a9d468f3171fe720787948ca67d7da4
[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 _0x92bd=['error','code','message','WhatsappQueue','findAll','options','raw','where','attributes','limit','map','include','model','debug','GetWhatsappQueue','catch','find','ShowWhatsappQueue','lodash','util','moment','bluebird','randomstring','ioredis','../../config/utils','../../config/logger','rpc','../../config/environment','http','redis','defaults','localhost','socket.io-emitter','./whatsappQueue.socket','register','request','then','info','WhatsappQueue,\x20%s,\x20%s','request\x20sent','stringify'];(function(_0x18237a,_0x3a2b11){var _0x5eab0e=function(_0x4aad3e){while(--_0x4aad3e){_0x18237a['push'](_0x18237a['shift']());}};_0x5eab0e(++_0x3a2b11);}(_0x92bd,0x108));var _0xd92b=function(_0x505756,_0x4f41dc){_0x505756=_0x505756-0x0;var _0x52ca07=_0x92bd[_0x505756];return _0x52ca07;};'use strict';var _=require(_0xd92b('0x0'));var util=require(_0xd92b('0x1'));var moment=require(_0xd92b('0x2'));var BPromise=require(_0xd92b('0x3'));var rs=require(_0xd92b('0x4'));var fs=require('fs');var Redis=require(_0xd92b('0x5'));var db=require('../../mysqldb')['db'];var utils=require(_0xd92b('0x6'));var logger=require(_0xd92b('0x7'))(_0xd92b('0x8'));var config=require(_0xd92b('0x9'));var jayson=require('jayson/promise');var client=jayson['client'][_0xd92b('0xa')]({'port':0x232a});config[_0xd92b('0xb')]=_[_0xd92b('0xc')](config['redis'],{'host':_0xd92b('0xd'),'port':0x18eb});var socket=require(_0xd92b('0xe'))(new Redis(config['redis']));require(_0xd92b('0xf'))[_0xd92b('0x10')](socket);function respondWithRpcPromise(_0x27cfc4,_0x3d6428,_0x1ade6e){return new BPromise(function(_0x54d075,_0x592c8c){return client[_0xd92b('0x11')](_0x27cfc4,_0x1ade6e)[_0xd92b('0x12')](function(_0x42a757){logger[_0xd92b('0x13')](_0xd92b('0x14'),_0x3d6428,'request\x20sent');logger['debug']('WhatsappQueue,\x20%s,\x20%s,\x20%s',_0x3d6428,_0xd92b('0x15'),JSON[_0xd92b('0x16')](_0x42a757));if(_0x42a757['error']){if(_0x42a757[_0xd92b('0x17')][_0xd92b('0x18')]===0x1f4){logger[_0xd92b('0x17')](_0xd92b('0x14'),_0x3d6428,_0x42a757[_0xd92b('0x17')][_0xd92b('0x19')]);return _0x592c8c(_0x42a757[_0xd92b('0x17')][_0xd92b('0x19')]);}logger[_0xd92b('0x17')](_0xd92b('0x14'),_0x3d6428,_0x42a757[_0xd92b('0x17')]['message']);return _0x54d075(_0x42a757[_0xd92b('0x17')][_0xd92b('0x19')]);}else{logger[_0xd92b('0x13')](_0xd92b('0x14'),_0x3d6428,_0xd92b('0x15'));_0x54d075(_0x42a757['result'][_0xd92b('0x19')]);}})['catch'](function(_0x56b8e8){logger[_0xd92b('0x17')]('WhatsappQueue,\x20%s,\x20%s',_0x3d6428,_0x56b8e8);_0x592c8c(_0x56b8e8);});});}exports['GetWhatsappQueue']=function(_0x40ed96){var _0x5457f6=this;return new Promise(function(_0x1d211a,_0x17776a){return db[_0xd92b('0x1a')][_0xd92b('0x1b')]({'raw':_0x40ed96[_0xd92b('0x1c')]?_0x40ed96[_0xd92b('0x1c')][_0xd92b('0x1d')]===undefined?!![]:![]:!![],'where':_0x40ed96[_0xd92b('0x1c')]?_0x40ed96[_0xd92b('0x1c')][_0xd92b('0x1e')]||null:null,'attributes':_0x40ed96[_0xd92b('0x1c')]?_0x40ed96[_0xd92b('0x1c')][_0xd92b('0x1f')]||null:null,'limit':_0x40ed96[_0xd92b('0x1c')]?_0x40ed96[_0xd92b('0x1c')][_0xd92b('0x20')]||null:null,'include':_0x40ed96[_0xd92b('0x1c')]?_0x40ed96[_0xd92b('0x1c')]['include']?_[_0xd92b('0x21')](_0x40ed96[_0xd92b('0x1c')][_0xd92b('0x22')],function(_0x27089c){return{'model':db[_0x27089c[_0xd92b('0x23')]],'as':_0x27089c['as'],'attributes':_0x27089c[_0xd92b('0x1f')],'include':_0x27089c[_0xd92b('0x22')]?_[_0xd92b('0x21')](_0x27089c[_0xd92b('0x22')],function(_0x5de926){return{'model':db[_0x5de926[_0xd92b('0x23')]],'as':_0x5de926['as'],'attributes':_0x5de926[_0xd92b('0x1f')],'include':_0x5de926[_0xd92b('0x22')]?_[_0xd92b('0x21')](_0x5de926[_0xd92b('0x22')],function(_0x202d84){return{'model':db[_0x202d84[_0xd92b('0x23')]],'as':_0x202d84['as'],'attributes':_0x202d84[_0xd92b('0x1f')]};}):[]};}):[]};}):[]:[]})[_0xd92b('0x12')](function(_0x4736b6){logger[_0xd92b('0x13')]('GetWhatsappQueue',_0x40ed96);logger[_0xd92b('0x24')](_0xd92b('0x25'),_0x40ed96,JSON[_0xd92b('0x16')](_0x4736b6));_0x1d211a(_0x4736b6);})[_0xd92b('0x26')](function(_0x3587e8){logger[_0xd92b('0x17')](_0xd92b('0x25'),_0x3587e8['message'],_0x40ed96);_0x17776a(_0x5457f6[_0xd92b('0x17')](0x1f4,_0x3587e8[_0xd92b('0x19')]));});});};exports['ShowWhatsappQueue']=function(_0x19e3d3){var _0x331ace=this;return new Promise(function(_0x4b429a,_0x2525cc){return db[_0xd92b('0x1a')][_0xd92b('0x27')]({'raw':_0x19e3d3[_0xd92b('0x1c')]?_0x19e3d3[_0xd92b('0x1c')][_0xd92b('0x1d')]===undefined?!![]:![]:!![],'where':_0x19e3d3[_0xd92b('0x1c')]?_0x19e3d3[_0xd92b('0x1c')][_0xd92b('0x1e')]||null:null,'attributes':_0x19e3d3[_0xd92b('0x1c')]?_0x19e3d3['options'][_0xd92b('0x1f')]||null:null,'include':_0x19e3d3[_0xd92b('0x1c')]?_0x19e3d3['options']['include']?_['map'](_0x19e3d3[_0xd92b('0x1c')][_0xd92b('0x22')],function(_0x447268){return{'model':db[_0x447268['model']],'as':_0x447268['as'],'attributes':_0x447268[_0xd92b('0x1f')],'include':_0x447268['include']?_[_0xd92b('0x21')](_0x447268[_0xd92b('0x22')],function(_0x4099be){return{'model':db[_0x4099be['model']],'as':_0x4099be['as'],'attributes':_0x4099be['attributes'],'include':_0x4099be['include']?_[_0xd92b('0x21')](_0x4099be['include'],function(_0x53a00e){return{'model':db[_0x53a00e[_0xd92b('0x23')]],'as':_0x53a00e['as'],'attributes':_0x53a00e[_0xd92b('0x1f')]};}):[]};}):[]};}):[]:[]})[_0xd92b('0x12')](function(_0x1d69c3){logger[_0xd92b('0x13')]('ShowWhatsappQueue',_0x19e3d3);logger[_0xd92b('0x24')](_0xd92b('0x28'),_0x19e3d3,JSON['stringify'](_0x1d69c3));_0x4b429a(_0x1d69c3);})[_0xd92b('0x26')](function(_0x20fb61){logger[_0xd92b('0x17')]('ShowWhatsappQueue',_0x20fb61[_0xd92b('0x19')],_0x19e3d3);_0x2525cc(_0x331ace[_0xd92b('0x17')](0x1f4,_0x20fb61[_0xd92b('0x19')]));});});};