Built motion from commit b0a9a629.|2.6.33
[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 _0x3b49=['defaults','localhost','socket.io-emitter','./whatsappQueue.socket','register','request','then','info','request\x20sent','error','code','WhatsappQueue,\x20%s,\x20%s','message','result','GetWhatsappQueue','findAll','options','raw','attributes','include','map','model','debug','stringify','catch','find','where','ShowWhatsappQueue','lodash','util','moment','bluebird','randomstring','../../mysqldb','../../config/logger','rpc','../../config/environment','client','http','redis'];(function(_0x50facb,_0x252ed9){var _0xc9bef3=function(_0x477dd1){while(--_0x477dd1){_0x50facb['push'](_0x50facb['shift']());}};_0xc9bef3(++_0x252ed9);}(_0x3b49,0xe4));var _0x93b4=function(_0x3b0731,_0xcf9925){_0x3b0731=_0x3b0731-0x0;var _0x4204d7=_0x3b49[_0x3b0731];return _0x4204d7;};'use strict';var _=require(_0x93b4('0x0'));var util=require(_0x93b4('0x1'));var moment=require(_0x93b4('0x2'));var BPromise=require(_0x93b4('0x3'));var rs=require(_0x93b4('0x4'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x93b4('0x5'))['db'];var utils=require('../../config/utils');var logger=require(_0x93b4('0x6'))(_0x93b4('0x7'));var config=require(_0x93b4('0x8'));var jayson=require('jayson/promise');var client=jayson[_0x93b4('0x9')][_0x93b4('0xa')]({'port':0x232a});config[_0x93b4('0xb')]=_[_0x93b4('0xc')](config[_0x93b4('0xb')],{'host':_0x93b4('0xd'),'port':0x18eb});var socket=require(_0x93b4('0xe'))(new Redis(config[_0x93b4('0xb')]));require(_0x93b4('0xf'))[_0x93b4('0x10')](socket);function respondWithRpcPromise(_0x2da54e,_0x5ea2a6,_0x4522ce){return new BPromise(function(_0x566859,_0x1c105f){return client[_0x93b4('0x11')](_0x2da54e,_0x4522ce)[_0x93b4('0x12')](function(_0x223893){logger[_0x93b4('0x13')]('WhatsappQueue,\x20%s,\x20%s',_0x5ea2a6,_0x93b4('0x14'));logger['debug']('WhatsappQueue,\x20%s,\x20%s,\x20%s',_0x5ea2a6,'request\x20sent',JSON['stringify'](_0x223893));if(_0x223893[_0x93b4('0x15')]){if(_0x223893[_0x93b4('0x15')][_0x93b4('0x16')]===0x1f4){logger[_0x93b4('0x15')](_0x93b4('0x17'),_0x5ea2a6,_0x223893[_0x93b4('0x15')][_0x93b4('0x18')]);return _0x1c105f(_0x223893[_0x93b4('0x15')][_0x93b4('0x18')]);}logger['error'](_0x93b4('0x17'),_0x5ea2a6,_0x223893[_0x93b4('0x15')][_0x93b4('0x18')]);return _0x566859(_0x223893[_0x93b4('0x15')][_0x93b4('0x18')]);}else{logger[_0x93b4('0x13')]('WhatsappQueue,\x20%s,\x20%s',_0x5ea2a6,_0x93b4('0x14'));_0x566859(_0x223893[_0x93b4('0x19')][_0x93b4('0x18')]);}})['catch'](function(_0x3548bd){logger[_0x93b4('0x15')](_0x93b4('0x17'),_0x5ea2a6,_0x3548bd);_0x1c105f(_0x3548bd);});});}exports[_0x93b4('0x1a')]=function(_0x3af372){var _0x22478a=this;return new Promise(function(_0x1d2efc,_0x1f6df4){return db['WhatsappQueue'][_0x93b4('0x1b')]({'raw':_0x3af372[_0x93b4('0x1c')]?_0x3af372['options'][_0x93b4('0x1d')]===undefined?!![]:![]:!![],'where':_0x3af372['options']?_0x3af372[_0x93b4('0x1c')]['where']||null:null,'attributes':_0x3af372[_0x93b4('0x1c')]?_0x3af372[_0x93b4('0x1c')][_0x93b4('0x1e')]||null:null,'limit':_0x3af372['options']?_0x3af372[_0x93b4('0x1c')]['limit']||null:null,'include':_0x3af372['options']?_0x3af372[_0x93b4('0x1c')][_0x93b4('0x1f')]?_[_0x93b4('0x20')](_0x3af372[_0x93b4('0x1c')][_0x93b4('0x1f')],function(_0x159f14){return{'model':db[_0x159f14[_0x93b4('0x21')]],'as':_0x159f14['as'],'attributes':_0x159f14[_0x93b4('0x1e')],'include':_0x159f14[_0x93b4('0x1f')]?_[_0x93b4('0x20')](_0x159f14[_0x93b4('0x1f')],function(_0x5d7c12){return{'model':db[_0x5d7c12[_0x93b4('0x21')]],'as':_0x5d7c12['as'],'attributes':_0x5d7c12[_0x93b4('0x1e')],'include':_0x5d7c12[_0x93b4('0x1f')]?_['map'](_0x5d7c12['include'],function(_0x2aef45){return{'model':db[_0x2aef45[_0x93b4('0x21')]],'as':_0x2aef45['as'],'attributes':_0x2aef45[_0x93b4('0x1e')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x13f125){logger[_0x93b4('0x13')](_0x93b4('0x1a'),_0x3af372);logger[_0x93b4('0x22')]('GetWhatsappQueue',_0x3af372,JSON[_0x93b4('0x23')](_0x13f125));_0x1d2efc(_0x13f125);})[_0x93b4('0x24')](function(_0x306e18){logger[_0x93b4('0x15')](_0x93b4('0x1a'),_0x306e18['message'],_0x3af372);_0x1f6df4(_0x22478a[_0x93b4('0x15')](0x1f4,_0x306e18['message']));});});};exports['ShowWhatsappQueue']=function(_0x25aea7){var _0x1517ff=this;return new Promise(function(_0x49b15d,_0x1a70fb){return db['WhatsappQueue'][_0x93b4('0x25')]({'raw':_0x25aea7[_0x93b4('0x1c')]?_0x25aea7[_0x93b4('0x1c')][_0x93b4('0x1d')]===undefined?!![]:![]:!![],'where':_0x25aea7[_0x93b4('0x1c')]?_0x25aea7[_0x93b4('0x1c')][_0x93b4('0x26')]||null:null,'attributes':_0x25aea7['options']?_0x25aea7[_0x93b4('0x1c')][_0x93b4('0x1e')]||null:null,'include':_0x25aea7[_0x93b4('0x1c')]?_0x25aea7['options']['include']?_['map'](_0x25aea7[_0x93b4('0x1c')]['include'],function(_0x36b6a3){return{'model':db[_0x36b6a3[_0x93b4('0x21')]],'as':_0x36b6a3['as'],'attributes':_0x36b6a3[_0x93b4('0x1e')],'include':_0x36b6a3['include']?_[_0x93b4('0x20')](_0x36b6a3[_0x93b4('0x1f')],function(_0x28f86a){return{'model':db[_0x28f86a[_0x93b4('0x21')]],'as':_0x28f86a['as'],'attributes':_0x28f86a[_0x93b4('0x1e')],'include':_0x28f86a[_0x93b4('0x1f')]?_[_0x93b4('0x20')](_0x28f86a[_0x93b4('0x1f')],function(_0x5048dd){return{'model':db[_0x5048dd[_0x93b4('0x21')]],'as':_0x5048dd['as'],'attributes':_0x5048dd[_0x93b4('0x1e')]};}):[]};}):[]};}):[]:[]})[_0x93b4('0x12')](function(_0x50364f){logger[_0x93b4('0x13')]('ShowWhatsappQueue',_0x25aea7);logger['debug'](_0x93b4('0x27'),_0x25aea7,JSON[_0x93b4('0x23')](_0x50364f));_0x49b15d(_0x50364f);})[_0x93b4('0x24')](function(_0x26bd11){logger[_0x93b4('0x15')](_0x93b4('0x27'),_0x26bd11[_0x93b4('0x18')],_0x25aea7);_0x1a70fb(_0x1517ff[_0x93b4('0x15')](0x1f4,_0x26bd11[_0x93b4('0x18')]));});});};