3e07cfb3b398d0fed67a65dd039fc17dfc9fc4e8
[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 _0x3ad2=['localhost','socket.io-emitter','./whatsappAccount.socket','request','info','WhatsappAccount,\x20%s,\x20%s','request\x20sent','debug','WhatsappAccount,\x20%s,\x20%s,\x20%s','error','code','message','result','catch','ShowWhatsappAccount','find','options','raw','where','map','attributes','include','model','then','stringify','lodash','util','randomstring','ioredis','rpc','../../config/environment','jayson/promise','http','defaults','redis'];(function(_0x51cda6,_0x3fa1d5){var _0x3ec907=function(_0x4f5ac5){while(--_0x4f5ac5){_0x51cda6['push'](_0x51cda6['shift']());}};_0x3ec907(++_0x3fa1d5);}(_0x3ad2,0x154));var _0x23ad=function(_0x542749,_0x3d95bb){_0x542749=_0x542749-0x0;var _0x4612dd=_0x3ad2[_0x542749];return _0x4612dd;};'use strict';var _=require(_0x23ad('0x0'));var util=require(_0x23ad('0x1'));var moment=require('moment');var BPromise=require('bluebird');var rs=require(_0x23ad('0x2'));var fs=require('fs');var Redis=require(_0x23ad('0x3'));var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')(_0x23ad('0x4'));var config=require(_0x23ad('0x5'));var jayson=require(_0x23ad('0x6'));var client=jayson['client'][_0x23ad('0x7')]({'port':0x232a});config['redis']=_[_0x23ad('0x8')](config[_0x23ad('0x9')],{'host':_0x23ad('0xa'),'port':0x18eb});var socket=require(_0x23ad('0xb'))(new Redis(config['redis']));require(_0x23ad('0xc'))['register'](socket);function respondWithRpcPromise(_0x1d5f49,_0x2af6e3,_0x44afb8){return new BPromise(function(_0x594cc9,_0x5d83d6){return client[_0x23ad('0xd')](_0x1d5f49,_0x44afb8)['then'](function(_0x3bfbe0){logger[_0x23ad('0xe')](_0x23ad('0xf'),_0x2af6e3,_0x23ad('0x10'));logger[_0x23ad('0x11')](_0x23ad('0x12'),_0x2af6e3,_0x23ad('0x10'),JSON['stringify'](_0x3bfbe0));if(_0x3bfbe0[_0x23ad('0x13')]){if(_0x3bfbe0[_0x23ad('0x13')][_0x23ad('0x14')]===0x1f4){logger[_0x23ad('0x13')](_0x23ad('0xf'),_0x2af6e3,_0x3bfbe0[_0x23ad('0x13')][_0x23ad('0x15')]);return _0x5d83d6(_0x3bfbe0['error'][_0x23ad('0x15')]);}logger['error'](_0x23ad('0xf'),_0x2af6e3,_0x3bfbe0['error'][_0x23ad('0x15')]);return _0x594cc9(_0x3bfbe0[_0x23ad('0x13')][_0x23ad('0x15')]);}else{logger[_0x23ad('0xe')](_0x23ad('0xf'),_0x2af6e3,'request\x20sent');_0x594cc9(_0x3bfbe0[_0x23ad('0x16')][_0x23ad('0x15')]);}})[_0x23ad('0x17')](function(_0x2bf640){logger['error'](_0x23ad('0xf'),_0x2af6e3,_0x2bf640);_0x5d83d6(_0x2bf640);});});}exports[_0x23ad('0x18')]=function(_0x4d0f57){var _0x4615c6=this;return new Promise(function(_0x1473a1,_0x31a222){return db['WhatsappAccount'][_0x23ad('0x19')]({'raw':_0x4d0f57[_0x23ad('0x1a')]?_0x4d0f57[_0x23ad('0x1a')][_0x23ad('0x1b')]===undefined?!![]:![]:!![],'where':_0x4d0f57[_0x23ad('0x1a')]?_0x4d0f57['options'][_0x23ad('0x1c')]||null:null,'attributes':_0x4d0f57[_0x23ad('0x1a')]?_0x4d0f57[_0x23ad('0x1a')]['attributes']||null:null,'include':_0x4d0f57[_0x23ad('0x1a')]?_0x4d0f57[_0x23ad('0x1a')]['include']?_[_0x23ad('0x1d')](_0x4d0f57[_0x23ad('0x1a')]['include'],function(_0x4d7819){return{'model':db[_0x4d7819['model']],'as':_0x4d7819['as'],'attributes':_0x4d7819[_0x23ad('0x1e')],'include':_0x4d7819[_0x23ad('0x1f')]?_['map'](_0x4d7819[_0x23ad('0x1f')],function(_0x3c85cd){return{'model':db[_0x3c85cd[_0x23ad('0x20')]],'as':_0x3c85cd['as'],'attributes':_0x3c85cd['attributes'],'include':_0x3c85cd[_0x23ad('0x1f')]?_['map'](_0x3c85cd[_0x23ad('0x1f')],function(_0x5947b8){return{'model':db[_0x5947b8['model']],'as':_0x5947b8['as'],'attributes':_0x5947b8[_0x23ad('0x1e')]};}):[]};}):[]};}):[]:[]})[_0x23ad('0x21')](function(_0x41f5f8){logger[_0x23ad('0xe')](_0x23ad('0x18'),_0x4d0f57);logger[_0x23ad('0x11')](_0x23ad('0x18'),_0x4d0f57,JSON[_0x23ad('0x22')](_0x41f5f8));_0x1473a1(_0x41f5f8);})[_0x23ad('0x17')](function(_0x17563d){logger[_0x23ad('0x13')]('ShowWhatsappAccount',_0x17563d['message'],_0x4d0f57);_0x31a222(_0x4615c6[_0x23ad('0x13')](0x1f4,_0x17563d[_0x23ad('0x15')]));});});};