831019fd8eb7619ca99437bc235ecff434e3aac4
[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 _0xa013=['code','Plugin,\x20%s,\x20%s','message','info','result','catch','CreatePlugin','create','body','options','util','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/environment','jayson/promise','client','http','defaults','redis','socket.io-emitter','./plugin.socket','register','request','then','request\x20sent','debug','Plugin,\x20%s,\x20%s,\x20%s','stringify','error'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0xa013,0x1ea));var _0x3a01=function(_0x2132a3,_0x4639e9){_0x2132a3=_0x2132a3-0x0;var _0x21890c=_0xa013[_0x2132a3];return _0x21890c;};'use strict';var _=require('lodash');var util=require(_0x3a01('0x0'));var moment=require('moment');var BPromise=require(_0x3a01('0x1'));var rs=require(_0x3a01('0x2'));var fs=require('fs');var Redis=require(_0x3a01('0x3'));var db=require(_0x3a01('0x4'))['db'];var utils=require(_0x3a01('0x5'));var logger=require('../../config/logger')('rpc');var config=require(_0x3a01('0x6'));var jayson=require(_0x3a01('0x7'));var client=jayson[_0x3a01('0x8')][_0x3a01('0x9')]({'port':0x232a});config['redis']=_[_0x3a01('0xa')](config[_0x3a01('0xb')],{'host':'localhost','port':0x18eb});var socket=require(_0x3a01('0xc'))(new Redis(config[_0x3a01('0xb')]));require(_0x3a01('0xd'))[_0x3a01('0xe')](socket);function respondWithRpcPromise(_0x2c864c,_0x1bcf00,_0x5584a6){return new BPromise(function(_0x4dad65,_0x125f2d){return client[_0x3a01('0xf')](_0x2c864c,_0x5584a6)[_0x3a01('0x10')](function(_0x525645){logger['info']('Plugin,\x20%s,\x20%s',_0x1bcf00,_0x3a01('0x11'));logger[_0x3a01('0x12')](_0x3a01('0x13'),_0x1bcf00,'request\x20sent',JSON[_0x3a01('0x14')](_0x525645));if(_0x525645[_0x3a01('0x15')]){if(_0x525645['error'][_0x3a01('0x16')]===0x1f4){logger[_0x3a01('0x15')](_0x3a01('0x17'),_0x1bcf00,_0x525645[_0x3a01('0x15')]['message']);return _0x125f2d(_0x525645['error'][_0x3a01('0x18')]);}logger[_0x3a01('0x15')](_0x3a01('0x17'),_0x1bcf00,_0x525645[_0x3a01('0x15')][_0x3a01('0x18')]);return _0x4dad65(_0x525645[_0x3a01('0x15')]['message']);}else{logger[_0x3a01('0x19')](_0x3a01('0x17'),_0x1bcf00,_0x3a01('0x11'));_0x4dad65(_0x525645[_0x3a01('0x1a')][_0x3a01('0x18')]);}})[_0x3a01('0x1b')](function(_0x250738){logger['error']('Plugin,\x20%s,\x20%s',_0x1bcf00,_0x250738);_0x125f2d(_0x250738);});});}exports[_0x3a01('0x1c')]=function(_0x51cf62){var _0x215dfd=this;return new Promise(function(_0x3c2326,_0x2cd6f9){return db['Plugin'][_0x3a01('0x1d')](_0x51cf62[_0x3a01('0x1e')],{'raw':_0x51cf62[_0x3a01('0x1f')]?_0x51cf62[_0x3a01('0x1f')]['raw']===undefined?!![]:![]:!![]})[_0x3a01('0x10')](function(_0x5419d3){logger[_0x3a01('0x19')](_0x3a01('0x1c'),_0x51cf62);logger[_0x3a01('0x12')](_0x3a01('0x1c'),_0x51cf62,JSON[_0x3a01('0x14')](_0x5419d3));_0x3c2326(_0x5419d3);})['catch'](function(_0x389917){logger[_0x3a01('0x15')](_0x3a01('0x1c'),_0x389917['message'],_0x51cf62);_0x2cd6f9(_0x215dfd[_0x3a01('0x15')](0x1f4,_0x389917['message']));});});};