9f2086cd5138c7701663b6d167f8d9c9934f13ec
[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 _0xecf8=['catch','Plugin','create','options','raw','CreatePlugin','stringify','lodash','util','moment','bluebird','../../config/logger','../../config/environment','jayson/promise','client','http','defaults','redis','localhost','socket.io-emitter','request','then','Plugin,\x20%s,\x20%s','request\x20sent','debug','Plugin,\x20%s,\x20%s,\x20%s','error','message','info','result'];(function(_0x1606ad,_0x2a757f){var _0x4ff678=function(_0x1037c7){while(--_0x1037c7){_0x1606ad['push'](_0x1606ad['shift']());}};_0x4ff678(++_0x2a757f);}(_0xecf8,0x16f));var _0x8ecf=function(_0x395488,_0x2254d1){_0x395488=_0x395488-0x0;var _0x23ff6b=_0xecf8[_0x395488];return _0x23ff6b;};'use strict';var _=require(_0x8ecf('0x0'));var util=require(_0x8ecf('0x1'));var moment=require(_0x8ecf('0x2'));var BPromise=require(_0x8ecf('0x3'));var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require(_0x8ecf('0x4'))('rpc');var config=require(_0x8ecf('0x5'));var jayson=require(_0x8ecf('0x6'));var client=jayson[_0x8ecf('0x7')][_0x8ecf('0x8')]({'port':0x232a});config['redis']=_[_0x8ecf('0x9')](config[_0x8ecf('0xa')],{'host':_0x8ecf('0xb'),'port':0x18eb});var socket=require(_0x8ecf('0xc'))(new Redis(config[_0x8ecf('0xa')]));require('./plugin.socket')['register'](socket);function respondWithRpcPromise(_0x315703,_0x14cc61,_0x1d9888){return new BPromise(function(_0x153aad,_0x446759){return client[_0x8ecf('0xd')](_0x315703,_0x1d9888)[_0x8ecf('0xe')](function(_0x4ef8b2){logger['info'](_0x8ecf('0xf'),_0x14cc61,_0x8ecf('0x10'));logger[_0x8ecf('0x11')](_0x8ecf('0x12'),_0x14cc61,_0x8ecf('0x10'),JSON['stringify'](_0x4ef8b2));if(_0x4ef8b2[_0x8ecf('0x13')]){if(_0x4ef8b2[_0x8ecf('0x13')]['code']===0x1f4){logger['error'](_0x8ecf('0xf'),_0x14cc61,_0x4ef8b2[_0x8ecf('0x13')][_0x8ecf('0x14')]);return _0x446759(_0x4ef8b2['error']['message']);}logger[_0x8ecf('0x13')](_0x8ecf('0xf'),_0x14cc61,_0x4ef8b2[_0x8ecf('0x13')][_0x8ecf('0x14')]);return _0x153aad(_0x4ef8b2['error'][_0x8ecf('0x14')]);}else{logger[_0x8ecf('0x15')]('Plugin,\x20%s,\x20%s',_0x14cc61,_0x8ecf('0x10'));_0x153aad(_0x4ef8b2[_0x8ecf('0x16')][_0x8ecf('0x14')]);}})[_0x8ecf('0x17')](function(_0x1afd3f){logger[_0x8ecf('0x13')](_0x8ecf('0xf'),_0x14cc61,_0x1afd3f);_0x446759(_0x1afd3f);});});}exports['CreatePlugin']=function(_0x4c979d){var _0x428383=this;return new Promise(function(_0xbf49a6,_0x190479){return db[_0x8ecf('0x18')][_0x8ecf('0x19')](_0x4c979d['body'],{'raw':_0x4c979d[_0x8ecf('0x1a')]?_0x4c979d[_0x8ecf('0x1a')][_0x8ecf('0x1b')]===undefined?!![]:![]:!![]})[_0x8ecf('0xe')](function(_0x450f94){logger[_0x8ecf('0x15')](_0x8ecf('0x1c'),_0x4c979d);logger[_0x8ecf('0x11')](_0x8ecf('0x1c'),_0x4c979d,JSON[_0x8ecf('0x1d')](_0x450f94));_0xbf49a6(_0x450f94);})[_0x8ecf('0x17')](function(_0x4dbe7f){logger[_0x8ecf('0x13')]('CreatePlugin',_0x4dbe7f['message'],_0x4c979d);_0x190479(_0x428383[_0x8ecf('0x13')](0x1f4,_0x4dbe7f[_0x8ecf('0x14')]));});});};