40c9164f9040c564947b91d184c34a982b641f4b
[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 _0x5761=['WhatsappAccount,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','info','catch','WhatsappAccount','find','options','raw','where','attributes','include','map','model','ShowWhatsappAccount','lodash','util','randomstring','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','redis','defaults','localhost','./whatsappAccount.socket','request','then','WhatsappAccount,\x20%s,\x20%s','debug'];(function(_0x1f7996,_0x299a14){var _0x584609=function(_0x14c34a){while(--_0x14c34a){_0x1f7996['push'](_0x1f7996['shift']());}};_0x584609(++_0x299a14);}(_0x5761,0x107));var _0x1576=function(_0x48d899,_0x1d6488){_0x48d899=_0x48d899-0x0;var _0x3188e1=_0x5761[_0x48d899];return _0x3188e1;};'use strict';var _=require(_0x1576('0x0'));var util=require(_0x1576('0x1'));var moment=require('moment');var BPromise=require('bluebird');var rs=require(_0x1576('0x2'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x1576('0x3'))['db'];var utils=require(_0x1576('0x4'));var logger=require(_0x1576('0x5'))(_0x1576('0x6'));var config=require(_0x1576('0x7'));var jayson=require(_0x1576('0x8'));var client=jayson['client']['http']({'port':0x232a});config[_0x1576('0x9')]=_[_0x1576('0xa')](config[_0x1576('0x9')],{'host':_0x1576('0xb'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x1576('0x9')]));require(_0x1576('0xc'))['register'](socket);function respondWithRpcPromise(_0xcd49df,_0x4aed5d,_0x522022){return new BPromise(function(_0xb449db,_0x2381da){return client[_0x1576('0xd')](_0xcd49df,_0x522022)[_0x1576('0xe')](function(_0x11acb5){logger['info'](_0x1576('0xf'),_0x4aed5d,'request\x20sent');logger[_0x1576('0x10')](_0x1576('0x11'),_0x4aed5d,_0x1576('0x12'),JSON[_0x1576('0x13')](_0x11acb5));if(_0x11acb5[_0x1576('0x14')]){if(_0x11acb5[_0x1576('0x14')][_0x1576('0x15')]===0x1f4){logger[_0x1576('0x14')](_0x1576('0xf'),_0x4aed5d,_0x11acb5['error'][_0x1576('0x16')]);return _0x2381da(_0x11acb5['error'][_0x1576('0x16')]);}logger[_0x1576('0x14')](_0x1576('0xf'),_0x4aed5d,_0x11acb5[_0x1576('0x14')][_0x1576('0x16')]);return _0xb449db(_0x11acb5[_0x1576('0x14')]['message']);}else{logger[_0x1576('0x17')](_0x1576('0xf'),_0x4aed5d,_0x1576('0x12'));_0xb449db(_0x11acb5['result'][_0x1576('0x16')]);}})[_0x1576('0x18')](function(_0x3b5408){logger[_0x1576('0x14')](_0x1576('0xf'),_0x4aed5d,_0x3b5408);_0x2381da(_0x3b5408);});});}exports['ShowWhatsappAccount']=function(_0x3e5fa4){var _0x3fd6f6=this;return new Promise(function(_0x3e2c11,_0x33eaf2){return db[_0x1576('0x19')][_0x1576('0x1a')]({'raw':_0x3e5fa4[_0x1576('0x1b')]?_0x3e5fa4[_0x1576('0x1b')][_0x1576('0x1c')]===undefined?!![]:![]:!![],'where':_0x3e5fa4[_0x1576('0x1b')]?_0x3e5fa4['options'][_0x1576('0x1d')]||null:null,'attributes':_0x3e5fa4['options']?_0x3e5fa4['options'][_0x1576('0x1e')]||null:null,'include':_0x3e5fa4[_0x1576('0x1b')]?_0x3e5fa4[_0x1576('0x1b')][_0x1576('0x1f')]?_[_0x1576('0x20')](_0x3e5fa4[_0x1576('0x1b')][_0x1576('0x1f')],function(_0x250dbf){return{'model':db[_0x250dbf[_0x1576('0x21')]],'as':_0x250dbf['as'],'attributes':_0x250dbf[_0x1576('0x1e')],'include':_0x250dbf[_0x1576('0x1f')]?_[_0x1576('0x20')](_0x250dbf['include'],function(_0xa885bb){return{'model':db[_0xa885bb[_0x1576('0x21')]],'as':_0xa885bb['as'],'attributes':_0xa885bb['attributes'],'include':_0xa885bb[_0x1576('0x1f')]?_[_0x1576('0x20')](_0xa885bb['include'],function(_0x4372b6){return{'model':db[_0x4372b6[_0x1576('0x21')]],'as':_0x4372b6['as'],'attributes':_0x4372b6[_0x1576('0x1e')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x953a76){logger['info'](_0x1576('0x22'),_0x3e5fa4);logger['debug'](_0x1576('0x22'),_0x3e5fa4,JSON[_0x1576('0x13')](_0x953a76));_0x3e2c11(_0x953a76);})['catch'](function(_0x3e587d){logger[_0x1576('0x14')](_0x1576('0x22'),_0x3e587d['message'],_0x3e5fa4);_0x33eaf2(_0x3fd6f6[_0x1576('0x14')](0x1f4,_0x3e587d['message']));});});};