058e03f858df178df828c28dac53b19957fd8870
[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 _0xc593=['raw','where','include','map','model','attributes','then','debug','lodash','util','randomstring','ioredis','../../mysqldb','../../config/logger','rpc','../../config/environment','client','http','redis','localhost','socket.io-emitter','./whatsappAccount.socket','register','request','info','WhatsappAccount,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','catch','ShowWhatsappAccount','find','options'];(function(_0xa8d427,_0x5afb5b){var _0x5a0ef7=function(_0xb56427){while(--_0xb56427){_0xa8d427['push'](_0xa8d427['shift']());}};_0x5a0ef7(++_0x5afb5b);}(_0xc593,0xfd));var _0x3c59=function(_0xfae23b,_0x2be4ba){_0xfae23b=_0xfae23b-0x0;var _0x200640=_0xc593[_0xfae23b];return _0x200640;};'use strict';var _=require(_0x3c59('0x0'));var util=require(_0x3c59('0x1'));var moment=require('moment');var BPromise=require('bluebird');var rs=require(_0x3c59('0x2'));var fs=require('fs');var Redis=require(_0x3c59('0x3'));var db=require(_0x3c59('0x4'))['db'];var utils=require('../../config/utils');var logger=require(_0x3c59('0x5'))(_0x3c59('0x6'));var config=require(_0x3c59('0x7'));var jayson=require('jayson/promise');var client=jayson[_0x3c59('0x8')][_0x3c59('0x9')]({'port':0x232a});config[_0x3c59('0xa')]=_['defaults'](config[_0x3c59('0xa')],{'host':_0x3c59('0xb'),'port':0x18eb});var socket=require(_0x3c59('0xc'))(new Redis(config[_0x3c59('0xa')]));require(_0x3c59('0xd'))[_0x3c59('0xe')](socket);function respondWithRpcPromise(_0x4ae3fa,_0x157db9,_0x53ee3a){return new BPromise(function(_0x37c0a0,_0x2be437){return client[_0x3c59('0xf')](_0x4ae3fa,_0x53ee3a)['then'](function(_0x1d55f0){logger[_0x3c59('0x10')](_0x3c59('0x11'),_0x157db9,_0x3c59('0x12'));logger['debug']('WhatsappAccount,\x20%s,\x20%s,\x20%s',_0x157db9,_0x3c59('0x12'),JSON[_0x3c59('0x13')](_0x1d55f0));if(_0x1d55f0[_0x3c59('0x14')]){if(_0x1d55f0[_0x3c59('0x14')][_0x3c59('0x15')]===0x1f4){logger[_0x3c59('0x14')](_0x3c59('0x11'),_0x157db9,_0x1d55f0[_0x3c59('0x14')][_0x3c59('0x16')]);return _0x2be437(_0x1d55f0[_0x3c59('0x14')][_0x3c59('0x16')]);}logger[_0x3c59('0x14')](_0x3c59('0x11'),_0x157db9,_0x1d55f0['error']['message']);return _0x37c0a0(_0x1d55f0[_0x3c59('0x14')][_0x3c59('0x16')]);}else{logger['info'](_0x3c59('0x11'),_0x157db9,_0x3c59('0x12'));_0x37c0a0(_0x1d55f0['result'][_0x3c59('0x16')]);}})[_0x3c59('0x17')](function(_0x46bdc3){logger[_0x3c59('0x14')](_0x3c59('0x11'),_0x157db9,_0x46bdc3);_0x2be437(_0x46bdc3);});});}exports[_0x3c59('0x18')]=function(_0x312b79){var _0x5cbc57=this;return new Promise(function(_0x551b1d,_0x4a1b64){return db['WhatsappAccount'][_0x3c59('0x19')]({'raw':_0x312b79[_0x3c59('0x1a')]?_0x312b79['options'][_0x3c59('0x1b')]===undefined?!![]:![]:!![],'where':_0x312b79[_0x3c59('0x1a')]?_0x312b79[_0x3c59('0x1a')][_0x3c59('0x1c')]||null:null,'attributes':_0x312b79[_0x3c59('0x1a')]?_0x312b79['options']['attributes']||null:null,'include':_0x312b79['options']?_0x312b79[_0x3c59('0x1a')][_0x3c59('0x1d')]?_[_0x3c59('0x1e')](_0x312b79[_0x3c59('0x1a')][_0x3c59('0x1d')],function(_0x107ece){return{'model':db[_0x107ece[_0x3c59('0x1f')]],'as':_0x107ece['as'],'attributes':_0x107ece[_0x3c59('0x20')],'include':_0x107ece[_0x3c59('0x1d')]?_[_0x3c59('0x1e')](_0x107ece['include'],function(_0x219e3e){return{'model':db[_0x219e3e[_0x3c59('0x1f')]],'as':_0x219e3e['as'],'attributes':_0x219e3e['attributes'],'include':_0x219e3e[_0x3c59('0x1d')]?_[_0x3c59('0x1e')](_0x219e3e['include'],function(_0xeb632){return{'model':db[_0xeb632[_0x3c59('0x1f')]],'as':_0xeb632['as'],'attributes':_0xeb632[_0x3c59('0x20')]};}):[]};}):[]};}):[]:[]})[_0x3c59('0x21')](function(_0x3c3687){logger[_0x3c59('0x10')](_0x3c59('0x18'),_0x312b79);logger[_0x3c59('0x22')](_0x3c59('0x18'),_0x312b79,JSON[_0x3c59('0x13')](_0x3c3687));_0x551b1d(_0x3c3687);})['catch'](function(_0x35cabd){logger[_0x3c59('0x14')](_0x3c59('0x18'),_0x35cabd['message'],_0x312b79);_0x4a1b64(_0x5cbc57[_0x3c59('0x14')](0x1f4,_0x35cabd[_0x3c59('0x16')]));});});};