14990738702c8c23dafe0984bfe0067fb91b7775
[motion2.git] / server / api / plugin / plugin.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 _0x974f=['redis','defaults','socket.io-emitter','./plugin.socket','register','info','request\x20sent','stringify','error','Plugin,\x20%s,\x20%s','message','result','catch','CreatePlugin','Plugin','create','body','options','raw','then','debug','util','moment','bluebird','randomstring','jayson/promise','client','http'];(function(_0x3b7af1,_0x16b3ca){var _0x224dd3=function(_0x54e9c8){while(--_0x54e9c8){_0x3b7af1['push'](_0x3b7af1['shift']());}};_0x224dd3(++_0x16b3ca);}(_0x974f,0x85));var _0xf974=function(_0xe836c2,_0x214edd){_0xe836c2=_0xe836c2-0x0;var _0x22f85c=_0x974f[_0xe836c2];return _0x22f85c;};'use strict';var _=require('lodash');var util=require(_0xf974('0x0'));var moment=require(_0xf974('0x1'));var BPromise=require(_0xf974('0x2'));var rs=require(_0xf974('0x3'));var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')('rpc');var config=require('../../config/environment');var jayson=require(_0xf974('0x4'));var client=jayson[_0xf974('0x5')][_0xf974('0x6')]({'port':0x232a});config[_0xf974('0x7')]=_[_0xf974('0x8')](config[_0xf974('0x7')],{'host':'localhost','port':0x18eb});var socket=require(_0xf974('0x9'))(new Redis(config[_0xf974('0x7')]));require(_0xf974('0xa'))[_0xf974('0xb')](socket);function respondWithRpcPromise(_0x3a7bbe,_0x1ee421,_0x4d82cb){return new BPromise(function(_0x933f8f,_0x4c7b0a){return client['request'](_0x3a7bbe,_0x4d82cb)['then'](function(_0x3dfdb2){logger[_0xf974('0xc')]('Plugin,\x20%s,\x20%s',_0x1ee421,'request\x20sent');logger['debug']('Plugin,\x20%s,\x20%s,\x20%s',_0x1ee421,_0xf974('0xd'),JSON[_0xf974('0xe')](_0x3dfdb2));if(_0x3dfdb2['error']){if(_0x3dfdb2[_0xf974('0xf')]['code']===0x1f4){logger[_0xf974('0xf')](_0xf974('0x10'),_0x1ee421,_0x3dfdb2[_0xf974('0xf')][_0xf974('0x11')]);return _0x4c7b0a(_0x3dfdb2[_0xf974('0xf')]['message']);}logger[_0xf974('0xf')](_0xf974('0x10'),_0x1ee421,_0x3dfdb2[_0xf974('0xf')]['message']);return _0x933f8f(_0x3dfdb2[_0xf974('0xf')]['message']);}else{logger[_0xf974('0xc')](_0xf974('0x10'),_0x1ee421,_0xf974('0xd'));_0x933f8f(_0x3dfdb2[_0xf974('0x12')][_0xf974('0x11')]);}})[_0xf974('0x13')](function(_0x1a7e51){logger[_0xf974('0xf')](_0xf974('0x10'),_0x1ee421,_0x1a7e51);_0x4c7b0a(_0x1a7e51);});});}exports[_0xf974('0x14')]=function(_0x1badf5){var _0xabcda1=this;return new Promise(function(_0x5e78f3,_0x4c5cd1){return db[_0xf974('0x15')][_0xf974('0x16')](_0x1badf5[_0xf974('0x17')],{'raw':_0x1badf5['options']?_0x1badf5[_0xf974('0x18')][_0xf974('0x19')]===undefined?!![]:![]:!![]})[_0xf974('0x1a')](function(_0x309d6e){logger[_0xf974('0xc')](_0xf974('0x14'),_0x1badf5);logger[_0xf974('0x1b')]('CreatePlugin',_0x1badf5,JSON['stringify'](_0x309d6e));_0x5e78f3(_0x309d6e);})[_0xf974('0x13')](function(_0xef33b5){logger[_0xf974('0xf')](_0xf974('0x14'),_0xef33b5[_0xf974('0x11')],_0x1badf5);_0x4c5cd1(_0xabcda1[_0xf974('0xf')](0x1f4,_0xef33b5[_0xf974('0x11')]));});});};