a468c217f3f2cee0a64a174deb0eaf42084164ed
[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 _0xf165=['randomstring','ioredis','../../mysqldb','../../config/logger','../../config/environment','jayson/promise','client','redis','defaults','socket.io-emitter','./plugin.socket','register','request','then','info','Plugin,\x20%s,\x20%s','request\x20sent','debug','Plugin,\x20%s,\x20%s,\x20%s','error','code','message','result','CreatePlugin','Plugin','body','options','raw','stringify','catch','moment','bluebird'];(function(_0x1ad0be,_0x201224){var _0x561fe0=function(_0x286b6d){while(--_0x286b6d){_0x1ad0be['push'](_0x1ad0be['shift']());}};_0x561fe0(++_0x201224);}(_0xf165,0x11e));var _0x5f16=function(_0x5ddb7a,_0x1b8eb7){_0x5ddb7a=_0x5ddb7a-0x0;var _0x55ae1d=_0xf165[_0x5ddb7a];return _0x55ae1d;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0x5f16('0x0'));var BPromise=require(_0x5f16('0x1'));var rs=require(_0x5f16('0x2'));var fs=require('fs');var Redis=require(_0x5f16('0x3'));var db=require(_0x5f16('0x4'))['db'];var utils=require('../../config/utils');var logger=require(_0x5f16('0x5'))('rpc');var config=require(_0x5f16('0x6'));var jayson=require(_0x5f16('0x7'));var client=jayson[_0x5f16('0x8')]['http']({'port':0x232a});config[_0x5f16('0x9')]=_[_0x5f16('0xa')](config[_0x5f16('0x9')],{'host':'localhost','port':0x18eb});var socket=require(_0x5f16('0xb'))(new Redis(config['redis']));require(_0x5f16('0xc'))[_0x5f16('0xd')](socket);function respondWithRpcPromise(_0x2386f0,_0x1de962,_0x38884f){return new BPromise(function(_0x5b0023,_0x358cfa){return client[_0x5f16('0xe')](_0x2386f0,_0x38884f)[_0x5f16('0xf')](function(_0x298972){logger[_0x5f16('0x10')](_0x5f16('0x11'),_0x1de962,_0x5f16('0x12'));logger[_0x5f16('0x13')](_0x5f16('0x14'),_0x1de962,'request\x20sent',JSON['stringify'](_0x298972));if(_0x298972[_0x5f16('0x15')]){if(_0x298972[_0x5f16('0x15')][_0x5f16('0x16')]===0x1f4){logger['error'](_0x5f16('0x11'),_0x1de962,_0x298972['error'][_0x5f16('0x17')]);return _0x358cfa(_0x298972[_0x5f16('0x15')][_0x5f16('0x17')]);}logger[_0x5f16('0x15')](_0x5f16('0x11'),_0x1de962,_0x298972[_0x5f16('0x15')][_0x5f16('0x17')]);return _0x5b0023(_0x298972[_0x5f16('0x15')]['message']);}else{logger[_0x5f16('0x10')](_0x5f16('0x11'),_0x1de962,_0x5f16('0x12'));_0x5b0023(_0x298972[_0x5f16('0x18')][_0x5f16('0x17')]);}})['catch'](function(_0x1e2d1a){logger[_0x5f16('0x15')](_0x5f16('0x11'),_0x1de962,_0x1e2d1a);_0x358cfa(_0x1e2d1a);});});}exports[_0x5f16('0x19')]=function(_0x2e4d78){var _0x5929ab=this;return new Promise(function(_0x36e4ad,_0x2745b3){return db[_0x5f16('0x1a')]['create'](_0x2e4d78[_0x5f16('0x1b')],{'raw':_0x2e4d78[_0x5f16('0x1c')]?_0x2e4d78['options'][_0x5f16('0x1d')]===undefined?!![]:![]:!![]})[_0x5f16('0xf')](function(_0x49f91a){logger[_0x5f16('0x10')](_0x5f16('0x19'),_0x2e4d78);logger[_0x5f16('0x13')](_0x5f16('0x19'),_0x2e4d78,JSON[_0x5f16('0x1e')](_0x49f91a));_0x36e4ad(_0x49f91a);})[_0x5f16('0x1f')](function(_0x218c1f){logger['error'](_0x5f16('0x19'),_0x218c1f[_0x5f16('0x17')],_0x2e4d78);_0x2745b3(_0x5929ab[_0x5f16('0x15')](0x1f4,_0x218c1f['message']));});});};