da87ba0526c07fb97ab7dad4378a2383b8c29fd0
[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 _0xa013=['register','request','then','request\x20sent','debug','WhatsappAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','WhatsappAccount,\x20%s,\x20%s','message','info','result','catch','ShowWhatsappAccount','find','options','raw','attributes','map','include','model','util','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/environment','jayson/promise','client','http','defaults','redis','socket.io-emitter','./whatsappAccount.socket'];(function(_0x14d5dc,_0x5f3046){var _0x1528a7=function(_0x5b08f2){while(--_0x5b08f2){_0x14d5dc['push'](_0x14d5dc['shift']());}};_0x1528a7(++_0x5f3046);}(_0xa013,0x1ea));var _0x3a01=function(_0x4bcf38,_0x3c12be){_0x4bcf38=_0x4bcf38-0x0;var _0x4a89be=_0xa013[_0x4bcf38];return _0x4a89be;};'use strict';var _=require('lodash');var util=require(_0x3a01('0x0'));var moment=require('moment');var BPromise=require(_0x3a01('0x1'));var rs=require(_0x3a01('0x2'));var fs=require('fs');var Redis=require(_0x3a01('0x3'));var db=require(_0x3a01('0x4'))['db'];var utils=require(_0x3a01('0x5'));var logger=require('../../config/logger')('rpc');var config=require(_0x3a01('0x6'));var jayson=require(_0x3a01('0x7'));var client=jayson[_0x3a01('0x8')][_0x3a01('0x9')]({'port':0x232a});config['redis']=_[_0x3a01('0xa')](config[_0x3a01('0xb')],{'host':'localhost','port':0x18eb});var socket=require(_0x3a01('0xc'))(new Redis(config[_0x3a01('0xb')]));require(_0x3a01('0xd'))[_0x3a01('0xe')](socket);function respondWithRpcPromise(_0x2c864c,_0x1bcf00,_0x5584a6){return new BPromise(function(_0x4dad65,_0x125f2d){return client[_0x3a01('0xf')](_0x2c864c,_0x5584a6)[_0x3a01('0x10')](function(_0x525645){logger['info']('WhatsappAccount,\x20%s,\x20%s',_0x1bcf00,_0x3a01('0x11'));logger[_0x3a01('0x12')](_0x3a01('0x13'),_0x1bcf00,'request\x20sent',JSON[_0x3a01('0x14')](_0x525645));if(_0x525645[_0x3a01('0x15')]){if(_0x525645['error'][_0x3a01('0x16')]===0x1f4){logger[_0x3a01('0x15')](_0x3a01('0x17'),_0x1bcf00,_0x525645[_0x3a01('0x15')]['message']);return _0x125f2d(_0x525645['error'][_0x3a01('0x18')]);}logger[_0x3a01('0x15')](_0x3a01('0x17'),_0x1bcf00,_0x525645[_0x3a01('0x15')][_0x3a01('0x18')]);return _0x4dad65(_0x525645[_0x3a01('0x15')]['message']);}else{logger[_0x3a01('0x19')](_0x3a01('0x17'),_0x1bcf00,_0x3a01('0x11'));_0x4dad65(_0x525645[_0x3a01('0x1a')][_0x3a01('0x18')]);}})[_0x3a01('0x1b')](function(_0x250738){logger['error']('WhatsappAccount,\x20%s,\x20%s',_0x1bcf00,_0x250738);_0x125f2d(_0x250738);});});}exports[_0x3a01('0x1c')]=function(_0x51cf62){var _0x215dfd=this;return new Promise(function(_0x3c2326,_0x2cd6f9){return db['WhatsappAccount'][_0x3a01('0x1d')]({'raw':_0x51cf62[_0x3a01('0x1e')]?_0x51cf62[_0x3a01('0x1e')][_0x3a01('0x1f')]===undefined?!![]:![]:!![],'where':_0x51cf62['options']?_0x51cf62[_0x3a01('0x1e')]['where']||null:null,'attributes':_0x51cf62[_0x3a01('0x1e')]?_0x51cf62[_0x3a01('0x1e')][_0x3a01('0x20')]||null:null,'include':_0x51cf62[_0x3a01('0x1e')]?_0x51cf62[_0x3a01('0x1e')]['include']?_[_0x3a01('0x21')](_0x51cf62[_0x3a01('0x1e')][_0x3a01('0x22')],function(_0x4f1898){return{'model':db[_0x4f1898[_0x3a01('0x23')]],'as':_0x4f1898['as'],'attributes':_0x4f1898['attributes'],'include':_0x4f1898[_0x3a01('0x22')]?_[_0x3a01('0x21')](_0x4f1898['include'],function(_0x333a24){return{'model':db[_0x333a24[_0x3a01('0x23')]],'as':_0x333a24['as'],'attributes':_0x333a24['attributes'],'include':_0x333a24[_0x3a01('0x22')]?_['map'](_0x333a24[_0x3a01('0x22')],function(_0x2688c2){return{'model':db[_0x2688c2[_0x3a01('0x23')]],'as':_0x2688c2['as'],'attributes':_0x2688c2[_0x3a01('0x20')]};}):[]};}):[]};}):[]:[]})[_0x3a01('0x10')](function(_0x357fa3){logger[_0x3a01('0x19')](_0x3a01('0x1c'),_0x51cf62);logger['debug']('ShowWhatsappAccount',_0x51cf62,JSON[_0x3a01('0x14')](_0x357fa3));_0x3c2326(_0x357fa3);})['catch'](function(_0x4c6962){logger['error']('ShowWhatsappAccount',_0x4c6962[_0x3a01('0x18')],_0x51cf62);_0x2cd6f9(_0x215dfd[_0x3a01('0x15')](0x1f4,_0x4c6962[_0x3a01('0x18')]));});});};