Built motion from commit da617fac.|2.6.6
[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 _0x3c15=['ShowWhatsappQueue','WhatsappQueue','find','debug','lodash','util','moment','bluebird','randomstring','ioredis','../../config/utils','../../config/logger','rpc','jayson/promise','client','http','redis','localhost','socket.io-emitter','./whatsappQueue.socket','register','request','then','WhatsappQueue,\x20%s,\x20%s','request\x20sent','WhatsappQueue,\x20%s,\x20%s,\x20%s','stringify','error','message','info','result','catch','GetWhatsappQueue','findAll','options','raw','where','attributes','limit','map','include','model'];(function(_0x3a5564,_0x265701){var _0x843b0a=function(_0x3a58aa){while(--_0x3a58aa){_0x3a5564['push'](_0x3a5564['shift']());}};_0x843b0a(++_0x265701);}(_0x3c15,0x100));var _0x53c1=function(_0x27a1e0,_0x3ff2cb){_0x27a1e0=_0x27a1e0-0x0;var _0x1ca624=_0x3c15[_0x27a1e0];return _0x1ca624;};'use strict';var _=require(_0x53c1('0x0'));var util=require(_0x53c1('0x1'));var moment=require(_0x53c1('0x2'));var BPromise=require(_0x53c1('0x3'));var rs=require(_0x53c1('0x4'));var fs=require('fs');var Redis=require(_0x53c1('0x5'));var db=require('../../mysqldb')['db'];var utils=require(_0x53c1('0x6'));var logger=require(_0x53c1('0x7'))(_0x53c1('0x8'));var config=require('../../config/environment');var jayson=require(_0x53c1('0x9'));var client=jayson[_0x53c1('0xa')][_0x53c1('0xb')]({'port':0x232a});config[_0x53c1('0xc')]=_['defaults'](config[_0x53c1('0xc')],{'host':_0x53c1('0xd'),'port':0x18eb});var socket=require(_0x53c1('0xe'))(new Redis(config[_0x53c1('0xc')]));require(_0x53c1('0xf'))[_0x53c1('0x10')](socket);function respondWithRpcPromise(_0x5001b6,_0x31ac7f,_0x4299c9){return new BPromise(function(_0x310822,_0x2ecdbe){return client[_0x53c1('0x11')](_0x5001b6,_0x4299c9)[_0x53c1('0x12')](function(_0x555f44){logger['info'](_0x53c1('0x13'),_0x31ac7f,_0x53c1('0x14'));logger['debug'](_0x53c1('0x15'),_0x31ac7f,_0x53c1('0x14'),JSON[_0x53c1('0x16')](_0x555f44));if(_0x555f44['error']){if(_0x555f44[_0x53c1('0x17')]['code']===0x1f4){logger[_0x53c1('0x17')]('WhatsappQueue,\x20%s,\x20%s',_0x31ac7f,_0x555f44[_0x53c1('0x17')][_0x53c1('0x18')]);return _0x2ecdbe(_0x555f44[_0x53c1('0x17')][_0x53c1('0x18')]);}logger[_0x53c1('0x17')]('WhatsappQueue,\x20%s,\x20%s',_0x31ac7f,_0x555f44[_0x53c1('0x17')][_0x53c1('0x18')]);return _0x310822(_0x555f44[_0x53c1('0x17')][_0x53c1('0x18')]);}else{logger[_0x53c1('0x19')](_0x53c1('0x13'),_0x31ac7f,'request\x20sent');_0x310822(_0x555f44[_0x53c1('0x1a')][_0x53c1('0x18')]);}})[_0x53c1('0x1b')](function(_0x1bc51d){logger[_0x53c1('0x17')](_0x53c1('0x13'),_0x31ac7f,_0x1bc51d);_0x2ecdbe(_0x1bc51d);});});}exports[_0x53c1('0x1c')]=function(_0x13e661){var _0x4488aa=this;return new Promise(function(_0x3eb7b8,_0xd60f79){return db['WhatsappQueue'][_0x53c1('0x1d')]({'raw':_0x13e661[_0x53c1('0x1e')]?_0x13e661[_0x53c1('0x1e')][_0x53c1('0x1f')]===undefined?!![]:![]:!![],'where':_0x13e661[_0x53c1('0x1e')]?_0x13e661[_0x53c1('0x1e')][_0x53c1('0x20')]||null:null,'attributes':_0x13e661[_0x53c1('0x1e')]?_0x13e661[_0x53c1('0x1e')][_0x53c1('0x21')]||null:null,'limit':_0x13e661[_0x53c1('0x1e')]?_0x13e661['options'][_0x53c1('0x22')]||null:null,'include':_0x13e661[_0x53c1('0x1e')]?_0x13e661[_0x53c1('0x1e')]['include']?_[_0x53c1('0x23')](_0x13e661[_0x53c1('0x1e')][_0x53c1('0x24')],function(_0x1c32ff){return{'model':db[_0x1c32ff['model']],'as':_0x1c32ff['as'],'attributes':_0x1c32ff['attributes'],'include':_0x1c32ff[_0x53c1('0x24')]?_[_0x53c1('0x23')](_0x1c32ff[_0x53c1('0x24')],function(_0x5a4050){return{'model':db[_0x5a4050[_0x53c1('0x25')]],'as':_0x5a4050['as'],'attributes':_0x5a4050['attributes'],'include':_0x5a4050[_0x53c1('0x24')]?_['map'](_0x5a4050[_0x53c1('0x24')],function(_0x4921fb){return{'model':db[_0x4921fb[_0x53c1('0x25')]],'as':_0x4921fb['as'],'attributes':_0x4921fb[_0x53c1('0x21')]};}):[]};}):[]};}):[]:[]})[_0x53c1('0x12')](function(_0x11728d){logger[_0x53c1('0x19')](_0x53c1('0x1c'),_0x13e661);logger['debug']('GetWhatsappQueue',_0x13e661,JSON[_0x53c1('0x16')](_0x11728d));_0x3eb7b8(_0x11728d);})[_0x53c1('0x1b')](function(_0x4162fd){logger['error'](_0x53c1('0x1c'),_0x4162fd['message'],_0x13e661);_0xd60f79(_0x4488aa[_0x53c1('0x17')](0x1f4,_0x4162fd[_0x53c1('0x18')]));});});};exports[_0x53c1('0x26')]=function(_0x213b4f){var _0x482b77=this;return new Promise(function(_0x40f0bd,_0x504899){return db[_0x53c1('0x27')][_0x53c1('0x28')]({'raw':_0x213b4f[_0x53c1('0x1e')]?_0x213b4f['options'][_0x53c1('0x1f')]===undefined?!![]:![]:!![],'where':_0x213b4f[_0x53c1('0x1e')]?_0x213b4f[_0x53c1('0x1e')]['where']||null:null,'attributes':_0x213b4f[_0x53c1('0x1e')]?_0x213b4f[_0x53c1('0x1e')]['attributes']||null:null,'include':_0x213b4f['options']?_0x213b4f[_0x53c1('0x1e')][_0x53c1('0x24')]?_[_0x53c1('0x23')](_0x213b4f[_0x53c1('0x1e')][_0x53c1('0x24')],function(_0x1e2f1f){return{'model':db[_0x1e2f1f[_0x53c1('0x25')]],'as':_0x1e2f1f['as'],'attributes':_0x1e2f1f[_0x53c1('0x21')],'include':_0x1e2f1f[_0x53c1('0x24')]?_[_0x53c1('0x23')](_0x1e2f1f[_0x53c1('0x24')],function(_0x546ee4){return{'model':db[_0x546ee4['model']],'as':_0x546ee4['as'],'attributes':_0x546ee4[_0x53c1('0x21')],'include':_0x546ee4[_0x53c1('0x24')]?_['map'](_0x546ee4[_0x53c1('0x24')],function(_0x381dc9){return{'model':db[_0x381dc9[_0x53c1('0x25')]],'as':_0x381dc9['as'],'attributes':_0x381dc9[_0x53c1('0x21')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x381ef2){logger[_0x53c1('0x19')](_0x53c1('0x26'),_0x213b4f);logger[_0x53c1('0x29')]('ShowWhatsappQueue',_0x213b4f,JSON['stringify'](_0x381ef2));_0x40f0bd(_0x381ef2);})[_0x53c1('0x1b')](function(_0x251466){logger[_0x53c1('0x17')](_0x53c1('0x26'),_0x251466[_0x53c1('0x18')],_0x213b4f);_0x504899(_0x482b77[_0x53c1('0x17')](0x1f4,_0x251466['message']));});});};