360886648f352c1edcf12cbf431a2b00358b860f
[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 _0x5cd2=['findAll','options','where','attributes','limit','include','model','map','then','debug','ShowWhatsappQueue','find','raw','lodash','moment','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','redis','defaults','localhost','socket.io-emitter','./whatsappQueue.socket','register','info','WhatsappQueue,\x20%s,\x20%s','request\x20sent','stringify','error','message','result','catch','GetWhatsappQueue','WhatsappQueue'];(function(_0x1694f5,_0x49b7c3){var _0x5b4321=function(_0x58c183){while(--_0x58c183){_0x1694f5['push'](_0x1694f5['shift']());}};_0x5b4321(++_0x49b7c3);}(_0x5cd2,0x103));var _0x25cd=function(_0x364e62,_0x4c899e){_0x364e62=_0x364e62-0x0;var _0x120331=_0x5cd2[_0x364e62];return _0x120331;};'use strict';var _=require(_0x25cd('0x0'));var util=require('util');var moment=require(_0x25cd('0x1'));var BPromise=require('bluebird');var rs=require(_0x25cd('0x2'));var fs=require('fs');var Redis=require(_0x25cd('0x3'));var db=require(_0x25cd('0x4'))['db'];var utils=require(_0x25cd('0x5'));var logger=require(_0x25cd('0x6'))(_0x25cd('0x7'));var config=require(_0x25cd('0x8'));var jayson=require(_0x25cd('0x9'));var client=jayson[_0x25cd('0xa')][_0x25cd('0xb')]({'port':0x232a});config[_0x25cd('0xc')]=_[_0x25cd('0xd')](config[_0x25cd('0xc')],{'host':_0x25cd('0xe'),'port':0x18eb});var socket=require(_0x25cd('0xf'))(new Redis(config[_0x25cd('0xc')]));require(_0x25cd('0x10'))[_0x25cd('0x11')](socket);function respondWithRpcPromise(_0x2bd868,_0x41bf9,_0x5f14a6){return new BPromise(function(_0x4836f5,_0xb4aa84){return client['request'](_0x2bd868,_0x5f14a6)['then'](function(_0x105a44){logger[_0x25cd('0x12')](_0x25cd('0x13'),_0x41bf9,_0x25cd('0x14'));logger['debug']('WhatsappQueue,\x20%s,\x20%s,\x20%s',_0x41bf9,_0x25cd('0x14'),JSON[_0x25cd('0x15')](_0x105a44));if(_0x105a44[_0x25cd('0x16')]){if(_0x105a44[_0x25cd('0x16')]['code']===0x1f4){logger[_0x25cd('0x16')](_0x25cd('0x13'),_0x41bf9,_0x105a44['error'][_0x25cd('0x17')]);return _0xb4aa84(_0x105a44[_0x25cd('0x16')][_0x25cd('0x17')]);}logger[_0x25cd('0x16')](_0x25cd('0x13'),_0x41bf9,_0x105a44[_0x25cd('0x16')]['message']);return _0x4836f5(_0x105a44[_0x25cd('0x16')][_0x25cd('0x17')]);}else{logger['info']('WhatsappQueue,\x20%s,\x20%s',_0x41bf9,_0x25cd('0x14'));_0x4836f5(_0x105a44[_0x25cd('0x18')]['message']);}})[_0x25cd('0x19')](function(_0xd500fb){logger[_0x25cd('0x16')](_0x25cd('0x13'),_0x41bf9,_0xd500fb);_0xb4aa84(_0xd500fb);});});}exports[_0x25cd('0x1a')]=function(_0x385545){var _0x53cfe5=this;return new Promise(function(_0x439b8e,_0x344e63){return db[_0x25cd('0x1b')][_0x25cd('0x1c')]({'raw':_0x385545[_0x25cd('0x1d')]?_0x385545[_0x25cd('0x1d')]['raw']===undefined?!![]:![]:!![],'where':_0x385545[_0x25cd('0x1d')]?_0x385545[_0x25cd('0x1d')][_0x25cd('0x1e')]||null:null,'attributes':_0x385545['options']?_0x385545[_0x25cd('0x1d')][_0x25cd('0x1f')]||null:null,'limit':_0x385545[_0x25cd('0x1d')]?_0x385545[_0x25cd('0x1d')][_0x25cd('0x20')]||null:null,'include':_0x385545[_0x25cd('0x1d')]?_0x385545[_0x25cd('0x1d')][_0x25cd('0x21')]?_['map'](_0x385545[_0x25cd('0x1d')][_0x25cd('0x21')],function(_0xf76949){return{'model':db[_0xf76949[_0x25cd('0x22')]],'as':_0xf76949['as'],'attributes':_0xf76949[_0x25cd('0x1f')],'include':_0xf76949[_0x25cd('0x21')]?_['map'](_0xf76949[_0x25cd('0x21')],function(_0x488887){return{'model':db[_0x488887[_0x25cd('0x22')]],'as':_0x488887['as'],'attributes':_0x488887[_0x25cd('0x1f')],'include':_0x488887[_0x25cd('0x21')]?_[_0x25cd('0x23')](_0x488887['include'],function(_0x3b5c14){return{'model':db[_0x3b5c14[_0x25cd('0x22')]],'as':_0x3b5c14['as'],'attributes':_0x3b5c14[_0x25cd('0x1f')]};}):[]};}):[]};}):[]:[]})[_0x25cd('0x24')](function(_0x3047c9){logger[_0x25cd('0x12')](_0x25cd('0x1a'),_0x385545);logger[_0x25cd('0x25')](_0x25cd('0x1a'),_0x385545,JSON[_0x25cd('0x15')](_0x3047c9));_0x439b8e(_0x3047c9);})[_0x25cd('0x19')](function(_0x3a62dd){logger['error']('GetWhatsappQueue',_0x3a62dd['message'],_0x385545);_0x344e63(_0x53cfe5[_0x25cd('0x16')](0x1f4,_0x3a62dd[_0x25cd('0x17')]));});});};exports[_0x25cd('0x26')]=function(_0x541227){var _0x1aeaf8=this;return new Promise(function(_0x3acdc3,_0x642129){return db[_0x25cd('0x1b')][_0x25cd('0x27')]({'raw':_0x541227['options']?_0x541227[_0x25cd('0x1d')][_0x25cd('0x28')]===undefined?!![]:![]:!![],'where':_0x541227[_0x25cd('0x1d')]?_0x541227[_0x25cd('0x1d')]['where']||null:null,'attributes':_0x541227['options']?_0x541227['options'][_0x25cd('0x1f')]||null:null,'include':_0x541227[_0x25cd('0x1d')]?_0x541227[_0x25cd('0x1d')]['include']?_[_0x25cd('0x23')](_0x541227['options']['include'],function(_0x588d56){return{'model':db[_0x588d56['model']],'as':_0x588d56['as'],'attributes':_0x588d56[_0x25cd('0x1f')],'include':_0x588d56[_0x25cd('0x21')]?_[_0x25cd('0x23')](_0x588d56[_0x25cd('0x21')],function(_0x38e90a){return{'model':db[_0x38e90a[_0x25cd('0x22')]],'as':_0x38e90a['as'],'attributes':_0x38e90a[_0x25cd('0x1f')],'include':_0x38e90a[_0x25cd('0x21')]?_[_0x25cd('0x23')](_0x38e90a['include'],function(_0x257da7){return{'model':db[_0x257da7[_0x25cd('0x22')]],'as':_0x257da7['as'],'attributes':_0x257da7['attributes']};}):[]};}):[]};}):[]:[]})[_0x25cd('0x24')](function(_0x5a8ac8){logger[_0x25cd('0x12')](_0x25cd('0x26'),_0x541227);logger['debug'](_0x25cd('0x26'),_0x541227,JSON[_0x25cd('0x15')](_0x5a8ac8));_0x3acdc3(_0x5a8ac8);})['catch'](function(_0x452723){logger[_0x25cd('0x16')](_0x25cd('0x26'),_0x452723[_0x25cd('0x17')],_0x541227);_0x642129(_0x1aeaf8[_0x25cd('0x16')](0x1f4,_0x452723[_0x25cd('0x17')]));});});};