03236d655e6023f4a79ee9795c35c28e6938bd7a
[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 _0x96ff=['error','message','result','catch','ShowWhatsappAccount','WhatsappAccount','find','options','where','map','include','attributes','moment','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','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'];(function(_0x4c706c,_0x57ebb7){var _0x1d8dc7=function(_0x50a0f3){while(--_0x50a0f3){_0x4c706c['push'](_0x4c706c['shift']());}};_0x1d8dc7(++_0x57ebb7);}(_0x96ff,0xd8));var _0xf96f=function(_0x19950b,_0x53d0d7){_0x19950b=_0x19950b-0x0;var _0x3c6b41=_0x96ff[_0x19950b];return _0x3c6b41;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0xf96f('0x0'));var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require(_0xf96f('0x1'));var db=require(_0xf96f('0x2'))['db'];var utils=require(_0xf96f('0x3'));var logger=require(_0xf96f('0x4'))(_0xf96f('0x5'));var config=require(_0xf96f('0x6'));var jayson=require(_0xf96f('0x7'));var client=jayson[_0xf96f('0x8')][_0xf96f('0x9')]({'port':0x232a});config['redis']=_['defaults'](config[_0xf96f('0xa')],{'host':_0xf96f('0xb'),'port':0x18eb});var socket=require(_0xf96f('0xc'))(new Redis(config['redis']));require(_0xf96f('0xd'))[_0xf96f('0xe')](socket);function respondWithRpcPromise(_0x22dc88,_0x40de4c,_0xed4cda){return new BPromise(function(_0x2d40a7,_0x1314ba){return client['request'](_0x22dc88,_0xed4cda)[_0xf96f('0xf')](function(_0x5c34da){logger[_0xf96f('0x10')](_0xf96f('0x11'),_0x40de4c,_0xf96f('0x12'));logger[_0xf96f('0x13')](_0xf96f('0x14'),_0x40de4c,'request\x20sent',JSON[_0xf96f('0x15')](_0x5c34da));if(_0x5c34da[_0xf96f('0x16')]){if(_0x5c34da[_0xf96f('0x16')]['code']===0x1f4){logger['error'](_0xf96f('0x11'),_0x40de4c,_0x5c34da['error'][_0xf96f('0x17')]);return _0x1314ba(_0x5c34da[_0xf96f('0x16')][_0xf96f('0x17')]);}logger['error']('WhatsappAccount,\x20%s,\x20%s',_0x40de4c,_0x5c34da[_0xf96f('0x16')][_0xf96f('0x17')]);return _0x2d40a7(_0x5c34da['error']['message']);}else{logger[_0xf96f('0x10')](_0xf96f('0x11'),_0x40de4c,_0xf96f('0x12'));_0x2d40a7(_0x5c34da[_0xf96f('0x18')][_0xf96f('0x17')]);}})[_0xf96f('0x19')](function(_0x33a4b8){logger['error'](_0xf96f('0x11'),_0x40de4c,_0x33a4b8);_0x1314ba(_0x33a4b8);});});}exports[_0xf96f('0x1a')]=function(_0x3ec023){var _0x57b902=this;return new Promise(function(_0x1f54d8,_0x419402){return db[_0xf96f('0x1b')][_0xf96f('0x1c')]({'raw':_0x3ec023['options']?_0x3ec023[_0xf96f('0x1d')]['raw']===undefined?!![]:![]:!![],'where':_0x3ec023[_0xf96f('0x1d')]?_0x3ec023[_0xf96f('0x1d')][_0xf96f('0x1e')]||null:null,'attributes':_0x3ec023[_0xf96f('0x1d')]?_0x3ec023[_0xf96f('0x1d')]['attributes']||null:null,'include':_0x3ec023[_0xf96f('0x1d')]?_0x3ec023[_0xf96f('0x1d')]['include']?_[_0xf96f('0x1f')](_0x3ec023[_0xf96f('0x1d')][_0xf96f('0x20')],function(_0x1d1238){return{'model':db[_0x1d1238['model']],'as':_0x1d1238['as'],'attributes':_0x1d1238[_0xf96f('0x21')],'include':_0x1d1238[_0xf96f('0x20')]?_[_0xf96f('0x1f')](_0x1d1238['include'],function(_0x3c1be4){return{'model':db[_0x3c1be4['model']],'as':_0x3c1be4['as'],'attributes':_0x3c1be4[_0xf96f('0x21')],'include':_0x3c1be4['include']?_['map'](_0x3c1be4[_0xf96f('0x20')],function(_0x66edc0){return{'model':db[_0x66edc0['model']],'as':_0x66edc0['as'],'attributes':_0x66edc0[_0xf96f('0x21')]};}):[]};}):[]};}):[]:[]})[_0xf96f('0xf')](function(_0x515405){logger[_0xf96f('0x10')](_0xf96f('0x1a'),_0x3ec023);logger['debug'](_0xf96f('0x1a'),_0x3ec023,JSON[_0xf96f('0x15')](_0x515405));_0x1f54d8(_0x515405);})[_0xf96f('0x19')](function(_0x42c516){logger['error']('ShowWhatsappAccount',_0x42c516[_0xf96f('0x17')],_0x3ec023);_0x419402(_0x57b902[_0xf96f('0x16')](0x1f4,_0x42c516[_0xf96f('0x17')]));});});};