0d3e7f36fa95e0b17d1902efa51b099dd67df9c3
[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 _0xe12f=['util','moment','bluebird','ioredis','../../mysqldb','../../config/utils','rpc','../../config/environment','http','defaults','redis','register','request','WhatsappAccount,\x20%s,\x20%s','WhatsappAccount,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','info','catch','ShowWhatsappAccount','find','options','raw','where','attributes','map','include','model','then','lodash'];(function(_0x2ba740,_0x62a305){var _0x358bda=function(_0x16cc07){while(--_0x16cc07){_0x2ba740['push'](_0x2ba740['shift']());}};_0x358bda(++_0x62a305);}(_0xe12f,0x83));var _0xfe12=function(_0x4f0da9,_0x445c5c){_0x4f0da9=_0x4f0da9-0x0;var _0x3471a0=_0xe12f[_0x4f0da9];return _0x3471a0;};'use strict';var _=require(_0xfe12('0x0'));var util=require(_0xfe12('0x1'));var moment=require(_0xfe12('0x2'));var BPromise=require(_0xfe12('0x3'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0xfe12('0x4'));var db=require(_0xfe12('0x5'))['db'];var utils=require(_0xfe12('0x6'));var logger=require('../../config/logger')(_0xfe12('0x7'));var config=require(_0xfe12('0x8'));var jayson=require('jayson/promise');var client=jayson['client'][_0xfe12('0x9')]({'port':0x232a});config['redis']=_[_0xfe12('0xa')](config[_0xfe12('0xb')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xfe12('0xb')]));require('./whatsappAccount.socket')[_0xfe12('0xc')](socket);function respondWithRpcPromise(_0x4c13f6,_0x23f9a6,_0x10f3b1){return new BPromise(function(_0x25f4eb,_0x276c9b){return client[_0xfe12('0xd')](_0x4c13f6,_0x10f3b1)['then'](function(_0x3c20a1){logger['info'](_0xfe12('0xe'),_0x23f9a6,'request\x20sent');logger['debug'](_0xfe12('0xf'),_0x23f9a6,_0xfe12('0x10'),JSON[_0xfe12('0x11')](_0x3c20a1));if(_0x3c20a1[_0xfe12('0x12')]){if(_0x3c20a1['error'][_0xfe12('0x13')]===0x1f4){logger[_0xfe12('0x12')]('WhatsappAccount,\x20%s,\x20%s',_0x23f9a6,_0x3c20a1[_0xfe12('0x12')][_0xfe12('0x14')]);return _0x276c9b(_0x3c20a1['error'][_0xfe12('0x14')]);}logger[_0xfe12('0x12')](_0xfe12('0xe'),_0x23f9a6,_0x3c20a1[_0xfe12('0x12')][_0xfe12('0x14')]);return _0x25f4eb(_0x3c20a1[_0xfe12('0x12')]['message']);}else{logger[_0xfe12('0x15')]('WhatsappAccount,\x20%s,\x20%s',_0x23f9a6,_0xfe12('0x10'));_0x25f4eb(_0x3c20a1['result']['message']);}})[_0xfe12('0x16')](function(_0x4ae563){logger[_0xfe12('0x12')](_0xfe12('0xe'),_0x23f9a6,_0x4ae563);_0x276c9b(_0x4ae563);});});}exports[_0xfe12('0x17')]=function(_0x5a570e){var _0x421567=this;return new Promise(function(_0x12853d,_0x1c988f){return db['WhatsappAccount'][_0xfe12('0x18')]({'raw':_0x5a570e['options']?_0x5a570e[_0xfe12('0x19')][_0xfe12('0x1a')]===undefined?!![]:![]:!![],'where':_0x5a570e[_0xfe12('0x19')]?_0x5a570e[_0xfe12('0x19')][_0xfe12('0x1b')]||null:null,'attributes':_0x5a570e[_0xfe12('0x19')]?_0x5a570e['options'][_0xfe12('0x1c')]||null:null,'include':_0x5a570e[_0xfe12('0x19')]?_0x5a570e[_0xfe12('0x19')]['include']?_[_0xfe12('0x1d')](_0x5a570e[_0xfe12('0x19')][_0xfe12('0x1e')],function(_0x525985){return{'model':db[_0x525985[_0xfe12('0x1f')]],'as':_0x525985['as'],'attributes':_0x525985[_0xfe12('0x1c')],'include':_0x525985[_0xfe12('0x1e')]?_[_0xfe12('0x1d')](_0x525985[_0xfe12('0x1e')],function(_0x2102f1){return{'model':db[_0x2102f1[_0xfe12('0x1f')]],'as':_0x2102f1['as'],'attributes':_0x2102f1['attributes'],'include':_0x2102f1[_0xfe12('0x1e')]?_[_0xfe12('0x1d')](_0x2102f1[_0xfe12('0x1e')],function(_0x2a361c){return{'model':db[_0x2a361c[_0xfe12('0x1f')]],'as':_0x2a361c['as'],'attributes':_0x2a361c['attributes']};}):[]};}):[]};}):[]:[]})[_0xfe12('0x20')](function(_0x5aca27){logger[_0xfe12('0x15')](_0xfe12('0x17'),_0x5a570e);logger['debug']('ShowWhatsappAccount',_0x5a570e,JSON['stringify'](_0x5aca27));_0x12853d(_0x5aca27);})[_0xfe12('0x16')](function(_0x3c80ae){logger[_0xfe12('0x12')](_0xfe12('0x17'),_0x3c80ae[_0xfe12('0x14')],_0x5a570e);_0x1c988f(_0x421567[_0xfe12('0x12')](0x1f4,_0x3c80ae[_0xfe12('0x14')]));});});};