1b3be2d5606ab692f5b33b72843a066d5d9013f4
[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 _0x8433=['error','code','Plugin,\x20%s,\x20%s','message','catch','CreatePlugin','Plugin','create','body','options','lodash','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/logger','../../config/environment','jayson/promise','client','http','redis','defaults','localhost','socket.io-emitter','./plugin.socket','request','then','info','request\x20sent','Plugin,\x20%s,\x20%s,\x20%s','stringify'];(function(_0xafdf47,_0x38b5b3){var _0x1e6c17=function(_0x6f64be){while(--_0x6f64be){_0xafdf47['push'](_0xafdf47['shift']());}};_0x1e6c17(++_0x38b5b3);}(_0x8433,0x1d8));var _0x3843=function(_0x3b87f4,_0x112243){_0x3b87f4=_0x3b87f4-0x0;var _0x63d16e=_0x8433[_0x3b87f4];return _0x63d16e;};'use strict';var _=require(_0x3843('0x0'));var util=require(_0x3843('0x1'));var moment=require(_0x3843('0x2'));var BPromise=require(_0x3843('0x3'));var rs=require(_0x3843('0x4'));var fs=require('fs');var Redis=require(_0x3843('0x5'));var db=require(_0x3843('0x6'))['db'];var utils=require('../../config/utils');var logger=require(_0x3843('0x7'))('rpc');var config=require(_0x3843('0x8'));var jayson=require(_0x3843('0x9'));var client=jayson[_0x3843('0xa')][_0x3843('0xb')]({'port':0x232a});config[_0x3843('0xc')]=_[_0x3843('0xd')](config[_0x3843('0xc')],{'host':_0x3843('0xe'),'port':0x18eb});var socket=require(_0x3843('0xf'))(new Redis(config[_0x3843('0xc')]));require(_0x3843('0x10'))['register'](socket);function respondWithRpcPromise(_0x4a39c3,_0x232d7c,_0x841392){return new BPromise(function(_0x371e22,_0x4c4994){return client[_0x3843('0x11')](_0x4a39c3,_0x841392)[_0x3843('0x12')](function(_0x2290ef){logger[_0x3843('0x13')]('Plugin,\x20%s,\x20%s',_0x232d7c,_0x3843('0x14'));logger['debug'](_0x3843('0x15'),_0x232d7c,_0x3843('0x14'),JSON[_0x3843('0x16')](_0x2290ef));if(_0x2290ef[_0x3843('0x17')]){if(_0x2290ef[_0x3843('0x17')][_0x3843('0x18')]===0x1f4){logger[_0x3843('0x17')](_0x3843('0x19'),_0x232d7c,_0x2290ef[_0x3843('0x17')][_0x3843('0x1a')]);return _0x4c4994(_0x2290ef[_0x3843('0x17')][_0x3843('0x1a')]);}logger[_0x3843('0x17')](_0x3843('0x19'),_0x232d7c,_0x2290ef[_0x3843('0x17')][_0x3843('0x1a')]);return _0x371e22(_0x2290ef[_0x3843('0x17')][_0x3843('0x1a')]);}else{logger['info']('Plugin,\x20%s,\x20%s',_0x232d7c,_0x3843('0x14'));_0x371e22(_0x2290ef['result'][_0x3843('0x1a')]);}})[_0x3843('0x1b')](function(_0x864fc8){logger[_0x3843('0x17')](_0x3843('0x19'),_0x232d7c,_0x864fc8);_0x4c4994(_0x864fc8);});});}exports[_0x3843('0x1c')]=function(_0xbbcc0e){var _0xa39464=this;return new Promise(function(_0xa4a8c7,_0xa2da5){return db[_0x3843('0x1d')][_0x3843('0x1e')](_0xbbcc0e[_0x3843('0x1f')],{'raw':_0xbbcc0e[_0x3843('0x20')]?_0xbbcc0e[_0x3843('0x20')]['raw']===undefined?!![]:![]:!![]})[_0x3843('0x12')](function(_0x219c9b){logger['info'](_0x3843('0x1c'),_0xbbcc0e);logger['debug'](_0x3843('0x1c'),_0xbbcc0e,JSON[_0x3843('0x16')](_0x219c9b));_0xa4a8c7(_0x219c9b);})['catch'](function(_0x19f8bd){logger[_0x3843('0x17')](_0x3843('0x1c'),_0x19f8bd[_0x3843('0x1a')],_0xbbcc0e);_0xa2da5(_0xa39464[_0x3843('0x17')](0x1f4,_0x19f8bd['message']));});});};