37b15e826075e41af8b3aae79591abc454a201ce
[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 _0xfe9b=['randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','http','defaults','localhost','socket.io-emitter','redis','./chatMessage.socket','register','request','then','info','ChatMessage,\x20%s,\x20%s','request\x20sent','debug','ChatMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','CreateChatMessage','create','body','options','raw','lodash','moment','bluebird'];(function(_0x2648bc,_0x55c59b){var _0x59f6e2=function(_0x51d83b){while(--_0x51d83b){_0x2648bc['push'](_0x2648bc['shift']());}};_0x59f6e2(++_0x55c59b);}(_0xfe9b,0x1d9));var _0xbfe9=function(_0x300eb2,_0x12fa40){_0x300eb2=_0x300eb2-0x0;var _0x177763=_0xfe9b[_0x300eb2];return _0x177763;};'use strict';var _=require(_0xbfe9('0x0'));var util=require('util');var moment=require(_0xbfe9('0x1'));var BPromise=require(_0xbfe9('0x2'));var rs=require(_0xbfe9('0x3'));var fs=require('fs');var Redis=require(_0xbfe9('0x4'));var db=require(_0xbfe9('0x5'))['db'];var utils=require(_0xbfe9('0x6'));var logger=require(_0xbfe9('0x7'))(_0xbfe9('0x8'));var config=require(_0xbfe9('0x9'));var jayson=require('jayson/promise');var client=jayson['client'][_0xbfe9('0xa')]({'port':0x232a});config['redis']=_[_0xbfe9('0xb')](config['redis'],{'host':_0xbfe9('0xc'),'port':0x18eb});var socket=require(_0xbfe9('0xd'))(new Redis(config[_0xbfe9('0xe')]));require(_0xbfe9('0xf'))[_0xbfe9('0x10')](socket);function respondWithRpcPromise(_0x44b87c,_0x234a9c,_0x1d596c){return new BPromise(function(_0x1d1504,_0x305dbc){return client[_0xbfe9('0x11')](_0x44b87c,_0x1d596c)[_0xbfe9('0x12')](function(_0x46a7a1){logger[_0xbfe9('0x13')](_0xbfe9('0x14'),_0x234a9c,_0xbfe9('0x15'));logger[_0xbfe9('0x16')](_0xbfe9('0x17'),_0x234a9c,_0xbfe9('0x15'),JSON[_0xbfe9('0x18')](_0x46a7a1));if(_0x46a7a1['error']){if(_0x46a7a1[_0xbfe9('0x19')][_0xbfe9('0x1a')]===0x1f4){logger[_0xbfe9('0x19')](_0xbfe9('0x14'),_0x234a9c,_0x46a7a1[_0xbfe9('0x19')][_0xbfe9('0x1b')]);return _0x305dbc(_0x46a7a1[_0xbfe9('0x19')][_0xbfe9('0x1b')]);}logger[_0xbfe9('0x19')]('ChatMessage,\x20%s,\x20%s',_0x234a9c,_0x46a7a1[_0xbfe9('0x19')][_0xbfe9('0x1b')]);return _0x1d1504(_0x46a7a1[_0xbfe9('0x19')]['message']);}else{logger[_0xbfe9('0x13')]('ChatMessage,\x20%s,\x20%s',_0x234a9c,_0xbfe9('0x15'));_0x1d1504(_0x46a7a1['result']['message']);}})[_0xbfe9('0x1c')](function(_0x178afb){logger[_0xbfe9('0x19')](_0xbfe9('0x14'),_0x234a9c,_0x178afb);_0x305dbc(_0x178afb);});});}exports[_0xbfe9('0x1d')]=function(_0x9e1ec8){var _0x4c6947=this;return new Promise(function(_0x3a14c8,_0x4b2038){return db['ChatMessage'][_0xbfe9('0x1e')](_0x9e1ec8[_0xbfe9('0x1f')],{'raw':_0x9e1ec8[_0xbfe9('0x20')]?_0x9e1ec8[_0xbfe9('0x20')][_0xbfe9('0x21')]===undefined?!![]:![]:!![]})[_0xbfe9('0x12')](function(_0x4a6e20){logger['info'](_0xbfe9('0x1d'),_0x9e1ec8);logger['debug']('CreateChatMessage',_0x9e1ec8,JSON['stringify'](_0x4a6e20));_0x3a14c8(_0x4a6e20);})[_0xbfe9('0x1c')](function(_0x38d163){logger['error'](_0xbfe9('0x1d'),_0x38d163[_0xbfe9('0x1b')],_0x9e1ec8);_0x4b2038(_0x4c6947[_0xbfe9('0x19')](0x1f4,_0x38d163[_0xbfe9('0x1b')]));});});};