Built motion from commit (unavailable).|2.5.4
[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 _0xddb9=['socket.io-emitter','./plugin.socket','register','request','then','Plugin,\x20%s,\x20%s','request\x20sent','debug','stringify','code','error','message','info','result','CreatePlugin','Plugin','create','options','raw','catch','lodash','util','bluebird','ioredis','../../mysqldb','../../config/utils','rpc','jayson/promise','client','http','redis'];(function(_0x2f899b,_0x39018c){var _0x18adca=function(_0x3c208e){while(--_0x3c208e){_0x2f899b['push'](_0x2f899b['shift']());}};_0x18adca(++_0x39018c);}(_0xddb9,0x169));var _0x9ddb=function(_0x4e2ca6,_0x4a29ca){_0x4e2ca6=_0x4e2ca6-0x0;var _0xd809ee=_0xddb9[_0x4e2ca6];return _0xd809ee;};'use strict';var _=require(_0x9ddb('0x0'));var util=require(_0x9ddb('0x1'));var moment=require('moment');var BPromise=require(_0x9ddb('0x2'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x9ddb('0x3'));var db=require(_0x9ddb('0x4'))['db'];var utils=require(_0x9ddb('0x5'));var logger=require('../../config/logger')(_0x9ddb('0x6'));var config=require('../../config/environment');var jayson=require(_0x9ddb('0x7'));var client=jayson[_0x9ddb('0x8')][_0x9ddb('0x9')]({'port':0x232a});config[_0x9ddb('0xa')]=_['defaults'](config[_0x9ddb('0xa')],{'host':'localhost','port':0x18eb});var socket=require(_0x9ddb('0xb'))(new Redis(config[_0x9ddb('0xa')]));require(_0x9ddb('0xc'))[_0x9ddb('0xd')](socket);function respondWithRpcPromise(_0x3293b3,_0x15e353,_0x565f3f){return new BPromise(function(_0x2888fb,_0x2f773e){return client[_0x9ddb('0xe')](_0x3293b3,_0x565f3f)[_0x9ddb('0xf')](function(_0x40e355){logger['info'](_0x9ddb('0x10'),_0x15e353,_0x9ddb('0x11'));logger[_0x9ddb('0x12')]('Plugin,\x20%s,\x20%s,\x20%s',_0x15e353,_0x9ddb('0x11'),JSON[_0x9ddb('0x13')](_0x40e355));if(_0x40e355['error']){if(_0x40e355['error'][_0x9ddb('0x14')]===0x1f4){logger[_0x9ddb('0x15')](_0x9ddb('0x10'),_0x15e353,_0x40e355[_0x9ddb('0x15')][_0x9ddb('0x16')]);return _0x2f773e(_0x40e355[_0x9ddb('0x15')][_0x9ddb('0x16')]);}logger['error'](_0x9ddb('0x10'),_0x15e353,_0x40e355['error'][_0x9ddb('0x16')]);return _0x2888fb(_0x40e355[_0x9ddb('0x15')][_0x9ddb('0x16')]);}else{logger[_0x9ddb('0x17')](_0x9ddb('0x10'),_0x15e353,'request\x20sent');_0x2888fb(_0x40e355[_0x9ddb('0x18')][_0x9ddb('0x16')]);}})['catch'](function(_0x592a88){logger[_0x9ddb('0x15')](_0x9ddb('0x10'),_0x15e353,_0x592a88);_0x2f773e(_0x592a88);});});}exports[_0x9ddb('0x19')]=function(_0xdade2b){var _0x4ca70f=this;return new Promise(function(_0x203e18,_0x47a556){return db[_0x9ddb('0x1a')][_0x9ddb('0x1b')](_0xdade2b['body'],{'raw':_0xdade2b[_0x9ddb('0x1c')]?_0xdade2b[_0x9ddb('0x1c')][_0x9ddb('0x1d')]===undefined?!![]:![]:!![]})['then'](function(_0x2087c1){logger['info'](_0x9ddb('0x19'),_0xdade2b);logger[_0x9ddb('0x12')](_0x9ddb('0x19'),_0xdade2b,JSON['stringify'](_0x2087c1));_0x203e18(_0x2087c1);})[_0x9ddb('0x1e')](function(_0x3c9db0){logger[_0x9ddb('0x15')](_0x9ddb('0x19'),_0x3c9db0[_0x9ddb('0x16')],_0xdade2b);_0x47a556(_0x4ca70f[_0x9ddb('0x15')](0x1f4,_0x3c9db0['message']));});});};