Built motion from commit 538092ac.|2.6.10
[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 _0xdcb7=['../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','defaults','redis','socket.io-emitter','./whatsappQueue.socket','register','request','info','request\x20sent','debug','WhatsappQueue,\x20%s,\x20%s,\x20%s','stringify','error','WhatsappQueue,\x20%s,\x20%s','message','result','catch','GetWhatsappQueue','WhatsappQueue','findAll','options','raw','where','attributes','limit','include','map','model','then','find','ShowWhatsappQueue','lodash','util','bluebird','randomstring','ioredis'];(function(_0x2f63a0,_0x51855d){var _0x536ae8=function(_0x4b9de2){while(--_0x4b9de2){_0x2f63a0['push'](_0x2f63a0['shift']());}};_0x536ae8(++_0x51855d);}(_0xdcb7,0x1a9));var _0x7dcb=function(_0x34ec09,_0x234bd6){_0x34ec09=_0x34ec09-0x0;var _0x5c9340=_0xdcb7[_0x34ec09];return _0x5c9340;};'use strict';var _=require(_0x7dcb('0x0'));var util=require(_0x7dcb('0x1'));var moment=require('moment');var BPromise=require(_0x7dcb('0x2'));var rs=require(_0x7dcb('0x3'));var fs=require('fs');var Redis=require(_0x7dcb('0x4'));var db=require(_0x7dcb('0x5'))['db'];var utils=require(_0x7dcb('0x6'));var logger=require(_0x7dcb('0x7'))(_0x7dcb('0x8'));var config=require(_0x7dcb('0x9'));var jayson=require(_0x7dcb('0xa'));var client=jayson[_0x7dcb('0xb')][_0x7dcb('0xc')]({'port':0x232a});config['redis']=_[_0x7dcb('0xd')](config[_0x7dcb('0xe')],{'host':'localhost','port':0x18eb});var socket=require(_0x7dcb('0xf'))(new Redis(config[_0x7dcb('0xe')]));require(_0x7dcb('0x10'))[_0x7dcb('0x11')](socket);function respondWithRpcPromise(_0x1951ca,_0x2857b4,_0x14de8a){return new BPromise(function(_0x2d0034,_0x166cd3){return client[_0x7dcb('0x12')](_0x1951ca,_0x14de8a)['then'](function(_0x33f0ed){logger[_0x7dcb('0x13')]('WhatsappQueue,\x20%s,\x20%s',_0x2857b4,_0x7dcb('0x14'));logger[_0x7dcb('0x15')](_0x7dcb('0x16'),_0x2857b4,'request\x20sent',JSON[_0x7dcb('0x17')](_0x33f0ed));if(_0x33f0ed[_0x7dcb('0x18')]){if(_0x33f0ed[_0x7dcb('0x18')]['code']===0x1f4){logger['error'](_0x7dcb('0x19'),_0x2857b4,_0x33f0ed[_0x7dcb('0x18')][_0x7dcb('0x1a')]);return _0x166cd3(_0x33f0ed[_0x7dcb('0x18')][_0x7dcb('0x1a')]);}logger[_0x7dcb('0x18')]('WhatsappQueue,\x20%s,\x20%s',_0x2857b4,_0x33f0ed[_0x7dcb('0x18')]['message']);return _0x2d0034(_0x33f0ed[_0x7dcb('0x18')][_0x7dcb('0x1a')]);}else{logger[_0x7dcb('0x13')]('WhatsappQueue,\x20%s,\x20%s',_0x2857b4,_0x7dcb('0x14'));_0x2d0034(_0x33f0ed[_0x7dcb('0x1b')][_0x7dcb('0x1a')]);}})[_0x7dcb('0x1c')](function(_0x1faaea){logger['error']('WhatsappQueue,\x20%s,\x20%s',_0x2857b4,_0x1faaea);_0x166cd3(_0x1faaea);});});}exports[_0x7dcb('0x1d')]=function(_0x116a0c){var _0x306740=this;return new Promise(function(_0x1356a6,_0x533553){return db[_0x7dcb('0x1e')][_0x7dcb('0x1f')]({'raw':_0x116a0c[_0x7dcb('0x20')]?_0x116a0c[_0x7dcb('0x20')][_0x7dcb('0x21')]===undefined?!![]:![]:!![],'where':_0x116a0c['options']?_0x116a0c[_0x7dcb('0x20')][_0x7dcb('0x22')]||null:null,'attributes':_0x116a0c[_0x7dcb('0x20')]?_0x116a0c['options'][_0x7dcb('0x23')]||null:null,'limit':_0x116a0c[_0x7dcb('0x20')]?_0x116a0c[_0x7dcb('0x20')][_0x7dcb('0x24')]||null:null,'include':_0x116a0c[_0x7dcb('0x20')]?_0x116a0c[_0x7dcb('0x20')][_0x7dcb('0x25')]?_[_0x7dcb('0x26')](_0x116a0c[_0x7dcb('0x20')]['include'],function(_0xe6940){return{'model':db[_0xe6940['model']],'as':_0xe6940['as'],'attributes':_0xe6940[_0x7dcb('0x23')],'include':_0xe6940[_0x7dcb('0x25')]?_[_0x7dcb('0x26')](_0xe6940[_0x7dcb('0x25')],function(_0x4df81){return{'model':db[_0x4df81[_0x7dcb('0x27')]],'as':_0x4df81['as'],'attributes':_0x4df81[_0x7dcb('0x23')],'include':_0x4df81[_0x7dcb('0x25')]?_[_0x7dcb('0x26')](_0x4df81['include'],function(_0x2266b5){return{'model':db[_0x2266b5[_0x7dcb('0x27')]],'as':_0x2266b5['as'],'attributes':_0x2266b5[_0x7dcb('0x23')]};}):[]};}):[]};}):[]:[]})[_0x7dcb('0x28')](function(_0x138f65){logger[_0x7dcb('0x13')](_0x7dcb('0x1d'),_0x116a0c);logger[_0x7dcb('0x15')](_0x7dcb('0x1d'),_0x116a0c,JSON[_0x7dcb('0x17')](_0x138f65));_0x1356a6(_0x138f65);})[_0x7dcb('0x1c')](function(_0x25e651){logger[_0x7dcb('0x18')]('GetWhatsappQueue',_0x25e651[_0x7dcb('0x1a')],_0x116a0c);_0x533553(_0x306740[_0x7dcb('0x18')](0x1f4,_0x25e651['message']));});});};exports['ShowWhatsappQueue']=function(_0x14b8aa){var _0x5e93d6=this;return new Promise(function(_0xfcda18,_0x45b6e5){return db['WhatsappQueue'][_0x7dcb('0x29')]({'raw':_0x14b8aa[_0x7dcb('0x20')]?_0x14b8aa[_0x7dcb('0x20')][_0x7dcb('0x21')]===undefined?!![]:![]:!![],'where':_0x14b8aa['options']?_0x14b8aa[_0x7dcb('0x20')][_0x7dcb('0x22')]||null:null,'attributes':_0x14b8aa['options']?_0x14b8aa[_0x7dcb('0x20')]['attributes']||null:null,'include':_0x14b8aa['options']?_0x14b8aa[_0x7dcb('0x20')][_0x7dcb('0x25')]?_['map'](_0x14b8aa[_0x7dcb('0x20')][_0x7dcb('0x25')],function(_0x467e3e){return{'model':db[_0x467e3e[_0x7dcb('0x27')]],'as':_0x467e3e['as'],'attributes':_0x467e3e[_0x7dcb('0x23')],'include':_0x467e3e[_0x7dcb('0x25')]?_[_0x7dcb('0x26')](_0x467e3e['include'],function(_0x44509a){return{'model':db[_0x44509a[_0x7dcb('0x27')]],'as':_0x44509a['as'],'attributes':_0x44509a[_0x7dcb('0x23')],'include':_0x44509a['include']?_[_0x7dcb('0x26')](_0x44509a[_0x7dcb('0x25')],function(_0x19b04c){return{'model':db[_0x19b04c[_0x7dcb('0x27')]],'as':_0x19b04c['as'],'attributes':_0x19b04c[_0x7dcb('0x23')]};}):[]};}):[]};}):[]:[]})[_0x7dcb('0x28')](function(_0x45a488){logger['info'](_0x7dcb('0x2a'),_0x14b8aa);logger['debug'](_0x7dcb('0x2a'),_0x14b8aa,JSON[_0x7dcb('0x17')](_0x45a488));_0xfcda18(_0x45a488);})[_0x7dcb('0x1c')](function(_0x315f0e){logger[_0x7dcb('0x18')](_0x7dcb('0x2a'),_0x315f0e[_0x7dcb('0x1a')],_0x14b8aa);_0x45b6e5(_0x5e93d6['error'](0x1f4,_0x315f0e[_0x7dcb('0x1a')]));});});};