fdc67e859c6a5d83a5a0663da1e76afcfe601024
[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 _0x9c32=['randomstring','../../config/utils','../../config/logger','../../config/environment','client','defaults','redis','localhost','register','request','then','info','request\x20sent','debug','WhatsappAccount,\x20%s,\x20%s,\x20%s','stringify','error','message','WhatsappAccount,\x20%s,\x20%s','result','catch','find','options','raw','attributes','include','map','model','ShowWhatsappAccount','lodash','util','moment'];(function(_0x4e1047,_0x3ef4bc){var _0x243fe7=function(_0x5b49ba){while(--_0x5b49ba){_0x4e1047['push'](_0x4e1047['shift']());}};_0x243fe7(++_0x3ef4bc);}(_0x9c32,0x15d));var _0x29c3=function(_0x3fb9db,_0x317a83){_0x3fb9db=_0x3fb9db-0x0;var _0x30ad07=_0x9c32[_0x3fb9db];return _0x30ad07;};'use strict';var _=require(_0x29c3('0x0'));var util=require(_0x29c3('0x1'));var moment=require(_0x29c3('0x2'));var BPromise=require('bluebird');var rs=require(_0x29c3('0x3'));var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require(_0x29c3('0x4'));var logger=require(_0x29c3('0x5'))('rpc');var config=require(_0x29c3('0x6'));var jayson=require('jayson/promise');var client=jayson[_0x29c3('0x7')]['http']({'port':0x232a});config['redis']=_[_0x29c3('0x8')](config[_0x29c3('0x9')],{'host':_0x29c3('0xa'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require('./whatsappAccount.socket')[_0x29c3('0xb')](socket);function respondWithRpcPromise(_0x2fa09a,_0x358ac4,_0x1df8cf){return new BPromise(function(_0x513af9,_0x43bc26){return client[_0x29c3('0xc')](_0x2fa09a,_0x1df8cf)[_0x29c3('0xd')](function(_0x132f2f){logger[_0x29c3('0xe')]('WhatsappAccount,\x20%s,\x20%s',_0x358ac4,_0x29c3('0xf'));logger[_0x29c3('0x10')](_0x29c3('0x11'),_0x358ac4,_0x29c3('0xf'),JSON[_0x29c3('0x12')](_0x132f2f));if(_0x132f2f['error']){if(_0x132f2f['error']['code']===0x1f4){logger[_0x29c3('0x13')]('WhatsappAccount,\x20%s,\x20%s',_0x358ac4,_0x132f2f[_0x29c3('0x13')][_0x29c3('0x14')]);return _0x43bc26(_0x132f2f[_0x29c3('0x13')][_0x29c3('0x14')]);}logger[_0x29c3('0x13')](_0x29c3('0x15'),_0x358ac4,_0x132f2f[_0x29c3('0x13')][_0x29c3('0x14')]);return _0x513af9(_0x132f2f[_0x29c3('0x13')]['message']);}else{logger[_0x29c3('0xe')](_0x29c3('0x15'),_0x358ac4,'request\x20sent');_0x513af9(_0x132f2f[_0x29c3('0x16')]['message']);}})[_0x29c3('0x17')](function(_0x5815c8){logger[_0x29c3('0x13')](_0x29c3('0x15'),_0x358ac4,_0x5815c8);_0x43bc26(_0x5815c8);});});}exports['ShowWhatsappAccount']=function(_0x1e3969){var _0x2bdd60=this;return new Promise(function(_0x128322,_0x2bbe49){return db['WhatsappAccount'][_0x29c3('0x18')]({'raw':_0x1e3969['options']?_0x1e3969[_0x29c3('0x19')][_0x29c3('0x1a')]===undefined?!![]:![]:!![],'where':_0x1e3969[_0x29c3('0x19')]?_0x1e3969[_0x29c3('0x19')]['where']||null:null,'attributes':_0x1e3969['options']?_0x1e3969[_0x29c3('0x19')][_0x29c3('0x1b')]||null:null,'include':_0x1e3969[_0x29c3('0x19')]?_0x1e3969[_0x29c3('0x19')][_0x29c3('0x1c')]?_[_0x29c3('0x1d')](_0x1e3969[_0x29c3('0x19')]['include'],function(_0xbb6330){return{'model':db[_0xbb6330[_0x29c3('0x1e')]],'as':_0xbb6330['as'],'attributes':_0xbb6330['attributes'],'include':_0xbb6330['include']?_['map'](_0xbb6330['include'],function(_0x2e6c77){return{'model':db[_0x2e6c77[_0x29c3('0x1e')]],'as':_0x2e6c77['as'],'attributes':_0x2e6c77[_0x29c3('0x1b')],'include':_0x2e6c77[_0x29c3('0x1c')]?_[_0x29c3('0x1d')](_0x2e6c77[_0x29c3('0x1c')],function(_0x471e2b){return{'model':db[_0x471e2b[_0x29c3('0x1e')]],'as':_0x471e2b['as'],'attributes':_0x471e2b[_0x29c3('0x1b')]};}):[]};}):[]};}):[]:[]})[_0x29c3('0xd')](function(_0x2c02cc){logger['info']('ShowWhatsappAccount',_0x1e3969);logger[_0x29c3('0x10')]('ShowWhatsappAccount',_0x1e3969,JSON[_0x29c3('0x12')](_0x2c02cc));_0x128322(_0x2c02cc);})['catch'](function(_0x277d7c){logger['error'](_0x29c3('0x1f'),_0x277d7c[_0x29c3('0x14')],_0x1e3969);_0x2bbe49(_0x2bdd60[_0x29c3('0x13')](0x1f4,_0x277d7c[_0x29c3('0x14')]));});});};