4a436e5a1c15b7958127f663f83058d27d7610af
[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 _0xb859=['../../mysqldb','../../config/utils','rpc','../../config/environment','jayson/promise','http','redis','defaults','localhost','./plugin.socket','then','info','Plugin,\x20%s,\x20%s','debug','Plugin,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','result','CreatePlugin','Plugin','options','raw','catch','lodash','bluebird'];(function(_0x2dd5f4,_0x37b7ba){var _0x52fcb3=function(_0x3fd5ff){while(--_0x3fd5ff){_0x2dd5f4['push'](_0x2dd5f4['shift']());}};_0x52fcb3(++_0x37b7ba);}(_0xb859,0xa6));var _0x9b85=function(_0x4c3070,_0xc2fb4c){_0x4c3070=_0x4c3070-0x0;var _0x536a44=_0xb859[_0x4c3070];return _0x536a44;};'use strict';var _=require(_0x9b85('0x0'));var util=require('util');var moment=require('moment');var BPromise=require(_0x9b85('0x1'));var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require(_0x9b85('0x2'))['db'];var utils=require(_0x9b85('0x3'));var logger=require('../../config/logger')(_0x9b85('0x4'));var config=require(_0x9b85('0x5'));var jayson=require(_0x9b85('0x6'));var client=jayson['client'][_0x9b85('0x7')]({'port':0x232a});config[_0x9b85('0x8')]=_[_0x9b85('0x9')](config[_0x9b85('0x8')],{'host':_0x9b85('0xa'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x9b85('0x8')]));require(_0x9b85('0xb'))['register'](socket);function respondWithRpcPromise(_0x560267,_0x47fe30,_0x3eadf2){return new BPromise(function(_0xdfddb0,_0x2e1253){return client['request'](_0x560267,_0x3eadf2)[_0x9b85('0xc')](function(_0xc18d17){logger[_0x9b85('0xd')](_0x9b85('0xe'),_0x47fe30,'request\x20sent');logger[_0x9b85('0xf')](_0x9b85('0x10'),_0x47fe30,_0x9b85('0x11'),JSON[_0x9b85('0x12')](_0xc18d17));if(_0xc18d17[_0x9b85('0x13')]){if(_0xc18d17['error'][_0x9b85('0x14')]===0x1f4){logger['error'](_0x9b85('0xe'),_0x47fe30,_0xc18d17[_0x9b85('0x13')][_0x9b85('0x15')]);return _0x2e1253(_0xc18d17['error']['message']);}logger[_0x9b85('0x13')]('Plugin,\x20%s,\x20%s',_0x47fe30,_0xc18d17[_0x9b85('0x13')][_0x9b85('0x15')]);return _0xdfddb0(_0xc18d17[_0x9b85('0x13')][_0x9b85('0x15')]);}else{logger[_0x9b85('0xd')](_0x9b85('0xe'),_0x47fe30,_0x9b85('0x11'));_0xdfddb0(_0xc18d17[_0x9b85('0x16')][_0x9b85('0x15')]);}})['catch'](function(_0x3036dc){logger[_0x9b85('0x13')](_0x9b85('0xe'),_0x47fe30,_0x3036dc);_0x2e1253(_0x3036dc);});});}exports[_0x9b85('0x17')]=function(_0x1ca95f){var _0x40c557=this;return new Promise(function(_0x59e27d,_0x221f49){return db[_0x9b85('0x18')]['create'](_0x1ca95f['body'],{'raw':_0x1ca95f['options']?_0x1ca95f[_0x9b85('0x19')][_0x9b85('0x1a')]===undefined?!![]:![]:!![]})['then'](function(_0x12bd72){logger['info']('CreatePlugin',_0x1ca95f);logger['debug'](_0x9b85('0x17'),_0x1ca95f,JSON['stringify'](_0x12bd72));_0x59e27d(_0x12bd72);})[_0x9b85('0x1b')](function(_0x2b052a){logger[_0x9b85('0x13')](_0x9b85('0x17'),_0x2b052a['message'],_0x1ca95f);_0x221f49(_0x40c557[_0x9b85('0x13')](0x1f4,_0x2b052a[_0x9b85('0x15')]));});});};