3281555bbc9a8b263663482a547ef0ab5b710f46
[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 _0x93a9=['Plugin,\x20%s,\x20%s','request\x20sent','debug','Plugin,\x20%s,\x20%s,\x20%s','error','code','message','info','catch','CreatePlugin','create','body','options','raw','stringify','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/environment','jayson/promise','client','redis','defaults','localhost','./plugin.socket','register','then'];(function(_0x22de84,_0x56142b){var _0x54fc49=function(_0x3be7bc){while(--_0x3be7bc){_0x22de84['push'](_0x22de84['shift']());}};_0x54fc49(++_0x56142b);}(_0x93a9,0x1d1));var _0x993a=function(_0x1b5d5f,_0x5ed766){_0x1b5d5f=_0x1b5d5f-0x0;var _0x3c9347=_0x93a9[_0x1b5d5f];return _0x3c9347;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0x993a('0x0'));var BPromise=require(_0x993a('0x1'));var rs=require(_0x993a('0x2'));var fs=require('fs');var Redis=require(_0x993a('0x3'));var db=require(_0x993a('0x4'))['db'];var utils=require(_0x993a('0x5'));var logger=require('../../config/logger')('rpc');var config=require(_0x993a('0x6'));var jayson=require(_0x993a('0x7'));var client=jayson[_0x993a('0x8')]['http']({'port':0x232a});config[_0x993a('0x9')]=_[_0x993a('0xa')](config[_0x993a('0x9')],{'host':_0x993a('0xb'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x993a('0xc'))[_0x993a('0xd')](socket);function respondWithRpcPromise(_0x406813,_0x2fbd60,_0x376b49){return new BPromise(function(_0x463286,_0x4747b6){return client['request'](_0x406813,_0x376b49)[_0x993a('0xe')](function(_0xe3ea94){logger['info'](_0x993a('0xf'),_0x2fbd60,_0x993a('0x10'));logger[_0x993a('0x11')](_0x993a('0x12'),_0x2fbd60,'request\x20sent',JSON['stringify'](_0xe3ea94));if(_0xe3ea94[_0x993a('0x13')]){if(_0xe3ea94['error'][_0x993a('0x14')]===0x1f4){logger['error'](_0x993a('0xf'),_0x2fbd60,_0xe3ea94[_0x993a('0x13')][_0x993a('0x15')]);return _0x4747b6(_0xe3ea94[_0x993a('0x13')]['message']);}logger['error']('Plugin,\x20%s,\x20%s',_0x2fbd60,_0xe3ea94[_0x993a('0x13')][_0x993a('0x15')]);return _0x463286(_0xe3ea94[_0x993a('0x13')][_0x993a('0x15')]);}else{logger[_0x993a('0x16')]('Plugin,\x20%s,\x20%s',_0x2fbd60,'request\x20sent');_0x463286(_0xe3ea94['result'][_0x993a('0x15')]);}})[_0x993a('0x17')](function(_0x2e697d){logger[_0x993a('0x13')]('Plugin,\x20%s,\x20%s',_0x2fbd60,_0x2e697d);_0x4747b6(_0x2e697d);});});}exports[_0x993a('0x18')]=function(_0x4c9f47){var _0x49afaa=this;return new Promise(function(_0x102143,_0x554010){return db['Plugin'][_0x993a('0x19')](_0x4c9f47[_0x993a('0x1a')],{'raw':_0x4c9f47[_0x993a('0x1b')]?_0x4c9f47[_0x993a('0x1b')][_0x993a('0x1c')]===undefined?!![]:![]:!![]})[_0x993a('0xe')](function(_0x42d4ed){logger[_0x993a('0x16')](_0x993a('0x18'),_0x4c9f47);logger[_0x993a('0x11')](_0x993a('0x18'),_0x4c9f47,JSON[_0x993a('0x1d')](_0x42d4ed));_0x102143(_0x42d4ed);})[_0x993a('0x17')](function(_0x4160fb){logger[_0x993a('0x13')](_0x993a('0x18'),_0x4160fb[_0x993a('0x15')],_0x4c9f47);_0x554010(_0x49afaa[_0x993a('0x13')](0x1f4,_0x4160fb['message']));});});};