84d1646a998b3b5920bf65e5bc23307fc6cb10ae
[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 _0x4aeb=['lodash','util','moment','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','http','redis','localhost','socket.io-emitter','./whatsappAccount.socket','register','then','info','WhatsappAccount,\x20%s,\x20%s','request\x20sent','debug','WhatsappAccount,\x20%s,\x20%s,\x20%s','stringify','error','message','result','catch','ShowWhatsappAccount','WhatsappAccount','find','options','raw','include','attributes','model'];(function(_0x2f34c4,_0x1d5bf5){var _0xe4e1ef=function(_0x582716){while(--_0x582716){_0x2f34c4['push'](_0x2f34c4['shift']());}};_0xe4e1ef(++_0x1d5bf5);}(_0x4aeb,0x1b0));var _0xb4ae=function(_0x23d784,_0x4c8941){_0x23d784=_0x23d784-0x0;var _0x2b1b4b=_0x4aeb[_0x23d784];return _0x2b1b4b;};'use strict';var _=require(_0xb4ae('0x0'));var util=require(_0xb4ae('0x1'));var moment=require(_0xb4ae('0x2'));var BPromise=require('bluebird');var rs=require(_0xb4ae('0x3'));var fs=require('fs');var Redis=require(_0xb4ae('0x4'));var db=require(_0xb4ae('0x5'))['db'];var utils=require(_0xb4ae('0x6'));var logger=require(_0xb4ae('0x7'))(_0xb4ae('0x8'));var config=require(_0xb4ae('0x9'));var jayson=require(_0xb4ae('0xa'));var client=jayson['client'][_0xb4ae('0xb')]({'port':0x232a});config[_0xb4ae('0xc')]=_['defaults'](config[_0xb4ae('0xc')],{'host':_0xb4ae('0xd'),'port':0x18eb});var socket=require(_0xb4ae('0xe'))(new Redis(config[_0xb4ae('0xc')]));require(_0xb4ae('0xf'))[_0xb4ae('0x10')](socket);function respondWithRpcPromise(_0x57e262,_0xd29cd5,_0x45ade8){return new BPromise(function(_0xdee621,_0x4f8056){return client['request'](_0x57e262,_0x45ade8)[_0xb4ae('0x11')](function(_0x3720fd){logger[_0xb4ae('0x12')](_0xb4ae('0x13'),_0xd29cd5,_0xb4ae('0x14'));logger[_0xb4ae('0x15')](_0xb4ae('0x16'),_0xd29cd5,'request\x20sent',JSON[_0xb4ae('0x17')](_0x3720fd));if(_0x3720fd[_0xb4ae('0x18')]){if(_0x3720fd[_0xb4ae('0x18')]['code']===0x1f4){logger[_0xb4ae('0x18')](_0xb4ae('0x13'),_0xd29cd5,_0x3720fd[_0xb4ae('0x18')]['message']);return _0x4f8056(_0x3720fd[_0xb4ae('0x18')][_0xb4ae('0x19')]);}logger[_0xb4ae('0x18')]('WhatsappAccount,\x20%s,\x20%s',_0xd29cd5,_0x3720fd[_0xb4ae('0x18')]['message']);return _0xdee621(_0x3720fd[_0xb4ae('0x18')][_0xb4ae('0x19')]);}else{logger['info'](_0xb4ae('0x13'),_0xd29cd5,_0xb4ae('0x14'));_0xdee621(_0x3720fd[_0xb4ae('0x1a')][_0xb4ae('0x19')]);}})[_0xb4ae('0x1b')](function(_0x27199f){logger['error']('WhatsappAccount,\x20%s,\x20%s',_0xd29cd5,_0x27199f);_0x4f8056(_0x27199f);});});}exports[_0xb4ae('0x1c')]=function(_0x4330f8){var _0x587ac3=this;return new Promise(function(_0x204af8,_0x19c9b6){return db[_0xb4ae('0x1d')][_0xb4ae('0x1e')]({'raw':_0x4330f8['options']?_0x4330f8[_0xb4ae('0x1f')][_0xb4ae('0x20')]===undefined?!![]:![]:!![],'where':_0x4330f8['options']?_0x4330f8[_0xb4ae('0x1f')]['where']||null:null,'attributes':_0x4330f8[_0xb4ae('0x1f')]?_0x4330f8['options']['attributes']||null:null,'include':_0x4330f8[_0xb4ae('0x1f')]?_0x4330f8['options'][_0xb4ae('0x21')]?_['map'](_0x4330f8[_0xb4ae('0x1f')][_0xb4ae('0x21')],function(_0x13b605){return{'model':db[_0x13b605['model']],'as':_0x13b605['as'],'attributes':_0x13b605[_0xb4ae('0x22')],'include':_0x13b605[_0xb4ae('0x21')]?_['map'](_0x13b605[_0xb4ae('0x21')],function(_0x547b53){return{'model':db[_0x547b53[_0xb4ae('0x23')]],'as':_0x547b53['as'],'attributes':_0x547b53[_0xb4ae('0x22')],'include':_0x547b53[_0xb4ae('0x21')]?_['map'](_0x547b53[_0xb4ae('0x21')],function(_0x4fdd57){return{'model':db[_0x4fdd57['model']],'as':_0x4fdd57['as'],'attributes':_0x4fdd57[_0xb4ae('0x22')]};}):[]};}):[]};}):[]:[]})[_0xb4ae('0x11')](function(_0x148ba4){logger[_0xb4ae('0x12')](_0xb4ae('0x1c'),_0x4330f8);logger[_0xb4ae('0x15')]('ShowWhatsappAccount',_0x4330f8,JSON[_0xb4ae('0x17')](_0x148ba4));_0x204af8(_0x148ba4);})[_0xb4ae('0x1b')](function(_0x12ef35){logger[_0xb4ae('0x18')](_0xb4ae('0x1c'),_0x12ef35[_0xb4ae('0x19')],_0x4330f8);_0x19c9b6(_0x587ac3[_0xb4ae('0x18')](0x1f4,_0x12ef35[_0xb4ae('0x19')]));});});};