e1ffe4925520e059fbc1c4b0e39ebf91bf7d2c31
[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 _0x5c38=['client','redis','defaults','socket.io-emitter','./plugin.socket','register','then','info','Plugin,\x20%s,\x20%s','request\x20sent','debug','Plugin,\x20%s,\x20%s,\x20%s','error','message','result','CreatePlugin','Plugin','body','options','stringify','catch','util','moment','bluebird','randomstring','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise'];(function(_0x22e11c,_0x32ef49){var _0x4fd8ed=function(_0x1098b7){while(--_0x1098b7){_0x22e11c['push'](_0x22e11c['shift']());}};_0x4fd8ed(++_0x32ef49);}(_0x5c38,0x189));var _0x85c3=function(_0x5153fd,_0x237b93){_0x5153fd=_0x5153fd-0x0;var _0x5ee7bc=_0x5c38[_0x5153fd];return _0x5ee7bc;};'use strict';var _=require('lodash');var util=require(_0x85c3('0x0'));var moment=require(_0x85c3('0x1'));var BPromise=require(_0x85c3('0x2'));var rs=require(_0x85c3('0x3'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x85c3('0x4'))['db'];var utils=require(_0x85c3('0x5'));var logger=require(_0x85c3('0x6'))(_0x85c3('0x7'));var config=require(_0x85c3('0x8'));var jayson=require(_0x85c3('0x9'));var client=jayson[_0x85c3('0xa')]['http']({'port':0x232a});config[_0x85c3('0xb')]=_[_0x85c3('0xc')](config[_0x85c3('0xb')],{'host':'localhost','port':0x18eb});var socket=require(_0x85c3('0xd'))(new Redis(config['redis']));require(_0x85c3('0xe'))[_0x85c3('0xf')](socket);function respondWithRpcPromise(_0x5b13dc,_0x2eb2aa,_0x38f5b3){return new BPromise(function(_0x46076e,_0x211f2a){return client['request'](_0x5b13dc,_0x38f5b3)[_0x85c3('0x10')](function(_0x32a29c){logger[_0x85c3('0x11')](_0x85c3('0x12'),_0x2eb2aa,_0x85c3('0x13'));logger[_0x85c3('0x14')](_0x85c3('0x15'),_0x2eb2aa,_0x85c3('0x13'),JSON['stringify'](_0x32a29c));if(_0x32a29c['error']){if(_0x32a29c['error']['code']===0x1f4){logger['error'](_0x85c3('0x12'),_0x2eb2aa,_0x32a29c[_0x85c3('0x16')][_0x85c3('0x17')]);return _0x211f2a(_0x32a29c[_0x85c3('0x16')][_0x85c3('0x17')]);}logger['error']('Plugin,\x20%s,\x20%s',_0x2eb2aa,_0x32a29c['error'][_0x85c3('0x17')]);return _0x46076e(_0x32a29c[_0x85c3('0x16')][_0x85c3('0x17')]);}else{logger['info']('Plugin,\x20%s,\x20%s',_0x2eb2aa,_0x85c3('0x13'));_0x46076e(_0x32a29c[_0x85c3('0x18')][_0x85c3('0x17')]);}})['catch'](function(_0x2fe249){logger[_0x85c3('0x16')](_0x85c3('0x12'),_0x2eb2aa,_0x2fe249);_0x211f2a(_0x2fe249);});});}exports[_0x85c3('0x19')]=function(_0x4c2815){var _0x2d2d9e=this;return new Promise(function(_0x586f2b,_0x5b268b){return db[_0x85c3('0x1a')]['create'](_0x4c2815[_0x85c3('0x1b')],{'raw':_0x4c2815[_0x85c3('0x1c')]?_0x4c2815[_0x85c3('0x1c')]['raw']===undefined?!![]:![]:!![]})[_0x85c3('0x10')](function(_0x3a339a){logger['info'](_0x85c3('0x19'),_0x4c2815);logger['debug'](_0x85c3('0x19'),_0x4c2815,JSON[_0x85c3('0x1d')](_0x3a339a));_0x586f2b(_0x3a339a);})[_0x85c3('0x1e')](function(_0x5bbb7d){logger[_0x85c3('0x16')](_0x85c3('0x19'),_0x5bbb7d['message'],_0x4c2815);_0x5b268b(_0x2d2d9e['error'](0x1f4,_0x5bbb7d[_0x85c3('0x17')]));});});};