Built motion from commit ac06311e.|2.6.28
[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 _0xf756=['CreatePlugin','Plugin','body','options','raw','stringify','lodash','util','moment','ioredis','../../mysqldb','rpc','jayson/promise','defaults','redis','socket.io-emitter','register','request','then','info','request\x20sent','debug','Plugin,\x20%s,\x20%s,\x20%s','error','code','Plugin,\x20%s,\x20%s','message','catch'];(function(_0x3714a0,_0x3775e4){var _0x430d52=function(_0xc846cb){while(--_0xc846cb){_0x3714a0['push'](_0x3714a0['shift']());}};_0x430d52(++_0x3775e4);}(_0xf756,0x18e));var _0x6f75=function(_0x6131cd,_0x4c26a1){_0x6131cd=_0x6131cd-0x0;var _0x47e916=_0xf756[_0x6131cd];return _0x47e916;};'use strict';var _=require(_0x6f75('0x0'));var util=require(_0x6f75('0x1'));var moment=require(_0x6f75('0x2'));var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x6f75('0x3'));var db=require(_0x6f75('0x4'))['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')(_0x6f75('0x5'));var config=require('../../config/environment');var jayson=require(_0x6f75('0x6'));var client=jayson['client']['http']({'port':0x232a});config['redis']=_[_0x6f75('0x7')](config[_0x6f75('0x8')],{'host':'localhost','port':0x18eb});var socket=require(_0x6f75('0x9'))(new Redis(config[_0x6f75('0x8')]));require('./plugin.socket')[_0x6f75('0xa')](socket);function respondWithRpcPromise(_0x56a2d3,_0x71459b,_0x1bbbae){return new BPromise(function(_0x41be99,_0x92976a){return client[_0x6f75('0xb')](_0x56a2d3,_0x1bbbae)[_0x6f75('0xc')](function(_0x4dd946){logger[_0x6f75('0xd')]('Plugin,\x20%s,\x20%s',_0x71459b,_0x6f75('0xe'));logger[_0x6f75('0xf')](_0x6f75('0x10'),_0x71459b,_0x6f75('0xe'),JSON['stringify'](_0x4dd946));if(_0x4dd946[_0x6f75('0x11')]){if(_0x4dd946[_0x6f75('0x11')][_0x6f75('0x12')]===0x1f4){logger[_0x6f75('0x11')](_0x6f75('0x13'),_0x71459b,_0x4dd946[_0x6f75('0x11')][_0x6f75('0x14')]);return _0x92976a(_0x4dd946[_0x6f75('0x11')][_0x6f75('0x14')]);}logger[_0x6f75('0x11')]('Plugin,\x20%s,\x20%s',_0x71459b,_0x4dd946[_0x6f75('0x11')][_0x6f75('0x14')]);return _0x41be99(_0x4dd946['error'][_0x6f75('0x14')]);}else{logger['info']('Plugin,\x20%s,\x20%s',_0x71459b,'request\x20sent');_0x41be99(_0x4dd946['result'][_0x6f75('0x14')]);}})[_0x6f75('0x15')](function(_0x203cfd){logger[_0x6f75('0x11')]('Plugin,\x20%s,\x20%s',_0x71459b,_0x203cfd);_0x92976a(_0x203cfd);});});}exports[_0x6f75('0x16')]=function(_0x4bc551){var _0xa58f38=this;return new Promise(function(_0x459443,_0x54b905){return db[_0x6f75('0x17')]['create'](_0x4bc551[_0x6f75('0x18')],{'raw':_0x4bc551[_0x6f75('0x19')]?_0x4bc551[_0x6f75('0x19')][_0x6f75('0x1a')]===undefined?!![]:![]:!![]})[_0x6f75('0xc')](function(_0x58a24b){logger[_0x6f75('0xd')](_0x6f75('0x16'),_0x4bc551);logger[_0x6f75('0xf')](_0x6f75('0x16'),_0x4bc551,JSON[_0x6f75('0x1b')](_0x58a24b));_0x459443(_0x58a24b);})[_0x6f75('0x15')](function(_0x28170e){logger[_0x6f75('0x11')](_0x6f75('0x16'),_0x28170e[_0x6f75('0x14')],_0x4bc551);_0x54b905(_0xa58f38['error'](0x1f4,_0x28170e[_0x6f75('0x14')]));});});};