0a9cc5880a03023e996215477f0828ef19e75bd5
[motion2.git] / server / api / whatsappAccount / whatsappAccount.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 _0x60a5=['../../config/environment','jayson/promise','client','localhost','socket.io-emitter','redis','./whatsappAccount.socket','then','info','WhatsappAccount,\x20%s,\x20%s','request\x20sent','debug','WhatsappAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','ShowWhatsappAccount','WhatsappAccount','find','options','raw','where','attributes','include','model','map','catch','lodash','bluebird','../../mysqldb','../../config/utils','../../config/logger'];(function(_0x87b0ff,_0x314389){var _0x3bc0b2=function(_0x41682b){while(--_0x41682b){_0x87b0ff['push'](_0x87b0ff['shift']());}};_0x3bc0b2(++_0x314389);}(_0x60a5,0x83));var _0x560a=function(_0x167cc1,_0x56ef5a){_0x167cc1=_0x167cc1-0x0;var _0x10bc4b=_0x60a5[_0x167cc1];return _0x10bc4b;};'use strict';var _=require(_0x560a('0x0'));var util=require('util');var moment=require('moment');var BPromise=require(_0x560a('0x1'));var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require(_0x560a('0x2'))['db'];var utils=require(_0x560a('0x3'));var logger=require(_0x560a('0x4'))('rpc');var config=require(_0x560a('0x5'));var jayson=require(_0x560a('0x6'));var client=jayson[_0x560a('0x7')]['http']({'port':0x232a});config['redis']=_['defaults'](config['redis'],{'host':_0x560a('0x8'),'port':0x18eb});var socket=require(_0x560a('0x9'))(new Redis(config[_0x560a('0xa')]));require(_0x560a('0xb'))['register'](socket);function respondWithRpcPromise(_0x4c7a7a,_0x359da4,_0x5d95ee){return new BPromise(function(_0x2e3b88,_0x13c6a3){return client['request'](_0x4c7a7a,_0x5d95ee)[_0x560a('0xc')](function(_0x36e345){logger[_0x560a('0xd')](_0x560a('0xe'),_0x359da4,_0x560a('0xf'));logger[_0x560a('0x10')](_0x560a('0x11'),_0x359da4,_0x560a('0xf'),JSON[_0x560a('0x12')](_0x36e345));if(_0x36e345['error']){if(_0x36e345[_0x560a('0x13')][_0x560a('0x14')]===0x1f4){logger[_0x560a('0x13')]('WhatsappAccount,\x20%s,\x20%s',_0x359da4,_0x36e345[_0x560a('0x13')][_0x560a('0x15')]);return _0x13c6a3(_0x36e345[_0x560a('0x13')][_0x560a('0x15')]);}logger['error'](_0x560a('0xe'),_0x359da4,_0x36e345[_0x560a('0x13')][_0x560a('0x15')]);return _0x2e3b88(_0x36e345[_0x560a('0x13')]['message']);}else{logger['info'](_0x560a('0xe'),_0x359da4,_0x560a('0xf'));_0x2e3b88(_0x36e345[_0x560a('0x16')][_0x560a('0x15')]);}})['catch'](function(_0x96deb7){logger[_0x560a('0x13')](_0x560a('0xe'),_0x359da4,_0x96deb7);_0x13c6a3(_0x96deb7);});});}exports[_0x560a('0x17')]=function(_0xe9be04){var _0x4807f2=this;return new Promise(function(_0x32ff83,_0x155c2b){return db[_0x560a('0x18')][_0x560a('0x19')]({'raw':_0xe9be04[_0x560a('0x1a')]?_0xe9be04[_0x560a('0x1a')][_0x560a('0x1b')]===undefined?!![]:![]:!![],'where':_0xe9be04['options']?_0xe9be04[_0x560a('0x1a')][_0x560a('0x1c')]||null:null,'attributes':_0xe9be04[_0x560a('0x1a')]?_0xe9be04[_0x560a('0x1a')][_0x560a('0x1d')]||null:null,'include':_0xe9be04[_0x560a('0x1a')]?_0xe9be04[_0x560a('0x1a')][_0x560a('0x1e')]?_['map'](_0xe9be04['options']['include'],function(_0x306510){return{'model':db[_0x306510[_0x560a('0x1f')]],'as':_0x306510['as'],'attributes':_0x306510['attributes'],'include':_0x306510['include']?_[_0x560a('0x20')](_0x306510['include'],function(_0x405eeb){return{'model':db[_0x405eeb[_0x560a('0x1f')]],'as':_0x405eeb['as'],'attributes':_0x405eeb['attributes'],'include':_0x405eeb[_0x560a('0x1e')]?_[_0x560a('0x20')](_0x405eeb['include'],function(_0x1ddcf6){return{'model':db[_0x1ddcf6[_0x560a('0x1f')]],'as':_0x1ddcf6['as'],'attributes':_0x1ddcf6[_0x560a('0x1d')]};}):[]};}):[]};}):[]:[]})[_0x560a('0xc')](function(_0x40a668){logger['info'](_0x560a('0x17'),_0xe9be04);logger[_0x560a('0x10')]('ShowWhatsappAccount',_0xe9be04,JSON[_0x560a('0x12')](_0x40a668));_0x32ff83(_0x40a668);})[_0x560a('0x21')](function(_0xf4a166){logger[_0x560a('0x13')](_0x560a('0x17'),_0xf4a166[_0x560a('0x15')],_0xe9be04);_0x155c2b(_0x4807f2[_0x560a('0x13')](0x1f4,_0xf4a166['message']));});});};