3ad9f71b0c19a6f49ae87c6bbdf46de6fe3db925
[motion2.git] / server / api / chatMessage / chatMessage.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 _0x9af9=['code','message','result','catch','CreateChatMessage','ChatMessage','create','body','options','raw','lodash','util','bluebird','ioredis','../../config/logger','jayson/promise','defaults','localhost','socket.io-emitter','redis','./chatMessage.socket','register','then','info','ChatMessage,\x20%s,\x20%s','request\x20sent','debug','error'];(function(_0x45a5a3,_0x4bbd82){var _0x5ba07c=function(_0xaedf7f){while(--_0xaedf7f){_0x45a5a3['push'](_0x45a5a3['shift']());}};_0x5ba07c(++_0x4bbd82);}(_0x9af9,0x7a));var _0x99af=function(_0x49bdd6,_0x217dec){_0x49bdd6=_0x49bdd6-0x0;var _0x19079d=_0x9af9[_0x49bdd6];return _0x19079d;};'use strict';var _=require(_0x99af('0x0'));var util=require(_0x99af('0x1'));var moment=require('moment');var BPromise=require(_0x99af('0x2'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x99af('0x3'));var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require(_0x99af('0x4'))('rpc');var config=require('../../config/environment');var jayson=require(_0x99af('0x5'));var client=jayson['client']['http']({'port':0x232a});config['redis']=_[_0x99af('0x6')](config['redis'],{'host':_0x99af('0x7'),'port':0x18eb});var socket=require(_0x99af('0x8'))(new Redis(config[_0x99af('0x9')]));require(_0x99af('0xa'))[_0x99af('0xb')](socket);function respondWithRpcPromise(_0x1cbf0f,_0x39f486,_0x2b0bd6){return new BPromise(function(_0x2c1e12,_0x256865){return client['request'](_0x1cbf0f,_0x2b0bd6)[_0x99af('0xc')](function(_0x1dd9a9){logger[_0x99af('0xd')](_0x99af('0xe'),_0x39f486,_0x99af('0xf'));logger[_0x99af('0x10')]('ChatMessage,\x20%s,\x20%s,\x20%s',_0x39f486,'request\x20sent',JSON['stringify'](_0x1dd9a9));if(_0x1dd9a9['error']){if(_0x1dd9a9[_0x99af('0x11')][_0x99af('0x12')]===0x1f4){logger[_0x99af('0x11')](_0x99af('0xe'),_0x39f486,_0x1dd9a9[_0x99af('0x11')]['message']);return _0x256865(_0x1dd9a9[_0x99af('0x11')][_0x99af('0x13')]);}logger[_0x99af('0x11')](_0x99af('0xe'),_0x39f486,_0x1dd9a9[_0x99af('0x11')]['message']);return _0x2c1e12(_0x1dd9a9[_0x99af('0x11')][_0x99af('0x13')]);}else{logger[_0x99af('0xd')](_0x99af('0xe'),_0x39f486,_0x99af('0xf'));_0x2c1e12(_0x1dd9a9[_0x99af('0x14')][_0x99af('0x13')]);}})[_0x99af('0x15')](function(_0x4dae2b){logger['error'](_0x99af('0xe'),_0x39f486,_0x4dae2b);_0x256865(_0x4dae2b);});});}exports[_0x99af('0x16')]=function(_0x2d2928){var _0x1b0899=this;return new Promise(function(_0x3af828,_0x4df1fe){return db[_0x99af('0x17')][_0x99af('0x18')](_0x2d2928[_0x99af('0x19')],{'raw':_0x2d2928['options']?_0x2d2928[_0x99af('0x1a')][_0x99af('0x1b')]===undefined?!![]:![]:!![]})[_0x99af('0xc')](function(_0x3fcfbe){logger[_0x99af('0xd')]('CreateChatMessage',_0x2d2928);logger[_0x99af('0x10')](_0x99af('0x16'),_0x2d2928,JSON['stringify'](_0x3fcfbe));_0x3af828(_0x3fcfbe);})[_0x99af('0x15')](function(_0x573e51){logger[_0x99af('0x11')](_0x99af('0x16'),_0x573e51[_0x99af('0x13')],_0x2d2928);_0x4df1fe(_0x1b0899['error'](0x1f4,_0x573e51[_0x99af('0x13')]));});});};