57d9fc4407899a0c1e31b01b92236fc74beab5ed
[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 _0xbffb=['jayson/promise','http','redis','defaults','localhost','./plugin.socket','register','request','then','Plugin,\x20%s,\x20%s','request\x20sent','debug','stringify','code','message','error','info','Plugin','body','options','raw','CreatePlugin','catch','lodash','util','moment','bluebird','ioredis','../../config/utils','../../config/logger','rpc','../../config/environment'];(function(_0x3e5997,_0x57c1cf){var _0x5d33fe=function(_0x8176d6){while(--_0x8176d6){_0x3e5997['push'](_0x3e5997['shift']());}};_0x5d33fe(++_0x57c1cf);}(_0xbffb,0x1b7));var _0xbbff=function(_0x3bc4ec,_0x439952){_0x3bc4ec=_0x3bc4ec-0x0;var _0x40a814=_0xbffb[_0x3bc4ec];return _0x40a814;};'use strict';var _=require(_0xbbff('0x0'));var util=require(_0xbbff('0x1'));var moment=require(_0xbbff('0x2'));var BPromise=require(_0xbbff('0x3'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0xbbff('0x4'));var db=require('../../mysqldb')['db'];var utils=require(_0xbbff('0x5'));var logger=require(_0xbbff('0x6'))(_0xbbff('0x7'));var config=require(_0xbbff('0x8'));var jayson=require(_0xbbff('0x9'));var client=jayson['client'][_0xbbff('0xa')]({'port':0x232a});config[_0xbbff('0xb')]=_[_0xbbff('0xc')](config[_0xbbff('0xb')],{'host':_0xbbff('0xd'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xbbff('0xb')]));require(_0xbbff('0xe'))[_0xbbff('0xf')](socket);function respondWithRpcPromise(_0x4da127,_0x2e3673,_0x4cec51){return new BPromise(function(_0x5c7ebf,_0x3af0fb){return client[_0xbbff('0x10')](_0x4da127,_0x4cec51)[_0xbbff('0x11')](function(_0x8eda7f){logger['info'](_0xbbff('0x12'),_0x2e3673,_0xbbff('0x13'));logger[_0xbbff('0x14')]('Plugin,\x20%s,\x20%s,\x20%s',_0x2e3673,_0xbbff('0x13'),JSON[_0xbbff('0x15')](_0x8eda7f));if(_0x8eda7f['error']){if(_0x8eda7f['error'][_0xbbff('0x16')]===0x1f4){logger['error'](_0xbbff('0x12'),_0x2e3673,_0x8eda7f['error'][_0xbbff('0x17')]);return _0x3af0fb(_0x8eda7f[_0xbbff('0x18')][_0xbbff('0x17')]);}logger[_0xbbff('0x18')]('Plugin,\x20%s,\x20%s',_0x2e3673,_0x8eda7f[_0xbbff('0x18')]['message']);return _0x5c7ebf(_0x8eda7f[_0xbbff('0x18')][_0xbbff('0x17')]);}else{logger[_0xbbff('0x19')](_0xbbff('0x12'),_0x2e3673,'request\x20sent');_0x5c7ebf(_0x8eda7f['result'][_0xbbff('0x17')]);}})['catch'](function(_0x563699){logger[_0xbbff('0x18')]('Plugin,\x20%s,\x20%s',_0x2e3673,_0x563699);_0x3af0fb(_0x563699);});});}exports['CreatePlugin']=function(_0x3f8548){var _0x4e1a81=this;return new Promise(function(_0x393dd8,_0x31f18b){return db[_0xbbff('0x1a')]['create'](_0x3f8548[_0xbbff('0x1b')],{'raw':_0x3f8548['options']?_0x3f8548[_0xbbff('0x1c')][_0xbbff('0x1d')]===undefined?!![]:![]:!![]})[_0xbbff('0x11')](function(_0x1cb423){logger[_0xbbff('0x19')](_0xbbff('0x1e'),_0x3f8548);logger[_0xbbff('0x14')](_0xbbff('0x1e'),_0x3f8548,JSON['stringify'](_0x1cb423));_0x393dd8(_0x1cb423);})[_0xbbff('0x1f')](function(_0x2e4a90){logger[_0xbbff('0x18')](_0xbbff('0x1e'),_0x2e4a90[_0xbbff('0x17')],_0x3f8548);_0x31f18b(_0x4e1a81['error'](0x1f4,_0x2e4a90['message']));});});};