Built motion from commit (unavailable).|2.4.3
[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 _0x6536=['randomstring','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','redis','localhost','./plugin.socket','register','request','then','Plugin,\x20%s,\x20%s','debug','request\x20sent','stringify','error','code','message','info','result','CreatePlugin','create','body','options','raw','moment'];(function(_0x3becc8,_0x3dc8a9){var _0x49f387=function(_0x48765f){while(--_0x48765f){_0x3becc8['push'](_0x3becc8['shift']());}};_0x49f387(++_0x3dc8a9);}(_0x6536,0x1cf));var _0x6653=function(_0x3a7272,_0x5f0cae){_0x3a7272=_0x3a7272-0x0;var _0x2483d5=_0x6536[_0x3a7272];return _0x2483d5;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0x6653('0x0'));var BPromise=require('bluebird');var rs=require(_0x6653('0x1'));var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require(_0x6653('0x2'));var logger=require(_0x6653('0x3'))(_0x6653('0x4'));var config=require(_0x6653('0x5'));var jayson=require(_0x6653('0x6'));var client=jayson[_0x6653('0x7')][_0x6653('0x8')]({'port':0x232a});config[_0x6653('0x9')]=_['defaults'](config[_0x6653('0x9')],{'host':_0x6653('0xa'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x6653('0x9')]));require(_0x6653('0xb'))[_0x6653('0xc')](socket);function respondWithRpcPromise(_0x5e5385,_0x3110bc,_0x2179f3){return new BPromise(function(_0x4f8aa9,_0x1027cc){return client[_0x6653('0xd')](_0x5e5385,_0x2179f3)[_0x6653('0xe')](function(_0x55b1c0){logger['info'](_0x6653('0xf'),_0x3110bc,'request\x20sent');logger[_0x6653('0x10')]('Plugin,\x20%s,\x20%s,\x20%s',_0x3110bc,_0x6653('0x11'),JSON[_0x6653('0x12')](_0x55b1c0));if(_0x55b1c0[_0x6653('0x13')]){if(_0x55b1c0[_0x6653('0x13')][_0x6653('0x14')]===0x1f4){logger[_0x6653('0x13')](_0x6653('0xf'),_0x3110bc,_0x55b1c0[_0x6653('0x13')][_0x6653('0x15')]);return _0x1027cc(_0x55b1c0['error'][_0x6653('0x15')]);}logger['error'](_0x6653('0xf'),_0x3110bc,_0x55b1c0[_0x6653('0x13')][_0x6653('0x15')]);return _0x4f8aa9(_0x55b1c0[_0x6653('0x13')][_0x6653('0x15')]);}else{logger[_0x6653('0x16')](_0x6653('0xf'),_0x3110bc,_0x6653('0x11'));_0x4f8aa9(_0x55b1c0[_0x6653('0x17')][_0x6653('0x15')]);}})['catch'](function(_0xb8bd56){logger['error'](_0x6653('0xf'),_0x3110bc,_0xb8bd56);_0x1027cc(_0xb8bd56);});});}exports[_0x6653('0x18')]=function(_0x6b2caa){var _0x32f907=this;return new Promise(function(_0x1d8b2a,_0xff8315){return db['Plugin'][_0x6653('0x19')](_0x6b2caa[_0x6653('0x1a')],{'raw':_0x6b2caa['options']?_0x6b2caa[_0x6653('0x1b')][_0x6653('0x1c')]===undefined?!![]:![]:!![]})[_0x6653('0xe')](function(_0x311050){logger[_0x6653('0x16')](_0x6653('0x18'),_0x6b2caa);logger[_0x6653('0x10')](_0x6653('0x18'),_0x6b2caa,JSON[_0x6653('0x12')](_0x311050));_0x1d8b2a(_0x311050);})['catch'](function(_0xaea7ff){logger[_0x6653('0x13')](_0x6653('0x18'),_0xaea7ff['message'],_0x6b2caa);_0xff8315(_0x32f907[_0x6653('0x13')](0x1f4,_0xaea7ff['message']));});});};