8d6657ae06e666be45d4d97f5657ee6f82348c07
[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 _0x98d2=['body','options','raw','catch','lodash','util','moment','randomstring','ioredis','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','defaults','localhost','socket.io-emitter','./chatMessage.socket','register','request','then','info','ChatMessage,\x20%s,\x20%s','debug','request\x20sent','stringify','error','code','message','CreateChatMessage','ChatMessage','create'];(function(_0x47d506,_0x5a1e99){var _0x58251a=function(_0x476cef){while(--_0x476cef){_0x47d506['push'](_0x47d506['shift']());}};_0x58251a(++_0x5a1e99);}(_0x98d2,0x1c4));var _0x298d=function(_0x3bceea,_0x58af75){_0x3bceea=_0x3bceea-0x0;var _0x30a8d3=_0x98d2[_0x3bceea];return _0x30a8d3;};'use strict';var _=require(_0x298d('0x0'));var util=require(_0x298d('0x1'));var moment=require(_0x298d('0x2'));var BPromise=require('bluebird');var rs=require(_0x298d('0x3'));var fs=require('fs');var Redis=require(_0x298d('0x4'));var db=require('../../mysqldb')['db'];var utils=require(_0x298d('0x5'));var logger=require(_0x298d('0x6'))(_0x298d('0x7'));var config=require(_0x298d('0x8'));var jayson=require(_0x298d('0x9'));var client=jayson['client']['http']({'port':0x232a});config['redis']=_[_0x298d('0xa')](config['redis'],{'host':_0x298d('0xb'),'port':0x18eb});var socket=require(_0x298d('0xc'))(new Redis(config['redis']));require(_0x298d('0xd'))[_0x298d('0xe')](socket);function respondWithRpcPromise(_0x1685f2,_0x2190f1,_0x1f8323){return new BPromise(function(_0x5e74db,_0x1abde7){return client[_0x298d('0xf')](_0x1685f2,_0x1f8323)[_0x298d('0x10')](function(_0x30965d){logger[_0x298d('0x11')](_0x298d('0x12'),_0x2190f1,'request\x20sent');logger[_0x298d('0x13')]('ChatMessage,\x20%s,\x20%s,\x20%s',_0x2190f1,_0x298d('0x14'),JSON[_0x298d('0x15')](_0x30965d));if(_0x30965d[_0x298d('0x16')]){if(_0x30965d['error'][_0x298d('0x17')]===0x1f4){logger[_0x298d('0x16')](_0x298d('0x12'),_0x2190f1,_0x30965d[_0x298d('0x16')][_0x298d('0x18')]);return _0x1abde7(_0x30965d[_0x298d('0x16')][_0x298d('0x18')]);}logger[_0x298d('0x16')](_0x298d('0x12'),_0x2190f1,_0x30965d[_0x298d('0x16')][_0x298d('0x18')]);return _0x5e74db(_0x30965d[_0x298d('0x16')][_0x298d('0x18')]);}else{logger[_0x298d('0x11')](_0x298d('0x12'),_0x2190f1,_0x298d('0x14'));_0x5e74db(_0x30965d['result'][_0x298d('0x18')]);}})['catch'](function(_0x48aba2){logger[_0x298d('0x16')](_0x298d('0x12'),_0x2190f1,_0x48aba2);_0x1abde7(_0x48aba2);});});}exports[_0x298d('0x19')]=function(_0x29f188){var _0x4dd663=this;return new Promise(function(_0x3a9b0c,_0x1c473c){return db[_0x298d('0x1a')][_0x298d('0x1b')](_0x29f188[_0x298d('0x1c')],{'raw':_0x29f188['options']?_0x29f188[_0x298d('0x1d')][_0x298d('0x1e')]===undefined?!![]:![]:!![]})[_0x298d('0x10')](function(_0x2666a4){logger['info'](_0x298d('0x19'),_0x29f188);logger['debug'](_0x298d('0x19'),_0x29f188,JSON['stringify'](_0x2666a4));_0x3a9b0c(_0x2666a4);})[_0x298d('0x1f')](function(_0x2bb89f){logger[_0x298d('0x16')](_0x298d('0x19'),_0x2bb89f['message'],_0x29f188);_0x1c473c(_0x4dd663[_0x298d('0x16')](0x1f4,_0x2bb89f[_0x298d('0x18')]));});});};