Built motion from commit d5e4af8c.|2.6.23
[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 _0x44d4=['redis','localhost','socket.io-emitter','./plugin.socket','register','request','then','Plugin,\x20%s,\x20%s','request\x20sent','debug','Plugin,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','result','CreatePlugin','Plugin','options','raw','catch','lodash','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','rpc','../../config/environment','http','defaults'];(function(_0x14add3,_0x13ce8d){var _0x4a174f=function(_0x2b3ed7){while(--_0x2b3ed7){_0x14add3['push'](_0x14add3['shift']());}};_0x4a174f(++_0x13ce8d);}(_0x44d4,0x7c));var _0x444d=function(_0x57172c,_0x1df512){_0x57172c=_0x57172c-0x0;var _0x38e8a4=_0x44d4[_0x57172c];return _0x38e8a4;};'use strict';var _=require(_0x444d('0x0'));var util=require(_0x444d('0x1'));var moment=require(_0x444d('0x2'));var BPromise=require(_0x444d('0x3'));var rs=require(_0x444d('0x4'));var fs=require('fs');var Redis=require(_0x444d('0x5'));var db=require(_0x444d('0x6'))['db'];var utils=require(_0x444d('0x7'));var logger=require('../../config/logger')(_0x444d('0x8'));var config=require(_0x444d('0x9'));var jayson=require('jayson/promise');var client=jayson['client'][_0x444d('0xa')]({'port':0x232a});config['redis']=_[_0x444d('0xb')](config[_0x444d('0xc')],{'host':_0x444d('0xd'),'port':0x18eb});var socket=require(_0x444d('0xe'))(new Redis(config[_0x444d('0xc')]));require(_0x444d('0xf'))[_0x444d('0x10')](socket);function respondWithRpcPromise(_0x43414a,_0x5603b1,_0x5033dc){return new BPromise(function(_0x210d27,_0x271df6){return client[_0x444d('0x11')](_0x43414a,_0x5033dc)[_0x444d('0x12')](function(_0x11179b){logger['info'](_0x444d('0x13'),_0x5603b1,_0x444d('0x14'));logger[_0x444d('0x15')](_0x444d('0x16'),_0x5603b1,'request\x20sent',JSON[_0x444d('0x17')](_0x11179b));if(_0x11179b[_0x444d('0x18')]){if(_0x11179b[_0x444d('0x18')][_0x444d('0x19')]===0x1f4){logger[_0x444d('0x18')](_0x444d('0x13'),_0x5603b1,_0x11179b[_0x444d('0x18')][_0x444d('0x1a')]);return _0x271df6(_0x11179b[_0x444d('0x18')][_0x444d('0x1a')]);}logger[_0x444d('0x18')](_0x444d('0x13'),_0x5603b1,_0x11179b[_0x444d('0x18')][_0x444d('0x1a')]);return _0x210d27(_0x11179b['error']['message']);}else{logger[_0x444d('0x1b')](_0x444d('0x13'),_0x5603b1,'request\x20sent');_0x210d27(_0x11179b[_0x444d('0x1c')]['message']);}})['catch'](function(_0x83b7a9){logger[_0x444d('0x18')]('Plugin,\x20%s,\x20%s',_0x5603b1,_0x83b7a9);_0x271df6(_0x83b7a9);});});}exports[_0x444d('0x1d')]=function(_0x1cf5a2){var _0x435aa4=this;return new Promise(function(_0x4f520d,_0x4473c0){return db[_0x444d('0x1e')]['create'](_0x1cf5a2['body'],{'raw':_0x1cf5a2[_0x444d('0x1f')]?_0x1cf5a2[_0x444d('0x1f')][_0x444d('0x20')]===undefined?!![]:![]:!![]})[_0x444d('0x12')](function(_0x52e33e){logger[_0x444d('0x1b')](_0x444d('0x1d'),_0x1cf5a2);logger[_0x444d('0x15')](_0x444d('0x1d'),_0x1cf5a2,JSON[_0x444d('0x17')](_0x52e33e));_0x4f520d(_0x52e33e);})[_0x444d('0x21')](function(_0x3cb14b){logger[_0x444d('0x18')](_0x444d('0x1d'),_0x3cb14b[_0x444d('0x1a')],_0x1cf5a2);_0x4473c0(_0x435aa4[_0x444d('0x18')](0x1f4,_0x3cb14b['message']));});});};