Built motion from commit a679711e.|2.6.15
[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 _0xc0c0=['lodash','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','rpc','../../config/environment','jayson/promise','http','redis','defaults','./plugin.socket','register','then','Plugin,\x20%s,\x20%s','request\x20sent','debug','error','code','message','info','result','Plugin','create','options','raw','CreatePlugin','catch'];(function(_0x138adb,_0x193fee){var _0x1b27f2=function(_0x5e97a2){while(--_0x5e97a2){_0x138adb['push'](_0x138adb['shift']());}};_0x1b27f2(++_0x193fee);}(_0xc0c0,0x136));var _0x0c0c=function(_0x1a9204,_0x1c9e00){_0x1a9204=_0x1a9204-0x0;var _0x17ca68=_0xc0c0[_0x1a9204];return _0x17ca68;};'use strict';var _=require(_0x0c0c('0x0'));var util=require(_0x0c0c('0x1'));var moment=require(_0x0c0c('0x2'));var BPromise=require(_0x0c0c('0x3'));var rs=require(_0x0c0c('0x4'));var fs=require('fs');var Redis=require(_0x0c0c('0x5'));var db=require(_0x0c0c('0x6'))['db'];var utils=require(_0x0c0c('0x7'));var logger=require('../../config/logger')(_0x0c0c('0x8'));var config=require(_0x0c0c('0x9'));var jayson=require(_0x0c0c('0xa'));var client=jayson['client'][_0x0c0c('0xb')]({'port':0x232a});config[_0x0c0c('0xc')]=_[_0x0c0c('0xd')](config[_0x0c0c('0xc')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x0c0c('0xe'))[_0x0c0c('0xf')](socket);function respondWithRpcPromise(_0x38840e,_0x1761bc,_0x48ba72){return new BPromise(function(_0x55084a,_0x20e6ec){return client['request'](_0x38840e,_0x48ba72)[_0x0c0c('0x10')](function(_0xe2aff3){logger['info'](_0x0c0c('0x11'),_0x1761bc,_0x0c0c('0x12'));logger[_0x0c0c('0x13')]('Plugin,\x20%s,\x20%s,\x20%s',_0x1761bc,_0x0c0c('0x12'),JSON['stringify'](_0xe2aff3));if(_0xe2aff3['error']){if(_0xe2aff3[_0x0c0c('0x14')][_0x0c0c('0x15')]===0x1f4){logger[_0x0c0c('0x14')]('Plugin,\x20%s,\x20%s',_0x1761bc,_0xe2aff3[_0x0c0c('0x14')][_0x0c0c('0x16')]);return _0x20e6ec(_0xe2aff3['error'][_0x0c0c('0x16')]);}logger['error'](_0x0c0c('0x11'),_0x1761bc,_0xe2aff3[_0x0c0c('0x14')][_0x0c0c('0x16')]);return _0x55084a(_0xe2aff3[_0x0c0c('0x14')][_0x0c0c('0x16')]);}else{logger[_0x0c0c('0x17')](_0x0c0c('0x11'),_0x1761bc,_0x0c0c('0x12'));_0x55084a(_0xe2aff3[_0x0c0c('0x18')]['message']);}})['catch'](function(_0x383e0c){logger[_0x0c0c('0x14')](_0x0c0c('0x11'),_0x1761bc,_0x383e0c);_0x20e6ec(_0x383e0c);});});}exports['CreatePlugin']=function(_0x36f578){var _0x54af47=this;return new Promise(function(_0x3b5eeb,_0x4be3d8){return db[_0x0c0c('0x19')][_0x0c0c('0x1a')](_0x36f578['body'],{'raw':_0x36f578[_0x0c0c('0x1b')]?_0x36f578[_0x0c0c('0x1b')][_0x0c0c('0x1c')]===undefined?!![]:![]:!![]})['then'](function(_0xa81e79){logger[_0x0c0c('0x17')](_0x0c0c('0x1d'),_0x36f578);logger[_0x0c0c('0x13')](_0x0c0c('0x1d'),_0x36f578,JSON['stringify'](_0xa81e79));_0x3b5eeb(_0xa81e79);})[_0x0c0c('0x1e')](function(_0x1125bd){logger[_0x0c0c('0x14')](_0x0c0c('0x1d'),_0x1125bd[_0x0c0c('0x16')],_0x36f578);_0x4be3d8(_0x54af47[_0x0c0c('0x14')](0x1f4,_0x1125bd['message']));});});};