dad83d82a844e0affbf888d1b5fcaa22e338eb01
[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 _0xf943=['./whatsappAccount.socket','register','request','info','WhatsappAccount,\x20%s,\x20%s','request\x20sent','WhatsappAccount,\x20%s,\x20%s,\x20%s','stringify','error','message','result','catch','ShowWhatsappAccount','WhatsappAccount','find','options','raw','where','include','map','attributes','model','then','debug','lodash','util','moment','bluebird','randomstring','ioredis','../../config/utils','../../config/logger','../../config/environment','client','http','redis','defaults','localhost','socket.io-emitter'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0xf943,0x150));var _0x3f94=function(_0x376f20,_0x2385f3){_0x376f20=_0x376f20-0x0;var _0x212a45=_0xf943[_0x376f20];return _0x212a45;};'use strict';var _=require(_0x3f94('0x0'));var util=require(_0x3f94('0x1'));var moment=require(_0x3f94('0x2'));var BPromise=require(_0x3f94('0x3'));var rs=require(_0x3f94('0x4'));var fs=require('fs');var Redis=require(_0x3f94('0x5'));var db=require('../../mysqldb')['db'];var utils=require(_0x3f94('0x6'));var logger=require(_0x3f94('0x7'))('rpc');var config=require(_0x3f94('0x8'));var jayson=require('jayson/promise');var client=jayson[_0x3f94('0x9')][_0x3f94('0xa')]({'port':0x232a});config[_0x3f94('0xb')]=_[_0x3f94('0xc')](config[_0x3f94('0xb')],{'host':_0x3f94('0xd'),'port':0x18eb});var socket=require(_0x3f94('0xe'))(new Redis(config[_0x3f94('0xb')]));require(_0x3f94('0xf'))[_0x3f94('0x10')](socket);function respondWithRpcPromise(_0x4d1c61,_0x1c0c19,_0x527765){return new BPromise(function(_0x5583cd,_0x2f7210){return client[_0x3f94('0x11')](_0x4d1c61,_0x527765)['then'](function(_0xc027c7){logger[_0x3f94('0x12')](_0x3f94('0x13'),_0x1c0c19,_0x3f94('0x14'));logger['debug'](_0x3f94('0x15'),_0x1c0c19,_0x3f94('0x14'),JSON[_0x3f94('0x16')](_0xc027c7));if(_0xc027c7[_0x3f94('0x17')]){if(_0xc027c7[_0x3f94('0x17')]['code']===0x1f4){logger['error']('WhatsappAccount,\x20%s,\x20%s',_0x1c0c19,_0xc027c7['error'][_0x3f94('0x18')]);return _0x2f7210(_0xc027c7[_0x3f94('0x17')][_0x3f94('0x18')]);}logger[_0x3f94('0x17')]('WhatsappAccount,\x20%s,\x20%s',_0x1c0c19,_0xc027c7[_0x3f94('0x17')]['message']);return _0x5583cd(_0xc027c7[_0x3f94('0x17')]['message']);}else{logger['info'](_0x3f94('0x13'),_0x1c0c19,_0x3f94('0x14'));_0x5583cd(_0xc027c7[_0x3f94('0x19')][_0x3f94('0x18')]);}})[_0x3f94('0x1a')](function(_0x16c4c2){logger[_0x3f94('0x17')](_0x3f94('0x13'),_0x1c0c19,_0x16c4c2);_0x2f7210(_0x16c4c2);});});}exports[_0x3f94('0x1b')]=function(_0x345d7b){var _0x1e121c=this;return new Promise(function(_0x3c81b2,_0x55b8cf){return db[_0x3f94('0x1c')][_0x3f94('0x1d')]({'raw':_0x345d7b[_0x3f94('0x1e')]?_0x345d7b[_0x3f94('0x1e')][_0x3f94('0x1f')]===undefined?!![]:![]:!![],'where':_0x345d7b[_0x3f94('0x1e')]?_0x345d7b[_0x3f94('0x1e')][_0x3f94('0x20')]||null:null,'attributes':_0x345d7b[_0x3f94('0x1e')]?_0x345d7b[_0x3f94('0x1e')]['attributes']||null:null,'include':_0x345d7b['options']?_0x345d7b['options'][_0x3f94('0x21')]?_[_0x3f94('0x22')](_0x345d7b[_0x3f94('0x1e')]['include'],function(_0x23b121){return{'model':db[_0x23b121['model']],'as':_0x23b121['as'],'attributes':_0x23b121[_0x3f94('0x23')],'include':_0x23b121[_0x3f94('0x21')]?_[_0x3f94('0x22')](_0x23b121[_0x3f94('0x21')],function(_0x141d80){return{'model':db[_0x141d80[_0x3f94('0x24')]],'as':_0x141d80['as'],'attributes':_0x141d80[_0x3f94('0x23')],'include':_0x141d80[_0x3f94('0x21')]?_[_0x3f94('0x22')](_0x141d80[_0x3f94('0x21')],function(_0x14009e){return{'model':db[_0x14009e[_0x3f94('0x24')]],'as':_0x14009e['as'],'attributes':_0x14009e[_0x3f94('0x23')]};}):[]};}):[]};}):[]:[]})[_0x3f94('0x25')](function(_0x3e0661){logger[_0x3f94('0x12')](_0x3f94('0x1b'),_0x345d7b);logger[_0x3f94('0x26')]('ShowWhatsappAccount',_0x345d7b,JSON[_0x3f94('0x16')](_0x3e0661));_0x3c81b2(_0x3e0661);})[_0x3f94('0x1a')](function(_0x5a7f24){logger['error'](_0x3f94('0x1b'),_0x5a7f24[_0x3f94('0x18')],_0x345d7b);_0x55b8cf(_0x1e121c[_0x3f94('0x17')](0x1f4,_0x5a7f24[_0x3f94('0x18')]));});});};