Built motion from commit 06eb8eb0.|2.6.31
[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 _0xa4e3=['body','options','raw','CreatePlugin','debug','catch','lodash','util','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','redis','defaults','socket.io-emitter','request','then','info','Plugin,\x20%s,\x20%s','request\x20sent','Plugin,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','create'];(function(_0x372a27,_0x4ec1c6){var _0x4e8005=function(_0x33f5de){while(--_0x33f5de){_0x372a27['push'](_0x372a27['shift']());}};_0x4e8005(++_0x4ec1c6);}(_0xa4e3,0x17c));var _0x3a4e=function(_0x18269d,_0xcc550c){_0x18269d=_0x18269d-0x0;var _0x3ba06f=_0xa4e3[_0x18269d];return _0x3ba06f;};'use strict';var _=require(_0x3a4e('0x0'));var util=require(_0x3a4e('0x1'));var moment=require('moment');var BPromise=require(_0x3a4e('0x2'));var rs=require(_0x3a4e('0x3'));var fs=require('fs');var Redis=require(_0x3a4e('0x4'));var db=require(_0x3a4e('0x5'))['db'];var utils=require(_0x3a4e('0x6'));var logger=require(_0x3a4e('0x7'))(_0x3a4e('0x8'));var config=require(_0x3a4e('0x9'));var jayson=require(_0x3a4e('0xa'));var client=jayson[_0x3a4e('0xb')][_0x3a4e('0xc')]({'port':0x232a});config[_0x3a4e('0xd')]=_[_0x3a4e('0xe')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0x3a4e('0xf'))(new Redis(config[_0x3a4e('0xd')]));require('./plugin.socket')['register'](socket);function respondWithRpcPromise(_0x191ccb,_0x4e7ca4,_0x40e403){return new BPromise(function(_0x2f9c97,_0xb737c){return client[_0x3a4e('0x10')](_0x191ccb,_0x40e403)[_0x3a4e('0x11')](function(_0x3eadbf){logger[_0x3a4e('0x12')](_0x3a4e('0x13'),_0x4e7ca4,_0x3a4e('0x14'));logger['debug'](_0x3a4e('0x15'),_0x4e7ca4,_0x3a4e('0x14'),JSON[_0x3a4e('0x16')](_0x3eadbf));if(_0x3eadbf[_0x3a4e('0x17')]){if(_0x3eadbf['error'][_0x3a4e('0x18')]===0x1f4){logger['error'](_0x3a4e('0x13'),_0x4e7ca4,_0x3eadbf[_0x3a4e('0x17')][_0x3a4e('0x19')]);return _0xb737c(_0x3eadbf[_0x3a4e('0x17')]['message']);}logger[_0x3a4e('0x17')](_0x3a4e('0x13'),_0x4e7ca4,_0x3eadbf[_0x3a4e('0x17')][_0x3a4e('0x19')]);return _0x2f9c97(_0x3eadbf[_0x3a4e('0x17')][_0x3a4e('0x19')]);}else{logger[_0x3a4e('0x12')](_0x3a4e('0x13'),_0x4e7ca4,'request\x20sent');_0x2f9c97(_0x3eadbf[_0x3a4e('0x1a')][_0x3a4e('0x19')]);}})['catch'](function(_0x5daf23){logger['error']('Plugin,\x20%s,\x20%s',_0x4e7ca4,_0x5daf23);_0xb737c(_0x5daf23);});});}exports['CreatePlugin']=function(_0x5778c8){var _0x526e5d=this;return new Promise(function(_0x3f631f,_0xd6c77d){return db['Plugin'][_0x3a4e('0x1b')](_0x5778c8[_0x3a4e('0x1c')],{'raw':_0x5778c8[_0x3a4e('0x1d')]?_0x5778c8[_0x3a4e('0x1d')][_0x3a4e('0x1e')]===undefined?!![]:![]:!![]})[_0x3a4e('0x11')](function(_0x3dd607){logger[_0x3a4e('0x12')](_0x3a4e('0x1f'),_0x5778c8);logger[_0x3a4e('0x20')](_0x3a4e('0x1f'),_0x5778c8,JSON['stringify'](_0x3dd607));_0x3f631f(_0x3dd607);})[_0x3a4e('0x21')](function(_0x30bbda){logger[_0x3a4e('0x17')](_0x3a4e('0x1f'),_0x30bbda['message'],_0x5778c8);_0xd6c77d(_0x526e5d[_0x3a4e('0x17')](0x1f4,_0x30bbda[_0x3a4e('0x19')]));});});};