Built motion from commit 5293bb2a.|2.6.30
[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 _0x6711=['lodash','util','moment','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','redis','socket.io-emitter','then','WhatsappQueue,\x20%s,\x20%s','debug','WhatsappQueue,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','message','info','result','catch','WhatsappQueue','findAll','options','where','attributes','include','map','model','GetWhatsappQueue','find','raw','ShowWhatsappQueue'];(function(_0x14a5f0,_0x4df871){var _0x53eb40=function(_0x5acde7){while(--_0x5acde7){_0x14a5f0['push'](_0x14a5f0['shift']());}};_0x53eb40(++_0x4df871);}(_0x6711,0x6f));var _0x1671=function(_0x2d2885,_0x667d70){_0x2d2885=_0x2d2885-0x0;var _0x2cea6=_0x6711[_0x2d2885];return _0x2cea6;};'use strict';var _=require(_0x1671('0x0'));var util=require(_0x1671('0x1'));var moment=require(_0x1671('0x2'));var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x1671('0x3'));var db=require(_0x1671('0x4'))['db'];var utils=require(_0x1671('0x5'));var logger=require(_0x1671('0x6'))(_0x1671('0x7'));var config=require(_0x1671('0x8'));var jayson=require(_0x1671('0x9'));var client=jayson[_0x1671('0xa')][_0x1671('0xb')]({'port':0x232a});config[_0x1671('0xc')]=_['defaults'](config[_0x1671('0xc')],{'host':'localhost','port':0x18eb});var socket=require(_0x1671('0xd'))(new Redis(config['redis']));require('./whatsappQueue.socket')['register'](socket);function respondWithRpcPromise(_0x10de57,_0x314c63,_0x14339c){return new BPromise(function(_0x22c74e,_0xff9e2d){return client['request'](_0x10de57,_0x14339c)[_0x1671('0xe')](function(_0x355697){logger['info'](_0x1671('0xf'),_0x314c63,'request\x20sent');logger[_0x1671('0x10')](_0x1671('0x11'),_0x314c63,_0x1671('0x12'),JSON[_0x1671('0x13')](_0x355697));if(_0x355697[_0x1671('0x14')]){if(_0x355697[_0x1671('0x14')]['code']===0x1f4){logger['error']('WhatsappQueue,\x20%s,\x20%s',_0x314c63,_0x355697[_0x1671('0x14')][_0x1671('0x15')]);return _0xff9e2d(_0x355697[_0x1671('0x14')][_0x1671('0x15')]);}logger['error'](_0x1671('0xf'),_0x314c63,_0x355697[_0x1671('0x14')]['message']);return _0x22c74e(_0x355697['error'][_0x1671('0x15')]);}else{logger[_0x1671('0x16')](_0x1671('0xf'),_0x314c63,_0x1671('0x12'));_0x22c74e(_0x355697[_0x1671('0x17')][_0x1671('0x15')]);}})[_0x1671('0x18')](function(_0x193b09){logger[_0x1671('0x14')](_0x1671('0xf'),_0x314c63,_0x193b09);_0xff9e2d(_0x193b09);});});}exports['GetWhatsappQueue']=function(_0x399a41){var _0x4ed8c9=this;return new Promise(function(_0x121e33,_0x2f9e9a){return db[_0x1671('0x19')][_0x1671('0x1a')]({'raw':_0x399a41[_0x1671('0x1b')]?_0x399a41['options']['raw']===undefined?!![]:![]:!![],'where':_0x399a41[_0x1671('0x1b')]?_0x399a41[_0x1671('0x1b')][_0x1671('0x1c')]||null:null,'attributes':_0x399a41[_0x1671('0x1b')]?_0x399a41[_0x1671('0x1b')][_0x1671('0x1d')]||null:null,'limit':_0x399a41[_0x1671('0x1b')]?_0x399a41[_0x1671('0x1b')]['limit']||null:null,'include':_0x399a41[_0x1671('0x1b')]?_0x399a41[_0x1671('0x1b')][_0x1671('0x1e')]?_[_0x1671('0x1f')](_0x399a41[_0x1671('0x1b')][_0x1671('0x1e')],function(_0x8a3e9a){return{'model':db[_0x8a3e9a['model']],'as':_0x8a3e9a['as'],'attributes':_0x8a3e9a[_0x1671('0x1d')],'include':_0x8a3e9a[_0x1671('0x1e')]?_[_0x1671('0x1f')](_0x8a3e9a[_0x1671('0x1e')],function(_0x2396c2){return{'model':db[_0x2396c2[_0x1671('0x20')]],'as':_0x2396c2['as'],'attributes':_0x2396c2['attributes'],'include':_0x2396c2['include']?_[_0x1671('0x1f')](_0x2396c2[_0x1671('0x1e')],function(_0x435279){return{'model':db[_0x435279[_0x1671('0x20')]],'as':_0x435279['as'],'attributes':_0x435279['attributes']};}):[]};}):[]};}):[]:[]})[_0x1671('0xe')](function(_0x24269c){logger[_0x1671('0x16')](_0x1671('0x21'),_0x399a41);logger[_0x1671('0x10')](_0x1671('0x21'),_0x399a41,JSON[_0x1671('0x13')](_0x24269c));_0x121e33(_0x24269c);})['catch'](function(_0x5209b9){logger['error'](_0x1671('0x21'),_0x5209b9['message'],_0x399a41);_0x2f9e9a(_0x4ed8c9[_0x1671('0x14')](0x1f4,_0x5209b9[_0x1671('0x15')]));});});};exports['ShowWhatsappQueue']=function(_0x491ea8){var _0x5a2877=this;return new Promise(function(_0x2d7418,_0x1aeb37){return db[_0x1671('0x19')][_0x1671('0x22')]({'raw':_0x491ea8[_0x1671('0x1b')]?_0x491ea8['options'][_0x1671('0x23')]===undefined?!![]:![]:!![],'where':_0x491ea8[_0x1671('0x1b')]?_0x491ea8['options'][_0x1671('0x1c')]||null:null,'attributes':_0x491ea8['options']?_0x491ea8[_0x1671('0x1b')][_0x1671('0x1d')]||null:null,'include':_0x491ea8[_0x1671('0x1b')]?_0x491ea8[_0x1671('0x1b')][_0x1671('0x1e')]?_[_0x1671('0x1f')](_0x491ea8[_0x1671('0x1b')][_0x1671('0x1e')],function(_0x5adf1b){return{'model':db[_0x5adf1b[_0x1671('0x20')]],'as':_0x5adf1b['as'],'attributes':_0x5adf1b['attributes'],'include':_0x5adf1b[_0x1671('0x1e')]?_[_0x1671('0x1f')](_0x5adf1b['include'],function(_0x3a4e27){return{'model':db[_0x3a4e27['model']],'as':_0x3a4e27['as'],'attributes':_0x3a4e27[_0x1671('0x1d')],'include':_0x3a4e27['include']?_[_0x1671('0x1f')](_0x3a4e27[_0x1671('0x1e')],function(_0x528ca2){return{'model':db[_0x528ca2[_0x1671('0x20')]],'as':_0x528ca2['as'],'attributes':_0x528ca2[_0x1671('0x1d')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x1f4b6e){logger[_0x1671('0x16')]('ShowWhatsappQueue',_0x491ea8);logger[_0x1671('0x10')]('ShowWhatsappQueue',_0x491ea8,JSON[_0x1671('0x13')](_0x1f4b6e));_0x2d7418(_0x1f4b6e);})['catch'](function(_0x23d6cc){logger['error'](_0x1671('0x24'),_0x23d6cc['message'],_0x491ea8);_0x1aeb37(_0x5a2877[_0x1671('0x14')](0x1f4,_0x23d6cc[_0x1671('0x15')]));});});};