Built motion from commit 3c2ce842.|2.6.31
[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 _0x2f93=['../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','redis','localhost','socket.io-emitter','./whatsappQueue.socket','register','then','info','request\x20sent','debug','stringify','error','WhatsappQueue,\x20%s,\x20%s','message','result','catch','GetWhatsappQueue','WhatsappQueue','options','raw','where','attributes','limit','include','map','model','find','ShowWhatsappQueue','lodash','util','moment','bluebird','randomstring','ioredis'];(function(_0x2642cb,_0x4b917f){var _0xe6e41=function(_0x281676){while(--_0x281676){_0x2642cb['push'](_0x2642cb['shift']());}};_0xe6e41(++_0x4b917f);}(_0x2f93,0x9a));var _0x32f9=function(_0x2c2785,_0x30dc45){_0x2c2785=_0x2c2785-0x0;var _0x43206d=_0x2f93[_0x2c2785];return _0x43206d;};'use strict';var _=require(_0x32f9('0x0'));var util=require(_0x32f9('0x1'));var moment=require(_0x32f9('0x2'));var BPromise=require(_0x32f9('0x3'));var rs=require(_0x32f9('0x4'));var fs=require('fs');var Redis=require(_0x32f9('0x5'));var db=require(_0x32f9('0x6'))['db'];var utils=require(_0x32f9('0x7'));var logger=require(_0x32f9('0x8'))(_0x32f9('0x9'));var config=require(_0x32f9('0xa'));var jayson=require(_0x32f9('0xb'));var client=jayson[_0x32f9('0xc')]['http']({'port':0x232a});config[_0x32f9('0xd')]=_['defaults'](config[_0x32f9('0xd')],{'host':_0x32f9('0xe'),'port':0x18eb});var socket=require(_0x32f9('0xf'))(new Redis(config[_0x32f9('0xd')]));require(_0x32f9('0x10'))[_0x32f9('0x11')](socket);function respondWithRpcPromise(_0x252f81,_0xbe1167,_0x5ec732){return new BPromise(function(_0x336ae6,_0x5674c7){return client['request'](_0x252f81,_0x5ec732)[_0x32f9('0x12')](function(_0x4eed25){logger[_0x32f9('0x13')]('WhatsappQueue,\x20%s,\x20%s',_0xbe1167,_0x32f9('0x14'));logger[_0x32f9('0x15')]('WhatsappQueue,\x20%s,\x20%s,\x20%s',_0xbe1167,_0x32f9('0x14'),JSON[_0x32f9('0x16')](_0x4eed25));if(_0x4eed25[_0x32f9('0x17')]){if(_0x4eed25[_0x32f9('0x17')]['code']===0x1f4){logger['error'](_0x32f9('0x18'),_0xbe1167,_0x4eed25[_0x32f9('0x17')][_0x32f9('0x19')]);return _0x5674c7(_0x4eed25['error'][_0x32f9('0x19')]);}logger[_0x32f9('0x17')](_0x32f9('0x18'),_0xbe1167,_0x4eed25['error']['message']);return _0x336ae6(_0x4eed25[_0x32f9('0x17')]['message']);}else{logger[_0x32f9('0x13')](_0x32f9('0x18'),_0xbe1167,_0x32f9('0x14'));_0x336ae6(_0x4eed25[_0x32f9('0x1a')][_0x32f9('0x19')]);}})[_0x32f9('0x1b')](function(_0x41308a){logger[_0x32f9('0x17')]('WhatsappQueue,\x20%s,\x20%s',_0xbe1167,_0x41308a);_0x5674c7(_0x41308a);});});}exports[_0x32f9('0x1c')]=function(_0x436d9e){var _0x21670d=this;return new Promise(function(_0x24f2ce,_0x2fa65f){return db[_0x32f9('0x1d')]['findAll']({'raw':_0x436d9e[_0x32f9('0x1e')]?_0x436d9e['options'][_0x32f9('0x1f')]===undefined?!![]:![]:!![],'where':_0x436d9e[_0x32f9('0x1e')]?_0x436d9e['options'][_0x32f9('0x20')]||null:null,'attributes':_0x436d9e[_0x32f9('0x1e')]?_0x436d9e['options'][_0x32f9('0x21')]||null:null,'limit':_0x436d9e[_0x32f9('0x1e')]?_0x436d9e[_0x32f9('0x1e')][_0x32f9('0x22')]||null:null,'include':_0x436d9e['options']?_0x436d9e[_0x32f9('0x1e')][_0x32f9('0x23')]?_[_0x32f9('0x24')](_0x436d9e[_0x32f9('0x1e')][_0x32f9('0x23')],function(_0x11bf36){return{'model':db[_0x11bf36['model']],'as':_0x11bf36['as'],'attributes':_0x11bf36['attributes'],'include':_0x11bf36[_0x32f9('0x23')]?_[_0x32f9('0x24')](_0x11bf36[_0x32f9('0x23')],function(_0x4c91e5){return{'model':db[_0x4c91e5[_0x32f9('0x25')]],'as':_0x4c91e5['as'],'attributes':_0x4c91e5['attributes'],'include':_0x4c91e5[_0x32f9('0x23')]?_[_0x32f9('0x24')](_0x4c91e5[_0x32f9('0x23')],function(_0x31dec0){return{'model':db[_0x31dec0['model']],'as':_0x31dec0['as'],'attributes':_0x31dec0[_0x32f9('0x21')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x2d56a2){logger[_0x32f9('0x13')]('GetWhatsappQueue',_0x436d9e);logger[_0x32f9('0x15')](_0x32f9('0x1c'),_0x436d9e,JSON[_0x32f9('0x16')](_0x2d56a2));_0x24f2ce(_0x2d56a2);})[_0x32f9('0x1b')](function(_0x668162){logger[_0x32f9('0x17')](_0x32f9('0x1c'),_0x668162[_0x32f9('0x19')],_0x436d9e);_0x2fa65f(_0x21670d['error'](0x1f4,_0x668162['message']));});});};exports['ShowWhatsappQueue']=function(_0x58e666){var _0x297561=this;return new Promise(function(_0x54b4f8,_0x1b5004){return db[_0x32f9('0x1d')][_0x32f9('0x26')]({'raw':_0x58e666[_0x32f9('0x1e')]?_0x58e666[_0x32f9('0x1e')][_0x32f9('0x1f')]===undefined?!![]:![]:!![],'where':_0x58e666[_0x32f9('0x1e')]?_0x58e666[_0x32f9('0x1e')][_0x32f9('0x20')]||null:null,'attributes':_0x58e666[_0x32f9('0x1e')]?_0x58e666[_0x32f9('0x1e')][_0x32f9('0x21')]||null:null,'include':_0x58e666['options']?_0x58e666[_0x32f9('0x1e')][_0x32f9('0x23')]?_['map'](_0x58e666[_0x32f9('0x1e')][_0x32f9('0x23')],function(_0x385983){return{'model':db[_0x385983['model']],'as':_0x385983['as'],'attributes':_0x385983[_0x32f9('0x21')],'include':_0x385983[_0x32f9('0x23')]?_['map'](_0x385983[_0x32f9('0x23')],function(_0x581bd9){return{'model':db[_0x581bd9[_0x32f9('0x25')]],'as':_0x581bd9['as'],'attributes':_0x581bd9['attributes'],'include':_0x581bd9[_0x32f9('0x23')]?_[_0x32f9('0x24')](_0x581bd9['include'],function(_0xfae886){return{'model':db[_0xfae886[_0x32f9('0x25')]],'as':_0xfae886['as'],'attributes':_0xfae886[_0x32f9('0x21')]};}):[]};}):[]};}):[]:[]})[_0x32f9('0x12')](function(_0x5cd696){logger[_0x32f9('0x13')](_0x32f9('0x27'),_0x58e666);logger[_0x32f9('0x15')](_0x32f9('0x27'),_0x58e666,JSON[_0x32f9('0x16')](_0x5cd696));_0x54b4f8(_0x5cd696);})[_0x32f9('0x1b')](function(_0x55bbd9){logger['error']('ShowWhatsappQueue',_0x55bbd9[_0x32f9('0x19')],_0x58e666);_0x1b5004(_0x297561[_0x32f9('0x17')](0x1f4,_0x55bbd9[_0x32f9('0x19')]));});});};