fe97605b58edcc7bbfbf05b7fd65ea512f3b0f13
[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 _0xb652=['stringify','error','message','result','ShowWhatsappAccount','find','raw','options','where','include','map','model','attributes','catch','util','bluebird','../../config/logger','../../config/environment','jayson/promise','client','http','redis','localhost','socket.io-emitter','./whatsappAccount.socket','request','then','info','WhatsappAccount,\x20%s,\x20%s','request\x20sent','debug','WhatsappAccount,\x20%s,\x20%s,\x20%s'];(function(_0x28111f,_0x254934){var _0x5203e6=function(_0x2c639a){while(--_0x2c639a){_0x28111f['push'](_0x28111f['shift']());}};_0x5203e6(++_0x254934);}(_0xb652,0x1ce));var _0x2b65=function(_0x588a1d,_0x505aeb){_0x588a1d=_0x588a1d-0x0;var _0x4d59af=_0xb652[_0x588a1d];return _0x4d59af;};'use strict';var _=require('lodash');var util=require(_0x2b65('0x0'));var moment=require('moment');var BPromise=require(_0x2b65('0x1'));var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require(_0x2b65('0x2'))('rpc');var config=require(_0x2b65('0x3'));var jayson=require(_0x2b65('0x4'));var client=jayson[_0x2b65('0x5')][_0x2b65('0x6')]({'port':0x232a});config['redis']=_['defaults'](config[_0x2b65('0x7')],{'host':_0x2b65('0x8'),'port':0x18eb});var socket=require(_0x2b65('0x9'))(new Redis(config['redis']));require(_0x2b65('0xa'))['register'](socket);function respondWithRpcPromise(_0x3e18c8,_0x4f4815,_0x18c0cc){return new BPromise(function(_0x217cb3,_0x1033bf){return client[_0x2b65('0xb')](_0x3e18c8,_0x18c0cc)[_0x2b65('0xc')](function(_0x4d7b87){logger[_0x2b65('0xd')](_0x2b65('0xe'),_0x4f4815,_0x2b65('0xf'));logger[_0x2b65('0x10')](_0x2b65('0x11'),_0x4f4815,'request\x20sent',JSON[_0x2b65('0x12')](_0x4d7b87));if(_0x4d7b87['error']){if(_0x4d7b87[_0x2b65('0x13')]['code']===0x1f4){logger['error'](_0x2b65('0xe'),_0x4f4815,_0x4d7b87['error'][_0x2b65('0x14')]);return _0x1033bf(_0x4d7b87[_0x2b65('0x13')]['message']);}logger[_0x2b65('0x13')](_0x2b65('0xe'),_0x4f4815,_0x4d7b87[_0x2b65('0x13')][_0x2b65('0x14')]);return _0x217cb3(_0x4d7b87[_0x2b65('0x13')][_0x2b65('0x14')]);}else{logger[_0x2b65('0xd')](_0x2b65('0xe'),_0x4f4815,_0x2b65('0xf'));_0x217cb3(_0x4d7b87[_0x2b65('0x15')][_0x2b65('0x14')]);}})['catch'](function(_0x38d99c){logger[_0x2b65('0x13')](_0x2b65('0xe'),_0x4f4815,_0x38d99c);_0x1033bf(_0x38d99c);});});}exports[_0x2b65('0x16')]=function(_0x331bdb){var _0x44aff7=this;return new Promise(function(_0x55908c,_0x57e3ed){return db['WhatsappAccount'][_0x2b65('0x17')]({'raw':_0x331bdb['options']?_0x331bdb['options'][_0x2b65('0x18')]===undefined?!![]:![]:!![],'where':_0x331bdb[_0x2b65('0x19')]?_0x331bdb[_0x2b65('0x19')][_0x2b65('0x1a')]||null:null,'attributes':_0x331bdb[_0x2b65('0x19')]?_0x331bdb[_0x2b65('0x19')]['attributes']||null:null,'include':_0x331bdb[_0x2b65('0x19')]?_0x331bdb[_0x2b65('0x19')][_0x2b65('0x1b')]?_[_0x2b65('0x1c')](_0x331bdb[_0x2b65('0x19')]['include'],function(_0x32eeb9){return{'model':db[_0x32eeb9[_0x2b65('0x1d')]],'as':_0x32eeb9['as'],'attributes':_0x32eeb9[_0x2b65('0x1e')],'include':_0x32eeb9['include']?_['map'](_0x32eeb9[_0x2b65('0x1b')],function(_0x38991e){return{'model':db[_0x38991e['model']],'as':_0x38991e['as'],'attributes':_0x38991e[_0x2b65('0x1e')],'include':_0x38991e['include']?_[_0x2b65('0x1c')](_0x38991e[_0x2b65('0x1b')],function(_0x1f7b20){return{'model':db[_0x1f7b20[_0x2b65('0x1d')]],'as':_0x1f7b20['as'],'attributes':_0x1f7b20[_0x2b65('0x1e')]};}):[]};}):[]};}):[]:[]})[_0x2b65('0xc')](function(_0x47d4e5){logger[_0x2b65('0xd')](_0x2b65('0x16'),_0x331bdb);logger[_0x2b65('0x10')](_0x2b65('0x16'),_0x331bdb,JSON[_0x2b65('0x12')](_0x47d4e5));_0x55908c(_0x47d4e5);})[_0x2b65('0x1f')](function(_0x1011d0){logger[_0x2b65('0x13')](_0x2b65('0x16'),_0x1011d0[_0x2b65('0x14')],_0x331bdb);_0x57e3ed(_0x44aff7[_0x2b65('0x13')](0x1f4,_0x1011d0['message']));});});};