8e1bebaa820b01cc504402ed486616320dcf5110
[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 _0xc39e=['message','result','CreateChatMessage','ChatMessage','options','raw','catch','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','../../config/environment','jayson/promise','http','redis','defaults','localhost','socket.io-emitter','./chatMessage.socket','register','request','info','ChatMessage,\x20%s,\x20%s','request\x20sent','debug','ChatMessage,\x20%s,\x20%s,\x20%s','error'];(function(_0x16b9ed,_0x56517a){var _0x66b1f8=function(_0x1c883){while(--_0x1c883){_0x16b9ed['push'](_0x16b9ed['shift']());}};_0x66b1f8(++_0x56517a);}(_0xc39e,0x1b9));var _0xec39=function(_0x104e21,_0x2ea86f){_0x104e21=_0x104e21-0x0;var _0x605b37=_0xc39e[_0x104e21];return _0x605b37;};'use strict';var _=require('lodash');var util=require(_0xec39('0x0'));var moment=require(_0xec39('0x1'));var BPromise=require(_0xec39('0x2'));var rs=require(_0xec39('0x3'));var fs=require('fs');var Redis=require(_0xec39('0x4'));var db=require(_0xec39('0x5'))['db'];var utils=require(_0xec39('0x6'));var logger=require(_0xec39('0x7'))('rpc');var config=require(_0xec39('0x8'));var jayson=require(_0xec39('0x9'));var client=jayson['client'][_0xec39('0xa')]({'port':0x232a});config[_0xec39('0xb')]=_[_0xec39('0xc')](config[_0xec39('0xb')],{'host':_0xec39('0xd'),'port':0x18eb});var socket=require(_0xec39('0xe'))(new Redis(config['redis']));require(_0xec39('0xf'))[_0xec39('0x10')](socket);function respondWithRpcPromise(_0x4e7d0e,_0x7b7a36,_0x3511e1){return new BPromise(function(_0x475573,_0x4e20d6){return client[_0xec39('0x11')](_0x4e7d0e,_0x3511e1)['then'](function(_0x251d44){logger[_0xec39('0x12')](_0xec39('0x13'),_0x7b7a36,_0xec39('0x14'));logger[_0xec39('0x15')](_0xec39('0x16'),_0x7b7a36,_0xec39('0x14'),JSON['stringify'](_0x251d44));if(_0x251d44['error']){if(_0x251d44[_0xec39('0x17')]['code']===0x1f4){logger[_0xec39('0x17')](_0xec39('0x13'),_0x7b7a36,_0x251d44[_0xec39('0x17')][_0xec39('0x18')]);return _0x4e20d6(_0x251d44['error'][_0xec39('0x18')]);}logger[_0xec39('0x17')]('ChatMessage,\x20%s,\x20%s',_0x7b7a36,_0x251d44[_0xec39('0x17')]['message']);return _0x475573(_0x251d44[_0xec39('0x17')][_0xec39('0x18')]);}else{logger[_0xec39('0x12')](_0xec39('0x13'),_0x7b7a36,_0xec39('0x14'));_0x475573(_0x251d44[_0xec39('0x19')][_0xec39('0x18')]);}})['catch'](function(_0xfb231b){logger['error'](_0xec39('0x13'),_0x7b7a36,_0xfb231b);_0x4e20d6(_0xfb231b);});});}exports[_0xec39('0x1a')]=function(_0x65ee0b){var _0x5703c2=this;return new Promise(function(_0x4421b2,_0x2d0498){return db[_0xec39('0x1b')]['create'](_0x65ee0b['body'],{'raw':_0x65ee0b[_0xec39('0x1c')]?_0x65ee0b[_0xec39('0x1c')][_0xec39('0x1d')]===undefined?!![]:![]:!![]})['then'](function(_0x2f847f){logger[_0xec39('0x12')](_0xec39('0x1a'),_0x65ee0b);logger[_0xec39('0x15')](_0xec39('0x1a'),_0x65ee0b,JSON['stringify'](_0x2f847f));_0x4421b2(_0x2f847f);})[_0xec39('0x1e')](function(_0x5a8d31){logger[_0xec39('0x17')](_0xec39('0x1a'),_0x5a8d31[_0xec39('0x18')],_0x65ee0b);_0x2d0498(_0x5703c2['error'](0x1f4,_0x5a8d31[_0xec39('0x18')]));});});};