Built motion from commit 0bd120ac.|2.6.25
[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 _0x1377=['lodash','moment','bluebird','rpc','jayson/promise','defaults','redis','localhost','socket.io-emitter','./whatsappAccount.socket','register','request','then','info','request\x20sent','debug','WhatsappAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','WhatsappAccount,\x20%s,\x20%s','message','result','catch','ShowWhatsappAccount','WhatsappAccount','find','raw','options','where','include','map','model','attributes'];(function(_0x4565bf,_0x5ad9d6){var _0x5610ba=function(_0x170988){while(--_0x170988){_0x4565bf['push'](_0x4565bf['shift']());}};_0x5610ba(++_0x5ad9d6);}(_0x1377,0x88));var _0x7137=function(_0x44a474,_0x226889){_0x44a474=_0x44a474-0x0;var _0x328959=_0x1377[_0x44a474];return _0x328959;};'use strict';var _=require(_0x7137('0x0'));var util=require('util');var moment=require(_0x7137('0x1'));var BPromise=require(_0x7137('0x2'));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('../../config/logger')(_0x7137('0x3'));var config=require('../../config/environment');var jayson=require(_0x7137('0x4'));var client=jayson['client']['http']({'port':0x232a});config['redis']=_[_0x7137('0x5')](config[_0x7137('0x6')],{'host':_0x7137('0x7'),'port':0x18eb});var socket=require(_0x7137('0x8'))(new Redis(config[_0x7137('0x6')]));require(_0x7137('0x9'))[_0x7137('0xa')](socket);function respondWithRpcPromise(_0x4868b1,_0xd5e806,_0x511197){return new BPromise(function(_0x368e49,_0x51e480){return client[_0x7137('0xb')](_0x4868b1,_0x511197)[_0x7137('0xc')](function(_0x23f29e){logger[_0x7137('0xd')]('WhatsappAccount,\x20%s,\x20%s',_0xd5e806,_0x7137('0xe'));logger[_0x7137('0xf')](_0x7137('0x10'),_0xd5e806,_0x7137('0xe'),JSON[_0x7137('0x11')](_0x23f29e));if(_0x23f29e[_0x7137('0x12')]){if(_0x23f29e[_0x7137('0x12')][_0x7137('0x13')]===0x1f4){logger[_0x7137('0x12')](_0x7137('0x14'),_0xd5e806,_0x23f29e[_0x7137('0x12')][_0x7137('0x15')]);return _0x51e480(_0x23f29e[_0x7137('0x12')][_0x7137('0x15')]);}logger[_0x7137('0x12')](_0x7137('0x14'),_0xd5e806,_0x23f29e[_0x7137('0x12')][_0x7137('0x15')]);return _0x368e49(_0x23f29e[_0x7137('0x12')]['message']);}else{logger['info'](_0x7137('0x14'),_0xd5e806,_0x7137('0xe'));_0x368e49(_0x23f29e[_0x7137('0x16')][_0x7137('0x15')]);}})[_0x7137('0x17')](function(_0x26ad36){logger[_0x7137('0x12')](_0x7137('0x14'),_0xd5e806,_0x26ad36);_0x51e480(_0x26ad36);});});}exports[_0x7137('0x18')]=function(_0x4f1923){var _0x4f4989=this;return new Promise(function(_0x5a7d86,_0x2c213d){return db[_0x7137('0x19')][_0x7137('0x1a')]({'raw':_0x4f1923['options']?_0x4f1923['options'][_0x7137('0x1b')]===undefined?!![]:![]:!![],'where':_0x4f1923['options']?_0x4f1923[_0x7137('0x1c')][_0x7137('0x1d')]||null:null,'attributes':_0x4f1923[_0x7137('0x1c')]?_0x4f1923[_0x7137('0x1c')]['attributes']||null:null,'include':_0x4f1923[_0x7137('0x1c')]?_0x4f1923[_0x7137('0x1c')][_0x7137('0x1e')]?_[_0x7137('0x1f')](_0x4f1923[_0x7137('0x1c')][_0x7137('0x1e')],function(_0x383656){return{'model':db[_0x383656[_0x7137('0x20')]],'as':_0x383656['as'],'attributes':_0x383656[_0x7137('0x21')],'include':_0x383656[_0x7137('0x1e')]?_['map'](_0x383656[_0x7137('0x1e')],function(_0x56750d){return{'model':db[_0x56750d['model']],'as':_0x56750d['as'],'attributes':_0x56750d['attributes'],'include':_0x56750d[_0x7137('0x1e')]?_[_0x7137('0x1f')](_0x56750d['include'],function(_0x12ed15){return{'model':db[_0x12ed15[_0x7137('0x20')]],'as':_0x12ed15['as'],'attributes':_0x12ed15[_0x7137('0x21')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x56e722){logger['info'](_0x7137('0x18'),_0x4f1923);logger['debug'](_0x7137('0x18'),_0x4f1923,JSON[_0x7137('0x11')](_0x56e722));_0x5a7d86(_0x56e722);})[_0x7137('0x17')](function(_0x21562e){logger[_0x7137('0x12')](_0x7137('0x18'),_0x21562e[_0x7137('0x15')],_0x4f1923);_0x2c213d(_0x4f4989['error'](0x1f4,_0x21562e['message']));});});};