Built motion from commit b5413ace.|2.6.9
[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 _0x52b8=['result','catch','CreatePlugin','Plugin','create','body','options','raw','util','bluebird','randomstring','../../mysqldb','../../config/logger','jayson/promise','http','redis','socket.io-emitter','./plugin.socket','register','request','then','info','Plugin,\x20%s,\x20%s','debug','Plugin,\x20%s,\x20%s,\x20%s','stringify','error','message','request\x20sent'];(function(_0x4a9fb1,_0x273043){var _0x348672=function(_0x142b69){while(--_0x142b69){_0x4a9fb1['push'](_0x4a9fb1['shift']());}};_0x348672(++_0x273043);}(_0x52b8,0xd3));var _0x852b=function(_0x5525e1,_0x329a28){_0x5525e1=_0x5525e1-0x0;var _0x245f5c=_0x52b8[_0x5525e1];return _0x245f5c;};'use strict';var _=require('lodash');var util=require(_0x852b('0x0'));var moment=require('moment');var BPromise=require(_0x852b('0x1'));var rs=require(_0x852b('0x2'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x852b('0x3'))['db'];var utils=require('../../config/utils');var logger=require(_0x852b('0x4'))('rpc');var config=require('../../config/environment');var jayson=require(_0x852b('0x5'));var client=jayson['client'][_0x852b('0x6')]({'port':0x232a});config[_0x852b('0x7')]=_['defaults'](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0x852b('0x8'))(new Redis(config[_0x852b('0x7')]));require(_0x852b('0x9'))[_0x852b('0xa')](socket);function respondWithRpcPromise(_0x1d5387,_0x5d4c6a,_0x213e24){return new BPromise(function(_0x12e3f4,_0x41a36b){return client[_0x852b('0xb')](_0x1d5387,_0x213e24)[_0x852b('0xc')](function(_0x56a9e7){logger[_0x852b('0xd')](_0x852b('0xe'),_0x5d4c6a,'request\x20sent');logger[_0x852b('0xf')](_0x852b('0x10'),_0x5d4c6a,'request\x20sent',JSON[_0x852b('0x11')](_0x56a9e7));if(_0x56a9e7[_0x852b('0x12')]){if(_0x56a9e7[_0x852b('0x12')]['code']===0x1f4){logger[_0x852b('0x12')](_0x852b('0xe'),_0x5d4c6a,_0x56a9e7[_0x852b('0x12')][_0x852b('0x13')]);return _0x41a36b(_0x56a9e7[_0x852b('0x12')][_0x852b('0x13')]);}logger[_0x852b('0x12')](_0x852b('0xe'),_0x5d4c6a,_0x56a9e7['error']['message']);return _0x12e3f4(_0x56a9e7[_0x852b('0x12')][_0x852b('0x13')]);}else{logger[_0x852b('0xd')]('Plugin,\x20%s,\x20%s',_0x5d4c6a,_0x852b('0x14'));_0x12e3f4(_0x56a9e7[_0x852b('0x15')][_0x852b('0x13')]);}})[_0x852b('0x16')](function(_0x16491a){logger[_0x852b('0x12')](_0x852b('0xe'),_0x5d4c6a,_0x16491a);_0x41a36b(_0x16491a);});});}exports[_0x852b('0x17')]=function(_0xa928f9){var _0x28326a=this;return new Promise(function(_0x272808,_0x15118e){return db[_0x852b('0x18')][_0x852b('0x19')](_0xa928f9[_0x852b('0x1a')],{'raw':_0xa928f9[_0x852b('0x1b')]?_0xa928f9[_0x852b('0x1b')][_0x852b('0x1c')]===undefined?!![]:![]:!![]})[_0x852b('0xc')](function(_0x2c0371){logger[_0x852b('0xd')](_0x852b('0x17'),_0xa928f9);logger[_0x852b('0xf')](_0x852b('0x17'),_0xa928f9,JSON['stringify'](_0x2c0371));_0x272808(_0x2c0371);})['catch'](function(_0x26f596){logger[_0x852b('0x12')](_0x852b('0x17'),_0x26f596[_0x852b('0x13')],_0xa928f9);_0x15118e(_0x28326a[_0x852b('0x12')](0x1f4,_0x26f596[_0x852b('0x13')]));});});};