152ebbfe42713f73e973709ba9bcd680f9296873
[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 _0x4987=['result','catch','WhatsappQueue','findAll','options','raw','where','attributes','include','model','map','info','GetWhatsappQueue','debug','find','ShowWhatsappQueue','lodash','util','moment','bluebird','randomstring','../../config/utils','../../config/logger','../../config/environment','client','redis','defaults','socket.io-emitter','./whatsappQueue.socket','register','request','then','request\x20sent','stringify','error','WhatsappQueue,\x20%s,\x20%s','message'];(function(_0x14bf66,_0x3e1066){var _0xaf4bf7=function(_0x3d9c3f){while(--_0x3d9c3f){_0x14bf66['push'](_0x14bf66['shift']());}};_0xaf4bf7(++_0x3e1066);}(_0x4987,0x182));var _0x7498=function(_0x2faddb,_0xc18b78){_0x2faddb=_0x2faddb-0x0;var _0x273c05=_0x4987[_0x2faddb];return _0x273c05;};'use strict';var _=require(_0x7498('0x0'));var util=require(_0x7498('0x1'));var moment=require(_0x7498('0x2'));var BPromise=require(_0x7498('0x3'));var rs=require(_0x7498('0x4'));var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require(_0x7498('0x5'));var logger=require(_0x7498('0x6'))('rpc');var config=require(_0x7498('0x7'));var jayson=require('jayson/promise');var client=jayson[_0x7498('0x8')]['http']({'port':0x232a});config[_0x7498('0x9')]=_[_0x7498('0xa')](config[_0x7498('0x9')],{'host':'localhost','port':0x18eb});var socket=require(_0x7498('0xb'))(new Redis(config['redis']));require(_0x7498('0xc'))[_0x7498('0xd')](socket);function respondWithRpcPromise(_0x39bd46,_0x529444,_0x35363e){return new BPromise(function(_0x48ecb9,_0x1343d3){return client[_0x7498('0xe')](_0x39bd46,_0x35363e)[_0x7498('0xf')](function(_0x38275d){logger['info']('WhatsappQueue,\x20%s,\x20%s',_0x529444,_0x7498('0x10'));logger['debug']('WhatsappQueue,\x20%s,\x20%s,\x20%s',_0x529444,'request\x20sent',JSON[_0x7498('0x11')](_0x38275d));if(_0x38275d['error']){if(_0x38275d[_0x7498('0x12')]['code']===0x1f4){logger[_0x7498('0x12')](_0x7498('0x13'),_0x529444,_0x38275d[_0x7498('0x12')]['message']);return _0x1343d3(_0x38275d['error'][_0x7498('0x14')]);}logger[_0x7498('0x12')](_0x7498('0x13'),_0x529444,_0x38275d[_0x7498('0x12')][_0x7498('0x14')]);return _0x48ecb9(_0x38275d[_0x7498('0x12')][_0x7498('0x14')]);}else{logger['info'](_0x7498('0x13'),_0x529444,_0x7498('0x10'));_0x48ecb9(_0x38275d[_0x7498('0x15')][_0x7498('0x14')]);}})[_0x7498('0x16')](function(_0x3b003c){logger[_0x7498('0x12')](_0x7498('0x13'),_0x529444,_0x3b003c);_0x1343d3(_0x3b003c);});});}exports['GetWhatsappQueue']=function(_0x257f35){var _0x4254cb=this;return new Promise(function(_0x106a72,_0x2e1e2e){return db[_0x7498('0x17')][_0x7498('0x18')]({'raw':_0x257f35[_0x7498('0x19')]?_0x257f35[_0x7498('0x19')][_0x7498('0x1a')]===undefined?!![]:![]:!![],'where':_0x257f35[_0x7498('0x19')]?_0x257f35[_0x7498('0x19')][_0x7498('0x1b')]||null:null,'attributes':_0x257f35['options']?_0x257f35[_0x7498('0x19')][_0x7498('0x1c')]||null:null,'limit':_0x257f35[_0x7498('0x19')]?_0x257f35[_0x7498('0x19')]['limit']||null:null,'include':_0x257f35[_0x7498('0x19')]?_0x257f35[_0x7498('0x19')][_0x7498('0x1d')]?_['map'](_0x257f35[_0x7498('0x19')][_0x7498('0x1d')],function(_0x110248){return{'model':db[_0x110248[_0x7498('0x1e')]],'as':_0x110248['as'],'attributes':_0x110248[_0x7498('0x1c')],'include':_0x110248[_0x7498('0x1d')]?_['map'](_0x110248[_0x7498('0x1d')],function(_0x3bd8e1){return{'model':db[_0x3bd8e1['model']],'as':_0x3bd8e1['as'],'attributes':_0x3bd8e1[_0x7498('0x1c')],'include':_0x3bd8e1[_0x7498('0x1d')]?_[_0x7498('0x1f')](_0x3bd8e1[_0x7498('0x1d')],function(_0x582910){return{'model':db[_0x582910[_0x7498('0x1e')]],'as':_0x582910['as'],'attributes':_0x582910[_0x7498('0x1c')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x76e676){logger[_0x7498('0x20')](_0x7498('0x21'),_0x257f35);logger[_0x7498('0x22')](_0x7498('0x21'),_0x257f35,JSON[_0x7498('0x11')](_0x76e676));_0x106a72(_0x76e676);})[_0x7498('0x16')](function(_0x2405e4){logger[_0x7498('0x12')](_0x7498('0x21'),_0x2405e4[_0x7498('0x14')],_0x257f35);_0x2e1e2e(_0x4254cb[_0x7498('0x12')](0x1f4,_0x2405e4[_0x7498('0x14')]));});});};exports['ShowWhatsappQueue']=function(_0x472f7d){var _0x850897=this;return new Promise(function(_0x35b895,_0x1c2568){return db['WhatsappQueue'][_0x7498('0x23')]({'raw':_0x472f7d['options']?_0x472f7d[_0x7498('0x19')][_0x7498('0x1a')]===undefined?!![]:![]:!![],'where':_0x472f7d['options']?_0x472f7d[_0x7498('0x19')][_0x7498('0x1b')]||null:null,'attributes':_0x472f7d[_0x7498('0x19')]?_0x472f7d[_0x7498('0x19')][_0x7498('0x1c')]||null:null,'include':_0x472f7d[_0x7498('0x19')]?_0x472f7d['options'][_0x7498('0x1d')]?_['map'](_0x472f7d[_0x7498('0x19')]['include'],function(_0x453f50){return{'model':db[_0x453f50[_0x7498('0x1e')]],'as':_0x453f50['as'],'attributes':_0x453f50[_0x7498('0x1c')],'include':_0x453f50[_0x7498('0x1d')]?_['map'](_0x453f50[_0x7498('0x1d')],function(_0x2930fd){return{'model':db[_0x2930fd[_0x7498('0x1e')]],'as':_0x2930fd['as'],'attributes':_0x2930fd[_0x7498('0x1c')],'include':_0x2930fd[_0x7498('0x1d')]?_[_0x7498('0x1f')](_0x2930fd[_0x7498('0x1d')],function(_0x5c6eec){return{'model':db[_0x5c6eec['model']],'as':_0x5c6eec['as'],'attributes':_0x5c6eec['attributes']};}):[]};}):[]};}):[]:[]})[_0x7498('0xf')](function(_0x25a230){logger[_0x7498('0x20')](_0x7498('0x24'),_0x472f7d);logger['debug'](_0x7498('0x24'),_0x472f7d,JSON[_0x7498('0x11')](_0x25a230));_0x35b895(_0x25a230);})[_0x7498('0x16')](function(_0xe5e4a){logger[_0x7498('0x12')]('ShowWhatsappQueue',_0xe5e4a['message'],_0x472f7d);_0x1c2568(_0x850897[_0x7498('0x12')](0x1f4,_0xe5e4a[_0x7498('0x14')]));});});};