Built motion from commit b5413ace.|2.6.9
[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 _0xc4f4=['defaults','redis','localhost','socket.io-emitter','./whatsappQueue.socket','register','request','info','WhatsappQueue,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','result','catch','GetWhatsappQueue','WhatsappQueue','options','raw','where','attributes','limit','include','map','model','then','ShowWhatsappQueue','lodash','util','moment','bluebird','randomstring','ioredis','../../config/utils','../../config/logger','rpc','../../config/environment','client','http'];(function(_0x5283f3,_0x5069d2){var _0x2ff816=function(_0x518645){while(--_0x518645){_0x5283f3['push'](_0x5283f3['shift']());}};_0x2ff816(++_0x5069d2);}(_0xc4f4,0x18e));var _0x4c4f=function(_0x6c993a,_0x5ea3ab){_0x6c993a=_0x6c993a-0x0;var _0x27f547=_0xc4f4[_0x6c993a];return _0x27f547;};'use strict';var _=require(_0x4c4f('0x0'));var util=require(_0x4c4f('0x1'));var moment=require(_0x4c4f('0x2'));var BPromise=require(_0x4c4f('0x3'));var rs=require(_0x4c4f('0x4'));var fs=require('fs');var Redis=require(_0x4c4f('0x5'));var db=require('../../mysqldb')['db'];var utils=require(_0x4c4f('0x6'));var logger=require(_0x4c4f('0x7'))(_0x4c4f('0x8'));var config=require(_0x4c4f('0x9'));var jayson=require('jayson/promise');var client=jayson[_0x4c4f('0xa')][_0x4c4f('0xb')]({'port':0x232a});config['redis']=_[_0x4c4f('0xc')](config[_0x4c4f('0xd')],{'host':_0x4c4f('0xe'),'port':0x18eb});var socket=require(_0x4c4f('0xf'))(new Redis(config[_0x4c4f('0xd')]));require(_0x4c4f('0x10'))[_0x4c4f('0x11')](socket);function respondWithRpcPromise(_0x37e68c,_0x107160,_0x2934a2){return new BPromise(function(_0x55d1b7,_0x369361){return client[_0x4c4f('0x12')](_0x37e68c,_0x2934a2)['then'](function(_0x240743){logger[_0x4c4f('0x13')](_0x4c4f('0x14'),_0x107160,_0x4c4f('0x15'));logger[_0x4c4f('0x16')]('WhatsappQueue,\x20%s,\x20%s,\x20%s',_0x107160,_0x4c4f('0x15'),JSON[_0x4c4f('0x17')](_0x240743));if(_0x240743[_0x4c4f('0x18')]){if(_0x240743[_0x4c4f('0x18')][_0x4c4f('0x19')]===0x1f4){logger[_0x4c4f('0x18')]('WhatsappQueue,\x20%s,\x20%s',_0x107160,_0x240743['error'][_0x4c4f('0x1a')]);return _0x369361(_0x240743['error'][_0x4c4f('0x1a')]);}logger[_0x4c4f('0x18')]('WhatsappQueue,\x20%s,\x20%s',_0x107160,_0x240743['error'][_0x4c4f('0x1a')]);return _0x55d1b7(_0x240743[_0x4c4f('0x18')][_0x4c4f('0x1a')]);}else{logger[_0x4c4f('0x13')](_0x4c4f('0x14'),_0x107160,'request\x20sent');_0x55d1b7(_0x240743[_0x4c4f('0x1b')]['message']);}})[_0x4c4f('0x1c')](function(_0x5b44bf){logger[_0x4c4f('0x18')](_0x4c4f('0x14'),_0x107160,_0x5b44bf);_0x369361(_0x5b44bf);});});}exports[_0x4c4f('0x1d')]=function(_0x52a18d){var _0x4ada6d=this;return new Promise(function(_0x1ca6ad,_0x40ef43){return db[_0x4c4f('0x1e')]['findAll']({'raw':_0x52a18d[_0x4c4f('0x1f')]?_0x52a18d[_0x4c4f('0x1f')][_0x4c4f('0x20')]===undefined?!![]:![]:!![],'where':_0x52a18d['options']?_0x52a18d['options'][_0x4c4f('0x21')]||null:null,'attributes':_0x52a18d['options']?_0x52a18d['options'][_0x4c4f('0x22')]||null:null,'limit':_0x52a18d[_0x4c4f('0x1f')]?_0x52a18d[_0x4c4f('0x1f')][_0x4c4f('0x23')]||null:null,'include':_0x52a18d[_0x4c4f('0x1f')]?_0x52a18d[_0x4c4f('0x1f')][_0x4c4f('0x24')]?_[_0x4c4f('0x25')](_0x52a18d[_0x4c4f('0x1f')][_0x4c4f('0x24')],function(_0x36c569){return{'model':db[_0x36c569['model']],'as':_0x36c569['as'],'attributes':_0x36c569['attributes'],'include':_0x36c569[_0x4c4f('0x24')]?_[_0x4c4f('0x25')](_0x36c569[_0x4c4f('0x24')],function(_0x53829a){return{'model':db[_0x53829a[_0x4c4f('0x26')]],'as':_0x53829a['as'],'attributes':_0x53829a[_0x4c4f('0x22')],'include':_0x53829a[_0x4c4f('0x24')]?_[_0x4c4f('0x25')](_0x53829a[_0x4c4f('0x24')],function(_0xb4165){return{'model':db[_0xb4165[_0x4c4f('0x26')]],'as':_0xb4165['as'],'attributes':_0xb4165[_0x4c4f('0x22')]};}):[]};}):[]};}):[]:[]})[_0x4c4f('0x27')](function(_0x153e1a){logger[_0x4c4f('0x13')](_0x4c4f('0x1d'),_0x52a18d);logger[_0x4c4f('0x16')](_0x4c4f('0x1d'),_0x52a18d,JSON['stringify'](_0x153e1a));_0x1ca6ad(_0x153e1a);})[_0x4c4f('0x1c')](function(_0x41b895){logger[_0x4c4f('0x18')]('GetWhatsappQueue',_0x41b895[_0x4c4f('0x1a')],_0x52a18d);_0x40ef43(_0x4ada6d[_0x4c4f('0x18')](0x1f4,_0x41b895[_0x4c4f('0x1a')]));});});};exports[_0x4c4f('0x28')]=function(_0x4dbec4){var _0xae3847=this;return new Promise(function(_0x46c342,_0x465d6e){return db[_0x4c4f('0x1e')]['find']({'raw':_0x4dbec4['options']?_0x4dbec4[_0x4c4f('0x1f')][_0x4c4f('0x20')]===undefined?!![]:![]:!![],'where':_0x4dbec4[_0x4c4f('0x1f')]?_0x4dbec4[_0x4c4f('0x1f')]['where']||null:null,'attributes':_0x4dbec4['options']?_0x4dbec4[_0x4c4f('0x1f')][_0x4c4f('0x22')]||null:null,'include':_0x4dbec4[_0x4c4f('0x1f')]?_0x4dbec4[_0x4c4f('0x1f')]['include']?_[_0x4c4f('0x25')](_0x4dbec4['options'][_0x4c4f('0x24')],function(_0x345d72){return{'model':db[_0x345d72[_0x4c4f('0x26')]],'as':_0x345d72['as'],'attributes':_0x345d72[_0x4c4f('0x22')],'include':_0x345d72[_0x4c4f('0x24')]?_[_0x4c4f('0x25')](_0x345d72['include'],function(_0x11cd60){return{'model':db[_0x11cd60['model']],'as':_0x11cd60['as'],'attributes':_0x11cd60['attributes'],'include':_0x11cd60[_0x4c4f('0x24')]?_[_0x4c4f('0x25')](_0x11cd60[_0x4c4f('0x24')],function(_0x493312){return{'model':db[_0x493312['model']],'as':_0x493312['as'],'attributes':_0x493312[_0x4c4f('0x22')]};}):[]};}):[]};}):[]:[]})[_0x4c4f('0x27')](function(_0x51ce87){logger[_0x4c4f('0x13')]('ShowWhatsappQueue',_0x4dbec4);logger['debug'](_0x4c4f('0x28'),_0x4dbec4,JSON[_0x4c4f('0x17')](_0x51ce87));_0x46c342(_0x51ce87);})['catch'](function(_0x1e908f){logger[_0x4c4f('0x18')](_0x4c4f('0x28'),_0x1e908f[_0x4c4f('0x1a')],_0x4dbec4);_0x465d6e(_0xae3847[_0x4c4f('0x18')](0x1f4,_0x1e908f[_0x4c4f('0x1a')]));});});};