b085506222071a1fe00a4a276f91d1fd19cb2a68
[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 _0x4b27=['defaults','localhost','socket.io-emitter','./plugin.socket','request','then','info','Plugin,\x20%s,\x20%s','debug','request\x20sent','error','code','message','catch','create','options','raw','CreatePlugin','lodash','util','moment','bluebird','../../mysqldb','../../config/utils','../../config/logger','rpc','jayson/promise','client','redis'];(function(_0x37f527,_0x6f9b27){var _0x4d119c=function(_0x332a13){while(--_0x332a13){_0x37f527['push'](_0x37f527['shift']());}};_0x4d119c(++_0x6f9b27);}(_0x4b27,0xfa));var _0x74b2=function(_0x44403d,_0x253dda){_0x44403d=_0x44403d-0x0;var _0x354c27=_0x4b27[_0x44403d];return _0x354c27;};'use strict';var _=require(_0x74b2('0x0'));var util=require(_0x74b2('0x1'));var moment=require(_0x74b2('0x2'));var BPromise=require(_0x74b2('0x3'));var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require(_0x74b2('0x4'))['db'];var utils=require(_0x74b2('0x5'));var logger=require(_0x74b2('0x6'))(_0x74b2('0x7'));var config=require('../../config/environment');var jayson=require(_0x74b2('0x8'));var client=jayson[_0x74b2('0x9')]['http']({'port':0x232a});config[_0x74b2('0xa')]=_[_0x74b2('0xb')](config[_0x74b2('0xa')],{'host':_0x74b2('0xc'),'port':0x18eb});var socket=require(_0x74b2('0xd'))(new Redis(config[_0x74b2('0xa')]));require(_0x74b2('0xe'))['register'](socket);function respondWithRpcPromise(_0x2cb29b,_0xa2e53f,_0x59a108){return new BPromise(function(_0x43d679,_0x203c2b){return client[_0x74b2('0xf')](_0x2cb29b,_0x59a108)[_0x74b2('0x10')](function(_0x18c952){logger[_0x74b2('0x11')](_0x74b2('0x12'),_0xa2e53f,'request\x20sent');logger[_0x74b2('0x13')]('Plugin,\x20%s,\x20%s,\x20%s',_0xa2e53f,_0x74b2('0x14'),JSON['stringify'](_0x18c952));if(_0x18c952[_0x74b2('0x15')]){if(_0x18c952['error'][_0x74b2('0x16')]===0x1f4){logger[_0x74b2('0x15')]('Plugin,\x20%s,\x20%s',_0xa2e53f,_0x18c952[_0x74b2('0x15')]['message']);return _0x203c2b(_0x18c952['error'][_0x74b2('0x17')]);}logger[_0x74b2('0x15')](_0x74b2('0x12'),_0xa2e53f,_0x18c952['error'][_0x74b2('0x17')]);return _0x43d679(_0x18c952[_0x74b2('0x15')]['message']);}else{logger[_0x74b2('0x11')](_0x74b2('0x12'),_0xa2e53f,'request\x20sent');_0x43d679(_0x18c952['result'][_0x74b2('0x17')]);}})[_0x74b2('0x18')](function(_0x3261a4){logger['error'](_0x74b2('0x12'),_0xa2e53f,_0x3261a4);_0x203c2b(_0x3261a4);});});}exports['CreatePlugin']=function(_0x3a090a){var _0x2ab04d=this;return new Promise(function(_0x1725bb,_0x4c42a0){return db['Plugin'][_0x74b2('0x19')](_0x3a090a['body'],{'raw':_0x3a090a[_0x74b2('0x1a')]?_0x3a090a['options'][_0x74b2('0x1b')]===undefined?!![]:![]:!![]})[_0x74b2('0x10')](function(_0x125b48){logger[_0x74b2('0x11')]('CreatePlugin',_0x3a090a);logger['debug'](_0x74b2('0x1c'),_0x3a090a,JSON['stringify'](_0x125b48));_0x1725bb(_0x125b48);})['catch'](function(_0x430bbc){logger[_0x74b2('0x15')](_0x74b2('0x1c'),_0x430bbc[_0x74b2('0x17')],_0x3a090a);_0x4c42a0(_0x2ab04d[_0x74b2('0x15')](0x1f4,_0x430bbc['message']));});});};